From 5f4935b71a48800ef927d34c822852e4980eeae9 Mon Sep 17 00:00:00 2001 From: Hu Chunming <2657262686@qq.com> Date: Thu, 1 Aug 2024 14:38:29 +0800 Subject: [PATCH] 删除不用的文件 --- build/jrtplib/Makefile | 49 ------------------------------------------------- build/jrtplib/example2.cpp | 92 -------------------------------------------------------------------------------------------- src/decoder/gb28181/DvppGB28181Decoder.cpp0 | 403 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/decoder/gb28181/DvppGB28181Decoder.h | 111 --------------------------------------------------------------------------------------------------------------- src/decoder/gb28181/DvppGB28181Decoder2.cpp | 16 ++++++++-------- src/decoder/gb28181/FFDecoder.cpp0 | 131 ----------------------------------------------------------------------------------------------------------------------------------- src/decoder/gb28181/FFDecoder.h0 | 57 --------------------------------------------------------- src/decoder/gb28181/rtp/Pack_Header_Def.h | 234 ------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------ src/decoder/gb28181/rtp/RTPReceiver.cpp | 374 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/decoder/gb28181/rtp/RTPReceiver.h | 151 ------------------------------------------------------------------------------------------------------------------------------------------------------- src/decoder/gb28181/rtp/RTPTcpReceiver.cpp | 494 -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/decoder/gb28181/rtp/RTPTcpReceiver.h | 79 ------------------------------------------------------------------------------- src/decoder/gb28181/rtp/RTPUdpReceiver.cpp | 298 ---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/decoder/gb28181/rtp/RTPUdpReceiver.h | 62 -------------------------------------------------------------- src/decoder/gb28181/rtp/buffer.h | 91 ------------------------------------------------------------------------------------------- src/decoder/gb28181/rtp/demuxer.cpp | 417 --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- src/decoder/gb28181/rtp/demuxer.h | 87 --------------------------------------------------------------------------------------- 17 files changed, 8 insertions(+), 3138 deletions(-) delete mode 100755 build/jrtplib/Makefile delete mode 100644 build/jrtplib/example2.cpp delete mode 100644 src/decoder/gb28181/DvppGB28181Decoder.cpp0 delete mode 100644 src/decoder/gb28181/DvppGB28181Decoder.h delete mode 100644 src/decoder/gb28181/FFDecoder.cpp0 delete mode 100644 src/decoder/gb28181/FFDecoder.h0 delete mode 100644 src/decoder/gb28181/rtp/Pack_Header_Def.h delete mode 100644 src/decoder/gb28181/rtp/RTPReceiver.cpp delete mode 100644 src/decoder/gb28181/rtp/RTPReceiver.h delete mode 100644 src/decoder/gb28181/rtp/RTPTcpReceiver.cpp delete mode 100644 src/decoder/gb28181/rtp/RTPTcpReceiver.h delete mode 100644 src/decoder/gb28181/rtp/RTPUdpReceiver.cpp delete mode 100644 src/decoder/gb28181/rtp/RTPUdpReceiver.h delete mode 100644 src/decoder/gb28181/rtp/buffer.h delete mode 100644 src/decoder/gb28181/rtp/demuxer.cpp delete mode 100644 src/decoder/gb28181/rtp/demuxer.h diff --git a/build/jrtplib/Makefile b/build/jrtplib/Makefile deleted file mode 100755 index 908a4bc..0000000 --- a/build/jrtplib/Makefile +++ /dev/null @@ -1,49 +0,0 @@ -XX = g++ - - -PROJECT_ROOT= /home/cmhu/vpt_ascend_arm - -DEPEND_DIR = $(PROJECT_ROOT)/bin - -TARGET= $(PROJECT_ROOT)/bin/test_rtp - -DEFS = -DLinux - - -THIRDPARTY_ROOT = $(PROJECT_ROOT)/3rdparty -SPDLOG_ROOT = $(THIRDPARTY_ROOT)/spdlog-1.9.2/release - -GB28181_ROOT = /home/cmhu/vpt_ascend_arm/3rdparty/gb28181_3rd -JRTP_ROOT = $(GB28181_ROOT)/jrtp_export - - -SRC_ROOT = /home/cmhu/vpt_ascend_arm/build/jrtplib - - -INCLUDE=-I $(SPDLOG_ROOT)/include \ - -I $(JRTP_ROOT)/jrtplib/include/jrtplib3 \ - - -LIBS= -L $(SPDLOG_ROOT)/lib -l:libspdlog.a \ - -L $(JRTP_ROOT)/jrtplib/lib -l:libjrtp.a \ - - -CXXFLAGS= -g -O0 -fPIC $(INCLUDE) $(LIBS) $(DEFS) -lpthread -lrt -lz -fexceptions -std=c++11 -D_GLIBCXX_USE_CXX11_ABI=0 -fvisibility=hidden -Wall -Wno-deprecated -Wdeprecated-declarations -Wl,-Bsymbolic -ldl - - - -SRCS:=$(wildcard $(SRC_ROOT)/*.cpp) \ - -OBJS = $(patsubst %.cpp, %.o, $(notdir $(SRCS))) - - -$(TARGET):$(OBJS) - rm -f $(TARGET) - $(XX) -o $@ $^ $(CXXFLAGS) -# rm -f *.o - -%.o:$(SRC_ROOT)/%.cpp - $(XX) $(CXXFLAGS) -c $< - -clean: - rm -f *.o $(TARGET) diff --git a/build/jrtplib/example2.cpp b/build/jrtplib/example2.cpp deleted file mode 100644 index 0fb6edf..0000000 --- a/build/jrtplib/example2.cpp +++ /dev/null @@ -1,92 +0,0 @@ -#include -#include -#include "rtpsessionparams.h" -#include "rtpudpv4transmitter.h" -#include "rtpsession.h" -#include "rtppacket.h" - -#include -#include - -using namespace jrtplib; - - - -int main(void) -{ - int localPort = 30026; - - // RTPSession rtpSession; - RTPSession* rtpSessionPtr = new RTPSession(); - RTPSessionParams SessParams; - RTPUDPv4TransmissionParams TransParams; - SessParams.SetOwnTimestampUnit(1.0/8000.0); // 时间戳:1秒钟8000个样本 - TransParams.SetPortbase(localPort); // 设置本地接收的端口号 - int iErrNum = rtpSessionPtr->Create(SessParams, &TransParams); - if (iErrNum < 0){ - printf( "Create RTP Session error! Reason: %d!\r\n", iErrNum ); - exit(-1); - } - printf( "Create RTP Session OK! Reason: %d!\r\n", iErrNum); - - - bool m_bRtpExit = false; - while (!m_bRtpExit) - { - - rtpSessionPtr->Poll(); - rtpSessionPtr->BeginDataAccess(); - - if (rtpSessionPtr->GotoFirstSourceWithData()) - { - do - { - RTPPacket* packet; - while ((packet = rtpSessionPtr->GetNextPacket()) != NULL) - { - printf("got data \n"); - - rtpSessionPtr->DeletePacket(packet); - } - } while (rtpSessionPtr->GotoNextSourceWithData()); - } - - rtpSessionPtr->EndDataAccess(); - - std::this_thread::sleep_for(std::chrono::milliseconds(10)); - } - - - - - - // // 开始接收数据 - // rtpSessionPtr->BeginDataAccess(); - // if (rtpSessionPtr->GotoFirstSource()) - // { - // do - // { - // RTPPacket *packet; - // while ((packet = rtpSessionPtr->GetNextPacket()) != 0) - // { - - // // 获取接收数据长度 - // unsigned int recvSize = packet->GetPayloadLength(); - // // 获取接收数据 - // unsigned char * recvData = (unsigned char *)packet->GetPayloadData(); - // std::cout << "Got packet with extended sequence number " - // << packet->GetExtendedSequenceNumber() - // << " from SSRC " << packet->GetSSRC() << "; recvSize " << recvSize << "[" << recvData << "]" - // << std::endl; - // // 删除数据包 - // rtpSessionPtr->DeletePacket(packet); - // } - // } while (rtpSessionPtr->GotoNextSource()); - // } - // rtpSessionPtr->EndDataAccess(); - - // rtpSessionPtr->Destroy(); - // rtpSessionPtr->AbortWait(); - - return 0; -} diff --git a/src/decoder/gb28181/DvppGB28181Decoder.cpp0 b/src/decoder/gb28181/DvppGB28181Decoder.cpp0 deleted file mode 100644 index 8d644f4..0000000 --- a/src/decoder/gb28181/DvppGB28181Decoder.cpp0 +++ /dev/null @@ -1,403 +0,0 @@ -//#include "LOG_manager.h" -#include -#include "DvppGB28181Decoder.h" - -extern "C" { - #include "libavutil/avstring.h" - #include "libavformat/avformat.h" - #include "libswscale/swscale.h" -} - -#include"RTPTcpReceiver.h" -#include"RTPUdpReceiver.h" - -#include "common_header.h" - -// #include "../nvdec/FFCuContextManager.h" -// #include "../nvdec/GpuRgbMemory.hpp" -// #include "../nvdec/cuda_kernels.h" - -#define ECLOSED 0 -#define ECLOSING 1 -#define ERUNNING 2 -#define EPAUSE 3 -#define EINITED 4 - -static void RTP_Stream_CallBack(void* userdata, int videoType, char* data, int len, int isKey, uint64_t pts, uint64_t localPts) -{ - DvppGB28181Decoder* decoder = (DvppGB28181Decoder*)userdata; - decoder->stream_callback(videoType, data, len, isKey, pts, localPts); -} - -static void RTP_Stream_End_CallBack(void* userdata) -{ - DvppGB28181Decoder* decoder = (DvppGB28181Decoder*)userdata; - decoder->stream_end_callback(); -} - -DvppGB28181Decoder::DvppGB28181Decoder() { - m_frameSkip = 1; - m_dec_keyframe = false; - m_post_decode_thread = 0; -} - -DvppGB28181Decoder::~DvppGB28181Decoder() -{ - close(); - - // if (m_pAVCodecCtx) { - // avcodec_close(m_pAVCodecCtx); - // avcodec_free_context(&m_pAVCodecCtx); - // } - - m_dec_keyframe = false; - - LOG_INFO("destroy OK--{}", m_dec_name); -} - -void DvppGB28181Decoder::close(){ - - if (m_status == ECLOSED) return; - - m_status = ECLOSING; - - LOG_DEBUG("real decode thread exit success 1--{}", m_dec_name); - - if(nullptr != m_rtpPtr){ - if (m_rtpPtr->IsOpened()) { - m_rtpPtr->Close(); - LOG_DEBUG("real decode thread exit success 2--{}", m_dec_name); - } - - delete m_rtpPtr; - m_rtpPtr = nullptr; - } - - // if (gpu_options) av_dict_free(&gpu_options); - - if (m_post_decode_thread != 0) { - pthread_join(m_post_decode_thread,0); - m_post_decode_thread = 0; - } - - streamDecoder.Close(); - - m_status = ECLOSED; - - LOG_INFO("解码器关闭成功 --{}", m_dec_name); -} - -bool DvppGB28181Decoder::init(FFDecConfig& cfg){ - if(cfg.force_tcp){ - m_rtpPtr = new RTPTcpReceiver(); - }else{ - m_rtpPtr = new RTPUdpReceiver(); - } - if(nullptr == m_rtpPtr){ - return false; - } - - m_dec_name = cfg.dec_name; - m_frameSkip = cfg.skip_frame; - if (m_frameSkip < 1) m_frameSkip = 1; - - m_gpuid = atoi(cfg.gpuid.c_str()); - - m_rtpPtr->SetOutputCallback(RTP_Stream_CallBack, this); - m_rtpPtr->SetVodEndCallback(RTP_Stream_End_CallBack, this); - - post_decoded_cbk = cfg.post_decoded_cbk; - decode_finished_cbk = cfg.decode_finished_cbk; - - if (!streamDecoder.Init(cfg)) { - return false; - } - - m_cfg = cfg; - - LOG_INFO("init - {} ", m_dec_name); - - m_status = EINITED; - - return true; -} - -bool DvppGB28181Decoder::start() { - - m_status = ERUNNING; - - bool bRet = m_rtpPtr->Open(m_cfg.uri); - if(bRet){ - pthread_create(&m_post_decode_thread,0, - [](void* arg) - { - DvppGB28181Decoder* a=(DvppGB28181Decoder*)arg; - a->display_thread(); - return (void*)0; - } - ,this); - - return true; - } - - close(); - - LOG_ERROR("[{}] - rtp receiver open failed !", m_dec_name); - - return bRet; -} - -void DvppGB28181Decoder::setDecKeyframe(bool bKeyframe){ - m_dec_keyframe = bKeyframe; -} - -void DvppGB28181Decoder::stream_callback(int videoType, char* data, int len, int isKey, uint64_t pts, uint64_t localPts) { - if (m_status == EPAUSE) return; - - // 若设置为关键帧解码,非关键帧数据直接返回 - if(m_dec_keyframe && !isKey) return; - - if (len <= 0) { - if (data == nullptr && pts == -1) { - LOG_INFO("frame callback EOF!"); - post_decoded_cbk(m_postDecArg, nullptr); - return ; - } - LOG_INFO("frame data is zero --{}", m_dec_name); - return; - } - - streamDecoder.SendData(videoType, data, len, isKey, pts); - - // AVPacket* pkt = av_packet_alloc(); - // av_init_packet(pkt); - - // pkt->size = len; - // pkt->data = (uint8_t*)data; - - // // ffmpeg 解码 - // ff_decode(videoType, pkt); - - // av_packet_free(&pkt); - // pkt = nullptr; - -} - -int DvppGB28181Decoder::ff_decode(int videoType, AVPacket* pkt) { - - // if (m_pAVCodecCtx == nullptr) { - // LOG_INFO("frame data is zero --{}", m_dec_name); - // if (VIDEO_TYPE_H264 == videoType) { - // if (m_gpuid >= 0){ - // m_pAVCodec = avcodec_find_decoder_by_name("h264_cuvid"); - // } - // else{ - // m_pAVCodec = avcodec_find_decoder(AV_CODEC_ID_H264); - // } - // LOG_INFO("m_avCodecName is H264"); - // } - // else if (VIDEO_TYPE_H265 == videoType) - // { - // if (m_gpuid >= 0){ - // m_pAVCodec = avcodec_find_decoder_by_name("hevc_cuvid"); - // } - // else{ - // m_pAVCodec = avcodec_find_decoder(AV_CODEC_ID_H265); - // } - // LOG_INFO("m_avCodecName is H265"); - // } - // else{ - // LOG_INFO("m_avCodecName is unknown, videoType is {}", videoType); - // } - - // if (!m_pAVCodec) - // { - // LOG_ERROR("frameCallback frame decode error, ERROR_DECODER_NOT_FOUND"); - // return; - // } - - // m_pAVCodecCtx = avcodec_alloc_context3(m_pAVCodec); - - // if (m_gpuid >= 0) { - // char gpui[8] = { 0 }; - // sprintf(gpui, "%d", m_gpuid); - // av_dict_set(&gpu_options, "gpu", gpui, 0); - - // m_pAVCodecCtx->get_format = get_hw_format; - - // FFCuContextManager* pCtxMgr = FFCuContextManager::getInstance(); - // m_pAVCodecCtx->hw_device_ctx = av_buffer_ref(pCtxMgr->getCuCtx(gpui)); - // if (nullptr == m_pAVCodecCtx->hw_device_ctx){ - // // TODO 这里应该抛出错误 - // return ; - // } - // } - - // if (avcodec_open2(m_pAVCodecCtx, m_pAVCodec, &gpu_options) < 0) - // return; - // } - - // //开始解码 - // int ret = avcodec_send_packet(m_pAVCodecCtx, pkt); - // if (ret < 0) { - // //send_exception(RunMessageType::E2002, e_msg); - // LOG_ERROR("Real stream视频解码失败,请检查视频设备{}: avcodec_send_packet failed. ret={}", m_dec_name, ret); - // return; - // } - - // if (frameW < 1) { - // frameW = m_pAVCodecCtx->width; - // frameH = m_pAVCodecCtx->height; - // if (frameW <= 0 || frameH <= 0) { - // LOG_ERROR("[{}] - frame W or H is error! ({},{})", m_dec_name, frameW, frameH); - // return; - // } - // } - - // m_fps = av_q2d(m_pAVCodecCtx->framerate); - - // AVFrame* gpuFrame = av_frame_alloc(); - // ret = avcodec_receive_frame(m_pAVCodecCtx, gpuFrame); - // if ((ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) || ret < 0){ - // LOG_ERROR("[{}] - Failed to receive frame: {}", m_dec_name, ret); - // av_frame_free(&gpuFrame); - // gpuFrame = nullptr; - // return; - // } - - // if (gpuFrame->width != frameW || gpuFrame->height != frameH){ - // LOG_INFO("[{}] - AVFrame is inconsistent: width is {}, height is {}; original frameW is {}, frameH is {}--{}", m_dec_name, gpuFrame->width, gpuFrame->height, frameW, frameH); - // av_frame_free(&gpuFrame); - // gpuFrame = nullptr; - // return; - // } - - // av_frame_free(&gpuFrame); - // gpuFrame = nullptr; -} - -void DvppGB28181Decoder::display_thread(){ - - int index = 0; - while (isRunning()) - { - auto mem = streamDecoder.GetFrame(); - if(mem) { - if ((m_frameSkip == 1 || index % m_frameSkip == 0) && post_decoded_cbk){ - post_decoded_cbk(m_postDecArg, mem); - } else { - delete mem; - mem = nullptr; - } - - index++; - if(index >= 100000){ - index = 0; - } - } - - std::this_thread::sleep_for(std::chrono::milliseconds(10)); - } - - LOG_INFO("[{}] - display thread exited.", m_dec_name); -} - -void DvppGB28181Decoder::stream_end_callback() -{ - LOG_INFO("[{}] - send_video_eof", m_dec_name); - - m_status = ECLOSING; - - decode_finished_cbk(m_finishedDecArg); - - return; -} - -void DvppGB28181Decoder::setPostDecArg(const void* postDecArg){ - m_postDecArg = postDecArg; -} - -void DvppGB28181Decoder::setFinishedDecArg(const void* finishedDecArg){ - m_finishedDecArg = finishedDecArg; -} - -void DvppGB28181Decoder::pause() { - m_status = EPAUSE; - LOG_INFO("[{}] - pause", m_dec_name); -} - -void DvppGB28181Decoder::resume() { - m_status = ERUNNING; - LOG_INFO("[{}] - resume", m_dec_name); -} - -bool DvppGB28181Decoder::isRunning(){ - if (m_status == ECLOSED || m_status == ECLOSING){ - return false; - } - return true; -} - -bool DvppGB28181Decoder::isFinished(){ - if (m_status == ECLOSED || m_status == ECLOSING){ - return true; - } - return false; -} - -bool DvppGB28181Decoder::isPausing(){ - if (m_status == EPAUSE){ - return true; - } - return false; -} - -bool DvppGB28181Decoder::getResolution( int &width, int &height ){ - width = frameW; - height = frameH; - return true; -} - -bool DvppGB28181Decoder::getOutResolution( int &width, int &height ) { - width = frameW; - height = frameH; - return true; -} - -float DvppGB28181Decoder::fps() { - return m_fps; -} - -bool DvppGB28181Decoder::isSurport(FFDecConfig& cfg){ - // 由于是否支持需要在拿到数据后才能断定,无法事先判断,所以这个地方默认返回true - return true; -} - -DeviceMemory* DvppGB28181Decoder::snapshot() { - - DeviceMemory* snapshot_mem = nullptr; - int loop_times = 0; - while (isRunning()) { - snapshot_mem = streamDecoder.GetFrame(); - if (snapshot_mem) { - break; - } - - loop_times++; - if(loop_times > 100) { - // 1s都没截取到图,退出 - break; - } - std::this_thread::sleep_for(std::chrono::milliseconds(10)); - } - - return snapshot_mem; -} - -void DvppGB28181Decoder::doRecode(RecoderInfo& recoderInfo) { - return streamDecoder.doRecode(recoderInfo); -} - -void DvppGB28181Decoder::set_mq_callback(std::function mq_publish) { - streamDecoder.set_mq_callback(mq_publish); -} \ No newline at end of file diff --git a/src/decoder/gb28181/DvppGB28181Decoder.h b/src/decoder/gb28181/DvppGB28181Decoder.h deleted file mode 100644 index c578b18..0000000 --- a/src/decoder/gb28181/DvppGB28181Decoder.h +++ /dev/null @@ -1,111 +0,0 @@ -#ifndef _GB28181_DECODER_H_ -#define _GB28181_DECODER_H_ - -#include -#include - -#include "RTPReceiver.h" -#include "../dvpp/DvppStreamDecoder.h" - -#include "common_header.h" -#include "../interface/AbstractDecoder.h" - - -struct AVFormatContext; -struct AVCodecContext; -struct AVCodec; -struct AVFrame; -struct AVDictionary; -struct AVPacket; - -using namespace std; - -class DvppGB28181Decoder: public AbstractDecoder -{ -public: - DvppGB28181Decoder(); - ~DvppGB28181Decoder(); - - bool init(FFDecConfig& cfg); - void close(); - bool start(); - void pause(); - void resume(); - - void setDecKeyframe(bool bKeyframe); - - bool isRunning(); - bool isFinished(); - bool isPausing(); - bool getResolution( int &width, int &height ); - bool getOutResolution( int &width, int &height ); - - bool isSurport(FFDecConfig& cfg); - - float fps(); - - DECODER_TYPE getDecoderType(){ return DECODER_TYPE_DVPP_GB28181; } - - DeviceMemory* snapshot(); - - void setName(string nm){ - m_dec_name = nm; - } - - string getName(){ - return m_dec_name; - } - - void setPostDecArg(const void* postDecArg); - void setFinishedDecArg(const void* finishedDecArg); - - void doRecode(RecoderInfo& recoderInfo); - - void set_mq_callback(std::function mq_publish); - -public: - void stream_callback(int videoType, char* data, int len, int isKey, uint64_t pts, uint64_t localPts); - void stream_end_callback(); - void display_thread(); - -private: - int ff_decode(int videoType, AVPacket* pkt); - -private: - string m_dec_name; // 必须为28181编码 - FFDecConfig m_cfg; - - RTPReceiver* m_rtpPtr {nullptr}; - - uint64_t m_startPts {}; - uint64_t m_lastPts {}; //上一次pts的值 - uint64_t m_curPts {}; //当前的pts值 - uint64_t m_diffPts {}; - - uint32_t frameW {}, frameH {}; - float m_fps {}; - int m_frameSkip {}; - - int log_count {}; - - std::atomic_int m_status {}; - - pthread_t m_post_decode_thread; - const void * m_postDecArg; - POST_DECODE_CALLBACK post_decoded_cbk; // 解码数据回调接口 - - const void * m_finishedDecArg; - DECODE_FINISHED_CALLBACK decode_finished_cbk; - - queue mFrameQueue; - mutex m_queue_mutex; - mutex m_snapshot_mutex; - - bool m_dec_keyframe; - - DvppStreamDecoder streamDecoder; - - int m_gpuid {0}; -}; - -#endif // _GB28181_DECODER_H_ diff --git a/src/decoder/gb28181/DvppGB28181Decoder2.cpp b/src/decoder/gb28181/DvppGB28181Decoder2.cpp index 37ada89..95713d4 100644 --- a/src/decoder/gb28181/DvppGB28181Decoder2.cpp +++ b/src/decoder/gb28181/DvppGB28181Decoder2.cpp @@ -46,22 +46,20 @@ void DvppGB28181Decoder2::close(){ LOG_DEBUG("real decode thread exit success 1--{}", m_dec_name); if(nullptr != m_rtpPtr){ - if (m_rtpPtr->IsOpened()) { - m_rtpPtr->Close(); - LOG_DEBUG("real decode thread exit success 2--{}", m_dec_name); - } + m_rtpPtr->Close(); + LOG_DEBUG("real decode thread exit success 2--{}", m_dec_name); delete m_rtpPtr; m_rtpPtr = nullptr; } + rtpDecoder.Close(); + if (m_post_decode_thread != 0) { pthread_join(m_post_decode_thread,0); m_post_decode_thread = 0; } - rtpDecoder.Close(); - m_status = ECLOSED; LOG_INFO("解码器关闭成功 --{}", m_dec_name); @@ -90,6 +88,8 @@ bool DvppGB28181Decoder2::init(FFDecConfig& cfg){ return false; } + rtpDecoder.SetFinishedCallback(RTP_Stream_End_CallBack, this); + m_cfg = cfg; LOG_INFO("init - {} ", m_dec_name); @@ -160,6 +160,8 @@ void DvppGB28181Decoder2::display_thread(){ std::this_thread::sleep_for(std::chrono::milliseconds(10)); } + decode_finished_cbk(m_finishedDecArg); + LOG_INFO("[{}] - display thread exited.", m_dec_name); } @@ -169,8 +171,6 @@ void DvppGB28181Decoder2::stream_end_callback() m_status = ECLOSING; - decode_finished_cbk(m_finishedDecArg); - return; } diff --git a/src/decoder/gb28181/FFDecoder.cpp0 b/src/decoder/gb28181/FFDecoder.cpp0 deleted file mode 100644 index 743139d..0000000 --- a/src/decoder/gb28181/FFDecoder.cpp0 +++ /dev/null @@ -1,131 +0,0 @@ -#include "FFDecoder.h" - -#include "./rtp/demuxer.h" - -#include "common_header.h" -#include "../nvdec/FFCuContextManager.h" - -static AVPixelFormat get_hw_format(AVCodecContext *avctx, const AVPixelFormat *pix_fmts){ - return AV_PIX_FMT_CUDA; -} - -FFDecoder::FFDecoder(/* args */) -{ -} - -FFDecoder::~FFDecoder() -{ -} - -FrameData* FFDecoder::Decode(int videoType, char* data, int len, int isKey, uint64_t pts) { - - AVPacket* pkt = av_packet_alloc(); - av_init_packet(pkt); - - pkt->size = len; - pkt->data = (uint8_t*)data; - - // ffmpeg 解码 - FrameData* frame_data = ff_decode(videoType, pkt); - - av_packet_free(&pkt); - pkt = nullptr; - - frame_data.bKeyframe = (isKey != 0); - frame_data.pts = pts; - - return frame_data; -} - -FrameData* FFDecoder::ff_decode(int videoType, AVPacket* pkt) { - if (m_pAVCodecCtx == nullptr) { - LOG_INFO("frame data is zero --{}", m_dec_name); - if (VIDEO_TYPE_H264 == videoType) { - if (m_devid >= 0){ - m_pAVCodec = avcodec_find_decoder_by_name("h264_cuvid"); - } - else{ - m_pAVCodec = avcodec_find_decoder(AV_CODEC_ID_H264); - } - LOG_INFO("m_avCodecName is H264"); - } - else if (VIDEO_TYPE_H265 == videoType) - { - if (m_devid >= 0){ - m_pAVCodec = avcodec_find_decoder_by_name("hevc_cuvid"); - } - else{ - m_pAVCodec = avcodec_find_decoder(AV_CODEC_ID_H265); - } - LOG_INFO("m_avCodecName is H265"); - } - else{ - LOG_INFO("m_avCodecName is unknown, videoType is {}", videoType); - } - - if (!m_pAVCodec) - { - LOG_ERROR("frameCallback frame decode error, ERROR_DECODER_NOT_FOUND"); - return nullptr;return; - } - - m_pAVCodecCtx = avcodec_alloc_context3(m_pAVCodec); - - if (m_devid >= 0) { - char gpui[8] = { 0 }; - sprintf(gpui, "%d", m_devid); - av_dict_set(&gpu_options, "gpu", gpui, 0); - - m_pAVCodecCtx->get_format = get_hw_format; - - FFCuContextManager* pCtxMgr = FFCuContextManager::getInstance(); - m_pAVCodecCtx->hw_device_ctx = av_buffer_ref(pCtxMgr->getCuCtx(gpui)); - if (nullptr == m_pAVCodecCtx->hw_device_ctx){ - // TODO 这里应该抛出错误 - return nullptr; - } - } - - if (avcodec_open2(m_pAVCodecCtx, m_pAVCodec, &gpu_options) < 0) - return nullptr; - } - - //开始解码 - int ret = avcodec_send_packet(m_pAVCodecCtx, pkt); - if (ret < 0) { - //send_exception(RunMessageType::E2002, e_msg); - LOG_ERROR("Real stream视频解码失败,请检查视频设备{}: avcodec_send_packet failed. ret={}", m_dec_name, ret); - return; - } - - if (frameW < 1) { - frameW = m_pAVCodecCtx->width; - frameH = m_pAVCodecCtx->height; - if (frameW <= 0 || frameH <= 0) { - LOG_ERROR("[{}] frame W or H is error! ({},{})", m_dec_name, frameW, frameH); - return nullptr; - } - } - // m_fps = m_pAVCodecCtx->pkt_timebase.den == 0 ? 25.0 : av_q2d(m_pAVCodecCtx->pkt_timebase); - m_fps = av_q2d(m_pAVCodecCtx->framerate); - // LOG_DEBUG("frameW {}--frameH {}", frameW, frameH); - - FrameData* pData = new FrameData(); - ret = avcodec_receive_frame(m_pAVCodecCtx, pData->frame); - if ((ret == AVERROR(EAGAIN) || ret == AVERROR_EOF) || ret < 0){ - LOG_ERROR("{} - Failed to receive frame: {}", m_dec_name, ret); - delete pData; - pData = nullptr; - return nullptr; - } - - AVFrame* gpuFrame = pData->frame; - if (gpuFrame->width != frameW || gpuFrame->height != frameH){ - LOG_INFO("AVFrame is inconsistent: width is {}, height is {}; original frameW is {}, frameH is {}--{}", gpuFrame->width, gpuFrame->height, frameW, frameH , m_dec_name); - delete pData; - pData = nullptr; - return nullptr; - } - - return pData; -} \ No newline at end of file diff --git a/src/decoder/gb28181/FFDecoder.h0 b/src/decoder/gb28181/FFDecoder.h0 deleted file mode 100644 index b289007..0000000 --- a/src/decoder/gb28181/FFDecoder.h0 +++ /dev/null @@ -1,57 +0,0 @@ -#ifndef __FF_DECODER_H__ -#define __FF_DECODER_H__ - -#include "../interface/interface_headers.h" - -extern "C" { - #include "libavutil/avstring.h" - #include "libavformat/avformat.h" - #include "libswscale/swscale.h" -} - -struct FrameData { - AVFrame* frame {nullptr}; - unsigned long pts {0}; - bool bKeyframe {false}; - - FrameData() { - frame = av_frame_alloc(); - } - - ~FrameData() { - if (frame) { - av_frame_free(&frame); - frame = nullptr; - } - } -}; - -class FFDecoder -{ -public: - FFDecoder(/* args */); - ~FFDecoder(); - - FrameData* Decode(int videoType, char* data, int len, int isKey, uint64_t pts); - -private: - FrameData* ff_decode(int videoType, AVPacket* pkt); - -private: - string m_dec_name; - - AVDictionary *gpu_options {nullptr}; - AVCodecContext* m_pAVCodecCtx {nullptr}; - const AVCodec* m_pAVCodec {nullptr}; - - int m_devid {-1}; - - int frameW {-1}; - int frameH {-1}; - float m_fps {0.0}; -}; - - - - -#endif // __FF_DECODER_H__ \ No newline at end of file diff --git a/src/decoder/gb28181/rtp/Pack_Header_Def.h b/src/decoder/gb28181/rtp/Pack_Header_Def.h deleted file mode 100644 index 757b55a..0000000 --- a/src/decoder/gb28181/rtp/Pack_Header_Def.h +++ /dev/null @@ -1,234 +0,0 @@ -/* -writer:Kevin.liu -Date:2010-08-06 -*/ -#ifndef __HEADER_PACK_HEADER_DEF_H__ -#define __HEADER_PACK_HEADER_DEF_H__ - -#include - -typedef struct PS_HEADER_tag -{ - unsigned char pack_start_code[4]; //'0x000001BA' - - unsigned char system_clock_reference_base21:2; - unsigned char marker_bit:1; - unsigned char system_clock_reference_base1:3; - unsigned char fix_bit:2; //'01' - - unsigned char system_clock_reference_base22; - - unsigned char system_clock_reference_base31:2; - unsigned char marker_bit1:1; - unsigned char system_clock_reference_base23:5; - - unsigned char system_clock_reference_base32; - - unsigned char system_clock_reference_extension1:2; - unsigned char marker_bit2:1; - unsigned char system_clock_reference_base33:5; //system_clock_reference_base 33bit - - unsigned char marker_bit3:1; - unsigned char system_clock_reference_extension2:7; //system_clock_reference_extension 9bit - - unsigned char program_mux_rate1; - - unsigned char program_mux_rate2; - - unsigned char marker_bit5:1; - unsigned char marker_bit4:1; - unsigned char program_mux_rate3:6; - - unsigned char pack_stuffing_length:3; - unsigned char reserved:5; - - PS_HEADER_tag() - { - pack_start_code[0] = 0x00; - pack_start_code[1] = 0x00; - pack_start_code[2] = 0x01; - pack_start_code[3] = 0xBA; - fix_bit = 0x01; - marker_bit = 0x01; - marker_bit1 = 0x01; - marker_bit2 = 0x01; - marker_bit3 = 0x01; - marker_bit4 = 0x01; - marker_bit5 = 0x01; - reserved = 0x1F; - pack_stuffing_length = 0x00; - system_clock_reference_extension1 = 0; - system_clock_reference_extension2 = 0; - } - - void getSystem_clock_reference_base(uint64_t &_ui64SCR) - { - _ui64SCR = (system_clock_reference_base1 << 30) | (system_clock_reference_base21 << 28) - | (system_clock_reference_base22 << 20) | (system_clock_reference_base23 << 15) - | (system_clock_reference_base31 << 13) | (system_clock_reference_base32 << 5) - | (system_clock_reference_base33); - - } - - void setSystem_clock_reference_base(uint64_t _ui64SCR) - { - system_clock_reference_base1 = (_ui64SCR >> 30) & 0x07; - system_clock_reference_base21 = (_ui64SCR >> 28) & 0x03; - system_clock_reference_base22 = (_ui64SCR >> 20) & 0xFF; - system_clock_reference_base23 = (_ui64SCR >> 15) & 0x1F; - system_clock_reference_base31 = (_ui64SCR >> 13) & 0x03; - system_clock_reference_base32 = (_ui64SCR >> 5) & 0xFF; - system_clock_reference_base33 = _ui64SCR & 0x1F; - } - - void getProgram_mux_rate(unsigned int &_uiMux_rate) - { - _uiMux_rate = (program_mux_rate1 << 14) | (program_mux_rate2 << 6) | program_mux_rate3; - } - - void setProgram_mux_rate(unsigned int _uiMux_rate) - { - program_mux_rate1 = (_uiMux_rate >> 14) & 0xFF; - program_mux_rate2 = (_uiMux_rate >> 6) & 0xFF; - program_mux_rate3 = _uiMux_rate & 0x3F; - } - -}*pPS_HEADER_tag; - -typedef struct PES_HEADER_tag -{ - unsigned char packet_start_code_prefix[3]; - unsigned char stream_id; - unsigned char PES_packet_length[2]; - - unsigned char original_or_copy:1; - unsigned char copyright:1; - unsigned char data_alignment_indicator:1; - unsigned char PES_priority:1; - unsigned char PES_scrambling_control:2; - unsigned char fix_bit:2; - - unsigned char PES_extension_flag:1; - unsigned char PES_CRC_flag:1; - unsigned char additional_copy_info_flag:1; - unsigned char DSM_trick_mode_flag:1; - unsigned char ES_rate_flag:1; - unsigned char ESCR_flag:1; - unsigned char PTS_DTS_flags:2; - - unsigned char PES_header_data_length; - - PES_HEADER_tag() - { - packet_start_code_prefix[0] = 0x00; - packet_start_code_prefix[1] = 0x00; - packet_start_code_prefix[2] = 0x01; - - PES_packet_length[0] = 0x00; - PES_packet_length[1] = 0x00; - - stream_id = 0xE0; - fix_bit = 0x02; - } - -}*pPES_HEADER_tag; - -typedef struct PTS_tag -{ - unsigned char marker_bit:1; - unsigned char PTS1:3; - unsigned char fix_bit:4; - - unsigned char PTS21; - - unsigned char marker_bit1:1; - unsigned char PTS22:7; - - unsigned char PTS31; - - unsigned char marker_bit2:1; - unsigned char PTS32:7; - - PTS_tag() - { - fix_bit = 0x02; - marker_bit = 0x01; - marker_bit1 = 0x01; - marker_bit2 = 0x01; - } - - void getPTS(uint64_t &_ui64PTS) - { - _ui64PTS = (PTS1 << 30) | (PTS21 << 22) - | (PTS22 << 15) | (PTS31 << 7) | (PTS32); - - } - - void setPTS(uint64_t _ui64PTS) - { - PTS1 = (_ui64PTS >> 30) & 0x07; - PTS21 = (_ui64PTS >> 22) & 0xFF; - PTS22 = (_ui64PTS >> 15) & 0x7F; - PTS31 = (_ui64PTS >> 7) & 0xFF; - PTS32 = _ui64PTS & 0x7F; - } -}*pPTS_tag; - -typedef struct PSM_tag -{ - unsigned char packet_start_code_prefix[3]; - unsigned char map_stream_id; - unsigned char program_stream_map_length[2]; - - unsigned char program_stream_map_version:5; - unsigned char reserved1:2; - unsigned char current_next_indicator:1; - - unsigned char marker_bit:1; - unsigned char reserved2:7; - - unsigned char program_stream_info_length[2]; - unsigned char elementary_stream_map_length[2]; - unsigned char stream_type; - unsigned char elementary_stream_id; - unsigned char elementary_stream_info_length[2]; - unsigned char CRC_32[4]; - - PSM_tag() - { - packet_start_code_prefix[0] = 0x00; - packet_start_code_prefix[1] = 0x00; - packet_start_code_prefix[2] = 0x01; - - map_stream_id = 0xBC; - program_stream_map_length[0] = 0x00; - program_stream_map_length[1] = 0x0E; - - program_stream_map_version = 0x00; - current_next_indicator = 0x01; - reserved1 = 0x03; - program_stream_map_version = 0x00; - - reserved2 = 0x7F; - marker_bit = 0x01; - - program_stream_info_length[0] = 0x00; - program_stream_info_length[1] = 0x00; - - elementary_stream_map_length[0] = 0x00; - elementary_stream_map_length[1] = 0x04; - - stream_type = 0x1B; - elementary_stream_id = 0xE0; - - elementary_stream_info_length[0] = 0x00; - elementary_stream_info_length[1] = 0x00; - - CRC_32[3] = 0x45; - CRC_32[2] = 0xBD; - CRC_32[1] = 0xDC; - CRC_32[0] = 0xF4; - } -}*pPSM_tag; - -#endif \ No newline at end of file diff --git a/src/decoder/gb28181/rtp/RTPReceiver.cpp b/src/decoder/gb28181/rtp/RTPReceiver.cpp deleted file mode 100644 index ea00b6d..0000000 --- a/src/decoder/gb28181/rtp/RTPReceiver.cpp +++ /dev/null @@ -1,374 +0,0 @@ -#include "RTPReceiver.h" -#include "rtppacket.h" -#include - -#include "../common_header.h" -#include "../websocket/WebsocketClient.h" - -#ifdef __linux__ -#include "arpa/inet.h" -#endif - -#define BUFFERSIZE_1024 1024 - -const int kVideoFrameSize = BUFFERSIZE_1024*BUFFERSIZE_1024*5*2; - -// PS解包器回调 -static int ReceivePESFunction(unsigned char streamid, void * data, int size, uint64_t pts, uint64_t localPts, bool key, void* param) -{ - if (NULL != data && size > 0) - { - ((RTPReceiver*)param)->OnPsDemux(streamid, (BYTE*)data, size, key, (uint64_t)pts, (uint64_t)localPts); - } - return 0; -} - -static int ps_demuxer_thread_(void* param) -{ - if (!param) - { - return -1; - } - - RTPReceiver* self = (RTPReceiver*)param; - return self->OnPsProcess(); -} - -RTPReceiver::RTPReceiver() -:m_LastPTS(-1) -, m_LastIsKeyFrame(0) -, m_SliceBuf(1024*1024) -, m_h264DataFunc(NULL) -, m_hVodEndFunc(NULL) -, m_usrParam(NULL) -, m_bPsExit(false) -, m_psThreadPtr(nullptr) -{ - m_LastStreamType = 0; - recvTmpBuf = new BYTE[kVideoFrameSize]; -} - -RTPReceiver::~RTPReceiver(){ - if(recvTmpBuf != nullptr){ - delete[] recvTmpBuf; - } - - WebsocketClient* pClient = WebsocketClient::getInstance(); - if (pClient){ - pClient->DeleteReceiverPair(m_SipChannelId, m_rtp_port); - } -} - -void RTPReceiver::SetOutputCallback(CallBack_Stream cb, void* param) -{ - m_h264DataFunc = cb; - m_usrParam = param; -} - -void RTPReceiver::SetVodEndCallback(CallBack_VodFileEnd cb, void* param) -{ - m_hVodEndFunc = cb; - m_usrParam = param; -} - -void RTPReceiver::SetRequestStreamCallback(CallBack_Request_Stream cb){ - m_callback_request_stream = cb; -} - -int RTPReceiver::InitPS(){ - - m_psParser.SetReceiveFunction(ReceivePESFunction, this); - - m_psThreadPtr = new std::thread(ps_demuxer_thread_, this); - if(nullptr == m_psThreadPtr){ - return -1; - } - - LOG_INFO("[{}] InitPS successed", m_SipChannelId); - - return 0; -} - -void RTPReceiver::ClosePsThread(){ - LOG_INFO("[{}] 3.", m_SipChannelId); - m_bPsExit = true; - // PS解包线程退出 - if (m_psThreadPtr && m_psThreadPtr->joinable()) - { - m_psThreadPtr->join(); - delete m_psThreadPtr; - m_psThreadPtr = nullptr; - } - - LOG_INFO("[{}] ps demux thread quit", m_SipChannelId); -} - -// 处理去除了PS头的数据 -// 下级厂商发过来的流有可能是MPEG-4/H264/SVAC中的任意一种 -// 国标标准规定, 编码方(下级)可以选择实现H264、MPEG4或者SVAC, 但解码方(上级) -// 必须同时实现对H264、MPEG4和SVAC的支持 -void RTPReceiver::OnPsDemux(unsigned char streamId, BYTE *data, int len, bool key, uint64_t pts, uint64_t localPts) -{ - if (!m_h264DataFunc) - { - return; - } - - if (-1 == m_LastPTS) - { - if (!key) - { - return; - } - m_LastPTS = pts; - m_LastIsKeyFrame = key; - m_LastStreamType = streamId; - } - - // 音频数据不处理 - if (0xC0 == streamId) - { - return; - } - - ////add by mds 20190424 - //if (m_notToDecodCount > 50000)//针对大华相机,可能会很久不调用解码 - //{ - // byte_buffer bb(64); - // bb << ERROR_REALSTREAM_INTERRUPT << "This session have a long time no decoding"; - // LOG_INFO("[{}] Long time no decoding!!!m_notToDecodCount=[{}]", m_SipChannelId, m_notToDecodCount); - // - // if (m_usrParam) - // { - // if (((VideoSession *)GetUsrParam())->msgChan()->is_valid()) - // ((VideoSession *)GetUsrParam())->msgChan()->send_msg(bb.data_ptr(), bb.data_size()); - - // //通知网关关闭句柄 - // if(!((VideoSession *)GetUsrParam())->streamHandle().empty()) - // { - // LOG_INFO("[{}] ---->Notify hisense gateway release handle = {} !<----", m_SipChannelId, ((VideoSession *)GetUsrParam())->streamHandle()); - - // if (((VideoSession *)GetUsrParam())->video_type() == EREAL) - // real_stream_stop(((VideoSession *)GetUsrParam())->streamHandle()); - // - // if (((VideoSession *)GetUsrParam())->video_type() == ERECORD) - // record_stream_stop(((VideoSession *)GetUsrParam())->streamHandle()); - // - // ((VideoSession *)GetUsrParam())->streamHandle().clear(); - // } - // - // m_hVodEndFunc(m_usrParam); - // } - // - // bb.bset(0); - // return; - //} - - if (m_LastPTS != pts) - { - int stream_type = 0; - if (VIDEO_TYPE_H264 == streamId) { - stream_type = 0; - } else if(VIDEO_TYPE_H265 == streamId) { - stream_type = 1; - } else { - LOG_ERROR("[{}] - video type not support!", m_SipChannelId); - } - - - m_notToDecodCount = 0; - m_h264DataFunc(m_usrParam, stream_type, (char *)m_SliceBuf.head(), m_SliceBuf.len(), m_LastIsKeyFrame, m_LastPTS, localPts); - - m_SliceBuf.reset(); - - m_LastPTS = pts; - m_LastIsKeyFrame = key; - m_LastStreamType = streamId; - } - - m_notToDecodCount++; - m_SliceBuf.add((char*)data, len); -} - -// 解PS包线程 -int RTPReceiver::OnPsProcess() -{ - LOG_INFO("[{}] started.", m_SipChannelId); - while (!m_bPsExit) { - m_psFrameMutex.lock(); - // LOG_DEBUG("[{}] PS frame size : {}", m_SipChannelId, m_psVideoFrames.size()); - if (m_psVideoFrames.size() <= 0){ - m_psFrameMutex.unlock(); - std::this_thread::sleep_for(std::chrono::milliseconds(10)); - continue; - } - Frame* frame = m_psVideoFrames.front(); - m_psVideoFrames.pop(); - m_psFrameMutex.unlock(); - if (frame != nullptr) - { - int nRet = m_psParser.AddData(frame->buf_, frame->len_); - if (nRet == -1) - { - LOG_INFO("m_psParser return -1--{}", m_SipChannelId); - } - else if (nRet == -2) - { - LOG_INFO("m_psParser return -2--{}", m_SipChannelId); - } - else if (nRet == -3) - { - LOG_INFO("m_psParser return -3--{}", m_SipChannelId); - } - - delete frame; - frame = nullptr; - } - } - - ClearPsVideoFrameList(); - - m_hVodEndFunc(m_usrParam); - - LOG_INFO("[{}] exited.", m_SipChannelId); - - return 0; -} - -int RTPReceiver::GetPsFrameListSize() -{ - std::lock_guard l(m_psFrameMutex); - return m_psVideoFrames.size(); -} - -void RTPReceiver::ClearPsVideoFrameList() -{ - std::lock_guard l(m_psFrameMutex); - while (!m_psVideoFrames.empty()) { - Frame* f = m_psVideoFrames.front(); - delete f; - m_psVideoFrames.pop(); - } - LOG_INFO("[{}] cleared ps video frame list!", m_SipChannelId); -} - -int RTPReceiver::ParsePacket(RTPPacket* packet){ - do { - - if (0 == packet->GetPayloadType()) - { - // 音频数据, 暂不处理 - break; - } - - // 判断是否收到完整的帧(有些厂商打的marker标记不准, 所以只能看时间戳来判断) - uint32_t curPts = packet->GetTimestamp(); - if (lastPts != 0 && curPts != lastPts) { - mark = 1; - } - lastPts = curPts; - - int payloadLen = packet->GetPayloadLength(); - if (offset + payloadLen > kVideoFrameSize) - { - offset = 0, mark = 0; - break; - } - - // LOG_DEBUG("[{}] ParsePacket GetPayloadLength", m_SipChannelId); - - if (mark) - { - BYTE* frameBuf = (BYTE*)malloc(sizeof(BYTE) * offset); - if (!frameBuf) { - offset = 0, mark = 0; - break; - } - memcpy(frameBuf, recvTmpBuf, offset); - if (!m_bPsExit){ - std::lock_guard l(m_psFrameMutex); - if (m_psVideoFrames.size() < 100) - { - // LOG_DEBUG("[{}]ParsePacket push", m_SipChannelId); - m_psVideoFrames.push(new Frame(frameBuf, offset, false)); - } - else { - free(frameBuf); - } - } - else{ - //若此时解码线程已经退出,不再往m_psVideoFrames推送帧,且退出当前线程 - free(frameBuf); - LOG_INFO("ParsePacket quit, device_id:{}", m_SipChannelId); - return 1; - } - offset = 0; - mark = 0; - } - - memcpy(recvTmpBuf + offset, packet->GetPayloadData(), payloadLen); - offset += payloadLen; - } while (0); - - return 0; -} - -int RTPReceiver::allocRtpPort() { - - WebsocketClient* pServer = WebsocketClient::getInstance(); - int MIN_RTP_PORT = pServer->GetMinRtpPort() ; - int MAX_RTP_PORT = pServer->GetMaxRtpPort(); - - int s_rtpPort = MIN_RTP_PORT; - - srand((unsigned int)time(NULL)); - s_rtpPort = MIN_RTP_PORT + (rand() % MIN_RTP_PORT); - - if (s_rtpPort % 2) - ++s_rtpPort; - - int count = 0; - - while (true) - { - if (s_rtpPort >= MAX_RTP_PORT) { - s_rtpPort = MIN_RTP_PORT; - count ++; - if (count > 1) { - LOG_ERROR("[{}] - 范围内没有可用的port", m_SipChannelId); - } - } - - int i = 0; - for (; i < 2; i++) { - sockaddr_in sRecvAddr; - int s = socket(AF_INET, SOCK_DGRAM, 0); - - sRecvAddr.sin_family = AF_INET; - sRecvAddr.sin_addr.s_addr = htonl(INADDR_ANY); - sRecvAddr.sin_port = htons(s_rtpPort + i); - - int nResult = bind(s, (sockaddr *)&sRecvAddr, sizeof(sRecvAddr)); - if (nResult != 0) { - break; - } - - nResult = close(s); - if (nResult != 0) { - LOG_ERROR("[{}] - closesocket failed : {}", m_SipChannelId, nResult); - break; - } - } - - if (i == 2) - break; - - s_rtpPort += 2; - } - - return s_rtpPort; -} - -void RTPReceiver::RequestStreamFailed() { - m_bRtpExit = true; -} \ No newline at end of file diff --git a/src/decoder/gb28181/rtp/RTPReceiver.h b/src/decoder/gb28181/rtp/RTPReceiver.h deleted file mode 100644 index d7c5c8f..0000000 --- a/src/decoder/gb28181/rtp/RTPReceiver.h +++ /dev/null @@ -1,151 +0,0 @@ -#ifndef _RTP_RECEIVER_H_ -#define _RTP_RECEIVER_H_ - -#include "buffer.h" -#include "demuxer.h" -#include "rtppacket.h" -#include -#include -#include -#include -#include - -typedef unsigned char BYTE; - -using namespace jrtplib; -using namespace std; - -/** 视频数据回调 -* -* @param videoType [in] 视频类型 音频-0xC0、h264-0x1B、MPEG4-0x01、SVAC-0x80 -* @param data [in] 视频数据 -* @param len [in] 视频数据长度 -* @param isKey [in] 是否为关键帧 -* @param pts [in] 时间戳 -*/ -typedef void(*CallBack_Stream)(void* userdata, int videoType, char* data, int len, int isKey, uint64_t pts, uint64_t localPts); - -/** 录像回放完成回调消息通知 -*/ -typedef void(*CallBack_VodFileEnd)(void* userdata); - -/** - * 请求流 -*/ -typedef bool(*CallBack_Request_Stream)(const char* deviceId, int rtp_port); - -// 标识帧, 注意buffer需要自己开辟和释放 -struct Frame { - Frame() { buf_ = NULL; len_ = 0; } - ~Frame() { - if (buf_ != nullptr) - { - free(buf_); - buf_ = nullptr; - } - } - Frame(BYTE* buf, int len, bool key) : buf_(buf), len_(len), key_(key) {} - BYTE* buf_; - int len_; - bool key_{}; -}; - -class FrameToDecode -{ -public: - FrameToDecode() - : m_SliceBuf(0) - , m_localPts(0) - , m_LastPTS(-1) - , m_LastIsKeyFrame(0) {} - FrameToDecode(unsigned char m_streamId) - : m_SliceBuf(0) - , m_localPts(0) - , m_LastPTS(-1) - , m_LastIsKeyFrame(0) - , m_streamId (m_streamId) {} - - void operator=(FrameToDecode &temp) - { - m_SliceBuf = temp.m_SliceBuf; - m_streamId = temp.m_streamId; - m_localPts = temp.m_localPts; - m_LastPTS = temp.m_LastPTS; - m_LastIsKeyFrame = temp.m_LastIsKeyFrame; - } - - CBuffer m_SliceBuf; - unsigned char m_streamId{}; - uint64_t m_localPts; - uint64_t m_LastPTS; - bool m_LastIsKeyFrame; -}; - -class RTPReceiver{ - -public: - RTPReceiver(); - virtual ~RTPReceiver(); - - virtual bool Open(string channel_id) = 0; - virtual bool IsOpened() = 0; - virtual void Close() = 0; - virtual bool RequestStream() = 0; - - void SetVodEndCallback(CallBack_VodFileEnd cb, void* param); - - void SetOutputCallback(CallBack_Stream cb, void* param); - - void SetRequestStreamCallback(CallBack_Request_Stream cb); - - int GetPsFrameListSize(); - - int allocRtpPort(); - - void RequestStreamFailed(); - -public: - void OnPsDemux(unsigned char streamId, BYTE *data, int len, bool key, uint64_t pts, uint64_t localPts); - int OnPsProcess(); - void ClearPsVideoFrameList(); - int ParsePacket(RTPPacket* packet); - -public: - int InitPS(); - void ClosePsThread(); - void *GetUsrParam(){ return m_usrParam; } - -public: - CBuffer m_SliceBuf; - uint64_t m_LastPTS; - bool m_LastIsKeyFrame; - unsigned char m_LastStreamType; - - int64_t m_notToDecodCount{0};//线程计数,用来代表多长时间没有调用解码回调,针对大华相机 - - void* m_usrParam; - CallBack_Stream m_h264DataFunc; // 视频流回调 - - std::queue m_psVideoFrames; - mutex m_psFrameMutex; - - string m_SipChannelId; - int m_rtp_port{-1}; - - CMpeg2Demux m_psParser; - std::atomic_bool m_bPsExit; // 标识PS解包线程关闭 - std::atomic_bool m_bRtpExit; // RTP收包线程结束开关 - - uint32_t lastPts{0}; - uint64_t last_recv_ts{0}; - int offset{0}; - int mark{0}; - BYTE* recvTmpBuf{nullptr}; - - std::thread* m_psThreadPtr{nullptr}; // PS解包线程 - - CallBack_VodFileEnd m_hVodEndFunc; // 录像流结束回调 - CallBack_Request_Stream m_callback_request_stream; //请求流回调 -}; - -#endif // _RTP_RECEIVER_H_ \ No newline at end of file diff --git a/src/decoder/gb28181/rtp/RTPTcpReceiver.cpp b/src/decoder/gb28181/rtp/RTPTcpReceiver.cpp deleted file mode 100644 index 4d101ef..0000000 --- a/src/decoder/gb28181/rtp/RTPTcpReceiver.cpp +++ /dev/null @@ -1,494 +0,0 @@ -#include"RTPTcpReceiver.h" - -#include "../common_header.h" -#include "../websocket/WebsocketClient.h" - - -// class TcpRTPSession : public RTPSession -// { -// public: -// void setReceiver(RTPTcpReceiver* r){ -// tcpReceiver = r; -// } - -// protected: -// void OnValidatedRTPPacket(RTPSourceData *srcdat, RTPPacket *rtppack, bool isonprobation, bool *ispackethandled) -// { -// // printf("SSRC %x Got packet (%d bytes) in OnValidatedRTPPacket from source 0x%04x!\n", GetLocalSSRC(), -// // (int)rtppack->GetPayloadLength(), srcdat->GetSSRC()); - -// LOG_DEBUG("SSRC {} Got packet ({} bytes) in OnValidatedRTPPacket from source {}}!\n", GetLocalSSRC(), -// (int)rtppack->GetPayloadLength(), srcdat->GetSSRC()); - -// if(nullptr != tcpReceiver){ -// tcpReceiver->ParsePacket(rtppack); -// } -// DeletePacket(rtppack); -// *ispackethandled = true; -// } - -// void OnRTCPSDESItem(RTPSourceData *srcdat, RTCPSDESPacket::ItemType t, const void *itemdata, size_t itemlength) -// { -// char msg[1024]; - -// memset(msg, 0, sizeof(msg)); -// if (itemlength >= sizeof(msg)) -// itemlength = sizeof(msg)-1; - -// memcpy(msg, itemdata, itemlength); -// // printf("SSRC %x Received SDES item (%d): %s from SSRC %x\n", GetLocalSSRC(), (int)t, msg, srcdat->GetSSRC()); -// LOG_DEBUG("SSRC {} Received SDES item ({}): {} from SSRC {}\n", GetLocalSSRC(), (int)t, msg, srcdat->GetSSRC()); -// } - -// private: -// RTPTcpReceiver* tcpReceiver{nullptr}; -// }; - -class MyTCPTransmitter : public RTPTCPTransmitter -{ -public: - void setReceiver(RTPTcpReceiver* r){ - tcpReceiver = r; - } - -public: - MyTCPTransmitter() : RTPTCPTransmitter(0){ } - - void OnSendError(SocketType sock) - { - LOG_ERROR("Error sending over socket {}, removing destination", sock); - DeleteDestination(RTPTCPAddress(sock)); - if(nullptr != tcpReceiver && !tcpReceiver->isClosing()){ - tcpReceiver->ReConnect(); - } - } - - void OnReceiveError(SocketType sock) - { - LOG_ERROR("Error receiving over socket {}, removing destination", sock); - DeleteDestination(RTPTCPAddress(sock)); - } - -private: - RTPTcpReceiver* tcpReceiver{nullptr}; -}; - -static int rtp_revc_thread_(void* param) -{ - if (!param) - { - return -1; - } - - RTPTcpReceiver* self = (RTPTcpReceiver*)param; - return self->OnRtpRecv(); -} - -static int listen_finish_thread_(void* param) -{ - if (!param) - { - return -1; - } - - RTPTcpReceiver* self = (RTPTcpReceiver*)param; - return self->ListenFinish(); -} - -RTPTcpReceiver::RTPTcpReceiver() -: m_bOpened(false) -, m_idleCount(-1) -, m_noDataCount(-1) -, m_nListener(-1) -, m_bAccepted(false) -, m_bClosing(false) -{ - m_bRtpExit = false; - m_rtpSessionPtr = new RTPSession(); - m_pSessparams = new RTPSessionParams(); - m_pTrans = new MyTCPTransmitter(); -} - -RTPTcpReceiver::~RTPTcpReceiver(){ - - Close(); - - if(m_rtpSessionPtr != nullptr){ - delete m_rtpSessionPtr; - m_rtpSessionPtr = nullptr; - } - - if(m_pSessparams != nullptr){ - delete m_pSessparams; - m_pSessparams = nullptr; - } - - if(m_pTrans != nullptr){ - delete m_pTrans; - m_pTrans = nullptr; - } -} - -bool RTPTcpReceiver::Open(string channel_id){ - m_SipChannelId = channel_id; - - m_rtp_port = allocRtpPort(); - if (m_rtp_port < 0) { - return false; - } - - if(0 != initSession(m_rtp_port)){ - return false; - } - - m_bOpened = true; - - LOG_INFO("[{}] started.", m_SipChannelId); - - return true; -} - -bool RTPTcpReceiver::IsOpened(){ - LOG_INFO("[{}] isopen:{} ", m_SipChannelId, m_bOpened); - return m_bOpened; -} - -void RTPTcpReceiver::Close(){ - m_bRtpExit = true; - - WebsocketClient* pServer = WebsocketClient::getInstance(); - if (pServer){ - pServer->ByeInvite(m_SipChannelId, m_rtp_port); - } - - if(m_listenFinishThread.joinable()){ - m_listenFinishThread.join(); - } -} - -void RTPTcpReceiver::close_task(){ - m_bRtpExit = true; - - m_bClosing = true; - - m_bAccepted = true; - - LOG_DEBUG("[{}] 1.", m_SipChannelId); - - // rtp接收线程退出 - if (m_rtpThread.joinable()) { - m_rtpThread.join(); - } - - LOG_DEBUG("[{}] 2.", m_SipChannelId); - - ClosePsThread(); - - m_bOpened = false; - - LOG_INFO("[{}] closed.", m_SipChannelId); -} - -bool RTPTcpReceiver::isClosing(){ - return m_bClosing; -} - -int RTPTcpReceiver::initSession(int localPort){ - m_nListener = socket(AF_INET, SOCK_STREAM | SOCK_NONBLOCK, IPPROTO_TCP); - if (m_nListener < 0) - { - return -1; - } - - sockaddr_in serverAddr; - memset(&serverAddr, 0, sizeof(sockaddr_in)); - serverAddr.sin_family = AF_INET; - serverAddr.sin_port = htons(localPort); - serverAddr.sin_addr.s_addr = htonl(INADDR_ANY); - int nRet = bind(m_nListener, (sockaddr*)&serverAddr, sizeof(serverAddr)); - if (nRet == -1) - { - LOG_ERROR("[{}] 绑定端口失败: {}", m_SipChannelId, localPort); - return -1; - } - - if (listen(m_nListener, 1) == -1) - { - LOG_ERROR("[{}] listen 失败", m_SipChannelId); - return -1; - } - - int nPackSize = 45678; - m_pSessparams->SetProbationType(RTPSources::NoProbation); - m_pSessparams->SetOwnTimestampUnit(90000.0 / 25.0); - m_pSessparams->SetMaximumPacketSize(nPackSize + 64); - - int status = m_pTrans->Init(false); - status = m_pTrans->Create(65535, NULL); - m_pTrans->setReceiver(this); - - status = m_rtpSessionPtr->Create(*m_pSessparams, m_pTrans); - if (status < 0) - { - // 若status = -59 ,需运行 export LOGNAME=root ,见 https://blog.csdn.net/m0_37876242/article/details/128588162 - LOG_ERROR("[{}] create session error: {}", m_SipChannelId, status); - return -1; - } - - m_rtpThread = std::thread(rtp_revc_thread_, this); - m_listenFinishThread = std::thread(listen_finish_thread_, this); - - if (InitPS() != 0) { - return false; - } - - bool bRet = RequestStream(); - if (!bRet) - { - LOG_INFO("[{}] 请求流失败!", m_SipChannelId); - return -1; - } - - LOG_INFO("[{}] 初始化成功, congratulations !!!", m_SipChannelId); - - return 0; -} - -// 图灵版本的请求 -int RTPTcpReceiver::OnRtpRecv() -{ - if(nullptr == m_rtpSessionPtr){ - return -1; - } - - LOG_INFO("[{}] OnRtpRecv started, m_nListener : {}", m_SipChannelId, m_nListener); - - sockaddr_in clientAddr; - int nLen = sizeof(sockaddr_in); - SocketType nServer = -1; - - LOG_INFO("[{}] Poll started.", m_SipChannelId); - int reconn_times = 0; - int reaccept_times = 0; - bool bReconn = false; - while(!m_bRtpExit){ - while(!m_bAccepted){ - if(m_bRtpExit){ - goto end_flag; - } - - while (!bReconn){ - if(m_bRtpExit){ - goto end_flag; - } - - reconn_times++; - if(reconn_times > 10){ - // 10次请求都失败,结束任务 - m_bRtpExit = true; - goto end_flag; - } - LOG_DEBUG("[{}] RequestStream...", m_SipChannelId); - bReconn = RequestStream(); - if (bReconn){ - LOG_DEBUG("[{}] RequestStream, True", m_SipChannelId); - continue; - } - LOG_DEBUG("[{}] RequestStream, False", m_SipChannelId); - - std::this_thread::sleep_for(std::chrono::seconds(5)); - } - - LOG_DEBUG("[{}] accepting...", m_SipChannelId); - nServer = accept(m_nListener, (sockaddr*)&clientAddr, (socklen_t * ) &nLen); - if (-1 == nServer){ - reaccept_times++; - LOG_DEBUG("[{}] reaccept_times = {}", m_SipChannelId, reaccept_times); - if(reaccept_times > 600){ - LOG_DEBUG("[{}] reaccept_times > 600", m_SipChannelId); - bReconn = false; - reaccept_times = 0; - } - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - continue; - } - LOG_DEBUG("[{}] accept success", m_SipChannelId); - m_rtpSessionPtr->AddDestination(RTPTCPAddress(nServer)); - m_bAccepted = true; - bReconn = false; - reconn_times = 0; - reaccept_times = 0; - - LOG_INFO("[{}] nServer={}", m_SipChannelId, nServer); - break; - } - - m_rtpSessionPtr->BeginDataAccess(); - if (m_rtpSessionPtr->GotoFirstSourceWithData()) - { - do - { - RTPPacket *pack; - - while ((pack = m_rtpSessionPtr->GetNextPacket()) != NULL) - { - // LOG_DEBUG("[{}] time: {} ", m_SipChannelId, UtilTools::get_cur_time_ms()); - ParsePacket(pack); - - m_rtpSessionPtr->DeletePacket(pack); - } - } while (m_rtpSessionPtr->GotoNextSourceWithData()); - } - - m_rtpSessionPtr->EndDataAccess(); - - m_rtpSessionPtr->Poll(); - std::this_thread::sleep_for(std::chrono::milliseconds(10)); - } - -end_flag: - - m_rtpSessionPtr->Destroy(); - - if(nServer > 0){ - close(nServer); - } - if(m_nListener > 0){ - close(m_nListener); - } - - LOG_INFO("[{}] OnRtpRecv exited.", m_SipChannelId); - - return 0; -} - - -int RTPTcpReceiver::OnRtpRecv2() -{ - if(nullptr == m_rtpSessionPtr){ - return -1; - } - - LOG_INFO("[{}] OnRtpRecv started, m_nListener : {}", m_SipChannelId, m_nListener); - - sockaddr_in clientAddr; - int nLen = sizeof(sockaddr_in); - SocketType nServer = -1; - - LOG_INFO("[{}] Poll started.", m_SipChannelId); - int reconn_times = 0; - int reaccept_times = 0; - bool bReconn = false; - while(!m_bRtpExit){ - while(!m_bAccepted){ - if(m_bRtpExit){ - goto end_flag; - } - - while (!bReconn){ - if(m_bRtpExit){ - goto end_flag; - } - - reconn_times++; - if(reconn_times > 10){ - // 10次请求都失败,结束任务 - m_bRtpExit = true; - goto end_flag; - } - LOG_DEBUG("[{}] RequestStream...", m_SipChannelId); - bReconn = RequestStream(); - if (bReconn){ - LOG_DEBUG("[{}] RequestStream, True", m_SipChannelId); - continue; - } - LOG_DEBUG("[{}] RequestStream, False", m_SipChannelId); - - std::this_thread::sleep_for(std::chrono::seconds(5)); - } - - LOG_DEBUG("[{}] accepting...", m_SipChannelId); - nServer = accept(m_nListener, (sockaddr*)&clientAddr, (socklen_t * ) &nLen); - if (-1 == nServer){ - reaccept_times++; - LOG_DEBUG("[{}] reaccept_times = {}", m_SipChannelId, reaccept_times); - if(reaccept_times > 600){ - LOG_DEBUG("[{}] reaccept_times > 600", m_SipChannelId); - bReconn = false; - reaccept_times = 0; - } - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - continue; - } - LOG_DEBUG("[{}] accept success", m_SipChannelId); - m_rtpSessionPtr->AddDestination(RTPTCPAddress(nServer)); - m_bAccepted = true; - bReconn = false; - reconn_times = 0; - reaccept_times = 0; - - LOG_INFO("[{}] nServer={}", m_SipChannelId, nServer); - break; - } - - m_rtpSessionPtr->BeginDataAccess(); - if (m_rtpSessionPtr->GotoFirstSourceWithData()) - { - do - { - RTPPacket *pack; - - while ((pack = m_rtpSessionPtr->GetNextPacket()) != NULL) - { - // LOG_DEBUG("[{}] time: {} ", m_SipChannelId, UtilTools::get_cur_time_ms()); - ParsePacket(pack); - - m_rtpSessionPtr->DeletePacket(pack); - } - } while (m_rtpSessionPtr->GotoNextSourceWithData()); - } - - m_rtpSessionPtr->EndDataAccess(); - - m_rtpSessionPtr->Poll(); - std::this_thread::sleep_for(std::chrono::milliseconds(10)); - } - -end_flag: - - m_rtpSessionPtr->Destroy(); - - if(nServer > 0){ - close(nServer); - } - if(m_nListener > 0){ - close(m_nListener); - } - - LOG_INFO("[{}] OnRtpRecv exited.", m_SipChannelId); - - return 0; -} - -int RTPTcpReceiver::ListenFinish(){ - while(!m_bRtpExit){ - std::this_thread::sleep_for(std::chrono::seconds(3)); - } - - close_task(); -} - -bool RTPTcpReceiver::ReConnect(){ - m_bAccepted = false; -} - -bool RTPTcpReceiver::RequestStream(){ - WebsocketClient* pServer = WebsocketClient::getInstance(); - if (pServer){ - if (pServer->InviteTcp(m_SipChannelId, m_rtp_port, this) < 0) { - return false; - } - } - - return true ; -} \ No newline at end of file diff --git a/src/decoder/gb28181/rtp/RTPTcpReceiver.h b/src/decoder/gb28181/rtp/RTPTcpReceiver.h deleted file mode 100644 index 8478ea6..0000000 --- a/src/decoder/gb28181/rtp/RTPTcpReceiver.h +++ /dev/null @@ -1,79 +0,0 @@ -#ifndef _RTP_TCP_RECEIVER_H_ -#define _RTP_TCP_RECEIVER_H_ - - -#include "demuxer.h" -#include "buffer.h" - -#include "rtpsession.h" -#include "rtptcptransmitter.h" -#include "rtpipv4address.h" -#include "rtptcpaddress.h" -#include "rtpsessionparams.h" -#include "rtperrors.h" -#include "rtpsourcedata.h" -#include "rtpsocketutil.h" -#include -#include -#include -#include - -#include -#include -#include -#include - -#include "RTPReceiver.h" - - -using namespace jrtplib; -using namespace std; - - - -class TcpRTPSession; -class MyTCPTransmitter; - -class RTPTcpReceiver:public RTPReceiver -{ -public: - RTPTcpReceiver(); - ~RTPTcpReceiver(); - - virtual bool Open(string channel_id); - virtual bool IsOpened() ; - virtual void Close() ; - virtual bool RequestStream(); - -public: - int OnRtpRecv(); - int OnRtpRecv2(); - bool ReConnect(); - int ListenFinish(); - bool isClosing(); - -private: - int initSession(int localPort); - void close_task(); - -private: - std::atomic_bool m_bOpened; - std::atomic_bool m_bAccepted; - std::atomic_bool m_bClosing; - - int64_t m_idleCount; - int64_t m_noDataCount;//线程计数,用于打开流成功但是实际没流过来 - - std::thread m_rtpThread; // RTP接收线程 - SocketType m_nListener; - - RTPSession* m_rtpSessionPtr; // RTP会话 - RTPSessionParams* m_pSessparams; - MyTCPTransmitter* m_pTrans; - - std::thread m_listenFinishThread; // RTP接收线程 - - std::atomic_bool m_bNoData{false}; -}; - -#endif // _RTP_TCP_RECEIVER_H_ diff --git a/src/decoder/gb28181/rtp/RTPUdpReceiver.cpp b/src/decoder/gb28181/rtp/RTPUdpReceiver.cpp deleted file mode 100644 index 69931bf..0000000 --- a/src/decoder/gb28181/rtp/RTPUdpReceiver.cpp +++ /dev/null @@ -1,298 +0,0 @@ - -#include "RTPUdpReceiver.h" -#include -#include - -#include -#include - -#include "../common_header.h" -#include "../websocket/WebsocketClient.h" - - -using namespace std; - -#define BUFFERSIZE_1024 4096 -#define BUFFERSIZE_GAP 4096//5120 //1024*5 - -namespace -{ - const int kVideoFrameSize = BUFFERSIZE_1024*BUFFERSIZE_1024*5*2; - const int kRtpRecvBufferSize = BUFFERSIZE_1024*BUFFERSIZE_1024*2; - const uint16_t kInvalidPort = 0; -}; // namespace - -class UdpRTPSession : public RTPSession -{ -public: - UdpRTPSession() {} - virtual ~UdpRTPSession() {} - -private: - virtual void OnRTPPacket(RTPPacket* pack, const RTPTime& receiverTime, const RTPAddress* senderAddress) - { - AddDestination(*senderAddress); - } - - virtual void OnRTCPCompoundPacket(RTCPCompoundPacket *pack, const RTPTime &receivetime,const RTPAddress *senderaddress) - { - //AddDestination(*senderaddress); - //const char* name = "hi~"; - //SendRTCPAPPPacket(0, (const uint8_t*)name, "keeplive", 8); - - //printf("send rtcp app"); - } -}; - -static int rtp_revc_thread_(void* param) -{ - if (!param) - { - return -1; - } - - RTPUdpReceiver* self = (RTPUdpReceiver*)param; - return self->OnRtpRecv(); -} - -static int connecting_thread_(void* param) -{ - if (!param) { - return -1; - } - - RTPUdpReceiver* self = (RTPUdpReceiver*)param; - return self->CheckConnecting(); -} - -RTPUdpReceiver::RTPUdpReceiver() -:m_bOpened(false) -, m_idleCount(-1) -,m_noDataCount(-1) -{ - m_bRtpExit = false; - m_sessparamsPtr = new RTPSessionParams(); - m_transparamsPtr = new RTPUDPv4TransmissionParams(); - m_rtpSessionPtr = new UdpRTPSession(); -} - -RTPUdpReceiver::~RTPUdpReceiver() -{ - m_bRtpExit = true; - - if(nullptr != m_sessparamsPtr){ - delete m_sessparamsPtr; - m_sessparamsPtr = nullptr; - } - - if(nullptr != m_transparamsPtr){ - delete m_transparamsPtr; - m_transparamsPtr = nullptr; - } - - if (nullptr != m_connThreadPtr && m_connThreadPtr->joinable()) { - m_connThreadPtr->join(); - delete m_connThreadPtr; - m_connThreadPtr = nullptr; - } - - if(nullptr != m_rtpSessionPtr){ - delete m_rtpSessionPtr; - m_rtpSessionPtr = nullptr; - } -} - -bool RTPUdpReceiver::Open(string channel_id) -{ - m_SipChannelId = channel_id; - - m_rtp_port = allocRtpPort(); - if (m_rtp_port < 0) { - return false; - } - - m_sessparamsPtr->SetUsePollThread(true); - m_sessparamsPtr->SetMinimumRTCPTransmissionInterval(10); - m_sessparamsPtr->SetOwnTimestampUnit(1.0/90000.0); - m_sessparamsPtr->SetAcceptOwnPackets(true); - - m_transparamsPtr->SetPortbase(m_rtp_port); - m_transparamsPtr->SetRTPReceiveBuffer(kRtpRecvBufferSize); - - LOG_INFO("[{}] port: {}", m_SipChannelId, m_rtp_port); - - int err = m_rtpSessionPtr->Create(*m_sessparamsPtr, m_transparamsPtr); - if (err != 0) { - LOG_ERROR("[{}] Create error: {}", m_SipChannelId, err); - return false; - } - - m_rtpThreadPtr = new std::thread(rtp_revc_thread_, this); - if (nullptr == m_rtpThreadPtr) { - LOG_ERROR("[{}] Create m_rtpThreadPtr error", m_SipChannelId); - return false; - } - - if (InitPS() != 0) { - return false; - } - - // InitPS()成功就得起该线程,因为ClosePsThread是在这里完成的 - m_connThreadPtr = new std::thread(connecting_thread_, this); - if (nullptr == m_connThreadPtr) { - LOG_ERROR("[{}] Create m_connThreadPtr error", m_SipChannelId); - return false; - } - - bool bReq = RequestStream(); - if (!bReq) { - LOG_INFO("[{}] RequestStream failed !", m_SipChannelId); - Close(); - return false; - } - - m_bOpened = true; - m_bNoData = false; - LOG_INFO("[{}] Open ok", m_SipChannelId); - - return true; -} - -bool RTPUdpReceiver::IsOpened() -{ - return m_bOpened; -} - -void RTPUdpReceiver::Close() -{ - m_bRtpExit = true; -} - -// 收RTP包线程 -int RTPUdpReceiver::OnRtpRecv() -{ - if(nullptr == m_rtpSessionPtr){ - return -1; - } - - m_bRecvExit = false; - - LOG_INFO("[{}] OnRtpRecv started.", m_SipChannelId); - while (!m_bRecvExit) - { - m_rtpSessionPtr->Poll(); - m_rtpSessionPtr->BeginDataAccess(); - - if (m_rtpSessionPtr->GotoFirstSourceWithData()) - { - // LOG_INFO("OnRtpRecv GotoFirstSourceWithData --{}", m_SipChannelId); - last_recv_ts = UtilTools::get_cur_time_ms(); - m_idleCount = 0; - m_noDataCount = 0; - do - { - RTPPacket* packet; - while ((packet = m_rtpSessionPtr->GetNextPacket()) != NULL) - { - m_bNoData = false; - // LOG_INFO("OnRtpRecv GetNextPacket --{}", m_SipChannelId); - int ret = ParsePacket(packet); - m_rtpSessionPtr->DeletePacket(packet); - - if(ret != 0){ - m_bRecvExit = true; - } - } - } while (m_rtpSessionPtr->GotoNextSourceWithData()); - } - - m_rtpSessionPtr->EndDataAccess(); - - std::this_thread::sleep_for(std::chrono::milliseconds(10)); - } - - LOG_INFO("[{}] OnRtpRecv exited.", m_SipChannelId); - - return 0; -} - -bool RTPUdpReceiver::RequestStream() { - WebsocketClient* pClient = WebsocketClient::getInstance(); - if (pClient){ - if (pClient->InviteUdp(m_SipChannelId, m_rtp_port, this) < 0) { - return false; - } - } - - return true; -} - -int RTPUdpReceiver::CheckConnecting() { - LOG_INFO("[{}] CheckConnecting started.", m_SipChannelId); - - int count = 0; - while (!m_bRtpExit) - { - if (m_bNoData) { - // bool bReq = RequestStream(); - // if (!bReq) { - // LOG_INFO("[{}] RequestStream failed !", m_SipChannelId); - // } - - wait_times(50); // 等待5s - - count++; - - if (count > 60) { - // 3min 依然没数据过来,则关闭 - m_bRtpExit = true; - break; - } - } else { - m_bNoData = true; - - wait_times(100); // 等待10s, 10s之内正常有数据的情况 m_bNoData 已经被置为false - } - } - - m_bRecvExit = true; - - // 结束整个任务 - WebsocketClient* pClient = WebsocketClient::getInstance(); - if (pClient){ - pClient->ByeInvite(m_SipChannelId, m_rtp_port); - } - - LOG_DEBUG("[{}] ByeInvite", m_SipChannelId); - - // rtp接收线程退出 - if (nullptr != m_rtpThreadPtr && m_rtpThreadPtr->joinable()) - { - m_rtpThreadPtr->join(); - delete m_rtpThreadPtr; - m_rtpThreadPtr = nullptr; - } - - m_rtpSessionPtr->Destroy(); - - ClosePsThread(); - - m_bOpened = false; - - LOG_INFO("[{}] CheckConnecting exited.", m_SipChannelId); - - return 0; -} - -// 对退出命令敏感的延时 -bool RTPUdpReceiver::wait_times(int times) { - int count_sleep = times; - while (!m_bRtpExit) { - count_sleep-- ; - if (count_sleep <= 0) { - count_sleep = times; - break; - } - std::this_thread::sleep_for(std::chrono::milliseconds(100)); - } -} \ No newline at end of file diff --git a/src/decoder/gb28181/rtp/RTPUdpReceiver.h b/src/decoder/gb28181/rtp/RTPUdpReceiver.h deleted file mode 100644 index 37675ad..0000000 --- a/src/decoder/gb28181/rtp/RTPUdpReceiver.h +++ /dev/null @@ -1,62 +0,0 @@ -#ifndef _RTP_UDP_RECEIVER_H_ -#define _RTP_UDP_RECEIVER_H_ - -#include "rtpsessionparams.h" -#include "rtpudpv4transmitter.h" -#include "rtpsession.h" -#include "rtppacket.h" -#include -#include -#include -#include -#include - -#include "RTPReceiver.h" - - -using namespace jrtplib; -using namespace std; - - -class UdpRTPSession; - -class RTPUdpReceiver: public RTPReceiver -{ -public: - RTPUdpReceiver(); - ~RTPUdpReceiver(); - - virtual bool Open(string channel_id); - virtual bool IsOpened() ; - virtual void Close() ; - virtual bool RequestStream(); - -public: - int OnRtpRecv(); - int CheckConnecting(); - -private: - bool wait_times(int times); - -private: - std::thread* m_rtpThreadPtr{nullptr}; // RTP接收线程 - std::thread* m_connThreadPtr{nullptr}; // 判断流是否还在的线程 - - RTPSession* m_rtpSessionPtr{nullptr}; // RTP会话 - RTPSession m_rtpSession; - - std::atomic_bool m_bOpened; - - int64_t m_idleCount; - int64_t m_noDataCount;//线程计数,用于打开流成功但是实际没流过来 - - RTPSessionParams* m_sessparamsPtr{nullptr}; - RTPUDPv4TransmissionParams* m_transparamsPtr{nullptr}; - - string m_sip_channel_id; - - std::atomic_bool m_bNoData{false}; - bool m_bRecvExit{false}; -}; - -#endif // _RTP_UDP_RECEIVER_H_ diff --git a/src/decoder/gb28181/rtp/buffer.h b/src/decoder/gb28181/rtp/buffer.h deleted file mode 100644 index 3092c38..0000000 --- a/src/decoder/gb28181/rtp/buffer.h +++ /dev/null @@ -1,91 +0,0 @@ -/*******************************************************} -{ } -{ File: buffer.h } -{ Created by Tsviatko Jongov } -{ http://tsviatko.jongov.com } -{ Date : 25.01.2007 } -{ } -{ CBuffer class. } -{ } -{*******************************************************/ -#pragma once -#include -#include - -typedef int BOOL; - -class CBuffer -{ -private: - char * fBuf = NULL; // buffer for bytes - int fSize; // size of buffer - int fLast; // points after Last valid byte -public: - CBuffer(int Size) - { - fLast = 0; - fSize = 0; - fFirst = 0; - - if (Size > 0) - { - fBuf = (char *)malloc(Size); - fSize = Size; - } - } - - ~CBuffer() - { - if (fBuf != NULL) - { - free(fBuf); - fBuf = NULL; - } - } - - - void add(char * Data, int Size) - { - - if (fLast + Size > fSize) - { - char * tmp = (char *)malloc(fSize + Size); - memcpy(tmp, fBuf, fLast); - fSize += Size; - free(fBuf); - fBuf = tmp; - } - - memcpy(fBuf + fLast, Data, Size); - fLast += Size; - } - - void compact() - { - if (fFirst > 0) - { - int aLen = fLast - fFirst; - memmove(fBuf, fBuf + fFirst, aLen); - fFirst = 0; - fLast = aLen; - } - } - - void reset() - { - fFirst = 0; - fLast = 0; - } - - int len() - { - return (fLast - fFirst); - } - - void * head() - { - return fBuf + fFirst; - } - - int fFirst; -}; \ No newline at end of file diff --git a/src/decoder/gb28181/rtp/demuxer.cpp b/src/decoder/gb28181/rtp/demuxer.cpp deleted file mode 100644 index 4d6e95b..0000000 --- a/src/decoder/gb28181/rtp/demuxer.cpp +++ /dev/null @@ -1,417 +0,0 @@ -/*******************************************************} -{ } -{ File: demuxer.cpp } -{ Created by Tsviatko Jongov } -{ http://tsviatko.jongov.com } -{ Date : 25.01.2007 } -{ } -{ CMpeg2Demux class. } -{ } -{*******************************************************/ -#include "assert.h" -#include -#include "demuxer.h" -#include "Pack_Header_Def.h" -#include "time.h" - -#include - -#ifdef _WIN32 -#include "Winsock2.h" -#pragma comment(lib, "ws2_32.lib") -#endif -#ifdef __linux__ -#include "arpa/inet.h" -#endif - -#include "../common_header.h" - -using namespace std; - - -static /*_inline*/ unsigned int asm_swap32(unsigned int x) -{ - return ntohl(x); -} - -static /*_inline*/ unsigned short asm_swap16(unsigned short x) -{ - return ntohs(x); -} - -CMpeg2Demux::CMpeg2Demux() -: m_streamType(STREAM_TYPE_UNKNOWN) -,m_userdata(NULL) -,m_userdata2(NULL) -,m_lastiskeyfram(false) -{ - try - { - fBuffer = new CBuffer(1024 * 1024); - if (fBuffer == NULL) - { - } - m_lastpts = 0; - fReceiveFunction = 0; - fReceiveFunction2 = 0; - - m_psvideo= new CBuffer(1024*50); - m_esvideo= new CBuffer(1024*50); - m_psaudio= new CBuffer(1024*50); - m_esaudio= new CBuffer(1024*50); - } - catch (...) - { - } -}; - -CMpeg2Demux::~CMpeg2Demux() -{ - try - { - if (fBuffer != NULL) - { - delete fBuffer; - fBuffer = NULL; - } - - if (NULL != m_psvideo) - { - delete m_psvideo; - m_psvideo = NULL; - } - if (NULL != m_esvideo) - { - delete m_esvideo; - m_esvideo = NULL; - } - if (NULL != m_psaudio) - { - delete m_psaudio; - m_psaudio = NULL; - } - if (NULL != m_esaudio) - { - delete m_esaudio; - m_esaudio = NULL; - } - } - catch (...) - { - } -}; - -int CMpeg2Demux::AddData(void * Data, int Size/*, DWORD pts*/) -{ - try - { - if ((Data == NULL) || (Size <= 0)) - { - return (-1); - } - - /*m_timeStamp = pts;*/ - fBuffer->add((char *)Data, Size); - if (!Demultiplex()) - { - return (-1); - } - - return (0); - } - catch (...) - { - return (-1); - } -} - -void CMpeg2Demux::SetReceiveFunction(ReceiveFunction * func, void* userdata) -{ - try - { - fReceiveFunction = func; - m_userdata = userdata; - } - catch (...) - { - } -} - -void CMpeg2Demux::SetReceiveFunction2(ReceiveFunction2 * func2, void* userdata2) -{ - fReceiveFunction2 = func2; - m_userdata2 = userdata2; -} - -uint64_t GetLocalTimeOfMicroSecond() -{ - chrono::time_point tpMicro - = chrono::time_point_cast(chrono::system_clock::now()); - - return tpMicro.time_since_epoch().count(); -} - -int CMpeg2Demux::Demultiplex() -{ - try - { - unsigned char * PDW {}; - unsigned int Code {}; - int Processed = 0; - int StreamID {}; - int PES_packet_length {}; - int PES_header_data_length {}; - int Val {}; - - if (fBuffer->len() <= 0) - { - return (0); - } - - PDW = (unsigned char *)fBuffer->head(); - while (fBuffer->len() - Processed > 140) - { - if ((*(unsigned int *)PDW & 0x00FFFFFF) != 0x00010000) - { - PDW++; - Processed++; - continue; - } - - Code = asm_swap32(*(unsigned int *)PDW); - StreamID = (Code & 0xFF); - if (PACK_START_CODE != Code) - { - unsigned short pespacklen = asm_swap16(*(unsigned short *)(PDW + 4)) + 6; - if (fBuffer->len() - Processed < pespacklen + 6) - { - break; - } - } - - if (PACK_START_CODE == Code)//ǰһ��pspack�����һ��pspack��ʼ - { - if (fReceiveFunction != NULL && m_esvideo->len())//��Ƶes - { - PS_HEADER_tag* pshead = (PS_HEADER_tag*)m_psvideo->head(); - uint64_t pts = 0; - pshead->getSystem_clock_reference_base(pts); - pts = pts/90; - int64_t localPts = GetLocalTimeOfMicroSecond(); - fReceiveFunction(m_streamType, m_esvideo->head(), m_esvideo->len(), pts, localPts, m_lastiskeyfram, m_userdata); - } - m_esvideo->fFirst = m_esvideo->len(); - m_esvideo->compact(); - - if (fReceiveFunction != NULL && m_esaudio->len())//��Ƶes - { - int64_t localPts = GetLocalTimeOfMicroSecond(); - fReceiveFunction(0xC0, m_esaudio->head(), m_esaudio->len(), m_lastpts, localPts, 0, m_userdata); - } - m_esaudio->fFirst = m_esaudio->len(); - m_esaudio->compact(); - - if (fReceiveFunction2 != NULL && m_psvideo->len())//��Ƶps - { - fReceiveFunction2(STREAM_TYPE_VIDEO,m_psvideo->head(),m_psvideo->len(),m_lastpts,m_lastiskeyfram,m_userdata2); - } - m_psvideo->fFirst = m_psvideo->len(); - m_psvideo->compact(); - - if (fReceiveFunction2 != NULL && m_psaudio->len())//��Ƶ - { - fReceiveFunction2(STREAM_TYPE_AUDIO,m_psaudio->head(),m_psaudio->len(),m_lastpts,0,m_userdata2); - } - m_psaudio->fFirst = m_psaudio->len(); - m_psaudio->compact(); - - PS_HEADER_tag* ppshead = (PS_HEADER_tag*)PDW; - unsigned long psheadlen = sizeof(PS_HEADER_tag) + ppshead->pack_stuffing_length; - if (fBuffer->len() - Processed < (int)psheadlen) - { - break; - } - - // - m_lastiskeyfram = false; - if ((*(unsigned int *)(PDW+psheadlen)&0x00FFFFFF) != 0x00010000) - { - } - else - { - m_psvideo->add((char*)PDW,psheadlen);//psͷд����Ƶ������ - PDW += psheadlen; - Processed += psheadlen; - continue; - } - } - else if (SYSTEM_START_CODE == Code)//system_header - { - unsigned short pespacklen = asm_swap16(*(unsigned short *)(PDW + 4)) + 6; - if ((*(unsigned int *)(PDW+pespacklen)&0x00FFFFFF) != 0x00010000) - { - LOG_WARN("SYSTEM_START_CODE: Warning in CMpeg2Demux::Demultiplex - ((*PDW & 0x00FFFFFF) != 0x00010000).\n"); - } - else - { - m_psvideo->add((char*)PDW,pespacklen);//psͷд����Ƶ������ - PDW += pespacklen; - Processed +=pespacklen; - m_lastiskeyfram = true; - continue; - } - } - else if (PROGRAM_STREAM_MAP == StreamID)//psm - { - unsigned short pespacklen = asm_swap16(*(unsigned short *)(PDW + 4)) + 6; - if ((*(unsigned int *)(PDW+pespacklen)&0x00FFFFFF) != 0x00010000) - { - } - else - { - unsigned short program_stream_info_length; - //unsigned short elementary_stream_map_length; - unsigned short* plen = (unsigned short*)(PDW + 8); - program_stream_info_length = ntohs(*plen); - int test = *(PDW + 8 + program_stream_info_length + 5);//192 - //assert(*(PDW+8+program_stream_info_length+5) == 0xe0); - - //if(*(PDW + 8 + program_stream_info_length + 5) != 0xe0) - //{ - // continue; - //} - //printf("0xe0=%d, 0x1b=%d\n", *(PDW + 8 + program_stream_info_length + 5), *(PDW + 8 + program_stream_info_length + 4)); - if (m_pserror > 5 && (*(PDW + 8 + program_stream_info_length + 5) != 0xe0 && *(PDW + 8 + program_stream_info_length + 5) != 0xc0))//�ж�c0��Ϊ�˼�����Ŧ�������в�ʿ������С���� - { - LOG_ERROR("{}", m_pserror); - return -1; - } - if (*(PDW + 8 + program_stream_info_length + 5) != 0xe0 && *(PDW + 8 + program_stream_info_length + 5) != 0xc0) - { - //printf("--------------------------------1\n"); - ++m_pserror; - continue; - } - m_lastiskeyfram = true; - if (*(PDW + 8 + program_stream_info_length + 4) == 0x1b || *(PDW + 8 + program_stream_info_length + 4) == 0x03) - { - m_streamType = VIDEO_TYPE_H264; // H264 - } - else if (*(PDW + 8 + program_stream_info_length + 4) == 0x24) - { - m_streamType = VIDEO_TYPE_H265; // H265 - } - else if (*(PDW+8+program_stream_info_length+4) == 0x10) - { - m_streamType = VIDEO_TYPE_MPEG4; // MPEG4 - } - else - { - m_streamType = STREAM_TYPE_UNKNOWN; - } - m_pserror = 0; - m_psvideo->add((char*)PDW,pespacklen);//psͷд����Ƶ������ - PDW += pespacklen; - Processed +=pespacklen; - continue; - } - } - else if (0xBD == StreamID)//˽������ - { - unsigned short pespacklen = asm_swap16(*(unsigned short *)(PDW + 4)) + 6; - - if ((*(unsigned int *)(PDW+pespacklen)&0x00FFFFFF) != 0x00010000) - { - } - else - { - m_psvideo->add((char*)PDW,pespacklen);//psͷд����Ƶ������ - PDW += pespacklen; - Processed +=pespacklen; - continue; - } - } - - if ((Code >= SYSTEM_START_CODE_MIN) && - (Code <= SYSTEM_START_CODE_MAX) && - (Code != PACK_START_CODE) && - (Code != SYSTEM_START_CODE) && - (StreamID != PROGRAM_STREAM_MAP) && - (StreamID != PADDING_STREAM) && - (StreamID != PRIVATE_STREAM_2) && - (StreamID != ECM_STREAM) && - (StreamID != EMM_STREAM) && - (StreamID != PROGRAM_STREAM_DIRECTORY) && - (StreamID != DSM_CC_STREAM) && - (StreamID != ITU_T_STREAM_E)) - { - PES_packet_length = asm_swap16(*(unsigned short *)(PDW + 4)); - PES_header_data_length = *(PDW + 8); - - if (PES_packet_length == 0) - PES_packet_length = fBuffer->len() - Processed/* - 4*/; - else - PES_packet_length += 6; - - if (fBuffer->len() - Processed >= PES_packet_length/* + 4*/) - { - PES_HEADER_tag* peshead = (PES_HEADER_tag*)PDW; - uint64_t pts = 0; - if (peshead->PTS_DTS_flags&0x3) - { - PTS_tag* ptstag = (PTS_tag*)(PDW + 9); - ptstag->getPTS(pts); - m_lastpts = pts/90; - } - - Val = 6 + 3 + PES_header_data_length; - - if (0xE0 == StreamID) - { - m_esvideo->add((char*)PDW + Val, PES_packet_length - Val); - m_psvideo->add((char*)PDW, PES_packet_length); - } - else if (0xC0 == StreamID) - { - if (PES_packet_length + 6 - Val > 0) - { - m_esaudio->add((char*)PDW + Val,PES_packet_length - Val); - } - else - { - m_esaudio->add((char*)PDW + Val,PES_packet_length - 19); - } - m_psaudio->add((char*)PDW,PES_packet_length+6); - } - - fBuffer->fFirst += Processed + PES_packet_length; - fBuffer->compact(); - - Processed = 0; - PDW = (unsigned char *)fBuffer->head(); - } - else - { - break; - } - } - else { - PDW++; - Processed++; - } - }; - - if (Processed) - { - fBuffer->fFirst += Processed; - fBuffer->compact(); - Processed = 0; - } - return (true); - } - catch (...) - { - return (-1); - } -} - diff --git a/src/decoder/gb28181/rtp/demuxer.h b/src/decoder/gb28181/rtp/demuxer.h deleted file mode 100644 index ca89aba..0000000 --- a/src/decoder/gb28181/rtp/demuxer.h +++ /dev/null @@ -1,87 +0,0 @@ -/*******************************************************} -{ } -{ File: demuxer.h } -{ Created by Tsviatko Jongov } -{ http://tsviatko.jongov.com } -{ Date : 25.01.2007 } -{ } -{ CMpeg2Demux class. } -{ } -{*******************************************************/ - -#ifndef _DEMUXER_H_ -#define _DEMUXER_H_ - - -#include -#include "buffer.h" - -//MPEG-2 start codes -#define SYSTEM_START_CODE_MIN 0x000001B9 -#define SYSTEM_START_CODE_MAX 0x000001FF -#define PACK_START_CODE 0x000001BA -#define SYSTEM_START_CODE 0x000001BB - -//MPEG-2 stream IDs -#define PROGRAM_STREAM_MAP 0xBC -#define PADDING_STREAM 0xBE -#define PRIVATE_STREAM_2 0xBF -#define ECM_STREAM 0xF0 -#define EMM_STREAM 0xF1 -#define PROGRAM_STREAM_DIRECTORY 0xFF -#define DSM_CC_STREAM 0xF2 -#define ITU_T_STREAM_E 0xF8 - -#define STREAM_TYPE_VIDEO 1 -#define STREAM_TYPE_AUDIO 2 - - -#define STREAM_TYPE_UNKNOWN 0x00 -#define VIDEO_TYPE_MPEG4 0x01 -#define VIDEO_TYPE_H264 0x1B -#define VIDEO_TYPE_H265 0x24 -#define VIDEO_TYPE_SVAC 0x80 -#define AUDIO_TYPE_G711 0x90 -#define AUDIO_TYPE_G722_1 0x92 -#define AUDIO_TYPE_G723_1 0x93 -#define AUDIO_TYPE_G729 0x99 -#define AUDIO_TYPE_SVAC 0x9B -//#include - -//typedef long long INT64; -//typedef unsigned long long UINT64; - -typedef int ReceiveFunction(unsigned char streamType, void* data, int size, uint64_t pts, uint64_t localPts, bool bKey, void* userData);//es�ص� -typedef int ReceiveFunction2(unsigned int streamtype, void * Data, int Size, uint64_t pts, bool iskeyfram, void* userdata);//ps�ص� - -static /*_inline*/ unsigned int asm_swap32(unsigned int x); -static /*_inline*/ unsigned short asm_swap16(unsigned short x); - -class CMpeg2Demux { -private: - CBuffer * fBuffer; - void* m_userdata; - void* m_userdata2; - ReceiveFunction * fReceiveFunction; - ReceiveFunction2* fReceiveFunction2; -// CBuffer* m_frambuf; - CBuffer* m_psvideo; - CBuffer* m_esvideo; - CBuffer* m_psaudio; - CBuffer* m_esaudio; - uint64_t m_lastpts; - bool m_lastiskeyfram; - unsigned char m_streamType; - int m_pserror = 0; - int Demultiplex(); - - /*DWORD m_timeStamp;*/ -public: - CMpeg2Demux(); - ~CMpeg2Demux(); - int AddData(void * Data, int Size/*, DWORD pts*/); - void SetReceiveFunction(ReceiveFunction * func, void* userdata); - void SetReceiveFunction2(ReceiveFunction2 * func2, void* userdata2); -}; - -#endif // _DEMUXER_H_ \ No newline at end of file -- libgit2 0.21.4