mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-29 14:45:55 +08:00
mp4点播无人观看时自动关闭
This commit is contained in:
parent
c3c4c72d1d
commit
42eece5b9a
@ -383,11 +383,17 @@ void MediaInfo::parse(const string &url){
|
|||||||
/////////////////////////////////////MediaSourceEvent//////////////////////////////////////
|
/////////////////////////////////////MediaSourceEvent//////////////////////////////////////
|
||||||
|
|
||||||
void MediaSourceEvent::onNoneReader(MediaSource &sender){
|
void MediaSourceEvent::onNoneReader(MediaSource &sender){
|
||||||
//没有任何读取器消费该源,表明该源可以关闭了
|
GET_CONFIG(string, recordApp, Record::kAppName);
|
||||||
GET_CONFIG(int, stream_none_reader_delay, General::kStreamNoneReaderDelayMS);
|
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<MediaSource> weakSender = sender.shared_from_this();
|
weak_ptr<MediaSource> weakSender = sender.shared_from_this();
|
||||||
_async_close_timer = std::make_shared<Timer>(stream_none_reader_delay / 1000.0, [weakSender]() {
|
_async_close_timer = std::make_shared<Timer>(close_delay, [weakSender,is_mp4_vod]() {
|
||||||
auto strongSender = weakSender.lock();
|
auto strongSender = weakSender.lock();
|
||||||
if (!strongSender) {
|
if (!strongSender) {
|
||||||
//对象已经销毁
|
//对象已经销毁
|
||||||
@ -399,14 +405,24 @@ void MediaSourceEvent::onNoneReader(MediaSource &sender){
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
WarnL << "onNoneReader:"
|
if(!is_mp4_vod){
|
||||||
<< strongSender->getSchema() << "/"
|
//直播时触发无人观看事件,让开发者自行选择是否关闭
|
||||||
<< strongSender->getVhost() << "/"
|
WarnL << "无人观看事件:"
|
||||||
<< strongSender->getApp() << "/"
|
<< strongSender->getSchema() << "/"
|
||||||
<< strongSender->getId();
|
<< 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;
|
return false;
|
||||||
}, nullptr);
|
}, nullptr);
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user