From 011f352705024636820f88f28f32ae5e2345336e Mon Sep 17 00:00:00 2001 From: "Zeeshan Ali (Khattak)" Date: Sun, 15 Mar 2009 19:00:34 +0000 Subject: [PATCH] MediaItem creates res for itself for a given URI. svn path=/trunk/; revision=651 --- src/rygel/rygel-didl-lite-writer.vala | 46 +--------------------------- src/rygel/rygel-media-item.vala | 56 +++++++++++++++++++++++++++++++++++ 2 files changed, 57 insertions(+), 45 deletions(-) diff --git a/src/rygel/rygel-didl-lite-writer.vala b/src/rygel/rygel-didl-lite-writer.vala index 37eb499..411c1bd 100644 --- a/src/rygel/rygel-didl-lite-writer.vala +++ b/src/rygel/rygel-didl-lite-writer.vala @@ -212,55 +212,11 @@ internal class Rygel.DIDLLiteWriter : GUPnP.DIDLLiteWriter { var resources = new ArrayList (); foreach (var uri in item.uris) { - DIDLLiteResource res = create_res (item, uri); + DIDLLiteResource res = item.create_res (uri); resources.add (res); } return resources; } - - private DIDLLiteResource create_res (MediaItem item, - string uri) - throws Error { - DIDLLiteResource res = DIDLLiteResource (); - res.reset (); - - res.uri = uri; - res.mime_type = item.mime_type; - - res.size = item.size; - res.duration = item.duration; - res.bitrate = item.bitrate; - - res.sample_freq = item.sample_freq; - res.bits_per_sample = item.bits_per_sample; - res.n_audio_channels = item.n_audio_channels; - - res.width = item.width; - res.height = item.height; - res.color_depth = item.color_depth; - - /* Protocol info */ - if (res.uri != null) { - string protocol = get_protocol_for_uri (res.uri); - res.protocol = protocol; - } - - /* DLNA related fields */ - res.dlna_profile = "MP3"; /* FIXME */ - - if (item.upnp_class.has_prefix (MediaItem.IMAGE_CLASS)) { - res.dlna_flags |= DLNAFlags.INTERACTIVE_TRANSFER_MODE; - } else { - res.dlna_flags |= DLNAFlags.STREAMING_TRANSFER_MODE; - } - - if (res.size > 0) { - res.dlna_operation = DLNAOperation.RANGE; - res.dlna_flags |= DLNAFlags.BACKGROUND_TRANSFER_MODE; - } - - return res; - } } diff --git a/src/rygel/rygel-media-item.vala b/src/rygel/rygel-media-item.vala index eccaf66..37b8226 100644 --- a/src/rygel/rygel-media-item.vala +++ b/src/rygel/rygel-media-item.vala @@ -73,4 +73,60 @@ public class Rygel.MediaItem : MediaObject { public virtual Gst.Element? create_stream_source () { return null; } + + internal DIDLLiteResource create_res (string uri) throws Error { + DIDLLiteResource res = DIDLLiteResource (); + res.reset (); + + res.uri = uri; + res.mime_type = this.mime_type; + + res.size = this.size; + res.duration = this.duration; + res.bitrate = this.bitrate; + + res.sample_freq = this.sample_freq; + res.bits_per_sample = this.bits_per_sample; + res.n_audio_channels = this.n_audio_channels; + + res.width = this.width; + res.height = this.height; + res.color_depth = this.color_depth; + + /* Protocol info */ + if (res.uri != null) { + string protocol = get_protocol_for_uri (res.uri); + res.protocol = protocol; + } + + /* DLNA related fields */ + res.dlna_profile = "MP3"; /* FIXME */ + + if (this.upnp_class.has_prefix (MediaItem.IMAGE_CLASS)) { + res.dlna_flags |= DLNAFlags.INTERACTIVE_TRANSFER_MODE; + } else { + res.dlna_flags |= DLNAFlags.STREAMING_TRANSFER_MODE; + } + + if (res.size > 0) { + res.dlna_operation = DLNAOperation.RANGE; + res.dlna_flags |= DLNAFlags.BACKGROUND_TRANSFER_MODE; + } + + return res; + } + + private string get_protocol_for_uri (string uri) throws Error { + if (uri.has_prefix ("http")) { + return "http-get"; + } else if (uri.has_prefix ("file")) { + return "internal"; + } else if (uri.has_prefix ("rtsp")) { + // FIXME: Assuming that RTSP is always accompanied with RTP over UDP + return "rtsp-rtp-udp"; + } else { + throw new DIDLLiteWriterError.UNKNOWN_URI_TYPE + ("Failed to probe protocol for URI %s", uri); + } + } } -- 2.7.4