mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2026-06-16 04:55:58 +08:00
修改文件录制、hls生成、拉流代理逻辑
This commit is contained in:
@@ -129,7 +129,7 @@ MediaReader::MediaReader(const string &strVhost,const string &strApp, const stri
|
||||
}
|
||||
|
||||
m_iDuration = MAX(m_video_ms,m_audio_ms);
|
||||
m_pChn.reset(new DevChannel(strVhost.data(),strApp.data(),strId.data(),m_iDuration/1000.0,false));
|
||||
m_pChn.reset(new DevChannel(strVhost.data(),strApp.data(),strId.data(),m_iDuration/1000.0,true, false));
|
||||
if (m_audio_trId != MP4_INVALID_TRACK_ID) {
|
||||
AudioInfo info;
|
||||
info.iChannel = m_audio_num_channels;
|
||||
|
||||
@@ -37,7 +37,13 @@ using namespace ZL::Network;
|
||||
namespace ZL {
|
||||
namespace MediaFile {
|
||||
|
||||
MediaRecorder::MediaRecorder(const string &strVhost ,const string &strApp,const string &strId,const std::shared_ptr<PlayerBase> &pPlayer) {
|
||||
MediaRecorder::MediaRecorder(const string &strVhost_tmp,
|
||||
const string &strApp,
|
||||
const string &strId,
|
||||
const std::shared_ptr<PlayerBase> &pPlayer,
|
||||
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];
|
||||
@@ -45,31 +51,41 @@ MediaRecorder::MediaRecorder(const string &strVhost ,const string &strApp,const
|
||||
static uint32_t hlsDuration = mINI::Instance()[Config::Hls::kSegmentDuration].as<uint32_t>();
|
||||
static uint32_t hlsNum = mINI::Instance()[Config::Hls::kSegmentNum].as<uint32_t>();
|
||||
|
||||
string hlsPrefixVhost = hlsPrefix;
|
||||
do{
|
||||
//生成hls http前缀
|
||||
if (strVhost.empty() || strVhost == DEFAULT_VHOST) {
|
||||
hlsPrefixVhost = hlsPrefixDefaultVhost;
|
||||
break;
|
||||
}
|
||||
auto pos_start = hlsPrefixVhost.find("${");
|
||||
auto pos_end = hlsPrefixVhost.find("}");
|
||||
if (pos_start != string::npos && pos_end != string::npos && pos_end - pos_start - 2 > 0 ) {
|
||||
auto key = hlsPrefixVhost.substr(pos_start + 2, pos_end - pos_start - 2);
|
||||
trim(key);
|
||||
if (key == VHOST_KEY) {
|
||||
hlsPrefixVhost.replace(pos_start, pos_end - pos_start + 1, strVhost);
|
||||
}
|
||||
}
|
||||
}while(0);
|
||||
m_hlsMaker.reset(new HLSMaker(hlsPath + "/" + strVhost + "/" + strApp + "/" + strId + "/hls.m3u8",
|
||||
hlsPrefixVhost + "/" + strApp + "/" + strId + "/",
|
||||
hlsBufSize,hlsDuration,hlsNum));
|
||||
string strVhost = strVhost_tmp;
|
||||
if(trim(strVhost).empty()){
|
||||
//如果strVhost为空,则强制为默认虚拟主机
|
||||
strVhost = DEFAULT_VHOST;
|
||||
}
|
||||
|
||||
if(enableHls) {
|
||||
string hlsPrefixVhost = hlsPrefix;
|
||||
do {
|
||||
//生成hls http前缀
|
||||
if (strVhost == DEFAULT_VHOST) {
|
||||
hlsPrefixVhost = hlsPrefixDefaultVhost;
|
||||
break;
|
||||
}
|
||||
auto pos_start = hlsPrefixVhost.find("${");
|
||||
auto pos_end = hlsPrefixVhost.find("}");
|
||||
if (pos_start != string::npos && pos_end != string::npos && pos_end - pos_start - 2 > 0) {
|
||||
auto key = hlsPrefixVhost.substr(pos_start + 2, pos_end - pos_start - 2);
|
||||
trim(key);
|
||||
if (key == VHOST_KEY) {
|
||||
hlsPrefixVhost.replace(pos_start, pos_end - pos_start + 1, strVhost);
|
||||
}
|
||||
}
|
||||
} while (0);
|
||||
m_hlsMaker.reset(new HLSMaker(hlsPath + "/" + strVhost + "/" + strApp + "/" + strId + "/hls.m3u8",
|
||||
hlsPrefixVhost + "/" + strApp + "/" + strId + "/",
|
||||
hlsBufSize, hlsDuration, hlsNum));
|
||||
}
|
||||
#ifdef ENABLE_MP4V2
|
||||
static string recordPath = mINI::Instance()[Config::Record::kFilePath];
|
||||
static string recordAppName = mINI::Instance()[Config::Record::kAppName];
|
||||
m_mp4Maker.reset(new Mp4Maker(recordPath + "/" + strVhost + "/" + recordAppName + "/" + strApp + "/" + strId + "/",
|
||||
strVhost,strApp,strId,pPlayer));
|
||||
if(enableMp4){
|
||||
m_mp4Maker.reset(new Mp4Maker(recordPath + "/" + strVhost + "/" + recordAppName + "/" + strApp + "/" + strId + "/",
|
||||
strVhost,strApp,strId,pPlayer));
|
||||
}
|
||||
#endif //ENABLE_MP4V2
|
||||
}
|
||||
|
||||
@@ -77,16 +93,24 @@ MediaRecorder::~MediaRecorder() {
|
||||
}
|
||||
|
||||
void MediaRecorder::inputH264(void* pData, uint32_t ui32Length, uint32_t ui32TimeStamp, int iType) {
|
||||
m_hlsMaker->inputH264(pData, ui32Length, ui32TimeStamp * 90, iType);
|
||||
if(m_hlsMaker){
|
||||
m_hlsMaker->inputH264(pData, ui32Length, ui32TimeStamp * 90, iType);
|
||||
}
|
||||
#ifdef ENABLE_MP4V2
|
||||
m_mp4Maker->inputH264(pData, ui32Length, ui32TimeStamp, iType);
|
||||
if(m_mp4Maker){
|
||||
m_mp4Maker->inputH264(pData, ui32Length, ui32TimeStamp, iType);
|
||||
}
|
||||
#endif //ENABLE_MP4V2
|
||||
}
|
||||
|
||||
void MediaRecorder::inputAAC(void* pData, uint32_t ui32Length, uint32_t ui32TimeStamp) {
|
||||
m_hlsMaker->inputAAC(pData, ui32Length, ui32TimeStamp * 90);
|
||||
if(m_hlsMaker){
|
||||
m_hlsMaker->inputAAC(pData, ui32Length, ui32TimeStamp * 90);
|
||||
}
|
||||
#ifdef ENABLE_MP4V2
|
||||
m_mp4Maker->inputAAC(pData, ui32Length, ui32TimeStamp);
|
||||
if(m_mp4Maker){
|
||||
m_mp4Maker->inputAAC(pData, ui32Length, ui32TimeStamp);
|
||||
}
|
||||
#endif //ENABLE_MP4V2
|
||||
}
|
||||
|
||||
|
||||
@@ -46,7 +46,12 @@ namespace MediaFile {
|
||||
class MediaRecorder {
|
||||
public:
|
||||
typedef std::shared_ptr<MediaRecorder> Ptr;
|
||||
MediaRecorder(const string &strVhost,const string &strApp,const string &strId,const std::shared_ptr<PlayerBase> &pPlayer);
|
||||
MediaRecorder(const string &strVhost,
|
||||
const string &strApp,
|
||||
const string &strId,
|
||||
const std::shared_ptr<PlayerBase> &pPlayer,
|
||||
bool m_enableHls = true,
|
||||
bool m_enableMp4 = false);
|
||||
virtual ~MediaRecorder();
|
||||
|
||||
void inputH264( void *pData,
|
||||
|
||||
Reference in New Issue
Block a user