config.cpp 10.5 KB
Newer Older
xiongziliang committed
1
/*
xiongziliang committed
2 3
 * MIT License
 *
xiongziliang committed
4
 * Copyright (c) 2016-2019 xiongziliang <771730766@qq.com>
xiongziliang committed
5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26
 *
 * 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.
 */

xiongziliang committed
27
#include "Common/config.h"
xzl committed
28
#include "Util/util.h"
29
#include "Util/logger.h"
xzl committed
30
#include "Util/onceToken.h"
31
#include "Util/NoticeCenter.h"
xzl committed
32 33
#include "Network/sockutil.h"

xiongziliang committed
34
using namespace toolkit;
xzl committed
35

xiongziliang committed
36
namespace mediakit {
xzl committed
37

38 39
bool loadIniConfig(const char *ini_path){
    string ini;
40
    if(ini_path && ini_path[0] != '\0'){
41 42 43 44
        ini = ini_path;
    }else{
        ini = exePath() + ".ini";
    }
xiongziliang committed
45
	try{
46
        mINI::Instance().parseFile(ini);
47
        NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastReloadConfig);
48
        return true;
xiongziliang committed
49
	}catch (std::exception &ex) {
50
		InfoL << "dump ini file to:" << ini;
51 52
        mINI::Instance().dumpFile(ini);
        return false;
xiongziliang committed
53 54
	}
}
xzl committed
55 56
////////////广播名称///////////
namespace Broadcast {
57
const string kBroadcastMediaChanged = "kBroadcastMediaChanged";
58
const string kBroadcastMediaResetTracks = "kBroadcastMediaResetTracks";
59 60 61 62 63 64 65 66 67 68 69 70
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";
71
const string kBroadcastHttpBeforeAccess = "kBroadcastHttpBeforeAccess";
72
} //namespace Broadcast
73

74 75 76
//通用配置项目
namespace General{
#define GENERAL_FIELD "general."
77 78 79 80
const string kFlowThreshold = GENERAL_FIELD"flowThreshold";
const string kStreamNoneReaderDelayMS = GENERAL_FIELD"streamNoneReaderDelayMS";
const string kMaxStreamWaitTimeMS = GENERAL_FIELD"maxStreamWaitMS";
const string kEnableVhost = GENERAL_FIELD"enableVhost";
81
const string kUltraLowDelay = GENERAL_FIELD"ultraLowDelay";
82
const string kAddMuteAudio = GENERAL_FIELD"addMuteAudio";
83
const string kResetWhenRePlay = GENERAL_FIELD"resetWhenRePlay";
84 85 86
const string kPublishToRtxp = GENERAL_FIELD"publishToRtxp";
const string kPublishToHls = GENERAL_FIELD"publishToHls";
const string kPublishToMP4 = GENERAL_FIELD"publishToMP4";
87

88 89
onceToken token([](){
    mINI::Instance()[kFlowThreshold] = 1024;
xiongziliang committed
90 91
    mINI::Instance()[kStreamNoneReaderDelayMS] = 20 * 1000;
    mINI::Instance()[kMaxStreamWaitTimeMS] = 15 * 1000;
92
    mINI::Instance()[kEnableVhost] = 0;
93
	mINI::Instance()[kUltraLowDelay] = 1;
94
	mINI::Instance()[kAddMuteAudio] = 1;
95
	mINI::Instance()[kResetWhenRePlay] = 1;
96 97 98
	mINI::Instance()[kPublishToRtxp] = 1;
	mINI::Instance()[kPublishToHls] = 1;
	mINI::Instance()[kPublishToMP4] = 0;
99
},nullptr);
100 101

}//namespace General
xzl committed
102 103 104 105 106

