2017-10-09 22:11:01 +08:00
|
|
|
|
/*
|
2020-04-04 20:30:09 +08:00
|
|
|
|
* Copyright (c) 2016 The ZLMediaKit project authors. All Rights Reserved.
|
2017-09-27 16:20:30 +08:00
|
|
|
|
*
|
2021-01-17 18:31:50 +08:00
|
|
|
|
* This file is part of ZLMediaKit(https://github.com/xia-chu/ZLMediaKit).
|
2017-09-27 16:20:30 +08:00
|
|
|
|
*
|
2020-04-04 20:30:09 +08:00
|
|
|
|
* Use of this source code is governed by MIT license that can be found in the
|
|
|
|
|
* 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.
|
2017-09-27 16:20:30 +08:00
|
|
|
|
*/
|
|
|
|
|
|
2021-12-27 17:40:15 +08:00
|
|
|
|
#include <stdio.h>
|
2022-03-01 19:00:50 +08:00
|
|
|
|
#include <assert.h>
|
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
|
|
|
|
|
2022-02-02 20:34:50 +08:00
|
|
|
|
using namespace std;
|
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
|
|
|
|
|
2018-02-08 17:24:42 +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'){
|
2018-02-08 17:24:42 +08:00
|
|
|
|
ini = ini_path;
|
|
|
|
|
}else{
|
|
|
|
|
ini = exePath() + ".ini";
|
|
|
|
|
}
|
2020-03-20 11:51:24 +08:00
|
|
|
|
try{
|
2018-02-08 17:24:42 +08:00
|
|
|
|
mINI::Instance().parseFile(ini);
|
2018-02-09 11:42:55 +08:00
|
|
|
|
NoticeCenter::Instance().emitEvent(Broadcast::kBroadcastReloadConfig);
|
2018-02-08 17:24:42 +08:00
|
|
|
|
return true;
|
2021-01-17 18:31:50 +08:00
|
|
|
|
}catch (std::exception &) {
|
2020-03-20 11:51:24 +08:00
|
|
|
|
InfoL << "dump ini file to:" << ini;
|
2018-02-08 17:24:42 +08:00
|
|
|
|
mINI::Instance().dumpFile(ini);
|
|
|
|
|
return false;
|
2020-03-20 11:51:24 +08:00
|
|
|
|
}
|
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";
|
2022-05-25 15:11:26 +08:00
|
|
|
|
const string kBroadcastRecordTs = "kBroadcastRecordTs";
|
2019-06-12 18:37:52 +08:00
|
|
|
|
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-12-23 12:47:04 +08:00
|
|
|
|
const string kBroadcastHttpBeforeAccess = "kBroadcastHttpBeforeAccess";
|
2019-05-28 17:14:36 +08:00
|
|
|
|
} //namespace Broadcast
|
2018-02-08 17:24:42 +08:00
|
|
|
|
|
2019-05-28 17:14:36 +08:00
|
|
|
|
//通用配置项目
|
|
|
|
|
namespace General{
|
|
|
|
|
#define GENERAL_FIELD "general."
|
2020-09-28 10:45:59 +08:00
|
|
|
|
const string kMediaServerId = GENERAL_FIELD"mediaServerId";
|
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";
|
2019-09-29 10:33:05 +08:00
|
|
|
|
const string kAddMuteAudio = GENERAL_FIELD"addMuteAudio";
|
2019-10-11 16:51:10 +08:00
|
|
|
|
const string kResetWhenRePlay = GENERAL_FIELD"resetWhenRePlay";
|
2019-11-08 15:54:13 +08:00
|
|
|
|
const string kPublishToHls = GENERAL_FIELD"publishToHls";
|
|
|
|
|
const string kPublishToMP4 = GENERAL_FIELD"publishToMP4";
|
2020-04-09 16:19:03 +08:00
|
|
|
|
const string kMergeWriteMS = GENERAL_FIELD"mergeWriteMS";
|
2020-05-25 12:07:38 +08:00
|
|
|
|
const string kModifyStamp = GENERAL_FIELD"modifyStamp";
|
2020-11-15 00:40:46 +08:00
|
|
|
|
const string kHlsDemand = GENERAL_FIELD"hls_demand";
|
|
|
|
|
const string kRtspDemand = GENERAL_FIELD"rtsp_demand";
|
|
|
|
|
const string kRtmpDemand = GENERAL_FIELD"rtmp_demand";
|
|
|
|
|
const string kTSDemand = GENERAL_FIELD"ts_demand";
|
|
|
|
|
const string kFMP4Demand = GENERAL_FIELD"fmp4_demand";
|
2021-05-22 10:17:52 +08:00
|
|
|
|
const string kEnableAudio = GENERAL_FIELD"enable_audio";
|
2022-05-25 15:11:26 +08:00
|
|
|
|
const string kCheckNvidiaDev = GENERAL_FIELD"check_nvidia_dev";
|
|
|
|
|
const string kEnableFFmpegLog = GENERAL_FIELD"enable_ffmpeg_log";
|
2021-11-30 18:02:52 +08:00
|
|
|
|
const string kWaitTrackReadyMS = GENERAL_FIELD"wait_track_ready_ms";
|
|
|
|
|
const string kWaitAddTrackMS = GENERAL_FIELD"wait_add_track_ms";
|
|
|
|
|
const string kUnreadyFrameCache = GENERAL_FIELD"unready_frame_cache";
|
2022-01-10 16:37:50 +08:00
|
|
|
|
const string kContinuePushMS = GENERAL_FIELD"continue_push_ms";
|
2019-09-29 10:33:05 +08:00
|
|
|
|
|
2022-03-13 20:48:01 +08:00
|
|
|
|
static onceToken token([](){
|
2018-02-06 15:28:27 +08:00
|
|
|
|
mINI::Instance()[kFlowThreshold] = 1024;
|
2019-12-29 11:52:02 +08:00
|
|
|
|
mINI::Instance()[kStreamNoneReaderDelayMS] = 20 * 1000;
|
|
|
|
|
mINI::Instance()[kMaxStreamWaitTimeMS] = 15 * 1000;
|
2019-12-26 12:23:38 +08:00
|
|
|
|
mINI::Instance()[kEnableVhost] = 0;
|
2020-03-20 11:51:24 +08:00
|
|
|
|
mINI::Instance()[kAddMuteAudio] = 1;
|
|
|
|
|
mINI::Instance()[kResetWhenRePlay] = 1;
|
|
|
|
|
mINI::Instance()[kPublishToHls] = 1;
|
|
|
|
|
mINI::Instance()[kPublishToMP4] = 0;
|
2020-04-29 11:08:43 +08:00
|
|
|
|
mINI::Instance()[kMergeWriteMS] = 0;
|
2020-05-25 12:07:38 +08:00
|
|
|
|
mINI::Instance()[kModifyStamp] = 0;
|
2020-10-01 14:37:52 +08:00
|
|
|
|
mINI::Instance()[kMediaServerId] = makeRandStr(16);
|
2020-11-15 00:43:42 +08:00
|
|
|
|
mINI::Instance()[kHlsDemand] = 0;
|
|
|
|
|
mINI::Instance()[kRtspDemand] = 0;
|
|
|
|
|
mINI::Instance()[kRtmpDemand] = 0;
|
|
|
|
|
mINI::Instance()[kTSDemand] = 0;
|
|
|
|
|
mINI::Instance()[kFMP4Demand] = 0;
|
2021-05-22 10:17:52 +08:00
|
|
|
|
mINI::Instance()[kEnableAudio] = 1;
|
2022-05-25 15:11:26 +08:00
|
|
|
|
mINI::Instance()[kCheckNvidiaDev] = 1;
|
|
|
|
|
mINI::Instance()[kEnableFFmpegLog] = 0;
|
2021-11-30 18:02:52 +08:00
|
|
|
|
mINI::Instance()[kWaitTrackReadyMS] = 10000;
|
|
|
|
|
mINI::Instance()[kWaitAddTrackMS] = 3000;
|
|
|
|
|
mINI::Instance()[kUnreadyFrameCache] = 100;
|
2022-01-10 16:37:50 +08:00
|
|
|
|
mINI::Instance()[kContinuePushMS] = 15 * 1000;
|
2022-03-13 20:48:01 +08:00
|
|
|
|
});
|
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."
|
2019-06-12 18:37:52 +08:00
|
|
|
|
const string kSendBufSize = HTTP_FIELD"sendBufSize";
|
|
|
|
|
const string kMaxReqSize = HTTP_FIELD"maxReqSize";
|
|
|
|
|
const string kKeepAliveSecond = HTTP_FIELD"keepAliveSecond";
|
|
|
|
|
const string kCharSet = HTTP_FIELD"charSet";
|
|
|
|
|
const string kRootPath = HTTP_FIELD"rootPath";
|
2021-08-25 14:30:31 +08:00
|
|
|
|
const string kVirtualPath = HTTP_FIELD "virtualPath";
|
2019-06-12 18:37:52 +08:00
|
|
|
|
const string kNotFound = HTTP_FIELD"notFound";
|
2020-06-30 09:16:02 +08:00
|
|
|
|
const string kDirMenu = HTTP_FIELD"dirMenu";
|
2022-02-17 10:35:10 +08:00
|
|
|
|
const string kForbidCacheSuffix = HTTP_FIELD"forbidCacheSuffix";
|
|
|
|
|
|
2022-03-13 20:48:01 +08:00
|
|
|
|
static onceToken token([](){
|
2020-03-20 11:51:24 +08:00
|
|
|
|
mINI::Instance()[kSendBufSize] = 64 * 1024;
|
2021-06-28 20:12:35 +08:00
|
|
|
|
mINI::Instance()[kMaxReqSize] = 4 * 10240;
|
2020-03-20 11:51:24 +08:00
|
|
|
|
mINI::Instance()[kKeepAliveSecond] = 15;
|
2020-06-30 09:16:02 +08:00
|
|
|
|
mINI::Instance()[kDirMenu] = true;
|
2021-08-26 19:36:38 +08:00
|
|
|
|
mINI::Instance()[kVirtualPath] = "";
|
2020-06-30 09:16:02 +08:00
|
|
|
|
|
2019-11-05 10:27:28 +08:00
|
|
|
|
#if defined(_WIN32)
|
2020-03-20 11:51:24 +08:00
|
|
|
|
mINI::Instance()[kCharSet] = "gb2312";
|
2019-11-05 10:27:28 +08:00
|
|
|
|
#else
|
2020-03-20 11:51:24 +08:00
|
|
|
|
mINI::Instance()[kCharSet] ="utf-8";
|
2019-11-05 10:27:28 +08:00
|
|
|
|
#endif
|
|
|
|
|
|
2020-03-20 11:51:24 +08:00
|
|
|
|
mINI::Instance()[kRootPath] = "./www";
|
2021-09-30 11:27:42 +08:00
|
|
|
|
mINI::Instance()[kNotFound] = StrPrinter << "<html>"
|
|
|
|
|
"<head><title>404 Not Found</title></head>"
|
|
|
|
|
"<body bgcolor=\"white\">"
|
|
|
|
|
"<center><h1>您访问的资源不存在!</h1></center>"
|
|
|
|
|
"<hr><center>"
|
2021-10-16 16:58:03 +08:00
|
|
|
|
<< kServerName
|
2021-09-30 11:27:42 +08:00
|
|
|
|
<< "</center>"
|
|
|
|
|
"</body>"
|
|
|
|
|
"</html>"
|
|
|
|
|
<< endl;
|
2022-02-17 10:35:10 +08:00
|
|
|
|
mINI::Instance()[kForbidCacheSuffix] = "";
|
2022-03-13 20:48:01 +08:00
|
|
|
|
});
|
2017-04-01 16:35:56 +08:00
|
|
|
|
|
|
|
|
|
}//namespace Http
|
|
|
|
|
|
|
|
|
|
////////////SHELL配置///////////
|
|
|
|
|
namespace Shell {
|
|
|
|
|
#define SHELL_FIELD "shell."
|
2019-06-12 18:37:52 +08:00
|
|
|
|
const string kMaxReqSize = SHELL_FIELD"maxReqSize";
|
2017-04-01 16:35:56 +08:00
|
|
|
|
|
2022-03-13 20:48:01 +08:00
|
|
|
|
static onceToken token([](){
|
2020-03-20 11:51:24 +08:00
|
|
|
|
mINI::Instance()[kMaxReqSize] = 1024;
|
2022-03-13 20:48:01 +08:00
|
|
|
|
});
|
2017-04-01 16:35:56 +08:00
|
|
|
|
} //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";
|
2019-08-22 16:05:35 +08:00
|
|
|
|
const string kDirectProxy = RTSP_FIELD"directProxy";
|
|
|
|
|
|
2022-03-13 20:48:01 +08:00
|
|
|
|
static onceToken token([](){
|
2020-03-20 11:51:24 +08:00
|
|
|
|
//默认Md5方式认证
|
|
|
|
|
mINI::Instance()[kAuthBasic] = 0;
|
2019-05-29 18:24:35 +08:00
|
|
|
|
mINI::Instance()[kHandshakeSecond] = 15;
|
|
|
|
|
mINI::Instance()[kKeepAliveSecond] = 15;
|
2020-03-20 11:51:24 +08:00
|
|
|
|
mINI::Instance()[kDirectProxy] = 1;
|
2022-03-13 20:48:01 +08:00
|
|
|
|
});
|
2017-04-01 16:35:56 +08:00
|
|
|
|
} //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
|
|
|
|
|
2022-03-13 20:48:01 +08:00
|
|
|
|
static onceToken token([](){
|
2020-03-20 11:51:24 +08:00
|
|
|
|
mINI::Instance()[kModifyStamp] = false;
|
2019-05-29 18:24:35 +08:00
|
|
|
|
mINI::Instance()[kHandshakeSecond] = 15;
|
|
|
|
|
mINI::Instance()[kKeepAliveSecond] = 15;
|
2022-03-13 20:48:01 +08:00
|
|
|
|
});
|
2017-04-01 16:35:56 +08:00
|
|
|
|
} //namespace RTMP
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
////////////RTP配置///////////
|
|
|
|
|
namespace Rtp {
|
|
|
|
|
#define RTP_FIELD "rtp."
|
|
|
|
|
//RTP打包最大MTU,公网情况下更小
|
2019-06-12 18:37:52 +08:00
|
|
|
|
const string kVideoMtuSize = RTP_FIELD"videoMtuSize";
|
|
|
|
|
const string kAudioMtuSize = RTP_FIELD"audioMtuSize";
|
2021-08-12 10:43:12 +08:00
|
|
|
|
//rtp包最大长度限制,单位是KB
|
2021-08-11 15:48:15 +08:00
|
|
|
|
const string kRtpMaxSize = RTP_FIELD"rtpMaxSize";
|
2017-04-01 16:35:56 +08:00
|
|
|
|
|
2022-03-13 20:48:01 +08:00
|
|
|
|
static onceToken token([](){
|
2020-03-20 11:51:24 +08:00
|
|
|
|
mINI::Instance()[kVideoMtuSize] = 1400;
|
|
|
|
|
mINI::Instance()[kAudioMtuSize] = 600;
|
2021-08-11 15:48:15 +08:00
|
|
|
|
mINI::Instance()[kRtpMaxSize] = 10;
|
2022-03-13 20:48:01 +08:00
|
|
|
|
});
|
2017-04-01 16:35:56 +08:00
|
|
|
|
} //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
|
2019-06-12 18:37:52 +08:00
|
|
|
|
const string kUdpTTL = MULTI_FIELD"udpTTL";
|
2017-04-01 16:35:56 +08:00
|
|
|
|
|
2022-03-13 20:48:01 +08:00
|
|
|
|
static onceToken token([](){
|
2020-03-20 11:51:24 +08:00
|
|
|
|
mINI::Instance()[kAddrMin] = "239.0.0.0";
|
|
|
|
|
mINI::Instance()[kAddrMax] = "239.255.255.255";
|
|
|
|
|
mINI::Instance()[kUdpTTL] = 64;
|
2022-03-13 20:48:01 +08:00
|
|
|
|
});
|
2017-04-01 16:35:56 +08:00
|
|
|
|
} //namespace MultiCast
|
|
|
|
|
|
|
|
|
|
////////////录像配置///////////
|
|
|
|
|
namespace Record {
|
|
|
|
|
#define RECORD_FIELD "record."
|
2019-06-12 18:37:52 +08:00
|
|
|
|
const string kAppName = RECORD_FIELD"appName";
|
|
|
|
|
const string kSampleMS = RECORD_FIELD"sampleMS";
|
|
|
|
|
const string kFileSecond = RECORD_FIELD"fileSecond";
|
|
|
|
|
const string kFilePath = RECORD_FIELD"filePath";
|
2019-08-01 22:13:26 +08:00
|
|
|
|
const string kFileBufSize = RECORD_FIELD"fileBufSize";
|
2019-10-10 13:37:56 +08:00
|
|
|
|
const string kFastStart = RECORD_FIELD"fastStart";
|
2019-09-24 20:48:30 +08:00
|
|
|
|
const string kFileRepeat = RECORD_FIELD"fileRepeat";
|
|
|
|
|
|
2022-03-13 20:48:01 +08:00
|
|
|
|
static onceToken token([](){
|
2020-03-20 11:51:24 +08:00
|
|
|
|
mINI::Instance()[kAppName] = "record";
|
|
|
|
|
mINI::Instance()[kSampleMS] = 500;
|
|
|
|
|
mINI::Instance()[kFileSecond] = 60*60;
|
|
|
|
|
mINI::Instance()[kFilePath] = "./www";
|
|
|
|
|
mINI::Instance()[kFileBufSize] = 64 * 1024;
|
|
|
|
|
mINI::Instance()[kFastStart] = false;
|
|
|
|
|
mINI::Instance()[kFileRepeat] = false;
|
2022-03-13 20:48:01 +08:00
|
|
|
|
});
|
2017-04-01 16:35:56 +08:00
|
|
|
|
} //namespace Record
|
|
|
|
|
|
|
|
|
|
////////////HLS相关配置///////////
|
|
|
|
|
namespace Hls {
|
|
|
|
|
#define HLS_FIELD "hls."
|
2019-06-12 18:37:52 +08:00
|
|
|
|
const string kSegmentDuration = HLS_FIELD"segDur";
|
|
|
|
|
const string kSegmentNum = HLS_FIELD"segNum";
|
2022-05-10 17:32:50 +08:00
|
|
|
|
const string kSegmentKeep = HLS_FIELD"segKeep";
|
2019-11-05 10:27:28 +08:00
|
|
|
|
const string kSegmentRetain = HLS_FIELD"segRetain";
|
2019-06-12 18:37:52 +08:00
|
|
|
|
const string kFileBufSize = HLS_FIELD"fileBufSize";
|
|
|
|
|
const string kFilePath = HLS_FIELD"filePath";
|
2020-09-15 17:46:12 +08:00
|
|
|
|
const string kBroadcastRecordTs = HLS_FIELD"broadcastRecordTs";
|
2021-06-23 10:25:09 +08:00
|
|
|
|
const string kDeleteDelaySec = HLS_FIELD"deleteDelaySec";
|
2017-04-01 16:35:56 +08:00
|
|
|
|
|
2022-03-13 20:48:01 +08:00
|
|
|
|
static onceToken token([](){
|
2020-03-20 11:51:24 +08:00
|
|
|
|
mINI::Instance()[kSegmentDuration] = 2;
|
|
|
|
|
mINI::Instance()[kSegmentNum] = 3;
|
2022-05-10 17:32:50 +08:00
|
|
|
|
mINI::Instance()[kSegmentKeep] = false;
|
2020-03-20 11:51:24 +08:00
|
|
|
|
mINI::Instance()[kSegmentRetain] = 5;
|
|
|
|
|
mINI::Instance()[kFileBufSize] = 64 * 1024;
|
|
|
|
|
mINI::Instance()[kFilePath] = "./www";
|
2020-09-15 17:46:12 +08:00
|
|
|
|
mINI::Instance()[kBroadcastRecordTs] = false;
|
2021-06-23 10:25:09 +08:00
|
|
|
|
mINI::Instance()[kDeleteDelaySec] = 0;
|
2022-03-13 20:48:01 +08:00
|
|
|
|
});
|
2017-04-01 16:35:56 +08:00
|
|
|
|
} //namespace Hls
|
|
|
|
|
|
2019-12-06 11:54:10 +08:00
|
|
|
|
|
|
|
|
|
////////////Rtp代理相关配置///////////
|
|
|
|
|
namespace RtpProxy {
|
|
|
|
|
#define RTP_PROXY_FIELD "rtp_proxy."
|
|
|
|
|
const string kDumpDir = RTP_PROXY_FIELD"dumpDir";
|
|
|
|
|
const string kTimeoutSec = RTP_PROXY_FIELD"timeoutSec";
|
2022-03-13 20:48:01 +08:00
|
|
|
|
const string kPortRange = RTP_PROXY_FIELD "port_range";
|
2019-12-06 11:54:10 +08:00
|
|
|
|
|
2022-03-13 20:48:01 +08:00
|
|
|
|
static onceToken token([](){
|
2020-03-20 11:51:24 +08:00
|
|
|
|
mINI::Instance()[kDumpDir] = "";
|
|
|
|
|
mINI::Instance()[kTimeoutSec] = 15;
|
2022-03-13 20:48:01 +08:00
|
|
|
|
mINI::Instance()[kPortRange] = "30000-35000";
|
|
|
|
|
});
|
2019-12-06 11:54:10 +08:00
|
|
|
|
} //namespace RtpProxy
|
|
|
|
|
|
|
|
|
|
|
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";
|
2020-04-08 11:16:09 +08:00
|
|
|
|
const string kBenchmarkMode = "benchmark_mode";
|
2021-11-10 13:56:04 +08:00
|
|
|
|
const string kWaitTrackReady = "wait_track_ready";
|
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
|
|
|
|
|
2021-02-21 21:28:17 +08:00
|
|
|
|
#ifdef ENABLE_MEM_DEBUG
|
|
|
|
|
|
2021-12-27 17:40:15 +08:00
|
|
|
|
extern "C" {
|
|
|
|
|
extern void *__real_malloc(size_t);
|
|
|
|
|
extern void __real_free(void *);
|
|
|
|
|
extern void *__real_realloc(void *ptr, size_t c);
|
|
|
|
|
void *__wrap_malloc(size_t c);
|
|
|
|
|
void __wrap_free(void *ptr);
|
|
|
|
|
void *__wrap_calloc(size_t __nmemb, size_t __size);
|
|
|
|
|
void *__wrap_realloc(void *ptr, size_t c);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-29 20:48:15 +08:00
|
|
|
|
#define BLOCK_TYPES 16
|
|
|
|
|
#define MIN_BLOCK_SIZE 128
|
|
|
|
|
|
|
|
|
|
static int get_mem_block_type(size_t c) {
|
|
|
|
|
int ret = 0;
|
|
|
|
|
while (c > MIN_BLOCK_SIZE && ret + 1 < BLOCK_TYPES) {
|
|
|
|
|
c >>= 1;
|
|
|
|
|
++ret;
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
std::vector<size_t> getBlockTypeSize() {
|
|
|
|
|
std::vector<size_t> ret;
|
|
|
|
|
ret.resize(BLOCK_TYPES);
|
|
|
|
|
size_t block_size = MIN_BLOCK_SIZE;
|
|
|
|
|
for (auto i = 0; i < BLOCK_TYPES; ++i) {
|
|
|
|
|
ret[i] = block_size;
|
|
|
|
|
block_size <<= 1;
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-30 20:34:56 +08:00
|
|
|
|
class MemThreadInfo {
|
2021-12-27 17:40:15 +08:00
|
|
|
|
public:
|
2021-12-30 20:34:56 +08:00
|
|
|
|
using Ptr = std::shared_ptr<MemThreadInfo>;
|
2021-12-27 17:40:15 +08:00
|
|
|
|
atomic<uint64_t> mem_usage{0};
|
2021-12-29 20:48:15 +08:00
|
|
|
|
atomic<uint64_t> mem_block{0};
|
|
|
|
|
atomic<uint64_t> mem_block_map[BLOCK_TYPES];
|
2021-12-30 12:02:45 +08:00
|
|
|
|
|
2021-12-30 20:34:56 +08:00
|
|
|
|
static MemThreadInfo *Instance(bool is_thread_local) {
|
|
|
|
|
if (!is_thread_local) {
|
|
|
|
|
static auto instance = new MemThreadInfo(is_thread_local);
|
|
|
|
|
return instance;
|
|
|
|
|
}
|
|
|
|
|
static auto thread_local instance = new MemThreadInfo(is_thread_local);
|
|
|
|
|
return instance;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~MemThreadInfo() {
|
|
|
|
|
//printf("%s %d\r\n", __FUNCTION__, (int) _is_thread_local);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MemThreadInfo(bool is_thread_local) {
|
|
|
|
|
_is_thread_local = is_thread_local;
|
|
|
|
|
if (_is_thread_local) {
|
|
|
|
|
//确保所有线程退出后才能释放全局内存统计器
|
|
|
|
|
total_mem = Instance(false);
|
|
|
|
|
}
|
|
|
|
|
//printf("%s %d\r\n", __FUNCTION__, (int) _is_thread_local);
|
2021-12-30 12:02:45 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void *operator new(size_t sz) {
|
|
|
|
|
return __real_malloc(sz);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void operator delete(void *ptr) {
|
|
|
|
|
__real_free(ptr);
|
|
|
|
|
}
|
2021-12-30 20:34:56 +08:00
|
|
|
|
|
|
|
|
|
void addBlock(size_t c) {
|
|
|
|
|
if (total_mem) {
|
|
|
|
|
total_mem->addBlock(c);
|
|
|
|
|
}
|
|
|
|
|
mem_usage += c;
|
|
|
|
|
++mem_block_map[get_mem_block_type(c)];
|
|
|
|
|
++mem_block;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void delBlock(size_t c) {
|
|
|
|
|
if (total_mem) {
|
|
|
|
|
total_mem->delBlock(c);
|
|
|
|
|
}
|
|
|
|
|
mem_usage -= c;
|
|
|
|
|
--mem_block_map[get_mem_block_type(c)];
|
|
|
|
|
if (0 == --mem_block) {
|
|
|
|
|
delete this;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
bool _is_thread_local;
|
|
|
|
|
MemThreadInfo *total_mem = nullptr;
|
2021-12-27 17:40:15 +08:00
|
|
|
|
};
|
|
|
|
|
|
2021-12-30 20:34:56 +08:00
|
|
|
|
class MemThreadInfoLocal {
|
2021-12-30 12:02:45 +08:00
|
|
|
|
public:
|
2021-12-30 20:34:56 +08:00
|
|
|
|
MemThreadInfoLocal() {
|
|
|
|
|
ptr = MemThreadInfo::Instance(true);
|
|
|
|
|
ptr->addBlock(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
~MemThreadInfoLocal() {
|
|
|
|
|
ptr->delBlock(1);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
MemThreadInfo *get() const {
|
|
|
|
|
return ptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
MemThreadInfo *ptr;
|
2021-12-30 12:02:45 +08:00
|
|
|
|
};
|
2021-12-27 17:40:15 +08:00
|
|
|
|
|
2021-12-30 20:34:56 +08:00
|
|
|
|
//该变量主要确保线程退出后才能释放MemThreadInfo变量
|
|
|
|
|
static thread_local MemThreadInfoLocal s_thread_mem_info;
|
2021-02-21 21:28:17 +08:00
|
|
|
|
|
|
|
|
|
uint64_t getTotalMemUsage() {
|
2021-12-30 20:34:56 +08:00
|
|
|
|
return MemThreadInfo::Instance(false)->mem_usage.load();
|
2021-02-21 21:28:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-29 20:48:15 +08:00
|
|
|
|
uint64_t getTotalMemBlock() {
|
2021-12-30 20:34:56 +08:00
|
|
|
|
return MemThreadInfo::Instance(false)->mem_block.load();
|
2021-12-29 20:48:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint64_t getTotalMemBlockByType(int type) {
|
|
|
|
|
assert(type < BLOCK_TYPES);
|
2021-12-30 20:34:56 +08:00
|
|
|
|
return MemThreadInfo::Instance(false)->mem_block_map[type].load();
|
2021-12-29 20:48:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-27 17:40:15 +08:00
|
|
|
|
uint64_t getThisThreadMemUsage() {
|
2021-12-30 20:34:56 +08:00
|
|
|
|
return MemThreadInfo::Instance(true)->mem_usage.load();
|
2021-12-27 17:40:15 +08:00
|
|
|
|
}
|
2021-02-21 21:28:17 +08:00
|
|
|
|
|
2021-12-29 20:48:15 +08:00
|
|
|
|
uint64_t getThisThreadMemBlock() {
|
2021-12-30 20:34:56 +08:00
|
|
|
|
return MemThreadInfo::Instance(true)->mem_block.load();
|
2021-12-29 20:48:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
uint64_t getThisThreadMemBlockByType(int type) {
|
|
|
|
|
assert(type < BLOCK_TYPES);
|
2021-12-30 20:34:56 +08:00
|
|
|
|
return MemThreadInfo::Instance(true)->mem_block_map[type].load();
|
2021-12-29 20:48:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-27 17:40:15 +08:00
|
|
|
|
class MemCookie {
|
|
|
|
|
public:
|
|
|
|
|
static constexpr uint32_t kMagic = 0xFEFDFCFB;
|
|
|
|
|
uint32_t magic;
|
|
|
|
|
uint32_t size;
|
2021-12-30 20:34:56 +08:00
|
|
|
|
MemThreadInfo* alloc_info;
|
2021-12-27 17:40:15 +08:00
|
|
|
|
char ptr;
|
2021-12-30 20:34:56 +08:00
|
|
|
|
};
|
2021-12-27 17:40:15 +08:00
|
|
|
|
|
2021-12-30 20:34:56 +08:00
|
|
|
|
#define MEM_OFFSET offsetof(MemCookie, ptr)
|
|
|
|
|
|
|
|
|
|
#if (defined(__linux__) && !defined(ANDROID)) || defined(__MACH__)
|
|
|
|
|
#define MAX_STACK_FRAMES 128
|
|
|
|
|
#define MEM_WARING
|
|
|
|
|
#include <limits.h>
|
|
|
|
|
#include <sys/resource.h>
|
|
|
|
|
#include <sys/wait.h>
|
|
|
|
|
#include <execinfo.h>
|
|
|
|
|
|
|
|
|
|
static void print_mem_waring(size_t c) {
|
|
|
|
|
void *array[MAX_STACK_FRAMES];
|
|
|
|
|
int size = backtrace(array, MAX_STACK_FRAMES);
|
|
|
|
|
char **strings = backtrace_symbols(array, size);
|
|
|
|
|
printf("malloc big memory:%d, back trace:\r\n", (int)c);
|
|
|
|
|
for (int i = 0; i < size; ++i) {
|
|
|
|
|
printf("[%d]: %s\r\n", i, strings[i]);
|
|
|
|
|
}
|
|
|
|
|
__real_free(strings);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2021-02-21 21:28:17 +08:00
|
|
|
|
|
2021-12-30 20:34:56 +08:00
|
|
|
|
static void init_cookie(MemCookie *cookie, size_t c) {
|
2021-12-27 17:40:15 +08:00
|
|
|
|
cookie->magic = MemCookie::kMagic;
|
|
|
|
|
cookie->size = c;
|
2021-12-30 20:34:56 +08:00
|
|
|
|
cookie->alloc_info = s_thread_mem_info.get();
|
|
|
|
|
cookie->alloc_info->addBlock(c);
|
|
|
|
|
|
|
|
|
|
#if defined(MEM_WARING)
|
2021-12-31 10:26:36 +08:00
|
|
|
|
static auto env = getenv("MEM_WARN_SIZE");
|
|
|
|
|
static size_t s_mem_waring_size = atoll(env ? env : "0");
|
|
|
|
|
if (s_mem_waring_size > 1024 && c >= s_mem_waring_size) {
|
2021-12-30 20:34:56 +08:00
|
|
|
|
print_mem_waring(c);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
2021-12-29 20:48:15 +08:00
|
|
|
|
}
|
|
|
|
|
|
2021-12-30 20:34:56 +08:00
|
|
|
|
static void un_init_cookie(MemCookie *cookie) {
|
|
|
|
|
cookie->alloc_info->delBlock(cookie->size);
|
2021-12-27 17:40:15 +08:00
|
|
|
|
}
|
2021-02-21 21:28:17 +08:00
|
|
|
|
|
|
|
|
|
void *__wrap_malloc(size_t c) {
|
2021-12-27 17:40:15 +08:00
|
|
|
|
c += MEM_OFFSET;
|
|
|
|
|
auto cookie = (MemCookie *) __real_malloc(c);
|
|
|
|
|
if (cookie) {
|
|
|
|
|
init_cookie(cookie, c);
|
|
|
|
|
return &cookie->ptr;
|
2021-02-21 21:28:17 +08:00
|
|
|
|
}
|
|
|
|
|
return nullptr;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void __wrap_free(void *ptr) {
|
|
|
|
|
if (!ptr) {
|
|
|
|
|
return;
|
|
|
|
|
}
|
2021-12-27 17:40:15 +08:00
|
|
|
|
auto cookie = (MemCookie *) ((char *) ptr - MEM_OFFSET);
|
|
|
|
|
if (cookie->magic != MemCookie::kMagic) {
|
2021-12-29 20:48:15 +08:00
|
|
|
|
__real_free(ptr);
|
|
|
|
|
return;
|
2021-02-21 21:28:17 +08:00
|
|
|
|
}
|
2021-12-29 20:48:15 +08:00
|
|
|
|
un_init_cookie(cookie);
|
2021-12-27 17:40:15 +08:00
|
|
|
|
__real_free(cookie);
|
2021-02-21 21:28:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void *__wrap_calloc(size_t __nmemb, size_t __size) {
|
|
|
|
|
auto size = __nmemb * __size;
|
|
|
|
|
auto ret = malloc(size);
|
|
|
|
|
if (ret) {
|
|
|
|
|
memset(ret, 0, size);
|
|
|
|
|
}
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-27 17:40:15 +08:00
|
|
|
|
void *__wrap_realloc(void *ptr, size_t c) {
|
2021-02-21 21:28:17 +08:00
|
|
|
|
if (!ptr) {
|
|
|
|
|
return malloc(c);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-27 17:40:15 +08:00
|
|
|
|
auto cookie = (MemCookie *) ((char *) ptr - MEM_OFFSET);
|
|
|
|
|
if (cookie->magic != MemCookie::kMagic) {
|
2021-12-29 20:48:15 +08:00
|
|
|
|
return __real_realloc(ptr, c);
|
2021-02-21 21:28:17 +08:00
|
|
|
|
}
|
2021-12-27 17:40:15 +08:00
|
|
|
|
|
2021-12-29 20:48:15 +08:00
|
|
|
|
un_init_cookie(cookie);
|
2021-12-27 17:40:15 +08:00
|
|
|
|
c += MEM_OFFSET;
|
|
|
|
|
cookie = (MemCookie *) __real_realloc(cookie, c);
|
|
|
|
|
if (cookie) {
|
|
|
|
|
init_cookie(cookie, c);
|
|
|
|
|
return &cookie->ptr;
|
2021-02-21 21:28:17 +08:00
|
|
|
|
}
|
2021-12-27 17:40:15 +08:00
|
|
|
|
return nullptr;
|
2021-02-21 21:28:17 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
void *operator new(std::size_t size) {
|
|
|
|
|
auto ret = malloc(size);
|
|
|
|
|
if (ret) {
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
throw std::bad_alloc();
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-30 12:02:45 +08:00
|
|
|
|
void operator delete(void *ptr) noexcept {
|
2021-02-21 21:28:17 +08:00
|
|
|
|
free(ptr);
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-30 12:02:45 +08:00
|
|
|
|
void operator delete(void *ptr, std::size_t) noexcept {
|
2021-06-08 17:48:52 +08:00
|
|
|
|
free(ptr);
|
|
|
|
|
}
|
|
|
|
|
|
2021-02-21 21:28:17 +08:00
|
|
|
|
void *operator new[](std::size_t size) {
|
|
|
|
|
auto ret = malloc(size);
|
|
|
|
|
if (ret) {
|
|
|
|
|
return ret;
|
|
|
|
|
}
|
|
|
|
|
throw std::bad_alloc();
|
|
|
|
|
}
|
|
|
|
|
|
2021-12-30 12:02:45 +08:00
|
|
|
|
void operator delete[](void *ptr) noexcept {
|
2021-02-21 21:28:17 +08:00
|
|
|
|
free(ptr);
|
|
|
|
|
}
|
2021-06-08 17:48:52 +08:00
|
|
|
|
|
2021-12-30 12:02:45 +08:00
|
|
|
|
void operator delete[](void *ptr, std::size_t) noexcept {
|
2021-06-08 17:48:52 +08:00
|
|
|
|
free(ptr);
|
|
|
|
|
}
|
2021-02-21 21:28:17 +08:00
|
|
|
|
#endif
|