libobs/media-io: Sleep to next audio time accurately#6415
libobs/media-io: Sleep to next audio time accurately#6415jp9000 merged 2 commits intoobsproject:masterfrom
Conversation
|
If the CPU usage is a concern, how about an idea to add a new function |
|
CPU usage is indeed a concern, |
The function `os_sleepto_ns` has a spin loop so it will consume CPU resource. The new function has same interface but consumes less CPU resource with a drawback of less precision.
Prior to this change, the audio thread roughly waits the time of `AUDIO_OUTPUT_FRAMES`, and consecutively processes twice or more if the latency is accumulated. This behavior causes fluctuation of timing to output audio packets. This change introduces `os_sleepto_ns_fast` so that the audio packets will be periodically output.
3d28177 to
8aeada4
Compare
|
The new function |
|
I would recommend More info: https://groups.google.com/a/chromium.org/g/scheduler-dev/c/0GlSPYreJeY |
Are you suggesting for |
|
I meant for |
|
I experimented with the waitable / high resolution timers last year, they seem very platform dependent in their accuracy (they would often overshoot the requested time) so are probably not a good idea to use in such critical code. For example, compare my numbers to the thread above: |

Description
This PR implements a new function
os_sleepto_ns_fast, which sleeps in a low precision but won't return until reaching the specific time.This change introduces
os_sleepto_ns_fastto the audio thread so that the audio packets will be periodically output.Motivation and Context
Prior to this change, the audio thread roughly waits the time of
AUDIO_OUTPUT_FRAMES, which is hard coded1024, and consecutively processes twice or more if the latency is accumulated. This behavior caused fluctuation of timing to output audio packets and affects audio buffering in decklink output.How Has This Been Tested?
The amount of audio buffer is monitored with a temporary commit db923d1, which is one more commit ahead of #1865 for logging purpose.
The buffer size in decklink is monitored at just before sending new audio frames. The buffer size is plotted and checked the buffer size is constant. (The buffer is gradually increasing, which is another issue to be fixed in the future.)
Audio buffer for the decklink-output device. This figure is taken with Intensity Pro 4K and Fedora 34. The buffer size is monitored at every 6.4 seconds.
Types of changes
Checklist: