diff --git a/conf/config.ini b/conf/config.ini index 433bb6d6..6c48df31 100644 --- a/conf/config.ini +++ b/conf/config.ini @@ -238,6 +238,8 @@ sampleMS=500 fastStart=0 #MP4点播(rtsp/rtmp/http-flv/ws-flv)是否循环播放文件 fileRepeat=0 +#MP4录制是否当做播放器参与播放人数统计 +mp4_as_player=0 [rtmp] #rtmp必须在此时间内完成握手,否则服务器会断开链接,单位秒 diff --git a/server/WebApi.cpp b/server/WebApi.cpp index 0375b38a..91c33598 100755 --- a/server/WebApi.cpp +++ b/server/WebApi.cpp @@ -966,6 +966,7 @@ void installWebApi() { ProtocolOption option; getArgsValue(allArgs, "enable_hls", option.enable_hls); getArgsValue(allArgs, "enable_mp4", option.enable_mp4); + getArgsValue(allArgs, "mp4_as_player", option.mp4_as_player); getArgsValue(allArgs, "enable_rtsp", option.enable_rtsp); getArgsValue(allArgs, "enable_rtmp", option.enable_rtmp); getArgsValue(allArgs, "enable_ts", option.enable_ts); diff --git a/server/WebHook.cpp b/server/WebHook.cpp index fe9a5516..a67a6b28 100755 --- a/server/WebHook.cpp +++ b/server/WebHook.cpp @@ -348,6 +348,9 @@ void installWebHook(){ if (obj.isMember("continue_push_ms")) { option.continue_push_ms = obj["continue_push_ms"].asUInt(); } + if (obj.isMember("mp4_as_player")) { + option.mp4_as_player = obj["mp4_as_player"].asBool(); + } invoker(err, option); } else { //推流鉴权失败 diff --git a/src/Common/MultiMediaSourceMuxer.cpp b/src/Common/MultiMediaSourceMuxer.cpp index 53515dba..399f4e06 100644 --- a/src/Common/MultiMediaSourceMuxer.cpp +++ b/src/Common/MultiMediaSourceMuxer.cpp @@ -26,14 +26,15 @@ ProtocolOption::ProtocolOption() { GET_CONFIG(bool, s_to_mp4, General::kPublishToMP4); GET_CONFIG(bool, s_enabel_audio, General::kEnableAudio); GET_CONFIG(bool, s_add_mute_audio, General::kAddMuteAudio); + GET_CONFIG(bool, s_mp4_as_player, Record::kMP4AsPlayer); GET_CONFIG(uint32_t, s_continue_push_ms, General::kContinuePushMS); - enable_hls = s_to_hls; enable_mp4 = s_to_mp4; enable_audio = s_enabel_audio; add_mute_audio = s_add_mute_audio; continue_push_ms = s_continue_push_ms; + mp4_as_player = s_mp4_as_player; } static std::shared_ptr makeRecorder(MediaSource &sender, const vector &tracks, Recorder::type type, const string &custom_path, size_t max_second){ @@ -75,6 +76,7 @@ static string getTrackInfoStr(const TrackSource *track_src){ } MultiMediaSourceMuxer::MultiMediaSourceMuxer(const string &vhost, const string &app, const string &stream, float dur_sec, const ProtocolOption &option) { + _option = option; _get_origin_url = [this, vhost, app, stream]() { auto ret = getOriginUrl(*MediaSource::NullMediaSource); if (!ret.empty()) { @@ -146,6 +148,7 @@ int MultiMediaSourceMuxer::totalReaderCount() const { #if defined(ENABLE_MP4) (_fmp4 ? _fmp4->readerCount() : 0) + #endif + (_mp4 ? _option.mp4_as_player : 0) + (hls ? hls->readerCount() : 0); #if defined(ENABLE_RTPPROXY) diff --git a/src/Common/MultiMediaSourceMuxer.h b/src/Common/MultiMediaSourceMuxer.h index caedd25d..75dbd437 100644 --- a/src/Common/MultiMediaSourceMuxer.h +++ b/src/Common/MultiMediaSourceMuxer.h @@ -31,6 +31,8 @@ public: bool enable_hls = false; //是否开启MP4录制 bool enable_mp4 = false; + //是否将mp4录制当做观看者 + bool mp4_as_player = false; //是否开启转换为rtsp/webrtc bool enable_rtsp = true; //是否开启转换为rtmp/flv @@ -175,6 +177,7 @@ protected: private: bool _is_enable = false; + ProtocolOption _option; toolkit::Ticker _last_check; Stamp _stamp[2]; std::weak_ptr _track_listener; diff --git a/src/Common/config.cpp b/src/Common/config.cpp index 1b775141..d02365a9 100644 --- a/src/Common/config.cpp +++ b/src/Common/config.cpp @@ -238,6 +238,7 @@ const string kFilePath = RECORD_FIELD "filePath"; const string kFileBufSize = RECORD_FIELD "fileBufSize"; const string kFastStart = RECORD_FIELD "fastStart"; const string kFileRepeat = RECORD_FIELD "fileRepeat"; +const string kMP4AsPlayer = RECORD_FIELD "mp4_as_player"; static onceToken token([]() { mINI::Instance()[kAppName] = "record"; @@ -247,6 +248,7 @@ static onceToken token([]() { mINI::Instance()[kFileBufSize] = 64 * 1024; mINI::Instance()[kFastStart] = false; mINI::Instance()[kFileRepeat] = false; + mINI::Instance()[kMP4AsPlayer] = false; }); } // namespace Record diff --git a/src/Common/config.h b/src/Common/config.h index 787a1fe2..3442d2e4 100644 --- a/src/Common/config.h +++ b/src/Common/config.h @@ -295,6 +295,8 @@ extern const std::string kFileBufSize; extern const std::string kFastStart; // mp4文件是否重头循环读取 extern const std::string kFileRepeat; +//MP4录制是否当做播放器参与播放人数统计 +extern const std::string kMP4AsPlayer; } // namespace Record ////////////HLS相关配置///////////