mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-10-31 00:37:39 +08:00
完善 c api
This commit is contained in:
parent
1d5c6cb141
commit
8859e89ade
@ -40,8 +40,13 @@ extern "C" {
|
||||
typedef struct {
|
||||
// 线程数
|
||||
int thread_num;
|
||||
|
||||
// 日志级别,支持0~4
|
||||
int log_level;
|
||||
//文件日志保存路径,路径可以不存在(内部可以创建文件夹),设置为NULL关闭日志输出至文件
|
||||
const char *log_file_path;
|
||||
//文件日志保存天数,设置为0关闭日志文件
|
||||
int log_file_days;
|
||||
|
||||
// 配置文件是内容还是路径
|
||||
int ini_is_path;
|
||||
@ -71,19 +76,23 @@ API_EXPORT void API_CALL mk_stop_all_server();
|
||||
* 基础类型参数版本的mk_env_init,为了方便其他语言调用
|
||||
* @param thread_num 线程数
|
||||
* @param log_level 日志级别,支持0~4
|
||||
* @param log_file_path 文件日志保存路径,路径可以不存在(内部可以创建文件夹),设置为NULL关闭日志输出至文件
|
||||
* @param log_file_days 文件日志保存天数,设置为0关闭日志文件
|
||||
* @param ini_is_path 配置文件是内容还是路径
|
||||
* @param ini 配置文件内容或路径,可以为NULL,如果该文件不存在,那么将导出默认配置至该文件
|
||||
* @param ssl_is_path ssl证书是内容还是路径
|
||||
* @param ssl ssl证书内容或路径,可以为NULL
|
||||
* @param ssl_pwd 证书密码,可以为NULL
|
||||
*/
|
||||
API_EXPORT void API_CALL mk_env_init1( int thread_num,
|
||||
int log_level,
|
||||
int ini_is_path,
|
||||
const char *ini,
|
||||
int ssl_is_path,
|
||||
const char *ssl,
|
||||
const char *ssl_pwd);
|
||||
API_EXPORT void API_CALL mk_env_init1(int thread_num,
|
||||
int log_level,
|
||||
const char *log_file_path,
|
||||
int log_file_days,
|
||||
int ini_is_path,
|
||||
const char *ini,
|
||||
int ssl_is_path,
|
||||
const char *ssl,
|
||||
const char *ssl_pwd);
|
||||
|
||||
/**
|
||||
* 设置配置项
|
||||
|
@ -73,6 +73,10 @@ API_EXPORT const char* API_CALL mk_media_info_get_vhost(const mk_media_info ctx)
|
||||
API_EXPORT const char* API_CALL mk_media_info_get_app(const mk_media_info ctx);
|
||||
//MediaInfo::_streamid
|
||||
API_EXPORT const char* API_CALL mk_media_info_get_stream(const mk_media_info ctx);
|
||||
//MediaInfo::_host
|
||||
API_EXPORT const char* API_CALL mk_media_info_get_host(const mk_media_info ctx);
|
||||
//MediaInfo::_port
|
||||
API_EXPORT uint16_t API_CALL mk_media_info_get_port(const mk_media_info ctx);
|
||||
|
||||
|
||||
///////////////////////////////////////////MediaSource/////////////////////////////////////////////
|
||||
|
29
api/source/mk_common.cpp
Executable file → Normal file
29
api/source/mk_common.cpp
Executable file → Normal file
@ -41,6 +41,8 @@ API_EXPORT void API_CALL mk_env_init(const mk_config *cfg) {
|
||||
assert(cfg);
|
||||
mk_env_init1(cfg->thread_num,
|
||||
cfg->log_level,
|
||||
cfg->log_file_path,
|
||||
cfg->log_file_days,
|
||||
cfg->ini_is_path,
|
||||
cfg->ini,
|
||||
cfg->ssl_is_path,
|
||||
@ -61,18 +63,29 @@ API_EXPORT void API_CALL mk_stop_all_server(){
|
||||
stopAllTcpServer();
|
||||
}
|
||||
|
||||
API_EXPORT void API_CALL mk_env_init1( int thread_num,
|
||||
int log_level,
|
||||
int ini_is_path,
|
||||
const char *ini,
|
||||
int ssl_is_path,
|
||||
const char *ssl,
|
||||
const char *ssl_pwd) {
|
||||
|
||||
API_EXPORT void API_CALL mk_env_init1(int thread_num,
|
||||
int log_level,
|
||||
const char *log_file_path,
|
||||
int log_file_days,
|
||||
int ini_is_path,
|
||||
const char *ini,
|
||||
int ssl_is_path,
|
||||
const char *ssl,
|
||||
const char *ssl_pwd) {
|
||||
//确保只初始化一次
|
||||
static onceToken token([&]() {
|
||||
//控制台日志
|
||||
Logger::Instance().add(std::make_shared<ConsoleChannel>("console", (LogLevel) log_level));
|
||||
if(log_file_path && log_file_days){
|
||||
//日志文件
|
||||
auto channel = std::make_shared<FileChannel>("FileChannel", File::absolutePath(log_file_path, ""), (LogLevel) log_level);
|
||||
Logger::Instance().add(channel);
|
||||
}
|
||||
|
||||
//异步日志线程
|
||||
Logger::Instance().setWriter(std::make_shared<AsyncLogWriter>());
|
||||
|
||||
//设置线程数
|
||||
EventPollerPool::setPoolSize(thread_num);
|
||||
WorkThreadPool::setPoolSize(thread_num);
|
||||
|
||||
|
@ -12,7 +12,6 @@
|
||||
#include "mk_events_objects.h"
|
||||
#include "Common/config.h"
|
||||
#include "Record/MP4Recorder.h"
|
||||
#include "Network/TcpSession.h"
|
||||
#include "Http/HttpSession.h"
|
||||
#include "Http/HttpBody.h"
|
||||
#include "Http/HttpClient.h"
|
||||
@ -137,16 +136,31 @@ API_EXPORT const char* API_CALL mk_media_info_get_schema(const mk_media_info ctx
|
||||
MediaInfo *info = (MediaInfo *)ctx;
|
||||
return info->_schema.c_str();
|
||||
}
|
||||
|
||||
API_EXPORT const char* API_CALL mk_media_info_get_vhost(const mk_media_info ctx){
|
||||
assert(ctx);
|
||||
MediaInfo *info = (MediaInfo *)ctx;
|
||||
return info->_vhost.c_str();
|
||||
}
|
||||
|
||||
API_EXPORT const char* API_CALL mk_media_info_get_host(const mk_media_info ctx){
|
||||
assert(ctx);
|
||||
MediaInfo *info = (MediaInfo *)ctx;
|
||||
return info->_host.c_str();
|
||||
}
|
||||
|
||||
API_EXPORT uint16_t API_CALL mk_media_info_get_port(const mk_media_info ctx){
|
||||
assert(ctx);
|
||||
MediaInfo *info = (MediaInfo *)ctx;
|
||||
return std::stoi(info->_port);
|
||||
}
|
||||
|
||||
API_EXPORT const char* API_CALL mk_media_info_get_app(const mk_media_info ctx){
|
||||
assert(ctx);
|
||||
MediaInfo *info = (MediaInfo *)ctx;
|
||||
return info->_app.c_str();
|
||||
}
|
||||
|
||||
API_EXPORT const char* API_CALL mk_media_info_get_stream(const mk_media_info ctx){
|
||||
assert(ctx);
|
||||
MediaInfo *info = (MediaInfo *)ctx;
|
||||
|
Loading…
Reference in New Issue
Block a user