mirror of
https://gitee.com/xia-chu/ZLMediaKit.git
synced 2026-05-06 10:57:50 +08:00
优化代码
Some checks failed
Android / build (push) Has been cancelled
CodeQL / Analyze (cpp) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Docker / build (push) Has been cancelled
Linux / build (push) Has been cancelled
macOS / build (push) Has been cancelled
Windows / build (push) Has been cancelled
Some checks failed
Android / build (push) Has been cancelled
CodeQL / Analyze (cpp) (push) Has been cancelled
CodeQL / Analyze (javascript) (push) Has been cancelled
Docker / build (push) Has been cancelled
Linux / build (push) Has been cancelled
macOS / build (push) Has been cancelled
Windows / build (push) Has been cancelled
This commit is contained in:
parent
c53730f36c
commit
a54a0b35c7
@ -176,7 +176,9 @@ void MediaSink::checkTrackIfReady() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
void MediaSink::addTrackCompleted() {
|
void MediaSink::addTrackCompleted() {
|
||||||
setMaxTrackCount(_track_map.size());
|
if (!_track_map.empty()) {
|
||||||
|
setMaxTrackCount(_track_map.size());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void MediaSink::setMaxTrackCount(size_t i) {
|
void MediaSink::setMaxTrackCount(size_t i) {
|
||||||
|
|||||||
@ -287,6 +287,36 @@ public:
|
|||||||
// Maximum number of tracks
|
// Maximum number of tracks
|
||||||
size_t max_track = 2;
|
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 <typename MAP>
|
template <typename MAP>
|
||||||
ProtocolOption(const MAP &allArgs) : ProtocolOption() {
|
ProtocolOption(const MAP &allArgs) : ProtocolOption() {
|
||||||
load(allArgs);
|
load(allArgs);
|
||||||
@ -294,35 +324,18 @@ public:
|
|||||||
|
|
||||||
template <typename MAP>
|
template <typename MAP>
|
||||||
void load(const MAP &allArgs) {
|
void load(const MAP &allArgs) {
|
||||||
#define GET_OPT_VALUE(key) getArgsValue(allArgs, #key, key)
|
#define GET(key) getArgsValue(allArgs, #key, key);
|
||||||
GET_OPT_VALUE(modify_stamp);
|
OPT_VALUE(GET)
|
||||||
GET_OPT_VALUE(enable_audio);
|
#undef GET
|
||||||
GET_OPT_VALUE(add_mute_audio);
|
}
|
||||||
GET_OPT_VALUE(auto_close);
|
|
||||||
GET_OPT_VALUE(continue_push_ms);
|
|
||||||
GET_OPT_VALUE(paced_sender_ms);
|
|
||||||
|
|
||||||
GET_OPT_VALUE(enable_hls);
|
template <typename MAP>
|
||||||
GET_OPT_VALUE(enable_hls_fmp4);
|
MAP as() {
|
||||||
GET_OPT_VALUE(enable_mp4);
|
MAP ret;
|
||||||
GET_OPT_VALUE(enable_rtsp);
|
#define SET(key) ret[#key] = key;
|
||||||
GET_OPT_VALUE(enable_rtmp);
|
OPT_VALUE(SET)
|
||||||
GET_OPT_VALUE(enable_ts);
|
#undef SET
|
||||||
GET_OPT_VALUE(enable_fmp4);
|
return ret;
|
||||||
|
|
||||||
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);
|
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -55,31 +55,31 @@ extern const std::string kBroadcastRecordTs;
|
|||||||
// 收到http api请求广播 [AUTO-TRANSLATED:c72e7c3f]
|
// 收到http api请求广播 [AUTO-TRANSLATED:c72e7c3f]
|
||||||
// Broadcast for receiving http api request
|
// Broadcast for receiving http api request
|
||||||
extern const std::string kBroadcastHttpRequest;
|
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]
|
// 在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.
|
// 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;
|
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]
|
// 在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.
|
// 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]
|
// 在该事件中通过自行覆盖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.
|
// 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;
|
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]
|
// 该流是否需要认证?是的话调用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.
|
// 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;
|
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]
|
// 请求认证用户密码事件,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.
|
// 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]
|
// 获取到密码后请调用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.
|
// 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;
|
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]
|
// 推流鉴权结果回调对象 [AUTO-TRANSLATED:7e508ed1]
|
||||||
// Push stream authentication result callback object
|
// Push stream authentication result callback object
|
||||||
@ -90,7 +90,7 @@ using PublishAuthInvoker = std::function<void(const std::string &err, const Prot
|
|||||||
// 收到rtsp/rtmp推流事件广播,通过该事件控制推流鉴权 [AUTO-TRANSLATED:72417373]
|
// 收到rtsp/rtmp推流事件广播,通过该事件控制推流鉴权 [AUTO-TRANSLATED:72417373]
|
||||||
// Broadcast for receiving rtsp/rtmp push stream event. Control push stream authentication through this event.
|
// Broadcast for receiving rtsp/rtmp push stream event. Control push stream authentication through this event.
|
||||||
extern const std::string kBroadcastMediaPublish;
|
extern const std::string kBroadcastMediaPublish;
|
||||||
#define BroadcastMediaPublishArgs const MediaOriginType &type, const MediaInfo &args, const Broadcast::PublishAuthInvoker &invoker, SockInfo &sender
|
#define BroadcastMediaPublishArgs const MediaOriginType &type, const MediaInfo &args, const Broadcast::PublishAuthInvoker &invoker, toolkit::SockInfo &sender
|
||||||
|
|
||||||
// 播放鉴权结果回调对象 [AUTO-TRANSLATED:c980162b]
|
// 播放鉴权结果回调对象 [AUTO-TRANSLATED:c980162b]
|
||||||
// Playback authentication result callback object
|
// Playback authentication result callback object
|
||||||
@ -101,22 +101,22 @@ using AuthInvoker = std::function<void(const std::string &err)>;
|
|||||||
// 播放rtsp/rtmp/http-flv事件广播,通过该事件控制播放鉴权 [AUTO-TRANSLATED:eddd7014]
|
// 播放rtsp/rtmp/http-flv事件广播,通过该事件控制播放鉴权 [AUTO-TRANSLATED:eddd7014]
|
||||||
// Broadcast for playing rtsp/rtmp/http-flv events. Control playback authentication through this event.
|
// Broadcast for playing rtsp/rtmp/http-flv events. Control playback authentication through this event.
|
||||||
extern const std::string kBroadcastMediaPlayed;
|
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登录鉴权 [AUTO-TRANSLATED:26b135d4]
|
||||||
// Shell login authentication
|
// Shell login authentication
|
||||||
extern const std::string kBroadcastShellLogin;
|
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]
|
// 停止rtsp/rtmp/http-flv会话后流量汇报事件广播 [AUTO-TRANSLATED:69df61d8]
|
||||||
// Broadcast for traffic reporting event after stopping rtsp/rtmp/http-flv session
|
// Broadcast for traffic reporting event after stopping rtsp/rtmp/http-flv session
|
||||||
extern const std::string kBroadcastFlowReport;
|
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]
|
// 未找到流后会广播该事件,请在监听该事件后去拉流或其他方式产生流,这样就能按需拉流了 [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.
|
// 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;
|
extern const std::string kBroadcastNotFoundStream;
|
||||||
#define BroadcastNotFoundStreamArgs const MediaInfo &args, SockInfo &sender, const std::function<void()> &closePlayer
|
#define BroadcastNotFoundStreamArgs const MediaInfo &args, toolkit::SockInfo &sender, const std::function<void()> &closePlayer
|
||||||
|
|
||||||
// 某个流无人消费时触发,目的为了实现无人观看时主动断开拉流等业务逻辑 [AUTO-TRANSLATED:3c45f002]
|
// 某个流无人消费时触发,目的为了实现无人观看时主动断开拉流等业务逻辑 [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.
|
// 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.
|
||||||
|
|||||||
@ -56,30 +56,33 @@ AudioMeta::AudioMeta(const AudioTrack::Ptr &audio) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
uint8_t getCodecFlags(CodecId cid) {
|
uint8_t getCodecFlags(CodecId cid) {
|
||||||
switch(cid) {
|
switch (cid) {
|
||||||
#define XX(a, b, c) case a: return static_cast<uint8_t>(b);
|
#define XX(a, b, c) \
|
||||||
RTMP_CODEC_MAP(XX)
|
case a: return static_cast<uint8_t>(b);
|
||||||
|
RTMP_CODEC_MAP(XX)
|
||||||
#undef XX
|
#undef XX
|
||||||
default: return 0;
|
default: return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
uint32_t getCodecFourCC(CodecId cid) {
|
uint32_t getCodecFourCC(CodecId cid) {
|
||||||
switch(cid) {
|
switch (cid) {
|
||||||
#define XX(a, b, c) case a: return static_cast<uint32_t>(c);
|
#define XX(a, b, c) \
|
||||||
RTMP_CODEC_MAP(XX)
|
case a: return static_cast<uint32_t>(c);
|
||||||
|
RTMP_CODEC_MAP(XX)
|
||||||
#undef XX
|
#undef XX
|
||||||
default: return 0;
|
default: return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
CodecId getFourccCodec(uint32_t id) {
|
CodecId getFourccCodec(uint32_t id) {
|
||||||
switch(id) {
|
switch (id) {
|
||||||
#define XX(a, b, c) case (uint32_t)c: return a;
|
#define XX(a, b, c) \
|
||||||
RTMP_CODEC_MAP(XX)
|
case (uint32_t)c: return a;
|
||||||
|
RTMP_CODEC_MAP(XX)
|
||||||
#undef XX
|
#undef XX
|
||||||
|
default: return CodecInvalid;
|
||||||
}
|
}
|
||||||
return CodecInvalid;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
uint8_t getAudioRtmpFlags(const Track::Ptr &track) {
|
uint8_t getAudioRtmpFlags(const Track::Ptr &track) {
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user