From 42eece5b9a8a1860920ae89dc0a743b16dcf1bdf Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Fri, 3 Apr 2020 22:39:44 +0800 Subject: [PATCH] =?UTF-8?q?mp4=E7=82=B9=E6=92=AD=E6=97=A0=E4=BA=BA?= =?UTF-8?q?=E8=A7=82=E7=9C=8B=E6=97=B6=E8=87=AA=E5=8A=A8=E5=85=B3=E9=97=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Common/MediaSource.cpp | 34 +++++++++++++++++++++++++--------- 1 file changed, 25 insertions(+), 9 deletions(-) diff --git a/src/Common/MediaSource.cpp b/src/Common/MediaSource.cpp index 3d6e901b..c0154d31 100644 --- a/src/Common/MediaSource.cpp +++ b/src/Common/MediaSource.cpp @@ -383,11 +383,17 @@ void MediaInfo::parse(const string &url){ /////////////////////////////////////MediaSourceEvent////////////////////////////////////// void MediaSourceEvent::onNoneReader(MediaSource &sender){ - //没有任何读取器消费该源,表明该源可以关闭了 + GET_CONFIG(string, recordApp, Record::kAppName); GET_CONFIG(int, stream_none_reader_delay, General::kStreamNoneReaderDelayMS); + //如果mp4点播, 无人观看时我们强制关闭点播 + bool is_mp4_vod = sender.getApp() == recordApp; + //无人观看mp4点播时,3秒后自动关闭 + auto close_delay = is_mp4_vod ? 3.0 : stream_none_reader_delay / 1000.0; + + //没有任何人观看该视频源,表明该源可以关闭了 weak_ptr weakSender = sender.shared_from_this(); - _async_close_timer = std::make_shared(stream_none_reader_delay / 1000.0, [weakSender]() { + _async_close_timer = std::make_shared(close_delay, [weakSender,is_mp4_vod]() { auto strongSender = weakSender.lock(); if (!strongSender) { //对象已经销毁 @@ -399,14 +405,24 @@ void MediaSourceEvent::onNoneReader(MediaSource &sender){ return false; } - WarnL << "onNoneReader:" - << strongSender->getSchema() << "/" - << strongSender->getVhost() << "/" - << strongSender->getApp() << "/" - << strongSender->getId(); + if(!is_mp4_vod){ + //直播时触发无人观看事件,让开发者自行选择是否关闭 + WarnL << "无人观看事件:" + << strongSender->getSchema() << "/" + << strongSender->getVhost() << "/" + << strongSender->getApp() << "/" + << strongSender->getId(); + NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastStreamNoneReader, *strongSender); + }else{ + //这个是mp4点播,我们自动关闭 + WarnL << "MP4点播无人观看,自动关闭:" + << strongSender->getSchema() << "/" + << strongSender->getVhost() << "/" + << strongSender->getApp() << "/" + << strongSender->getId(); + strongSender->close(false); + } - //触发消息广播 - NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastStreamNoneReader, *strongSender); return false; }, nullptr); }