mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-10-31 08:39:34 +08:00
完善Rtsp复用器
This commit is contained in:
parent
d1348f3846
commit
413b18521d
@ -33,15 +33,22 @@ void RtspMuxer::addTrack(const Track::Ptr &track, uint32_t ssrc, int mtu) {
|
|||||||
//记录该Track
|
//记录该Track
|
||||||
auto codec_id = track->getCodecId();
|
auto codec_id = track->getCodecId();
|
||||||
_track_map[codec_id] = track;
|
_track_map[codec_id] = track;
|
||||||
|
|
||||||
auto lam = [this,ssrc,mtu,track](){
|
auto lam = [this,ssrc,mtu,track](){
|
||||||
|
//异步生成rtp编码器
|
||||||
|
//根据track生产sdp
|
||||||
Sdp::Ptr sdp = Factory::getSdpByTrack(track);
|
Sdp::Ptr sdp = Factory::getSdpByTrack(track);
|
||||||
if (!sdp) {
|
if (!sdp) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// 根据sdp生成rtp编码器
|
||||||
auto encoder = sdp->createRtpEncoder(ssrc ? ssrc : ((uint64_t) sdp.get()) & 0xFFFFFFFF, mtu);
|
auto encoder = sdp->createRtpEncoder(ssrc ? ssrc : ((uint64_t) sdp.get()) & 0xFFFFFFFF, mtu);
|
||||||
if (!encoder) {
|
if (!encoder) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
//添加其sdp
|
||||||
|
_sdp.append(sdp->getSdp());
|
||||||
//设置Track的代理,这样输入frame至Track时,最终数据将输出到RtpEncoder中
|
//设置Track的代理,这样输入frame至Track时,最终数据将输出到RtpEncoder中
|
||||||
track->setDelegate(encoder);
|
track->setDelegate(encoder);
|
||||||
//rtp编码器共用同一个环形缓存
|
//rtp编码器共用同一个环形缓存
|
||||||
@ -59,12 +66,7 @@ string RtspMuxer::getSdp() {
|
|||||||
//尚未就绪
|
//尚未就绪
|
||||||
return "";
|
return "";
|
||||||
}
|
}
|
||||||
|
return _sdp;
|
||||||
// _StrPrinter printer;
|
|
||||||
// for (auto &pr : _sdp_map) {
|
|
||||||
// printer << pr.second->getSdp();
|
|
||||||
// }
|
|
||||||
// return printer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -80,7 +82,7 @@ void RtspMuxer::inputFrame(const Frame::Ptr &frame) {
|
|||||||
it->second->inputFrame(frame);
|
it->second->inputFrame(frame);
|
||||||
|
|
||||||
if(!ready && it->second->ready()){
|
if(!ready && it->second->ready()){
|
||||||
//Track又未就绪状态装换成就绪状态,我们就生成sdp以及rtp编码器
|
//Track由未就绪状态装换成就绪状态,我们就生成sdp以及rtp编码器
|
||||||
auto it_callback = _trackReadyCallback.find(codec_id);
|
auto it_callback = _trackReadyCallback.find(codec_id);
|
||||||
if(it_callback != _trackReadyCallback.end()){
|
if(it_callback != _trackReadyCallback.end()){
|
||||||
it_callback->second();
|
it_callback->second();
|
||||||
|
@ -38,7 +38,8 @@ public:
|
|||||||
/**
|
/**
|
||||||
* 构造函数
|
* 构造函数
|
||||||
*/
|
*/
|
||||||
RtspMuxer(){
|
RtspMuxer(const TitleSdp::Ptr &title = std::make_shared<TitleSdp>()){
|
||||||
|
_sdp = title->getSdp();
|
||||||
_rtpRing = std::make_shared<RtpRingInterface::RingType>();
|
_rtpRing = std::make_shared<RtpRingInterface::RingType>();
|
||||||
}
|
}
|
||||||
virtual ~RtspMuxer(){}
|
virtual ~RtspMuxer(){}
|
||||||
@ -79,6 +80,7 @@ private:
|
|||||||
map<int,Track::Ptr> _track_map;
|
map<int,Track::Ptr> _track_map;
|
||||||
map<int,function<void()> > _trackReadyCallback;
|
map<int,function<void()> > _trackReadyCallback;
|
||||||
RtpRingInterface::RingType::Ptr _rtpRing;
|
RtpRingInterface::RingType::Ptr _rtpRing;
|
||||||
|
string _sdp;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user