mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-25 20:27:34 +08:00
拉去hls索引文件时, 不能仅仅只是按照m3u8文件中的分段时间来拉取, 这样在网络延迟的情况下很容易出现问题, 根据规范与ffmpeg中的实现修改如下
This commit is contained in:
parent
120879df0f
commit
0c1159959c
@ -137,4 +137,7 @@ bool HlsParser::isM3u8Inner() const {
|
||||
return _is_m3u8_inner;
|
||||
}
|
||||
|
||||
float HlsParser::getTotalDuration() const {
|
||||
return _total_dur;
|
||||
}
|
||||
}//namespace mediakit
|
@ -74,6 +74,11 @@ public:
|
||||
* 内部是否含有子m3u8
|
||||
*/
|
||||
bool isM3u8Inner() const;
|
||||
/**
|
||||
* 得到总时间
|
||||
* @return
|
||||
*/
|
||||
float getTotalDuration() const;
|
||||
|
||||
protected:
|
||||
//解析出ts文件地址回调
|
||||
|
@ -186,7 +186,23 @@ void HlsPlayer::onResponseCompleted() {
|
||||
|
||||
float HlsPlayer::delaySecond() {
|
||||
if (HlsParser::isM3u8() && HlsParser::getTargetDur() > 0) {
|
||||
return (float)HlsParser::getTargetDur();
|
||||
float targetOffset;
|
||||
if (HlsParser::isLive()) {
|
||||
// see RFC 8216, Section 4.4.3.8.
|
||||
// 根据rfc刷新index列表的周期应该是分段时间x3, 因为根据规范播放器只处理最后3个Segment
|
||||
targetOffset = (float) (3 * HlsParser::getTargetDur());
|
||||
} else {
|
||||
// 点播则一般m3u8文件不会在改变了, 没必要频繁的刷新, 所以按照总时间来进行刷新
|
||||
targetOffset = HlsParser::getTotalDuration();
|
||||
}
|
||||
// 取最小值, 避免因为分段时长不规则而导致的问题
|
||||
if (targetOffset > HlsParser::getTotalDuration()) {
|
||||
targetOffset = HlsParser::getTotalDuration();
|
||||
}
|
||||
// 根据规范为一半的时间
|
||||
if(targetOffset / 2 > 1.0f) {
|
||||
return targetOffset / 2;
|
||||
}
|
||||
}
|
||||
return 1.0f;
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user