初步提供c标准接口

This commit is contained in:
xiongziliang 2019-12-17 18:45:31 +08:00
parent ee88297d4a
commit 31438cfde4
13 changed files with 894 additions and 0 deletions

View File

@ -187,6 +187,9 @@ elseif(NOT ANDROID OR IOS)
list(APPEND LINK_LIB_LIST pthread)
endif ()
#c
add_subdirectory(api)
if (NOT IOS)
#
add_subdirectory(tests)

11
api/CMakeLists.txt Normal file
View File

@ -0,0 +1,11 @@
include_directories(include source)
file(GLOB api_src_list include/*.h source/*.cpp source/*.h source/*.c)
add_library(api SHARED ${api_src_list})
if(WIN32)
add_definitions(-DMediaKitApi_EXPORTS)
endif()
target_link_libraries(api ${LINK_LIB_LIST})

129
api/include/common.h Executable file
View File

@ -0,0 +1,129 @@
/*
* MIT License
*
* Copyright (c) 2019 xiongziliang <771730766@qq.com>
*
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef MK_COMMON_H
#define MK_COMMON_H
#include <stdint.h>
#if defined(_WIN32)
#if defined(MediaKitApi_EXPORTS)
#define API_EXPORT __declspec(dllexport)
#else
#define API_EXPORT __declspec(dllimport)
#endif
#define API_CALL __cdecl
#else
#define API_EXPORT
#define API_CALL
#endif
#ifdef __cplusplus
extern "C" {
#endif
typedef struct {
// 线程数
int thread_num;
// 日志级别,支持0~4
int log_level;
// 配置文件是内容还是路径
int ini_is_path;
// 配置文件内容或路径可以为NULL
const char *ini;
// ssl证书是内容还是路径
int ssl_is_path;
// ssl证书内容或路径可以为NULL
const char *ssl;
// 证书密码可以为NULL
const char *ssl_pwd;
} config;
/**
*
* @param cfg
*/
API_EXPORT void API_CALL mk_env_init(const config *cfg);
/**
*
* @param key
* @param val
*/
API_EXPORT void API_CALL mk_set_option(const char *key, const char *val);
/**
* http[s]
* @param port htt监听端口800
* @param ssl ssl类型服务器
* @return 0:,0:
*/
API_EXPORT uint16_t API_CALL mk_http_server_start(uint16_t port, int ssl);
/**
* rtsp[s]
* @param port rtsp监听端口5540
* @param ssl ssl类型服务器
* @return 0:,0:
*/
API_EXPORT uint16_t API_CALL mk_rtsp_server_start(uint16_t port, int ssl);
/**
* rtmp[s]
* @param port rtmp监听端口19350
* @param ssl ssl类型服务器
* @return 0:,0:
*/
API_EXPORT uint16_t API_CALL mk_rtmp_server_start(uint16_t port, int ssl);
/**
*
* @param level ,0~4
* @param file __FILE__
* @param function __FUNCTION__
* @param line __LINE__
* @param fmt printf类型的格式控制字符串
* @param ...
*/
API_EXPORT void API_CALL mk_log_printf(int level, const char *file, const char *function, int line, const char *fmt, ...);
// 以下宏可以替换printf使用
#define log_trace(fmt,...) mk_log_printf(0,__FILE__,__FUNCTION__,__LINE__,fmt,##__VA_ARGS__)
#define log_debug(fmt,...) mk_log_printf(1,__FILE__,__FUNCTION__,__LINE__,fmt,##__VA_ARGS__)
#define log_info(fmt,...) mk_log_printf(2,__FILE__,__FUNCTION__,__LINE__,fmt,##__VA_ARGS__)
#define log_warn(fmt,...) mk_log_printf(3,__FILE__,__FUNCTION__,__LINE__,fmt,##__VA_ARGS__)
#define log_error(fmt,...) mk_log_printf(4,__FILE__,__FUNCTION__,__LINE__,fmt,##__VA_ARGS__)
#define log_printf(lev,fmt,...) mk_log_printf(lev,__FILE__,__FUNCTION__,__LINE__,fmt,##__VA_ARGS__)
#ifdef __cplusplus
}
#endif
#endif /* MK_COMMON_H */

64
api/include/flvrecorder.h Normal file
View File

