寻找下一分片等待时间做细分
This commit is contained in:
@@ -194,12 +194,18 @@ class HLSFrameProcessor(threading.Thread):
|
||||
# 处理初始分片
|
||||
self.process_segment_with_rate_control(initial_segment)
|
||||
|
||||
# 连续检测失败计数器
|
||||
consecutive_failures = 0
|
||||
|
||||
while not self.stop_event.is_set():
|
||||
try:
|
||||
# 查找下一个分片
|
||||
next_segment = self.find_next_segment()
|
||||
|
||||
if next_segment is not None:
|
||||
# 重置连续失败计数器
|
||||
consecutive_failures = 0
|
||||
|
||||
# 处理下一个分片
|
||||
logger.info(f"[INFO] Starting to process TS segment: {next_segment}")
|
||||
self.current_segment_num += 1
|
||||
@@ -208,9 +214,18 @@ class HLSFrameProcessor(threading.Thread):
|
||||
|
||||
logger.info(f"[INFO] Finished processing segment {self.current_segment_num}")
|
||||
else:
|
||||
# 下一个分片不存在,等待
|
||||
logger.warning(f"[WARN] No next segment found, waiting...")
|
||||
time.sleep(0.5)
|
||||
# 下一个分片不存在,根据连续失败次数调整等待时间
|
||||
consecutive_failures += 1
|
||||
|
||||
if consecutive_failures <= 10:
|
||||
sleep_time = 0.02 # 前10次失败,等待0.02秒
|
||||
elif consecutive_failures <= 20:
|
||||
sleep_time = 0.05 # 继续5次失败,等待0.05秒
|
||||
else:
|
||||
sleep_time = 0.5 # 超过15次失败,等待0.5秒
|
||||
|
||||
logger.warning(f"[WARN] No next segment found (failures: {consecutive_failures}), waiting {sleep_time}s...")
|
||||
time.sleep(sleep_time)
|
||||
|
||||
except Exception as e:
|
||||
logger.error(f"[ERROR] HLSFrameProcessor loop error: {e}")
|
||||
|
||||
Reference in New Issue
Block a user