* 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
* Adjust dts warning messages
* Wait for second packet with overflow dts condition
* Rename dts gap watch variable
* Remove out of order packet warning
* Remove unnecessary exception re-wraps
* Preserve exception chains on re-raise
We slap "from cause" to almost all possible cases here. In some cases it
could conceivably be better to do "from None" if we really want to hide
the cause. However those should be in the minority, and "from cause"
should be an improvement over the corresponding raise without a "from"
in all cases anyway.
The only case where we raise from None here is in plex, where the
exception for an original invalid SSL cert is not the root cause for
failure to validate a newly fetched one.
Follow local convention on exception variable names if there is a
consistent one, otherwise `err` to match with majority of codebase.
* Fix mistaken re-wrap in homematicip_cloud/hap.py
Missed the difference between HmipConnectionError and
HmipcConnectionError.
* Do not hide original error on plex new cert validation error
Original is not the cause for the new one, but showing old in the
traceback is useful nevertheless.
* 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>