Commit Graph

47 Commits (2d1744c573af7e2275436a992acef53207f3b05f)

Author SHA1 Message Date
uvjustin e8b5790846
Clean up stream refactor (#51951)
* Clean up target_duration method

* Consolidate Part creation in one place

* Use BytesIO.read instead of memoryview access

* Change flush() signature
2021-06-20 13:38:02 +08:00
uvjustin 6d656dd2ec
Speed up record stream audio test (#51901) 2021-06-15 14:27:53 -04:00
uvjustin 97e77ab229
Improve type hints in stream (#51837)
* Improve type hints in stream

* Fix import locations

* Add stream to .strict-typing

Co-authored-by: Ruslan Sayfutdinov <ruslan@sayfutdinov.com>
2021-06-14 23:59:25 +08:00
uvjustin 123e8f01a1
Refactor stream to create partial segments (#51282) 2021-06-14 00:41:21 +08:00
uvjustin 3ca7eb9440
Update HLS playlist in stream (#51191)
* 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
2021-05-30 11:41:23 +08:00
uvjustin 6ad29aec2c
Adjust segment duration calculation in stream (#51149)
* Calculate min segment duration internally

* Rename segments to sequences in StreamOutput

* Fix segment duration calculation in test_worker
2021-05-28 13:36:41 +08:00
uvjustin 38e0cbe964
Change stream sequence number to start from 0 (#51101)
* Use constants for provider strings

* Add last_sequence property
2021-05-27 11:22:31 +08:00
uvjustin c6f108f7c3
Refactor stream to use bytes (#51066)
* Refactor stream to use bytes
2021-05-26 16:19:09 +08:00
Erik Montnemery b0aa64d59c
Replace redacted stream recorder credentials with '****' (#48832) 2021-04-08 12:44:17 -07:00
uvjustin cd455e296e
Remove login details before logging stream source (#45398)
* 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>
2021-03-23 07:30:45 +01:00
Allen Porter 02a82d3f00
Add timeouts in stream tests to prevent possible hangs (#47545)
* Add timeouts on recving packets

Add a timeout when recving packets from the worker thread in case it hangs.
Add an exit condition just in case the while loop goes on forever.

* Add a timeout to recorder thread join.

* Wait for recorder thread to be invoked in tests

Remove the while loop and instead wait for segments to be produced by the background worker thread.

* Allow worker to resume before stopping to fix timeouts

* Lower test timeout further

* Remove test_stream_ended since it is flaky

This test doesn't really add additional value on top of other tests.
2021-03-13 01:53:26 -08:00
uvjustin d9bf63103f
Fix I-frame interval in stream test video (#47638) 2021-03-08 11:23:57 -08:00
uvjustin 14f85d8731
Disable audio stream when ADTS AAC detected (#47441)
* Disable audio stream when ADTS AAC detected

* Use context manager for memoryview

* Fix tests

* Add test

* Fix tests

* Change FakePacket bytearray size to 3
2021-03-06 16:40:49 +01:00
Allen Porter 715a254913
Handle stream failures in recorder (#47151)
* 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>
2021-02-28 18:01:28 -08:00
Allen Porter 5cc8302e6a
Fix flaky hls keepalive test (#47186)
Remove a call to stream.start() which is issued before the test is fully
setup (e.g. keepalive is not set to True, and mock calls are not registered)
2021-02-28 10:25:07 -08:00
uvjustin f005c68630
Restore stream recorder functionality and add discontinuity support (#46772)
* 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
2021-02-23 10:37:19 +08:00
Allen Porter 4aa4f7e285
Rollback stream StreamOutput refactoring in PR#46610 (#46684)
* Rollback PR#46610

* Update stream tests post-merge
2021-02-20 06:49:39 -08:00
Allen Porter 88d143a644
Add discontinuity support to HLS streams and fix nest expiring stream urls (#46683)
* 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
2021-02-18 20:26:02 +08:00
Allen Porter 56f32196bd
Add back block_until_done calls removed in PR 46610 (#46680) 2021-02-16 22:05:20 -08:00
Allen Porter aaecd91407
Fix exception in stream idle callback (#46642)
* 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
2021-02-16 12:10:26 -08:00
Allen Porter 08201d146b
Separate HLS logic out of core StreamOutput to prepare for discontinuity (#46610)
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.
2021-02-16 06:59:43 -08:00
Allen Porter 89aaeb3c35
Refactor stream worker responsibilities for segmenting into a separate class (#46563)
* 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>
2021-02-15 09:52:37 -08:00
Allen Porter 3f4828f5e1
Add additional stream HLS payload tests (#46517)
* Add tests for HLS playlist view details

* Add tests for hls playlist payloads

* Update tests/components/stream/test_hls.py

Co-authored-by: uvjustin <46082645+uvjustin@users.noreply.github.com>

* Update tests/components/stream/test_hls.py

Co-authored-by: uvjustin <46082645+uvjustin@users.noreply.github.com>

* Update tests/components/stream/test_hls.py

Co-authored-by: uvjustin <46082645+uvjustin@users.noreply.github.com>

* Update tests/components/stream/test_hls.py

Co-authored-by: uvjustin <46082645+uvjustin@users.noreply.github.com>

* Update tests/components/stream/test_hls.py

Co-authored-by: uvjustin <46082645+uvjustin@users.noreply.github.com>

* Update tests/components/stream/test_hls.py

Co-authored-by: uvjustin <46082645+uvjustin@users.noreply.github.com>

* Update tests/components/stream/test_hls.py

Co-authored-by: uvjustin <46082645+uvjustin@users.noreply.github.com>

Co-authored-by: uvjustin <46082645+uvjustin@users.noreply.github.com>
2021-02-14 20:32:37 -08:00
Allen Porter 26f455223b
Update nest stream URLs expiration (#46311) 2021-02-09 23:53:34 -08:00
Allen Porter 00aebec90d
Fix bug in test found by manual log inspection (#46309) 2021-02-09 21:59:49 -08:00
Allen Porter 2bcf87b980
Change the API boundary between camera and stream with initial improvement for nest expiring stream urls (#45431)
* 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>
2021-02-08 19:53:28 -08:00
Allen Porter dca6a93898
Centralize keepalive logic in Stream class (#45850)
* 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.
2021-02-08 07:19:41 -08:00
Allen Porter 2136b3013f
Increase test coverage for stream worker (#44161)
Co-authored-by: Justin Wong <46082645+uvjustin@users.noreply.github.com>
2021-02-01 17:48:49 +01:00
Allen Porter bf0e012d1e
Repair stream test_recorder.py and mark not flaky (#45054)
Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2021-01-20 14:44:24 +01:00
Allen Porter 65e3661f88
Repair flaky and broken stream tests in test_hls.py, and turn back on (#45025)
* 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
2021-01-11 14:34:45 +01:00
Franck Nijhof 65cf2fcb6f
Drop asynctest (#44746) 2021-01-01 22:31:56 +01:00
uvjustin 66dccd86bd
Modify wait timeout in stream (#42794)
* Set wait timeout to 40

* Use dynamic wait_timeout

* Catch error in container open

* Get restart times from const.py

* Fix test_stream_keepalive
2020-11-11 12:32:56 -05:00
Philip Allgaier dde6305549
Cleanup unused loggers (components N-Z + tests) (#41982) 2020-10-16 21:24:08 -05:00
Eric Severance 9baa7c6c24
Restart keepalive streams (#38863) 2020-09-03 12:22:00 -04:00
uvjustin dc2d0b9297
Add audio to stream (#38846)
* 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>
2020-08-19 23:18:54 -04:00
uvjustin 5355fcaba8
Add H.265 support to stream component (#38125)
* Add H.265 support to stream component

* Change find_box to generator

* Move fmp4 utilities to fmp4utils.py

* Add minimum segments and segment durations

* Remove MIN_SEGMENTS

* Fix when container_options is None

* Fix missing num_segments and update tests

* Remove unnecessary mock attribute

* Fix Segment construction in test_recorder_save

* fix recorder with lookback

Co-authored-by: Jason Hunter <hunterjm@gmail.com>
2020-08-11 17:12:41 -04:00
Paulus Schoutsen 2af984917e
Use asynctest-mock in most places (#35109)
* Use asynctest-mock in most places

* Fix broken patch in pilight
2020-05-03 11:27:19 -07:00
Paulus Schoutsen ec47216388
Use built-in test helpers on 3.8 (#34901) 2020-04-30 13:29:50 -07:00
springstan 9a40d5b7ed
Use HTTP_NOT_FOUND constant (#33835) 2020-04-09 00:57:47 +02:00
Christian Clauss df7d2b3aeb
Fix typos found by codespell (#31243)
* Fix typos found by codespell

* Fix typos found by codespell

* codespell: Furture  ==> Future

* Update test_config_flow.py

* Update __init__.py

* Spellcheck: successfull  ==> successful

* Codespell: unsuccesful  ==> unsuccessful

* Codespell: cant  ==> can't

* Codespell: firware ==> firmware

* Codespell: mimick  ==> mimic
2020-01-31 08:33:00 -08:00
Michał Mrozek 9aa28dfd54 move imports in stream component (#27647) 2019-10-14 14:20:18 -07:00
Paulus Schoutsen 4de97abc3a Black 2019-07-31 12:25:30 -07:00
Anders Melchiorsen 37badbbf09
Skip flaky stream tests (#23493)
* Skip flaky test_hls tests

* Skip flaky test_recorder tests
2019-04-28 13:58:19 +02:00
Jason Hu abe85c73ae
Fix flaky test (#22850) 2019-04-07 12:42:16 -07:00
Jason Hunter a75b151dfa fix flaky test (#22748) 2019-04-04 23:39:19 -07:00
Jason Hunter 26726af689 Stream Record Service (#22456)
* Initial commit of record service for live streams

* fix lint

* update service descriptions

* add tests

* fix lint
2019-03-27 21:47:07 -07:00
Jason Hunter 7ccd0bba9a Live Streams Component (#21473)
* initial commit of streams

* refactor stream component

* refactor so stream formats are not considered a platform

* initial test and minor refactor

* fix linting

* update requirements

* need av in tests as well

* fix import in class def vs method

* fix travis and docker builds

* address code review comments

* fix logger, add stream start/stop logs, listen to HASS stop

* address additional code review comments

* beef up tests

* fix tests

* fix lint

* add stream_source to onvif camera

* address pr comments

* add keepalive to camera play_stream service

* remove keepalive and move import

* implement registry and have output provider remove itself from stream after idle, set libav log level to error
2019-03-11 19:57:10 -07:00