@ -0,0 +1,64 @@
/*
* MIT License
*
* Copyright (c) 2019 xiongziliang <771730766@qq.com>
*
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef MK_FLV_RECORDER_API_H_
#define MK_FLV_RECORDER_API_H_
#include "common.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef void* mk_flv_recorder;
/**
* flv录制器
* @return
*/
API_EXPORT mk_flv_recorder API_CALL mk_flv_recorder_create();
/**
* flv录制器
* @param ctx
*/
API_EXPORT void API_CALL mk_flv_recorder_release(mk_flv_recorder ctx);
/**
* flv
* @param ctx flv录制器
* @param app RtmpMediaSource的 app名
* @param stream RtmpMediaSource的 stream名
* @param file_path
* @return 0:-1:,RtmpMediaSource不存在
*/
API_EXPORT int API_CALL mk_flv_recorder_start(mk_flv_recorder ctx, const char *app, const char *stream, const char *file_path);
#ifdef __cplusplus
}
#endif
#endif /* MK_FLV_RECORDER_API_H_ */

73
api/include/httpdownloader.h Executable file
View File

@ -0,0 +1,73 @@
/*
* MIT License
*
* Copyright (c) 2019 xiongziliang <771730766@qq.com>
*
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef MK_HTTP_DOWNLOADER_H_
#define MK_HTTP_DOWNLOADER_H_
#include "common.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef void *mk_http_downloader;
/**
* @param user_data
* @param code 0
* @param err_msg
* @param file_path
*/
typedef void(API_CALL *on_download_complete)(void *user_data, int code, const char *err_msg, const char *file_path);
/**
* http[s]
* @return
*/
API_EXPORT mk_http_downloader API_CALL mk_http_downloader_create();
/**
* http[s]
* @param ctx
*/
API_EXPORT void API_CALL mk_http_downloader_release(mk_http_downloader ctx);
/**
* http[s]
* @param ctx
* @param url http[s]url
* @param file
* @param cb
* @param user_data
*/
API_EXPORT void API_CALL mk_http_downloader_start(mk_http_downloader ctx, const char *url, const char *file, on_download_complete cb, void *user_data);
#ifdef __cplusplus
}
#endif
#endif /* MK_HTTP_DOWNLOADER_H_ */

127
api/include/media.h Executable file
View File

@ -0,0 +1,127 @@
/*
* MIT License
*
* Copyright (c) 2019 xiongziliang <771730766@qq.com>
*
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef MK_MEDIA_H_
#define MK_MEDIA_H_
#include "common.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef void *mk_media;
/**
*
* @param app live
* @param stream idcamera
* @param duration ()0
* @param hls_enabled hls
* @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);
/**
*
* @param ctx
*/
API_EXPORT void API_CALL mk_media_release(mk_media ctx);
/**
* h264视频轨道
* @param ctx
* @param width
* @param height
* @param fps fps
*/
API_EXPORT void API_CALL mk_media_init_h264(mk_media ctx, int width, int height, int fps);
/**
* h265视频轨道
* @param ctx
* @param width
* @param height
* @param fps fps
*/
API_EXPORT void API_CALL mk_media_init_h265(mk_media ctx, int width, int height, int fps);
/**
* aac音频轨道
* @param ctx
* @param channel
* @param sample_bit 16
* @param sample_rate
* @param profile aac编码profileadts头时用于生产adts头
*/
API_EXPORT void API_CALL mk_media_init_aac(mk_media ctx, int channel, int sample_bit, int sample_rate, int profile);
/**
* H264视频00 00 01,00 00 00 01
* @param ctx
* @param data H264数据
* @param len H264数据字节数
* @param dts
* @param dts
*/
API_EXPORT void API_CALL mk_media_input_h264(mk_media ctx, void *data, int len, uint32_t dts, uint32_t pts);
/**
* H265视频00 00 01,00 00 00 01
* @param ctx
* @param data H265数据
* @param len H265数据字节数
* @param dts
* @param dts
*/
API_EXPORT void API_CALL mk_media_input_h265(mk_media ctx, void *data, int len, uint32_t dts, uint32_t pts);
/**
* AAC音频
* @param ctx
* @param data AAC数据
* @param len AAC数据字节数
* @param dts
* @param with_adts_header data中是否包含7个字节的adts头
*/
API_EXPORT void API_CALL mk_media_input_aac(mk_media ctx, void *data, int len, uint32_t dts, int with_adts_header);
/**
* AAC音频(adts头)
* @param ctx
* @param data adts头的单帧AAC数据
* @param len AAC数据字节数
* @param dts
* @param adts adts头
*/
API_EXPORT void API_CALL mk_media_input_aac1(mk_media ctx, void *data, int len, uint32_t dts, void *adts);
#ifdef __cplusplus
}
#endif
#endif /* MK_MEDIA_H_ */

36
api/include/mediakit.h Executable file
View File

@ -0,0 +1,36 @@
/*
* MIT License
*
* Copyright (c) 2019 xiongziliang <771730766@qq.com>
*
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef MK_API_H_
#define MK_API_H_
#include "common.h"
#include "httpdownloader.h"
#include "media.h"
#include "proxyplayer.h"
#include "flvrecorder.h"
#endif /* MK_API_H_ */

