ZLMediaKit/src/Common/config.cpp

322 lines
9.7 KiB
C++
Raw Normal View History

2017-10-09 22:11:01 +08:00
/*
2017-09-27 16:20:30 +08:00
* MIT License
*
2019-05-08 15:40:07 +08:00
* Copyright (c) 2016-2019 xiongziliang <771730766@qq.com>
2017-09-27 16:20:30 +08:00
*
* 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.
*/
2017-05-02 17:15:12 +08:00
#include "Common/config.h"
2017-04-01 16:35:56 +08:00
#include "Util/util.h"
2019-05-10 13:25:22 +08:00
#include "Util/logger.h"
2017-04-01 16:35:56 +08:00
#include "Util/onceToken.h"
2019-05-10 13:25:22 +08:00
#include "Util/NoticeCenter.h"
2017-04-01 16:35:56 +08:00
#include "Network/sockutil.h"
2018-10-24 17:17:55 +08:00
using namespace toolkit;
2017-04-01 16:35:56 +08:00
2018-10-24 17:17:55 +08:00
namespace mediakit {
2017-04-01 16:35:56 +08:00
bool loadIniConfig(const char *ini_path){
string ini;
2019-05-20 11:22:59 +08:00
if(ini_path && ini_path[0] != '\0'){
ini = ini_path;
}else{
ini = exePath() + ".ini";
}
2017-05-05 18:03:23 +08:00
try{
mINI::Instance().parseFile(ini);
2018-02-09 11:42:55 +08:00
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastReloadConfig);
return true;
2017-05-05 18:03:23 +08:00
}catch (std::exception &ex) {
2019-05-10 13:25:22 +08:00
InfoL << "dump ini file to:" << ini;
mINI::Instance().dumpFile(ini);
return false;
2017-05-05 18:03:23 +08:00
}
}
2017-04-01 16:35:56 +08:00
////////////广播名称///////////
namespace Broadcast {
2019-06-12 18:37:52 +08:00
const string kBroadcastMediaChanged = "kBroadcastMediaChanged";
const string kBroadcastRecordMP4 = "kBroadcastRecordMP4";
const string kBroadcastHttpRequest = "kBroadcastHttpRequest";
const string kBroadcastHttpAccess = "kBroadcastHttpAccess";
const string kBroadcastOnGetRtspRealm = "kBroadcastOnGetRtspRealm";
const string kBroadcastOnRtspAuth = "kBroadcastOnRtspAuth";
const string kBroadcastMediaPlayed = "kBroadcastMediaPlayed";
const string kBroadcastMediaPublish = "kBroadcastMediaPublish";
const string kBroadcastFlowReport = "kBroadcastFlowReport";
const string kBroadcastReloadConfig = "kBroadcastReloadConfig";
const string kBroadcastShellLogin = "kBroadcastShellLogin";
const string kBroadcastNotFoundStream = "kBroadcastNotFoundStream";
const string kBroadcastStreamNoneReader = "kBroadcastStreamNoneReader";
2019-05-28 17:14:36 +08:00
} //namespace Broadcast
2019-05-28 17:14:36 +08:00
//通用配置项目
namespace General{
#define GENERAL_FIELD "general."
2019-06-12 18:37:52 +08:00
const string kFlowThreshold = GENERAL_FIELD"flowThreshold";
const string kStreamNoneReaderDelayMS = GENERAL_FIELD"streamNoneReaderDelayMS";
const string kMaxStreamWaitTimeMS = GENERAL_FIELD"maxStreamWaitMS";
const string kEnableVhost = GENERAL_FIELD"enableVhost";
onceToken token([](){
mINI::Instance()[kFlowThreshold] = 1024;
2019-05-27 18:39:43 +08:00
mINI::Instance()[kStreamNoneReaderDelayMS] = 5 * 1000;
2019-05-28 09:25:41 +08:00
mINI::Instance()[kMaxStreamWaitTimeMS] = 5 * 1000;
2019-05-28 17:14:36 +08:00
mINI::Instance()[kEnableVhost] = 1;
},nullptr);
2019-05-28 17:14:36 +08:00
}//namespace General
2017-04-01 16:35:56 +08:00
////////////HTTP配置///////////
namespace Http {
#define HTTP_FIELD "http."
//http 文件发送缓存大小
#define HTTP_SEND_BUF_SIZE (64 * 1024)
2019-06-12 18:37:52 +08:00
const string kSendBufSize = HTTP_FIELD"sendBufSize";
2017-04-01 16:35:56 +08:00
//http 最大请求字节数
#define HTTP_MAX_REQ_SIZE (4*1024)
2019-06-12 18:37:52 +08:00
const string kMaxReqSize = HTTP_FIELD"maxReqSize";
2017-04-01 16:35:56 +08:00
//http keep-alive秒数
#define HTTP_KEEP_ALIVE_SECOND 10
2019-06-12 18:37:52 +08:00
const string kKeepAliveSecond = HTTP_FIELD"keepAliveSecond";
2017-04-01 16:35:56 +08:00
//http keep-alive最大请求数
#define HTTP_MAX_REQ_CNT 100
2019-06-12 18:37:52 +08:00
const string kMaxReqCount = HTTP_FIELD"maxReqCount";
2017-04-01 16:35:56 +08:00
2017-04-01 16:35:56 +08:00
//http 字符编码
2017-10-10 00:04:07 +08:00
#if defined(_WIN32)
#define HTTP_CHAR_SET "gb2312"
#else
2017-04-01 16:35:56 +08:00
#define HTTP_CHAR_SET "utf-8"
2017-10-10 00:04:07 +08:00
#endif
2019-06-12 18:37:52 +08:00
const string kCharSet = HTTP_FIELD"charSet";
2017-04-01 16:35:56 +08:00
//http 服务器根目录
#define HTTP_ROOT_PATH (exeDir() + "httpRoot")
2019-06-12 18:37:52 +08:00
const string kRootPath = HTTP_FIELD"rootPath";
2017-04-01 16:35:56 +08:00
//http 404错误提示内容
#define HTTP_NOT_FOUND "<html>"\
"<head><title>404 Not Found</title></head>"\
"<body bgcolor=\"white\">"\
"<center><h1>您访问的资源不存在!</h1></center>"\
"<hr><center>"\
SERVER_NAME\
2017-04-01 16:35:56 +08:00
"</center>"\
"</body>"\
"</html>"
2019-06-12 18:37:52 +08:00
const string kNotFound = HTTP_FIELD"notFound";
2017-04-01 16:35:56 +08:00
2017-04-13 17:38:25 +08:00
2017-04-01 16:35:56 +08:00
onceToken token([](){
mINI::Instance()[kSendBufSize] = HTTP_SEND_BUF_SIZE;
mINI::Instance()[kMaxReqSize] = HTTP_MAX_REQ_SIZE;
mINI::Instance()[kKeepAliveSecond] = HTTP_KEEP_ALIVE_SECOND;
mINI::Instance()[kMaxReqCount] = HTTP_MAX_REQ_CNT;
mINI::Instance()[kCharSet] = HTTP_CHAR_SET;
mINI::Instance()[kRootPath] = HTTP_ROOT_PATH;
mINI::Instance()[kNotFound] = HTTP_NOT_FOUND;
},nullptr);
}//namespace Http
////////////SHELL配置///////////
namespace Shell {
#define SHELL_FIELD "shell."
#define SHELL_MAX_REQ_SIZE 1024
2019-06-12 18:37:52 +08:00
const string kMaxReqSize = SHELL_FIELD"maxReqSize";
2017-04-01 16:35:56 +08:00
onceToken token([](){
mINI::Instance()[kMaxReqSize] = SHELL_MAX_REQ_SIZE;
},nullptr);
} //namespace Shell
////////////RTSP服务器配置///////////
namespace Rtsp {
#define RTSP_FIELD "rtsp."
2019-06-12 18:37:52 +08:00
const string kAuthBasic = RTSP_FIELD"authBasic";
const string kHandshakeSecond = RTSP_FIELD"handshakeSecond";
const string kKeepAliveSecond = RTSP_FIELD"keepAliveSecond";
const string kDirectProxy = RTSP_FIELD"directProxy";;
2017-04-01 16:35:56 +08:00
onceToken token([](){
2017-12-10 01:34:43 +08:00
//默认Md5方式认证
mINI::Instance()[kAuthBasic] = 0;
2019-05-29 18:24:35 +08:00
mINI::Instance()[kHandshakeSecond] = 15;
mINI::Instance()[kKeepAliveSecond] = 15;
mINI::Instance()[kDirectProxy] = 1;
2017-04-01 16:35:56 +08:00
},nullptr);
} //namespace Rtsp
////////////RTMP服务器配置///////////
namespace Rtmp {
#define RTMP_FIELD "rtmp."
2019-06-12 18:37:52 +08:00
const string kModifyStamp = RTMP_FIELD"modifyStamp";
const string kHandshakeSecond = RTMP_FIELD"handshakeSecond";
const string kKeepAliveSecond = RTMP_FIELD"keepAliveSecond";
2017-04-01 16:35:56 +08:00
onceToken token([](){
mINI::Instance()[kModifyStamp] = true;
2019-05-29 18:24:35 +08:00
mINI::Instance()[kHandshakeSecond] = 15;
mINI::Instance()[kKeepAliveSecond] = 15;
2017-04-01 16:35:56 +08:00
},nullptr);
2019-05-29 18:24:35 +08:00
2017-04-01 16:35:56 +08:00
} //namespace RTMP
////////////RTP配置///////////
namespace Rtp {
#define RTP_FIELD "rtp."
//RTP打包最大MTU,公网情况下更小
#define RTP_VIDOE_MTU_SIZE 1400
2019-06-12 18:37:52 +08:00
const string kVideoMtuSize = RTP_FIELD"videoMtuSize";
2017-04-01 16:35:56 +08:00
#define RTP_Audio_MTU_SIZE 600
2019-06-12 18:37:52 +08:00
const string kAudioMtuSize = RTP_FIELD"audioMtuSize";
2017-04-01 16:35:56 +08:00
//RTP排序缓存最大个数
#define RTP_MAX_RTP_COUNT 50
2019-06-12 18:37:52 +08:00
const string kMaxRtpCount = RTP_FIELD"maxRtpCount";
2017-04-01 16:35:56 +08:00
//如果RTP序列正确次数累计达到该数字就启动清空排序缓存
#define RTP_CLEAR_COUNT 10
2019-06-12 18:37:52 +08:00
const string kClearCount = RTP_FIELD"clearCount";
2017-04-01 16:35:56 +08:00
//最大RTP时间为13个小时每13小时回环一次
#define RTP_CYCLE_MS (13*60*60*1000)
2019-06-12 18:37:52 +08:00
const string kCycleMS = RTP_FIELD"cycleMS";
2017-04-01 16:35:56 +08:00
onceToken token([](){
mINI::Instance()[kVideoMtuSize] = RTP_VIDOE_MTU_SIZE;
mINI::Instance()[kAudioMtuSize] = RTP_Audio_MTU_SIZE;
mINI::Instance()[kMaxRtpCount] = RTP_MAX_RTP_COUNT;
mINI::Instance()[kClearCount] = RTP_CLEAR_COUNT;
mINI::Instance()[kCycleMS] = RTP_CYCLE_MS;
},nullptr);
} //namespace Rtsp
////////////组播配置///////////
namespace MultiCast {
#define MULTI_FIELD "multicast."
//组播分配起始地址
2019-06-12 18:37:52 +08:00
const string kAddrMin = MULTI_FIELD"addrMin";
2017-04-01 16:35:56 +08:00
//组播分配截止地址
2019-06-12 18:37:52 +08:00
const string kAddrMax = MULTI_FIELD"addrMax";
2017-04-01 16:35:56 +08:00
//组播TTL
#define MULTI_UDP_TTL 64
2019-06-12 18:37:52 +08:00
const string kUdpTTL = MULTI_FIELD"udpTTL";
2017-04-01 16:35:56 +08:00
onceToken token([](){
2018-02-07 13:43:44 +08:00
mINI::Instance()[kAddrMin] = "239.0.0.0";
mINI::Instance()[kAddrMax] = "239.255.255.255";
2017-04-01 16:35:56 +08:00
mINI::Instance()[kUdpTTL] = MULTI_UDP_TTL;
},nullptr);
} //namespace MultiCast
////////////录像配置///////////
namespace Record {
#define RECORD_FIELD "record."
//查看录像的应用名称
#define RECORD_APP_NAME "record"
2019-06-12 18:37:52 +08:00
const string kAppName = RECORD_FIELD"appName";
2017-04-01 16:35:56 +08:00
//每次流化MP4文件的时长,单位毫秒
#define RECORD_SAMPLE_MS 100
2019-06-12 18:37:52 +08:00
const string kSampleMS = RECORD_FIELD"sampleMS";
2017-04-01 16:35:56 +08:00
2019-04-03 11:09:50 +08:00
//MP4文件录制大小,默认一个小时
#define RECORD_FILE_SECOND (60*60)
2019-06-12 18:37:52 +08:00
const string kFileSecond = RECORD_FIELD"fileSecond";
2017-04-01 16:35:56 +08:00
//录制文件路径
#define RECORD_FILE_PATH HTTP_ROOT_PATH
2019-06-12 18:37:52 +08:00
const string kFilePath = RECORD_FIELD"filePath";
2017-04-01 16:35:56 +08:00
2019-08-01 22:13:26 +08:00
//mp4文件写缓存大小
const string kFileBufSize = RECORD_FIELD"fileBufSize";
2017-04-01 16:35:56 +08:00
onceToken token([](){
mINI::Instance()[kAppName] = RECORD_APP_NAME;
mINI::Instance()[kSampleMS] = RECORD_SAMPLE_MS;
mINI::Instance()[kFileSecond] = RECORD_FILE_SECOND;
mINI::Instance()[kFilePath] = RECORD_FILE_PATH;
2019-08-01 22:13:26 +08:00
mINI::Instance()[kFileBufSize] = 64 * 1024;
2017-04-01 16:35:56 +08:00
},nullptr);
} //namespace Record
////////////HLS相关配置///////////
namespace Hls {
#define HLS_FIELD "hls."
//HLS切片时长,单位秒
2018-09-03 10:28:41 +08:00
#define HLS_SEGMENT_DURATION 3
2019-06-12 18:37:52 +08:00
const string kSegmentDuration = HLS_FIELD"segDur";
2017-04-01 16:35:56 +08:00
//HLS切片个数
2018-09-03 10:28:41 +08:00
#define HLS_SEGMENT_NUM 3
2019-06-12 18:37:52 +08:00
const string kSegmentNum = HLS_FIELD"segNum";
2017-04-01 16:35:56 +08:00
//HLS文件写缓存大小
#define HLS_FILE_BUF_SIZE (64 * 1024)
2019-06-12 18:37:52 +08:00
const string kFileBufSize = HLS_FIELD"fileBufSize";
2017-04-01 16:35:56 +08:00
//录制文件路径
#define HLS_FILE_PATH (HTTP_ROOT_PATH)
2019-06-12 18:37:52 +08:00
const string kFilePath = HLS_FIELD"filePath";
2017-04-01 16:35:56 +08:00
onceToken token([](){
mINI::Instance()[kSegmentDuration] = HLS_SEGMENT_DURATION;
mINI::Instance()[kSegmentNum] = HLS_SEGMENT_NUM;
mINI::Instance()[kFileBufSize] = HLS_FILE_BUF_SIZE;
mINI::Instance()[kFilePath] = HLS_FILE_PATH;
},nullptr);
} //namespace Hls
2019-03-27 18:56:49 +08:00
namespace Client {
2019-06-12 18:37:52 +08:00
const string kNetAdapter = "net_adapter";
const string kRtpType = "rtp_type";
const string kRtspUser = "rtsp_user" ;
const string kRtspPwd = "rtsp_pwd";
const string kRtspPwdIsMD5 = "rtsp_pwd_md5";
const string kTimeoutMS = "protocol_timeout_ms";
const string kMediaTimeoutMS = "media_timeout_ms";
const string kBeatIntervalMS = "beat_interval_ms";
const string kMaxAnalysisMS = "max_analysis_ms";
2019-03-27 18:56:49 +08:00
}
2018-10-24 17:17:55 +08:00
} // namespace mediakit
2017-04-01 16:35:56 +08:00