Fix possible soft-lock in HLS if Queue is left empty after error

This commit is contained in:
rlaphoenix 2023-03-04 11:11:20 +00:00
parent 7df6aa42b4
commit c3a22431f0
1 changed files with 41 additions and 37 deletions

View File

@ -222,6 +222,7 @@ class HLS:
segment_save_path = (save_dir / filename).with_suffix(".mp4") segment_save_path = (save_dir / filename).with_suffix(".mp4")
newest_segment_key = segment_key.get() newest_segment_key = segment_key.get()
try:
if segment.key and newest_segment_key[1] != segment.key: if segment.key and newest_segment_key[1] != segment.key:
try: try:
drm = HLS.get_drm( drm = HLS.get_drm(
@ -246,12 +247,14 @@ class HLS:
raise ValueError("license_widevine func must be supplied to use Widevine DRM") raise ValueError("license_widevine func must be supplied to use Widevine DRM")
license_widevine(drm) license_widevine(drm)
newest_segment_key = (drm, segment.key) newest_segment_key = (drm, segment.key)
finally:
segment_key.put(newest_segment_key) segment_key.put(newest_segment_key)
if callable(track.OnSegmentFilter) and track.OnSegmentFilter(segment): if callable(track.OnSegmentFilter) and track.OnSegmentFilter(segment):
return 0 return 0
newest_init_data = init_data.get() newest_init_data = init_data.get()
try:
if segment.init_section and (not newest_init_data or segment.discontinuity): if segment.init_section and (not newest_init_data or segment.discontinuity):
# Only use the init data if there's no init data yet (e.g., start of file) # Only use the init data if there's no init data yet (e.g., start of file)
# or if EXT-X-DISCONTINUITY is reached at the same time as EXT-X-MAP. # or if EXT-X-DISCONTINUITY is reached at the same time as EXT-X-MAP.
@ -264,6 +267,7 @@ class HLS:
res = session.get(segment.init_section.uri) res = session.get(segment.init_section.uri)
res.raise_for_status() res.raise_for_status()
newest_init_data = res.content newest_init_data = res.content
finally:
init_data.put(newest_init_data) init_data.put(newest_init_data)
if not segment.uri.startswith(segment.base_uri): if not segment.uri.startswith(segment.base_uri):