mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-23 03:10:04 +08:00
解决hls iPhone无法播放的问题
This commit is contained in:
parent
412424b2bb
commit
f2e82fc2cc
@ -287,21 +287,11 @@ const char kFileBufSize[] = HLS_FIELD"fileBufSize";
|
|||||||
#define HLS_FILE_PATH (HTTP_ROOT_PATH)
|
#define HLS_FILE_PATH (HTTP_ROOT_PATH)
|
||||||
const char kFilePath[] = HLS_FIELD"filePath";
|
const char kFilePath[] = HLS_FIELD"filePath";
|
||||||
|
|
||||||
//HTTP访问url前缀
|
|
||||||
#define HTTP_PREFIX (StrPrinter << "http://${" << VHOST_KEY << "}:" << HTTP_PORT << endl)
|
|
||||||
const char kHttpPrefix[] = HLS_FIELD"httpPrefix";
|
|
||||||
|
|
||||||
#define HTTP_PREFIX_DEFAULT_VHOST (StrPrinter << "http://" << SockUtil::get_local_ip() << ":" << HTTP_PORT << endl)
|
|
||||||
const char kHttpPrefixDefaultVhost[] = HLS_FIELD"httpPrefixDefaultVhost";
|
|
||||||
|
|
||||||
onceToken token([](){
|
onceToken token([](){
|
||||||
mINI::Instance()[kSegmentDuration] = HLS_SEGMENT_DURATION;
|
mINI::Instance()[kSegmentDuration] = HLS_SEGMENT_DURATION;
|
||||||
mINI::Instance()[kSegmentNum] = HLS_SEGMENT_NUM;
|
mINI::Instance()[kSegmentNum] = HLS_SEGMENT_NUM;
|
||||||
mINI::Instance()[kFileBufSize] = HLS_FILE_BUF_SIZE;
|
mINI::Instance()[kFileBufSize] = HLS_FILE_BUF_SIZE;
|
||||||
mINI::Instance()[kFilePath] = HLS_FILE_PATH;
|
mINI::Instance()[kFilePath] = HLS_FILE_PATH;
|
||||||
mINI::Instance()[kHttpPrefix] = HTTP_PREFIX;
|
|
||||||
mINI::Instance()[kHttpPrefixDefaultVhost] = HTTP_PREFIX_DEFAULT_VHOST;
|
|
||||||
|
|
||||||
},nullptr);
|
},nullptr);
|
||||||
|
|
||||||
} //namespace Hls
|
} //namespace Hls
|
||||||
|
@ -232,10 +232,6 @@ extern const char kSegmentNum[];
|
|||||||
extern const char kFileBufSize[];
|
extern const char kFileBufSize[];
|
||||||
//录制文件路径
|
//录制文件路径
|
||||||
extern const char kFilePath[];
|
extern const char kFilePath[];
|
||||||
//HTTP访问url前缀
|
|
||||||
extern const char kHttpPrefix[];
|
|
||||||
//HTTP默认vhost访问url前缀
|
|
||||||
extern const char kHttpPrefixDefaultVhost[];
|
|
||||||
} //namespace Hls
|
} //namespace Hls
|
||||||
|
|
||||||
} // namespace Config
|
} // namespace Config
|
||||||
|
@ -33,8 +33,10 @@ using namespace ZL::Util;
|
|||||||
namespace ZL {
|
namespace ZL {
|
||||||
namespace MediaFile {
|
namespace MediaFile {
|
||||||
|
|
||||||
HLSMaker::HLSMaker(const string& strM3u8File, const string& strHttpUrl,
|
HLSMaker::HLSMaker(const string& strM3u8File,
|
||||||
uint32_t ui32BufSize, uint32_t ui32Duration, uint32_t ui32Num) {
|
uint32_t ui32BufSize,
|
||||||
|
uint32_t ui32Duration,
|
||||||
|
uint32_t ui32Num) {
|
||||||
if (ui32BufSize < 16 * 1024) {
|
if (ui32BufSize < 16 * 1024) {
|
||||||
ui32BufSize = 16 * 1024;
|
ui32BufSize = 16 * 1024;
|
||||||
}
|
}
|
||||||
@ -44,7 +46,6 @@ HLSMaker::HLSMaker(const string& strM3u8File, const string& strHttpUrl,
|
|||||||
m_ui32BufSize = ui32BufSize;
|
m_ui32BufSize = ui32BufSize;
|
||||||
m_ui64TsCnt = 0;
|
m_ui64TsCnt = 0;
|
||||||
m_strM3u8File = strM3u8File;
|
m_strM3u8File = strM3u8File;
|
||||||
m_strHttpUrl = strHttpUrl.substr(0, strHttpUrl.find_last_of('/') + 1);
|
|
||||||
m_ui32NumSegments = ui32Num;
|
m_ui32NumSegments = ui32Num;
|
||||||
m_ui32SegmentDuration = ui32Duration;
|
m_ui32SegmentDuration = ui32Duration;
|
||||||
|
|
||||||
@ -85,6 +86,7 @@ bool HLSMaker::write_index_file(int iFirstSegment, unsigned int uiLastSegment, i
|
|||||||
snprintf(acWriteBuf,
|
snprintf(acWriteBuf,
|
||||||
sizeof(acWriteBuf),
|
sizeof(acWriteBuf),
|
||||||
"#EXTM3U\n"
|
"#EXTM3U\n"
|
||||||
|
"#EXT-X-VERSION:3\n"
|
||||||
"#EXT-X-TARGETDURATION:%u\n"
|
"#EXT-X-TARGETDURATION:%u\n"
|
||||||
"#EXT-X-MEDIA-SEQUENCE:%u\n",
|
"#EXT-X-MEDIA-SEQUENCE:%u\n",
|
||||||
maxSegmentDuration,
|
maxSegmentDuration,
|
||||||
@ -93,6 +95,7 @@ bool HLSMaker::write_index_file(int iFirstSegment, unsigned int uiLastSegment, i
|
|||||||
snprintf(acWriteBuf,
|
snprintf(acWriteBuf,
|
||||||
sizeof(acWriteBuf),
|
sizeof(acWriteBuf),
|
||||||
"#EXTM3U\n"
|
"#EXTM3U\n"
|
||||||
|
"#EXT-X-VERSION:3\n"
|
||||||
"#EXT-X-TARGETDURATION:%u\n",
|
"#EXT-X-TARGETDURATION:%u\n",
|
||||||
maxSegmentDuration);
|
maxSegmentDuration);
|
||||||
}
|
}
|
||||||
@ -104,9 +107,8 @@ bool HLSMaker::write_index_file(int iFirstSegment, unsigned int uiLastSegment, i
|
|||||||
for (unsigned int i = iFirstSegment; i < uiLastSegment; i++) {
|
for (unsigned int i = iFirstSegment; i < uiLastSegment; i++) {
|
||||||
snprintf(acWriteBuf,
|
snprintf(acWriteBuf,
|
||||||
sizeof(acWriteBuf),
|
sizeof(acWriteBuf),
|
||||||
"#EXTINF:%.3f,\n%s%s-%u.ts\n",
|
"#EXTINF:%.3f,\n%s-%u.ts\n",
|
||||||
m_iDurations[i-iFirstSegment]/1000.0,
|
m_iDurations[i-iFirstSegment]/1000.0,
|
||||||
m_strHttpUrl.c_str(),
|
|
||||||
m_strFileName.c_str(),
|
m_strFileName.c_str(),
|
||||||
i);
|
i);
|
||||||
if (fwrite(acWriteBuf, strlen(acWriteBuf), 1, pM3u8File.get()) != 1) {
|
if (fwrite(acWriteBuf, strlen(acWriteBuf), 1, pM3u8File.get()) != 1) {
|
||||||
|
@ -43,7 +43,6 @@ namespace MediaFile {
|
|||||||
class HLSMaker {
|
class HLSMaker {
|
||||||
public:
|
public:
|
||||||
HLSMaker(const string &strM3u8File,
|
HLSMaker(const string &strM3u8File,
|
||||||
const string &strHttpUrl,
|
|
||||||
uint32_t ui32BufSize = 64 * 1024,
|
uint32_t ui32BufSize = 64 * 1024,
|
||||||
uint32_t ui32Duration = 5,
|
uint32_t ui32Duration = 5,
|
||||||
uint32_t ui32Num = 3);
|
uint32_t ui32Num = 3);
|
||||||
@ -63,7 +62,6 @@ public:
|
|||||||
private:
|
private:
|
||||||
TSMaker m_ts;
|
TSMaker m_ts;
|
||||||
string m_strM3u8File;
|
string m_strM3u8File;
|
||||||
string m_strHttpUrl;
|
|
||||||
string m_strFileName;
|
string m_strFileName;
|
||||||
string m_strOutputPrefix;
|
string m_strOutputPrefix;
|
||||||
uint32_t m_ui32SegmentDuration;
|
uint32_t m_ui32SegmentDuration;
|
||||||
|
@ -44,8 +44,6 @@ MediaRecorder::MediaRecorder(const string &strVhost_tmp,
|
|||||||
bool enableHls,
|
bool enableHls,
|
||||||
bool enableMp4) {
|
bool enableMp4) {
|
||||||
|
|
||||||
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(string,hlsPath,Config::Hls::kFilePath);
|
||||||
GET_CONFIG_AND_REGISTER(uint32_t,hlsBufSize,Config::Hls::kFileBufSize);
|
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,hlsDuration,Config::Hls::kSegmentDuration);
|
||||||
@ -58,40 +56,17 @@ MediaRecorder::MediaRecorder(const string &strVhost_tmp,
|
|||||||
}
|
}
|
||||||
|
|
||||||
if(enableHls) {
|
if(enableHls) {
|
||||||
string hlsPrefixVhost = hlsPrefix;
|
auto m3u8FilePath = hlsPath + "/" + strVhost + "/" + strApp + "/" + strId + "/hls.m3u8";
|
||||||
do {
|
m_hlsMaker.reset(new HLSMaker(m3u8FilePath,hlsBufSize, hlsDuration, hlsNum));
|
||||||
//生成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);
|
|
||||||
} else{
|
|
||||||
//不识别的环境变量
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}else{
|
|
||||||
//没有更多环境变量了
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
} while (true);
|
|
||||||
m_hlsMaker.reset(new HLSMaker(hlsPath + "/" + strVhost + "/" + strApp + "/" + strId + "/hls.m3u8",
|
|
||||||
hlsPrefixVhost + "/" + strApp + "/" + strId + "/",
|
|
||||||
hlsBufSize, hlsDuration, hlsNum));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifdef ENABLE_MP4V2
|
#ifdef ENABLE_MP4V2
|
||||||
GET_CONFIG_AND_REGISTER(string,recordPath,Config::Record::kFilePath);
|
GET_CONFIG_AND_REGISTER(string,recordPath,Config::Record::kFilePath);
|
||||||
GET_CONFIG_AND_REGISTER(string,recordAppName,Config::Record::kAppName);
|
GET_CONFIG_AND_REGISTER(string,recordAppName,Config::Record::kAppName);
|
||||||
|
|
||||||
if(enableMp4){
|
if(enableMp4){
|
||||||
m_mp4Maker.reset(new Mp4Maker(recordPath + "/" + strVhost + "/" + recordAppName + "/" + strApp + "/" + strId + "/",
|
auto mp4FilePath = recordPath + "/" + strVhost + "/" + recordAppName + "/" + strApp + "/" + strId + "/";
|
||||||
strVhost,strApp,strId,pPlayer));
|
m_mp4Maker.reset(new Mp4Maker(mp4FilePath,strVhost,strApp,strId,pPlayer));
|
||||||
}
|
}
|
||||||
#endif //ENABLE_MP4V2
|
#endif //ENABLE_MP4V2
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user