From ef7e937808081c9fdb9802b2f003ce61d0c7945c Mon Sep 17 00:00:00 2001 From: xiongziliang <771730766@qq.com> Date: Wed, 18 Dec 2019 14:43:32 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0pusher=E6=8E=A5=E5=8F=A3=20?= =?UTF-8?q?=E6=95=B4=E7=90=86=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- api/include/media.h | 3 ++- api/include/mediakit.h | 1 + api/include/player.h | 6 +++--- api/include/proxyplayer.h | 12 +++++++++++- api/source/common.cpp | 4 +++- api/source/flvrecorder.cpp | 5 +++-- api/source/httpdownloader.cpp | 2 ++ api/source/media.cpp | 13 +++++++++++-- api/source/player.cpp | 13 ++++--------- api/source/proxyplayer.cpp | 28 ++++++++++++++++++++++------ 10 files changed, 62 insertions(+), 25 deletions(-) diff --git a/api/include/media.h b/api/include/media.h index f80e4083..55c6f141 100755 --- a/api/include/media.h +++ b/api/include/media.h @@ -37,6 +37,7 @@ typedef void *mk_media; /** * 创建一个媒体源 + * @param vhost 虚拟主机名,一般为__defaultVhost__ * @param app 应用名,推荐为live * @param stream 流id,例如camera * @param duration 时长(单位秒),直播则为0 @@ -44,7 +45,7 @@ typedef void *mk_media; * @param mp4_enabled 是否生成mp4 * @return 对象指针 */ -API_EXPORT mk_media API_CALL mk_media_create(const char *app, const char *stream, float duration, int hls_enabled, int mp4_enabled); +API_EXPORT mk_media API_CALL mk_media_create(const char *vhost, const char *app, const char *stream, float duration, int hls_enabled, int mp4_enabled); /** * 销毁媒体源 diff --git a/api/include/mediakit.h b/api/include/mediakit.h index 534eac83..2cbcc442 100755 --- a/api/include/mediakit.h +++ b/api/include/mediakit.h @@ -33,5 +33,6 @@ #include "proxyplayer.h" #include "flvrecorder.h" #include "player.h" +#include "pusher.h" #endif /* MK_API_H_ */ diff --git a/api/include/player.h b/api/include/player.h index cb4da62c..ad119a72 100755 --- a/api/include/player.h +++ b/api/include/player.h @@ -56,7 +56,7 @@ typedef void(API_CALL *on_mk_play_event)(void *user_data,int err_code,const char typedef void(API_CALL *on_mk_play_data)(void *user_data,int track_type,int codec_id,void *data,int len,uint32_t dts,uint32_t pts); /** - * 创建一个播放器,支持rtmp/rtsp + * 创建一个播放器,支持rtmp[s]/rtsp[s] * @return 播放器指针 */ API_EXPORT mk_player API_CALL mk_player_create(); @@ -78,7 +78,7 @@ API_EXPORT void API_CALL mk_player_set_option(mk_player ctx, const char *key, co /** * 开始播放url * @param ctx 播放器指针 - * @param url rtsp/rtmp url + * @param url rtsp[s]/rtmp[s] url */ API_EXPORT void API_CALL mk_player_play(mk_player ctx, const char *url); @@ -99,7 +99,7 @@ API_EXPORT void API_CALL mk_player_seekto(mk_player ctx, float progress); /** * 设置播放器开启播放结果回调函数 * @param ctx 播放器指针 - * @param cb 回调函数指针 + * @param cb 回调函数指针,不得为null * @param user_data 用户数据指针 */ API_EXPORT void API_CALL mk_player_set_on_result(mk_player ctx, on_mk_play_event cb, void *user_data); diff --git a/api/include/proxyplayer.h b/api/include/proxyplayer.h index 660be015..d1230f7f 100644 --- a/api/include/proxyplayer.h +++ b/api/include/proxyplayer.h @@ -37,6 +37,7 @@ typedef void *mk_proxy_player; /** * 创建一个代理播放器 + * @param vhost 虚拟主机名,一般为__defaultVhost__ * @param app 应用名 * @param stream 流名 * @param rtp_type rtsp播放方式:RTP_TCP = 0, RTP_UDP = 1, RTP_MULTICAST = 2 @@ -44,7 +45,7 @@ typedef void *mk_proxy_player; * @param mp4_enabled 是否生成mp4 * @return 对象指针 */ -API_EXPORT mk_proxy_player API_CALL mk_proxy_player_create(const char *app, const char *stream, int rtp_type, int hls_enabled, int mp4_enabled); +API_EXPORT mk_proxy_player API_CALL mk_proxy_player_create(const char *vhost, const char *app, const char *stream, int hls_enabled, int mp4_enabled); /** * 销毁代理播放器 @@ -52,6 +53,15 @@ API_EXPORT mk_proxy_player API_CALL mk_proxy_player_create(const char *app, cons */ API_EXPORT void API_CALL mk_proxy_player_release(mk_proxy_player ctx); + +/** + * 设置代理播放器配置选项 + * @param ctx 代理播放器指针 + * @param key 配置项键,支持 net_adapter/rtp_type/rtsp_user/rtsp_pwd/protocol_timeout_ms/media_timeout_ms/beat_interval_ms/max_analysis_ms + * @param val 配置项值,如果是整形,需要转换成统一转换成string + */ +API_EXPORT void API_CALL mk_proxy_player_set_option(mk_proxy_player ctx, const char *key, const char *val); + /** * 开始播放 * @param ctx 对象指针 diff --git a/api/source/common.cpp b/api/source/common.cpp index 9299bd79..8f6d79b6 100755 --- a/api/source/common.cpp +++ b/api/source/common.cpp @@ -45,7 +45,7 @@ static TcpServer::Ptr http_server[2]; //////////////////////////environment init/////////////////////////// API_EXPORT void API_CALL mk_env_init(const config *cfg) { - assert(cfg != nullptr); + assert(cfg); static onceToken token([&]() { Logger::Instance().add(std::make_shared("console", (LogLevel) cfg->log_level)); Logger::Instance().setWriter(std::make_shared()); @@ -70,6 +70,7 @@ API_EXPORT void API_CALL mk_env_init(const config *cfg) { } API_EXPORT void API_CALL mk_set_option(const char *key, const char *val) { + assert(key && val); if (mINI::Instance().find(key) == mINI::Instance().end()) { WarnL << "key:" << key << " not existed!"; return; @@ -129,6 +130,7 @@ API_EXPORT uint16_t API_CALL mk_rtmp_server_start(uint16_t port, int ssl) { } API_EXPORT void API_CALL mk_log_printf(int level, const char *file, const char *function, int line, const char *fmt, ...) { + assert(file && function && fmt); LogContextCapturer info(Logger::Instance(), (LogLevel) level, file, function, line); va_list pArg; va_start(pArg, fmt); diff --git a/api/source/flvrecorder.cpp b/api/source/flvrecorder.cpp index ab89af80..93882320 100644 --- a/api/source/flvrecorder.cpp +++ b/api/source/flvrecorder.cpp @@ -34,13 +34,14 @@ API_EXPORT mk_flv_recorder API_CALL mk_flv_recorder_create(){ return ret; } API_EXPORT void API_CALL mk_flv_recorder_release(mk_flv_recorder ctx){ + assert(ctx); FlvRecorder::Ptr *record = (FlvRecorder::Ptr *)(ctx); delete record; } API_EXPORT int API_CALL mk_flv_recorder_start(mk_flv_recorder ctx, const char *app, const char *stream, const char *file_path){ - DebugL << app << " " << stream << " " << file_path; - FlvRecorder::Ptr *record = (FlvRecorder::Ptr *)(ctx); + assert(ctx && app && stream && file_path); try { + FlvRecorder::Ptr *record = (FlvRecorder::Ptr *)(ctx); (*record)->startRecord(EventPollerPool::Instance().getPoller(), DEFAULT_VHOST,app,stream,file_path); return 0; }catch (std::exception &ex){ diff --git a/api/source/httpdownloader.cpp b/api/source/httpdownloader.cpp index 0f9c5004..4e742924 100755 --- a/api/source/httpdownloader.cpp +++ b/api/source/httpdownloader.cpp @@ -37,11 +37,13 @@ API_EXPORT mk_http_downloader API_CALL mk_http_downloader_create() { } API_EXPORT void API_CALL mk_http_downloader_release(mk_http_downloader ctx) { + assert(ctx); HttpDownloader::Ptr *obj = (HttpDownloader::Ptr *) ctx; delete obj; } API_EXPORT void API_CALL mk_http_downloader_start(mk_http_downloader ctx, const char *url, const char *file, on_mk_download_complete cb, void *user_data) { + assert(ctx && url && file); HttpDownloader::Ptr *obj = (HttpDownloader::Ptr *) ctx; (*obj)->setOnResult([cb, user_data](ErrCode code, const string &errMsg, const string &filePath) { if (cb) { diff --git a/api/source/media.cpp b/api/source/media.cpp index 1a1addb2..df488b51 100755 --- a/api/source/media.cpp +++ b/api/source/media.cpp @@ -32,17 +32,20 @@ using namespace std; using namespace toolkit; using namespace mediakit; -API_EXPORT mk_media API_CALL mk_media_create(const char *app, const char *stream, float duration, int hls_enabled, int mp4_enabled) { - DevChannel::Ptr *obj(new DevChannel::Ptr(new DevChannel(DEFAULT_VHOST, app, stream, duration, true, true, hls_enabled, mp4_enabled))); +API_EXPORT mk_media API_CALL mk_media_create(const char *vhost, const char *app, const char *stream, float duration, int hls_enabled, int mp4_enabled) { + assert(vhost && app && stream); + DevChannel::Ptr *obj(new DevChannel::Ptr(new DevChannel(vhost, app, stream, duration, true, true, hls_enabled, mp4_enabled))); return (mk_media) obj; } API_EXPORT void API_CALL mk_media_release(mk_media ctx) { + assert(ctx); DevChannel::Ptr *obj = (DevChannel::Ptr *) ctx; delete obj; } API_EXPORT void API_CALL mk_media_init_h264(mk_media ctx, int width, int height, int frameRate) { + assert(ctx); DevChannel::Ptr *obj = (DevChannel::Ptr *) ctx; VideoInfo info; info.iFrameRate = frameRate; @@ -52,6 +55,7 @@ API_EXPORT void API_CALL mk_media_init_h264(mk_media ctx, int width, int height, } API_EXPORT void API_CALL mk_media_init_h265(mk_media ctx, int width, int height, int frameRate) { + assert(ctx); DevChannel::Ptr *obj = (DevChannel::Ptr *) ctx; VideoInfo info; info.iFrameRate = frameRate; @@ -61,6 +65,7 @@ API_EXPORT void API_CALL mk_media_init_h265(mk_media ctx, int width, int height, } API_EXPORT void API_CALL mk_media_init_aac(mk_media ctx, int channel, int sample_bit, int sample_rate, int profile) { + assert(ctx); DevChannel::Ptr *obj = (DevChannel::Ptr *) ctx; AudioInfo info; info.iSampleRate = sample_rate; @@ -71,21 +76,25 @@ API_EXPORT void API_CALL mk_media_init_aac(mk_media ctx, int channel, int sample } API_EXPORT void API_CALL mk_media_input_h264(mk_media ctx, void *data, int len, uint32_t dts, uint32_t pts) { + assert(ctx && data && len > 0); DevChannel::Ptr *obj = (DevChannel::Ptr *) ctx; (*obj)->inputH264((char *) data, len, dts, pts); } API_EXPORT void API_CALL mk_media_input_h265(mk_media ctx, void *data, int len, uint32_t dts, uint32_t pts) { + assert(ctx && data && len > 0); DevChannel::Ptr *obj = (DevChannel::Ptr *) ctx; (*obj)->inputH265((char *) data, len, dts, pts); } API_EXPORT void API_CALL mk_media_input_aac(mk_media ctx, void *data, int len, uint32_t dts, int with_adts_header) { + assert(ctx && data && len > 0); DevChannel::Ptr *obj = (DevChannel::Ptr *) ctx; (*obj)->inputAAC((char *) data, len, dts, with_adts_header); } API_EXPORT void API_CALL mk_media_input_aac1(mk_media ctx, void *data, int len, uint32_t dts, void *adts) { + assert(ctx && data && len > 0 && adts); DevChannel::Ptr *obj = (DevChannel::Ptr *) ctx; (*obj)->inputAAC((char *) data, len, dts, (char *) adts); } diff --git a/api/source/player.cpp b/api/source/player.cpp index 2e60f7cd..6a320f0e 100755 --- a/api/source/player.cpp +++ b/api/source/player.cpp @@ -42,9 +42,7 @@ API_EXPORT void API_CALL mk_player_release(mk_player ctx) { } API_EXPORT void API_CALL mk_player_set_option(mk_player ctx,const char* key,const char *val){ - assert(ctx); - assert(key); - assert(val); + assert(ctx && key && val); MediaPlayer::Ptr &player = *((MediaPlayer::Ptr *)ctx); string key_str(key), val_str(val); player->getPoller()->async([key_str,val_str,player](){ @@ -53,8 +51,7 @@ API_EXPORT void API_CALL mk_player_set_option(mk_player ctx,const char* key,cons }); } API_EXPORT void API_CALL mk_player_play(mk_player ctx, const char *url) { - assert(ctx); - assert(url); + assert(ctx && url); MediaPlayer::Ptr &player = *((MediaPlayer::Ptr *)ctx); string url_str(url); player->getPoller()->async([url_str,player](){ @@ -82,8 +79,7 @@ API_EXPORT void API_CALL mk_player_seekto(mk_player ctx, float progress) { } static void mk_player_set_on_event(mk_player ctx, on_mk_play_event cb, void *user_data, int type) { - assert(ctx); - assert(cb); + assert(ctx && cb); MediaPlayer::Ptr &player = *((MediaPlayer::Ptr *)ctx); player->getPoller()->async([cb,user_data,type,player](){ //切换线程后再操作 @@ -108,8 +104,7 @@ API_EXPORT void API_CALL mk_player_set_on_shutdown(mk_player ctx, on_mk_play_eve } API_EXPORT void API_CALL mk_player_set_on_data(mk_player ctx, on_mk_play_data cb, void *user_data) { - assert(ctx); - assert(cb); + assert(ctx && cb); MediaPlayer::Ptr &player = *((MediaPlayer::Ptr *)ctx); player->getPoller()->async([player,cb,user_data](){ //切换线程后再操作 diff --git a/api/source/proxyplayer.cpp b/api/source/proxyplayer.cpp index d733fe01..0bf9d43a 100644 --- a/api/source/proxyplayer.cpp +++ b/api/source/proxyplayer.cpp @@ -30,18 +30,34 @@ using namespace toolkit; using namespace mediakit; -API_EXPORT mk_proxy_player API_CALL mk_proxy_player_create(const char *app, const char *stream, int rtp_type, int hls_enabled, int mp4_enabled) { - PlayerProxy::Ptr *obj(new PlayerProxy::Ptr(new PlayerProxy(DEFAULT_VHOST, app, stream, true, true, hls_enabled, mp4_enabled))); - (**obj)[Client::kRtpType] = rtp_type; +API_EXPORT mk_proxy_player API_CALL mk_proxy_player_create(const char *vhost, const char *app, const char *stream, int hls_enabled, int mp4_enabled) { + assert(vhost && app && stream); + PlayerProxy::Ptr *obj(new PlayerProxy::Ptr(new PlayerProxy(vhost, app, stream, true, true, hls_enabled, mp4_enabled))); return (mk_proxy_player) obj; } API_EXPORT void API_CALL mk_proxy_player_release(mk_proxy_player ctx) { + assert(ctx); PlayerProxy::Ptr *obj = (PlayerProxy::Ptr *) ctx; delete obj; } -API_EXPORT void API_CALL mk_proxy_player_play(mk_proxy_player ctx, const char *url) { - PlayerProxy::Ptr *obj = (PlayerProxy::Ptr *) ctx; - (*obj)->play(url); +API_EXPORT void API_CALL mk_proxy_player_set_option(mk_proxy_player ctx, const char *key, const char *val){ + assert(ctx && key && val); + PlayerProxy::Ptr &obj = *((PlayerProxy::Ptr *) ctx); + string key_str(key),val_str(val); + obj->getPoller()->async([obj,key_str,val_str](){ + //切换线程再操作 + (*obj)[key_str] = val_str; + }); +} + +API_EXPORT void API_CALL mk_proxy_player_play(mk_proxy_player ctx, const char *url) { + assert(ctx && url); + PlayerProxy::Ptr &obj = *((PlayerProxy::Ptr *) ctx); + string url_str(url); + obj->getPoller()->async([obj,url_str](){ + //切换线程再操作 + obj->play(url_str); + }); }