Skip to content
Snippets Groups Projects

qt: run all medialibrary operations in a thread

Merged Pierre Lamot requested to merge chub/vlc:qt/run-on-ml-thread-dev into master

While counting and loading the data from view was already done in a background thread, many operations where done directly on the medialibrary from the Qt thread. this MR aims to move all theses operations in a background thread

This MR offers a common pattern that allows to run ML operation in a background thread and have the result on a callback.

Code for the code that is executed on the ML thread and as callback on the UI thread is inlined with lambdas, this allows to avoid declaring structures and managing connections to get the result, which makes the code clearer in my opinion, code is declared where it's used.

sample usage:

    //structure used to pass data from the ML thread to the UI thread
    struct Ctx {
        bool success;
    };
    m_mediaLib->runOnMLThread<Ctx>(
    //reference to the object making the call, this is used to ensure that
    //the caller still exists before calling the UI callback
    this,
    //ML thread, data needed from the caller are passed in the capture of the lambda
    //capturing this or any of its member is not allowed here
    //the callback have in parametters the ml instance and a context that will be shared with
    //the UI callback  
    [url, indexed](vlc_medialibrary_t* ml, Ctx& ctx)
    {
        int res;
        if ( indexed )
            res = vlc_ml_add_folder(  ml, qtu( url ) );
        else
            res = vlc_ml_remove_folder( ml, qtu( url ) );
        ctx.success = (res == VLC_SUCCESS);
    },
    //UI callback, capturing this is allowed, (runOnMLThread will ensure that `this`
    //still exists at this point
    //the callback has as parametters the request id and the shared context
    [this, indexed](quint64, Ctx& ctx){
        if (ctx.success)
        {
            m_indexed = indexed;
            emit isIndexedChanged();
        }
    },
    //allow to specify if the task should be run on a specific thread, null (default) will run on any thread
    "ML_FOLDER_ADD_QUEUE");

updates

V2) Remove Object dependency in CoverGenerator, factorize thumbnail updated events handling, provide runOnMLThread version without UI callback

V3) Rebase fail -_-'

V4) don't call UI callback when task is canceled; fix medialib not deleted on shutdown when all tasks can be canceled; typos and nits

V5) rebase on master (after benjamin's changes), remove findInCache(int), add rejection mechanims, + minor changes

v6) Added the ability to run tasks on a dedicated thread in order to warranty that theses tasks will be executed sequentially

v7) update MLThreadPool implementation

v8) fix nits

v9) rebase on master, fix beginResetModel/endResetModel scope, delete queue when removing last tasks from MLThreadPool::tryTake, nits

v10) apply same logic as beginResetModel/endResetModel fixes for row removal/moves

Edited by Pierre Lamot

Merge request reports

Loading
Loading

Activity

Filter activity
  • Approvals
  • Assignees & reviewers
  • Comments (from bots)
  • Comments (from users)
  • Commits & branches
  • Edits
  • Labels
  • Lock status
  • Mentions
  • Merge request status
  • Tracking
  • Prince Gupta
  • Prince Gupta
  • Pierre Lamot added 61 commits

    added 61 commits

    • fe57b0d1...abf527b5 - 33 commits from branch videolan:master
    • 6187a4dc - qt: allow to register ml event callback on MediaLib instance
    • ab46f7ff - qt: register to ML events using MediaLib instance
    • 6715c15a - qt: provide runOnMLThread function
    • b1cd196b - qt: run ml playlist insertion on ML thread
    • 10591582 - qt: add a findInCache MLBaseModel helper that takes a MLItemId
    • f31b70e5 - qt: use runOnMLThread to generate covers
    • a1f2c056 - qt: remove CoverGenerator inheriance from QObject
    • 8d4dee91 - qt: run ML operations in background thread in MLRecentsModel
    • 3d421991 - qt: fech medialib media from url on ML thread
    • d28c4638 - qt: run ML operations in background thread in NetworkMediaModel
    • 52465331 - qt: run ML operations in background thread in BookmarkModel
    • 8c3bf309 - qt: use modern connection syntax in Bookmark dialog
    • 5f3cecfe - qt: run ML operations in background thread in MLFolderModel
    • 82a80912 - qt: run ML operations in background thread in NetworkMediaModel
    • 0cc3b9e9 - qt: remove unused constructors in medialib models
    • cea4684d - qt: use runOnMLThread to count and load data
    • 02964304 - qt: run ML operations in background thread in MLPlaylistListModel
    • 2561ed29 - qt: run ML operations in background thread in MLPlaylistModel
    • ea8e3c3d - qt: make MLEvent non-copiable
    • 0ba9c83d - qt: add more informations regarding thumbnails in MLEvent
    • d4bd10de - qt: don't assert in MLListCache::find when cache is empty
    • 356db6bd - qt: pass the updated item along with the new data to the thumbnailUpdated cb
    • 931440e4 - qt: generate video thumbnail in MLXXXVideoModel instead of MLVideo
    • 949a5a07 - qt: generate playlist thumbnail in MLPlaylistModel instead of MLPlaylist
    • dfc0edba - qt: remove unused medialib reference
    • 0d4c33d4 - qt: remove unused getItemsForIndexes function
    • d58dd154 - qt: remove direct accessor to vlc_medialibrary_t instance
    • 9d74c103 - qt: move mlitem function on the ML thread

    Compare with previous version

  • Pierre Lamot changed the description

    changed the description

  • Pierre Lamot added 6 commits

    added 6 commits

    • 9325c293 - qt: generate video thumbnail in MLXXXVideoModel instead of MLVideo
    • ceed4207 - qt: generate playlist thumbnail in MLPlaylistModel instead of MLPlaylist
    • e59c926b - qt: remove unused medialib reference
    • 68c6404a - qt: remove unused getItemsForIndexes function
    • 0aec11a0 - qt: remove direct accessor to vlc_medialibrary_t instance
    • bfcb9ab4 - qt: move mlitem function on the ML thread

    Compare with previous version

  • Pierre Lamot changed the description

    changed the description

  • Romain Vimont
  • Romain Vimont
  • Romain Vimont
  • Romain Vimont
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Loading
  • Please register or sign in to reply
    Loading