From 413b18521d357c1a2598227b3967a9410b806180 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Thu, 25 Oct 2018 13:43:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E5=96=84Rtsp=E5=A4=8D=E7=94=A8?= =?UTF-8?q?=E5=99=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/RtspMuxer/RtspMuxer.cpp | 16 +++++++++------- src/RtspMuxer/RtspMuxer.h | 4 +++- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/src/RtspMuxer/RtspMuxer.cpp b/src/RtspMuxer/RtspMuxer.cpp index a8031135..6bf7f3e7 100644 --- a/src/RtspMuxer/RtspMuxer.cpp +++ b/src/RtspMuxer/RtspMuxer.cpp @@ -33,15 +33,22 @@ void RtspMuxer::addTrack(const Track::Ptr &track, uint32_t ssrc, int mtu) { //记录该Track auto codec_id = track->getCodecId(); _track_map[codec_id] = track; + auto lam = [this,ssrc,mtu,track](){ + //异步生成rtp编码器 + //根据track生产sdp Sdp::Ptr sdp = Factory::getSdpByTrack(track); if (!sdp) { return; } + + // 根据sdp生成rtp编码器 auto encoder = sdp->createRtpEncoder(ssrc ? ssrc : ((uint64_t) sdp.get()) & 0xFFFFFFFF, mtu); if (!encoder) { return; } + //添加其sdp + _sdp.append(sdp->getSdp()); //设置Track的代理,这样输入frame至Track时,最终数据将输出到RtpEncoder中 track->setDelegate(encoder); //rtp编码器共用同一个环形缓存 @@ -59,12 +66,7 @@ string RtspMuxer::getSdp() { //尚未就绪 return ""; } - -// _StrPrinter printer; -// for (auto &pr : _sdp_map) { -// printer << pr.second->getSdp(); -// } -// return printer; + return _sdp; } @@ -80,7 +82,7 @@ void RtspMuxer::inputFrame(const Frame::Ptr &frame) { it->second->inputFrame(frame); if(!ready && it->second->ready()){ - //Track又未就绪状态装换成就绪状态,我们就生成sdp以及rtp编码器 + //Track由未就绪状态装换成就绪状态,我们就生成sdp以及rtp编码器 auto it_callback = _trackReadyCallback.find(codec_id); if(it_callback != _trackReadyCallback.end()){ it_callback->second(); diff --git a/src/RtspMuxer/RtspMuxer.h b/src/RtspMuxer/RtspMuxer.h index 1115013a..89185753 100644 --- a/src/RtspMuxer/RtspMuxer.h +++ b/src/RtspMuxer/RtspMuxer.h @@ -38,7 +38,8 @@ public: /** * 构造函数 */ - RtspMuxer(){ + RtspMuxer(const TitleSdp::Ptr &title = std::make_shared()){ + _sdp = title->getSdp(); _rtpRing = std::make_shared(); } virtual ~RtspMuxer(){} @@ -79,6 +80,7 @@ private: map _track_map; map > _trackReadyCallback; RtpRingInterface::RingType::Ptr _rtpRing; + string _sdp; };