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 337438 - Information for flac files yields "unknown"
Information for flac files yields "unknown"
Status: RESOLVED FIXED
Product: rhythmbox
Classification: Other
Component: User Interface
0.9.x
Other All
: Normal minor
: ---
Assigned To: RhythmBox Maintainers
RhythmBox Maintainers
Depends on:
Blocks:
 
 
Reported: 2006-04-05 21:14 UTC by Adam Petaccia
Modified: 2009-06-02 12:52 UTC
See Also:
GNOME target: ---
GNOME version: ---


Attachments
Patch File To Check for FLAC mime-type (768 bytes, patch)
2009-03-31 04:51 UTC, Paul Bellamy
needs-work Details | Review
Proposed patch to display FLAC files as Lossless (2.49 KB, patch)
2009-04-01 00:28 UTC, Paul Bellamy
needs-work Details | Review
Proposed patch to display FLAC files as Lossless (4.02 KB, patch)
2009-04-02 05:27 UTC, Paul Bellamy
needs-work Details | Review
Proposed Patch (4.52 KB, patch)
2009-04-02 22:38 UTC, Paul Bellamy
none Details | Review
Proposed Patch (4.55 KB, patch)
2009-04-05 18:04 UTC, Paul Bellamy
committed Details | Review

Description Adam Petaccia 2006-04-05 21:14:38 UTC
FLAC files are lossless.  Rather than specifying that there is an unknown
bitrate, perhaps it should display either the string "lossless" or "1411" (which
I think is what CDs are... or I remember seeing that before)

Other information:
gstreamer0.8
Comment 1 Adam Petaccia 2006-06-25 21:35:34 UTC
Still a bug in with gstreamer0.10, Rhythmbox 0.9.5.
Comment 2 James "Doc" Livingston 2006-06-28 03:42:45 UTC
It would be relatively easy to do, just make the "quality" column check the mime-type. However there a are a few things that need considering:

* we'd then probably need to allow people to use "quality = lossless" for playlist criteria
* we'd need to make it sort correctly
* the list of what we consider lossless would need to be hardcoded, unless someone can think of a way to determine it at runtime
Comment 3 Adam Petaccia 2006-06-28 11:22:59 UTC
I think an "easy" way to do take care of number one (and maybe three) would have it to _display_ lossless, but actually hold the value 1411kbps or something along those lines.  
Comment 4 Paul Bellamy 2009-03-31 04:51:59 UTC
Created attachment 131750 [details] [review]
Patch File To Check for FLAC mime-type

This is a patch, which makes the info-widget check the mime-type for a flac file.
Comment 5 Jonathan Matthew 2009-03-31 05:25:03 UTC
Your patch is backwards.  If you're working from a svn checkout, you can just do 'svn diff' to generate a patch to attach.

The comparison could be written a bit more simply:

  const char *type = rhythmdb_entry_get_string (entry, RHYTHMDB_PROP_MIMETYPE);
  if (g_str_equal (type, "audio/x-flac")) {
     ...
  } else {
     ...
  }

This only addresses one aspect of this problem (the song info dialog).  I'd suggest adding a helper function (probably in lib/rb-util.c) to figure out if a database entry represents a lossless encoding or not.  Initially this can just check if the media type is audio/x-flac, but it might get more complicated than that.

The other two things you'd need to do: modify the 'quality' cell data function in rb-entry-view.c to display _("Lossless") for lossless encodings, and add a specialised sort function for the quality column that sorts lossless entries appropriately.

I don't know what to do about allowing 'quality = lossless' in auto playlists.

(unless you're going to follow all rhythmbox bugzilla activity, you should add yourself to the cc list for bugs you're interested in)
Comment 6 Paul Bellamy 2009-03-31 15:47:55 UTC
What about changing how it imports the files? So that if it imports a flac file, it stores the bitrate as 1411.  It wouldn't fix the display for already imported files, but would technically solve the issue.
Comment 7 Jonathan Matthew 2009-03-31 22:10:50 UTC
I don't like that idea at all.
Comment 8 Paul Bellamy 2009-04-01 00:28:22 UTC
Created attachment 131815 [details] [review]
Proposed patch to display FLAC files as Lossless

 - Added rb_check_lossless function to lib/rb-util.h and lib/rb-util.c
 - Modified rb-entry-view.c and rb-song-info.c to use rb_check_lossless and display accordingly.
 - rb-song-info.c now depends on rb-util.h

Not sure how to change the sorting order.  Does it use gtk_tree_view_column_set_sort_order to resort the entries when the sort order is changed?

Thanks for putting up with me.  Sorry if some of my questions/suggestions are sort of dumb, this is my first time contributing to a project.
Comment 9 Jonathan Matthew 2009-04-01 01:27:52 UTC

>  gboolean
> +rb_check_lossless (const char *mime_type) {

I was thinking this would take a RhythmDBEntry, not a media type, since there may be other checks we'd want to do, such as checking if the URI starts with 'cdda://'.  'rb_entry_is_lossless' is probably a better name for it too.  Also, just as a style thing, the opening brace for a function body goes on the next line.

For sorting, the entry view widget and the source containing it take care of re-sorting the track list when the sort column changes.  Each column has an associated sort function that compares two entries.

All you need to do is add a new sort function to rhythmdb-query-model.c that compares the bitrate property taking lossless encodings into consideration.  You can base this on rhythmdb_query_model_ulong_sort_func, which is what is currently used for to compare bitrates.  Then, in widgets/rb-entry-view.c, use the new sort function for the 'quality' column (line 1488).

You should also add the translation for "Lossless" to the set of strings used to calculate the width of the quality column (lines 1491 to 1493 of rb-entry-view.c).

> Thanks for putting up with me.  Sorry if some of my questions/suggestions are
> sort of dumb, this is my first time contributing to a project.

Don't worry, you're doing fine.

I should probably explain why I don't like the idea of setting a fake bitrate.  It mostly just feels wrong to insert fake data to get sorting right when we don't really have enough information to do it correctly, and we can get the same results without it.
Comment 10 Paul Bellamy 2009-04-01 22:49:08 UTC
(In reply to comment #9)
> >  gboolean
> > +rb_check_lossless (const char *mime_type) {
> 
> I was thinking this would take a RhythmDBEntry, not a media type, since there
> may be other checks we'd want to do, such as checking if the URI starts with
> 'cdda://'.  'rb_entry_is_lossless' is probably a better name for it too.

I had made it a string because RhythmDBEntry is not defined in rb-util.h.  Should I include 'rhythmdb.h' into 'rb-util.h' (seems ugly), or how should I handle that?
Comment 11 Jonathan Matthew 2009-04-02 02:06:00 UTC
Good point.  I guess that function belongs in rhythmdb.c.
Comment 12 Paul Bellamy 2009-04-02 05:27:51 UTC
Created attachment 131893 [details] [review]
Proposed patch to display FLAC files as Lossless

Implemented
-> rb_entry_is_lossless (RhythmDBEntry *entry) in rhythmdb.c
-> rhythmdb_query_model_bitrate_sort_func in rhythmdb-query-model.c
-> Set rb-entry-view.c to display "Lossless"
-> Set rb-song-info.c to display "Lossless"
-> Set rb-entry-view.c to sort using rhythmdb_query_model_bitrate_sort_func

Not Done
-> Add _("Lossless") to strings[] in rb-entry-view.c
        -> Reason: Causes SegFault?
Comment 13 Jonathan Matthew 2009-04-02 07:02:09 UTC
If it's going in rhythmdb.c, it should be named rhythmdb_entry_is_lossless.  We sort of pretend rhythmdb is a different code base.  I don't really know why.

> Not Done
> -> Add _("Lossless") to strings[] in rb-entry-view.c
>         -> Reason: Causes SegFault?

The array currently only has four elements, and it needs to have a trailing NULL.  We just need to expand it to 5.

Other than that, this looks pretty good.
Comment 14 Paul Bellamy 2009-04-02 22:38:38 UTC
Created attachment 131945 [details] [review]
Proposed Patch

Fixed size of 'strings[]'
Comment 15 Jonathan Matthew 2009-04-05 10:34:06 UTC
We could probably make the media type check more efficient.  Since it's a reference counted string, we can just do a pointer comparison.  That'd be a bit ugly though.

I was just about to commit this when I realised there's a bit of inconsistency here.  The sort function doesn't check that the bitrate value is 0 first, but the other two places do.  I don't think this would actually cause any problems, but the checks should all work the same way.
Comment 16 Paul Bellamy 2009-04-05 18:04:21 UTC
Created attachment 132141 [details] [review]
Proposed Patch

Unfortunately, if we have
if (a_val != b_val)
  do stuff
else
  lossless checks here

Since, Lossless files still technically have a bitrate of 0.
It will sort the files like: 320kbps, 120kbps, Lossless, Unknown

So, we have to run the lossless tests first to sort them: Lossless, 320kbps, 120kbps, Unknown

am I correct on that?

(regardless, I cleaned up the sorting function, into two if-else blocks)
Comment 17 Jonathan Matthew 2009-04-06 11:53:15 UTC
> Since, Lossless files still technically have a bitrate of 0.
> It will sort the files like: 320kbps, 120kbps, Lossless, Unknown
> 
> So, we have to run the lossless tests first to sort them: Lossless, 320kbps,
> 120kbps, Unknown
> 
> am I correct on that?
> 

Yes, that's correct.  I didn't really think it through.  It's not really important, certainly less important than having the code actually work properly.

(In reply to comment #16)
> Created an attachment (id=132141) [edit]
> Proposed Patch
> 
> Unfortunately, if we have
> if (a_val != b_val)
>   do stuff
> else
>   lossless checks here
> 
> (regardless, I cleaned up the sorting function, into two if-else blocks)

I much preferred the previous version.  The ternary operator almost always makes the code harder to read, without really buying much.
Comment 18 Jonathan Matthew 2009-04-07 06:33:48 UTC
I've tidied up a few things, tested a bit to make sure I didn't break it too obviously, and committed it.  We can use a new bug for the playlist criteria thing if you're interested in working on that.

2009-04-07  Jonathan Matthew  <jonathan@d14n.org>

        patch by:  Paul Bellamy  <paul.a.bellamy@gmail.com>

        * rhythmdb/rhythmdb.c: (rhythmdb_entry_is_lossless):
        * rhythmdb/rhythmdb.h:
        Add a function to determine if an entry represents a lossless encoded
        stream.  This currently just checks that the bitrate field is 0 and
        the media type is 'audio/x-flac'.  More media types and other checks
        can be added later.

        * rhythmdb/rhythmdb-query-model.c:
        (rhythmdb_query_model_bitrate_sort_func):
        * rhythmdb/rhythmdb-query-model.h:
        Add a query model sort function for bitrate comparisons, sorting
        lossless encodings as being of higher quality than anything with a
        bitrate.  Not exactly correct, but it's the best we can do.

        * widgets/rb-entry-view.c: (rb_entry_view_quality_cell_data_func),
        (rb_entry_view_append_column):
        * widgets/rb-song-info.c: (rb_song_info_update_bitrate):
        Display "Lossless" for lossless encodings in the 'quality' column in
        track lists and the same field in the song info dialog.

        Fixes #337438.
Comment 19 Paul Bellamy 2009-04-07 15:35:36 UTC
Sure, that sounds good.
Comment 20 Hew McLachlan 2009-06-02 12:45:50 UTC
With rhythmbox 0.12.2, many of my flac files are now "Lossless", but some are still "Unknown". 
Comment 21 Jonathan Matthew 2009-06-02 12:52:53 UTC
They're probably flac-in-ogg or flac files with id3 tags.  We can't display those properly without some significant changes elsewhere.