mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-20 07:12:21 +08:00
添加配置文件热加载功能
This commit is contained in:
@@ -37,8 +37,9 @@ namespace MediaFile {
|
||||
|
||||
#ifdef ENABLE_MP4V2
|
||||
MediaReader::MediaReader(const string &strVhost,const string &strApp, const string &strId) {
|
||||
static string recordPath = mINI::Instance()[Config::Record::kFilePath];
|
||||
auto strFileName = recordPath + "/" + strVhost + "/" + strApp + "/" + strId;
|
||||
GET_CONFIG_AND_REGISTER(string,recordPath,Config::Record::kFilePath);
|
||||
|
||||
auto strFileName = recordPath + "/" + strVhost + "/" + strApp + "/" + strId;
|
||||
|
||||
m_hMP4File = MP4Read(strFileName.data());
|
||||
if(m_hMP4File == MP4_INVALID_FILE_HANDLE){
|
||||
@@ -168,8 +169,9 @@ MediaReader::~MediaReader() {
|
||||
|
||||
void MediaReader::startReadMP4() {
|
||||
auto strongSelf = shared_from_this();
|
||||
static uint32_t sampleMS = mINI::Instance()[Config::Record::kSampleMS].as<uint32_t>();
|
||||
AsyncTaskThread::Instance().DoTaskDelay(reinterpret_cast<uint64_t>(this), sampleMS, [strongSelf](){
|
||||
GET_CONFIG_AND_REGISTER(uint32_t,sampleMS,Config::Record::kSampleMS);
|
||||
|
||||
AsyncTaskThread::Instance().DoTaskDelay(reinterpret_cast<uint64_t>(this), sampleMS, [strongSelf](){
|
||||
return strongSelf->readSample();
|
||||
});
|
||||
m_pChn->setListener(strongSelf);
|
||||
@@ -321,8 +323,9 @@ void MediaReader::seek(int iSeekTime,bool bReStart){
|
||||
|
||||
MediaSource::Ptr MediaReader::onMakeMediaSource(const string &strSchema,const string &strVhost,const string &strApp, const string &strId){
|
||||
#ifdef ENABLE_MP4V2
|
||||
static string appName = mINI::Instance()[Config::Record::kAppName];
|
||||
if (strApp != appName) {
|
||||
GET_CONFIG_AND_REGISTER(string,appName,Config::Record::kAppName);
|
||||
|
||||
if (strApp != appName) {
|
||||
return nullptr;
|
||||
}
|
||||
try {
|
||||
|
||||
@@ -44,12 +44,12 @@ MediaRecorder::MediaRecorder(const string &strVhost_tmp,
|
||||
bool enableHls,
|
||||
bool enableMp4) {
|
||||
|
||||
static string hlsPrefix = mINI::Instance()[Config::Hls::kHttpPrefix];
|
||||
static string hlsPrefixDefaultVhost = mINI::Instance()[Config::Hls::kHttpPrefixDefaultVhost];
|
||||
static string hlsPath = mINI::Instance()[Config::Hls::kFilePath];
|
||||
static uint32_t hlsBufSize = mINI::Instance()[Config::Hls::kFileBufSize].as<uint32_t>();
|
||||
static uint32_t hlsDuration = mINI::Instance()[Config::Hls::kSegmentDuration].as<uint32_t>();
|
||||
static uint32_t hlsNum = mINI::Instance()[Config::Hls::kSegmentNum].as<uint32_t>();
|
||||
GET_CONFIG_AND_REGISTER(string,hlsPrefix,Config::Hls::kHttpPrefix);
|
||||
GET_CONFIG_AND_REGISTER(string,hlsPrefixDefaultVhost,Config::Hls::kHttpPrefixDefaultVhost);
|
||||
GET_CONFIG_AND_REGISTER(string,hlsPath,Config::Hls::kFilePath);
|
||||
GET_CONFIG_AND_REGISTER(uint32_t,hlsBufSize,Config::Hls::kFileBufSize);
|
||||
GET_CONFIG_AND_REGISTER(uint32_t,hlsDuration,Config::Hls::kSegmentDuration);
|
||||
GET_CONFIG_AND_REGISTER(uint32_t,hlsNum,Config::Hls::kSegmentNum);
|
||||
|
||||
string strVhost = strVhost_tmp;
|
||||
if(trim(strVhost).empty()){
|
||||
@@ -80,8 +80,9 @@ MediaRecorder::MediaRecorder(const string &strVhost_tmp,
|
||||
hlsBufSize, hlsDuration, hlsNum));
|
||||
}
|
||||
#ifdef ENABLE_MP4V2
|
||||
static string recordPath = mINI::Instance()[Config::Record::kFilePath];
|
||||
static string recordAppName = mINI::Instance()[Config::Record::kAppName];
|
||||
GET_CONFIG_AND_REGISTER(string,recordPath,Config::Record::kFilePath);
|
||||
GET_CONFIG_AND_REGISTER(string,recordAppName,Config::Record::kAppName);
|
||||
|
||||
if(enableMp4){
|
||||
m_mp4Maker.reset(new Mp4Maker(recordPath + "/" + strVhost + "/" + recordAppName + "/" + strApp + "/" + strId + "/",
|
||||
strVhost,strApp,strId,pPlayer));
|
||||
|
||||
@@ -119,8 +119,9 @@ void Mp4Maker::inputAAC(void *pData, uint32_t ui32Length, uint32_t ui32TimeStamp
|
||||
}
|
||||
|
||||
void Mp4Maker::_inputH264(void* pData, uint32_t ui32Length, uint32_t ui32Duration, int iType) {
|
||||
static uint32_t recordMS = 1000 * mINI::Instance()[Config::Record::kFileSecond].as<uint32_t>();
|
||||
if(iType == 5 && (m_hMp4 == MP4_INVALID_FILE_HANDLE || m_ticker.elapsedTime() > recordMS)){
|
||||
GET_CONFIG_AND_REGISTER(uint32_t,recordSec,Config::Record::kFileSecond);
|
||||
|
||||
if(iType == 5 && (m_hMp4 == MP4_INVALID_FILE_HANDLE || m_ticker.elapsedTime() > recordSec * 1000)){
|
||||
//在I帧率处新建MP4文件
|
||||
//如果文件未创建或者文件超过10分钟则创建新文件
|
||||
createFile();
|
||||
@@ -131,8 +132,9 @@ void Mp4Maker::_inputH264(void* pData, uint32_t ui32Length, uint32_t ui32Duratio
|
||||
}
|
||||
|
||||
void Mp4Maker::_inputAAC(void* pData, uint32_t ui32Length, uint32_t ui32Duration) {
|
||||
static uint32_t recordMS = 1000 * mINI::Instance()[Config::Record::kFileSecond].as<uint32_t>();
|
||||
if (!m_pPlayer->containVideo() && (m_hMp4 == MP4_INVALID_FILE_HANDLE || m_ticker.elapsedTime() > recordMS)) {
|
||||
GET_CONFIG_AND_REGISTER(uint32_t,recordSec,Config::Record::kFileSecond);
|
||||
|
||||
if (!m_pPlayer->containVideo() && (m_hMp4 == MP4_INVALID_FILE_HANDLE || m_ticker.elapsedTime() > recordSec * 1000)) {
|
||||
//在I帧率处新建MP4文件
|
||||
//如果文件未创建或者文件超过10分钟则创建新文件
|
||||
createFile();
|
||||
@@ -158,8 +160,10 @@ void Mp4Maker::createFile() {
|
||||
m_info.ui64StartedTime = ::time(NULL);
|
||||
m_info.strFileName = strTime + ".mp4";
|
||||
m_info.strFilePath = strFile;
|
||||
static string appName = mINI::Instance()[Config::Record::kAppName];
|
||||
m_info.strUrl = m_info.strVhost + "/"
|
||||
|
||||
GET_CONFIG_AND_REGISTER(string,appName,Config::Record::kAppName);
|
||||
|
||||
m_info.strUrl = m_info.strVhost + "/"
|
||||
+ appName + "/"
|
||||
+ m_info.strAppName + "/"
|
||||
+ m_info.strStreamId + "/"
|
||||
|
||||
Reference in New Issue
Block a user