优化代码

This commit is contained in:
xiongziliang 2021-04-05 00:06:21 +08:00
parent 6070654860
commit 3c935e7fdd
3 changed files with 18 additions and 23 deletions

View File

@ -1496,8 +1496,18 @@ void RtcConfigure::setPlayRtspInfo(const string &sdp){
session.loadFrom(sdp, false); session.loadFrom(sdp, false);
for (auto &m : session.media) { for (auto &m : session.media) {
switch (m.type) { switch (m.type) {
case TrackVideo : _rtsp_video_plan = std::make_shared<RtcCodecPlan>(m.plan[0]); break; case TrackVideo : {
case TrackAudio : _rtsp_audio_plan = std::make_shared<RtcCodecPlan>(m.plan[0]); break; _rtsp_video_plan = std::make_shared<RtcCodecPlan>(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<RtcCodecPlan>(m.plan[0]);
audio.preferred_codec.clear();
audio.preferred_codec.emplace_back(getCodecId(_rtsp_audio_plan->codec));
break;
}
default: break; default: break;
} }
} }

View File

@ -298,11 +298,14 @@ void WebRtcTransportImp::onCheckSdp(SdpType type, RtcSession &sdp) const{
return; return;
} }
//添加answer sdp的ssrc信息并且记录发送rtp的pt RtcSession rtsp_send_sdp;
rtsp_send_sdp.loadFrom(_src->getSdp(), false);
for (auto &m : sdp.media) { for (auto &m : sdp.media) {
if (m.type == TrackApplication) { if (m.type == TrackApplication) {
continue; continue;
} }
//添加answer sdp的ssrc信息
m.rtp_ssrc.ssrc = _src->getSsrc(m.type); m.rtp_ssrc.ssrc = _src->getSsrc(m.type);
m.rtp_ssrc.cname = RTP_CNAME; m.rtp_ssrc.cname = RTP_CNAME;
//todo 先屏蔽rtx因为chrome报错 //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.ssrc = RTX_SSRC_OFFSET + m.rtp_ssrc.ssrc;
m.rtx_ssrc.cname = RTX_CNAME; 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)) { 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; _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.video.direction = RtpDirection::sendonly;
configure.audio.direction = RtpDirection::sendonly; configure.audio.direction = RtpDirection::sendonly;
configure.setPlayRtspInfo(_src->getSdp()); 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 { } else {
//这是推流 //这是推流
configure.video.direction = RtpDirection::recvonly; configure.video.direction = RtpDirection::recvonly;

View File

@ -159,7 +159,6 @@ private:
Socket::Ptr _socket; Socket::Ptr _socket;
RtcSession _answer_sdp; RtcSession _answer_sdp;
RtspMediaSource::Ptr _src; RtspMediaSource::Ptr _src;
mutable RtcSession _rtsp_send_sdp;
RtspMediaSource::RingType::RingReader::Ptr _reader; RtspMediaSource::RingType::RingReader::Ptr _reader;
unordered_map<uint8_t, RtpPayloadInfo> _rtp_info_pt; unordered_map<uint8_t, RtpPayloadInfo> _rtp_info_pt;
unordered_map<uint32_t, RtpPayloadInfo*> _rtp_info_ssrc; unordered_map<uint32_t, RtpPayloadInfo*> _rtp_info_ssrc;