From cb4709e60cdbf7dd8dcc31d416cc430eefb581a8 Mon Sep 17 00:00:00 2001 From: lidaofu Date: Fri, 18 Oct 2024 15:22:29 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20C=20Api=E5=A2=9E=E5=8A=A0loadMP4File?= =?UTF-8?q?=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/include/mk_recorder.h | 18 ++++++++++++++ api/source/mk_recorder.cpp | 51 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 69 insertions(+) diff --git a/api/include/mk_recorder.h b/api/include/mk_recorder.h index e4f101e7..a16e801e 100644 --- a/api/include/mk_recorder.h +++ b/api/include/mk_recorder.h @@ -12,6 +12,7 @@ #define MK_RECORDER_API_H_ #include "mk_common.h" +#include "mk_util.h" #ifdef __cplusplus extern "C" { @@ -124,6 +125,23 @@ API_EXPORT int API_CALL mk_recorder_start(int type, const char *vhost, const cha */ API_EXPORT int API_CALL mk_recorder_stop(int type, const char *vhost, const char *app, const char *stream); + +#if ENABLE_MP4 + +/** + * 加载mp4列表 + * @param vhost 虚拟主机 + * @param app app + * @param stream 流id + * @param file_path 文件路径 + * @param file_repeat 循环解复用 + * @param ini 配置 + */ +API_EXPORT void API_CALL mk_player_load_mp4_file(const char *vhost, const char *app, const char *stream, const char *file_path, int file_repeat); +API_EXPORT void API_CALL mk_player_load_mp4_file2(const char *vhost, const char *app, const char *stream, const char *file_path, int file_repeat, mk_ini ini); + +#endif + #ifdef __cplusplus } #endif diff --git a/api/source/mk_recorder.cpp b/api/source/mk_recorder.cpp index 3f57cc7b..be6c1c1d 100644 --- a/api/source/mk_recorder.cpp +++ b/api/source/mk_recorder.cpp @@ -11,6 +11,7 @@ #include "mk_recorder.h" #include "Rtmp/FlvMuxer.h" #include "Record/Recorder.h" +#include "Record/MP4Reader.h" using namespace std; using namespace toolkit; @@ -83,3 +84,53 @@ API_EXPORT int API_CALL mk_recorder_stop(int type, const char *vhost, const char assert(vhost && app && stream); return stopRecord((Recorder::type)type,vhost,app,stream); } + +#if ENABLE_MP4 + +API_EXPORT void API_CALL mk_player_load_mp4_file(const char *vhost, const char *app, const char *stream, const char *file_path, int file_repeat) { + assert(vhost && app && stream && file_path); + ProtocolOption option; + // mp4支持多track [AUTO-TRANSLATED:b9688762] + // mp4 supports multiple tracks + option.max_track = 16; + // 默认解复用mp4不生成mp4 [AUTO-TRANSLATED:11f2dcee] + // By default, demultiplexing mp4 does not generate mp4 + option.enable_mp4 = false; + // 但是如果参数明确指定开启mp4, 那么也允许之 [AUTO-TRANSLATED:b143a9e3] + // But if the parameter explicitly specifies to enable mp4, then it is also allowed + + // 强制无人观看时自动关闭 [AUTO-TRANSLATED:f7c85948] + // Force automatic shutdown when no one is watching + option.auto_close = true; + MediaTuple tuple = { vhost, app, stream, "" }; + auto reader = std::make_shared(tuple, file_path, option); + // sample_ms设置为0,从配置文件加载;file_repeat可以指定,如果配置文件也指定循环解复用,那么强制开启 [AUTO-TRANSLATED:23e826b4] + // sample_ms is set to 0, loaded from the configuration file; file_repeat can be specified, if the configuration file also specifies loop demultiplexing, + // then force it to be enabled + reader->startReadMP4(0, true, file_repeat); +} + +API_EXPORT void API_CALL mk_player_load_mp4_file2(const char *vhost, const char *app, const char *stream, const char *file_path, int file_repeat, mk_ini ini) { + assert(vhost && app && stream && file_path); + ProtocolOption option(*((mINI *)ini)); + // mp4支持多track [AUTO-TRANSLATED:b9688762] + // mp4 supports multiple tracks + option.max_track = 16; + // 默认解复用mp4不生成mp4 [AUTO-TRANSLATED:11f2dcee] + // By default, demultiplexing mp4 does not generate mp4 + option.enable_mp4 = false; + // 但是如果参数明确指定开启mp4, 那么也允许之 [AUTO-TRANSLATED:b143a9e3] + // But if the parameter explicitly specifies to enable mp4, then it is also allowed + + // 强制无人观看时自动关闭 [AUTO-TRANSLATED:f7c85948] + // Force automatic shutdown when no one is watching + option.auto_close = true; + MediaTuple tuple = { vhost, app, stream, "" }; + auto reader = std::make_shared(tuple, file_path, option); + // sample_ms设置为0,从配置文件加载;file_repeat可以指定,如果配置文件也指定循环解复用,那么强制开启 [AUTO-TRANSLATED:23e826b4] + // sample_ms is set to 0, loaded from the configuration file; file_repeat can be specified, if the configuration file also specifies loop demultiplexing, + // then force it to be enabled + reader->startReadMP4(0, true, file_repeat); +} + +#endif