* Fix EXT-X-PROGRAM-DATE-TIME in stream
* Update fragment duration comments in worker
* Update duration test in worker
* Augment test on low latency playlists
* Reset start_time on discontinuity
Add a test that reproduces the issue where resetting the iterator
drops the already read packets. Fix a bug in replace_underlying_iterator
because checking the self._next function turns out not to work since
it points to a bound method so the "is not" check fails.
* 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>
* 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
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>
* 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
* Adjust dts warning messages
* Wait for second packet with overflow dts condition
* Rename dts gap watch variable
* Remove out of order packet warning
* Add audio to stream component
* Use container options to do most fmp4 formatting
* Add test for treatment of different audio inputs
* Add test for treatment of different audio inputs
* pcm_mulaw frames should be s16
* Use seek to get BytesIO length
* Remove unused utcnow
* Remove peek_next_audio_pts
* only demux audio and video packets - ignoring data and subtitle streams
Co-authored-by: Jason Hunter <hunterjm@gmail.com>