Skip to content

Commit

Permalink
Stream fixes (#22238)
Browse files Browse the repository at this point in the history
* fix issues with out of order packets, and empty first packet on some IP camera models

* do not skip the first packet
  • Loading branch information
hunterjm authored and balloob committed Mar 21, 2019
1 parent 0f73031 commit 56cbe8a
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions homeassistant/components/stream/worker.py
Expand Up @@ -63,21 +63,29 @@ def stream_worker(hass, stream, quit_event):
first_packet = True
sequence = 1
audio_packets = {}
last_dts = None

while not quit_event.is_set():
try:
packet = next(container.demux(video_stream))
if packet.dts is None:
if first_packet:
continue
# If we get a "flushing" packet, the stream is done
raise StopIteration
raise StopIteration("No dts in packet")
except (av.AVError, StopIteration) as ex:
# 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", ex)
_LOGGER.error("Error demuxing stream: %s", str(ex))
break

# Skip non monotonically increasing dts in feed
if not first_packet and last_dts >= packet.dts:
continue
last_dts = packet.dts

# Reset segment on every keyframe
if packet.is_keyframe:
# Save segment to outputs
Expand Down

0 comments on commit 56cbe8a

Please sign in to comment.