ZLMediaKit/api/include/mk_common.h

220 lines
6.8 KiB
C++
Raw Normal View History

2019-12-18 11:47:49 +08:00
/*
2023-12-09 16:23:51 +08:00
* Copyright (c) 2016-present The ZLMediaKit project authors. All Rights Reserved.
2019-12-17 18:45:31 +08:00
*
2023-12-09 16:23:51 +08:00
* This file is part of ZLMediaKit(https://github.com/ZLMediaKit/ZLMediaKit).
2019-12-17 18:45:31 +08:00
*
2023-12-09 16:23:51 +08:00
* Use of this source code is governed by MIT-like license that can be found in the
2020-04-04 20:30:09 +08:00
* LICENSE file in the root of the source tree. All contributing project authors
* may be found in the AUTHORS file in the root of the source tree.
2019-12-17 18:45:31 +08:00
*/
#ifndef MK_COMMON_H
#define MK_COMMON_H
#include <stdint.h>
#include <stddef.h>
2019-12-17 18:45:31 +08:00
#if defined(GENERATE_EXPORT)
#include "mk_export.h"
#endif
2022-05-25 15:38:32 +08:00
#if defined(_WIN32) && defined(_MSC_VER)
# define API_CALL __cdecl
2019-12-17 18:45:31 +08:00
#else
# define API_CALL
#endif
#ifndef _WIN32
#define _strdup strdup
#endif
#if defined(_WIN32) && defined(_MSC_VER)
# if !defined(GENERATE_EXPORT)
# if defined(MediaKitApi_EXPORTS)
# define API_EXPORT __declspec(dllexport)
# else
# define API_EXPORT __declspec(dllimport)
# endif
# endif
#elif !defined(GENERATE_EXPORT)
# define API_EXPORT __attribute__((visibility("default")))
2019-12-17 18:45:31 +08:00
#endif
#ifdef __cplusplus
extern "C" {
#endif
2021-08-30 20:43:03 +08:00
//输出日志到shell
#define LOG_CONSOLE (1 << 0)
//输出日志到文件
#define LOG_FILE (1 << 1)
//输出日志到回调函数(mk_events::on_mk_log)
#define LOG_CALLBACK (1 << 2)
//向下兼容
#define mk_env_init1 mk_env_init2
//回调user_data回调函数
typedef void(API_CALL *on_user_data_free)(void *user_data);
2019-12-17 18:45:31 +08:00
typedef struct {
// 线程数
int thread_num;
2020-04-22 09:51:04 +08:00
2019-12-17 18:45:31 +08:00
// 日志级别,支持0~4
int log_level;
2021-08-30 20:43:03 +08:00
//控制日志输出的掩模请查看LOG_CONSOLE、LOG_FILE、LOG_CALLBACK等宏
int log_mask;
2020-04-22 09:51:04 +08:00
//文件日志保存路径,路径可以不存在(内部可以创建文件夹)设置为NULL关闭日志输出至文件
const char *log_file_path;
//文件日志保存天数,设置为0关闭日志文件
int log_file_days;
2019-12-17 18:45:31 +08:00
// 配置文件是内容还是路径
int ini_is_path;
2019-12-23 15:31:35 +08:00
// 配置文件内容或路径可以为NULL,如果该文件不存在,那么将导出默认配置至该文件
2019-12-17 18:45:31 +08:00
const char *ini;
// ssl证书是内容还是路径
int ssl_is_path;
// ssl证书内容或路径可以为NULL
const char *ssl;
// 证书密码可以为NULL
const char *ssl_pwd;
2019-12-19 16:45:32 +08:00
} mk_config;
2019-12-17 18:45:31 +08:00
/**
*
* @param cfg
*/
2019-12-19 16:45:32 +08:00
API_EXPORT void API_CALL mk_env_init(const mk_config *cfg);
2019-12-17 18:45:31 +08:00
2019-12-23 14:20:49 +08:00
/**
* main函数退出时调用
*/
API_EXPORT void API_CALL mk_stop_all_server();
2019-12-20 11:04:18 +08:00
/**
* mk_env_init便
2019-12-23 15:31:35 +08:00
* @param thread_num 线
* @param log_level ,0~4
2021-08-30 20:43:03 +08:00
* @param log_mask LOG_CONSOLELOG_FILELOG_CALLBACK等宏
2020-04-22 09:51:04 +08:00
* @param log_file_path ,()NULL关闭日志输出至文件
* @param log_file_days ,0
2019-12-23 15:31:35 +08:00
* @param ini_is_path
* @param ini NULL,
* @param ssl_is_path ssl证书是内容还是路径
* @param ssl ssl证书内容或路径NULL
* @param ssl_pwd NULL
2019-12-20 11:04:18 +08:00
*/
API_EXPORT void API_CALL mk_env_init2(int thread_num,
2020-04-22 09:51:04 +08:00
int log_level,
2021-08-30 20:43:03 +08:00
int log_mask,
2020-04-22 09:51:04 +08:00
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);
2019-12-20 11:04:18 +08:00
2021-09-28 09:52:29 +08:00
/**
*
* @param file_max_size (MB)
* @param file_max_count
*/
API_EXPORT void API_CALL mk_set_log(int file_max_size, int file_max_count);
2019-12-17 18:45:31 +08:00
/**
*
2023-02-11 11:39:26 +08:00
* @deprecated 使mk_ini_set_option替代
2019-12-17 18:45:31 +08:00
* @param key
* @param val
*/
API_EXPORT void API_CALL mk_set_option(const char *key, const char *val);
/**
*
2023-02-11 11:39:26 +08:00
* @deprecated 使mk_ini_get_option替代
* @param key
*/
API_EXPORT const char * API_CALL mk_get_option(const char *key);
2019-12-17 18:45:31 +08:00
/**
* 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);
2019-12-18 14:53:42 +08:00
/**
* rtp服务器
* @param port rtp监听端口(udp/tcp)
* @return 0:,0:
*/
API_EXPORT uint16_t API_CALL mk_rtp_server_start(uint16_t port);
2019-12-24 16:09:09 +08:00
/**
* rtc服务器
2022-09-22 21:18:34 +08:00
* @param port rtc监听端口
* @return 0:,0:
*/
API_EXPORT uint16_t API_CALL mk_rtc_server_start(uint16_t port);
2022-10-06 12:33:48 +08:00
//获取webrtc answer sdp回调函数
typedef void(API_CALL *on_mk_webrtc_get_answer_sdp)(void *user_data, const char *answer, const char *err);
/**
* webrtc交换sdpoffer sdp生成answer sdp
* @param user_data
* @param cb
* @param type webrtc插件类型echo,play,push
* @param offer webrtc offer sdp
* @param url rtc url, rtc://__defaultVhost/app/stream?key1=val1&key2=val2
*/
API_EXPORT void API_CALL mk_webrtc_get_answer_sdp(void *user_data, on_mk_webrtc_get_answer_sdp cb, const char *type,
const char *offer, const char *url);
API_EXPORT void API_CALL mk_webrtc_get_answer_sdp2(void *user_data, on_user_data_free user_data_free, on_mk_webrtc_get_answer_sdp cb, const char *type,
const char *offer, const char *url);
2022-09-22 21:18:34 +08:00
/**
* srt服务器
* @param port srt监听端口
* @return 0:,0:
*/
API_EXPORT uint16_t API_CALL mk_srt_server_start(uint16_t port);
2019-12-24 16:09:09 +08:00
/**
* shell服务器
* @param port shell监听端口
* @return 0:,0:
*/
API_EXPORT uint16_t API_CALL mk_shell_server_start(uint16_t port);
2019-12-18 14:53:42 +08:00
2019-12-17 18:45:31 +08:00
#ifdef __cplusplus
}
#endif
#endif /* MK_COMMON_H */