diff --git a/src/Common/MediaSink.cpp b/src/Common/MediaSink.cpp index 147d8444..7da389d6 100644 --- a/src/Common/MediaSink.cpp +++ b/src/Common/MediaSink.cpp @@ -176,7 +176,9 @@ void MediaSink::checkTrackIfReady() { } void MediaSink::addTrackCompleted() { - setMaxTrackCount(_track_map.size()); + if (!_track_map.empty()) { + setMaxTrackCount(_track_map.size()); + } } void MediaSink::setMaxTrackCount(size_t i) { diff --git a/src/Common/MediaSource.h b/src/Common/MediaSource.h index 9b9a78a1..fc7f77d2 100644 --- a/src/Common/MediaSource.h +++ b/src/Common/MediaSource.h @@ -287,6 +287,36 @@ public: // Maximum number of tracks size_t max_track = 2; +#define OPT_VALUE(XX) \ + XX(modify_stamp) \ + XX(enable_audio) \ + XX(add_mute_audio) \ + XX(auto_close) \ + XX(continue_push_ms) \ + XX(paced_sender_ms) \ + \ + XX(enable_hls) \ + XX(enable_hls_fmp4) \ + XX(enable_mp4) \ + XX(enable_rtsp) \ + XX(enable_rtmp) \ + XX(enable_ts) \ + XX(enable_fmp4) \ + \ + XX(hls_demand) \ + XX(rtsp_demand) \ + XX(rtmp_demand) \ + XX(ts_demand) \ + XX(fmp4_demand) \ + \ + XX(mp4_max_second) \ + XX(mp4_as_player) \ + XX(mp4_save_path) \ + \ + XX(hls_save_path) \ + XX(stream_replace) \ + XX(max_track) + template ProtocolOption(const MAP &allArgs) : ProtocolOption() { load(allArgs); @@ -294,35 +324,18 @@ public: template void load(const MAP &allArgs) { -#define GET_OPT_VALUE(key) getArgsValue(allArgs, #key, key) - GET_OPT_VALUE(modify_stamp); - GET_OPT_VALUE(enable_audio); - GET_OPT_VALUE(add_mute_audio); - GET_OPT_VALUE(auto_close); - GET_OPT_VALUE(continue_push_ms); - GET_OPT_VALUE(paced_sender_ms); +#define GET(key) getArgsValue(allArgs, #key, key); + OPT_VALUE(GET) +#undef GET + } - GET_OPT_VALUE(enable_hls); - GET_OPT_VALUE(enable_hls_fmp4); - GET_OPT_VALUE(enable_mp4); - GET_OPT_VALUE(enable_rtsp); - GET_OPT_VALUE(enable_rtmp); - GET_OPT_VALUE(enable_ts); - GET_OPT_VALUE(enable_fmp4); - - GET_OPT_VALUE(hls_demand); - GET_OPT_VALUE(rtsp_demand); - GET_OPT_VALUE(rtmp_demand); - GET_OPT_VALUE(ts_demand); - GET_OPT_VALUE(fmp4_demand); - - GET_OPT_VALUE(mp4_max_second); - GET_OPT_VALUE(mp4_as_player); - GET_OPT_VALUE(mp4_save_path); - - GET_OPT_VALUE(hls_save_path); - GET_OPT_VALUE(stream_replace); - GET_OPT_VALUE(max_track); + template + MAP as() { + MAP ret; +#define SET(key) ret[#key] = key; + OPT_VALUE(SET) +#undef SET + return ret; } }; diff --git a/src/Common/config.h b/src/Common/config.h index c6c0b2db..a26757cf 100644 --- a/src/Common/config.h +++ b/src/Common/config.h @@ -55,31 +55,31 @@ extern const std::string kBroadcastRecordTs; // 收到http api请求广播 [AUTO-TRANSLATED:c72e7c3f] // Broadcast for receiving http api request extern const std::string kBroadcastHttpRequest; -#define BroadcastHttpRequestArgs const Parser &parser, const HttpSession::HttpResponseInvoker &invoker, bool &consumed, SockInfo &sender +#define BroadcastHttpRequestArgs const Parser &parser, const HttpSession::HttpResponseInvoker &invoker, bool &consumed, toolkit::SockInfo &sender // 在http文件服务器中,收到http访问文件或目录的广播,通过该事件控制访问http目录的权限 [AUTO-TRANSLATED:2de426b4] // In the http file server, broadcast for receiving http access to files or directories. Control access permissions to the http directory through this event. extern const std::string kBroadcastHttpAccess; -#define BroadcastHttpAccessArgs const Parser &parser, const std::string &path, const bool &is_dir, const HttpSession::HttpAccessPathInvoker &invoker, SockInfo &sender +#define BroadcastHttpAccessArgs const Parser &parser, const std::string &path, const bool &is_dir, const HttpSession::HttpAccessPathInvoker &invoker, toolkit::SockInfo &sender // 在http文件服务器中,收到http访问文件或目录前的广播,通过该事件可以控制http url到文件路径的映射 [AUTO-TRANSLATED:0294d0c5] // In the http file server, broadcast before receiving http access to files or directories. Control the mapping from http url to file path through this event. // 在该事件中通过自行覆盖path参数,可以做到譬如根据虚拟主机或者app选择不同http根目录的目的 [AUTO-TRANSLATED:1bea3efb] // By overriding the path parameter in this event, you can achieve the purpose of selecting different http root directories based on virtual hosts or apps. extern const std::string kBroadcastHttpBeforeAccess; -#define BroadcastHttpBeforeAccessArgs const Parser &parser, std::string &path, SockInfo &sender +#define BroadcastHttpBeforeAccessArgs const Parser &parser, std::string &path, toolkit::SockInfo &sender // 该流是否需要认证?是的话调用invoker并传入realm,否则传入空的realm.如果该事件不监听则不认证 [AUTO-TRANSLATED:5f436d8f] // Does this stream need authentication? If yes, call invoker and pass in realm, otherwise pass in an empty realm. If this event is not listened to, no authentication will be performed. extern const std::string kBroadcastOnGetRtspRealm; -#define BroadcastOnGetRtspRealmArgs const MediaInfo &args, const RtspSession::onGetRealm &invoker, SockInfo &sender +#define BroadcastOnGetRtspRealmArgs const MediaInfo &args, const RtspSession::onGetRealm &invoker, toolkit::SockInfo &sender // 请求认证用户密码事件,user_name为用户名,must_no_encrypt如果为true,则必须提供明文密码(因为此时是base64认证方式),否则会导致认证失败 [AUTO-TRANSLATED:22b6dfcc] // Request authentication user password event, user_name is the username, must_no_encrypt if true, then the plaintext password must be provided (because it is base64 authentication method at this time), otherwise it will lead to authentication failure. // 获取到密码后请调用invoker并输入对应类型的密码和密码类型,invoker执行时会匹配密码 [AUTO-TRANSLATED:8c57fd43] // After getting the password, please call invoker and input the corresponding type of password and password type. The invoker will match the password when executing. extern const std::string kBroadcastOnRtspAuth; -#define BroadcastOnRtspAuthArgs const MediaInfo &args, const std::string &realm, const std::string &user_name, const bool &must_no_encrypt, const RtspSession::onAuth &invoker, SockInfo &sender +#define BroadcastOnRtspAuthArgs const MediaInfo &args, const std::string &realm, const std::string &user_name, const bool &must_no_encrypt, const RtspSession::onAuth &invoker, toolkit::SockInfo &sender // 推流鉴权结果回调对象 [AUTO-TRANSLATED:7e508ed1] // Push stream authentication result callback object @@ -90,7 +90,7 @@ using PublishAuthInvoker = std::function; // 播放rtsp/rtmp/http-flv事件广播,通过该事件控制播放鉴权 [AUTO-TRANSLATED:eddd7014] // Broadcast for playing rtsp/rtmp/http-flv events. Control playback authentication through this event. extern const std::string kBroadcastMediaPlayed; -#define BroadcastMediaPlayedArgs const MediaInfo &args, const Broadcast::AuthInvoker &invoker, SockInfo &sender +#define BroadcastMediaPlayedArgs const MediaInfo &args, const Broadcast::AuthInvoker &invoker, toolkit::SockInfo &sender // shell登录鉴权 [AUTO-TRANSLATED:26b135d4] // Shell login authentication extern const std::string kBroadcastShellLogin; -#define BroadcastShellLoginArgs const std::string &user_name, const std::string &passwd, const Broadcast::AuthInvoker &invoker, SockInfo &sender +#define BroadcastShellLoginArgs const std::string &user_name, const std::string &passwd, const Broadcast::AuthInvoker &invoker, toolkit::SockInfo &sender // 停止rtsp/rtmp/http-flv会话后流量汇报事件广播 [AUTO-TRANSLATED:69df61d8] // Broadcast for traffic reporting event after stopping rtsp/rtmp/http-flv session extern const std::string kBroadcastFlowReport; -#define BroadcastFlowReportArgs const MediaInfo &args, const uint64_t &totalBytes, const uint64_t &totalDuration, const bool &isPlayer, SockInfo &sender +#define BroadcastFlowReportArgs const MediaInfo &args, const uint64_t &totalBytes, const uint64_t &totalDuration, const bool &isPlayer, toolkit::SockInfo &sender // 未找到流后会广播该事件,请在监听该事件后去拉流或其他方式产生流,这样就能按需拉流了 [AUTO-TRANSLATED:0c00171d] // This event will be broadcast after the stream is not found. Please pull the stream or other methods to generate the stream after listening to this event, so that you can pull the stream on demand. extern const std::string kBroadcastNotFoundStream; -#define BroadcastNotFoundStreamArgs const MediaInfo &args, SockInfo &sender, const std::function &closePlayer +#define BroadcastNotFoundStreamArgs const MediaInfo &args, toolkit::SockInfo &sender, const std::function &closePlayer // 某个流无人消费时触发,目的为了实现无人观看时主动断开拉流等业务逻辑 [AUTO-TRANSLATED:3c45f002] // Triggered when a stream is not consumed by anyone. The purpose is to achieve business logic such as actively disconnecting the pull stream when no one is watching. diff --git a/src/Rtmp/Rtmp.cpp b/src/Rtmp/Rtmp.cpp index 6e5d877b..fe1ff1c8 100644 --- a/src/Rtmp/Rtmp.cpp +++ b/src/Rtmp/Rtmp.cpp @@ -56,30 +56,33 @@ AudioMeta::AudioMeta(const AudioTrack::Ptr &audio) { } uint8_t getCodecFlags(CodecId cid) { - switch(cid) { -#define XX(a, b, c) case a: return static_cast(b); - RTMP_CODEC_MAP(XX) + switch (cid) { +#define XX(a, b, c) \ + case a: return static_cast(b); + RTMP_CODEC_MAP(XX) #undef XX default: return 0; } } uint32_t getCodecFourCC(CodecId cid) { - switch(cid) { -#define XX(a, b, c) case a: return static_cast(c); - RTMP_CODEC_MAP(XX) + switch (cid) { +#define XX(a, b, c) \ + case a: return static_cast(c); + RTMP_CODEC_MAP(XX) #undef XX default: return 0; } } CodecId getFourccCodec(uint32_t id) { - switch(id) { -#define XX(a, b, c) case (uint32_t)c: return a; - RTMP_CODEC_MAP(XX) + switch (id) { +#define XX(a, b, c) \ + case (uint32_t)c: return a; + RTMP_CODEC_MAP(XX) #undef XX + default: return CodecInvalid; } - return CodecInvalid; } uint8_t getAudioRtmpFlags(const Track::Ptr &track) {