添加RtspMaker类

This commit is contained in:
xiongziliang 2018-10-24 09:45:57 +08:00
parent 92ea956730
commit f3f7a96281
4 changed files with 169 additions and 138 deletions

23
src/Rtsp/RtspMaker.cpp Normal file
View File

@ -0,0 +1,23 @@
//
// 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 */

137
src/Rtsp/RtspMaker.h Normal file
View File

@ -0,0 +1,137 @@
//
// 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

View File

@ -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);
}
}
}

View File

@ -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