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;