| | |
| | | #include "PL_RTSPServer.h"
|
| | | #include "MaterialBuffer.h"
|
| | | #include "logger.h"
|
| | |
|
| | | #include <liveMedia.hh>
|
| | | #include <BasicUsageEnvironment.hh>
|
| | | #include <liveMedia/liveMedia.hh>
|
| | | #include <BasicUsageEnvironment/BasicUsageEnvironment.hh>
|
| | |
|
| | | #include "FFmpegRTSPServer/IEncoder.h"
|
| | | #include "FFmpegRTSPServer/LiveRTSPServer.h"
|
| | |
| | |
|
| | | struct RTSPServer_Internal
|
| | | {
|
| | | uint8_t* buffer;
|
| | | uint8_t buffer[1920*1080*3];
|
| | | size_t buffSize;
|
| | | size_t buffSizeMax;
|
| | | |
| | | RTSPServerConfig config;
|
| | |
|
| | | bool payError;
|
| | | pthread_t live_daemon_thid;
|
| | |
| | | MyEncoderStub * encoderStub;
|
| | |
|
| | | RTSPServer_Internal() :
|
| | | buffer(nullptr), buffSize(0), |
| | | buffSize(0), buffSizeMax(sizeof(buffer)), config(), |
| | | payError(true), live_daemon_thid(0), frame_mutex(new pthread_mutex_t), live_daemon_running(false),
|
| | | server(nullptr), encoderStub(nullptr)
|
| | | {
|
| | |
| | |
|
| | | void reset()
|
| | | {
|
| | | buffer = nullptr;
|
| | | buffSize = 0;
|
| | | |
| | | RTSPServerConfig _config;
|
| | | config =_config;
|
| | |
|
| | | payError = true;
|
| | |
|
| | |
| | |
|
| | | virtual char GetFrame(u_int8_t** FrameBuffer, unsigned int *FrameSize)
|
| | | {
|
| | | if (in.buffer != nullptr && in.buffSize > 0)
|
| | | {
|
| | | *FrameBuffer = in.buffer;
|
| | | *FrameSize = in.buffSize;
|
| | |
|
| | | printf("send frame size=%u\n", in.buffSize);
|
| | | |
| | | in.buffer = nullptr;
|
| | | in.buffSize = 0;
|
| | | |
| | | return 1;
|
| | | }
|
| | | else
|
| | | if (in.buffer == nullptr || in.buffSize <= 0)
|
| | | {
|
| | | ReleaseFrame();
|
| | | return 0;
|
| | | }
|
| | |
|
| | | //static size_t f = 0;
|
| | | //static FILE *pFile = fopen("/data/bb.264", "wb");
|
| | | //fwrite(in.buffer, sizeof(char), in.buffSize, pFile);
|
| | | //if (++f > 400){
|
| | | // fclose(pFile);
|
| | | // exit(0);
|
| | | //}
|
| | |
|
| | | uint8_t* pBuffer = in.buffer;
|
| | | size_t newBufferSize = in.buffSize;
|
| | |
|
| | | if (in.config.payWithAux)
|
| | | {
|
| | | if (newBufferSize <= 4)
|
| | | {
|
| | | ReleaseFrame();
|
| | | return 0;
|
| | | }
|
| | | pBuffer += 4;
|
| | | newBufferSize -= 4;
|
| | | }
|
| | |
|
| | | *FrameBuffer = pBuffer;
|
| | | *FrameSize = newBufferSize;
|
| | |
|
| | | LOG_DEBUG << "send frame size=" << in.buffSize << std::endl;
|
| | | return 1;
|
| | | }
|
| | |
|
| | | virtual char ReleaseFrame()
|
| | | {
|
| | | int ret = pthread_mutex_unlock(in.frame_mutex);
|
| | | if(ret != 0)
|
| | | in.buffSize = 0;
|
| | | |
| | | if (in.config.syncDeliverFrame)
|
| | | {
|
| | | printf("pthread_mutex_unlock frame_mutex: %s/n", strerror(ret));
|
| | | return 0;
|
| | | int ret = pthread_mutex_unlock(in.frame_mutex);
|
| | | if(ret != 0)
|
| | | {
|
| | | LOG_WARN << "pthread_mutex_unlock frame_mutex: " << strerror(ret) << std::endl;
|
| | | return 0;
|
| | | }
|
| | | }
|
| | |
|
| | | return 1;
|
| | |
| | | // write frame buffer of RTSPServer_Internal::buffer
|
| | | onFrame();
|
| | |
|
| | | int ret = pthread_mutex_lock(in.frame_mutex);
|
| | | if(ret != 0)
|
| | | if (in.config.syncDeliverFrame)
|
| | | {
|
| | | printf("pthread_mutex_lock frame_mutex: %s/n", strerror(ret));
|
| | | return;
|
| | | int ret = pthread_mutex_lock(in.frame_mutex);
|
| | | if(ret != 0)
|
| | | {
|
| | | LOG_WARN << "pthread_mutex_lock frame_mutex: " << strerror(ret) << std::endl;
|
| | | return;
|
| | | }
|
| | | }
|
| | | }
|
| | |
|
| | |
| | | RTSPServer_Internal* in = (RTSPServer_Internal*)internal;
|
| | | in->reset();
|
| | |
|
| | | if (args)
|
| | | {
|
| | | RTSPServerConfig* config = (RTSPServerConfig*)args;
|
| | | in->config = *config;
|
| | | }
|
| | |
|
| | | int ret = pthread_create(&(in->live_daemon_thid), NULL, live_daemon_thd, in);
|
| | | if(ret != 0)
|
| | | {
|
| | | printf("pthread_create: %s/n", strerror(ret));
|
| | | LOG_ERROR << "pthread_create: " << strerror(ret) << std::endl;
|
| | | return false;
|
| | | }
|
| | |
|
| | |
| | | {
|
| | | RTSPServer_Internal* in = (RTSPServer_Internal*)internal;
|
| | |
|
| | | if (pm.buffer == nullptr || pm.buffSize <= 0)
|
| | | if (pm.buffer == nullptr)
|
| | | return false;
|
| | |
|
| | | in->buffer = pm.buffer;
|
| | | in->buffSize = pm.buffSize;
|
| | | if (pm.type != PipeMaterial::PMT_FRAME)
|
| | | {
|
| | | LOG_ERROR << "PL_RTSPServer::pay only support PMT_FRAME" << std::endl;
|
| | | return false;
|
| | | }
|
| | |
|
| | | if (in->buffSize > 0)
|
| | | LOG_WARN << "PL_RTSPServer::pay may lost data size=" << in->buffSize << std::endl;
|
| | | |
| | | MB_Frame* frame = (MB_Frame*)pm.buffer;
|
| | | if (frame->buffer == nullptr)
|
| | | return false;
|
| | | memcpy(in->buffer, frame->buffer, frame->buffSize);
|
| | | in->buffSize = frame->buffSize;
|
| | |
|
| | | if (in->encoderStub == nullptr)
|
| | | return false;
|
| | |
|
| | |
| | | {
|
| | | RTSPServer_Internal* in = (RTSPServer_Internal*)internal;
|
| | |
|
| | | pm.type = PipeMaterial::PMT_NONE;
|
| | | pm.buffer = nullptr;
|
| | | pm.buffSize = 0;
|
| | | pm.former = this;
|