Add discontinuity support to HLS streams and fix nest expiring stream urls (#46683)

* Support HLS stream discontinuity.

* Clarify discontinuity comments

* Signal a stream discontinuity on restart due to stream error

* Apply suggestions from code review

Co-authored-by: uvjustin <46082645+uvjustin@users.noreply.github.com>

* Simplify stream discontinuity logic
This commit is contained in:
Allen Porter 2021-02-18 04:26:02 -08:00 committed by GitHub
parent 62cfe24ed4
commit 88d143a644
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
6 changed files with 132 additions and 29 deletions

View file

@ -27,7 +27,7 @@ from homeassistant.components.stream.const import (
MIN_SEGMENT_DURATION,
PACKETS_TO_WAIT_FOR_AUDIO,
)
from homeassistant.components.stream.worker import stream_worker
from homeassistant.components.stream.worker import SegmentBuffer, stream_worker
STREAM_SOURCE = "some-stream-source"
# Formats here are arbitrary, not exercised by tests
@ -197,7 +197,8 @@ async def async_decode_stream(hass, packets, py_av=None):
"homeassistant.components.stream.core.StreamOutput.put",
side_effect=py_av.capture_buffer.capture_output_segment,
):
stream_worker(STREAM_SOURCE, {}, stream.outputs, threading.Event())
segment_buffer = SegmentBuffer(stream.outputs)
stream_worker(STREAM_SOURCE, {}, segment_buffer, threading.Event())
await hass.async_block_till_done()
return py_av.capture_buffer
@ -209,7 +210,8 @@ async def test_stream_open_fails(hass):
stream.hls_output()
with patch("av.open") as av_open:
av_open.side_effect = av.error.InvalidDataError(-2, "error")
stream_worker(STREAM_SOURCE, {}, stream.outputs, threading.Event())
segment_buffer = SegmentBuffer(stream.outputs)
stream_worker(STREAM_SOURCE, {}, segment_buffer, threading.Event())
await hass.async_block_till_done()
av_open.assert_called_once()