添加pusher接口

整理代码
This commit is contained in:
xiongziliang 2019-12-18 14:43:32 +08:00
parent ee4659a185
commit ef7e937808
10 changed files with 62 additions and 25 deletions

View File

@ -37,6 +37,7 @@ typedef void *mk_media;
/** /**
* *
* @param vhost __defaultVhost__
* @param app live * @param app live
* @param stream idcamera * @param stream idcamera
* @param duration ()0 * @param duration ()0
@ -44,7 +45,7 @@ typedef void *mk_media;
* @param mp4_enabled mp4 * @param mp4_enabled mp4
* @return * @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);
/** /**
* *

View File

@ -33,5 +33,6 @@
#include "proxyplayer.h" #include "proxyplayer.h"
#include "flvrecorder.h" #include "flvrecorder.h"
#include "player.h" #include "player.h"
#include "pusher.h"
#endif /* MK_API_H_ */ #endif /* MK_API_H_ */

View File

@ -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); 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 * @return
*/ */
API_EXPORT mk_player API_CALL mk_player_create(); 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 * url
* @param ctx * @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); 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 ctx
* @param cb * @param cb ,null
* @param user_data * @param user_data
*/ */
API_EXPORT void API_CALL mk_player_set_on_result(mk_player ctx, on_mk_play_event cb, void *user_data); API_EXPORT void API_CALL mk_player_set_on_result(mk_player ctx, on_mk_play_event cb, void *user_data);

View File

