From acde33dbbc82a8cedfa4bd3d5c077dc595e16b2f Mon Sep 17 00:00:00 2001 From: uvjustin <46082645+uvjustin@users.noreply.github.com> Date: Thu, 11 Feb 2021 04:51:16 +0800 Subject: [PATCH] Keep 1 extra segment around after playlist removal (#46310) * Keep 1 extra segment around after playlist removal * Remove segments length check --- homeassistant/components/stream/const.py | 3 ++- homeassistant/components/stream/hls.py | 4 ++-- 2 files changed, 4 insertions(+), 3 deletions(-) diff --git a/homeassistant/components/stream/const.py b/homeassistant/components/stream/const.py index 4ee9f2a9814..41df806d020 100644 --- a/homeassistant/components/stream/const.py +++ b/homeassistant/components/stream/const.py @@ -10,7 +10,8 @@ FORMAT_CONTENT_TYPE = {"hls": "application/vnd.apple.mpegurl"} OUTPUT_IDLE_TIMEOUT = 300 # Idle timeout due to inactivity -MAX_SEGMENTS = 3 # Max number of segments to keep around +NUM_PLAYLIST_SEGMENTS = 3 # Number of segments to use in HLS playlist +MAX_SEGMENTS = 4 # Max number of segments to keep around MIN_SEGMENT_DURATION = 1.5 # Each segment is at least this many seconds PACKETS_TO_WAIT_FOR_AUDIO = 20 # Some streams have an audio stream with no audio diff --git a/homeassistant/components/stream/hls.py b/homeassistant/components/stream/hls.py index 2b305442b80..bd5fbd5e9ae 100644 --- a/homeassistant/components/stream/hls.py +++ b/homeassistant/components/stream/hls.py @@ -6,7 +6,7 @@ from aiohttp import web from homeassistant.core import callback -from .const import FORMAT_CONTENT_TYPE +from .const import FORMAT_CONTENT_TYPE, NUM_PLAYLIST_SEGMENTS from .core import PROVIDERS, StreamOutput, StreamView from .fmp4utils import get_codec_string, get_init, get_m4s @@ -77,7 +77,7 @@ class HlsPlaylistView(StreamView): @staticmethod def render_playlist(track): """Render playlist.""" - segments = track.segments + segments = track.segments[-NUM_PLAYLIST_SEGMENTS:] if not segments: return []