[rygel] media-export: Use common constants for serialisation
- From: Jens Georg <jensgeorg src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [rygel] media-export: Use common constants for serialisation
- Date: Sun, 26 Jun 2016 21:25:02 +0000 (UTC)
commit 07ffa9196955c72ea19aa4219c0d6335fe065823
Author: Jens Georg <mail jensge org>
Date: Mon May 16 12:00:48 2016 +0200
media-export: Use common constants for serialisation
src/plugins/media-export/Makefile.am | 4 +-
src/plugins/media-export/constants.vala | 43 ++++
.../rygel-media-export-dvd-parser.vala | 16 +-
.../media-export/rygel-media-export-extractor.vala | 18 +-
.../rygel-media-export-generic-extractor.vala | 40 ++--
.../rygel-media-export-harvesting-task.vala | 2 +-
.../rygel-media-export-image-extractor.vala | 29 ++-
.../rygel-media-export-info-serializer.vala | 258 +++++--------------
.../rygel-media-export-playlist-extractor.vala | 10 +-
9 files changed, 178 insertions(+), 242 deletions(-)
---
diff --git a/src/plugins/media-export/Makefile.am b/src/plugins/media-export/Makefile.am
index 3724eda..cee3351 100644
--- a/src/plugins/media-export/Makefile.am
+++ b/src/plugins/media-export/Makefile.am
@@ -9,12 +9,14 @@ include $(top_srcdir)/common.am
## Extraction helper
pkglibexec_PROGRAMS = mx-extract
mx_extract_SOURCES = \
+ constants.vala \
rygel-media-export-extract.vala \
rygel-media-export-dvd-parser.vala \
rygel-media-export-playlist-extractor.vala \
rygel-media-export-image-extractor.vala \
rygel-media-export-extractor.vala \
- rygel-media-export-generic-extractor.vala
+ rygel-media-export-generic-extractor.vala \
+ rygel-media-export-info-serializer.vala
mx_extract_VALAFLAGS = \
--enable-experimental \
diff --git a/src/plugins/media-export/constants.vala b/src/plugins/media-export/constants.vala
new file mode 100644
index 0000000..783c3bf
--- /dev/null
+++ b/src/plugins/media-export/constants.vala
@@ -0,0 +1,43 @@
+/*
+ * Copyright (C) 2016 Jens Georg <mail jensge org>
+ *
+ * Author: Jens Georg <mail jensge org>
+ *
+ * This file is part of Rygel.
+ *
+ * Rygel is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public
+ * License as published by the Free Software Foundation; either
+ * version 2.1 of the License, or (at your option) any later version.
+ *
+ * Rygel is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this library; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
+ */
+
+namespace Rygel.MediaExport.Serializer {
+ public const string TITLE = "Title";
+ public const string MODIFIED = "MTime";
+ public const string MIME_TYPE = "MimeType";
+ public const string SIZE = "Size";
+ public const string UPNP_CLASS = "UPnPClass";
+ public const string DURATION = "Duration";
+ public const string VIDEO_WIDTH = "VideoWidth";
+ public const string VIDEO_HEIGHT = "VideoHeight";
+ public const string DLNA_PROFILE = "DLNAProfile";
+ public const string ARTIST = "Artist";
+ public const string DATE = "Date";
+ public const string VIDEO_DEPTH = "VideoDepth";
+ public const string AUDIO_CHANNELS = "AudioChannels";
+ public const string AUDIO_RATE = "AudioRate";
+ public const string ALBUM = "Album";
+ public const string GENRE = "Genre";
+ public const string VOLUME_NUMBER = "VolumeNumber";
+ public const string TRACK_NUMBER = "TrackNumber";
+ public const string AUDIO_BITRATE = "AudioBitrate";
+}
diff --git a/src/plugins/media-export/rygel-media-export-dvd-parser.vala
b/src/plugins/media-export/rygel-media-export-dvd-parser.vala
index 4a02362..9e950aa 100644
--- a/src/plugins/media-export/rygel-media-export-dvd-parser.vala
+++ b/src/plugins/media-export/rygel-media-export-dvd-parser.vala
@@ -78,10 +78,10 @@ internal class Rygel.MediaExport.DVDParser : Extractor {
if ((xpo != null) &&
(xpo->type == Xml.XPath.ObjectType.NODESET) &&
(xpo->nodesetval->length () == 1)) {
- this.serialized_info.insert ("UPnPClass",
+ this.serialized_info.insert (Serializer.UPNP_CLASS,
"s",
UPNP_CLASS_DVD_TRACK);
- this.serialized_info.insert ("MimeType", "s", "video/mpeg");
+ this.serialized_info.insert (Serializer.MIME_TYPE, "s", "video/mpeg");
var node = xpo->nodesetval->item (0);
@@ -90,22 +90,22 @@ internal class Rygel.MediaExport.DVDParser : Extractor {
if (it->name == "length") {
var duration = (int) double.parse (it->children->content);
- this.serialized_info.insert ("Duration",
+ this.serialized_info.insert (Serializer.DURATION,
"i",
duration);
} else if (it->name == "width") {
var width = int.parse (it->children->content);
- this.serialized_info.insert ("VideoWidth",
+ this.serialized_info.insert (Serializer.VIDEO_WIDTH,
"i",
width);
} else if (it->name == "height") {
var height = int.parse (it->children->content);
- this.serialized_info.insert ("VideoHeight",
+ this.serialized_info.insert (Serializer.VIDEO_HEIGHT,
"i",
height);
} else if (it->name == "format") {
var dlna_profile = "MPEG_PS_" + it->children->content;
- this.serialized_info.insert ("DLNAProfile",
+ this.serialized_info.insert (Serializer.DLNA_PROFILE,
"s",
dlna_profile);
}
@@ -114,10 +114,10 @@ internal class Rygel.MediaExport.DVDParser : Extractor {
it = it->next;
}
} else {
- this.serialized_info.insert ("UPnPClass",
+ this.serialized_info.insert (Serializer.UPNP_CLASS,
"s",
UPNP_CLASS_PLAYLIST_CONTAINER_DVD);
- this.serialized_info.insert ("MimeType",
+ this.serialized_info.insert (Serializer.MIME_TYPE,
"s",
"application/x-cd-image");
}
diff --git a/src/plugins/media-export/rygel-media-export-extractor.vala
b/src/plugins/media-export/rygel-media-export-extractor.vala
index 97dfed1..261a7c1 100644
--- a/src/plugins/media-export/rygel-media-export-extractor.vala
+++ b/src/plugins/media-export/rygel-media-export-extractor.vala
@@ -100,18 +100,24 @@ public class Rygel.MediaExport.Extractor : Object {
this.serialized_info.insert ("DisplayName", "s", display_name);
var title = this.strip_invalid_entities (display_name);
- this.serialized_info.insert ("Title", "s", title);
+ this.serialized_info.insert (Serializer.TITLE, "s", title);
- this.serialized_info.insert ("MTime", "t", file_info.get_attribute_uint64
- (FileAttribute.TIME_MODIFIED));
+ var mtime = file_info.get_attribute_uint64
+ (FileAttribute.TIME_MODIFIED);
+ this.serialized_info.insert (Serializer.MODIFIED, "t", mtime);
var content_type = ContentType.get_mime_type
(file_info.get_content_type ());
- this.serialized_info.insert ("MimeType", "s", content_type);
- this.serialized_info.insert ("Size", "t", file_info.get_size ());
+ this.serialized_info.insert (Serializer.MIME_TYPE, "s", content_type);
+ this.serialized_info.insert (Serializer.SIZE, "t", file_info.get_size ());
}
public new Variant? @get () {
- return this.serialized_info.end ();
+ var s = new Rygel.InfoSerializer ();
+ try {
+ return s.serialize (this.serialized_info);
+ } catch (Error error) {
+ return null;
+ }
}
private string strip_invalid_entities (string original) {
diff --git a/src/plugins/media-export/rygel-media-export-generic-extractor.vala
b/src/plugins/media-export/rygel-media-export-generic-extractor.vala
index 35cd65d..97ca444 100644
--- a/src/plugins/media-export/rygel-media-export-generic-extractor.vala
+++ b/src/plugins/media-export/rygel-media-export-generic-extractor.vala
@@ -73,8 +73,6 @@ internal class Rygel.MediaExport.GenericExtractor: Extractor {
var uri = this.file.get_uri ();
if (path != null) {
- warning ("Using local path %s instead of %s",
- path, uri);
uri = Filename.to_uri (path);
}
@@ -122,7 +120,7 @@ internal class Rygel.MediaExport.GenericExtractor: Extractor {
this.upnp_class = UPNP_CLASS_MUSIC;
}
- this.serialized_info.insert ("UPnPClass", "s", upnp_class);
+ this.serialized_info.insert (Serializer.UPNP_CLASS, "s", upnp_class);
var dlna_info = GUPnPDLNAGst.utils_information_from_discoverer_info
(info);
@@ -130,15 +128,15 @@ internal class Rygel.MediaExport.GenericExtractor: Extractor {
(dlna_info);
if (dlna != null) {
- this.serialized_info.insert ("DLNAProfile", "s", dlna.name,
- "MimeType", "s", dlna.mime);
+ this.serialized_info.insert (Serializer.DLNA_PROFILE, "s", dlna.name);
+ this.serialized_info.insert (Serializer.MIME_TYPE, "s", dlna.mime);
}
- this.serialized_info.lookup ("MimeType", "s", out this.mime_type);
+ this.serialized_info.lookup (Serializer.MIME_TYPE, "s", out this.mime_type);
long duration = -1;
if (info.get_duration () > 0) {
duration = (long) (info.get_duration () / Gst.SECOND);
- this.serialized_info.insert ("Duration", "i", duration);
+ this.serialized_info.insert (Serializer.DURATION, "i", duration);
}
// Info has several tags, general and on audio info for music files
@@ -148,7 +146,7 @@ internal class Rygel.MediaExport.GenericExtractor: Extractor {
if (tags.get_string (Tags.TITLE, out title)) {
// If not AVI file, replace title we guessed from filename
if (this.mime_type != "video/x-msvideo" && title != null) {
- this.serialized_info.insert ("Title", "s", title);
+ this.serialized_info.insert (Serializer.TITLE, "s", title);
}
}
@@ -167,58 +165,60 @@ internal class Rygel.MediaExport.GenericExtractor: Extractor {
date = dt.to_iso8601_string ();
}
- this.serialized_info.insert ("Date", "s", date);
+ this.serialized_info.insert (Serializer.DATE, "s", date);
}
}
if (video_streams != null && video_streams.data != null) {
var vinfo = (DiscovererVideoInfo) video_streams.data;
- this.serialized_info.insert ("VideoWidth", "i",
+ this.serialized_info.insert (Serializer.VIDEO_WIDTH, "i",
(int) vinfo.get_width ());
- this.serialized_info.insert ("VideoHeight", "i",
+ this.serialized_info.insert (Serializer.VIDEO_HEIGHT, "i",
(int) vinfo.get_height ());
- this.serialized_info.insert ("VideoDepth", "i",
+ this.serialized_info.insert (Serializer.VIDEO_DEPTH, "i",
vinfo.get_depth () > 0 ?
vinfo.get_depth () : -1);
}
if (audio_streams != null && audio_streams.data != null) {
var ainfo = (DiscovererAudioInfo) audio_streams.data;
- this.serialized_info.insert ("AudioChannels", "i",
+ this.serialized_info.insert (Serializer.AUDIO_CHANNELS, "i",
(int) ainfo.get_channels ());
- this.serialized_info.insert ("AudioRate", "i",
+ this.serialized_info.insert (Serializer.AUDIO_RATE, "i",
(int) ainfo.get_sample_rate ());
var atags = ainfo.get_tags ();
if (atags != null) {
string artist = null;
if (atags.get_string (Tags.ARTIST, out artist) &&
this.mime_type != "video/x-msvideo") {
- this.serialized_info.insert ("Artist", "s", artist);
+ this.serialized_info.insert (Serializer.ARTIST, "s", artist);
}
string album = null;
if (atags.get_string (Tags.ALBUM, out album)) {
- this.serialized_info.insert ("Album", "s", album);
+ this.serialized_info.insert (Serializer.ALBUM, "s", album);
}
string genre = null;
if (atags.get_string (Tags.GENRE, out genre)) {
- this.serialized_info.insert ("Genre", "s", genre);
+ this.serialized_info.insert (Serializer.GENRE, "s", genre);
}
uint volume = uint.MAX;
if (atags.get_uint (Tags.ALBUM_VOLUME_NUMBER, out volume)) {
- this.serialized_info.insert ("VolumeNumber", "i", volume);
+ this.serialized_info.insert (Serializer.VOLUME_NUMBER,
+ "i",
+ volume);
}
uint track = uint.MAX;
if (atags.get_uint (Tags.TRACK_NUMBER, out track)) {
- this.serialized_info.insert ("Track", "i", track);
+ this.serialized_info.insert (Serializer.TRACK_NUMBER, "i", track);
}
uint bitrate = uint.MAX;
if (atags.get_uint (Tags.BITRATE, out bitrate)) {
- this.serialized_info.insert ("AudioBitrate", "i",
+ this.serialized_info.insert (Serializer.AUDIO_BITRATE, "i",
((int) bitrate) / 8);
}
diff --git a/src/plugins/media-export/rygel-media-export-harvesting-task.vala
b/src/plugins/media-export/rygel-media-export-harvesting-task.vala
index 2a20dab..8a803e9 100644
--- a/src/plugins/media-export/rygel-media-export-harvesting-task.vala
+++ b/src/plugins/media-export/rygel-media-export-harvesting-task.vala
@@ -297,7 +297,7 @@ public class Rygel.MediaExport.HarvestingTask : Rygel.StateMachine,
} else {
// nothing to do
this.completed ();
- debug ("Harvesting of %s done in %f",
+ message ("Harvesting of %s done in %f",
origin.get_uri (),
timer.elapsed ());
}
diff --git a/src/plugins/media-export/rygel-media-export-image-extractor.vala
b/src/plugins/media-export/rygel-media-export-image-extractor.vala
index 7652266..ee1d2ff 100644
--- a/src/plugins/media-export/rygel-media-export-image-extractor.vala
+++ b/src/plugins/media-export/rygel-media-export-image-extractor.vala
@@ -28,6 +28,8 @@ internal class Rygel.MediaExport.ImageExtractor : Extractor {
}
public override async void run () throws Error {
+ yield base.run ();
+
int width;
int height;
@@ -38,30 +40,33 @@ internal class Rygel.MediaExport.ImageExtractor : Extractor {
var mime = format.get_mime_types ()[0];
// TODO: Use enhanced EXIF information?
- this.serialized_info.insert ("UPnPClass", "s", UPNP_CLASS_PHOTO);
- this.serialized_info.insert ("MimeType", "s", mime);
+ this.serialized_info.insert (Serializer.UPNP_CLASS, "s",
+ UPNP_CLASS_PHOTO);
+
+ this.serialized_info.insert (Serializer.MIME_TYPE, "s", mime);
+ this.serialized_info.insert (Serializer.VIDEO_WIDTH, "i", width);
+ this.serialized_info.insert (Serializer.VIDEO_HEIGHT, "i", height);
- this.serialized_info.insert ("VideoWidth", "i", width);
- this.serialized_info.insert ("VideoHeight", "i", height);
+ string? profile = null;
if (mime == "image/png") {
if (width <= 4096 && height <= 4096) {
- this.serialized_info.insert ("DLNAProfile", "s", "PNG_LRG");
+ profile = "PNG_LRG";
} else {
- var profile = "PNG_RES_%d_%d".printf (width, height);
- this.serialized_info.insert ("DLNAProfile", "s", profile);
+ profile = "PNG_RES_%d_%d".printf (width, height);
}
} else {
if (width <= 640 && height <= 480) {
- this.serialized_info.insert ("DLNAProfile", "s", "JPG_SM");
+ profile = "JPEG_SM";
} else if (width <= 1024 && height <= 768) {
- this.serialized_info.insert ("DLNAProfile", "s", "JPG_MED");
+ profile = "JPEG_MED";
} else if (width <= 4096 && height <= 4096) {
- this.serialized_info.insert ("DLNAProfile", "s", "JPEG_LRG");
+ profile = "JPEG_LRG";
} else {
- var profile = "JPEG_RES_%d_%d".printf (width, height);
- this.serialized_info.insert ("DLNAProfile", "s", profile);
+ profile = "JPEG_RES_%d_%d".printf (width, height);
}
}
+
+ this.serialized_info.insert (Serializer.DLNA_PROFILE, "s", profile);
}
}
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 e8d4568..203747e 100644
--- a/src/plugins/media-export/rygel-media-export-info-serializer.vala
+++ b/src/plugins/media-export/rygel-media-export-info-serializer.vala
@@ -22,6 +22,7 @@
using Gst;
using Gst.PbUtils;
+using Rygel.MediaExport;
internal errordomain InfoSerializerError {
INVALID_STREAM,
@@ -29,130 +30,53 @@ internal errordomain InfoSerializerError {
}
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,
- GUPnPDLNA.Profile? dlna_profile) throws Error {
- // Guess UPnP class
- if (info != null) {
- string? upnp_class = null;
-
- var audio_streams = (GLib.List<DiscovererAudioInfo>)
- info.get_audio_streams ();
- var video_streams = (GLib.List<DiscovererVideoInfo>)
- info.get_video_streams ();
- if (audio_streams == null && video_streams == null) {
- debug ("%s had neither audio nor video/picture " +
- "streams. Ignoring.",
- file.get_uri ());
-
- throw new InfoSerializerError.INVALID_STREAM ("No stream information");
- }
-
- if (audio_streams == null && video_streams.data.is_image ()) {
- upnp_class = UPNP_CLASS_PHOTO;
- } else if (video_streams != null) {
- upnp_class = UPNP_CLASS_VIDEO;
- } else if (audio_streams != null) {
- upnp_class = UPNP_CLASS_MUSIC;
- } else {
- // Uh...
- }
-
- return new Variant ("(smvmvmvmvmvmv)",
- upnp_class,
- this.serialize_file_info (file_info),
- this.serialize_dlna_profile (dlna_profile),
- this.serialize_info (info),
- this.serialize_audio_info (audio_streams != null ?
- audio_streams.data : null),
- this.serialize_video_info (video_streams != null ?
- video_streams.data : null),
- this.serialize_meta_data (file, audio_streams != null ?
- audio_streams.data : null));
- } else {
- string? upnp_class = null;
- var mime = ContentType.get_mime_type (file_info.get_content_type ());
- if (mime.has_prefix ("video/")) {
- upnp_class = UPNP_CLASS_VIDEO;
- } else if (mime.has_prefix ("image/")) {
- upnp_class = UPNP_CLASS_PHOTO;
- } else if (mime.has_prefix ("audio/") || mime == "application/ogg") {
- upnp_class = UPNP_CLASS_MUSIC;
- } else if (mime.has_suffix ("/xml")) { // application/xml or text/xml
- upnp_class = UPNP_CLASS_PLAYLIST;
- } else if (mime == "application/x-cd-image") {
- upnp_class = UPNP_CLASS_PLAYLIST_CONTAINER_DVD;
- } else {
- debug ("Unsupported content-type %s, skipping %s…",
- mime,
- file.get_uri ());
-
- throw new InfoSerializerError.BAD_MIME ("Not supported: %s", mime);
- }
-
- return new Variant ("(smvmvmvmvmvmv)",
- upnp_class,
- this.serialize_file_info (file_info),
- null,
- null,
- null,
- null,
- null);
- }
+ private VariantType? t = null;
+
+ public Variant serialize (VariantDict in_v) throws Error {
+ return new Variant ("(smvmvmvmvmvmv)",
+ in_v.lookup_value
+ (Serializer.UPNP_CLASS, this.t).get_string (),
+ this.serialize_file_info (in_v),
+ this.serialize_dlna_profile (in_v),
+ this.serialize_info (in_v),
+ this.serialize_audio_info (in_v),
+ this.serialize_video_info (in_v),
+ this.serialize_meta_data (in_v));
}
- private Variant serialize_file_info (FileInfo info) {
+ private Variant serialize_file_info (VariantDict in_v) {
return new Variant ("(stst)",
- info.get_display_name (),
- info.get_attribute_uint64
- (FileAttribute.TIME_MODIFIED),
- ContentType.get_mime_type
- (info.get_content_type ()),
- info.get_size ());
+ in_v.lookup_value (Serializer.TITLE,
+ this.t).get_string (),
+ in_v.lookup_value (Serializer.MODIFIED,
+ this.t).get_uint64 (),
+ in_v.lookup_value (Serializer.MIME_TYPE,
+ this.t).get_string (),
+ in_v.lookup_value (Serializer.SIZE,
+ this.t).get_uint64 ());
}
- private Variant? serialize_dlna_profile (GUPnPDLNA.Profile? profile) {
- if (profile == null) {
+ private Variant? serialize_dlna_profile (VariantDict in_v) {
+ var val = in_v.lookup_value (Serializer.DLNA_PROFILE, this.t);
+ if (val == null) {
return null;
}
- return new Variant ("(ss)", profile.name, profile.mime);
+ return new Variant ("(ss)",
+ val.get_string (),
+ in_v.lookup_value
+ (Serializer.MIME_TYPE, this.t).get_string ());
}
- private Variant? serialize_info (DiscovererInfo? info) {
+ private Variant? serialize_info (VariantDict in_v) {
long duration = -1;
- if (info.get_duration () > 0) {
- duration = (long) (info.get_duration () / Gst.SECOND);
- }
+ in_v.lookup (Serializer.DURATION, "i", out duration);
- var tags = info.get_tags ();
string? title = null;
- if (tags != null) {
- tags.get_string (Tags.TITLE, out title);
- }
+ in_v.lookup (Serializer.TITLE, "s", out title);
- string date = null;
- Gst.DateTime? dt = null;
- if (tags != null && tags.get_date_time (Tags.DATE_TIME, out dt)) {
- // Make a minimal valid iso8601 date - bgo#702231
- // This mostly happens with MP3 files which only have a year
- if (!dt.has_day () || !dt.has_month ()) {
- date = "%d-%02d-%02d".printf (dt.get_year (),
- dt.has_month () ?
- dt.get_month () : 1,
- dt.has_day () ?
- dt.get_day () : 1);
- } else {
- date = dt.to_iso8601_string ();
- }
- }
+ string? date = null;
+ in_v.lookup (Serializer.DATE, "s", out date);
return new Variant ("(msmsi)",
title,
@@ -160,105 +84,59 @@ internal class Rygel.InfoSerializer : GLib.Object {
duration);
}
- private Variant? serialize_video_info (DiscovererVideoInfo? info) {
- if (info == null) {
- return null;
- }
+ private Variant? serialize_video_info (VariantDict in_v) {
+ int width = -1;
+ int height = -1;
+ int depth = -1;
- return new Variant ("(iii)",
- (int) info.get_width (),
- (int) info.get_height (),
- info.get_depth () > 0 ?
- info.get_depth () : -1);
- }
+ in_v.lookup (Serializer.VIDEO_WIDTH, "i", out width);
+ in_v.lookup (Serializer.VIDEO_HEIGHT, "i", out height);
+ in_v.lookup (Serializer.VIDEO_DEPTH, "i", out depth);
- private Variant? serialize_audio_info (DiscovererAudioInfo? info) {
- if (info == null) {
+
+ if (width == -1 && height == -1) {
return null;
}
- return new Variant ("(ii)",
- (int) info.get_channels (),
- (int) info.get_sample_rate ());
-
+ return new Variant ("(iii)", width, height, depth);
}
- private Variant? serialize_meta_data (File file,
- DiscovererAudioInfo? info) {
- if (info == null) {
- return null;
- }
+ private Variant? serialize_audio_info (VariantDict in_v) {
+ int channels = -1;
+ int rate = -1;
+
+ in_v.lookup (Serializer.AUDIO_CHANNELS, "i", out channels);
+ in_v.lookup (Serializer.AUDIO_RATE, "i", out rate);
- var tags = info.get_tags ();
- if (tags == null) {
+ if (channels == -1 && rate == -1) {
return null;
}
+ return new Variant ("(ii)", channels, rate);
+ }
+
+ private Variant? serialize_meta_data (VariantDict in_v) {
string artist = null;
- tags.get_string (Tags.ARTIST, out artist);
+ in_v.lookup (Serializer.ARTIST, "s", out artist);
string album = null;
- tags.get_string (Tags.ALBUM, out album);
+ in_v.lookup (Serializer.ALBUM, "s", out album);
string genre = null;
- tags.get_string (Tags.GENRE, out genre);
+ in_v.lookup (Serializer.GENRE, "s", out genre);
- uint volume = uint.MAX;
- tags.get_uint (Tags.ALBUM_VOLUME_NUMBER, out volume);
+ int volume = -1;
+ in_v.lookup (Serializer.VOLUME_NUMBER, "i", out volume);
- uint track = uint.MAX;
- tags.get_uint (Tags.TRACK_NUMBER, out track);
+ int track = -1;
+ in_v.lookup (Serializer.TRACK_NUMBER, "i", out track);
- 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);
- }
+ int bitrate = -1;
+ in_v.lookup (Serializer.AUDIO_BITRATE, "i", out bitrate);
- 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);
- }
+ if (artist == null && album == null && genre == null &&
+ volume == -1 && track == -1 && bitrate == -1) {
+ return null;
}
return new Variant ("(msmsmsiii)",
@@ -267,6 +145,6 @@ internal class Rygel.InfoSerializer : GLib.Object {
genre,
volume,
track,
- ((int) bitrate) / 8);
+ bitrate);
}
}
diff --git a/src/plugins/media-export/rygel-media-export-playlist-extractor.vala
b/src/plugins/media-export/rygel-media-export-playlist-extractor.vala
index 59d40a8..9986cfa 100644
--- a/src/plugins/media-export/rygel-media-export-playlist-extractor.vala
+++ b/src/plugins/media-export/rygel-media-export-playlist-extractor.vala
@@ -6,6 +6,8 @@ internal class Rygel.MediaExport.PlaylistExtractor : Extractor {
}
public override async void run () throws Error {
+ yield base.run ();
+
uint8[] contents;
if (!yield file.load_contents_async (null, out contents, null)) {
@@ -33,15 +35,15 @@ internal class Rygel.MediaExport.PlaylistExtractor : Extractor {
}
if (title != null) {
- this.serialized_info.insert ("Title", "s", title);
+ this.serialized_info.insert (Serializer.TITLE, "s", title);
}
if (author != null) {
- this.serialized_info.insert ("Creator", author);
+ this.serialized_info.insert (Serializer.ARTIST, "s", author);
}
- this.serialized_info.insert ("DLNAProfile", "s", "DIDL_S");
- this.serialized_info.insert ("UPnPClass",
+ this.serialized_info.insert (Serializer.DLNA_PROFILE, "s", "DIDL_S");
+ this.serialized_info.insert (Serializer.UPNP_CLASS,
"s",
UPNP_CLASS_PLAYLIST);
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]