[grilo-plugins/0.1.x] local-metadata: Don't leave unfinished calls



commit 6c049ba0858ec834d35ec098efb47b9150198555
Author: Bastien Nocera <hadess hadess net>
Date:   Wed Apr 11 19:25:42 2012 +0100

    local-metadata: Don't leave unfinished calls
    
    It was possible to hang an application that would have been
    waiting for metadata because of us not calling the callback
    in some cases.
    
    We must make sure to either have async calls ongoing from which
    the callback will be called, or call the callback straight away.
    
    Fixes grilo-test-ui hanging when browsing large UPnP containers
    full of videos to parse.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=673936

 src/metadata/local-metadata/grl-local-metadata.c |   30 +++++++++++++++------
 1 files changed, 21 insertions(+), 9 deletions(-)
---
diff --git a/src/metadata/local-metadata/grl-local-metadata.c b/src/metadata/local-metadata/grl-local-metadata.c
index b48902d..9475981 100644
--- a/src/metadata/local-metadata/grl-local-metadata.c
+++ b/src/metadata/local-metadata/grl-local-metadata.c
@@ -553,7 +553,7 @@ resolve_video (GrlMetadataSource *source,
   }
 }
 
-static void
+static gboolean
 resolve_image (GrlMetadataSource *source,
                GrlMetadataSourceResolveSpec *rs,
                resolution_flags_t flags)
@@ -572,7 +572,11 @@ resolve_image (GrlMetadataSource *source,
                              G_FILE_QUERY_INFO_NONE, G_PRIORITY_DEFAULT, cancellable,
                              (GAsyncReadyCallback)got_file_info, rs);
     g_object_unref (file);
+
+    return FALSE;
   }
+
+  return TRUE;
 }
 
 /* Taken from: http://live.gnome.org/MediaArtStorageSpec/SampleStripCodeInC */
@@ -708,7 +712,7 @@ albumart_strip_invalid_entities (const gchar *original)
   return str;
 }
 
-static void
+static gboolean
 resolve_album_art (GrlMetadataSource *source,
                    GrlMetadataSourceResolveSpec *rs,
                    resolution_flags_t flags)
@@ -723,7 +727,7 @@ resolve_album_art (GrlMetadataSource *source,
   album_value = grl_media_audio_get_album (GRL_MEDIA_AUDIO (rs->media));
 
   if (!artist_value || !album_value)
-    return;
+    return TRUE;
 
   /* regex to find if we need to strip invalid chars
    * ()[]<>{}_! #$^&*+=|\\/\"'?~" and 2 or more spaces
@@ -769,6 +773,8 @@ resolve_album_art (GrlMetadataSource *source,
     g_free (file_path);
   }
   rs->callback (rs->source, rs->resolve_id, rs->media, rs->user_data, NULL);
+
+  return FALSE;
 }
 
 static gboolean
@@ -956,6 +962,7 @@ grl_local_metadata_source_resolve (GrlMetadataSource *source,
   GrlLocalMetadataSourcePriv *priv =
     GRL_LOCAL_METADATA_SOURCE_GET_PRIVATE (source);
   gboolean can_access;
+  gboolean done;
 
   GRL_DEBUG ("grl_local_metadata_source_resolve");
 
@@ -980,19 +987,24 @@ grl_local_metadata_source_resolve (GrlMetadataSource *source,
 
   GRL_DEBUG ("\ttrying to resolve for: %s", grl_media_get_url (rs->media));
 
+  done = FALSE;
+
   if (GRL_IS_MEDIA_VIDEO (rs->media)) {
+    done = TRUE;
     if (priv->guess_video)
       resolve_video (source, rs, can_access ? GRL_METADATA_KEY_URL : GRL_METADATA_KEY_TITLE, flags);
     if (can_access)
-      resolve_image (source, rs, flags);
+      done = resolve_image (source, rs, flags);
   } else if (GRL_IS_MEDIA_IMAGE (rs->media)) {
-    resolve_image (source, rs, flags);
+    done = resolve_image (source, rs, flags);
   } else if (GRL_IS_MEDIA_AUDIO (rs->media)) {
-    resolve_album_art (source, rs, flags);
-  } else {
-    /* What's that media type? */
-    rs->callback (source, rs->resolve_id, rs->media, rs->user_data, NULL);
+    done = resolve_album_art (source, rs, flags);
   }
+
+  /* Only call the callback if there are no async jobs left-over,
+   * such as resolve_image() checking for thumbnails */
+  if (done)
+    rs->callback (source, rs->resolve_id, rs->media, rs->user_data, NULL);
 }
 
 static void



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]