From be9af50dbba6e084b48518243e4bc52772b7f6bb Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Tue, 23 Oct 2018 21:55:09 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90Rtp=E8=A7=A3=E7=A0=81?= =?UTF-8?q?=E5=99=A8=E4=B8=8ETrack=E4=B9=8B=E9=97=B4=E7=9A=84=E5=B8=A7?= =?UTF-8?q?=E6=95=B0=E6=8D=AE=E4=BC=A0=E9=80=92?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/RTP/RtpCodec.h | 39 ++++++++++++++++++++++++++++++++++++++- src/Rtsp/RtpParser.cpp | 12 ++++++++++++ 2 files changed, 50 insertions(+), 1 deletion(-) diff --git a/src/RTP/RtpCodec.h b/src/RTP/RtpCodec.h index d6808da9..0253c737 100644 --- a/src/RTP/RtpCodec.h +++ b/src/RTP/RtpCodec.h @@ -156,12 +156,46 @@ protected: ResourcePool m_rtpPool; }; -class RtpCodec : public RtpRing, public FrameRing , public CodecInfo{ +class RtpCodec : public RtpRing, public FrameRingInterface , public CodecInfo{ public: typedef std::shared_ptr Ptr; RtpCodec(){} virtual ~RtpCodec(){} + void setDelegate(const FrameRingInterface::Ptr &delegate){ + _delegate = delegate; + } + /** + * 获取帧环形缓存 + * @return + */ + FrameRingInterface::RingType::Ptr getFrameRing() const override { + if(_delegate){ + return _delegate->getFrameRing(); + } + return nullptr; + } + + /** + * 设置帧环形缓存 + * @param ring + */ + void setFrameRing(const FrameRingInterface::RingType::Ptr &ring) override { + if(_delegate){ + _delegate->setFrameRing(ring); + } + } + + /** + * 写入帧数据 + * @param frame 帧 + */ + void inputFrame(const Frame::Ptr &frame) override{ + if(_delegate){ + _delegate->inputFrame(frame); + } + } + /** * 根据CodecId生成Rtp打包器 * @param codecId @@ -186,6 +220,9 @@ public: * @return */ static Ptr getRtpDecoderById(CodecId codecId,uint32_t ui32SampleRate); + +private: + FrameRingInterface::Ptr _delegate; }; diff --git a/src/Rtsp/RtpParser.cpp b/src/Rtsp/RtpParser.cpp index 8e28e3b9..15c73b3e 100644 --- a/src/Rtsp/RtpParser.cpp +++ b/src/Rtsp/RtpParser.cpp @@ -96,16 +96,28 @@ inline bool RtpParser::inputAudio(const RtpPacket::Ptr &rtp) { } inline void RtpParser::onGetAudioTrack(const RtspTrack& audio) { + //生成Track对象 _audioTrack = dynamic_pointer_cast(Track::getTrackBySdp(audio.trackSdp)); if(_audioTrack){ + //生成RtpCodec对象以便解码rtp _audioRtpDecoder = RtpCodec::getRtpDecoderById(_audioTrack->getCodecId(),_audioTrack->getAudioSampleRate()); + if(_audioRtpDecoder){ + //设置rtp解码器代理,生成的frame写入该Track + _audioRtpDecoder->setDelegate(_audioTrack); + } } } inline void RtpParser::onGetVideoTrack(const RtspTrack& video) { + //生成Track对象 _videoTrack = dynamic_pointer_cast(Track::getTrackBySdp(video.trackSdp)); if(_videoTrack){ + //生成RtpCodec对象以便解码rtp _videoRtpDecoder = RtpCodec::getRtpDecoderById(_videoTrack->getCodecId(),90000); + if(_videoRtpDecoder){ + //设置rtp解码器代理,生成的frame写入该Track + _videoRtpDecoder->setDelegate(_videoTrack); + } } }