diff options
author | Jens Georg <mail@jensge.org> | 2014-12-03 18:00:37 +0100 |
---|---|---|
committer | Jens Georg <mail@jensge.org> | 2015-02-08 13:18:38 +0100 |
commit | a9eb713a8cba0efb10d1400c48ed6243bd03d179 (patch) | |
tree | bec95dea2992e929132b6f20f1c04a3919f4568b | |
parent | 072a0734b5a96d72db0540f7cfc1eef156d896a1 (diff) | |
download | rygel-a9eb713a8cba0efb10d1400c48ed6243bd03d179.tar.gz |
server: Serialize resources
Code based on Cablelabs's CVP-2 implementation.
Signed-off-by: Jens Georg <mail@jensge.org>
-rw-r--r-- | src/librygel-server/rygel-http-item-uri.vala | 24 | ||||
-rw-r--r-- | src/librygel-server/rygel-http-server.vala | 20 | ||||
-rw-r--r-- | src/librygel-server/rygel-media-file-item.vala | 23 | ||||
-rw-r--r-- | src/librygel-server/rygel-media-object.vala | 75 | ||||
-rw-r--r-- | src/librygel-server/rygel-media-resource.vala | 2 | ||||
-rw-r--r-- | src/librygel-server/rygel-music-item.vala | 1 | ||||
-rw-r--r-- | src/librygel-server/rygel-transcode-manager.vala | 3 | ||||
-rw-r--r-- | src/librygel-server/rygel-transcoder.vala | 1 | ||||
-rw-r--r-- | src/librygel-server/rygel-video-item.vala | 1 | ||||
-rw-r--r-- | src/librygel-server/rygel-visual-item.vala | 1 |
10 files changed, 121 insertions, 30 deletions
diff --git a/src/librygel-server/rygel-http-item-uri.vala b/src/librygel-server/rygel-http-item-uri.vala index 914288bd..99e81cbb 100644 --- a/src/librygel-server/rygel-http-item-uri.vala +++ b/src/librygel-server/rygel-http-item-uri.vala @@ -31,6 +31,7 @@ internal class Rygel.HTTPItemURI : Object { public int subtitle_index { get; set; default = -1; } public string? transcode_target { get; set; default = null; } public string? playlist_format { get; set; default = null; } + public string? resource_name { get; set; default = null; } public unowned HTTPServer http_server { get; set; } private string real_extension; @@ -53,17 +54,29 @@ internal class Rygel.HTTPItemURI : Object { int thumbnail_index = -1, int subtitle_index = -1, string? transcode_target = null, - string? playlist_format = null) { + string? playlist_format = null, + string? resource_name = null) { 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 = playlist_format; + this.resource_name = resource_name; this.extension = ""; - if (!(object is MediaFileItem)) { + if (this.resource_name != null) { + var resource = object.get_resource_by_name + (this.resource_name); + if (resource != null) { + this.extension = resource.extension; + } + return; + } else { + if (!(object is MediaFileItem)) { + return; + } } var item = object as MediaFileItem; @@ -187,6 +200,10 @@ internal class Rygel.HTTPItemURI : Object { this.playlist_format = Soup.URI.decode (parts[i + 1]); break; + case "res": + this.resource_name = Soup.URI.decode (parts[i + 1]); + + break; default: break; } @@ -216,6 +233,9 @@ internal class Rygel.HTTPItemURI : Object { } else if (this.playlist_format != null) { path += "/pl/" + Uri.escape_string (this.playlist_format, "", true); + } else if (this.resource_name != null) { + path += "/res/" + Uri.escape_string + (this.resource_name, "", true); } path += this.extension; diff --git a/src/librygel-server/rygel-http-server.vala b/src/librygel-server/rygel-http-server.vala index 369a13ee..cfe470a9 100644 --- a/src/librygel-server/rygel-http-server.vala +++ b/src/librygel-server/rygel-http-server.vala @@ -65,6 +65,18 @@ public class Rygel.HTTPServer : Rygel.TranscodeManager, Rygel.StateMachine { } } + /** + * Set or unset options the server supports/doesn't support + * + * Resources should be setup assuming server supports all optional delivery modes + */ + public void set_resource_delivery_options (MediaResource res) { + res.protocol = this.get_protocol (); + // Set this just to be safe + res.dlna_flags |= DLNAFlags.DLNA_V15; + // This server supports all DLNA delivery modes - so leave those flags alone + } + internal void add_proxy_resource (DIDLLiteItem didl_item, MediaFileItem item) throws Error { @@ -72,7 +84,7 @@ public class Rygel.HTTPServer : Rygel.TranscodeManager, Rygel.StateMachine { return; } - var uri = this.create_uri_for_object (item, -1, -1, null, null); + var uri = this.create_uri_for_object (item, -1, -1, null, null, null); item.add_resource (didl_item, uri, this.get_protocol (), uri); } @@ -108,13 +120,15 @@ public class Rygel.HTTPServer : Rygel.TranscodeManager, Rygel.StateMachine { int thumbnail_index, int subtitle_index, string? transcode_target, - string? playlist_target) { + string? playlist_target, + string? resource_name) { var uri = new HTTPItemURI (object, this, thumbnail_index, subtitle_index, transcode_target, - playlist_target); + playlist_target, + resource_name); return uri.to_string (); } diff --git a/src/librygel-server/rygel-media-file-item.vala b/src/librygel-server/rygel-media-file-item.vala index 77d33ec9..a410f04a 100644 --- a/src/librygel-server/rygel-media-file-item.vala +++ b/src/librygel-server/rygel-media-file-item.vala @@ -255,29 +255,6 @@ public abstract class Rygel.MediaFileItem : MediaItem { return protocol_info; } - internal string get_protocol_for_uri (string uri) throws Error { - var scheme = Uri.parse_scheme (uri); - if (scheme == null) { - throw new MediaItemError.BAD_URI (_("Bad URI: %s"), uri); - } - - if (scheme == "http") { - return "http-get"; - } else if (scheme == "file") { - return "internal"; - } else if (scheme == "rtsp") { - // FIXME: Assuming that RTSP is always accompanied with RTP over UDP - return "rtsp-rtp-udp"; - } else { - // Assume the protocol to be the scheme of the URI - warning (_("Failed to probe protocol for URI %s. Assuming '%s'"), - uri, - scheme); - - return scheme; - } - } - protected virtual void add_resources (DIDLLiteItem didl_item, bool allow_internal) throws Error { diff --git a/src/librygel-server/rygel-media-object.vala b/src/librygel-server/rygel-media-object.vala index 5235f967..2917c8a8 100644 --- a/src/librygel-server/rygel-media-object.vala +++ b/src/librygel-server/rygel-media-object.vala @@ -224,10 +224,62 @@ public abstract class Rygel.MediaObject : GLib.Object { return media_resources; } + public MediaResource? get_resource_by_name (string resource_name) { + foreach (var resource in this.media_resources) { + if (resource.get_name () == resource_name) { + return resource; + } + } + + return null; + } + public abstract DIDLLiteObject? serialize (Serializer serializer, HTTPServer http_server) throws Error; + /** + * Serialize the resource list + * + * Any resource with an empty URIs will get a resource-based HTTP URI and have its protocol + * and delivery options adjusted to the HTTPServer. + * + * Internal (e.g. "file:") resources will only be included when the http server + * is on the local host. + * + * Resources will be serialized in list order. + */ + public void serialize_resource_list (DIDLLiteObject didl_object, + HTTPServer http_server) + throws Error { + foreach (var res in this.get_resource_list ()) { + if (res.uri == null || res.uri == "") { + res.uri = http_server.create_uri_for_object (this, + -1, + -1, + null, + null, + res.get_name ()); + var didl_resource = didl_object.add_resource (); + http_server.set_resource_delivery_options (res); + res.serialize (didl_resource); + res.uri = null; + } else { + try { + var protocol = this.get_protocol_for_uri (res.uri); + if (protocol != "internal") { + // Exclude internal resources when request is non-local + var didl_resource = didl_object.add_resource (); + res.serialize (didl_resource); + } + } catch (Error e) { + warning (_("Could not determine protocol for %s"), res.uri); + } + } + } + } + + internal virtual void apply_didl_lite (DIDLLiteObject didl_object) { this.title = didl_object.title; this.artist = this.get_first (didl_object.get_artists ()); @@ -415,4 +467,27 @@ public abstract class Rygel.MediaObject : GLib.Object { return ""; } + + internal string get_protocol_for_uri (string uri) throws Error { + var scheme = Uri.parse_scheme (uri); + if (scheme == null) { + throw new MediaItemError.BAD_URI (_("Bad URI: %s"), uri); + } + + if (scheme == "http") { + return "http-get"; + } else if (scheme == "file") { + return "internal"; + } else if (scheme == "rtsp") { + // FIXME: Assuming that RTSP is always accompanied with RTP over UDP + return "rtsp-rtp-udp"; + } else { + // Assume the protocol to be the scheme of the URI + warning (_("Failed to probe protocol for URI %s. Assuming '%s'"), + uri, + scheme); + + return scheme; + } + } } diff --git a/src/librygel-server/rygel-media-resource.vala b/src/librygel-server/rygel-media-resource.vala index 8bbf2269..05207342 100644 --- a/src/librygel-server/rygel-media-resource.vala +++ b/src/librygel-server/rygel-media-resource.vala @@ -170,7 +170,7 @@ public class Rygel.MediaResource : GLib.Object { didl_resource.height = this.height; didl_resource.audio_channels = this.audio_channels; didl_resource.sample_freq = this.sample_freq; - didl_resource.protocol_info = get_protocol_info (); + didl_resource.protocol_info = this.get_protocol_info (); return didl_resource; } diff --git a/src/librygel-server/rygel-music-item.vala b/src/librygel-server/rygel-music-item.vala index 9c48f5de..43678f8d 100644 --- a/src/librygel-server/rygel-music-item.vala +++ b/src/librygel-server/rygel-music-item.vala @@ -135,6 +135,7 @@ public class Rygel.MusicItem : AudioItem { 0, -1, null, + null, null); } } diff --git a/src/librygel-server/rygel-transcode-manager.vala b/src/librygel-server/rygel-transcode-manager.vala index ddc45ff1..916ef04a 100644 --- a/src/librygel-server/rygel-transcode-manager.vala +++ b/src/librygel-server/rygel-transcode-manager.vala @@ -45,7 +45,8 @@ public abstract class Rygel.TranscodeManager : GLib.Object { int thumbnail_index, int subtitle_index, string? transcode_target, - string? playlist_target); + string? playlist_target, + string? resource_name); public void add_resources (DIDLLiteItem didl_item, MediaFileItem item) throws Error { diff --git a/src/librygel-server/rygel-transcoder.vala b/src/librygel-server/rygel-transcoder.vala index fb48fd30..efa6152d 100644 --- a/src/librygel-server/rygel-transcoder.vala +++ b/src/librygel-server/rygel-transcoder.vala @@ -83,6 +83,7 @@ public abstract class Rygel.Transcoder : GLib.Object { -1, -1, this.dlna_profile, + null, 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 c9d3a16f..514bbd13 100644 --- a/src/librygel-server/rygel-video-item.vala +++ b/src/librygel-server/rygel-video-item.vala @@ -195,6 +195,7 @@ public class Rygel.VideoItem : AudioItem, VisualItem { -1, index, null, + 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 2ab8897d..254d61d5 100644 --- a/src/librygel-server/rygel-visual-item.vala +++ b/src/librygel-server/rygel-visual-item.vala @@ -101,6 +101,7 @@ public interface Rygel.VisualItem : MediaFileItem { index, -1, null, + null, null); thumbnail.add_resource (didl_item, server.get_protocol ()); |