From: Jens Georg Date: Fri, 2 Nov 2012 16:15:26 +0000 (+0100) Subject: server: Add DIDL_S resource to container X-Git-Tag: RYGEL_0_17_2_W48~29 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=302f9a0390ce91429e3357d3792434266efa0424;p=profile%2Fivi%2Frygel.git server: Add DIDL_S resource to container This resource is a playlist in DIDL_S format. Some players and renderers can process those playlists directly. --- diff --git a/src/librygel-server/rygel-audio-item.vala b/src/librygel-server/rygel-audio-item.vala index 33fec7e..24b34a1 100644 --- a/src/librygel-server/rygel-audio-item.vala +++ b/src/librygel-server/rygel-audio-item.vala @@ -49,12 +49,12 @@ public class Rygel.AudioItem : MediaItem { } internal override DIDLLiteResource add_resource - (DIDLLiteItem didl_item, - string? uri, - string protocol, - string? import_uri = null) + (DIDLLiteObject didl_object, + string? uri, + string protocol, + string? import_uri = null) throws Error { - var res = base.add_resource (didl_item, uri, protocol, import_uri); + var res = base.add_resource (didl_object, uri, protocol, import_uri); res.duration = this.duration; res.bitrate = this.bitrate; diff --git a/src/librygel-server/rygel-http-get-handler.vala b/src/librygel-server/rygel-http-get-handler.vala index cec9a09..df0603f 100644 --- a/src/librygel-server/rygel-http-get-handler.vala +++ b/src/librygel-server/rygel-http-get-handler.vala @@ -69,6 +69,7 @@ internal abstract class Rygel.HTTPGetHandler: GLib.Object { (request.object as MediaItem, -1, 0, // FIXME: offer first subtitle only? + null, null); request.msg.response_headers.append ("CaptionInfo.sec", @@ -86,7 +87,7 @@ internal abstract class Rygel.HTTPGetHandler: GLib.Object { public abstract HTTPResponse render_body (HTTPGet request) throws HTTPRequestError; - protected abstract DIDLLiteResource add_resource (DIDLLiteItem didl_item, + protected abstract DIDLLiteResource add_resource (DIDLLiteObject didl_object, HTTPGet request) throws Error; diff --git a/src/librygel-server/rygel-http-identity-handler.vala b/src/librygel-server/rygel-http-identity-handler.vala index e7a5b08..215a6ea 100644 --- a/src/librygel-server/rygel-http-identity-handler.vala +++ b/src/librygel-server/rygel-http-identity-handler.vala @@ -75,15 +75,17 @@ internal class Rygel.HTTPIdentityHandler : Rygel.HTTPGetHandler { size > 0; } - protected override DIDLLiteResource add_resource (DIDLLiteItem didl_item, - HTTPGet request) - throws Error { + protected override DIDLLiteResource add_resource + (DIDLLiteObject didl_object, + HTTPGet request) + throws Error { var protocol = request.http_server.get_protocol (); if (request.thumbnail != null) { - return request.thumbnail.add_resource (didl_item, protocol); + return request.thumbnail.add_resource (didl_object as DIDLLiteItem, + protocol); } else { - return (request.object as MediaItem).add_resource (didl_item, null, protocol); + return request.object.add_resource (didl_object, null, protocol); } } diff --git a/src/librygel-server/rygel-http-item-uri.vala b/src/librygel-server/rygel-http-item-uri.vala index 43e17f8..dc98e0d 100644 --- a/src/librygel-server/rygel-http-item-uri.vala +++ b/src/librygel-server/rygel-http-item-uri.vala @@ -48,68 +48,71 @@ internal class Rygel.HTTPItemURI : Object { public static HashMap mime_to_ext; - public HTTPItemURI (MediaItem item, + public HTTPItemURI (MediaObject object, HTTPServer http_server, int thumbnail_index = -1, int subtitle_index = -1, string? transcode_target = null, string? playlist_format = null) { - this.item_id = item.id; + this.item_id = object.id; this.thumbnail_index = thumbnail_index; this.subtitle_index = subtitle_index; this.transcode_target = transcode_target; this.http_server = http_server; - this.playlist_format = null; + this.playlist_format = playlist_format; this.extension = ""; - if (thumbnail_index > -1) { - if (item is VisualItem) { - var thumbnails = (item as VisualItem).thumbnails; - - if (thumbnails.size > thumbnail_index) { - this.extension = thumbnails[thumbnail_index].file_extension; + if (object is MediaItem) { + var item = object as MediaItem; + if (thumbnail_index > -1) { + if (item is VisualItem) { + var thumbnails = (item as VisualItem).thumbnails; + + if (thumbnails.size > thumbnail_index) { + this.extension = thumbnails[thumbnail_index].file_extension; + } + } else if (item is MusicItem) { + var album_art = (item as MusicItem).album_art; + + if (album_art != null) { + this.extension = album_art.file_extension; + } } - } else if (item is MusicItem) { - var album_art = (item as MusicItem).album_art; + } else if (subtitle_index > -1) { + if (item is VideoItem) { + var subtitles = (item as VideoItem).subtitles; - if (album_art != null) { - this.extension = album_art.file_extension; + if (subtitles.size > subtitle_index) { + this.extension = subtitles[subtitle_index].caption_type; + } } - } - } else if (subtitle_index > -1) { - if (item is VideoItem) { - var subtitles = (item as VideoItem).subtitles; + } else if (transcode_target != null) { + try { + var tc = this.http_server.get_transcoder (transcode_target); - if (subtitles.size > subtitle_index) { - this.extension = subtitles[subtitle_index].caption_type; - } + this.extension = tc.extension; + } catch (Error error) {} } - } else if (transcode_target != null) { - try { - var tc = this.http_server.get_transcoder (transcode_target); - - this.extension = tc.extension; - } catch (Error error) {} - } - if (this.extension == "") { - string uri_extension = ""; + if (this.extension == "") { + string uri_extension = ""; - foreach (string uri_string in item.uris) { - string basename = Path.get_basename (uri_string); - int dot_index = basename.last_index_of("."); + foreach (string uri_string in item.uris) { + string basename = Path.get_basename (uri_string); + int dot_index = basename.last_index_of("."); - if (dot_index > -1) { - uri_extension = basename.substring (dot_index + 1); + if (dot_index > -1) { + uri_extension = basename.substring (dot_index + 1); - break; + break; + } } - } - if (uri_extension == "") { - this.extension = this.ext_from_mime_type (item.mime_type); - } else { - this.extension = uri_extension; + if (uri_extension == "") { + this.extension = this.ext_from_mime_type (item.mime_type); + } else { + this.extension = uri_extension; + } } } } diff --git a/src/librygel-server/rygel-http-playlist-handler.vala b/src/librygel-server/rygel-http-playlist-handler.vala index a7fa0e1..7adf0b7 100644 --- a/src/librygel-server/rygel-http-playlist-handler.vala +++ b/src/librygel-server/rygel-http-playlist-handler.vala @@ -109,6 +109,13 @@ internal class Rygel.HTTPPlaylistHandler : Rygel.HTTPGetHandler { this.cancellable = cancellable; } + public override void add_response_headers (HTTPGet request) + throws HTTPRequestError { + request.msg.response_headers.append ("Content-Type", "text/xml"); + + base.add_response_headers (request); + } + public override HTTPResponse render_body (HTTPGet request) throws HTTPRequestError { try { @@ -123,8 +130,16 @@ internal class Rygel.HTTPPlaylistHandler : Rygel.HTTPGetHandler { } } - protected override DIDLLiteResource add_resource (DIDLLiteItem didl_item, - HTTPGet request) { - return null as DIDLLiteResource; + protected override DIDLLiteResource add_resource + (DIDLLiteObject didl_object, + HTTPGet request) { + var protocol = request.http_server.get_protocol (); + debug ("=> Protocol of this http server is: %s", protocol); + + try { + return request.object.add_resource (didl_object, null, protocol); + } catch (Error error) { + return null as DIDLLiteResource; + } } } diff --git a/src/librygel-server/rygel-http-server.vala b/src/librygel-server/rygel-http-server.vala index 1a76fec..f68e7ae 100644 --- a/src/librygel-server/rygel-http-server.vala +++ b/src/librygel-server/rygel-http-server.vala @@ -65,7 +65,7 @@ internal class Rygel.HTTPServer : Rygel.TranscodeManager, Rygel.StateMachine { return; } - var uri = this.create_uri_for_item (item, -1, -1, null); + var uri = this.create_uri_for_item (item, -1, -1, null, null); item.add_resource (didl_item, uri, this.get_protocol (), uri); } @@ -100,12 +100,14 @@ internal class Rygel.HTTPServer : Rygel.TranscodeManager, Rygel.StateMachine { internal override string create_uri_for_item (MediaItem item, int thumbnail_index, int subtitle_index, - string? transcode_target) { + string? transcode_target, + string? playlist_target) { var uri = new HTTPItemURI (item, this, thumbnail_index, subtitle_index, - transcode_target); + transcode_target, + playlist_target); return uri.to_string (); } diff --git a/src/librygel-server/rygel-http-transcode-handler.vala b/src/librygel-server/rygel-http-transcode-handler.vala index 65e088a..da21a06 100644 --- a/src/librygel-server/rygel-http-transcode-handler.vala +++ b/src/librygel-server/rygel-http-transcode-handler.vala @@ -67,10 +67,11 @@ internal class Rygel.HTTPTranscodeHandler : HTTPGetHandler { } } - protected override DIDLLiteResource add_resource (DIDLLiteItem didl_item, - HTTPGet request) - throws Error { - return this.transcoder.add_resource (didl_item, + protected override DIDLLiteResource add_resource + (DIDLLiteObject didl_object, + HTTPGet request) + throws Error { + return this.transcoder.add_resource (didl_object as DIDLLiteItem, request.object as MediaItem, request.http_server); } diff --git a/src/librygel-server/rygel-image-item.vala b/src/librygel-server/rygel-image-item.vala index 4566164..07b12be 100644 --- a/src/librygel-server/rygel-image-item.vala +++ b/src/librygel-server/rygel-image-item.vala @@ -86,12 +86,12 @@ public class Rygel.ImageItem : MediaItem, VisualItem { } internal override DIDLLiteResource add_resource - (DIDLLiteItem didl_item, + (DIDLLiteObject didl_object, string? uri, string protocol, string? import_uri = null) throws Error { - var res = base.add_resource (didl_item, uri, protocol, import_uri); + var res = base.add_resource (didl_object, uri, protocol, import_uri); this.add_visual_props (res); diff --git a/src/librygel-server/rygel-media-container.vala b/src/librygel-server/rygel-media-container.vala index e4b6d11..3639d13 100644 --- a/src/librygel-server/rygel-media-container.vala +++ b/src/librygel-server/rygel-media-container.vala @@ -237,9 +237,48 @@ public abstract class Rygel.MediaContainer : MediaObject { didl_container.restricted = true; } + var uri = new HTTPItemURI (this, + http_server, + -1, + -1, + null, + "DIDL_S"); + uri.extension = "xml"; + + this.add_resource (didl_container, + uri.to_string (), + http_server.get_protocol ()); + return didl_container; } + internal override DIDLLiteResource add_resource + (DIDLLiteObject didl_object, + string? uri, + string protocol, + string? import_uri = null) + throws Error { + var res = base.add_resource (didl_object, + uri, + protocol, + import_uri); + + if (uri != null) { + res.uri = uri; + } + + var protocol_info = new ProtocolInfo (); + protocol_info.mime_type = "text/xml"; + protocol_info.dlna_profile = "DIDL_S"; + protocol_info.protocol = protocol; + protocol_info.dlna_flags = DLNAFlags.DLNA_V15 | + DLNAFlags.CONNECTION_STALL | + DLNAFlags.BACKGROUND_TRANSFER_MODE; + res.protocol_info = protocol_info; + + return res; + } + /** * handler for container_updated signal on this container. We only forward * it to the parent, hoping someone will get it from the root container diff --git a/src/librygel-server/rygel-media-item.vala b/src/librygel-server/rygel-media-item.vala index ab852d6..9677258 100644 --- a/src/librygel-server/rygel-media-item.vala +++ b/src/librygel-server/rygel-media-item.vala @@ -143,13 +143,16 @@ public abstract class Rygel.MediaItem : MediaObject { (int) transcoder2.get_distance (this); } - internal virtual DIDLLiteResource add_resource - (DIDLLiteItem didl_item, - string? uri, - string protocol, - string? import_uri = null) + internal override DIDLLiteResource add_resource + (DIDLLiteObject didl_object, + string? uri, + string protocol, + string? import_uri = null) throws Error { - var res = didl_item.add_resource (); + var res = base.add_resource (didl_object, + uri, + protocol, + import_uri); if (uri != null && !this.place_holder) { res.uri = uri; diff --git a/src/librygel-server/rygel-media-object.vala b/src/librygel-server/rygel-media-object.vala index 45da38c..59d1a7f 100644 --- a/src/librygel-server/rygel-media-object.vala +++ b/src/librygel-server/rygel-media-object.vala @@ -220,6 +220,17 @@ public abstract class Rygel.MediaObject : GLib.Object { } } + internal virtual DIDLLiteResource add_resource + (DIDLLiteObject object, + string? uri, + string protocol, + string? import_uri = null) + throws Error { + var res = object.add_resource (); + + return res; + } + protected int compare_int_props (int prop1, int prop2) { return (prop1 - prop2).clamp (-1, 1); } diff --git a/src/librygel-server/rygel-music-item.vala b/src/librygel-server/rygel-music-item.vala index a1acb0e..f51883c 100644 --- a/src/librygel-server/rygel-music-item.vala +++ b/src/librygel-server/rygel-music-item.vala @@ -158,6 +158,7 @@ public class Rygel.MusicItem : AudioItem { didl_item.album_art = server.create_uri_for_item (this, 0, -1, + null, null); } } diff --git a/src/librygel-server/rygel-transcode-manager.vala b/src/librygel-server/rygel-transcode-manager.vala index 538f53d..8df32d3 100644 --- a/src/librygel-server/rygel-transcode-manager.vala +++ b/src/librygel-server/rygel-transcode-manager.vala @@ -44,7 +44,8 @@ public abstract class Rygel.TranscodeManager : GLib.Object { public abstract string create_uri_for_item (MediaItem item, int thumbnail_index, int subtitle_index, - string? transcode_target); + string? transcode_target, + string? playlist_target); public void add_resources (DIDLLiteItem didl_item, MediaItem item) throws Error { diff --git a/src/librygel-server/rygel-transcoder.vala b/src/librygel-server/rygel-transcoder.vala index 6427694..95488a4 100644 --- a/src/librygel-server/rygel-transcoder.vala +++ b/src/librygel-server/rygel-transcoder.vala @@ -58,7 +58,8 @@ public abstract class Rygel.Transcoder : GLib.Object { var uri = manager.create_uri_for_item (item, -1, -1, - this.dlna_profile); + this.dlna_profile, + null); var res = item.add_resource (didl_item, uri, protocol); res.size = -1; diff --git a/src/librygel-server/rygel-video-item.vala b/src/librygel-server/rygel-video-item.vala index 679b700..93f61a1 100644 --- a/src/librygel-server/rygel-video-item.vala +++ b/src/librygel-server/rygel-video-item.vala @@ -109,12 +109,12 @@ public class Rygel.VideoItem : AudioItem, VisualItem { } internal override DIDLLiteResource add_resource - (DIDLLiteItem didl_item, - string? uri, - string protocol, - string? import_uri = null) + (DIDLLiteObject didl_object, + string? uri, + string protocol, + string? import_uri = null) throws Error { - var res = base.add_resource (didl_item, uri, protocol, import_uri); + var res = base.add_resource (didl_object, uri, protocol, import_uri); this.add_visual_props (res); @@ -180,6 +180,7 @@ public class Rygel.VideoItem : AudioItem, VisualItem { subtitle.uri = server.create_uri_for_item (this, -1, index, + null, null); subtitle.add_didl_node (didl_item); diff --git a/src/librygel-server/rygel-visual-item.vala b/src/librygel-server/rygel-visual-item.vala index 13bd8c5..82a792e 100644 --- a/src/librygel-server/rygel-visual-item.vala +++ b/src/librygel-server/rygel-visual-item.vala @@ -63,7 +63,9 @@ public interface Rygel.VisualItem : MediaItem { try { var thumb = thumbnailer.get_thumbnail (uri, this.mime_type); this.thumbnails.add (thumb); - } catch (Error err) {} + } catch (Error err) { + debug ("Failed to get thumbnail: %s", err.message); + } } } @@ -96,6 +98,7 @@ public interface Rygel.VisualItem : MediaItem { thumbnail.uri = server.create_uri_for_item (this, index, -1, + null, null); thumbnail.add_resource (didl_item, server.get_protocol ()); diff --git a/tests/rygel-http-item-uri-test.vala b/tests/rygel-http-item-uri-test.vala index 82889a5..cfc0f16 100644 --- a/tests/rygel-http-item-uri-test.vala +++ b/tests/rygel-http-item-uri-test.vala @@ -72,8 +72,11 @@ private class Rygel.HTTPServer : GLib.Object { } } -private class Rygel.MediaItem : GLib.Object { +private class Rygel.MediaObject : GLib.Object { public string id; +} + +private class Rygel.MediaItem : Rygel.MediaObject { public ArrayList uris = new ArrayList (); public string mime_type; }