config.cpp 9.61 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 58 59 60 61 62 63 64 65 66 67 68 69
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";
70
} //namespace Broadcast
71

72 73 74
//通用配置项目
namespace General{
#define GENERAL_FIELD "general."
75 76 77 78
const string kFlowThreshold = GENERAL_FIELD"flowThreshold";
const string kStreamNoneReaderDelayMS = GENERAL_FIELD"streamNoneReaderDelayMS";
const string kMaxStreamWaitTimeMS = GENERAL_FIELD"maxStreamWaitMS";
const string kEnableVhost = GENERAL_FIELD"enableVhost";
79 80
onceToken token([](){
    mINI::Instance()[kFlowThreshold] = 1024;
81
    mINI::Instance()[kStreamNoneReaderDelayMS] = 5 * 1000;
82
    mINI::Instance()[kMaxStreamWaitTimeMS] = 5 * 1000;
83
    mINI::Instance()[kEnableVhost] = 1;
84
},nullptr);
85 86

}//namespace General
xzl committed
87 88 89 90 91 92 93

////////////HTTP配置///////////
namespace Http {
#define HTTP_FIELD "http."

//http 文件发送缓存大小
#define HTTP_SEND_BUF_SIZE (64 * 1024)
94
const string kSendBufSize = HTTP_FIELD"sendBufSize";
xzl committed
95 96 97

//http 最大请求字节数
#define HTTP_MAX_REQ_SIZE (4*1024)
98
const string kMaxReqSize = HTTP_FIELD"maxReqSize";
xzl committed
99 100

//http keep-alive秒数
xiongziliang committed
101
#define HTTP_KEEP_ALIVE_SECOND 10
102
const string kKeepAliveSecond = HTTP_FIELD"keepAliveSecond";
xzl committed
103 104 105

//http keep-alive最大请求数
#define HTTP_MAX_REQ_CNT 100
106
const string kMaxReqCount = HTTP_FIELD"maxReqCount";
xzl committed
107

108

xzl committed
109
//http 字符编码
110 111 112
#if defined(_WIN32)
#define HTTP_CHAR_SET "gb2312"
#else
xzl committed
113
#define HTTP_CHAR_SET "utf-8"
114
#endif
115
const string kCharSet = HTTP_FIELD"charSet";
xzl committed
116 117 118

//http 服务器根目录
#define HTTP_ROOT_PATH (exeDir() + "httpRoot")
119
const string kRootPath = HTTP_FIELD"rootPath";
xzl committed
120 121 122 123 124 125 126

//http 404错误提示内容
#define HTTP_NOT_FOUND "<html>"\
		"<head><title>404 Not Found</title></head>"\
		"<body bgcolor=\"white\">"\
		"<center><h1>您访问的资源不存在!</h1></center>"\
		"<hr><center>"\
127
		 SERVER_NAME\
xzl committed
128 129 130
		"</center>"\
		"</body>"\
		"</html>"
131
const string kNotFound = HTTP_FIELD"notFound";
xzl committed
132

xzl committed
133

xzl committed
134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150
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
151
const string kMaxReqSize = SHELL_FIELD"maxReqSize";
xzl committed
152 153 154 155 156 157 158 159 160

onceToken token([](){
	mINI::Instance()[kMaxReqSize] = SHELL_MAX_REQ_SIZE;
},nullptr);
} //namespace Shell

////////////RTSP服务器配置///////////
namespace Rtsp {
#define RTSP_FIELD "rtsp."
161 162 163
const string kAuthBasic = RTSP_FIELD"authBasic";
const string kHandshakeSecond = RTSP_FIELD"handshakeSecond";
const string kKeepAliveSecond = RTSP_FIELD"keepAliveSecond";
164
const string kDirectProxy = RTSP_FIELD"directProxy";;
xzl committed
165
onceToken token([](){
166 167
	//默认Md5方式认证
	mINI::Instance()[kAuthBasic] = 0;
168 169
    mINI::Instance()[kHandshakeSecond] = 15;
    mINI::Instance()[kKeepAliveSecond] = 15;
170
	mINI::Instance()[kDirectProxy] = 1;
xzl committed
171 172 173 174 175 176 177
},nullptr);

} //namespace Rtsp

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

