From 071f008108b1408ca7d3521ace97ebf213b67951 Mon Sep 17 00:00:00 2001 From: lidaofu-hub <61726674+lidaofu-hub@users.noreply.github.com> Date: Fri, 5 Apr 2024 22:09:40 +0800 Subject: [PATCH] add c api for MediaSource (#3433) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 补充MediaSource C API 获取源地址 获取源类型 获取创建时间戳 --------- Co-authored-by: 李道甫 --- api/include/mk_common.h | 4 ++++ api/include/mk_events_objects.h | 10 ++++++++++ api/source/mk_events_objects.cpp | 24 ++++++++++++++++++++++++ api/source/mk_util.cpp | 4 ---- 4 files changed, 38 insertions(+), 4 deletions(-) diff --git a/api/include/mk_common.h b/api/include/mk_common.h index 90b4c8a6..b6f480cd 100755 --- a/api/include/mk_common.h +++ b/api/include/mk_common.h @@ -24,6 +24,10 @@ # define API_CALL #endif +#ifndef _WIN32 +#define _strdup strdup +#endif + #if defined(_WIN32) && defined(_MSC_VER) # if !defined(GENERATE_EXPORT) # if defined(MediaKitApi_EXPORTS) diff --git a/api/include/mk_events_objects.h b/api/include/mk_events_objects.h index ddbaf87d..428f9dc6 100644 --- a/api/include/mk_events_objects.h +++ b/api/include/mk_events_objects.h @@ -103,6 +103,16 @@ API_EXPORT int API_CALL mk_media_source_get_track_count(const mk_media_source ct 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); +// MediaSource::getOriginUrl() +API_EXPORT const char* API_CALL mk_media_source_get_origin_url(const mk_media_source ctx); +// MediaSource::getOriginType() +API_EXPORT int API_CALL mk_media_source_get_origin_type(const mk_media_source ctx); +// MediaSource::getCreateStamp() +API_EXPORT uint64_t API_CALL mk_media_source_get_create_stamp(const mk_media_source ctx); +// MediaSource::isRecording() 0:hls,1:MP4 +API_EXPORT int API_CALL mk_media_source_is_recording(const mk_media_source ctx, int type); + + /** * 直播源在ZLMediaKit中被称作为MediaSource, diff --git a/api/source/mk_events_objects.cpp b/api/source/mk_events_objects.cpp index 7046f1ab..758e38a3 100644 --- a/api/source/mk_events_objects.cpp +++ b/api/source/mk_events_objects.cpp @@ -228,6 +228,30 @@ API_EXPORT int API_CALL mk_media_source_broadcast_msg(const mk_media_source ctx, return src->broadcastMessage(any); } +API_EXPORT const char* API_CALL mk_media_source_get_origin_url(const mk_media_source ctx) { + assert(ctx); + MediaSource *src = (MediaSource *)ctx; + return _strdup(src->getOriginUrl().c_str()); +} + +API_EXPORT int API_CALL mk_media_source_get_origin_type(const mk_media_source ctx) { + assert(ctx); + MediaSource *src = (MediaSource *)ctx; + return static_cast(src->getOriginType()); +} + +API_EXPORT uint64_t API_CALL mk_media_source_get_create_stamp(const mk_media_source ctx) { + assert(ctx); + MediaSource *src = (MediaSource *)ctx; + return src->getCreateStamp(); +} + +API_EXPORT int API_CALL mk_media_source_is_recording(const mk_media_source ctx,int type) { + assert(ctx); + MediaSource *src = (MediaSource *)ctx; + return src->isRecording((Recorder::type)type); +} + API_EXPORT int API_CALL mk_media_source_close(const mk_media_source ctx,int force){ assert(ctx); MediaSource *src = (MediaSource *)ctx; diff --git a/api/source/mk_util.cpp b/api/source/mk_util.cpp index 66d0d3b2..eda27162 100644 --- a/api/source/mk_util.cpp +++ b/api/source/mk_util.cpp @@ -21,10 +21,6 @@ using namespace std; using namespace toolkit; using namespace mediakit; -#ifndef _WIN32 -#define _strdup strdup -#endif - API_EXPORT void API_CALL mk_free(void *ptr) { free(ptr); }