From 412d280cd7e5b94176575b70ae899bb9a4ff0aab Mon Sep 17 00:00:00 2001 From: ziyue <1213642868@qq.com> Date: Mon, 10 Jan 2022 17:34:25 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8D=E6=96=AD=E8=BF=9E=E7=BB=AD?= =?UTF-8?q?=E6=8E=A8=E8=BD=AC=E5=8D=8F=E8=AE=AE=E5=A4=B1=E6=95=88=E7=9A=84?= =?UTF-8?q?bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Rtmp/RtmpDemuxer.cpp | 6 ++++++ src/Rtsp/RtspDemuxer.cpp | 26 ++++++++++++++++---------- src/Rtsp/RtspDemuxer.h | 4 ++-- src/Rtsp/RtspMediaSourceImp.h | 3 +++ 4 files changed, 27 insertions(+), 12 deletions(-) diff --git a/src/Rtmp/RtmpDemuxer.cpp b/src/Rtmp/RtmpDemuxer.cpp index 08edbdfa..c7c3dd18 100644 --- a/src/Rtmp/RtmpDemuxer.cpp +++ b/src/Rtmp/RtmpDemuxer.cpp @@ -131,6 +131,9 @@ void RtmpDemuxer::inputRtmp(const RtmpPacket::Ptr &pkt) { } void RtmpDemuxer::makeVideoTrack(const AMFValue &videoCodec, int bit_rate) { + if (_video_rtmp_decoder) { + return; + } //生成Track对象 _video_track = dynamic_pointer_cast(Factory::getVideoTrackByAmf(videoCodec)); if (!_video_track) { @@ -151,6 +154,9 @@ void RtmpDemuxer::makeVideoTrack(const AMFValue &videoCodec, int bit_rate) { } void RtmpDemuxer::makeAudioTrack(const AMFValue &audioCodec,int sample_rate, int channels, int sample_bit, int bit_rate) { + if (_audio_rtmp_decoder) { + return; + } //生成Track对象 _audio_track = dynamic_pointer_cast(Factory::getAudioTrackByAmf(audioCodec, sample_rate, channels, sample_bit)); if (!_audio_track) { diff --git a/src/Rtsp/RtspDemuxer.cpp b/src/Rtsp/RtspDemuxer.cpp index ca4c835b..c380252e 100644 --- a/src/Rtsp/RtspDemuxer.cpp +++ b/src/Rtsp/RtspDemuxer.cpp @@ -54,14 +54,14 @@ float RtspDemuxer::getDuration() const { bool RtspDemuxer::inputRtp(const RtpPacket::Ptr &rtp) { switch (rtp->type) { case TrackVideo: { - if (_videoRtpDecoder) { - return _videoRtpDecoder->inputRtp(rtp, true); + if (_video_rtp_decoder) { + return _video_rtp_decoder->inputRtp(rtp, true); } return false; } case TrackAudio: { - if (_audioRtpDecoder) { - _audioRtpDecoder->inputRtp(rtp, false); + if (_audio_rtp_decoder) { + _audio_rtp_decoder->inputRtp(rtp, false); return false; } return false; @@ -81,6 +81,9 @@ static void setBitRate(const SdpTrack::Ptr &sdp, const Track::Ptr &track) { } void RtspDemuxer::makeAudioTrack(const SdpTrack::Ptr &audio) { + if (_audio_rtp_decoder) { + return; + } //生成Track对象 _audio_track = dynamic_pointer_cast(Factory::getTrackBySdp(audio)); if (!_audio_track) { @@ -88,18 +91,21 @@ void RtspDemuxer::makeAudioTrack(const SdpTrack::Ptr &audio) { } setBitRate(audio, _audio_track); //生成RtpCodec对象以便解码rtp - _audioRtpDecoder = Factory::getRtpDecoderByTrack(_audio_track); - if (!_audioRtpDecoder) { + _audio_rtp_decoder = Factory::getRtpDecoderByTrack(_audio_track); + if (!_audio_rtp_decoder) { //找不到相应的rtp解码器,该track无效 _audio_track.reset(); return; } //设置rtp解码器代理,生成的frame写入该Track - _audioRtpDecoder->addDelegate(_audio_track); + _audio_rtp_decoder->addDelegate(_audio_track); addTrack(_audio_track); } void RtspDemuxer::makeVideoTrack(const SdpTrack::Ptr &video) { + if (_video_rtp_decoder) { + return; + } //生成Track对象 _video_track = dynamic_pointer_cast(Factory::getTrackBySdp(video)); if (!_video_track) { @@ -107,14 +113,14 @@ void RtspDemuxer::makeVideoTrack(const SdpTrack::Ptr &video) { } setBitRate(video, _video_track); //生成RtpCodec对象以便解码rtp - _videoRtpDecoder = Factory::getRtpDecoderByTrack(_video_track); - if (!_videoRtpDecoder) { + _video_rtp_decoder = Factory::getRtpDecoderByTrack(_video_track); + if (!_video_rtp_decoder) { //找不到相应的rtp解码器,该track无效 _video_track.reset(); return; } //设置rtp解码器代理,生成的frame写入该Track - _videoRtpDecoder->addDelegate(_video_track); + _video_rtp_decoder->addDelegate(_video_track); addTrack(_video_track); } diff --git a/src/Rtsp/RtspDemuxer.h b/src/Rtsp/RtspDemuxer.h index abdd1937..865b84be 100644 --- a/src/Rtsp/RtspDemuxer.h +++ b/src/Rtsp/RtspDemuxer.h @@ -54,8 +54,8 @@ private: float _duration = 0; AudioTrack::Ptr _audio_track; VideoTrack::Ptr _video_track; - RtpCodec::Ptr _audioRtpDecoder; - RtpCodec::Ptr _videoRtpDecoder; + RtpCodec::Ptr _audio_rtp_decoder; + RtpCodec::Ptr _video_rtp_decoder; }; } /* namespace mediakit */ diff --git a/src/Rtsp/RtspMediaSourceImp.h b/src/Rtsp/RtspMediaSourceImp.h index ab393502..cbc1623b 100644 --- a/src/Rtsp/RtspMediaSourceImp.h +++ b/src/Rtsp/RtspMediaSourceImp.h @@ -40,6 +40,9 @@ public: * 设置sdp */ void setSdp(const string &strSdp) override { + if (!getSdp().empty()) { + return; + } _demuxer->loadSdp(strSdp); RtspMediaSource::setSdp(strSdp); }