From 109ffe9a777658936a38d0c146579a67c60a0d17 Mon Sep 17 00:00:00 2001 From: xuxiuxi <xuxiuxi@454eff88-639b-444f-9e54-f578c98de674> Date: 星期四, 11 五月 2017 17:48:48 +0800 Subject: [PATCH] --- RtspFace/PL_RTSPClient.cpp | 57 +++++++++++++++++++++++++++++++-------------------------- 1 files changed, 31 insertions(+), 26 deletions(-) diff --git a/RtspFace/PL_RTSPClient.cpp b/RtspFace/PL_RTSPClient.cpp index b26b2c1..8290f8a 100644 --- a/RtspFace/PL_RTSPClient.cpp +++ b/RtspFace/PL_RTSPClient.cpp @@ -1,30 +1,31 @@ #include "PL_RTSPClient.h" +#include "MaterialBuffer.h" +#include "logger.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); +//struct PL_RTSPClient_Config; #include "live555/testProgs/testRTSPClient.hpp" struct RTSPClient_Internal { - PL_RTSPClient* client; - RTSPConfig rtspConfig; + PL_RTSPClient_Config rtspConfig; pthread_t live_daemon_thid; char eventLoopWatchVariable; bool live_daemon_running; 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); @@ -49,9 +50,8 @@ void reset() { - client = nullptr; - rtspConfig.progName = ""; - rtspConfig.rtspURL = ""; + PL_RTSPClient_Config _rtspConfig; + rtspConfig = _rtspConfig; live_daemon_thid = 0; eventLoopWatchVariable = 0; live_daemon_running = false; @@ -76,12 +76,12 @@ 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; @@ -90,7 +90,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)); @@ -117,11 +117,11 @@ if (args == nullptr) return false; - const RTSPConfig* config = reinterpret_cast<const RTSPConfig*>(args); + const PL_RTSPClient_Config* config = reinterpret_cast<const PL_RTSPClient_Config*>(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) @@ -179,8 +179,9 @@ return false; } - pm.buffer = in->lastBuffer; - pm.buffSize = in->lastBuffSize; + pm.type = PipeMaterial::PMT_FRAME; + pm.buffer = &(in->lastFrame); + pm.buffSize = 0; pm.former = this; return true; @@ -196,7 +197,7 @@ if (client->manager == nullptr) return; - client->manager->set_global_param(PLGP_RTSP_SDP, val); + client->manager->set_param(PLGP_RTSP_SDP, val); } void rtsp_client_fmtp_callback(void* arg, const char* val) @@ -209,24 +210,28 @@ if (client->manager == nullptr) return; - client->manager->set_global_param(PLGP_RTSP_FMTP, val); + client->manager->set_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.width = 0; + in->lastFrame.height = 0; + in->lastFrame.pts = presentationTime; + int ret = pthread_mutex_unlock(in->frame_mutex); if(ret != 0) { - printf("pthread_mutex_unlock frame_mutex: %s/n", strerror(ret)); + LOG_ERROR << "pthread_mutex_unlock frame_mutex: " << strerror(ret) << std::endl; } } @@ -241,6 +246,6 @@ int ret = pthread_mutex_lock(in->continue_mutex); if(ret != 0) { - printf("pthread_mutex_unlock continue_mutex: %s/n", strerror(ret)); + LOG_ERROR << "pthread_mutex_unlock continue_mutex: " << strerror(ret) << std::endl; } } -- Gitblit v1.8.0