2018-10-25 10:00:17 +08:00
|
|
|
|
/*
|
2020-04-04 20:30:09 +08:00
|
|
|
|
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
|
|
|
|
*
|
2021-01-17 18:31:50 +08:00
|
|
|
|
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
2020-04-04 20:30:09 +08:00
|
|
|
|
*
|
|
|
|
|
* Use of this source code is governed by MIT license that can be found in the
|
|
|
|
|
* LICENSE file in the root of the source tree. All contributing project authors
|
|
|
|
|
* may be found in the AUTHORS file in the root of the source tree.
|
|
|
|
|
*/
|
2018-10-24 09:45:57 +08:00
|
|
|
|
|
2018-10-24 18:09:54 +08:00
|
|
|
|
#include "RtspMuxer.h"
|
2018-10-30 14:59:42 +08:00
|
|
|
|
#include "Extension/Factory.h"
|
2018-10-24 09:45:57 +08:00
|
|
|
|
|
2018-10-24 17:17:55 +08:00
|
|
|
|
namespace mediakit {
|
2018-10-24 09:45:57 +08:00
|
|
|
|
|
2018-10-27 22:40:44 +08:00
|
|
|
|
RtspMuxer::RtspMuxer(const TitleSdp::Ptr &title){
|
|
|
|
|
if(!title){
|
|
|
|
|
_sdp = std::make_shared<TitleSdp>()->getSdp();
|
|
|
|
|
} else{
|
|
|
|
|
_sdp = title->getSdp();
|
2018-10-26 17:14:39 +08:00
|
|
|
|
}
|
2019-12-26 09:43:44 +08:00
|
|
|
|
_rtpRing = std::make_shared<RtpRing::RingType>();
|
2018-10-27 22:40:44 +08:00
|
|
|
|
}
|
2018-10-25 13:43:41 +08:00
|
|
|
|
|
2019-12-03 12:32:57 +08:00
|
|
|
|
void RtspMuxer::addTrack(const Track::Ptr &track) {
|
2019-08-30 11:17:27 +08:00
|
|
|
|
//根据track生成sdp
|
2019-06-28 16:12:39 +08:00
|
|
|
|
Sdp::Ptr sdp = track->getSdp();
|
2018-10-27 22:40:44 +08:00
|
|
|
|
if (!sdp) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2019-12-03 12:32:57 +08:00
|
|
|
|
|
|
|
|
|
auto &encoder = _encoder[track->getTrackType()];
|
|
|
|
|
encoder = Factory::getRtpEncoderBySdp(sdp);
|
2018-10-27 22:40:44 +08:00
|
|
|
|
if (!encoder) {
|
|
|
|
|
return;
|
2018-10-25 11:53:45 +08:00
|
|
|
|
}
|
2019-12-03 12:32:57 +08:00
|
|
|
|
|
|
|
|
|
//设置rtp输出环形缓存
|
|
|
|
|
encoder->setRtpRing(_rtpRing);
|
|
|
|
|
|
2018-10-27 22:40:44 +08:00
|
|
|
|
//添加其sdp
|
|
|
|
|
_sdp.append(sdp->getSdp());
|
2018-10-25 11:53:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-03 12:32:57 +08:00
|
|
|
|
void RtspMuxer::inputFrame(const Frame::Ptr &frame) {
|
|
|
|
|
auto &encoder = _encoder[frame->getTrackType()];
|
|
|
|
|
if(encoder){
|
|
|
|
|
encoder->inputFrame(frame);
|
2018-10-25 11:53:45 +08:00
|
|
|
|
}
|
2019-12-03 12:32:57 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
string RtspMuxer::getSdp() {
|
2018-10-25 13:43:41 +08:00
|
|
|
|
return _sdp;
|
2018-10-25 11:53:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
2019-12-26 09:43:44 +08:00
|
|
|
|
RtpRing::RingType::Ptr RtspMuxer::getRtpRing() const {
|
2018-10-25 11:53:45 +08:00
|
|
|
|
return _rtpRing;
|
|
|
|
|
}
|
|
|
|
|
|
2019-12-03 12:32:57 +08:00
|
|
|
|
void RtspMuxer::resetTracks() {
|
|
|
|
|
_sdp.clear();
|
|
|
|
|
for(auto &encoder : _encoder){
|
|
|
|
|
encoder = nullptr;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2018-10-27 22:40:44 +08:00
|
|
|
|
|
2018-10-24 17:17:55 +08:00
|
|
|
|
} /* namespace mediakit */
|