////////////HTTP配置///////////
namespace Http {
#define HTTP_FIELD "http."
//http 文件发送缓存大小
107
const string kSendBufSize = HTTP_FIELD"sendBufSize";
xzl committed
108
//http 最大请求字节数
109
const string kMaxReqSize = HTTP_FIELD"maxReqSize";
xzl committed
110
//http keep-alive秒数
111
const string kKeepAliveSecond = HTTP_FIELD"keepAliveSecond";
xzl committed
112
//http 字符编码
113
const string kCharSet = HTTP_FIELD"charSet";
xzl committed
114
//http 服务器根目录
115
const string kRootPath = HTTP_FIELD"rootPath";
xzl committed
116
//http 404错误提示内容
117
const string kNotFound = HTTP_FIELD"notFound";
xzl committed
118 119

onceToken token([](){
120 121 122 123 124 125 126 127 128
	mINI::Instance()[kSendBufSize] = 64 * 1024;
	mINI::Instance()[kMaxReqSize] = 4*1024;
	mINI::Instance()[kKeepAliveSecond] = 15;
#if defined(_WIN32)
	mINI::Instance()[kCharSet] = "gb2312";
#else
	mINI::Instance()[kCharSet] ="utf-8";
#endif

129
	mINI::Instance()[kRootPath] = "./www";
130 131 132 133 134 135 136 137 138 139
	mINI::Instance()[kNotFound] =
					"<html>"
					"<head><title>404 Not Found</title></head>"
					"<body bgcolor=\"white\">"
					"<center><h1>您访问的资源不存在!</h1></center>"
					"<hr><center>"
					SERVER_NAME
					"</center>"
					"</body>"
					"</html>";
xzl committed
140 141 142 143 144 145 146
},nullptr);

}//namespace Http

////////////SHELL配置///////////
namespace Shell {
#define SHELL_FIELD "shell."
147
const string kMaxReqSize = SHELL_FIELD"maxReqSize";
xzl committed
148 149

onceToken token([](){
150
	mINI::Instance()[kMaxReqSize] = 1024;
xzl committed
151 152 153 154 155 156
},nullptr);
} //namespace Shell

////////////RTSP服务器配置///////////
namespace Rtsp {
#define RTSP_FIELD "rtsp."
157 158 159
const string kAuthBasic = RTSP_FIELD"authBasic";
const string kHandshakeSecond = RTSP_FIELD"handshakeSecond";
const string kKeepAliveSecond = RTSP_FIELD"keepAliveSecond";
160 161 162
const string kDirectProxy = RTSP_FIELD"directProxy";
const string kModifyStamp = RTSP_FIELD"modifyStamp";

xzl committed
163
onceToken token([](){
164 165
	//默认Md5方式认证
	mINI::Instance()[kAuthBasic] = 0;
166 167
    mINI::Instance()[kHandshakeSecond] = 15;
    mINI::Instance()[kKeepAliveSecond] = 15;
168
	mINI::Instance()[kDirectProxy] = 1;
169
	mINI::Instance()[kModifyStamp] = false;
xzl committed
170 171 172 173 174 175
},nullptr);
} //namespace Rtsp

////////////RTMP服务器配置///////////
namespace Rtmp {
#define RTMP_FIELD "rtmp."
176 177 178
const string kModifyStamp = RTMP_FIELD"modifyStamp";
const string kHandshakeSecond = RTMP_FIELD"handshakeSecond";
const string kKeepAliveSecond = RTMP_FIELD"keepAliveSecond";
xzl committed
179 180

onceToken token([](){
181
	mINI::Instance()[kModifyStamp] = false;
182 183
    mINI::Instance()[kHandshakeSecond] = 15;
    mINI::Instance()[kKeepAliveSecond] = 15;
xzl committed
184 185 186 187 188 189 190 191
},nullptr);
} //namespace RTMP


////////////RTP配置///////////
namespace Rtp {
#define RTP_FIELD "rtp."
//RTP打包最大MTU,公网情况下更小
192 193
const string kVideoMtuSize = RTP_FIELD"videoMtuSize";
const string kAudioMtuSize = RTP_FIELD"audioMtuSize";
xzl committed
194
//RTP排序缓存最大个数
195
const string kMaxRtpCount = RTP_FIELD"maxRtpCount";
xzl committed
196
//如果RTP序列正确次数累计达到该数字就启动清空排序缓存
197
const string kClearCount = RTP_FIELD"clearCount";
xzl committed
198
//最大RTP时间为13个小时,每13小时回环一次
199
const string kCycleMS = RTP_FIELD"cycleMS";
xzl committed
200 201

onceToken token([](){
202 203 204 205 206
	mINI::Instance()[kVideoMtuSize] = 1400;
	mINI::Instance()[kAudioMtuSize] = 600;
	mINI::Instance()[kMaxRtpCount] = 50;
	mINI::Instance()[kClearCount] = 10;
	mINI::Instance()[kCycleMS] = 13*60*60*1000;
xzl committed
207 208 209 210 211 212 213
},nullptr);
} //namespace Rtsp

