Commit Graph

77 Commits (68809e9f43699b2ae414954b6cab0456dc8e40a3)

Author SHA1 Message Date
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
uvjustin acde33dbbc
Keep 1 extra segment around after playlist removal (#46310)
* Keep 1 extra segment around after playlist removal

* Remove segments length check
2021-02-10 15:51:16 -05:00
uvjustin 1fea24502c
Bump pyav version to 8.03 (#46315) 2021-02-10 18:14:03 +08:00
Allen Porter 26f455223b
Update nest stream URLs expiration (#46311) 2021-02-09 23:53:34 -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 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
Paulus Schoutsen e584902b8b
Remove empty schema (#45044) 2021-01-11 14:25:09 +01:00
uvjustin 414f167508
Remove pts adjustments in stream (#42399)
* 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
2020-11-16 15:13:33 -05: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
springstan a967f689c7
Remove unnecessary instances of dict.keys() (#42518) 2020-10-28 20:43:48 +01:00
uvjustin f8d87bff16
Fix AVError and allow more missing DTS packets in stream (#42277)
* Fix AVError and allow more missing DTS in stream init

* Avoid recreating container demux iterator

* Relax missing dts requirement

* Fix spelling error

* Fix error message count

* Add timeout to av.open read

* Increase STREAM_TIMEOUT to 30
2020-10-24 22:55:12 -04:00
uvjustin 6a59e79bc6
Remove duplicated finalize_stream code in stream (#42171) 2020-10-21 23:36:54 +02:00
Colin Robbins 6f8e3d2544
Update stream integration for Python 3.9 which removed isAlive from threading in favor of is_alive (#42051)
Python 3.9 compact
2020-10-18 23:42:50 -04:00
uvjustin ce0e08838f
Fix timestamp overflow error in stream (#41951) 2020-10-16 11:48:45 -04:00
uvjustin 9270585a44
Cap AVC profile level at 4.1 in stream master playlist (#41592)
* Cap AVC profile level at 4.1

* Use smaller multiplier in bandwidth calculation
2020-10-15 16:37:27 -04:00
uvjustin 1c6d0d138d
Adjust dts warning messages in stream (#41467)
* Adjust dts warning messages

* Wait for second packet with overflow dts condition

* Rename dts gap watch variable

* Remove out of order packet warning
2020-10-11 12:55:13 -04:00
uvjustin 6c18feb4ed
Allow only one packet with no dts in stream init (#41129)
* Allow only one packet with no dts in stream init

* Call finalize_stream() on exit
2020-10-11 12:52:51 -04:00
uvjustin e85d1deddd
Return target duration of 1 when no segments (#40518) 2020-09-30 11:46:35 -04:00
uvjustin 5658abfaca
Log timestamp overflow in stream (#39844) 2020-09-30 11:45:59 -04:00
uvjustin 9a32e28574
Create master playlist for cast (#40483)
Co-authored-by: Jason Hunter <hunterjm@gmail.com>
2020-09-27 22:38:14 +02:00
uvjustin 8e0bb92c79
Disable audio in stream when audio stream profile is None (#40521) 2020-09-24 14:35:52 +02:00
uvjustin 8d3e4b6b3f
Ignore packets with missing dts in peek_first_pts (#40299) 2020-09-20 21:26:24 -04:00
uvjustin b0ba0e77f8
Remove skip_sidx container option in stream (#39970)
* Remove skip_sidx container option

* Add comment
2020-09-12 15:19:37 -04:00
uvjustin 9b29d09d45
Set output timescale to input timescale (#39946) 2020-09-11 14:07:45 -04:00
uvjustin 4ee5a29bc0
Disable audio for HLS or mpegts input (#39906) 2020-09-10 15:55:55 -04:00
Jason Hunter 1a78d96014
allow creating directories from camera snapshot, stream record, and tensorflow file out (#39728) 2020-09-06 18:54:24 -04:00
uvjustin c9a4deb118
Set log level for libav.mp4 in stream (#39719)
Also add @uvjustin to codeowners
2020-09-06 20:46:36 +02:00
Chris Talkington a0663d84d2
fix black for stream (#39622) 2020-09-03 11:54:04 -05:00
Eric Severance 9baa7c6c24
Restart keepalive streams (#38863) 2020-09-03 12:22:00 -04:00
Ville Skyttä b4bac0f7a0
Exception chaining and wrapping improvements (#39320)
* 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.
2020-08-28 13:50:32 +02:00
Franck Nijhof 1c2ebdf307
Upgrade black to 20.8b1 (#39287) 2020-08-27 13:56:20 +02: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
Eric Severance 4d1ef02802
Stream clients operate on a copy of the intnernal self._outputs dict (#38766) 2020-08-11 17:20:43 -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
J. Nick Koston 57883ec10a
Fix variable error during stream close (#38417) 2020-07-30 16:58:17 -10:00
Ville Skyttä ac0dbb17af
Attrs cleanups (#37849) 2020-07-14 10:30:30 -07:00
Paulus Schoutsen 9ac1475251
Simplify logger integration (#37780)
Co-authored-by: J. Nick Koston <nick@koston.org>
2020-07-13 10:20:18 -07:00
Dermot Duffy eb6fda8387
Allow an extra packet without dts (for Arlo camera streaming) (#37792)
* Allow 1 packet without dts. See https://github.com/twrecked/hass-aarlo/issues/151 .

* Reset boolean once a packet with dts is found.

* Fix no-else-continue lint error.
2020-07-13 09:47:33 -04:00
Franck Nijhof 53545c984b
Log lines do not end with a full stop (#37527) 2020-07-05 23:04:19 +02:00
Patrick Kishino e80fac36d8
Bumped PyAv to 8.0.2 to fix mac os stream issue (#36396) 2020-06-03 08:00:50 +02:00
Jason Hunter 8cd905487e
Bump pyAV and close unclosed outputs (#35960)
* bump pyAV and close unclosed outputs

* skip stream from coverage for now

* fix divide by zero error
2020-05-22 18:13:37 +02:00
Jason Hunter 40d3d64027
Fix recording duration flag (#34648) 2020-04-24 14:18:58 -07:00
Franck Nijhof 24840b54ac
Add yamllint (in pre-commit and CI) (#33676)
* Add yamllint (in pre-commit and CI)

* Fix linting for all YAML files

* Bump and add it to requirements

* Fix gen_requirements for pre-commit, remove 'v' from version
2020-04-05 10:33:45 +02:00
Rami Mosleh e1cc2acdf9
Specify rtsp_transport for Onvif Camera (#31918)
* specify rtsp_transport for onvif camera

* remove used variable

* Update homeassistant/components/stream/__init__.py

Co-Authored-By: Paulus Schoutsen <paulus@home-assistant.io>

* change options to stream_options

Co-authored-by: Paulus Schoutsen <paulus@home-assistant.io>
2020-03-06 09:59:57 -08: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
Franck Nijhof bfa0edaf92 Migrate Integration Quality Scale from docs to manifest: internal (#30551) 2020-01-07 20:58:49 +01:00
Franck Nijhof a84741392b
Format all manifests with prettier (#30521) 2020-01-06 21:28:23 +01:00
Ville Skyttä 130571c478 Remove no longer needed auth.util, use secrets instead (#29861) 2019-12-12 16:46:33 +01:00