完成Track对象与SDP对象的转换

This commit is contained in:
xiongziliang 2018-10-23 22:16:54 +08:00
parent be9af50dbb
commit b6c64fb4ed
4 changed files with 95 additions and 39 deletions

View File

@ -95,7 +95,6 @@ public:
virtual void inputFrame(const Frame::Ptr &frame) = 0;
};
class FrameRing : public FrameRingInterface{
public:
typedef std::shared_ptr<FrameRing> Ptr;
@ -132,6 +131,53 @@ protected:
RingType::Ptr _frameRing;
};
class FrameRingInterfaceDelegate : public FrameRingInterface {
public:
typedef std::shared_ptr<FrameRingInterfaceDelegate> Ptr;
FrameRingInterfaceDelegate(){
_delegate = std::make_shared<FrameRing>();
}
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
*/

View File

@ -156,46 +156,12 @@ protected:
ResourcePool<RtpPacket> m_rtpPool;
};
class RtpCodec : public RtpRing, public FrameRingInterface , public CodecInfo{
class RtpCodec : public RtpRing, public FrameRingInterfaceDelegate , public CodecInfo{
public:
typedef std::shared_ptr<RtpCodec> 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;
};

38
src/Rtsp/RtspEncoder.cpp Normal file
View File

@ -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<H264Track>(track);
if(!h264Track){
return nullptr;
}
return std::make_shared<H264Sdp>(h264Track->getSps(),h264Track->getPps());
}
case CodecAAC:{
AACTrack::Ptr aacTrack = dynamic_pointer_cast<AACTrack>(track);
if(!aacTrack){
return nullptr;
}
return std::make_shared<AACSdp>(aacTrack->getAacCfg(),aacTrack->getAudioSampleRate());
}
default:
return nullptr;
}
}
}
}

View File

@ -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(){}
/**