From f55e13f9dac22a6cc6241836b382299a64da8344 Mon Sep 17 00:00:00 2001 From: xia-chu <771730766@qq.com> Date: Sat, 8 Jul 2023 22:34:09 +0800 Subject: [PATCH] =?UTF-8?q?c=20sdk=E6=96=B0=E5=A2=9Eon=5Fmk=5Fmedia=5Fsend?= =?UTF-8?q?=5Frtp=5Fstop=E4=BA=8B=E4=BB=B6=E5=9B=9E=E8=B0=83?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/include/mk_events.h | 11 +++++++++++ api/source/mk_events.cpp | 7 +++++++ server/WebHook.cpp | 4 ++-- src/Common/config.h | 4 ++-- 4 files changed, 22 insertions(+), 4 deletions(-) diff --git a/api/include/mk_events.h b/api/include/mk_events.h index c628a0ec..0db68a5f 100644 --- a/api/include/mk_events.h +++ b/api/include/mk_events.h @@ -166,6 +166,17 @@ typedef struct { */ void (API_CALL *on_mk_log)(int level, const char *file, int line, const char *function, const char *message); + /** + * 发送rtp流失败回调,适用于mk_media_source_start_send_rtp/mk_media_start_send_rtp接口触发的rtp发送 + * @param vhost 虚拟主机 + * @param app 应用名 + * @param stream 流id + * @param ssrc ssrc的10进制打印,通过atoi转换为整型 + * @param err 错误代码 + * @param msg 错误提示 + */ + void(API_CALL *on_mk_media_send_rtp_stop)(const char *vhost, const char *app, const char *stream, const char *ssrc, int err, const char *msg); + } mk_events; diff --git a/api/source/mk_events.cpp b/api/source/mk_events.cpp index 43e3362c..6e81ccc5 100644 --- a/api/source/mk_events.cpp +++ b/api/source/mk_events.cpp @@ -160,6 +160,13 @@ API_EXPORT void API_CALL mk_events_listen(const mk_events *events){ s_events.on_mk_log((int) ctx->_level, ctx->_file.data(), ctx->_line, ctx->_function.data(), log.data()); } }); + + NoticeCenter::Instance().addListener(&s_tag, Broadcast::kBroadcastSendRtpStopped,[](BroadcastSendRtpStoppedArgs){ + if (s_events.on_mk_media_send_rtp_stop) { + s_events.on_mk_media_send_rtp_stop(sender.getMediaTuple().vhost.c_str(), sender.getMediaTuple().app.c_str(), + sender.getMediaTuple().stream.c_str(), ssrc.c_str(), ex.getErrCode(), ex.what()); + } + }); }); } diff --git a/server/WebHook.cpp b/server/WebHook.cpp index 424b8d1a..8eed641f 100755 --- a/server/WebHook.cpp +++ b/server/WebHook.cpp @@ -585,7 +585,7 @@ void installWebHook() { }); }); - NoticeCenter::Instance().addListener(&web_hook_tag, Broadcast::kBroadcastSendRtpStopped, [](BroadcastSendRtpStopped) { + NoticeCenter::Instance().addListener(&web_hook_tag, Broadcast::kBroadcastSendRtpStopped, [](BroadcastSendRtpStoppedArgs) { GET_CONFIG(string, hook_send_rtp_stopped, Hook::kOnSendRtpStopped); if (!hook_enable || hook_send_rtp_stopped.empty()) { return; @@ -656,7 +656,7 @@ void installWebHook() { }); }); - NoticeCenter::Instance().addListener(&web_hook_tag, Broadcast::KBroadcastRtpServerTimeout, [](BroadcastRtpServerTimeout) { + NoticeCenter::Instance().addListener(&web_hook_tag, Broadcast::KBroadcastRtpServerTimeout, [](BroadcastRtpServerTimeoutArgs) { GET_CONFIG(string, rtp_server_timeout, Hook::kOnRtpServerTimeout); if (!hook_enable || rtp_server_timeout.empty()) { return; diff --git a/src/Common/config.h b/src/Common/config.h index baafac2d..ec546a17 100644 --- a/src/Common/config.h +++ b/src/Common/config.h @@ -99,7 +99,7 @@ extern const std::string kBroadcastStreamNoneReader; // rtp推流被动停止时触发 extern const std::string kBroadcastSendRtpStopped; -#define BroadcastSendRtpStopped MultiMediaSourceMuxer &sender, const std::string &ssrc, const SockException &ex +#define BroadcastSendRtpStoppedArgs MultiMediaSourceMuxer &sender, const std::string &ssrc, const SockException &ex // 更新配置文件事件广播,执行loadIniConfig函数加载配置文件成功后会触发该广播 extern const std::string kBroadcastReloadConfig; @@ -107,7 +107,7 @@ extern const std::string kBroadcastReloadConfig; // rtp server 超时 extern const std::string KBroadcastRtpServerTimeout; -#define BroadcastRtpServerTimeout uint16_t &local_port, const string &stream_id,int &tcp_mode, bool &re_use_port, uint32_t &ssrc +#define BroadcastRtpServerTimeoutArgs uint16_t &local_port, const string &stream_id,int &tcp_mode, bool &re_use_port, uint32_t &ssrc #define ReloadConfigTag ((void *)(0xFF)) #define RELOAD_KEY(arg, key) \