After an evaluation, GNOME has moved from Bugzilla to GitLab. Learn more about GitLab.
No new issues can be reported in GNOME Bugzilla anymore.
To report an issue in a GNOME project, go to GNOME GitLab.
Do not go to GNOME Gitlab for: Bluefish, Doxygen, GnuCash, GStreamer, java-gnome, LDTP, NetworkManager, Tomboy.
Bug 752057 - local-metadata: Query for media art existence
local-metadata: Query for media art existence
Status: RESOLVED FIXED
Product: grilo
Classification: Other
Component: plugins
unspecified
Other All
: Normal normal
: ---
Assigned To: grilo-maint
grilo-maint
Depends on:
Blocks:
 
 
Reported: 2015-07-07 10:37 UTC by Philip Withnall
Modified: 2015-07-31 10:36 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
local-metadata: Correctly track asynchronous resolve operations (13.67 KB, patch)
2015-07-07 10:37 UTC, Philip Withnall
committed Details | Review
local-metadata: Query for media art existence (4.03 KB, patch)
2015-07-07 10:37 UTC, Philip Withnall
committed Details | Review
local-metadata: Add thumbnails rather than setting them (1.71 KB, patch)
2015-07-07 10:37 UTC, Philip Withnall
rejected Details | Review
local-metadata: don't double-free cancellable (1.53 KB, patch)
2015-07-16 14:51 UTC, Simon McVittie
committed Details | Review

Description Philip Withnall 2015-07-07 10:37:35 UTC
Series of patches to tidy up the local-metadata code for handling asynchronous operations, and use those tidy-ups to ensure that the plugin doesn’t set the thumbnail URI for a GrlMedia to something which doesn’t exist — this is necessary because libmediaart returns paths for media art which it has not checked, so they might not exist.
Comment 1 Philip Withnall 2015-07-07 10:37:38 UTC
Created attachment 306989 [details] [review]
local-metadata: Correctly track asynchronous resolve operations

Currently, only a single asynchronous operation is (potentially) used to
resolve local metadata. However, to fix the problem where the
thumbnail may be set to a non-existent URI, a second asynchronous
operation needs to happen in parallel. The current GrlSourceResolveSpec
closure cannot track this, so a new wrapper closure has to be added
which tracks the number of pending sub-operations and only calls the
GrlSourceResolveSpec’s callback once all are complete, or when a single
one errors.

Signed-off-by: Philip Withnall <philip.withnall@collabora.co.uk>
Comment 2 Philip Withnall 2015-07-07 10:37:43 UTC
Created attachment 306990 [details] [review]
local-metadata: Query for media art existence

Don’t set the media art on a GrlMedia if it doesn’t exist — libmediaart
unconditionally returns a path for where it would expect the media art
for a file to be, without checking that some art actually exists at that
path. That’s our job.

Asynchronously query for the file info to check it exists. Ignore
whether the media art is readable; that’s for the caller to handle when
they try to read it (and is consistent with the other thumbnail URIs
Grilo returns).

Signed-off-by: Philip Withnall <philip.withnall@collabora.co.uk>
Comment 3 Philip Withnall 2015-07-07 10:37:47 UTC
Created attachment 306991 [details] [review]
local-metadata: Add thumbnails rather than setting them

This allows multiple thumbnails to be supported for a particular piece
of local media. For example, this allows both a thumbnail and a piece of
media art to be displayed.

Signed-off-by: Philip Withnall <philip.withnall@collabora.co.uk>
Comment 4 Bastien Nocera 2015-07-07 14:24:31 UTC
Review of attachment 306989 [details] [review]:

You can remove the SOB from the commit message.

The commit subject is also misleading, as there are currently no errors, but those changes are necessary if we want to extend its capabilities.

Looks fine otherwise.
Comment 5 Bastien Nocera 2015-07-07 14:25:14 UTC
Review of attachment 306990 [details] [review]:

Remove the SOB again.

Looks good.
Comment 6 Bastien Nocera 2015-07-07 14:26:47 UTC
Review of attachment 306991 [details] [review]:

Hmm, the problem here is that it means that there's no way for the caller to know which thumbnail we should use, unless they specifically call resolution in a specific order.

In which case is that useful?
Comment 7 Philip Withnall 2015-07-07 14:58:26 UTC
Committed the first two patches with SOB removed, and with the first one’s commit subject tweaked.

