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;