From 144165d53733ed1afb5f08e440e22bead3832972 Mon Sep 17 00:00:00 2001 From: xia-chu <771730766@qq.com> Date: Sat, 2 Sep 2023 12:58:20 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Emk=5Fmedia=5Fsource=5Fbroadca?= =?UTF-8?q?st=5Fmsg=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 通过该接口可以广播webrtc datachannel消息给webrtc播放器 --- api/include/mk_events_objects.h | 3 +++ api/source/mk_events_objects.cpp | 10 ++++++++++ 2 files changed, 13 insertions(+) diff --git a/api/include/mk_events_objects.h b/api/include/mk_events_objects.h index 018988f4..3dc9a2c3 100644 --- a/api/include/mk_events_objects.h +++ b/api/include/mk_events_objects.h @@ -100,6 +100,9 @@ API_EXPORT int API_CALL mk_media_source_get_total_reader_count(const mk_media_so API_EXPORT int API_CALL mk_media_source_get_track_count(const mk_media_source ctx); // copy track reference by index from MediaSource, please use mk_track_unref to release it API_EXPORT mk_track API_CALL mk_media_source_get_track(const mk_media_source ctx, int index); +// MediaSource::broadcastMessage +API_EXPORT int API_CALL mk_media_source_broadcast_msg(const mk_media_source ctx, const char *msg, size_t len); + /** * 直播源在ZLMediaKit中被称作为MediaSource, * 目前支持3种,分别是RtmpMediaSource、RtspMediaSource、HlsMediaSource diff --git a/api/source/mk_events_objects.cpp b/api/source/mk_events_objects.cpp index fd7f696c..f6b535bf 100644 --- a/api/source/mk_events_objects.cpp +++ b/api/source/mk_events_objects.cpp @@ -214,6 +214,16 @@ API_EXPORT mk_track API_CALL mk_media_source_get_track(const mk_media_source ctx return (mk_track) new Track::Ptr(std::move(tracks[index])); } +API_EXPORT int API_CALL mk_media_source_broadcast_msg(const mk_media_source ctx, const char *msg, size_t len) { + assert(ctx && msg && len); + MediaSource *src = (MediaSource *)ctx; + + Any any; + Buffer::Ptr buffer = std::make_shared(std::string(msg, len)); + any.set(std::move(buffer)); + src->broadcastMessage(any); +} + API_EXPORT int API_CALL mk_media_source_close(const mk_media_source ctx,int force){ assert(ctx); MediaSource *src = (MediaSource *)ctx;