From b6c64fb4edb9e3d2e05b1edb1e67d54fa22bf7ee Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Tue, 23 Oct 2018 22:16:54 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=8C=E6=88=90Track=E5=AF=B9=E8=B1=A1?= =?UTF-8?q?=E4=B8=8ESDP=E5=AF=B9=E8=B1=A1=E7=9A=84=E8=BD=AC=E6=8D=A2?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Player/Frame.h | 48 +++++++++++++++++++++++++++++++++++++++- src/RTP/RtpCodec.h | 39 +------------------------------- src/Rtsp/RtspEncoder.cpp | 38 +++++++++++++++++++++++++++++++ src/Rtsp/RtspEncoder.h | 9 ++++++++ 4 files changed, 95 insertions(+), 39 deletions(-) create mode 100644 src/Rtsp/RtspEncoder.cpp diff --git a/src/Player/Frame.h b/src/Player/Frame.h index e2f24ac9..36f22d98 100644 --- a/src/Player/Frame.h +++ b/src/Player/Frame.h @@ -95,7 +95,6 @@ public: virtual void inputFrame(const Frame::Ptr &frame) = 0; }; - class FrameRing : public FrameRingInterface{ public: typedef std::shared_ptr Ptr; @@ -132,6 +131,53 @@ protected: RingType::Ptr _frameRing; }; +class FrameRingInterfaceDelegate : public FrameRingInterface { +public: + typedef std::shared_ptr Ptr; + + FrameRingInterfaceDelegate(){ + _delegate = std::make_shared(); + } + virtual ~FrameRingInterfaceDelegate(){} + + 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); + } + } +private: + FrameRingInterface::Ptr _delegate; +}; + + /** * 264帧类 */ diff --git a/src/RTP/RtpCodec.h b/src/RTP/RtpCodec.h index 0253c737..8a1e61a0 100644 --- a/src/RTP/RtpCodec.h +++ b/src/RTP/RtpCodec.h @@ -156,46 +156,12 @@ protected: ResourcePool m_rtpPool; }; -class RtpCodec : public RtpRing, public FrameRingInterface , public CodecInfo{ +class RtpCodec : public RtpRing, public FrameRingInterfaceDelegate , 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 @@ -220,9 +186,6 @@ public: * @return */ static Ptr getRtpDecoderById(CodecId codecId,uint32_t ui32SampleRate); - -private: - FrameRingInterface::Ptr _delegate; }; diff --git a/src/Rtsp/RtspEncoder.cpp b/src/Rtsp/RtspEncoder.cpp new file mode 100644 index 00000000..55a1e4d2 --- /dev/null +++ b/src/Rtsp/RtspEncoder.cpp @@ -0,0 +1,38 @@ +// +// Created by xzl on 2018/10/23. +// +#include "RtspEncoder.h" + +namespace ZL{ +namespace Rtsp{ + + +Sdp::Ptr Sdp::getSdpByTrack(const Track::Ptr &track) { + switch (track->getCodecId()){ + case CodecH264:{ + H264Track::Ptr h264Track = dynamic_pointer_cast(track); + if(!h264Track){ + return nullptr; + } + return std::make_shared(h264Track->getSps(),h264Track->getPps()); + } + + case CodecAAC:{ + AACTrack::Ptr aacTrack = dynamic_pointer_cast(track); + if(!aacTrack){ + return nullptr; + } + return std::make_shared(aacTrack->getAacCfg(),aacTrack->getAudioSampleRate()); + } + + default: + return nullptr; + } +} + + + + +} +} + diff --git a/src/Rtsp/RtspEncoder.h b/src/Rtsp/RtspEncoder.h index d80e7d61..dc9e180d 100644 --- a/src/Rtsp/RtspEncoder.h +++ b/src/Rtsp/RtspEncoder.h @@ -8,6 +8,7 @@ #include "RTP/H264RtpCodec.h" #include "RTP/AACRtpCodec.h" #include "Util/base64.h" +#include "Player/Track.h" namespace ZL{ namespace Rtsp{ @@ -28,6 +29,14 @@ public: _sample_rate = sample_rate; _playload_type = playload_type; } + + /** + * 根据Track生成SDP对象 + * @param track 媒体信息 + * @return 返回sdp对象 + */ + static Ptr getSdpByTrack(const Track::Ptr &track); + virtual ~Sdp(){} /**