修复HLS按需生成相关bug
This commit is contained in:
parent
3b5053af50
commit
1b9550cfc4
|
|
@ -557,6 +557,10 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo
|
||||||
}
|
}
|
||||||
//hls文件不存在,我们等待其生成并延后回复
|
//hls文件不存在,我们等待其生成并延后回复
|
||||||
MediaSource::findAsync(mediaInfo, strongSession, [response_file, cookie, cb, strFile, parser](const MediaSource::Ptr &src) {
|
MediaSource::findAsync(mediaInfo, strongSession, [response_file, cookie, cb, strFile, parser](const MediaSource::Ptr &src) {
|
||||||
|
if(cookie){
|
||||||
|
//尝试添加HlsMediaSource的观看人数
|
||||||
|
(*cookie)[kCookieName].get<HttpCookieAttachment>()._hls_data->addByteUsage(0);
|
||||||
|
}
|
||||||
if (src && File::is_file(strFile.data())) {
|
if (src && File::is_file(strFile.data())) {
|
||||||
//流和m3u8文件都存在,那么直接返回文件
|
//流和m3u8文件都存在,那么直接返回文件
|
||||||
response_file(cookie, cb, strFile, parser);
|
response_file(cookie, cb, strFile, parser);
|
||||||
|
|
@ -570,7 +574,7 @@ static void accessFile(TcpSession &sender, const Parser &parser, const MediaInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
//流存在,但是m3u8文件不存在,那么等待生成m3u8文件
|
//流存在,但是m3u8文件不存在,那么等待生成m3u8文件
|
||||||
hls->waitForHls([response_file, cookie, cb, strFile, parser]() {
|
hls->waitForFile([response_file, cookie, cb, strFile, parser]() {
|
||||||
response_file(cookie, cb, strFile, parser);
|
response_file(cookie, cb, strFile, parser);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
|
||||||
|
|
@ -89,7 +89,7 @@ void HlsMakerImp::onWriteHls(const char *data, int len) {
|
||||||
fwrite(data, len, 1, hls.get());
|
fwrite(data, len, 1, hls.get());
|
||||||
hls.reset();
|
hls.reset();
|
||||||
if (_media_src) {
|
if (_media_src) {
|
||||||
_media_src->registHls();
|
_media_src->registHls(true);
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
WarnL << "create hls file failed," << _path_hls << " " << get_uv_errmsg();
|
WarnL << "create hls file failed," << _path_hls << " " << get_uv_errmsg();
|
||||||
|
|
|
||||||
|
|
@ -45,14 +45,19 @@ public:
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 生成m3u8文件时触发
|
* 生成m3u8文件时触发
|
||||||
|
* @param file_created 是否产生了hls文件
|
||||||
*/
|
*/
|
||||||
void registHls(){
|
void registHls(bool file_created){
|
||||||
if (!_is_regist) {
|
if (!_is_regist) {
|
||||||
_is_regist = true;
|
_is_regist = true;
|
||||||
onReaderChanged(0);
|
onReaderChanged(0);
|
||||||
regist();
|
regist();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (!file_created) {
|
||||||
|
//没产生文件
|
||||||
|
return;
|
||||||
|
}
|
||||||
//m3u8文件生成,发送给播放器
|
//m3u8文件生成,发送给播放器
|
||||||
decltype(_list_cb) copy;
|
decltype(_list_cb) copy;
|
||||||
{
|
{
|
||||||
|
|
@ -64,7 +69,7 @@ public:
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
void waitForHls(function<void()> cb){
|
void waitForFile(function<void()> cb){
|
||||||
//等待生成m3u8文件
|
//等待生成m3u8文件
|
||||||
lock_guard<mutex> lck(_mtx_cb);
|
lock_guard<mutex> lck(_mtx_cb);
|
||||||
_list_cb.emplace_back(std::move(cb));
|
_list_cb.emplace_back(std::move(cb));
|
||||||
|
|
|
||||||
|
|
@ -37,7 +37,7 @@ public:
|
||||||
_listener = listener;
|
_listener = listener;
|
||||||
_hls->getMediaSource()->setListener(shared_from_this());
|
_hls->getMediaSource()->setListener(shared_from_this());
|
||||||
//先注册媒体流,后续可以按需生成
|
//先注册媒体流,后续可以按需生成
|
||||||
_hls->getMediaSource()->registHls();
|
_hls->getMediaSource()->registHls(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
int readerCount() {
|
int readerCount() {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue