支持全局的禁用虚拟主机

This commit is contained in:
xiongziliang
2019-05-28 17:14:36 +08:00
parent 2f976214ce
commit a100ee0acd
23 changed files with 173 additions and 124 deletions

View File

@@ -36,8 +36,13 @@ namespace mediakit {
MediaReader::MediaReader(const string &strVhost,const string &strApp, const string &strId,const string &filePath ) {
auto strFileName = filePath;
if(strFileName.empty()){
GET_CONFIG_AND_REGISTER(string,recordPath,Record::kFilePath);
strFileName = recordPath + "/" + strVhost + "/" + strApp + "/" + strId;
GET_CONFIG(string,recordPath,Record::kFilePath);
GET_CONFIG(bool,enableVhost,General::kEnableVhost);
if(enableVhost){
strFileName = recordPath + "/" + strVhost + "/" + strApp + "/" + strId;
}else{
strFileName = recordPath + "/" + strApp + "/" + strId;
}
}
_hMP4File = MP4Read(strFileName.data());
@@ -152,7 +157,7 @@ MediaReader::~MediaReader() {
void MediaReader::startReadMP4() {
auto strongSelf = shared_from_this();
GET_CONFIG_AND_REGISTER(uint32_t,sampleMS,Record::kSampleMS);
GET_CONFIG(uint32_t,sampleMS,Record::kSampleMS);
_timer = std::make_shared<Timer>(sampleMS / 1000.0f,[strongSelf](){
return strongSelf->readSample(0,false);
@@ -321,7 +326,7 @@ MediaSource::Ptr MediaReader::onMakeMediaSource(const string &strSchema,
const string &filePath,
bool checkApp ){
#ifdef ENABLE_MP4V2
GET_CONFIG_AND_REGISTER(string,appName,Record::kAppName);
GET_CONFIG(string,appName,Record::kAppName);
if (checkApp && strApp != appName) {
return nullptr;
}

View File

@@ -41,10 +41,11 @@ MediaRecorder::MediaRecorder(const string &strVhost_tmp,
bool enableHls,
bool enableMp4) {
GET_CONFIG_AND_REGISTER(string,hlsPath,Hls::kFilePath);
GET_CONFIG_AND_REGISTER(uint32_t,hlsBufSize,Hls::kFileBufSize);
GET_CONFIG_AND_REGISTER(uint32_t,hlsDuration,Hls::kSegmentDuration);
GET_CONFIG_AND_REGISTER(uint32_t,hlsNum,Hls::kSegmentNum);
GET_CONFIG(string,hlsPath,Hls::kFilePath);
GET_CONFIG(uint32_t,hlsBufSize,Hls::kFileBufSize);
GET_CONFIG(uint32_t,hlsDuration,Hls::kSegmentDuration);
GET_CONFIG(uint32_t,hlsNum,Hls::kSegmentNum);
GET_CONFIG(bool,enableVhost,General::kEnableVhost);
string strVhost = strVhost_tmp;
if(trim(strVhost).empty()){
@@ -54,17 +55,28 @@ MediaRecorder::MediaRecorder(const string &strVhost_tmp,
#if defined(ENABLE_HLS)
if(enableHls) {
auto m3u8FilePath = hlsPath + "/" + strVhost + "/" + strApp + "/" + strId + "/hls.m3u8";
_hlsMaker.reset(new HlsRecorder(m3u8FilePath,string(VHOST_KEY) + "=" + strVhost ,hlsBufSize, hlsDuration, hlsNum));
string m3u8FilePath;
if(enableVhost){
m3u8FilePath = hlsPath + "/" + strVhost + "/" + strApp + "/" + strId + "/hls.m3u8";
_hlsMaker.reset(new HlsRecorder(m3u8FilePath,string(VHOST_KEY) + "=" + strVhost ,hlsBufSize, hlsDuration, hlsNum));
}else{
m3u8FilePath = hlsPath + "/" + strApp + "/" + strId + "/hls.m3u8";
_hlsMaker.reset(new HlsRecorder(m3u8FilePath,"",hlsBufSize, hlsDuration, hlsNum));
}
}
#endif //defined(ENABLE_HLS)
#if defined(ENABLE_MP4V2)
GET_CONFIG_AND_REGISTER(string,recordPath,Record::kFilePath);
GET_CONFIG_AND_REGISTER(string,recordAppName,Record::kAppName);
GET_CONFIG(string,recordPath,Record::kFilePath);
GET_CONFIG(string,recordAppName,Record::kAppName);
if(enableMp4){
auto mp4FilePath = recordPath + "/" + strVhost + "/" + recordAppName + "/" + strApp + "/" + strId + "/";
string mp4FilePath;
if(enableVhost){
mp4FilePath = recordPath + "/" + strVhost + "/" + recordAppName + "/" + strApp + "/" + strId + "/";
} else {
mp4FilePath = recordPath + "/" + recordAppName + "/" + strApp + "/" + strId + "/";
}
_mp4Maker.reset(new Mp4Maker(mp4FilePath,strVhost,strApp,strId));
}
#endif //defined(ENABLE_MP4V2)

View File

@@ -115,7 +115,7 @@ void Mp4Maker::inputAAC(void *pData, uint32_t ui32Length, uint32_t ui32TimeStamp
}
void Mp4Maker::inputH264_l(void *pData, uint32_t ui32Length, uint32_t ui32Duration) {
GET_CONFIG_AND_REGISTER(uint32_t,recordSec,Record::kFileSecond);
GET_CONFIG(uint32_t,recordSec,Record::kFileSecond);
auto iType = H264_TYPE(((uint8_t*)pData)[4]);
if(iType == H264Frame::NAL_IDR && (_hMp4 == MP4_INVALID_FILE_HANDLE || _ticker.elapsedTime() > recordSec * 1000)){
//在I帧率处新建MP4文件
@@ -128,7 +128,7 @@ void Mp4Maker::inputH264_l(void *pData, uint32_t ui32Length, uint32_t ui32Durati
}
void Mp4Maker::inputAAC_l(void *pData, uint32_t ui32Length, uint32_t ui32Duration) {
GET_CONFIG_AND_REGISTER(uint32_t,recordSec,Record::kFileSecond);
GET_CONFIG(uint32_t,recordSec,Record::kFileSecond);
if (!_haveVideo && (_hMp4 == MP4_INVALID_FILE_HANDLE || _ticker.elapsedTime() > recordSec * 1000)) {
//在I帧率处新建MP4文件
@@ -154,14 +154,24 @@ void Mp4Maker::createFile() {
_info.strFileName = strTime + ".mp4";
_info.strFilePath = strFile;
GET_CONFIG_AND_REGISTER(string,appName,Record::kAppName);
GET_CONFIG(string,appName,Record::kAppName);
GET_CONFIG(bool,enableVhost,General::kEnableVhost);
if(enableVhost){
_info.strUrl = _info.strVhost + "/"
+ appName + "/"
+ _info.strAppName + "/"
+ _info.strStreamId + "/"
+ strDate + "/"
+ strTime + ".mp4";
}else{
_info.strUrl = appName + "/"
+ _info.strAppName + "/"
+ _info.strStreamId + "/"
+ strDate + "/"
+ strTime + ".mp4";
}
_info.strUrl = _info.strVhost + "/"
+ appName + "/"
+ _info.strAppName + "/"
+ _info.strStreamId + "/"
+ strDate + "/"
+ strTime + ".mp4";
//----record 业务逻辑----//
#if !defined(_WIN32)