@ -37,6 +37,7 @@ typedef void *mk_proxy_player;
/** /**
* *
* @param vhost __defaultVhost__
* @param app * @param app
* @param stream * @param stream
* @param rtp_type rtsp播放方式:RTP_TCP = 0, RTP_UDP = 1, RTP_MULTICAST = 2 * @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 * @param mp4_enabled mp4
* @return * @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); 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 * @param ctx

View File

@ -45,7 +45,7 @@ static TcpServer::Ptr http_server[2];
//////////////////////////environment init/////////////////////////// //////////////////////////environment init///////////////////////////
API_EXPORT void API_CALL mk_env_init(const config *cfg) { API_EXPORT void API_CALL mk_env_init(const config *cfg) {
assert(cfg != nullptr); assert(cfg);
static onceToken token([&]() { static onceToken token([&]() {
Logger::Instance().add(std::make_shared<ConsoleChannel>("console", (LogLevel) cfg->log_level)); Logger::Instance().add(std::make_shared<ConsoleChannel>("console", (LogLevel) cfg->log_level));
Logger::Instance().setWriter(std::make_shared<AsyncLogWriter>()); Logger::Instance().setWriter(std::make_shared<AsyncLogWriter>());
@ -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) { 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()) { if (mINI::Instance().find(key) == mINI::Instance().end()) {
WarnL << "key:" << key << " not existed!"; WarnL << "key:" << key << " not existed!";
return; 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, ...) { 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); LogContextCapturer info(Logger::Instance(), (LogLevel) level, file, function, line);
va_list pArg; va_list pArg;
va_start(pArg, fmt); va_start(pArg, fmt);

View File

@ -34,13 +34,14 @@ API_EXPORT mk_flv_recorder API_CALL mk_flv_recorder_create(){
return ret; return ret;
} }
API_EXPORT void API_CALL mk_flv_recorder_release(mk_flv_recorder ctx){ API_EXPORT void API_CALL mk_flv_recorder_release(mk_flv_recorder ctx){
assert(ctx);
FlvRecorder::Ptr *record = (FlvRecorder::Ptr *)(ctx); FlvRecorder::Ptr *record = (FlvRecorder::Ptr *)(ctx);
delete record; 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){ 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; assert(ctx && app && stream && file_path);
FlvRecorder::Ptr *record = (FlvRecorder::Ptr *)(ctx);
try { try {
FlvRecorder::Ptr *record = (FlvRecorder::Ptr *)(ctx);
(*record)->startRecord(EventPollerPool::Instance().getPoller(), DEFAULT_VHOST,app,stream,file_path); (*record)->startRecord(EventPollerPool::Instance().getPoller(), DEFAULT_VHOST,app,stream,file_path);
return 0; return 0;
}catch (std::exception &ex){ }catch (std::exception &ex){

View File

@ -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) { API_EXPORT void API_CALL mk_http_downloader_release(mk_http_downloader ctx) {
assert(ctx);
HttpDownloader::Ptr *obj = (HttpDownloader::Ptr *) ctx; HttpDownloader::Ptr *obj = (HttpDownloader::Ptr *) ctx;
delete obj; 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) { 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; HttpDownloader::Ptr *obj = (HttpDownloader::Ptr *) ctx;
(*obj)->setOnResult([cb, user_data](ErrCode code, const string &errMsg, const string &filePath) { (*obj)->setOnResult([cb, user_data](ErrCode code, const string &errMsg, const string &filePath) {
if (cb) { if (cb) {

View File

@ -32,17 +32,20 @@ using namespace std;
using namespace toolkit; using namespace toolkit;
using namespace mediakit; 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) { 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) {
DevChannel::Ptr *obj(new DevChannel::Ptr(new DevChannel(DEFAULT_VHOST, app, stream, duration, true, true, hls_enabled, 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; return (mk_media) obj;
} }
API_EXPORT void API_CALL mk_media_release(mk_media ctx) { API_EXPORT void API_CALL mk_media_release(mk_media ctx) {
assert(ctx);
DevChannel::Ptr *obj = (DevChannel::Ptr *) ctx; DevChannel::Ptr *obj = (DevChannel::Ptr *) ctx;
delete obj; delete obj;
} }
API_EXPORT void API_CALL mk_media_init_h264(mk_media ctx, int width, int height, int frameRate) { 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; DevChannel::Ptr *obj = (DevChannel::Ptr *) ctx;
VideoInfo info; VideoInfo info;
info.iFrameRate = frameRate; 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) { 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; DevChannel::Ptr *obj = (DevChannel::Ptr *) ctx;
VideoInfo info; VideoInfo info;
info.iFrameRate = frameRate; 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) { 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; DevChannel::Ptr *obj = (DevChannel::Ptr *) ctx;
AudioInfo info; AudioInfo info;
info.iSampleRate = sample_rate; 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) { 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; DevChannel::Ptr *obj = (DevChannel::Ptr *) ctx;
(*obj)->inputH264((char *) data, len, dts, pts); (*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) { 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; DevChannel::Ptr *obj = (DevChannel::Ptr *) ctx;
(*obj)->inputH265((char *) data, len, dts, pts); (*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) { 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; DevChannel::Ptr *obj = (DevChannel::Ptr *) ctx;
(*obj)->inputAAC((char *) data, len, dts, with_adts_header); (*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) { 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; DevChannel::Ptr *obj = (DevChannel::Ptr *) ctx;
(*obj)->inputAAC((char *) data, len, dts, (char *) adts); (*obj)->inputAAC((char *) data, len, dts, (char *) adts);
} }

View File

@ -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){ API_EXPORT void API_CALL mk_player_set_option(mk_player ctx,const char* key,const char *val){
assert(ctx); assert(ctx && key && val);
assert(key);
assert(val);
MediaPlayer::Ptr &player = *((MediaPlayer::Ptr *)ctx); MediaPlayer::Ptr &player = *((MediaPlayer::Ptr *)ctx);
string key_str(key), val_str(val); string key_str(key), val_str(val);
player->getPoller()->async([key_str,val_str,player](){ 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) { API_EXPORT void API_CALL mk_player_play(mk_player ctx, const char *url) {
assert(ctx); assert(ctx && url);
assert(url);
MediaPlayer::Ptr &player = *((MediaPlayer::Ptr *)ctx); MediaPlayer::Ptr &player = *((MediaPlayer::Ptr *)ctx);
string url_str(url); string url_str(url);
player->getPoller()->async([url_str,player](){ 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) { static void mk_player_set_on_event(mk_player ctx, on_mk_play_event cb, void *user_data, int type) {
assert(ctx); assert(ctx && cb);
assert(cb);
MediaPlayer::Ptr &player = *((MediaPlayer::Ptr *)ctx); MediaPlayer::Ptr &player = *((MediaPlayer::Ptr *)ctx);
player->getPoller()->async([cb,user_data,type,player](){ 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) { API_EXPORT void API_CALL mk_player_set_on_data(mk_player ctx, on_mk_play_data cb, void *user_data) {
assert(ctx); assert(ctx && cb);
assert(cb);
MediaPlayer::Ptr &player = *((MediaPlayer::Ptr *)ctx); MediaPlayer::Ptr &player = *((MediaPlayer::Ptr *)ctx);
player->getPoller()->async([player,cb,user_data](){ player->getPoller()->async([player,cb,user_data](){
//切换线程后再操作 //切换线程后再操作

View File

@ -30,18 +30,34 @@
using namespace toolkit; using namespace toolkit;
using namespace mediakit; 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) { 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) {
PlayerProxy::Ptr *obj(new PlayerProxy::Ptr(new PlayerProxy(DEFAULT_VHOST, app, stream, true, true, hls_enabled, mp4_enabled))); assert(vhost && app && stream);
(**obj)[Client::kRtpType] = rtp_type; PlayerProxy::Ptr *obj(new PlayerProxy::Ptr(new PlayerProxy(vhost, app, stream, true, true, hls_enabled, mp4_enabled)));
return (mk_proxy_player) obj; return (mk_proxy_player) obj;
} }
API_EXPORT void API_CALL mk_proxy_player_release(mk_proxy_player ctx) { API_EXPORT void API_CALL mk_proxy_player_release(mk_proxy_player ctx) {
assert(ctx);
PlayerProxy::Ptr *obj = (PlayerProxy::Ptr *) ctx; PlayerProxy::Ptr *obj = (PlayerProxy::Ptr *) ctx;
delete obj; delete obj;
} }
API_EXPORT void API_CALL mk_proxy_player_play(mk_proxy_player ctx, const char *url) { API_EXPORT void API_CALL mk_proxy_player_set_option(mk_proxy_player ctx, const char *key, const char *val){
PlayerProxy::Ptr *obj = (PlayerProxy::Ptr *) ctx; assert(ctx && key && val);
(*obj)->play(url); 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);
});
} }