////////////组播配置///////////
namespace MultiCast {
#define MULTI_FIELD "multicast."
//组播分配起始地址
214
const string kAddrMin = MULTI_FIELD"addrMin";
xzl committed
215
//组播分配截止地址
216
const string kAddrMax = MULTI_FIELD"addrMax";
xzl committed
217
//组播TTL
218
const string kUdpTTL = MULTI_FIELD"udpTTL";
xzl committed
219 220

onceToken token([](){
221 222
	mINI::Instance()[kAddrMin] = "239.0.0.0";
	mINI::Instance()[kAddrMax] = "239.255.255.255";
223
	mINI::Instance()[kUdpTTL] = 64;
xzl committed
224 225 226 227 228 229 230
},nullptr);
} //namespace MultiCast

////////////录像配置///////////
namespace Record {
#define RECORD_FIELD "record."
//查看录像的应用名称
231
const string kAppName = RECORD_FIELD"appName";
xzl committed
232
//每次流化MP4文件的时长,单位毫秒
233
const string kSampleMS = RECORD_FIELD"sampleMS";
234
//MP4文件录制大小,默认一个小时
235
const string kFileSecond = RECORD_FIELD"fileSecond";
xzl committed
236
//录制文件路径
237
const string kFilePath = RECORD_FIELD"filePath";
238 239
//mp4文件写缓存大小
const string kFileBufSize = RECORD_FIELD"fileBufSize";
240 241
//mp4录制完成后是否进行二次关键帧索引写入头部
const string kFastStart = RECORD_FIELD"fastStart";
Weiwei.Zhou committed
242 243 244
//mp4文件是否重头循环读取
const string kFileRepeat = RECORD_FIELD"fileRepeat";

xzl committed
245
onceToken token([](){
246 247 248
	mINI::Instance()[kAppName] = "record";
	mINI::Instance()[kSampleMS] = 500;
	mINI::Instance()[kFileSecond] = 60*60;
249
	mINI::Instance()[kFilePath] = "./www";
250
	mINI::Instance()[kFileBufSize] = 64 * 1024;
251
	mINI::Instance()[kFastStart] = false;
Weiwei.Zhou committed
252
	mINI::Instance()[kFileRepeat] = false;
xzl committed
253 254 255 256 257 258 259
},nullptr);
} //namespace Record

////////////HLS相关配置///////////
namespace Hls {
#define HLS_FIELD "hls."
//HLS切片时长,单位秒
260
const string kSegmentDuration = HLS_FIELD"segDur";
xzl committed
261
//HLS切片个数
262
const string kSegmentNum = HLS_FIELD"segNum";
263 264
//HLS切片从m3u8文件中移除后,继续保留在磁盘上的个数
const string kSegmentRetain = HLS_FIELD"segRetain";
xzl committed
265
//HLS文件写缓存大小
266
const string kFileBufSize = HLS_FIELD"fileBufSize";
xzl committed
267
//录制文件路径
268
const string kFilePath = HLS_FIELD"filePath";
xzl committed
269 270

onceToken token([](){
271 272 273 274
	mINI::Instance()[kSegmentDuration] = 2;
	mINI::Instance()[kSegmentNum] = 3;
	mINI::Instance()[kSegmentRetain] = 5;
	mINI::Instance()[kFileBufSize] = 64 * 1024;
275
	mINI::Instance()[kFilePath] = "./www";
xzl committed
276 277 278
},nullptr);
} //namespace Hls

279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300

////////////Rtp代理相关配置///////////
namespace RtpProxy {
#define RTP_PROXY_FIELD "rtp_proxy."
//rtp调试数据保存目录
const string kDumpDir = RTP_PROXY_FIELD"dumpDir";
//是否限制udp数据来源ip和端口
const string kCheckSource = RTP_PROXY_FIELD"checkSource";
//rtp类型,支持MP2P/MP4V-ES
const string kRtpType = RTP_PROXY_FIELD"rtp_type";
//rtp接收超时时间
const string kTimeoutSec = RTP_PROXY_FIELD"timeoutSec";

onceToken token([](){
	mINI::Instance()[kDumpDir] = "";
	mINI::Instance()[kCheckSource] = 1;
	mINI::Instance()[kRtpType] = "MP2P";
	mINI::Instance()[kTimeoutSec] = 15;
},nullptr);
} //namespace RtpProxy


xiongziliang committed
301
namespace Client {
302 303 304 305 306 307 308 309 310
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";
xiongziliang committed
311 312
}

xiongziliang committed
313
}  // namespace mediakit
xzl committed
314 315