diff options
author | Jens Georg <mail@jensge.org> | 2015-07-04 07:59:25 +0200 |
---|---|---|
committer | Jens Georg <mail@jensge.org> | 2015-07-04 12:49:24 +0200 |
commit | ef991d21cb0934de3f0f4a606d5a4a52f71d5abc (patch) | |
tree | 2325f821b71c4617c6126cbc3155094c4d2c7ffc /src | |
parent | 3285e40fbaab49bc98913b548f665151e1fc3a2d (diff) | |
download | rygel-ef991d21cb0934de3f0f4a606d5a4a52f71d5abc.tar.gz |
media-export: Re-add album art extraction
Signed-off-by: Jens Georg <mail@jensge.org>
Diffstat (limited to 'src')
-rw-r--r-- | src/plugins/media-export/rygel-media-export-extract.vala | 15 | ||||
-rw-r--r-- | src/plugins/media-export/rygel-media-export-info-serializer.vala | 62 |
2 files changed, 70 insertions, 7 deletions
diff --git a/src/plugins/media-export/rygel-media-export-extract.vala b/src/plugins/media-export/rygel-media-export-extract.vala index a1fb0c5e..5b10d003 100644 --- a/src/plugins/media-export/rygel-media-export-extract.vala +++ b/src/plugins/media-export/rygel-media-export-extract.vala @@ -45,6 +45,7 @@ DataInputStream input_stream; OutputStream output_stream; OutputStream error_stream; Rygel.InfoSerializer serializer; +MediaArt.Process media_art; public errordomain MetadataExtractorError { GENERAL @@ -207,7 +208,13 @@ int main (string[] args) { return Posix.EXIT_FAILURE; } - serializer = new Rygel.InfoSerializer (); + try { + media_art = new MediaArt.Process (); + } catch (Error error) { + warning (_("Failed to create media art extractor: %s"), + error.message); + } + serializer = new Rygel.InfoSerializer (media_art); Posix.nice (19); var action = new Posix.sigaction_t (); @@ -217,9 +224,9 @@ int main (string[] args) { message ("Started with descriptors %d %d %d", in_fd, out_fd, err_fd); - input_stream = new DataInputStream (new UnixInputStream (in_fd, false)); - output_stream = new UnixOutputStream (out_fd, false); - error_stream = new UnixOutputStream (err_fd, false); + input_stream = new DataInputStream (new UnixInputStream (in_fd, true)); + output_stream = new UnixOutputStream (out_fd, true); + error_stream = new UnixOutputStream (err_fd, true); loop = new MainLoop (); try { diff --git a/src/plugins/media-export/rygel-media-export-info-serializer.vala b/src/plugins/media-export/rygel-media-export-info-serializer.vala index 3e46caa2..f2607e8f 100644 --- a/src/plugins/media-export/rygel-media-export-info-serializer.vala +++ b/src/plugins/media-export/rygel-media-export-info-serializer.vala @@ -28,7 +28,13 @@ internal errordomain InfoSerializerError { BAD_MIME } -internal class Rygel.InfoSerializer { +internal class Rygel.InfoSerializer : GLib.Object { + public MediaArt.Process? media_art { get; construct set; } + + public InfoSerializer (MediaArt.Process? media_art) { + GLib.Object (media_art: media_art); + } + public Variant serialize (File file, FileInfo file_info, DiscovererInfo? info, @@ -68,7 +74,7 @@ internal class Rygel.InfoSerializer { audio_streams.data : null), this.serialize_video_info (video_streams != null ? video_streams.data : null), - this.serialize_meta_data (audio_streams != null ? + this.serialize_meta_data (file, audio_streams != null ? audio_streams.data : null)); } else { string? upnp_class = null; @@ -176,7 +182,8 @@ internal class Rygel.InfoSerializer { } - private Variant? serialize_meta_data (DiscovererAudioInfo? info) { + private Variant? serialize_meta_data (File file, + DiscovererAudioInfo? info) { if (info == null) { return null; } @@ -204,6 +211,55 @@ internal class Rygel.InfoSerializer { uint bitrate = uint.MAX; tags.get_uint (Tags.BITRATE, out bitrate); + Sample sample; + tags.get_sample (Tags.IMAGE, out sample); + if (sample == null) { + tags.get_sample (Tags.PREVIEW_IMAGE, out sample); + } + + if (sample == null) { + try { + if (artist != null || album != null) { + this.media_art.file (MediaArt.Type.ALBUM, + MediaArt.ProcessFlags.NONE, + file, + artist, + album); + } + } catch (Error error) { + debug ("Failed to add external media art: %s", error.message); + } + } else { + unowned Structure structure = sample.get_caps ().get_structure (0); + int image_type; + structure.get_enum ("image-type", + typeof (Gst.Tag.ImageType), + out image_type); + if (image_type == Tag.ImageType.UNDEFINED || + image_type == Tag.ImageType.FRONT_COVER) { + MapInfo map_info; + sample.get_buffer ().map (out map_info, Gst.MapFlags.READ); + + // work-around for bgo#739915 + weak uint8[] data = map_info.data; + data.length = (int) map_info.size; + + try { + this.media_art.buffer (MediaArt.Type.ALBUM, + MediaArt.ProcessFlags.NONE, + file, + data, + structure.get_name (), + artist, + album); + } catch (Error error) { + debug ("Failed to add media art to cache: %s", + error.message); + } + sample.get_buffer ().unmap (map_info); + } + } + return new Variant ("(msmsmsiii)", artist, album, |