Commit 3630839b by xiongziliang

关闭转协议后,将关闭解复用以提供性能

parent 02700579
......@@ -22,17 +22,21 @@ MultiMuxerPrivate::MultiMuxerPrivate(const string &vhost,
bool enable_mp4) {
if (enable_rtmp) {
_rtmp = std::make_shared<RtmpMediaSourceMuxer>(vhost, app, stream, std::make_shared<TitleMeta>(dur_sec));
_enable_rtxp = true;
}
if (enable_rtsp) {
_rtsp = std::make_shared<RtspMediaSourceMuxer>(vhost, app, stream, std::make_shared<TitleSdp>(dur_sec));
_enable_rtxp = true;
}
if (enable_hls) {
_hls = Recorder::createRecorder(Recorder::type_hls, vhost, app, stream);
_enable_record = true;
}
if (enable_mp4) {
_mp4 = Recorder::createRecorder(Recorder::type_mp4, vhost, app, stream);
_enable_record = true;
}
}
......@@ -102,6 +106,7 @@ bool MultiMuxerPrivate::setupRecord(MediaSource &sender, Recorder::type type, bo
//停止录制
_hls = nullptr;
}
_enable_record = _hls || _mp4;
return true;
}
case Recorder::type_mp4 : {
......@@ -112,10 +117,10 @@ bool MultiMuxerPrivate::setupRecord(MediaSource &sender, Recorder::type type, bo
//停止录制
_mp4 = nullptr;
}
_enable_record = _hls || _mp4;
return true;
}
default:
return false;
default : return false;
}
}
......@@ -163,6 +168,10 @@ void MultiMuxerPrivate::onTrackReady(const Track::Ptr &track) {
}
}
bool MultiMuxerPrivate::isEnabled(){
return _enable_rtxp || _enable_record;
}
void MultiMuxerPrivate::onTrackFrame(const Frame::Ptr &frame) {
if (_rtmp) {
_rtmp->inputFrame(frame);
......@@ -293,4 +302,9 @@ void MultiMediaSourceMuxer::inputFrame(const Frame::Ptr &frame) {
_muxer->inputFrame(frame);
}
bool MultiMediaSourceMuxer::isEnabled(){
return _muxer->isEnabled();
}
}//namespace mediakit
\ No newline at end of file
......@@ -45,6 +45,7 @@ private:
void setTrackListener(Listener *listener);
bool setupRecord(MediaSource &sender, Recorder::type type, bool start, const string &custom_path);
bool isRecording(MediaSource &sender, Recorder::type type);
bool isEnabled();
private:
void onTrackReady(const Track::Ptr & track) override;
void onTrackFrame(const Frame::Ptr &frame) override;
......@@ -57,6 +58,8 @@ private:
MediaSinkInterface::Ptr _mp4;
Listener *_listener = nullptr;
std::weak_ptr<MediaSourceEvent> _meida_listener;
bool _enable_rtxp = false;
bool _enable_record = false;
};
class MultiMediaSourceMuxer : public MediaSourceEvent, public MediaSinkInterface, public TrackSource, public std::enable_shared_from_this<MultiMediaSourceMuxer>{
......@@ -167,6 +170,11 @@ public:
* @param frame 帧
*/
void inputFrame(const Frame::Ptr &frame) override;
/**
* 判断是否生效(是否正在转其他协议)
*/
bool isEnabled();
private:
MultiMuxerPrivate::Ptr _muxer;
std::weak_ptr<MediaSourceEvent> _listener;
......
......@@ -57,7 +57,14 @@ public:
* 输入rtmp并解析
*/
void onWrite(const RtmpPacket::Ptr &pkt,bool key_pos = true) override {
key_pos = _demuxer->inputRtmp(pkt);
if(_all_track_ready && !_muxer->isEnabled()){
//获取到所有Track后,并且未开启转协议,那么不需要解复用rtmp
key_pos = pkt->isVideoKeyFrame();
}else{
//需要解复用rtmp
key_pos = _demuxer->inputRtmp(pkt);
}
RtmpMediaSource::onWrite(pkt,key_pos);
}
......@@ -138,10 +145,12 @@ public:
*/
void onAllTrackReady() override{
setTrackSource(_muxer);
_all_track_ready = true;
}
private:
RtmpDemuxer::Ptr _demuxer;
MultiMediaSourceMuxer::Ptr _muxer;
bool _all_track_ready = false;
};
} /* namespace mediakit */
......
......@@ -48,7 +48,14 @@ public:
* 输入rtp并解析
*/
void onWrite(const RtpPacket::Ptr &rtp, bool key_pos) override {
key_pos = _demuxer->inputRtp(rtp);
if(_all_track_ready && !_muxer->isEnabled()){
//获取到所有Track后,并且未开启转协议,那么不需要解复用rtp
//在关闭rtp解复用后,无法知道是否为关键帧,这样会导致无法秒开,或者开播花屏
key_pos = rtp->type == TrackVideo;
}else{
//需要解复用rtp
key_pos = _demuxer->inputRtp(rtp);
}
RtspMediaSource::onWrite(rtp, key_pos);
}
......@@ -129,10 +136,12 @@ public:
*/
void onAllTrackReady() override{
setTrackSource(_muxer);
_all_track_ready = true;
}
private:
RtspDemuxer::Ptr _demuxer;
MultiMediaSourceMuxer::Ptr _muxer;
bool _all_track_ready = false;
};
} /* namespace mediakit */
......
Markdown 格式
0%
您添加了 0 到此讨论。请谨慎行事。
请先完成此评论的编辑!
注册 或者 后发表评论