From 0514278ce6b38c603ebc0352868ad6c1a86e38b5 Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Thu, 16 Sep 2021 10:47:49 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dwebrtc=E6=92=AD=E6=94=BE?= =?UTF-8?q?=E4=B8=8D=E8=83=BD=E7=A7=92=E5=BC=80=E7=9A=84=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webrtc/WebRtcTransport.cpp | 30 +++++++++++++++--------------- 1 file changed, 15 insertions(+), 15 deletions(-) diff --git a/webrtc/WebRtcTransport.cpp b/webrtc/WebRtcTransport.cpp index 9d137a29..daaf1f76 100644 --- a/webrtc/WebRtcTransport.cpp +++ b/webrtc/WebRtcTransport.cpp @@ -470,6 +470,21 @@ void WebRtcTransportImp::onStartWebRTC() { _simulcast = getSdp(SdpType::answer).supportSimulcast(); } if (canSendRtp()) { + RtcSession rtsp_send_sdp; + rtsp_send_sdp.loadFrom(_play_src->getSdp(), false); + for (auto &m : getSdp(SdpType::answer).media) { + if (m.type == TrackApplication) { + continue; + } + auto rtsp_media = rtsp_send_sdp.getMedia(m.type); + if (rtsp_media && getCodecId(rtsp_media->plan[0].codec) == getCodecId(m.plan[0].codec)) { + auto it = _pt_to_track.find(m.plan[0].pt); + CHECK(it != _pt_to_track.end()); + //记录发送rtp时约定的信息,届时发送rtp时需要修改pt和ssrc + _type_to_track[m.type] = it->second.second; + } + } + _reader = _play_src->getRing()->attach(getPoller(), true); weak_ptr weak_self = static_pointer_cast(shared_from_this()); _reader->setReadCB([weak_self](const RtspMediaSource::RingDataType &pkt) { @@ -489,21 +504,6 @@ void WebRtcTransportImp::onStartWebRTC() { } strongSelf->onShutdown(SockException(Err_shutdown, "rtsp ring buffer detached")); }); - - RtcSession rtsp_send_sdp; - rtsp_send_sdp.loadFrom(_play_src->getSdp(), false); - for (auto &m : getSdp(SdpType::answer).media) { - if (m.type == TrackApplication) { - continue; - } - auto rtsp_media = rtsp_send_sdp.getMedia(m.type); - if (rtsp_media && getCodecId(rtsp_media->plan[0].codec) == getCodecId(m.plan[0].codec)) { - auto it = _pt_to_track.find(m.plan[0].pt); - CHECK(it != _pt_to_track.end()); - //记录发送rtp时约定的信息,届时发送rtp时需要修改pt和ssrc - _type_to_track[m.type] = it->second.second; - } - } } //使用完毕后,释放强引用,这样确保推流器断开后能及时注销媒体 _play_src = nullptr;