onceToken token([](){
183
	mINI::Instance()[kModifyStamp] = true;
184 185
    mINI::Instance()[kHandshakeSecond] = 15;
    mINI::Instance()[kKeepAliveSecond] = 15;
xzl committed
186
},nullptr);
187

xzl committed
188 189 190 191 192 193 194 195 196
} //namespace RTMP


////////////RTP配置///////////
namespace Rtp {
#define RTP_FIELD "rtp."

//RTP打包最大MTU,公网情况下更小
#define RTP_VIDOE_MTU_SIZE 1400
197
const string kVideoMtuSize = RTP_FIELD"videoMtuSize";
xzl committed
198 199

#define RTP_Audio_MTU_SIZE 600
200
const string kAudioMtuSize = RTP_FIELD"audioMtuSize";
xzl committed
201 202 203

//RTP排序缓存最大个数
#define RTP_MAX_RTP_COUNT 50
204
const string kMaxRtpCount = RTP_FIELD"maxRtpCount";
xzl committed
205 206 207

//如果RTP序列正确次数累计达到该数字就启动清空排序缓存
#define RTP_CLEAR_COUNT 10
208
const string kClearCount = RTP_FIELD"clearCount";
xzl committed
209 210 211

//最大RTP时间为13个小时,每13小时回环一次
#define RTP_CYCLE_MS (13*60*60*1000)
212
const string kCycleMS = RTP_FIELD"cycleMS";
xzl committed
213 214 215 216 217 218 219 220 221 222 223 224 225 226 227


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."
//组播分配起始地址
228
const string kAddrMin = MULTI_FIELD"addrMin";
xzl committed
229
//组播分配截止地址
230
const string kAddrMax = MULTI_FIELD"addrMax";
xzl committed
231 232
//组播TTL
#define MULTI_UDP_TTL 64
233
const string kUdpTTL = MULTI_FIELD"udpTTL";
xzl committed
234 235

onceToken token([](){
236 237
	mINI::Instance()[kAddrMin] = "239.0.0.0";
	mINI::Instance()[kAddrMax] = "239.255.255.255";
xzl committed
238 239 240 241 242 243 244 245 246 247 248
	mINI::Instance()[kUdpTTL] = MULTI_UDP_TTL;
},nullptr);

} //namespace MultiCast

////////////录像配置///////////
namespace Record {
#define RECORD_FIELD "record."

//查看录像的应用名称
#define RECORD_APP_NAME "record"
249
const string kAppName = RECORD_FIELD"appName";
xzl committed
250 251 252

//每次流化MP4文件的时长,单位毫秒
#define RECORD_SAMPLE_MS 100
253
const string kSampleMS = RECORD_FIELD"sampleMS";
xzl committed
254

255 256
//MP4文件录制大小,默认一个小时
#define RECORD_FILE_SECOND (60*60)
257
const string kFileSecond = RECORD_FIELD"fileSecond";
xzl committed
258 259 260

//录制文件路径
#define RECORD_FILE_PATH HTTP_ROOT_PATH
261
const string kFilePath = RECORD_FIELD"filePath";
xzl committed
262 263 264 265 266 267 268 269 270 271 272 273 274 275 276

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;
},nullptr);

} //namespace Record

////////////HLS相关配置///////////
namespace Hls {
#define HLS_FIELD "hls."

//HLS切片时长,单位秒
xiongziliang committed
277
#define HLS_SEGMENT_DURATION 3
278
const string kSegmentDuration = HLS_FIELD"segDur";
xzl committed
279 280

//HLS切片个数
xiongziliang committed
281
#define HLS_SEGMENT_NUM 3
282
const string kSegmentNum = HLS_FIELD"segNum";
xzl committed
283 284 285

//HLS文件写缓存大小
#define HLS_FILE_BUF_SIZE (64 * 1024)
286
const string kFileBufSize = HLS_FIELD"fileBufSize";
xzl committed
287 288 289

//录制文件路径
#define HLS_FILE_PATH (HTTP_ROOT_PATH)
290
const string kFilePath = HLS_FIELD"filePath";
xzl committed
291 292 293 294 295 296 297 298 299 300

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

xiongziliang committed
301 302

namespace Client {
303 304 305 306 307 308 309 310 311
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
312 313 314

}

xiongziliang committed
315
}  // namespace mediakit
xzl committed
316 317