mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-25 12:11:36 +08:00
初步提供c标准接口
This commit is contained in:
parent
ee88297d4a
commit
31438cfde4
@ -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
11
api/CMakeLists.txt
Normal 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
129
api/include/common.h
Executable 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监听端口,推荐80,传入0则随机分配
|
||||
* @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监听端口,推荐554,传入0则随机分配
|
||||
* @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监听端口,推荐1935,传入0则随机分配
|
||||
* @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
64
api/include/flvrecorder.h
Normal 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
73
api/include/httpdownloader.h
Executable 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
127
api/include/media.h
Executable 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 流id,例如camera
|
||||
* @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编码profile,在不输入adts头时用于生产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
36
api/include/mediakit.h
Executable 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
66
api/include/proxyplayer.h
Normal 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
139
api/source/common.cpp
Executable 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;
|
||||
}
|
||||
|
50
api/source/flvrecorder.cpp
Normal file
50
api/source/flvrecorder.cpp
Normal 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
54
api/source/httpdownloader.cpp
Executable 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
95
api/source/media.cpp
Executable 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);
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
47
api/source/proxyplayer.cpp
Normal file
47
api/source/proxyplayer.cpp
Normal 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);
|
||||
}
|
Loading…
Reference in New Issue
Block a user