66
api/include/proxyplayer.h Normal file
View File

@ -0,0 +1,66 @@
/*
* MIT License
*
* Copyright (c) 2019 xiongziliang <771730766@qq.com>
*
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#ifndef MK_PROXY_PLAYER_H_
#define MK_PROXY_PLAYER_H_
#include "common.h"
#ifdef __cplusplus
extern "C" {
#endif
typedef void *mk_proxy_player;
/**
*
* @param app
* @param stream
* @param rtp_type rtsp播放方式:RTP_TCP = 0, RTP_UDP = 1, RTP_MULTICAST = 2
* @param hls_enabled hls
* @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);
/**
*
* @param ctx
*/
API_EXPORT void API_CALL mk_proxy_player_release(mk_proxy_player ctx);
/**
*
* @param ctx
* @param url url,rtsp/rtmp
*/
API_EXPORT void API_CALL mk_proxy_player_play(mk_proxy_player ctx, const char *url);
#ifdef __cplusplus
}
#endif
#endif /* MK_PROXY_PLAYER_H_ */

139
api/source/common.cpp Executable file
View File

@ -0,0 +1,139 @@
/*
* MIT License
*
* Copyright (c) 2019 xiongziliang <771730766@qq.com>
*
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "common.h"
#include <stdarg.h>
#include <unordered_map>
#include "Util/logger.h"
#include "Util/SSLBox.h"
#include "Network/TcpServer.h"
#include "Thread/WorkThreadPool.h"
#include "Rtsp/RtspSession.h"
#include "Rtmp/RtmpSession.h"
#include "Http/HttpSession.h"
using namespace std;
using namespace toolkit;
using namespace mediakit;
static TcpServer::Ptr rtsp_server[2];
static TcpServer::Ptr rtmp_server[2];
static TcpServer::Ptr http_server[2];
//////////////////////////environment init///////////////////////////
API_EXPORT void API_CALL mk_env_init(const config *cfg) {
assert(cfg != nullptr);
static onceToken token([&]() {
Logger::Instance().add(std::make_shared<ConsoleChannel>("console", (LogLevel) cfg->log_level));
EventPollerPool::setPoolSize(cfg->thread_num);
WorkThreadPool::setPoolSize(cfg->thread_num);
if (cfg->ini) {
//设置配置文件
if (cfg->ini_is_path) {
mINI::Instance().parseFile(cfg->ini);
} else {
mINI::Instance().parse(cfg->ini);
}
}
if (cfg->ssl) {
//设置ssl证书
SSL_Initor::Instance().loadCertificate(cfg->ssl, true, cfg->ssl_pwd ? cfg->ssl_pwd : "", cfg->ssl_is_path);
}
});
}
API_EXPORT void API_CALL mk_set_option(const char *key, const char *val) {
if (mINI::Instance().find(key) == mINI::Instance().end()) {
WarnL << "key:" << key << " not existed!";
return;
}
mINI::Instance()[key] = val;
}
API_EXPORT uint16_t API_CALL mk_http_server_start(uint16_t port, int ssl) {
ssl = MAX(0,MIN(ssl,1));
try {
http_server[ssl].reset(new TcpServer());
if(ssl){
http_server[ssl]->start<TcpSessionWithSSL<HttpSession> >(port);
} else{
http_server[ssl]->start<HttpSession>(port);
}
return http_server[ssl]->getPort();
} catch (std::exception &ex) {
http_server[ssl].reset();
WarnL << ex.what();
return 0;
}
}
API_EXPORT uint16_t API_CALL mk_rtsp_server_start(uint16_t port, int ssl) {
ssl = MAX(0,MIN(ssl,1));
try {
rtsp_server[ssl].reset(new TcpServer());
if(ssl){
rtsp_server[ssl]->start<TcpSessionWithSSL<RtspSession> >(port);
}else{
rtsp_server[ssl]->start<RtspSession>(port);
}
return rtsp_server[ssl]->getPort();
} catch (std::exception &ex) {
rtsp_server[ssl].reset();
WarnL << ex.what();
return 0;
}
}
API_EXPORT uint16_t API_CALL mk_rtmp_server_start(uint16_t port, int ssl) {
ssl = MAX(0,MIN(ssl,1));
try {
rtmp_server[ssl].reset(new TcpServer());
if(ssl){
rtmp_server[ssl]->start<TcpSessionWithSSL<RtmpSession> >(port);
}else{
rtmp_server[ssl]->start<RtmpSession>(port);
}
return rtmp_server[ssl]->getPort();
} catch (std::exception &ex) {
rtmp_server[ssl].reset();
WarnL << ex.what();
return 0;
}
}
API_EXPORT void API_CALL mk_log_printf(int level, const char *file, const char *function, int line, const char *fmt, ...) {
LogContextCapturer info(Logger::Instance(), (LogLevel) level, file, function, line);
va_list pArg;
va_start(pArg, fmt);
char buf[4096];
int n = vsprintf(buf, fmt, pArg);
buf[n] = '\0';
va_end(pArg);
info << buf;
}

View File

@ -0,0 +1,50 @@
/*
* MIT License
*
* Copyright (c) 2019 xiongziliang <771730766@qq.com>
*
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "flvrecorder.h"
#include "Rtmp/FlvMuxer.h"
using namespace toolkit;
using namespace mediakit;
API_EXPORT mk_flv_recorder API_CALL mk_flv_recorder_create(){
FlvRecorder::Ptr *ret = new FlvRecorder::Ptr(new FlvRecorder);
return ret;
}
API_EXPORT void API_CALL mk_flv_recorder_release(mk_flv_recorder 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);
try {
(*record)->startRecord(EventPollerPool::Instance().getPoller(), DEFAULT_VHOST,app,stream,file_path);
return 0;
}catch (std::exception &ex){
WarnL << ex.what();
return -1;
}
}

54
api/source/httpdownloader.cpp Executable file
View File

@ -0,0 +1,54 @@
/*
* MIT License
*
* Copyright (c) 2019 xiongziliang <771730766@qq.com>
*
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "httpdownloader.h"
#include "Util/logger.h"
#include "Util/TimeTicker.h"
#include "Util/onceToken.h"
#include "Http/HttpDownloader.h"
using namespace std;
using namespace toolkit;
using namespace mediakit;
API_EXPORT mk_http_downloader API_CALL mk_http_downloader_create() {
HttpDownloader::Ptr *obj(new HttpDownloader::Ptr(new HttpDownloader()));
return (mk_http_downloader) obj;
}
API_EXPORT void API_CALL mk_http_downloader_release(mk_http_downloader 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_download_complete cb, void *user_data) {
HttpDownloader::Ptr *obj = (HttpDownloader::Ptr *) ctx;
(*obj)->setOnResult([cb, user_data](ErrCode code, const string &errMsg, const string &filePath) {
if (cb) {
cb(user_data, code, errMsg.data(), filePath.data());
}
});
(*obj)->startDownload(url, file, false);
}

95
api/source/media.cpp Executable file
View File

@ -0,0 +1,95 @@
/*
* MIT License
*
* Copyright (c) 2019 xiongziliang <771730766@qq.com>
*
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "media.h"
#include "Util/logger.h"
#include "Common/Device.h"
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)));
return (mk_media) obj;
}
API_EXPORT void API_CALL mk_media_release(mk_media 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) {
DevChannel::Ptr *obj = (DevChannel::Ptr *) ctx;
VideoInfo info;
info.iFrameRate = frameRate;
info.iWidth = width;
info.iHeight = height;
(*obj)->initVideo(info);
}
API_EXPORT void API_CALL mk_media_init_h265(mk_media ctx, int width, int height, int frameRate) {
DevChannel::Ptr *obj = (DevChannel::Ptr *) ctx;
VideoInfo info;
info.iFrameRate = frameRate;
info.iWidth = width;
info.iHeight = height;
(*obj)->initH265Video(info);
}
API_EXPORT void API_CALL mk_media_init_aac(mk_media ctx, int channel, int sample_bit, int sample_rate, int profile) {
DevChannel::Ptr *obj = (DevChannel::Ptr *) ctx;
AudioInfo info;
info.iSampleRate = sample_rate;
info.iChannel = channel;
info.iSampleBit = sample_bit;
info.iProfile = profile;
(*obj)->initAudio(info);
}
API_EXPORT void API_CALL mk_media_input_h264(mk_media ctx, void *data, int len, uint32_t dts, uint32_t pts) {
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) {
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) {
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) {
DevChannel::Ptr *obj = (DevChannel::Ptr *) ctx;
(*obj)->inputAAC((char *) data, len, dts, (char *) adts);
}

View File

@ -0,0 +1,47 @@
/*
* MIT License
*
* Copyright (c) 2019 xiongziliang <771730766@qq.com>
*
* This file is part of ZLMediaKit(https://github.com/xiongziliang/ZLMediaKit).
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
#include "proxyplayer.h"
#include "Player/PlayerProxy.h"
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;
return (mk_proxy_player) obj;
}
API_EXPORT void API_CALL mk_proxy_player_release(mk_proxy_player 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);
}