Duplicate common DIDLLiteResource fields in MediaItem.
authorZeeshan Ali (Khattak) <zeeshanak@src.gnome.org>
Wed, 28 Jan 2009 12:32:17 +0000 (12:32 +0000)
committerZeeshan Ali (Khattak) <zeeshanak@src.gnome.org>
Wed, 28 Jan 2009 12:32:17 +0000 (12:32 +0000)
This is to save typical plugin developer from the knowlege of
DIDLLiteResource. Next we need to make sure he doesn't need to know about
DIDL-Lite at all.

svn path=/trunk/; revision=482

src/plugins/dvb/rygel-dvb-channel.vala
src/plugins/test/rygel-test-item.vala
src/plugins/tracker/rygel-tracker-image-item.vala
src/plugins/tracker/rygel-tracker-music-item.vala
src/plugins/tracker/rygel-tracker-video-item.vala
src/rygel/rygel-http-server.vala
src/rygel/rygel-media-item.vala

index e786318..c151e55 100644 (file)
@@ -63,8 +63,8 @@ public class Rygel.DVBChannel : MediaItem {
             this.upnp_class = "object.item.videoItem.videoBroadcast";
         }
 
-        this.res.mime_type = "video/mpeg";
-        this.res.uri = this.channel_list.GetChannelURL (cid);
+        this.mime_type = "video/mpeg";
+        this.uri = this.channel_list.GetChannelURL (cid);
     }
 }
 
index 74e4339..0715a93 100644 (file)
@@ -40,7 +40,7 @@ public abstract class Rygel.TestItem : Rygel.MediaItem {
                      HTTPServer http_server) {
         base (id, parent_id, title, upnp_class, http_server);
 
-        this.res.mime_type = mime;
+        this.mime_type = mime;
         this.author = TEST_AUTHOR;
     }
 
index 6db5c40..b526222 100644 (file)
@@ -73,16 +73,16 @@ public class Rygel.TrackerImageItem : TrackerItem {
             this.title = values[Metadata.FILE_NAME];
 
         if (values[Metadata.SIZE] != "")
-            this.res.size = values[Metadata.SIZE].to_int ();
+            this.size = values[Metadata.SIZE].to_int ();
 
         if (values[Metadata.WIDTH] != "")
-            this.res.width = values[Metadata.WIDTH].to_int ();
+            this.width = values[Metadata.WIDTH].to_int ();
 
         if (values[Metadata.HEIGHT] != "")
-            this.res.height = values[Metadata.HEIGHT].to_int ();
+            this.height = values[Metadata.HEIGHT].to_int ();
 
         if (values[Metadata.SIZE] != "")
-            this.res.size = values[Metadata.SIZE].to_int ();
+            this.size = values[Metadata.SIZE].to_int ();
 
         if (values[Metadata.DATE] != "") {
             this.date = seconds_to_iso8601 (values[Metadata.DATE]);
@@ -90,10 +90,10 @@ public class Rygel.TrackerImageItem : TrackerItem {
             this.date = seconds_to_iso8601 (values[Metadata.IMAGE_DATE]);
         }
 
-        this.res.mime_type = values[Metadata.MIME];
+        this.mime_type = values[Metadata.MIME];
         this.author = values[Metadata.CREATOR];
         this.album = values[Metadata.ALBUM];
-        this.res.uri = this.uri_from_path (path);
+        this.uri = this.uri_from_path (path);
     }
 }
 
index 7e2c402..3858932 100644 (file)
@@ -73,7 +73,7 @@ public class Rygel.TrackerMusicItem : TrackerItem {
             this.title = values[Metadata.FILE_NAME];
 
         if (values[Metadata.SIZE] != "")
-            this.res.size = values[Metadata.SIZE].to_int ();
+            this.size = values[Metadata.SIZE].to_int ();
 
         if (values[Metadata.TRACK_NUM] != "")
             this.track_number = values[Metadata.TRACK_NUM].to_int ();
@@ -86,10 +86,10 @@ public class Rygel.TrackerMusicItem : TrackerItem {
             this.date = seconds_to_iso8601 (values[Metadata.DATE_ADDED]);
         }
 
-        this.res.mime_type = values[Metadata.MIME];
+        this.mime_type = values[Metadata.MIME];
         this.author = values[Metadata.ARTIST];
         this.album = values[Metadata.ALBUM];
-        this.res.uri = this.uri_from_path (path);
+        this.uri = this.uri_from_path (path);
     }
 }
 