Attachment 306990 [details] pushed as 519d205 - local-metadata: Query for media art existence
Comment 8 Philip Withnall 2015-07-07 15:01:45 UTC
(In reply to Bastien Nocera from comment #6)
> Review of attachment 306991 [details] [review] [review]:
> 
> Hmm, the problem here is that it means that there's no way for the caller to
> know which thumbnail we should use, unless they specifically call resolution
> in a specific order.
> 
> In which case is that useful?

I was thinking of it as a way of solving the problem of whether to set the thumbnail or the media art as the GrlMedia’s thumbnail, but you’re right; it just punts the choice to the application instead.

I see two ways of solving this:
 1. Ranking the possible thumbnails so that, for example, we always prefer album art over a thumbnail. This would mean blocking the completion of one of the sub-operations on the other, and would not be fun.
 2. Completely ignoring it, and letting the last sub-operation to complete (successfully) overwrite any previous GrlMedia thumbnail.

I can’t really see one type of thumbnail being any more valuable than another, so I’d be in favour of option #2, but I’m very interested in what you think.
Comment 9 Bastien Nocera 2015-07-07 15:47:35 UTC
(In reply to Philip Withnall from comment #8)
> (In reply to Bastien Nocera from comment #6)
> > Review of attachment 306991 [details] [review] [review] [review]:
> > 
> > Hmm, the problem here is that it means that there's no way for the caller to
> > know which thumbnail we should use, unless they specifically call resolution
> > in a specific order.
> > 
> > In which case is that useful?
> 
> I was thinking of it as a way of solving the problem of whether to set the
> thumbnail or the media art as the GrlMedia’s thumbnail, but you’re right; it
> just punts the choice to the application instead.

Ha, it's useful when the local-metadata plugin sets both the coverart and the thumbnail. In which case it could be useful, but generally, coverart is only set for music and thumbnails for videos. Do we care about thumbnails for audio? Probably not.

So #2 I guess.
Comment 10 Simon McVittie 2015-07-16 13:48:33 UTC
Review of attachment 306990 [details] [review]:

I think this actually has a double-free in it: if we go into the g_file_query_info_async() code path, then we free the GCancellable one time too many.

Because it's freed at the end of the overall operation by the GDestroyNotify, there is no need for resolve_album_art_cb() to free it as well.

::: src/local-metadata/grl-local-metadata.c
@@ +851,3 @@
+  resolve_data = user_data;
+
+  cancellable = grl_operation_get_data (resolve_data->rs->operation_id);

No effect on refcount

@@ +868,3 @@
+  g_clear_object (&info);
+  g_clear_error (&error);
+  g_clear_object (&cancellable);

Consumes one ref

@@ +889,1 @@
+  cancellable = g_cancellable_new ();

Creates one ref

@@ +890,3 @@
+  grl_operation_set_data_full (resolve_data->rs->operation_id,
+                               g_object_ref (cancellable),
+                               (GDestroyNotify) g_object_unref);

Adds one ref now, removes one ref later, therefore no net effect

@@ +908,3 @@
 
+  g_clear_object (&cache_file);
+  g_clear_object (&cancellable);

Consumes one ref
Comment 11 Simon McVittie 2015-07-16 14:51:57 UTC
Created attachment 307563 [details] [review]
local-metadata: don't double-free cancellable

resolve_album_art() is "balanced" with respect to the cancellable's
refcount: it exits with 1 reference to the cancellable owned by
the operation_id, having arranged for that reference to be destroyed
by a GDestroyNotify when the operation_id finishes. There
is no need for resolve_album_art_cb() to release the same reference.

---

Fix for double-free in Attachment #306990 [details]
Comment 12 Bastien Nocera 2015-07-17 12:53:35 UTC
Review of attachment 307563 [details] [review]:

Sure.
Comment 13 Simon McVittie 2015-07-17 15:41:33 UTC
Comment on attachment 307563 [details] [review]
local-metadata: don't double-free cancellable

committed as b5a05ec for 0.2.15
Comment 14 Philip Withnall 2015-07-31 10:35:11 UTC
(In reply to Bastien Nocera from comment #9)
> (In reply to Philip Withnall from comment #8)
> > (In reply to Bastien Nocera from comment #6)
> > > Review of attachment 306991 [details] [review] [review] [review] [review]:
> > > 
> > > Hmm, the problem here is that it means that there's no way for the caller to
> > > know which thumbnail we should use, unless they specifically call resolution
> > > in a specific order.
> > > 
> > > In which case is that useful?
> > 
> > I was thinking of it as a way of solving the problem of whether to set the
> > thumbnail or the media art as the GrlMedia’s thumbnail, but you’re right; it
> > just punts the choice to the application instead.
> 
> Ha, it's useful when the local-metadata plugin sets both the coverart and
> the thumbnail. In which case it could be useful, but generally, coverart is
> only set for music and thumbnails for videos. Do we care about thumbnails
> for audio? Probably not.
> 
> So #2 I guess.

That means we can just drop the patch, so this bug is fixed. Cheers.