mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-26 04:31:37 +08:00
新增无人观看自动关闭流(无须hook返回)功能 (#2643)
auto_close参数适用于配置文件、addStreamProxy接口、on_publish hook
This commit is contained in:
parent
e52c1cc510
commit
beae515bb2
@ -40,6 +40,11 @@ modify_stamp=2
|
|||||||
enable_audio=1
|
enable_audio=1
|
||||||
#添加acc静音音频,在关闭音频时,此开关无效
|
#添加acc静音音频,在关闭音频时,此开关无效
|
||||||
add_mute_audio=1
|
add_mute_audio=1
|
||||||
|
#无人观看时,是否直接关闭(而不是通过on_none_reader hook返回close)
|
||||||
|
#此配置置1时,此流如果无人观看,将不触发on_none_reader hook回调,
|
||||||
|
#而是将直接关闭流
|
||||||
|
auto_close=0
|
||||||
|
|
||||||
#推流断开后可以在超时时间内重新连接上继续推流,这样播放器会接着播放。
|
#推流断开后可以在超时时间内重新连接上继续推流,这样播放器会接着播放。
|
||||||
#置0关闭此特性(推流断开会导致立即断开播放器)
|
#置0关闭此特性(推流断开会导致立即断开播放器)
|
||||||
#此参数不应大于播放器超时时间;单位毫秒
|
#此参数不应大于播放器超时时间;单位毫秒
|
||||||
|
@ -56,6 +56,7 @@ ProtocolOption::ProtocolOption() {
|
|||||||
GET_CONFIG(int, s_modify_stamp, Protocol::kModifyStamp);
|
GET_CONFIG(int, s_modify_stamp, Protocol::kModifyStamp);
|
||||||
GET_CONFIG(bool, s_enabel_audio, Protocol::kEnableAudio);
|
GET_CONFIG(bool, s_enabel_audio, Protocol::kEnableAudio);
|
||||||
GET_CONFIG(bool, s_add_mute_audio, Protocol::kAddMuteAudio);
|
GET_CONFIG(bool, s_add_mute_audio, Protocol::kAddMuteAudio);
|
||||||
|
GET_CONFIG(bool, s_auto_close, Protocol::kAutoClose);
|
||||||
GET_CONFIG(uint32_t, s_continue_push_ms, Protocol::kContinuePushMS);
|
GET_CONFIG(uint32_t, s_continue_push_ms, Protocol::kContinuePushMS);
|
||||||
|
|
||||||
GET_CONFIG(bool, s_enable_hls, Protocol::kEnableHls);
|
GET_CONFIG(bool, s_enable_hls, Protocol::kEnableHls);
|
||||||
@ -81,6 +82,7 @@ ProtocolOption::ProtocolOption() {
|
|||||||
modify_stamp = s_modify_stamp;
|
modify_stamp = s_modify_stamp;
|
||||||
enable_audio = s_enabel_audio;
|
enable_audio = s_enabel_audio;
|
||||||
add_mute_audio = s_add_mute_audio;
|
add_mute_audio = s_add_mute_audio;
|
||||||
|
auto_close = s_auto_close;
|
||||||
continue_push_ms = s_continue_push_ms;
|
continue_push_ms = s_continue_push_ms;
|
||||||
|
|
||||||
enable_hls = s_enable_hls;
|
enable_hls = s_enable_hls;
|
||||||
@ -658,8 +660,15 @@ void MediaSourceEvent::onReaderChanged(MediaSource &sender, int size){
|
|||||||
}
|
}
|
||||||
|
|
||||||
if (!is_mp4_vod) {
|
if (!is_mp4_vod) {
|
||||||
//直播时触发无人观看事件,让开发者自行选择是否关闭
|
auto muxer = strong_sender->getMuxer();
|
||||||
|
if (muxer && muxer->getOption().auto_close) {
|
||||||
|
// 此流被标记为无人观看自动关闭流
|
||||||
|
WarnL << "Auto cloe stream when none reader: " << strong_sender->getUrl();
|
||||||
|
strong_sender->close(false);
|
||||||
|
} else {
|
||||||
|
// 直播时触发无人观看事件,让开发者自行选择是否关闭
|
||||||
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastStreamNoneReader, *strong_sender);
|
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastStreamNoneReader, *strong_sender);
|
||||||
|
}
|
||||||
} else {
|
} else {
|
||||||
//这个是mp4点播,我们自动关闭
|
//这个是mp4点播,我们自动关闭
|
||||||
WarnL << "MP4点播无人观看,自动关闭:" << strong_sender->getUrl();
|
WarnL << "MP4点播无人观看,自动关闭:" << strong_sender->getUrl();
|
||||||
|
@ -151,6 +151,11 @@ public:
|
|||||||
bool enable_audio;
|
bool enable_audio;
|
||||||
//添加静音音频,在关闭音频时,此开关无效
|
//添加静音音频,在关闭音频时,此开关无效
|
||||||
bool add_mute_audio;
|
bool add_mute_audio;
|
||||||
|
// 无人观看时,是否直接关闭(而不是通过on_none_reader hook返回close)
|
||||||
|
// 此配置置1时,此流如果无人观看,将不触发on_none_reader hook回调,
|
||||||
|
// 而是将直接关闭流
|
||||||
|
bool auto_close;
|
||||||
|
|
||||||
//断连续推延时,单位毫秒,默认采用配置文件
|
//断连续推延时,单位毫秒,默认采用配置文件
|
||||||
uint32_t continue_push_ms;
|
uint32_t continue_push_ms;
|
||||||
|
|
||||||
@ -199,6 +204,7 @@ public:
|
|||||||
GET_OPT_VALUE(modify_stamp);
|
GET_OPT_VALUE(modify_stamp);
|
||||||
GET_OPT_VALUE(enable_audio);
|
GET_OPT_VALUE(enable_audio);
|
||||||
GET_OPT_VALUE(add_mute_audio);
|
GET_OPT_VALUE(add_mute_audio);
|
||||||
|
GET_OPT_VALUE(auto_close);
|
||||||
GET_OPT_VALUE(continue_push_ms);
|
GET_OPT_VALUE(continue_push_ms);
|
||||||
|
|
||||||
GET_OPT_VALUE(enable_hls);
|
GET_OPT_VALUE(enable_hls);
|
||||||
|
@ -99,6 +99,7 @@ namespace Protocol {
|
|||||||
const string kModifyStamp = PROTOCOL_FIELD "modify_stamp";
|
const string kModifyStamp = PROTOCOL_FIELD "modify_stamp";
|
||||||
const string kEnableAudio = PROTOCOL_FIELD "enable_audio";
|
const string kEnableAudio = PROTOCOL_FIELD "enable_audio";
|
||||||
const string kAddMuteAudio = PROTOCOL_FIELD "add_mute_audio";
|
const string kAddMuteAudio = PROTOCOL_FIELD "add_mute_audio";
|
||||||
|
const string kAutoClose = PROTOCOL_FIELD "auto_close";
|
||||||
const string kContinuePushMS = PROTOCOL_FIELD "continue_push_ms";
|
const string kContinuePushMS = PROTOCOL_FIELD "continue_push_ms";
|
||||||
|
|
||||||
const string kEnableHls = PROTOCOL_FIELD "enable_hls";
|
const string kEnableHls = PROTOCOL_FIELD "enable_hls";
|
||||||
@ -126,6 +127,7 @@ static onceToken token([]() {
|
|||||||
mINI::Instance()[kEnableAudio] = 1;
|
mINI::Instance()[kEnableAudio] = 1;
|
||||||
mINI::Instance()[kAddMuteAudio] = 1;
|
mINI::Instance()[kAddMuteAudio] = 1;
|
||||||
mINI::Instance()[kContinuePushMS] = 15000;
|
mINI::Instance()[kContinuePushMS] = 15000;
|
||||||
|
mINI::Instance()[kAutoClose] = 0;
|
||||||
|
|
||||||
mINI::Instance()[kEnableHls] = 1;
|
mINI::Instance()[kEnableHls] = 1;
|
||||||
mINI::Instance()[kEnableHlsFmp4] = 0;
|
mINI::Instance()[kEnableHlsFmp4] = 0;
|
||||||
|
@ -190,6 +190,10 @@ extern const std::string kModifyStamp;
|
|||||||
extern const std::string kEnableAudio;
|
extern const std::string kEnableAudio;
|
||||||
//添加静音音频,在关闭音频时,此开关无效
|
//添加静音音频,在关闭音频时,此开关无效
|
||||||
extern const std::string kAddMuteAudio;
|
extern const std::string kAddMuteAudio;
|
||||||
|
// 无人观看时,是否直接关闭(而不是通过on_none_reader hook返回close)
|
||||||
|
// 此配置置1时,此流如果无人观看,将不触发on_none_reader hook回调,
|
||||||
|
// 而是将直接关闭流
|
||||||
|
extern const std::string kAutoClose;
|
||||||
//断连续推延时,单位毫秒,默认采用配置文件
|
//断连续推延时,单位毫秒,默认采用配置文件
|
||||||
extern const std::string kContinuePushMS;
|
extern const std::string kContinuePushMS;
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user