[vlc-commits] preparser: post-pone event until after art fetching is complete

Filip Roséen git at videolan.org
Wed Mar 29 17:37:09 CEST 2017


vlc | branch: master | Filip Roséen <filip at atch.se> | Fri Mar 17 14:03:33 2017 +0100| [5e6e0a66682e5fe42ca99b969b7cb898c51a01b5] | committer: Hugo Beauzée-Luyssen

preparser: post-pone event until after art fetching is complete

Since one can request art to be fetched through
libvlc_media_parse_with_options, one would expect the event
originating from this request to be sent upon the completion of all
requested operations (not just the preparsing). The alternative would
be to monitor the libvlc_MediaMetaChanged, hoping for an artwork URL
change, but this can't account for error nor timeout.

--

The changes introduced were written after a discussion with Hugo
Beauzée-Luyssen where he expressed that he would, if possible, be able to
post-pone the preparsing events until the art fetching is complete.

Post-poning the event fixes issues that are currently reproducible where
medialibrary is used, and art is missing (because it listens to the preparse
event in order to generate the database contents).

It can be viewed as a follow-up to the below rejected patch (with the
same goal in mind):

 - https://patches.videolan.org/patch/15810/

Signed-off-by: Hugo Beauzée-Luyssen <hugo at beauzee.fr>

> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=5e6e0a66682e5fe42ca99b969b7cb898c51a01b5
---

 src/playlist/fetcher.c   | 39 +++++++++++++++++++++++++++++++--------
 src/playlist/fetcher.h   |  4 ++--
 src/playlist/preparser.c |  7 +++++--
 3 files changed, 38 insertions(+), 12 deletions(-)

diff --git a/src/playlist/fetcher.c b/src/playlist/fetcher.c
index 7e9f412..44c13a5 100644
--- a/src/playlist/fetcher.c
+++ b/src/playlist/fetcher.c
@@ -53,6 +53,7 @@ struct playlist_fetcher_t {
 struct fetcher_request {
     input_item_t* item;
     atomic_uint refs;
+    int preparse_status;
     int options;
 };
 
@@ -206,13 +207,22 @@ static int SearchByScope( playlist_fetcher_t* fetcher,
         ! SearchArt( fetcher, item, scope ) )
     {
         AddAlbumCache( fetcher, req->item, false );
-        background_worker_Push( fetcher->downloader, req, NULL, 0 );
-        return VLC_SUCCESS;
+        if( !background_worker_Push( fetcher->downloader, req, NULL, 0 ) )
+            return VLC_SUCCESS;
     }
 
     return VLC_EGENERIC;
 }
 
+static void SetPreparsed( struct fetcher_request* req )
+{
+    if( req->preparse_status != -1 )
+    {
+        input_item_SetPreparsed( req->item, true );
+        input_item_SignalPreparseEnded( req->item, req->preparse_status );
+    }
+}
+
 static void Downloader( playlist_fetcher_t* fetcher,
     struct fetcher_request* req )
 {
@@ -271,6 +281,7 @@ out:
     }
 
     free( psz_arturl );
+    SetPreparsed( req );
     return;
 
 error:
@@ -286,15 +297,23 @@ static void SearchLocal( playlist_fetcher_t* fetcher, struct fetcher_request* re
     if( var_InheritBool( fetcher->owner, "metadata-network-access" ) ||
         req->options & META_REQUEST_OPTION_SCOPE_NETWORK )
     {
-        background_worker_Push( fetcher->network, req, NULL, 0 );
+        if( background_worker_Push( fetcher->network, req, NULL, 0 ) )
+            SetPreparsed( req );
+    }
+    else
+    {
+        input_item_SetArtNotFound( req->item, true );
+        SetPreparsed( req );
     }
-    else input_item_SetArtNotFound( req->item, true );
 }
 
 static void SearchNetwork( playlist_fetcher_t* fetcher, struct fetcher_request* req )
 {
     if( SearchByScope( fetcher, req, FETCHER_SCOPE_NETWORK ) )
+    {
         input_item_SetArtNotFound( req->item, true );
+        SetPreparsed( req );
+    }
 }
 
 static void RequestRelease( void* req_ )
@@ -428,22 +447,26 @@ playlist_fetcher_t* playlist_fetcher_New( vlc_object_t* owner )
     return fetcher;
 }
 
-void playlist_fetcher_Push( playlist_fetcher_t* fetcher, input_item_t* item,
-    input_item_meta_request_option_t options )
+int playlist_fetcher_Push( playlist_fetcher_t* fetcher, input_item_t* item,
+    input_item_meta_request_option_t options, int preparse_status )
 {
     struct fetcher_request* req = malloc( sizeof *req );
 
     if( unlikely( !req ) )
-        return;
+        return VLC_ENOMEM;
 
     req->item = item;
     req->options = options;
+    req->preparse_status = preparse_status;
 
     atomic_init( &req->refs, 1 );
     input_item_Hold( item );
 
-    background_worker_Push( fetcher->local, req, NULL, 0 );
+    if( background_worker_Push( fetcher->local, req, NULL, 0 ) )
+        SetPreparsed( req );
+
     RequestRelease( req );
+    return VLC_SUCCESS;
 }
 
 void playlist_fetcher_Delete( playlist_fetcher_t* fetcher )
diff --git a/src/playlist/fetcher.h b/src/playlist/fetcher.h
index c5d9a3d..06718ac 100644
--- a/src/playlist/fetcher.h
+++ b/src/playlist/fetcher.h
@@ -46,8 +46,8 @@ playlist_fetcher_t *playlist_fetcher_New( vlc_object_t * );
  * The input item is retained until the art fetching is done or until the
  * fetcher object is destroyed.
  */
-void playlist_fetcher_Push( playlist_fetcher_t *, input_item_t *,
-                            input_item_meta_request_option_t );
+int playlist_fetcher_Push( playlist_fetcher_t *, input_item_t *,
+                           input_item_meta_request_option_t, int );
 
 /**
  * This function destroys the fetcher object and thread.
diff --git a/src/playlist/preparser.c b/src/playlist/preparser.c
index d7e2d8c..04ba92d 100644
--- a/src/playlist/preparser.c
+++ b/src/playlist/preparser.c
@@ -95,7 +95,10 @@ static void PreparserCloseInput( void* preparser_, void* input_ )
     input_Close( input );
 
     if( preparser->fetcher )
-        playlist_fetcher_Push( preparser->fetcher, item, 0 );
+    {
+        if( !playlist_fetcher_Push( preparser->fetcher, item, 0, status ) )
+            return;
+    }
 
     input_item_SetPreparsed( item, true );
     input_item_SignalPreparseEnded( item, status );
@@ -169,7 +172,7 @@ void playlist_preparser_fetcher_Push( playlist_preparser_t *preparser,
     input_item_t *item, input_item_meta_request_option_t options )
 {
     if( preparser->fetcher )
-        playlist_fetcher_Push( preparser->fetcher, item, options );
+        playlist_fetcher_Push( preparser->fetcher, item, options, -1 );
 }
 
 void playlist_preparser_Cancel( playlist_preparser_t *preparser, void *id )



More information about the vlc-commits mailing list