Published by Arto Jarvinen on 31 Jan 2010
Threads and devices
“Device” – isn’t that a funny word? I’m not a native English speaker so I don’t know but I get the feeling that engineers are sometimes running out of imagination and sometimes they (or I should really say “we” as I’m as guilty as the next guy) associate along very convoluted paths. Anyway…
The graphics “device” is a piece of software that represents the graphics output unit of the PC. It is in effect a COM object that obeys all the intricate and very mathematical rules of COM programming. It’s today used for pretty much everything you write or draw on the display. In MPC-HC the graphics device sometimes needs to be “reset”, meaning that memory needs to be reallocated due to a new video pixel format or some other reason.
If a COM object like the graphics device is created on one thread and naively destroyed or reset (reallocation of memory) on another, a dangling pointer to the object may remain on the thread of creation. This may cause all kinds of strange behavior. The safest thing (and the recommended thing according to Microsoft docs [1][2]) is therefore to create, reset and destroy the graphics device object on one and the same thread. This is not done in MPC-HC today and my plan is to fix that.
Another funny thing is that the exclusive mode full-screen will keep rendering through ALT+TAB and clicking on other windows, unlike other exclusive mode full-screen applications. The thing with exclusive mode is exactly that an application in this mode is supposed to have exclusive access to the driver without passing through any window manager and without sharing the device with any other application that may bother it. I may need to edit this post later if I find that this is a feature, not a bug. But that will be then.
My plan is to make it possible to toggle between windowed mode and exclusive mode (aka D3D) full-screen while streaming. This worked in my old player so at least it is feasible. But as always, time is scarce so don’t start holding your breath just yet.