index 19a376e..1df9426 100644 (file)
@@ -69,18 +69,18 @@ public class Rygel.TrackerVideoItem : TrackerItem {
             this.title = values[Metadata.FILE_NAME];
 
         if (values[Metadata.SIZE] != "")
-            this.res.size = values[Metadata.SIZE].to_int ();
+            this.size = values[Metadata.SIZE].to_int ();
 
         if (values[Metadata.WIDTH] != "")
-            this.res.width = values[Metadata.WIDTH].to_int ();
+            this.width = values[Metadata.WIDTH].to_int ();
 
         if (values[Metadata.HEIGHT] != "")
-            this.res.height = values[Metadata.HEIGHT].to_int ();
+            this.height = values[Metadata.HEIGHT].to_int ();
 
         this.date = this.seconds_to_iso8601 (values[Metadata.DATE]);
-        this.res.mime_type = values[Metadata.MIME];
+        this.mime_type = values[Metadata.MIME];
         this.author = values[Metadata.AUTHOR];
-        this.res.uri = this.uri_from_path (path);
+        this.uri = this.uri_from_path (path);
     }
 }
 
index 8182172..07e11cf 100644 (file)
@@ -158,7 +158,7 @@ public class Rygel.HTTPServer : GLib.Object {
             return;
         }
 
