mirror of
https://github.com/home-assistant/core.git
synced 2025-07-25 14:17:45 +00:00
Log timestamp overflow in stream (#39844)
This commit is contained in:
parent
42ad36e9f8
commit
5658abfaca
@ -19,3 +19,4 @@ MAX_SEGMENTS = 3 # Max number of segments to keep around
|
|||||||
MIN_SEGMENT_DURATION = 1.5 # Each segment is at least this many seconds
|
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
|
PACKETS_TO_WAIT_FOR_AUDIO = 20 # Some streams have an audio stream with no audio
|
||||||
|
MAX_TIMESTAMP_GAP = 10000 # seconds - anything from 10 to 50000 is probably reasonable
|
||||||
|
@ -6,7 +6,7 @@ import time
|
|||||||
|
|
||||||
import av
|
import av
|
||||||
|
|
||||||
from .const import MIN_SEGMENT_DURATION, PACKETS_TO_WAIT_FOR_AUDIO
|
from .const import MAX_TIMESTAMP_GAP, MIN_SEGMENT_DURATION, PACKETS_TO_WAIT_FOR_AUDIO
|
||||||
from .core import Segment, StreamBuffer
|
from .core import Segment, StreamBuffer
|
||||||
|
|
||||||
_LOGGER = logging.getLogger(__name__)
|
_LOGGER = logging.getLogger(__name__)
|
||||||
@ -200,6 +200,12 @@ def _stream_worker_internal(hass, stream, quit_event):
|
|||||||
packet.stream = output_streams[audio_stream]
|
packet.stream = output_streams[audio_stream]
|
||||||
buffer.output.mux(packet)
|
buffer.output.mux(packet)
|
||||||
|
|
||||||
|
def finalize_stream():
|
||||||
|
if not stream.keepalive:
|
||||||
|
# End of stream, clear listeners and stop thread
|
||||||
|
for fmt, _ in outputs.items():
|
||||||
|
hass.loop.call_soon_threadsafe(stream.outputs[fmt].put, None)
|
||||||
|
|
||||||
if not peek_first_pts():
|
if not peek_first_pts():
|
||||||
container.close()
|
container.close()
|
||||||
return
|
return
|
||||||
@ -222,15 +228,26 @@ def _stream_worker_internal(hass, stream, quit_event):
|
|||||||
continue
|
continue
|
||||||
last_packet_was_without_dts = False
|
last_packet_was_without_dts = False
|
||||||
except (av.AVError, StopIteration) as ex:
|
except (av.AVError, StopIteration) as ex:
|
||||||
if not stream.keepalive:
|
|
||||||
# End of stream, clear listeners and stop thread
|
|
||||||
for fmt, _ in outputs.items():
|
|
||||||
hass.loop.call_soon_threadsafe(stream.outputs[fmt].put, None)
|
|
||||||
_LOGGER.error("Error demuxing stream: %s", str(ex))
|
_LOGGER.error("Error demuxing stream: %s", str(ex))
|
||||||
|
finalize_stream()
|
||||||
break
|
break
|
||||||
|
|
||||||
# Discard packet if dts is not monotonic
|
# Discard packet if dts is not monotonic
|
||||||
if packet.dts <= last_dts[packet.stream]:
|
if packet.dts <= last_dts[packet.stream]:
|
||||||
|
if (last_dts[packet.stream] - packet.dts) > (
|
||||||
|
packet.time_base * MAX_TIMESTAMP_GAP
|
||||||
|
):
|
||||||
|
_LOGGER.warning(
|
||||||
|
"Timestamp overflow detected: dts = %s, resetting stream",
|
||||||
|
packet.dts,
|
||||||
|
)
|
||||||
|
finalize_stream()
|
||||||
|
break
|
||||||
|
_LOGGER.warning(
|
||||||
|
"Dropping out of order packet: %s <= %s",
|
||||||
|
packet.dts,
|
||||||
|
last_dts[packet.stream],
|
||||||
|
)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
# Check for end of segment
|
# Check for end of segment
|
||||||
|
Loading…
x
Reference in New Issue
Block a user