新增mk_media_source_get_track方法: #2530

This commit is contained in:
xia-chu 2023-06-10 09:34:00 +08:00 committed by 夏楚
parent d3f1c2fab1
commit 24fb666fb3
2 changed files with 21 additions and 0 deletions

View File

@ -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
* 3RtmpMediaSourceRtspMediaSourceHlsMediaSource

View File

@ -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<mk_track>(& (tracks[index]));
}
API_EXPORT int API_CALL mk_media_source_close(const mk_media_source ctx,int force){
assert(ctx);
MediaSource *src = (MediaSource *)ctx;