core: Add HTTPTranscodeHandler
authorZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Tue, 1 Sep 2009 13:04:51 +0000 (16:04 +0300)
committerZeeshan Ali (Khattak) <zeeshanak@gnome.org>
Tue, 1 Sep 2009 13:04:51 +0000 (16:04 +0300)
Move HTTPRequestHandler implementation from Transcoder to a new class,
HTTPTranscodeHandler. This is to keep the HTTP protocol implementation
as separate as possible so that later we can easily add more protocol
handlers (e.g RTSP).

src/rygel/Makefile.am
src/rygel/rygel-http-request.vala
src/rygel/rygel-http-transcode-handler.vala [new file with mode: 0644]
src/rygel/rygel-transcoder.vala

index fa29b50..3eb3da9 100644 (file)
@@ -53,6 +53,7 @@ VAPI_SOURCE_FILES = rygel-configuration.vala \
                    rygel-http-request.vala \
                    rygel-http-request-handler.vala \
                    rygel-identity-request-handler.vala \
+                   rygel-http-transcode-handler.vala \
                    rygel-seek.vala \
                    rygel-http-response.vala \
                    rygel-live-response.vala \
index 481f25b..61d21ff 100644 (file)
@@ -80,10 +80,10 @@ internal class Rygel.HTTPRequest : GLib.Object, Rygel.StateMachine {
 
         if (this.query != null) {
             this.item_id = this.query.lookup ("itemid");
-            var transcode_target = this.query.lookup ("transcode");
-            if (transcode_target != null) {
-                this.request_handler = this.http_server.get_transcoder (
-                                                    transcode_target);
+            var target = this.query.lookup ("transcode");
+            if (target != null) {
+                var transcoder = this.http_server.get_transcoder (target);
+                this.request_handler = new HTTPTranscodeHandler (transcoder);
             }
         }
 
diff --git a/src/rygel/rygel-http-transcode-handler.vala b/src/rygel/rygel-http-transcode-handler.vala
new file mode 100644 (file)
index 0000000..3596e7a
--- /dev/null
@@ -0,0 +1,62 @@
+/*
+ * Copyright (C) 2009 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 Rygel;
+using Gst;
+
+/**
+ * The handler for HTTP transcoding requests.
+ */
+internal class Rygel.HTTPTranscodeHandler : GLib.Object, HTTPRequestHandler {
+    private Transcoder transcoder;
+
+    public HTTPTranscodeHandler (Transcoder transcoder) {
+        this.transcoder = transcoder;
+    }
+
+    public virtual void add_response_headers (HTTPRequest request)
+                                              throws HTTPRequestError {
+        request.msg.response_headers.append ("Content-Type",
+                                             this.transcoder.mime_type);
+        if (request.time_range != null) {
+            request.time_range.add_response_header (request.msg);
+        }
+    }
+
+    public virtual HTTPResponse render_body (HTTPRequest request)
+                                             throws HTTPRequestError {
+        var item = request.item;
+        var src = item.create_stream_source ();
+        if (src == null) {
+            throw new HTTPRequestError.NOT_FOUND ("Not found");
+        }
+
+        src = this.transcoder.create_source (item, src);
+
+        return new LiveResponse (request.server,
+                                 request.msg,
+                                 "RygelLiveResponse",
+                                 src,
+                                 request.time_range);
+    }
+}
+
index 593e9bd..f826ba7 100644 (file)
@@ -29,7 +29,7 @@ using Gee;
  * The base Transcoder class. Each implementation derives from it and must
  * at least implement create_source method.
  */
-internal abstract class Rygel.Transcoder : GLib.Object, HTTPRequestHandler {
+internal abstract class Rygel.Transcoder : GLib.Object {
     public string mime_type { get; protected set; }
     public string dlna_profile { get; protected set; }
 
@@ -103,30 +103,5 @@ internal abstract class Rygel.Transcoder : GLib.Object, HTTPRequestHandler {
 
         return g_content_type_is_a (content_type1, content_type2);
     }
-
-    public virtual void add_response_headers (HTTPRequest request)
-                                              throws HTTPRequestError {
-        request.msg.response_headers.append ("Content-Type", this.mime_type);
-        if (request.time_range != null) {
-            request.time_range.add_response_header(request.msg);
-        }
-    }
-
-    public virtual HTTPResponse render_body (HTTPRequest request)
-                                             throws HTTPRequestError {
-        var item = request.item;
-        var src = item.create_stream_source ();
-        if (src == null) {
-            throw new HTTPRequestError.NOT_FOUND ("Not found");
-        }
-
-        src = this.create_source (item, src);
-
-        return new LiveResponse (request.server,
-                                 request.msg,
-                                 "RygelLiveResponse",
-                                 src,
-                                 request.time_range);
-    }
 }