From d017b7a212760a4b0eddcdf9fa8b3c91b820a8e4 Mon Sep 17 00:00:00 2001 From: qydysky Date: Sun, 4 Feb 2024 22:18:49 +0800 Subject: [PATCH] =?utf8?q?Improve=20=E8=B0=83=E6=95=B4=E8=8E=B7=E5=8F=96?= =?utf8?q?=E9=99=90=E5=88=B6?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Reply/stream.go | 25 +++++++++---------------- 1 file changed, 9 insertions(+), 16 deletions(-) diff --git a/Reply/stream.go b/Reply/stream.go index 6181de4..c079141 100644 --- a/Reply/stream.go +++ b/Reply/stream.go @@ -860,8 +860,9 @@ func (t *M4SStream) saveStreamM4s() (e error) { keyframe = slice.New[byte]() lastM4s *m4s_link_item to = 3 - waitT = 1.0 fmp4ListUpdateTo = 5.0 + fmp4Count = 0 + startT = time.Now() ) if v, ok := t.common.K_v.LoadV(`fmp4音视频时间戳容差s`).(float64); ok && v > 0.1 { @@ -877,16 +878,6 @@ func (t *M4SStream) saveStreamM4s() (e error) { // 下载循环 for download_seq := []*m4s_link_item{}; ; { - // 刷新流地址 - // if !flashingSer && int64(t.common.Live[0].Expires)-time.Now().Unix() < 60 { - // flashingSer = true - // t.log.L(`T: `, `刷新流地址...`) - // go func() { - // t.fetchCheckStream() - // flashingSer = false - // }() - // } - // 存在待下载切片 if len(download_seq) != 0 { var downingCount = 0 //本轮下载数量 @@ -1076,12 +1067,14 @@ func (t *M4SStream) saveStreamM4s() (e error) { } // 避免过于频繁的请求 - if len(m4s_links) < 2 { - waitT += 0.5 - } else if len(m4s_links) > 2 { - waitT -= 0.5 + fmp4Count += len(m4s_links) + if dru := time.Since(startT).Seconds(); dru > fmp4ListUpdateTo && fmp4Count == 0 { + e = fmt.Errorf("%.2f 秒未产出切片", dru) + t.log.L("E: ", "获取解析m3u8发生错误", e) + break + } else { + time.Sleep(time.Second * time.Duration(dru/float64(fmp4Count+1)+1)) } - time.Sleep(time.Second * time.Duration(waitT)) // 设置最后的切片 for i := len(m4s_links) - 1; i >= 0; i-- { -- 2.39.2