Skip to content

stream.dash: remove time.sleep() calls #4630

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Jul 2, 2022

Conversation

bastimeyer
Copy link
Member

@bastimeyer bastimeyer commented Jun 28, 2022

Resolves #4311

This replaces the time.sleep() calls made by the DASHStreamWorker thread and threads of the DASHStreamWriter thread pool with threading.Event.wait() calls, so that the execution of those threads can be stopped immediately when the stream gets closed.


  1. Refactor SegmentedStream{Worker,Writer} and add a common wait() method via the AwaitableMixin.
    Not sure if this is a fitting name. Any better suggestions?
  2. Refactor DASHStreamWorker tests. Not strictly necessary, but one test needed to be parametrized, because it was testing two things without resetting its state. Parametrizing while also patching via unittest.mock doesn't work via decorators, so the whole test needed to be rewritten either way.
  3. Remove time.sleep() from DASHStreamWorker.iter_segments() and make thread stop immediately when calling close() or after putting segments into the writer's queue if the manifest type is "static".
  4. Remove time.sleep() from DASHStreamWriter.fetch() and make threads of the thread pool stop immediately when calling close().

Notes

  • Even though the worker tests were refactored, they weren't necessarily improved. There's still some stuff that needs to be tested here, ideally via proper integration tests, similar to the HLS tests.
  • The writer.fetch changes don't have any tests.
  • stream.ffmpegmux: close sub-streams concurrently #4634:
    Any additional closing delay needs to be fixed in the FFMPEGMuxer (see Delay in closing of Muxed Streams #3137).
    For example, FFMPEGMuxer.close() calls close() on the various substreams sequentially, which means that if the streams wait until all of their threads have terminated (see stream.segmented: join worker+writer on close #4517), this introduces an additional delay.
  • Being able to abort HTTP requests would also be good.

DASH live streams for testing can be found on https://steamcommunity.com/?subsection=broadcasts

- Move SegmentedStreamWorker.wait to AwaitableMixin
- Make both SegmentedStream{Worker,Writer} inherit from AwaitableMixin
- Refactor DASHStreamWorker.iter_segments()
- Replace dash_manifest.sleeper() with SegmentedStreamWorker.wait(),
  and make the worker thread shut down immediately on close().
- Prevent unnecessary wait times for static manifest types by calling
  close() after all segments were put into the writer's queue.
- Replace dash_manifest.sleep_until() with SegmentedStreamWriter.wait(),
  and make the thread-pool threads shut down immediately on close().
- Fix segment name logging
@bastimeyer bastimeyer requested a review from back-to June 28, 2022 13:23
@back-to back-to merged commit b277114 into streamlink:master Jul 2, 2022
@bastimeyer bastimeyer deleted the stream/dash/remove-sleep branch July 2, 2022 07:03
Billy2011 added a commit to Billy2011/streamlink-27 that referenced this pull request Jul 10, 2022
- Move SegmentedStreamWorker.wait to AwaitableMixin
- Make both SegmentedStream{Worker,Writer} inherit from AwaitableMixin
Billy2011 added a commit to Billy2011/streamlink-27 that referenced this pull request Jul 10, 2022
…#4630)

- Refactor DASHStreamWorker.iter_segments()
- Replace dash_manifest.sleeper() with SegmentedStreamWorker.wait(),
  and make the worker thread shut down immediately on close().
- Prevent unnecessary wait times for static manifest types by calling
  close() after all segments were put into the writer's queue.
Billy2011 added a commit to Billy2011/streamlink-27 that referenced this pull request Jul 10, 2022
- Replace dash_manifest.sleep_until() with SegmentedStreamWriter.wait(),
  and make the thread-pool threads shut down immediately on close().
- Fix segment name logging
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

stream.dash (or stream.segmented): takes long time to finish dash manifest
2 participants