mirror of
https://github.com/ZLMediaKit/ZLMediaKit.git
synced 2024-11-22 10:40:05 +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;
|
||||
}
|
||||
|
||||
}//namespace mediakit
|
||||
float HlsParser::getTotalDuration() const {
|
||||
return _total_dur;
|
||||
}
|
||||
}//namespace mediakit
|
||||
|
@ -74,7 +74,12 @@ public:
|
||||
* 内部是否含有子m3u8
|
||||
*/
|
||||
bool isM3u8Inner() const;
|
||||
|
||||
/**
|
||||
* 得到总时间
|
||||
* @return
|
||||
*/
|
||||
float getTotalDuration() const;
|
||||
|
||||
protected:
|
||||
//解析出ts文件地址回调
|
||||
virtual void onParsed(bool is_m3u8_inner,int64_t sequence,const map<int,ts_segment> &ts_list) {};
|
||||
|
@ -184,9 +184,25 @@ void HlsPlayer::onResponseCompleted() {
|
||||
}
|
||||
}
|
||||
|
||||
float HlsPlayer::delaySecond(){
|
||||
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;
|
||||
}
|
||||
@ -391,4 +407,4 @@ vector<Track::Ptr> HlsPlayerImp::getTracks(bool ready) const {
|
||||
return static_pointer_cast<HlsDemuxer>(_demuxer)->getTracks(ready);
|
||||
}
|
||||
|
||||
}//namespace mediakit
|
||||
}//namespace mediakit
|
||||
|
Loading…
Reference in New Issue
Block a user