[rygel] core,plugins: Simpler way to provide thumbnails
- From: Zeeshan Ali Khattak <zeeshanak src gnome org>
- To: svn-commits-list gnome org
- Cc:
- Subject: [rygel] core,plugins: Simpler way to provide thumbnails
- Date: Tue, 8 Sep 2009 16:23:47 +0000 (UTC)
commit af20a97943591b7ce977bf2a06d7ef98b8c86bc4
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date: Tue Sep 8 19:11:42 2009 +0300
core,plugins: Simpler way to provide thumbnails
Provide a method to add URIs to MediaItem, using which the plugin
can also provide a thumbnail. If no thumbnail is provided, Rygel
tries to get it using the Thumbnailer.
src/plugins/external/rygel-external-item.vala | 2 +-
.../media-export/rygel-media-export-item.vala | 4 +-
.../mediathek/rygel-mediathek-video-item.vala | 2 +-
src/plugins/tracker/rygel-tracker-image-item.vala | 2 +-
src/plugins/tracker/rygel-tracker-music-item.vala | 2 +-
src/plugins/tracker/rygel-tracker-video-item.vala | 2 +-
src/rygel/rygel-http-server.vala | 37 --------------------
src/rygel/rygel-media-item.vala | 24 +++++++++++++
src/rygel/rygel-thumbnailer.vala | 11 +++++-
9 files changed, 40 insertions(+), 46 deletions(-)
---
diff --git a/src/plugins/external/rygel-external-item.vala b/src/plugins/external/rygel-external-item.vala
index 85de301..b6cef26 100644
--- a/src/plugins/external/rygel-external-item.vala
+++ b/src/plugins/external/rygel-external-item.vala
@@ -76,7 +76,7 @@ public class Rygel.ExternalItem : Rygel.MediaItem {
for (var i = 0; uris[i] != null; i++) {
var tmp = uris[i].replace ("@ADDRESS@", parent.host_ip);
- this.uris.add (tmp);
+ this.add_uri (tmp, null);
}
// Optional properties
diff --git a/src/plugins/media-export/rygel-media-export-item.vala b/src/plugins/media-export/rygel-media-export-item.vala
index 2723add..f274261 100644
--- a/src/plugins/media-export/rygel-media-export-item.vala
+++ b/src/plugins/media-export/rygel-media-export-item.vala
@@ -56,7 +56,7 @@ public class Rygel.MediaExportItem : Rygel.MediaItem {
base (id, parent, info.get_name (), item_class);
this.mime_type = content_type;
- this.uris.add (file.get_uri ());
+ this.add_uri (file.get_uri (), null);
}
private void fill_from_tags_as_image (Gst.TagList tag_list) {
@@ -191,7 +191,7 @@ public class Rygel.MediaExportItem : Rygel.MediaItem {
break;
}
- this.uris.add (file.get_uri ());
+ this.add_uri (file.get_uri (), null);
}
}
diff --git a/src/plugins/mediathek/rygel-mediathek-video-item.vala b/src/plugins/mediathek/rygel-mediathek-video-item.vala
index 2724dfa..b5554be 100644
--- a/src/plugins/mediathek/rygel-mediathek-video-item.vala
+++ b/src/plugins/mediathek/rygel-mediathek-video-item.vala
@@ -121,7 +121,7 @@ public class Rygel.MediathekVideoItem : Rygel.MediaItem {
video_item = new MediathekVideoItem (parent, title);
foreach (string uri in asx.uris) {
- video_item.uris.add (uri);
+ video_item.add_uri (uri, null);
}
return video_item;
diff --git a/src/plugins/tracker/rygel-tracker-image-item.vala b/src/plugins/tracker/rygel-tracker-image-item.vala
index c79fce7..e914f13 100644
--- a/src/plugins/tracker/rygel-tracker-image-item.vala
+++ b/src/plugins/tracker/rygel-tracker-image-item.vala
@@ -93,7 +93,7 @@ public class Rygel.TrackerImageItem : Rygel.TrackerItem {
this.mime_type = values[Metadata.MIME];
this.author = values[Metadata.CREATOR];
this.album = values[Metadata.ALBUM];
- this.uris.add (Filename.to_uri (path, null));
+ this.add_uri (Filename.to_uri (path, null), null);
}
}
diff --git a/src/plugins/tracker/rygel-tracker-music-item.vala b/src/plugins/tracker/rygel-tracker-music-item.vala
index d40e67f..9b2c871 100644
--- a/src/plugins/tracker/rygel-tracker-music-item.vala
+++ b/src/plugins/tracker/rygel-tracker-music-item.vala
@@ -94,7 +94,7 @@ public class Rygel.TrackerMusicItem : Rygel.TrackerItem {
this.mime_type = values[Metadata.MIME];
this.author = values[Metadata.ARTIST];
this.album = values[Metadata.ALBUM];
- this.uris.add (Filename.to_uri (path, null));
+ this.add_uri (Filename.to_uri (path, null), null);
}
}
diff --git a/src/plugins/tracker/rygel-tracker-video-item.vala b/src/plugins/tracker/rygel-tracker-video-item.vala
index 99fb9d9..d5fbf9c 100644
--- a/src/plugins/tracker/rygel-tracker-video-item.vala
+++ b/src/plugins/tracker/rygel-tracker-video-item.vala
@@ -85,7 +85,7 @@ public class Rygel.TrackerVideoItem : Rygel.TrackerItem {
this.date = this.seconds_to_iso8601 (values[Metadata.DATE]);
this.mime_type = values[Metadata.MIME];
this.author = values[Metadata.AUTHOR];
- this.uris.add (Filename.to_uri (path, null));
+ this.add_uri (Filename.to_uri (path, null), null);
}
}
diff --git a/src/rygel/rygel-http-server.vala b/src/rygel/rygel-http-server.vala
index 38b1d55..0a2bc07 100644
--- a/src/rygel/rygel-http-server.vala
+++ b/src/rygel/rygel-http-server.vala
@@ -45,12 +45,6 @@ internal class Rygel.HTTPServer : Rygel.TranscodeManager, Rygel.StateMachine {
this.requests = new ArrayList<HTTPRequest> ();
this.path_root = SERVER_PATH_PREFIX + "/" + name;
-
- var thumbnailer = Thumbnailer.get_default ();
- if (thumbnailer != null) {
- this.context.host_path (thumbnailer.directory,
- this.path_root + "/thumbnails");
- }
}
public void run (Cancellable? cancellable) {
@@ -80,37 +74,6 @@ internal class Rygel.HTTPServer : Rygel.TranscodeManager, Rygel.StateMachine {
base.add_resources (didl_item, item);
// Thumbnails comes in the end
- if (item.upnp_class.has_prefix (MediaItem.IMAGE_CLASS) ||
- item.upnp_class.has_prefix (MediaItem.VIDEO_CLASS) &&
- item.thumbnails.size == 0) {
- var thumbnailer = Thumbnailer.get_default ();
-
- // Lets see if we can provide the thumbnails
- if (thumbnailer != null) {
- foreach (var uri in item.uris) {
- Thumbnail thumbnail = null;
-
- try {
- thumbnail = thumbnailer.get_thumbnail (uri);
- thumbnail.add_resource (didl_item, "internal");
-
- // Now create the HTTP URI
- var basename = Path.get_basename (thumbnail.path);
- thumbnail.uri = this.create_uri_for_path (
- "/thumbnails/" + basename);
- thumbnail.add_resource (didl_item,
- this.get_protocol ());
- } catch (ThumbnailerError err) {}
-
- // No error means we found the thumbnail
- break;
- }
- }
-
- return; // We won't be here if there were thumbnails provided by
- // the item itself
- }
-
foreach (var thumbnail in item.thumbnails) {
if (!is_http_uri (thumbnail.uri)) {
var uri = thumbnail.uri; // Save the original URI
diff --git a/src/rygel/rygel-media-item.vala b/src/rygel/rygel-media-item.vala
index ef76150..fd402ae 100644
--- a/src/rygel/rygel-media-item.vala
+++ b/src/rygel/rygel-media-item.vala
@@ -103,6 +103,30 @@ public class Rygel.MediaItem : MediaObject {
return this.size <= 0;
}
+ // Adds URI to MediaItem. You can either provide the associated thumbnail or
+ // ask Rygel to try to fetch it for you by passing null as @thumbnail.
+ public void add_uri (string uri,
+ Thumbnail? thumbnail) {
+ this.uris.add (uri);
+
+ if (thumbnail != null) {
+ this.thumbnails.add (thumbnail);
+ } else if (this.upnp_class.has_prefix (MediaItem.IMAGE_CLASS) ||
+ this.upnp_class.has_prefix (MediaItem.VIDEO_CLASS)) {
+ // Lets see if we can provide the thumbnails
+ var thumbnailer = Thumbnailer.get_default ();
+
+ if (thumbnailer == null) {
+ return;
+ }
+
+ try {
+ var thumb = thumbnailer.get_thumbnail (uri);
+ this.thumbnails.add (thumb);
+ } catch (Error err) {}
+ }
+ }
+
internal int compare_transcoders (void *a, void *b) {
var transcoder1 = (Transcoder) a;
var transcoder2 = (Transcoder) b;
diff --git a/src/rygel/rygel-thumbnailer.vala b/src/rygel/rygel-thumbnailer.vala
index 6918e21..0403681 100644
--- a/src/rygel/rygel-thumbnailer.vala
+++ b/src/rygel/rygel-thumbnailer.vala
@@ -87,7 +87,7 @@ internal class Rygel.Thumbnailer : GLib.Object {
return thumbnailer;
}
- public Thumbnail get_thumbnail (string uri) throws ThumbnailerError {
+ public Thumbnail get_thumbnail (string uri) throws Error {
Thumbnail thumbnail = null;
var path = Checksum.compute_for_string (ChecksumType.MD5, uri) +
@@ -95,7 +95,12 @@ internal class Rygel.Thumbnailer : GLib.Object {
var full_path = Path.build_filename (this.directory, path);
var file = File.new_for_path (full_path);
- if (!file.query_exists (null)) {
+ var info = file.query_info (FILE_ATTRIBUTE_ACCESS_CAN_READ + "," +
+ FILE_ATTRIBUTE_STANDARD_SIZE,
+ FileQueryInfoFlags.NONE,
+ null);
+
+ if (!info.get_attribute_boolean (FILE_ATTRIBUTE_ACCESS_CAN_READ)) {
throw new ThumbnailerError.NO_THUMBNAIL ("No thumbnail available");
}
@@ -105,6 +110,8 @@ internal class Rygel.Thumbnailer : GLib.Object {
thumbnail.depth = this.template.depth;
thumbnail.path = path;
thumbnail.uri = Filename.to_uri (full_path, null);
+ thumbnail.size = (long) info.get_attribute_uint64 (
+ FILE_ATTRIBUTE_STANDARD_SIZE);
return thumbnail;
}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]