Make thumbnail generation API synchronous
Many medialib controls (exposed in the VLC API) execute database queries synchronously. Therefore, they must not be called from the UI thread.
But in addition, some of them, like VLC_ML_MEDIA_GENERATE_THUMBNAIL
, do some processing in a separate medialibrary thread, and send a medialibrary event once completed.
This is a bit inconvenient to use, because it requires both to spawn a task manually and to handle the result via a callback from a medialibrary thread. Concretely, the UI code has to:
- register a medialib callback to receive all medialib events
- spawn a task (thread pool, coroutine, etc.) to execute
vlc_ml_media_generate_thumbnail()
, which executes some database queries and requests thumbnail generation asynchronously - on ML event
VLC_ML_EVENT_MEDIA_THUMBNAIL_GENERATED
from a medialibrary thread, repost the event on the UI thread (btw this is currently not always done on the Qt side, causing race conditions) - handle the event from the main thread
I think that only controls (if any) callable from the main thread (which may never execute any database query) could be made asynchronous.
But for simplicity and consistency with the other API functions, I suggest to make them synchronous, so that each client can decide how they execute them (coroutine, thread pool…). Moreover, the client typically wants to execute the callback in its UI thread; this couldn't be directly done by the medialibrary (so the client would have to repost the result event to its main thread).
Concretely, I would like vlc_ml_media_generate_thumbnail()
to block until the thumbnail generation is complete, and immediately give the result (either by returning the value or writing to an output parameter).
This might also apply to other medialibrary functions, but I don't know yet.