完善 c api

This commit is contained in:
xiongziliang 2020-04-22 09:51:04 +08:00
parent 1d5c6cb141
commit 8859e89ade
4 changed files with 56 additions and 16 deletions

View File

@ -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,14 +76,18 @@ 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,
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,

View File

@ -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/////////////////////////////////////////////

17
api/source/mk_common.cpp Executable file → Normal file
View 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,
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);

View File

@ -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;