From 24fb666fb39ff0a286d34829269fcd7b03f0f8a7 Mon Sep 17 00:00:00 2001 From: xia-chu <771730766@qq.com> Date: Sat, 10 Jun 2023 09:34:00 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9Emk=5Fmedia=5Fsource=5Fget=5Ft?= =?UTF-8?q?rack=E6=96=B9=E6=B3=95:=20#2530?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/include/mk_events_objects.h | 5 +++++ api/source/mk_events_objects.cpp | 16 ++++++++++++++++ 2 files changed, 21 insertions(+) diff --git a/api/include/mk_events_objects.h b/api/include/mk_events_objects.h index c114c783..425243a6 100644 --- a/api/include/mk_events_objects.h +++ b/api/include/mk_events_objects.h @@ -12,6 +12,7 @@ #define MK_EVENT_OBJECTS_H #include "mk_common.h" #include "mk_tcp.h" +#include "mk_track.h" #ifdef __cplusplus extern "C" { #endif @@ -95,6 +96,10 @@ API_EXPORT const char* API_CALL mk_media_source_get_stream(const mk_media_source API_EXPORT int API_CALL mk_media_source_get_reader_count(const mk_media_source ctx); //MediaSource::totalReaderCount() API_EXPORT int API_CALL mk_media_source_get_total_reader_count(const mk_media_source ctx); +// get track count from MediaSource +API_EXPORT int API_CALL mk_media_source_get_track_count(const mk_media_source ctx); +// get track by index from MediaSource +API_EXPORT mk_track API_CALL mk_media_source_get_track(const mk_media_source ctx, int index); /** * 直播源在ZLMediaKit中被称作为MediaSource, * 目前支持3种,分别是RtmpMediaSource、RtspMediaSource、HlsMediaSource diff --git a/api/source/mk_events_objects.cpp b/api/source/mk_events_objects.cpp index 617151e5..b92aa7e8 100644 --- a/api/source/mk_events_objects.cpp +++ b/api/source/mk_events_objects.cpp @@ -198,6 +198,22 @@ API_EXPORT int API_CALL mk_media_source_get_total_reader_count(const mk_media_so return src->totalReaderCount(); } +API_EXPORT int API_CALL mk_media_source_get_track_count(const mk_media_source ctx) { + assert(ctx); + MediaSource *src = (MediaSource *)ctx; + return src->getTracks(false).size(); +} + +API_EXPORT mk_track API_CALL mk_media_source_get_track(const mk_media_source ctx, int index) { + assert(ctx); + MediaSource *src = (MediaSource *)ctx; + auto tracks = src->getTracks(false); + if (index < 0 && index >= tracks.size()) { + return nullptr; + } + return reinterpret_cast(& (tracks[index])); +} + API_EXPORT int API_CALL mk_media_source_close(const mk_media_source ctx,int force){ assert(ctx); MediaSource *src = (MediaSource *)ctx;