Commit f3f7a962 by xiongziliang

添加RtspMaker类

parent 92ea9567
//
// Created by xzl on 2018/10/24.
//
#include "RtspMaker.h"
#include "Common/Factory.h"
namespace ZL {
namespace Rtsp {
void RtspMaker::addTrack(const Track::Ptr &track, uint32_t ssrc, int mtu) {
if (track->getCodecId() == CodecInvalid) {
addTrack(std::make_shared<TitleSdp>(), ssrc, mtu);
} else {
Sdp::Ptr sdp = Factory::getSdpByTrack(track);
if (sdp) {
addTrack(sdp, ssrc, mtu);
}
}
}
} /* namespace Rtsp */
} /* namespace ZL */
\ No newline at end of file
//
// Created by xzl on 2018/10/24.
//
#ifndef ZLMEDIAKIT_RTSPMAKER_H
#define ZLMEDIAKIT_RTSPMAKER_H
#include "RtspSdp.h"
namespace ZL{
namespace Rtsp{
/**
* rtsp生成器
*/
class RtspMaker : public FrameRingInterface , public RtpRingInterface{
public:
/**
* 构成函数
*/
RtspMaker(){
_rtpRing = std::make_shared<RtpRingInterface::RingType>();
_frameRing = std::make_shared<FrameRingInterface::RingType>();
}
virtual ~RtspMaker(){}
/**
* 添加音视频或title 媒体
* @param sdp 媒体描述对象
* @param ssrc 媒体rtp ssrc
* @param mtu 媒体rtp mtu
*/
void addTrack(const Sdp::Ptr & sdp,uint32_t ssrc = 0,int mtu = 1400){
if(ssrc == 0){
ssrc = ((uint64_t) sdp.get()) & 0xFFFFFFFF;
}
sdp->createRtpEncoder(ssrc, mtu);
sdp->setFrameRing(_frameRing);
sdp->setRtpRing(_rtpRing);
_sdp_map[sdp->getTrackType()] = sdp;
}
/**
* 添加音视频或title 媒体
* @param track 媒体描述
* @param ssrc 媒体rtp ssrc
* @param mtu 媒体rtp mtu
*/
void addTrack(const Track::Ptr & track,uint32_t ssrc = 0,int mtu = 1400) ;
/**
* 获取完整的SDP字符串
* @return SDP字符串
*/
string getSdp() {
_StrPrinter printer;
for(auto &pr : _sdp_map){
printer << pr.second->getSdp() ;
}
return printer;
}
/**
* 写入帧数据然后打包rtp
* @param frame 帧数据
*/
void inputFrame(const Frame::Ptr &frame) override {
auto it = _sdp_map.find(frame->getTrackType());
if(it == _sdp_map.end()){
return ;
}
it->second->inputFrame(frame);
}
/**
* 也可以在外部打包好rtp然后再写入
* @param rtp rtp包
* @param key_pos 是否为关键帧的第一个rtp包
*/
bool inputRtp(const RtpPacket::Ptr &rtp, bool key_pos = true) override {
auto it = _sdp_map.find(rtp->getTrackType());
if(it == _sdp_map.end()){
return false;
}
return it->second->inputRtp(rtp,key_pos);
}
/**
* 获取rtp环形缓存
* @return
*/
RtpRingInterface::RingType::Ptr getRtpRing() const override{
return _rtpRing;
}
/**
* 获取帧环形缓存
* @return
*/
FrameRingInterface::RingType::Ptr getFrameRing() const override{
return _frameRing;
}
/**
* 设置帧环形缓存
* @param ring
*/
void setFrameRing(const FrameRingInterface::RingType::Ptr &ring) override{
_frameRing = ring;
for(auto &pr : _sdp_map){
pr.second->setFrameRing(ring);
}
}
/**
* 设置rtp环形缓存
* @param ring
*/
void setRtpRing(const RtpRingInterface::RingType::Ptr &ring) override{
_rtpRing = ring;
for(auto &pr : _sdp_map){
pr.second->setRtpRing(ring);
}
}
private:
map<int,Sdp::Ptr> _sdp_map;
RtpRingInterface::RingType::Ptr _rtpRing;
FrameRingInterface::RingType::Ptr _frameRing;
};
} /* namespace Rtsp */
} /* namespace ZL */
#endif //ZLMEDIAKIT_RTSPMAKER_H
......@@ -10,13 +10,5 @@ void Sdp::createRtpEncoder(uint32_t ssrc, int mtu) {
getTrackType() * 2);
}
void RtspMaker::addTrack(const Track::Ptr &track, uint32_t ssrc, int mtu) {
if (track->getCodecId() == CodecInvalid) {
addTrack(std::make_shared<TitleSdp>(), ssrc, mtu);
} else {
Sdp::Ptr sdp = Factory::getSdpByTrack(track);
if (sdp) {
addTrack(sdp, ssrc, mtu);
}
}
}
......@@ -2,16 +2,16 @@
// Created by xzl on 2018/9/18.
//
#ifndef ZLMEDIAKIT_RTSPMAKER_H
#define ZLMEDIAKIT_RTSPMAKER_H
#ifndef ZLMEDIAKIT_RTSPSDP_H
#define ZLMEDIAKIT_RTSPSDP_H
#include "RTP/H264RtpCodec.h"
#include "RTP/AACRtpCodec.h"
#include "Util/base64.h"
#include "Player/Track.h"
namespace ZL{
namespace Rtsp{
namespace ZL {
namespace Rtsp {
/**
* sdp基类
......@@ -260,131 +260,10 @@ private:
_StrPrinter _printer;
};
/**
* rtsp生成器
*/
class RtspMaker : public FrameRingInterface , public RtpRingInterface{
public:
/**
* 构成函数
*/
RtspMaker(){
_rtpRing = std::make_shared<RtpRingInterface::RingType>();
_frameRing = std::make_shared<FrameRingInterface::RingType>();
}
virtual ~RtspMaker(){}
/**
* 添加音视频或title 媒体
* @param sdp 媒体描述对象
* @param ssrc 媒体rtp ssrc
* @param mtu 媒体rtp mtu
*/
void addTrack(const Sdp::Ptr & sdp,uint32_t ssrc = 0,int mtu = 1400){
if(ssrc == 0){
ssrc = ((uint64_t) sdp.get()) & 0xFFFFFFFF;
}
sdp->createRtpEncoder(ssrc, mtu);
sdp->setFrameRing(_frameRing);
sdp->setRtpRing(_rtpRing);
_sdp_map[sdp->getTrackType()] = sdp;
}
/**
* 添加音视频或title 媒体
* @param track 媒体描述
* @param ssrc 媒体rtp ssrc
* @param mtu 媒体rtp mtu
*/
void addTrack(const Track::Ptr & track,uint32_t ssrc = 0,int mtu = 1400) ;
/**
* 获取完整的SDP字符串
* @return SDP字符串
*/
string getSdp() {
_StrPrinter printer;
for(auto &pr : _sdp_map){
printer << pr.second->getSdp() ;
}
return printer;
}
/**
* 写入帧数据然后打包rtp
* @param frame 帧数据
*/
void inputFrame(const Frame::Ptr &frame) override {
auto it = _sdp_map.find(frame->getTrackType());
if(it == _sdp_map.end()){
return ;
}
it->second->inputFrame(frame);
}
/**
* 也可以在外部打包好rtp然后再写入
* @param rtp rtp包
* @param key_pos 是否为关键帧的第一个rtp包
*/
bool inputRtp(const RtpPacket::Ptr &rtp, bool key_pos = true) override {
auto it = _sdp_map.find(rtp->getTrackType());
if(it == _sdp_map.end()){
return false;
}
return it->second->inputRtp(rtp,key_pos);
}
/**
* 获取rtp环形缓存
* @return
*/
RtpRingInterface::RingType::Ptr getRtpRing() const override{
return _rtpRing;
}
/**
* 获取帧环形缓存
* @return
*/
FrameRingInterface::RingType::Ptr getFrameRing() const override{
return _frameRing;
}
/**
* 设置帧环形缓存
* @param ring
*/
void setFrameRing(const FrameRingInterface::RingType::Ptr &ring) override{
_frameRing = ring;
for(auto &pr : _sdp_map){
pr.second->setFrameRing(ring);
}
}
/**
* 设置rtp环形缓存
* @param ring
*/
void setRtpRing(const RtpRingInterface::RingType::Ptr &ring) override{
_rtpRing = ring;
for(auto &pr : _sdp_map){
pr.second->setRtpRing(ring);
}
}
private:
map<int,Sdp::Ptr> _sdp_map;
RtpRingInterface::RingType::Ptr _rtpRing;
FrameRingInterface::RingType::Ptr _frameRing;
};
}
}
} /* namespace Rtsp */
} /* namespace ZL */
#endif //ZLMEDIAKIT_RTSPMAKER_H
#endif //ZLMEDIAKIT_RTSPSDP_H
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论