Reset the stream backoff timeout when the url updates, meant to improve the retry behavior
for nest cameras. The problem is the nest url updates faster than the stream reset time
so the wait timeout never resets if there is a temporarily problem with the new url. In particular
this *may* help with the flaky cloud nest urls, but seems more correct otherwise.
Improve stream robustness by always retrying in the worker on failure, rather than only when
keepalive is enabled.
This will make cloud cameras like nest more robust, since they have a tendency to be flaky. This
is also needed to improve client side retry behavior because when the client attempts to retry,
the stream token is already revoked because the worker stopped.
The worker will still idle timeout if no streams are present, so it won't go on forever if no
frontend is viewing the stream.
Rename create_stream to async_create_stream in Camera
Rename get_image to async_get_image in Stream
Rename get_image to async_get_image in KeyFrameConverter
* Add a camera specific logger to help diagnose stream errors
Add a camera specific logger to help users associate stream errors with a particular camera.
Issue #54659
* Apply code review feedback
* Update package name based on manual testing
* Mark camera unavailable when keepalive stream fails
Add a listener in stream that notifies camera when the stream state has changed, and
use that to inform the camera `available` property. Update the property to be set
only from the main loop where it is read to reduce thread safety races.
Issue #54659
* Fix pylint import related errors
* Address lint naming errors
* Apply suggestions from code review
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
This refactoring was pulled out of https://github.com/home-assistant/core/pull/53676 as an
initial step towards reverting the addition of the SegmentBuffer class, which will be
unrolled back into a for loop.
The StreamState class holds the persistent state in stream that is used across stream worker
instantiations, e.g. state across a retry or url expiration, which primarily handles
discontinuities. By itself, this PR is not a large win until follow up PRs further simplify
the SegmentBuffer class.
* 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