[rygel] core: Add XBox hacks



commit 2f94f36e638acc84cdb5b6aaa87f307027b2ad86
Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
Date:   Wed Mar 24 03:07:53 2010 +0200

    core: Add XBox hacks
    
    If the "User-Agent" header in the request contains "XBox", we assume the
    client is Xbox. The hacks are currently simple: we just override the
    mime-type of the item so that XBox likes it better.

 src/rygel/Makefile.am           |    1 +
 src/rygel/rygel-browse.vala     |    9 +++++++
 src/rygel/rygel-xbox-hacks.vala |   45 +++++++++++++++++++++++++++++++++++++++
 3 files changed, 55 insertions(+), 0 deletions(-)
---
diff --git a/src/rygel/Makefile.am b/src/rygel/Makefile.am
index ccd19b0..b093db1 100644
--- a/src/rygel/Makefile.am
+++ b/src/rygel/Makefile.am
@@ -77,6 +77,7 @@ VAPI_SOURCE_FILES = rygel-configuration.vala \
 		    rygel-thumbnailer.vala \
 		    rygel-browse.vala \
 		    rygel-search.vala \
+			rygel-xbox-hacks.vala \
 		    rygel-import-resource.vala \
 		    rygel-item-creator.vala \
 		    rygel-search-expression.vala \
diff --git a/src/rygel/rygel-browse.vala b/src/rygel/rygel-browse.vala
index 496f196..4e942a1 100644
--- a/src/rygel/rygel-browse.vala
+++ b/src/rygel/rygel-browse.vala
@@ -52,6 +52,7 @@ internal class Rygel.Browse: GLib.Object, Rygel.StateMachine {
     private uint32 system_update_id;
     private ServiceAction action;
     private Rygel.DIDLLiteWriter didl_writer;
+    private XBoxHacks xbox_hacks;
 
     public Cancellable cancellable { get; set; }
 
@@ -63,6 +64,10 @@ internal class Rygel.Browse: GLib.Object, Rygel.StateMachine {
         this.action = (owned) action;
 
         this.didl_writer = new Rygel.DIDLLiteWriter (content_dir.http_server);
+
+        try {
+            this.xbox_hacks = new XBoxHacks (action.get_message ());
+        } catch { /* This just means we are not dealing with Xbox, yay! */ }
     }
 
     public async void run () {
@@ -81,6 +86,10 @@ internal class Rygel.Browse: GLib.Object, Rygel.StateMachine {
             }
 
             foreach (var result in results) {
+                if (result is MediaItem && this.xbox_hacks != null) {
+                    this.xbox_hacks.apply (result as MediaItem);
+                }
+
                 this.didl_writer.serialize (result);
             }
 
diff --git a/src/rygel/rygel-xbox-hacks.vala b/src/rygel/rygel-xbox-hacks.vala
new file mode 100644
index 0000000..fe71a1b
--- /dev/null
+++ b/src/rygel/rygel-xbox-hacks.vala
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2010 Nokia Corporation.
+ *
+ * Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
+ *                               <zeeshan ali nokia com>
+ *
+ * This file is part of Rygel.
+ *
+ * Rygel is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * Rygel is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+ */
+
+using Soup;
+
+internal errordomain Rygel.XBoxHacksError {
+    NA
+}
+
+internal class Rygel.XBoxHacks : GLib.Object {
+    public XBoxHacks (Message msg) throws XBoxHacksError {
+        if (!msg.request_headers.get ("User-Agent").contains ("XBox")) {
+            throw new XBoxHacksError.NA ("Not Applicable");
+        }
+    }
+
+    public void apply (MediaItem item) {
+        if (item.mime_type == "video/x-msvideo") {
+            item.mime_type = "video/avi";
+        } else if (item.mime_type == "video/mpeg") {
+            // Force transcoding for MPEG files
+            item.mime_type = "invalid/content";
+        }
+    }
+}



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]