* Use defaultdict for TimestampValidator._last_dts
* Combine filters
* Allow PeekIterator to be updated while preserving buffer
* Fix peek edge case
* Readd is_valid filter to video only iterator
* Reset dts validator when container is reset
* Reuse existing dts_validator when disabling audio stream
* Refactor peek logic at the start of a stream
Add a PeekingIterator to support rewinding an iterator so that the code
for adjusting audio streams and start pts can be inlined in the worker.
* Simplification and readability improvements
* Remove unnecessary verbiage from comments and pydoc
* Address pylint errors
* Remove rewind function and just mux the first packet separately
* More cleanup after removing rewind()
* Skip check to self._buffer on every iteration
* Refactor dts validation logic into a separate function
Create a decompression timestamp validation function to move the logic out of
the worker into a separate class. This also uses the python itertools.chain
to chain together the initial packets with the remaining packets in the
container iterator, removing additional inline if statements.
* Reset dts validator when container is reset
* Fix typo in a comment
* Reuse existing dts_validator when disabling audio stream
* Enable gzip encoding for playlist responses
* Add EXT-X-PROGRAM-DATE-TIME to playlist
* Add EXT-X-START to playlist
* Change EXT-X-VERSION from 7 to 6
* Move idle timer call to recv
* Refactor recv to remove cursor and return bool
* Rename STREAM_TIMEOUT to SOURCE_TIMEOUT
* Combine StreamBuffer into SegmentBuffer in stream
* Use new style type hint in comment
Remove unused member self._segment
* Change reset_av to static helper function
* Change make_new_av to only return OutputContainer
* Remove login details before logging stream source
* Convert to str before re
* Use compiled RE
* Add tests and filter log message in worker
* Update import
Co-authored-by: Erik Montnemery <erik@montnemery.com>
* isort
Co-authored-by: Erik Montnemery <erik@montnemery.com>
* Handle stream failures in recorder
Fail gracefully with an error message when the recorder is invoked with no segments due to a stream failure.
* Update homeassistant/components/stream/recorder.py
Co-authored-by: uvjustin <46082645+uvjustin@users.noreply.github.com>
Co-authored-by: uvjustin <46082645+uvjustin@users.noreply.github.com>
* Improve handling for start of nest cam stream
Add negative_cts_offsets to segment container options in order to better handle recording at the start of a stream. Nest streams start off with a negative offset, and if the segment container does not support it, then it adjusts the timestamps making it out of order with the next segment as described in issue #46968
* Update homeassistant/components/stream/__init__.py
Co-authored-by: uvjustin <46082645+uvjustin@users.noreply.github.com>
Co-authored-by: uvjustin <46082645+uvjustin@users.noreply.github.com>
* Add discontinuity support to stream recorder
* Use same container options for both StreamOutputs
* Fix pts adjuster
* Remove redundant/incorrect duplicate hls segment check
* Use same StreamBuffer across outputs
* Remove keepalive check for recorder
* Set output video timescale explicitly
* Disable avoid_negative_ts
* 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
* Fix exception in stream idle callback
Fix bug where idle timeout callback fails if the stream previously exited.
* Add a test for stream idle timeout after stream is stopped.
* Add clarifying comment to idle timer clear method
* Clear hls timer only on stop
Separate the HLS stream view logic out of StreamOutput since the hls
stream view is about to get more complex to track discontinuities. This
makes the idle timeout, shutdown, and coupling between hls and record
more explicit.
* Remove stream_worker dependencies on Stream
Removee stream_worker dependencies on Stream and split out the logic
for writing segments to a stream buffer.
* Stop calling internal stream methods
* Update homeassistant/components/stream/worker.py
Co-authored-by: uvjustin <46082645+uvjustin@users.noreply.github.com>
* Reuse self._outputs when creating new streams
Co-authored-by: uvjustin <46082645+uvjustin@users.noreply.github.com>
* Change the API boundary between stream and camera
Shift more of the stream lifecycle management to the camera. The motivation is to support stream urls that expire
giving the camera the ability to change the stream once it is created.
* Document stream lifecycle and simplify stream/camera interaction
* Reorder create_stream function to reduce diffs
* Increase test coverage for camera_sdm.py
* Fix ffmpeg typo.
* Add a stream identifier for each stream, managed by camera
* Remove stream record service
* Update homeassistant/components/stream/__init__.py
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
* Unroll changes to Stream interface back into camera component
* Fix preload stream to actually start the background worker
* Reduce unncessary diffs for readability
* Remove redundant camera stream start code
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
* Remove dependencies on keepalive from StremaOutput and stream_worker
Pull logic from StreamOutput and stream_worker into the Stream
class, unifying keepalive and idle timeout logic. This prepares
for future changes to preserve hls state across stream url changes.
* Unmark tests as flaky (though still flaky)
This put tests into the broken state where they are flaky and do not yet pass
* Fix bug in test_hls_stream with incorrect path
* Enable and de-flake HLS stream tests
Background: Tests encode a fake video them start a stream to be decoded. Test
assert on the decoded segments, however there is a race with the stream worker
which can finish decoding first, and end the stream which ereases all buffers.
Breadown of fixes:
- Fix the race conditions by adding synchronization points right before the
stream is finalized.
- Refactor StreamOutput.put so that a patch() can block the worker
thread. Previously, the put call would happen in the event loop which was
not safe to block. This is a bit of a hack, but it is the simplist possible
code change to add this synchronization and arguably provides slightly better
separation of responsibilities from the worker anyway.
- Fix bugs in the tests that make them not pass, likely due to changes
introduced while the tests were disabled
- Fix case where the HLS stream view recv() call returns None, indicating
the worker finished while the request was waiting.
The tests were previously failing anywhere from 2-5% of the time on a lightly
loaded machine doing 1k iterations. Now, have 0% flake rate. Tested with:
$ py.test --count=1000 tests/components/strema/test_hls.py
* Remove unnecessary pts adjustments
* Add comments
* Use -inf for initial last_dts to be more clear
* Use video first_pts as common adjuster in recorder
* Remove seek(0) before av.open