pans
2016-12-28 928db0d6dc74630e35df9360e9d9968f17d11ca9
RtspFace/PL_RTSPClient.cpp
@@ -1,15 +1,16 @@
#include "PL_RTSPClient.h"
#include "MaterialBuffer.h"
#include <pthread.h>
void rtsp_client_sdp_callback(void* arg, const char* val);
void rtsp_client_fmtp_callback(void* arg, const char* val);
void rtsp_client_frame_callback(void* arg, uint8_t* buffer, size_t buffSize);
void rtsp_client_frame_callback(void* arg, uint8_t* buffer, size_t buffSize, timeval presentationTime);
void rtsp_client_continue_callback(void* arg);
#include "testRTSPClient.hpp"
//struct RTSPConfig;
#include "live555/testProgs/testRTSPClient.hpp"
struct RTSPClient_Internal
{
   PL_RTSPClient* client;
   RTSPConfig rtspConfig;
   pthread_t live_daemon_thid;
   char eventLoopWatchVariable;
@@ -17,14 +18,13 @@
   pthread_mutex_t* frame_mutex;
   pthread_mutex_t* continue_mutex;
   
   uint8_t* lastBuffer;
   size_t lastBuffSize;
   MB_Frame lastFrame;
   
   RTSPClient_Internal() : 
      client(nullptr), rtspConfig(), live_daemon_thid(0),
      rtspConfig(), live_daemon_thid(0),
      eventLoopWatchVariable(0), live_daemon_running(false), 
      frame_mutex(new pthread_mutex_t), continue_mutex(new pthread_mutex_t), 
      lastBuffer(nullptr), lastBuffSize(0)
      lastFrame()
   {
      pthread_mutex_init(frame_mutex, NULL);
      pthread_mutex_init(continue_mutex, NULL);
@@ -36,20 +36,21 @@
      {
         pthread_mutex_destroy(frame_mutex);
         delete frame_mutex;
         frame_mutex = nullptr;
      }
      
      if (continue_mutex != nullptr)
      {
         pthread_mutex_destroy(continue_mutex);
         delete continue_mutex;
         continue_mutex = nullptr;
      }
   }
   
   void reset()
   {
      client = nullptr;
      rtspConfig.progName = "";
      rtspConfig.rtspURL = "";
      RTSPConfig _rtspConfig;
      rtspConfig = _rtspConfig;
      live_daemon_thid = 0;
      eventLoopWatchVariable = 0;
      live_daemon_running = false;
@@ -58,6 +59,7 @@
      {
         pthread_mutex_destroy(frame_mutex);
         delete frame_mutex;
         frame_mutex = nullptr;
      }
      
      frame_mutex = new pthread_mutex_t;
@@ -67,17 +69,18 @@
      {
         pthread_mutex_destroy(continue_mutex);
         delete continue_mutex;
         continue_mutex = nullptr;
      }
      
      continue_mutex = new pthread_mutex_t;
      pthread_mutex_init(continue_mutex, NULL);
      
      lastBuffer = nullptr;
      lastBuffSize = 0;
      MB_Frame _lastFrame;
      lastFrame = _lastFrame;
   }
};
void* live_daemon_thd(void* arg)
static void* live_daemon_thd(void* arg)
{
   RTSPClient_Internal* in = (RTSPClient_Internal*)arg;
   
@@ -86,7 +89,7 @@
   usage(*env, in->rtspConfig.progName.c_str());
   
   openURL(*env, in->client, in->rtspConfig.progName.c_str(), in->rtspConfig.rtspURL.c_str());
   openURL(*env, in->rtspConfig);
   
   in->live_daemon_running = true;
   env->taskScheduler().doEventLoop(&(in->eventLoopWatchVariable));
@@ -116,8 +119,8 @@
   const RTSPConfig* config = reinterpret_cast<const RTSPConfig*>(args);
   RTSPClient_Internal* in = (RTSPClient_Internal*)internal;
   in->reset();
   in->client = this;
   in->rtspConfig = *config;
   in->rtspConfig.args = this;
   
   int ret = pthread_mutex_lock(in->frame_mutex);
   if(ret != 0)
@@ -175,8 +178,9 @@
      return false;
   }
   
   pm.buffer = in->lastBuffer;
   pm.buffSize = in->lastBuffSize;
   pm.type = PipeMaterial::PMT_FRAME;
   pm.buffer = (uint8_t*)(&(in->lastFrame));
   pm.buffSize = sizeof(in->lastFrame);
   pm.former = this;
   return true;
@@ -208,17 +212,19 @@
   client->manager->set_global_param(PLGP_RTSP_FMTP, val);
}
void rtsp_client_frame_callback(void* arg, uint8_t* buffer, size_t buffSize)
void rtsp_client_frame_callback(void* arg, uint8_t* buffer, size_t buffSize, timeval presentationTime)
{
   if (arg == nullptr || buffer == nullptr || buffSize == 0)
      return;
   PL_RTSPClient* client = (PL_RTSPClient*)arg;
   RTSPClient_Internal* in = (RTSPClient_Internal*)(client->internal);
   in->lastBuffer = buffer;
   in->lastBuffSize = buffSize;
   in->lastFrame.type = MB_Frame::MBFT_H264_NALU;
   in->lastFrame.buffer = buffer;
   in->lastFrame.buffSize = buffSize;
   in->lastFrame.pts = presentationTime;
   int ret = pthread_mutex_unlock(in->frame_mutex);
   if(ret != 0)
   {