From 54700490762053a2411de23acc9bb9777521fe62 Mon Sep 17 00:00:00 2001 From: xia-chu <771730766@qq.com> Date: Fri, 28 Jun 2024 19:35:03 +0800 Subject: [PATCH] =?UTF-8?q?=E7=B2=BE=E7=AE=80ProtocolOption=E7=9B=B8?= =?UTF-8?q?=E5=85=B3=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/Common/MediaSource.cpp | 60 +++++--------------------------------- src/Common/MediaSource.h | 9 ++++++ src/Common/config.cpp | 45 ++++++++++++++-------------- src/Common/config.h | 1 + 4 files changed, 39 insertions(+), 76 deletions(-) diff --git a/src/Common/MediaSource.cpp b/src/Common/MediaSource.cpp index 1504a1dc..1f2d6cd3 100644 --- a/src/Common/MediaSource.cpp +++ b/src/Common/MediaSource.cpp @@ -55,59 +55,13 @@ string getOriginTypeString(MediaOriginType type){ ////////////////////////////////////////////////////////////////////////////////////////////////////////////// ProtocolOption::ProtocolOption() { - GET_CONFIG(int, s_modify_stamp, Protocol::kModifyStamp); - GET_CONFIG(bool, s_enabel_audio, Protocol::kEnableAudio); - 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_paced_sender_ms, Protocol::kPacedSenderMS); - - GET_CONFIG(bool, s_enable_hls, Protocol::kEnableHls); - GET_CONFIG(bool, s_enable_hls_fmp4, Protocol::kEnableHlsFmp4); - GET_CONFIG(bool, s_enable_mp4, Protocol::kEnableMP4); - GET_CONFIG(bool, s_enable_rtsp, Protocol::kEnableRtsp); - GET_CONFIG(bool, s_enable_rtmp, Protocol::kEnableRtmp); - GET_CONFIG(bool, s_enable_ts, Protocol::kEnableTS); - GET_CONFIG(bool, s_enable_fmp4, Protocol::kEnableFMP4); - - GET_CONFIG(bool, s_hls_demand, Protocol::kHlsDemand); - GET_CONFIG(bool, s_rtsp_demand, Protocol::kRtspDemand); - GET_CONFIG(bool, s_rtmp_demand, Protocol::kRtmpDemand); - GET_CONFIG(bool, s_ts_demand, Protocol::kTSDemand); - GET_CONFIG(bool, s_fmp4_demand, Protocol::kFMP4Demand); - - GET_CONFIG(bool, s_mp4_as_player, Protocol::kMP4AsPlayer); - GET_CONFIG(uint32_t, s_mp4_max_second, Protocol::kMP4MaxSecond); - GET_CONFIG(string, s_mp4_save_path, Protocol::kMP4SavePath); - - GET_CONFIG(string, s_hls_save_path, Protocol::kHlsSavePath); - - modify_stamp = s_modify_stamp; - enable_audio = s_enabel_audio; - add_mute_audio = s_add_mute_audio; - auto_close = s_auto_close; - continue_push_ms = s_continue_push_ms; - paced_sender_ms = s_paced_sender_ms; - - enable_hls = s_enable_hls; - enable_hls_fmp4 = s_enable_hls_fmp4; - enable_mp4 = s_enable_mp4; - enable_rtsp = s_enable_rtsp; - enable_rtmp = s_enable_rtmp; - enable_ts = s_enable_ts; - enable_fmp4 = s_enable_fmp4; - - hls_demand = s_hls_demand; - rtsp_demand = s_rtsp_demand; - rtmp_demand = s_rtmp_demand; - ts_demand = s_ts_demand; - fmp4_demand = s_fmp4_demand; - - mp4_as_player = s_mp4_as_player; - mp4_max_second = s_mp4_max_second; - mp4_save_path = s_mp4_save_path; - - hls_save_path = s_hls_save_path; + mINI ini; + auto &config = mINI::Instance(); + static auto sz = strlen(Protocol::kFieldName); + for (auto it = config.lower_bound(Protocol::kFieldName); it != config.end() && start_with(it->first, Protocol::kFieldName); ++it) { + ini.emplace(it->first.substr(sz), it->second); + } + load(ini); } ////////////////////////////////////////////////////////////////////////////////////////////////////////////// diff --git a/src/Common/MediaSource.h b/src/Common/MediaSource.h index 0cc3f88c..0792b75b 100644 --- a/src/Common/MediaSource.h +++ b/src/Common/MediaSource.h @@ -15,6 +15,7 @@ #include #include #include +#include "Util/mini.h" #include "Network/Socket.h" #include "Extension/Track.h" #include "Record/Recorder.h" @@ -148,6 +149,14 @@ static void getArgsValue(const MAP &allArgs, const KEY &key, TYPE &value) { } } +template +static void getArgsValue(const toolkit::mINI &allArgs, const KEY &key, TYPE &value) { + auto it = allArgs.find(key); + if (it != allArgs.end()) { + value = (TYPE)it->second; + } +} + class ProtocolOption { public: ProtocolOption(); diff --git a/src/Common/config.cpp b/src/Common/config.cpp index 3c10404d..bbb97c39 100644 --- a/src/Common/config.cpp +++ b/src/Common/config.cpp @@ -104,33 +104,32 @@ static onceToken token([]() { } // namespace General namespace Protocol { -#define PROTOCOL_FIELD "protocol." -const string kModifyStamp = PROTOCOL_FIELD "modify_stamp"; -const string kEnableAudio = PROTOCOL_FIELD "enable_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 kPacedSenderMS = PROTOCOL_FIELD "paced_sender_ms"; +const string kModifyStamp = string(kFieldName) + "modify_stamp"; +const string kEnableAudio = string(kFieldName) + "enable_audio"; +const string kAddMuteAudio = string(kFieldName) + "add_mute_audio"; +const string kAutoClose = string(kFieldName) + "auto_close"; +const string kContinuePushMS = string(kFieldName) + "continue_push_ms"; +const string kPacedSenderMS = string(kFieldName) + "paced_sender_ms"; -const string kEnableHls = PROTOCOL_FIELD "enable_hls"; -const string kEnableHlsFmp4 = PROTOCOL_FIELD "enable_hls_fmp4"; -const string kEnableMP4 = PROTOCOL_FIELD "enable_mp4"; -const string kEnableRtsp = PROTOCOL_FIELD "enable_rtsp"; -const string kEnableRtmp = PROTOCOL_FIELD "enable_rtmp"; -const string kEnableTS = PROTOCOL_FIELD "enable_ts"; -const string kEnableFMP4 = PROTOCOL_FIELD "enable_fmp4"; +const string kEnableHls = string(kFieldName) + "enable_hls"; +const string kEnableHlsFmp4 = string(kFieldName) + "enable_hls_fmp4"; +const string kEnableMP4 = string(kFieldName) + "enable_mp4"; +const string kEnableRtsp = string(kFieldName) + "enable_rtsp"; +const string kEnableRtmp = string(kFieldName) + "enable_rtmp"; +const string kEnableTS = string(kFieldName) + "enable_ts"; +const string kEnableFMP4 = string(kFieldName) + "enable_fmp4"; -const string kMP4AsPlayer = PROTOCOL_FIELD "mp4_as_player"; -const string kMP4MaxSecond = PROTOCOL_FIELD "mp4_max_second"; -const string kMP4SavePath = PROTOCOL_FIELD "mp4_save_path"; +const string kMP4AsPlayer = string(kFieldName) + "mp4_as_player"; +const string kMP4MaxSecond = string(kFieldName) + "mp4_max_second"; +const string kMP4SavePath = string(kFieldName) + "mp4_save_path"; -const string kHlsSavePath = PROTOCOL_FIELD "hls_save_path"; +const string kHlsSavePath = string(kFieldName) + "hls_save_path"; -const string kHlsDemand = PROTOCOL_FIELD "hls_demand"; -const string kRtspDemand = PROTOCOL_FIELD "rtsp_demand"; -const string kRtmpDemand = PROTOCOL_FIELD "rtmp_demand"; -const string kTSDemand = PROTOCOL_FIELD "ts_demand"; -const string kFMP4Demand = PROTOCOL_FIELD "fmp4_demand"; +const string kHlsDemand = string(kFieldName) + "hls_demand"; +const string kRtspDemand = string(kFieldName) + "rtsp_demand"; +const string kRtmpDemand = string(kFieldName) + "rtmp_demand"; +const string kTSDemand = string(kFieldName) + "ts_demand"; +const string kFMP4Demand = string(kFieldName) + "fmp4_demand"; static onceToken token([]() { mINI::Instance()[kModifyStamp] = (int)ProtocolOption::kModifyStampRelative; diff --git a/src/Common/config.h b/src/Common/config.h index 3a4f6d58..6f9bed08 100644 --- a/src/Common/config.h +++ b/src/Common/config.h @@ -205,6 +205,7 @@ extern const std::string kBroadcastPlayerCountChanged; } // namespace General namespace Protocol { +static constexpr char kFieldName[] = "protocol."; //时间戳修复这一路流标志位 extern const std::string kModifyStamp; //转协议是否开启音频