mirror of
https://github.com/home-assistant/core.git
synced 2025-07-17 18:27:09 +00:00
Allow only one packet with no dts in stream init (#41129)
* Allow only one packet with no dts in stream init * Call finalize_stream() on exit
This commit is contained in:
parent
c7bbba9d48
commit
6c18feb4ed
@ -103,6 +103,7 @@ def _stream_worker_internal(hass, stream, quit_event):
|
|||||||
|
|
||||||
def peek_first_pts():
|
def peek_first_pts():
|
||||||
nonlocal first_pts, audio_stream
|
nonlocal first_pts, audio_stream
|
||||||
|
missing_dts = False
|
||||||
|
|
||||||
def empty_stream_dict():
|
def empty_stream_dict():
|
||||||
return {
|
return {
|
||||||
@ -117,10 +118,13 @@ def _stream_worker_internal(hass, stream, quit_event):
|
|||||||
while first_packet[video_stream] is None:
|
while first_packet[video_stream] is None:
|
||||||
packet = next(container.demux())
|
packet = next(container.demux())
|
||||||
if (
|
if (
|
||||||
packet.stream == video_stream
|
packet.dts is None
|
||||||
and packet.is_keyframe
|
): # Allow single packet with no dts, raise error on second
|
||||||
and packet.dts is not None
|
if missing_dts:
|
||||||
):
|
raise av.AVError
|
||||||
|
missing_dts = True
|
||||||
|
continue
|
||||||
|
if packet.stream == video_stream and packet.is_keyframe:
|
||||||
first_packet[video_stream] = packet
|
first_packet[video_stream] = packet
|
||||||
initial_packets.append(packet)
|
initial_packets.append(packet)
|
||||||
# Get first_pts from subsequent frame to first keyframe
|
# Get first_pts from subsequent frame to first keyframe
|
||||||
@ -128,8 +132,13 @@ def _stream_worker_internal(hass, stream, quit_event):
|
|||||||
[pts is None for pts in {**first_packet, **first_pts}.values()]
|
[pts is None for pts in {**first_packet, **first_pts}.values()]
|
||||||
) and (len(initial_packets) < PACKETS_TO_WAIT_FOR_AUDIO):
|
) and (len(initial_packets) < PACKETS_TO_WAIT_FOR_AUDIO):
|
||||||
packet = next(container.demux((video_stream, audio_stream)))
|
packet = next(container.demux((video_stream, audio_stream)))
|
||||||
if packet.dts is None:
|
if (
|
||||||
continue # Discard packets with no dts
|
packet.dts is None
|
||||||
|
): # Allow single packet with no dts, raise error on second
|
||||||
|
if missing_dts:
|
||||||
|
raise av.AVError
|
||||||
|
missing_dts = True
|
||||||
|
continue
|
||||||
if (
|
if (
|
||||||
first_packet[packet.stream] is None
|
first_packet[packet.stream] is None
|
||||||
): # actually video already found above so only for audio
|
): # actually video already found above so only for audio
|
||||||
@ -158,6 +167,7 @@ def _stream_worker_internal(hass, stream, quit_event):
|
|||||||
_LOGGER.error(
|
_LOGGER.error(
|
||||||
"Error demuxing stream while finding first packet: %s", str(ex)
|
"Error demuxing stream while finding first packet: %s", str(ex)
|
||||||
)
|
)
|
||||||
|
finalize_stream()
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
||||||
@ -203,7 +213,7 @@ def _stream_worker_internal(hass, stream, quit_event):
|
|||||||
def finalize_stream():
|
def finalize_stream():
|
||||||
if not stream.keepalive:
|
if not stream.keepalive:
|
||||||
# End of stream, clear listeners and stop thread
|
# End of stream, clear listeners and stop thread
|
||||||
for fmt, _ in outputs.items():
|
for fmt in stream.outputs.keys():
|
||||||
hass.loop.call_soon_threadsafe(stream.outputs[fmt].put, None)
|
hass.loop.call_soon_threadsafe(stream.outputs[fmt].put, None)
|
||||||
|
|
||||||
if not peek_first_pts():
|
if not peek_first_pts():
|
||||||
|
Loading…
x
Reference in New Issue
Block a user