-        if (item.res.size > 0) {
+        if (item.size > 0) {
             this.handle_interactive_item (msg, item, seek);
         } else {
             this.handle_streaming_item (msg, item);
@@ -168,20 +168,16 @@ public class Rygel.HTTPServer : GLib.Object {
     private void add_item_headers (Soup.Message msg,
                                    MediaItem    item,
                                    Seek?        seek) {
-        if (item.res.mime_type != null) {
-            msg.response_headers.append ("Content-Type", item.res.mime_type);
+        if (item.mime_type != null) {
+            msg.response_headers.append ("Content-Type", item.mime_type);
         }
 
-        if (item.res.size >= 0) {
+        if (item.size >= 0) {
             msg.response_headers.append ("Content-Length",
-                                         item.res.size.to_string ());
+                                         item.size.to_string ());
         }
 
-        if (DLNAOperation.RANGE in item.res.dlna_operation) {
-            msg.response_headers.append ("Accept-Ranges", "bytes");
-        }
-
-        if (item.res.size > 0) {
+        if (item.size > 0) {
             int64 first_byte;
             int64 last_byte;
 
@@ -190,21 +186,22 @@ public class Rygel.HTTPServer : GLib.Object {
                 last_byte = seek.stop;
             } else {
                 first_byte = 0;
-                last_byte = item.res.size - 1;
+                last_byte = item.size - 1;
             }
 
             // Content-Range: bytes START_BYTE-STOP_BYTE/TOTAL_LENGTH
             var content_range = "bytes " +
                                 first_byte.to_string () + "-" +
                                 last_byte.to_string () + "/" +
-                                item.res.size.to_string ();
+                                item.size.to_string ();
             msg.response_headers.append ("Content-Range", content_range);
+            msg.response_headers.append ("Accept-Ranges", "bytes");
         }
     }
 
     private void handle_streaming_item (Soup.Message msg,
                                         MediaItem    item) {
-        string uri = item.res.uri;
+        string uri = item.uri;
         dynamic Element src = null;
 
         if (uri != null) {
@@ -239,7 +236,7 @@ public class Rygel.HTTPServer : GLib.Object {
     private void handle_interactive_item (Soup.Message msg,
                                           MediaItem    item,
                                           Seek?        seek) {
-        string uri = item.res.uri;
+        string uri = item.uri;
 
         if (uri == null) {
             warning ("Requested item '%s' didn't provide a URI\n", item.id);
@@ -248,7 +245,7 @@ public class Rygel.HTTPServer : GLib.Object {
         }
 
         try {
-            this.serve_uri (uri, msg, seek, item.res.size);
+            this.serve_uri (uri, msg, seek, item.size);
         } catch (Error error) {
             warning ("Error in attempting to serve %s: %s",
                      uri,
@@ -291,7 +288,7 @@ public class Rygel.HTTPServer : GLib.Object {
                                                        range);
             }
 
-            seek = new Seek (Format.BYTES, 0, item.res.size - 1);
+            seek = new Seek (Format.BYTES, 0, item.size - 1);
 
             // Get first byte position
             string first_byte = range_tokens[0];
@@ -311,16 +308,16 @@ public class Rygel.HTTPServer : GLib.Object {
                                                        range);
             }
 
-            if (item.res.size > 0) {
+            if (item.size > 0) {
                 // shouldn't go beyond actual length of media
-                if (seek.start > item.res.size ||
-                    seek.length > item.res.size) {
+                if (seek.start > item.size ||
+                    seek.length > item.size) {
                     throw new HTTPServerError.OUT_OF_RANGE (
                             "Range '%s' not setsifiable", range);
                 }
 
                 // No need to seek if whole stream is requested
-                if (seek.start == 0 && seek.length == item.res.size) {
+                if (seek.start == 0 && seek.length == item.size) {
                     return null;
                 }
             } else if (seek.start == 0) {
index 42b1643..d3a131a 100644 (file)
@@ -42,10 +42,25 @@ public class Rygel.MediaItem : MediaObject {
     public string date;
     public string upnp_class;
 
-    public DIDLLiteResource res;
-
+    // Resource info
+    public string uri;
+    public string mime_type;
+
+    public long size = -1;       // Size in bytes
+    public long duration = -1;   // Duration in seconds
+    public int bitrate = -1;     // Bytes/second
+
+    // Audio/Music
+    public int sample_freq = -1;
+    public int bits_per_sample = -1;
+    public int n_audio_channels = -1;
     public int track_number = -1;
 
+    // Image/Video
+    public int width = -1;
+    public int height = -1;
+    public int color_depth = -1;
+
     protected Rygel.HTTPServer http_server;
 
     public MediaItem (string     id,
@@ -58,9 +73,6 @@ public class Rygel.MediaItem : MediaObject {
         this.title = title;
         this.upnp_class = upnp_class;
         this.http_server = http_server;
-
-        this.res = DIDLLiteResource ();
-        this.res.reset ();
     }
 
     public override void serialize (DIDLLiteWriter didl_writer) throws Error {
@@ -121,23 +133,25 @@ public class Rygel.MediaItem : MediaObject {
         }
 
         /* Add resource data */
+        DIDLLiteResource res = this.get_original_res ();
+
         /* Protocol info */
-        if (this.res.uri != null) {
-            string protocol = get_protocol_for_uri (this.res.uri);
-            this.res.protocol = protocol;
+        if (res.uri != null) {
+            string protocol = get_protocol_for_uri (res.uri);
+            res.protocol = protocol;
         }
 
-        this.res.dlna_profile = "MP3"; /* FIXME */
+        res.dlna_profile = "MP3"; /* FIXME */
 
         if (this.upnp_class.has_prefix (MediaItem.IMAGE_CLASS)) {
-            this.res.dlna_flags |= DLNAFlags.INTERACTIVE_TRANSFER_MODE;
+            res.dlna_flags |= DLNAFlags.INTERACTIVE_TRANSFER_MODE;
         } else {
-            this.res.dlna_flags |= DLNAFlags.STREAMING_TRANSFER_MODE;
+            res.dlna_flags |= DLNAFlags.STREAMING_TRANSFER_MODE;
         }
 
-        if (this.res.size > 0) {
-            this.res.dlna_operation = DLNAOperation.RANGE;
-            this.res.dlna_flags |= DLNAFlags.BACKGROUND_TRANSFER_MODE;
+        if (res.size > 0) {
+            res.dlna_operation = DLNAOperation.RANGE;
+            res.dlna_flags |= DLNAFlags.BACKGROUND_TRANSFER_MODE;
         }
 
         /* Now get the transcoded/proxy URIs */
@@ -147,7 +161,7 @@ public class Rygel.MediaItem : MediaObject {
         }
 
         /* Add the original res in the end */
-        if (this.res.uri != null) {
+        if (res.uri != null) {
             didl_writer.add_res (res);
         }
 
@@ -188,4 +202,26 @@ public class Rygel.MediaItem : MediaObject {
 
         return resources;
     }
+
+    private DIDLLiteResource get_original_res () {
+        DIDLLiteResource res = DIDLLiteResource ();
+        res.reset ();
+
+        res.uri = this.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;
+
+        return res;
+    }
 }