From 3c935e7fddc951d4c27bf769adb35f6be1478242 Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Mon, 5 Apr 2021 00:06:21 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- webrtc/Sdp.cpp | 14 ++++++++++++-- webrtc/WebRtcTransport.cpp | 26 ++++++-------------------- webrtc/WebRtcTransport.h | 1 - 3 files changed, 18 insertions(+), 23 deletions(-) diff --git a/webrtc/Sdp.cpp b/webrtc/Sdp.cpp index 91d822bf..42e85241 100644 --- a/webrtc/Sdp.cpp +++ b/webrtc/Sdp.cpp @@ -1496,8 +1496,18 @@ void RtcConfigure::setPlayRtspInfo(const string &sdp){ session.loadFrom(sdp, false); for (auto &m : session.media) { switch (m.type) { - case TrackVideo : _rtsp_video_plan = std::make_shared(m.plan[0]); break; - case TrackAudio : _rtsp_audio_plan = std::make_shared(m.plan[0]); break; + case TrackVideo : { + _rtsp_video_plan = std::make_shared(m.plan[0]); + video.preferred_codec.clear(); + video.preferred_codec.emplace_back(getCodecId(_rtsp_video_plan->codec)); + break; + } + case TrackAudio : { + _rtsp_audio_plan = std::make_shared(m.plan[0]); + audio.preferred_codec.clear(); + audio.preferred_codec.emplace_back(getCodecId(_rtsp_audio_plan->codec)); + break; + } default: break; } } diff --git a/webrtc/WebRtcTransport.cpp b/webrtc/WebRtcTransport.cpp index 7aa6417b..2dbbef3b 100644 --- a/webrtc/WebRtcTransport.cpp +++ b/webrtc/WebRtcTransport.cpp @@ -298,11 +298,14 @@ void WebRtcTransportImp::onCheckSdp(SdpType type, RtcSession &sdp) const{ return; } - //添加answer sdp的ssrc信息,并且记录发送rtp的pt + RtcSession rtsp_send_sdp; + rtsp_send_sdp.loadFrom(_src->getSdp(), false); + for (auto &m : sdp.media) { if (m.type == TrackApplication) { continue; } + //添加answer sdp的ssrc信息 m.rtp_ssrc.ssrc = _src->getSsrc(m.type); m.rtp_ssrc.cname = RTP_CNAME; //todo 先屏蔽rtx,因为chrome报错 @@ -310,8 +313,9 @@ void WebRtcTransportImp::onCheckSdp(SdpType type, RtcSession &sdp) const{ m.rtx_ssrc.ssrc = RTX_SSRC_OFFSET + m.rtp_ssrc.ssrc; m.rtx_ssrc.cname = RTX_CNAME; } - auto rtsp_media = _rtsp_send_sdp.getMedia(m.type); + auto rtsp_media = rtsp_send_sdp.getMedia(m.type); if (rtsp_media && getCodecId(rtsp_media->plan[0].codec) == getCodecId(m.plan[0].codec)) { + //记录发送rtp的pt _send_rtp_pt[m.type] = m.plan[0].pt; } } @@ -325,24 +329,6 @@ void WebRtcTransportImp::onRtcConfigure(RtcConfigure &configure) const { configure.video.direction = RtpDirection::sendonly; configure.audio.direction = RtpDirection::sendonly; configure.setPlayRtspInfo(_src->getSdp()); - _rtsp_send_sdp.loadFrom(_src->getSdp(), false); - //根据rtsp流的相关信息,设置rtc最佳编码 - for (auto &m : _rtsp_send_sdp.media) { - switch (m.type) { - case TrackVideo: { - configure.video.preferred_codec.clear(); - configure.video.preferred_codec.emplace_back(getCodecId(m.plan[0].codec)); - break; - } - case TrackAudio: { - configure.audio.preferred_codec.clear(); - configure.audio.preferred_codec.emplace_back(getCodecId(m.plan[0].codec)); - break; - } - default: - break; - } - } } else { //这是推流 configure.video.direction = RtpDirection::recvonly; diff --git a/webrtc/WebRtcTransport.h b/webrtc/WebRtcTransport.h index 000c4cc7..28086a01 100644 --- a/webrtc/WebRtcTransport.h +++ b/webrtc/WebRtcTransport.h @@ -159,7 +159,6 @@ private: Socket::Ptr _socket; RtcSession _answer_sdp; RtspMediaSource::Ptr _src; - mutable RtcSession _rtsp_send_sdp; RtspMediaSource::RingType::RingReader::Ptr _reader; unordered_map _rtp_info_pt; unordered_map _rtp_info_ssrc;