directsound: increase thread priority read/write to avoid stutter and glitches
Submitted by Dustin Spicuzza
Link to original bug (#781998)
Description
Since forever [1], when using GStreamer on Windows if there's enough load on the system (or various other things), playback will stutter. Other media players on Windows (for example, Windows Media Player (WMP)) don't exhibit these issues.
An easy way to reproduce this issue is by running Windows in a VM, and doing things like rapidly moving around windows that change frequently (like Process Explorer). The experiment I did today was running gst-play (msys2 gst 1.10.4) and WMP, and comparing their performance under load.
- It's very easy to get gst-play to stutter, even under very light load
- It's much more difficult to get WMP to stutter, even under heavy load
A brief examination of the processes themselves with Process Explorer reveals that the thread priorites in WMP are significantly higher than the thread priorities in the gst-play process.
More digging reveals that there's a Windows API [2] for telling the system that you're doing important multimedia processing. I theorize that if GStreamer calls the relevant APIs when doing processing (AvSetMmThreadCharacteristics followed by AvRevertMmThreadCharacteristics), then the performance will become similar to WMP.
I note that Clementine has a hack to set realtime priority for OSX [3] by setting thread priority when a GstTask is detected to start. Perhaps this is a good place to do this? If not, where?
I'm very very interested in getting rid of this stutter issue on Windows, and would be willing to implement/test something if someone will give me some pointers on the best place to implement it.
I note that the Clementine audio player also has a open bug report for this issue as well [4].
[1] https://github.com/exaile/exaile/issues/76
[2] https://msdn.microsoft.com/en-us/library/ms684247(VS.85).aspx
[3] https://github.com/clementine-player/Clementine/commit/df21da786e74a504adbdbd74d9d7c7577c6e52ed
[4] https://github.com/clementine-player/clementine/issues/2570