[rygel/wip/media-engine: 3/13] core: Separate GStreamer details from Transcoder class



commit 62818ba02438c1c05e1e2b1895faeb375d65a627
Author: Jens Georg <jensg openismus org>
Date:   Thu Aug 30 14:00:21 2012 +0200

    core: Separate GStreamer details from Transcoder class

 src/librygel-server/filelist.am                  |    7 +-
 src/librygel-server/rygel-audio-transcoder.vala  |    3 +-
 src/librygel-server/rygel-gst-transcoder.vala    |  160 ++++++++++++++++++++++
 src/librygel-server/rygel-transcode-manager.vala |    6 +-
 src/librygel-server/rygel-transcoder.vala        |  118 +---------------
 5 files changed, 177 insertions(+), 117 deletions(-)
---
diff --git a/src/librygel-server/filelist.am b/src/librygel-server/filelist.am
index 9bea5f8..46ad6a3 100644
--- a/src/librygel-server/filelist.am
+++ b/src/librygel-server/filelist.am
@@ -18,6 +18,8 @@ LIBRYGEL_SERVER_VAPI_SOURCE_FILES = \
 	rygel-media-server-plugin.vala \
 	rygel-search-expression.vala \
 	rygel-searchable-container.vala \
+	rygel-transcode-manager.vala \
+	rygel-transcoder.vala \
 	rygel-visual-item.vala \
 	rygel-writable-container.vala \
 	rygel-media-server.vala \
@@ -60,15 +62,14 @@ LIBRYGEL_SERVER_NONVAPI_SOURCE_FILES = \
 	rygel-source-connection-manager.vala \
 	rygel-subtitle-manager.vala \
 	rygel-thumbnailer.vala \
-	rygel-transcode-manager.vala \
-	rygel-transcoder.vala \
 	rygel-v1-hacks.vala \
 	rygel-video-transcoder.vala \
 	rygel-wmp-hacks.vala \
 	rygel-wmv-transcoder.vala \
 	rygel-xbmc-hacks.vala \
 	rygel-xbox-hacks.vala \
-	rygel-gst-media-engine.vala
+	rygel-gst-media-engine.vala \
+	rygel-gst-transcoder.vala
 
 LIBRYGEL_SERVER_VALAFLAGS_PKG = \
 	--pkg gstreamer-0.10 \
diff --git a/src/librygel-server/rygel-audio-transcoder.vala b/src/librygel-server/rygel-audio-transcoder.vala
index 8ff88a4..d46880c 100644
--- a/src/librygel-server/rygel-audio-transcoder.vala
+++ b/src/librygel-server/rygel-audio-transcoder.vala
@@ -1,5 +1,6 @@
 /*
  * Copyright (C) 2011 Nokia Corporation.
+ * Copyright (C) 2012 Intel Corporation.
  *
  * Author: Jens Georg <jensg openismus com>
  *
@@ -25,7 +26,7 @@ using GUPnP;
 /**
  * Base class for all transcoders that handle audio.
  */
-internal class Rygel.AudioTranscoder : Rygel.Transcoder {
+internal class Rygel.AudioTranscoder : Rygel.GstTranscoder {
     protected int audio_bitrate;
     protected Caps container_format = null;
     protected Caps audio_codec_format = null;
diff --git a/src/librygel-server/rygel-gst-transcoder.vala b/src/librygel-server/rygel-gst-transcoder.vala
new file mode 100644
index 0000000..af6f6c6
--- /dev/null
+++ b/src/librygel-server/rygel-gst-transcoder.vala
@@ -0,0 +1,160 @@
+/*
+ * Copyright (C) 2009-2012 Nokia Corporation.
+ * Copyright (C) 2012 Intel Corporation.
+ *
+ * Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
+ *                               <zeeshan ali nokia com>
+ *         Jens Georg <jensg openismus 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 Gst;
+using GUPnP;
+
+/**
+ * The base Transcoder class. Each implementation derives from it and must
+ * implement get_distance and get_encoding_profile methods.
+ */
+internal abstract class Rygel.GstTranscoder : Rygel.Transcoder {
+    public string preset { get;
+                           protected set;
+                           default =  DEFAULT_ENCODING_PRESET; }
+
+    private const string DECODE_BIN = "decodebin2";
+    private const string ENCODE_BIN = "encodebin";
+    private const string DEFAULT_ENCODING_PRESET = "Rygel DLNA preset";
+
+    dynamic Element decoder;
+    dynamic Element encoder;
+
+    private bool link_failed;
+
+    public GstTranscoder (string mime_type,
+                          string dlna_profile,
+                          string upnp_class,
+                          string extension) {
+        this.mime_type = mime_type;
+        this.dlna_profile = dlna_profile;
+        this.link_failed = true;
+        this.extension = extension;
+    }
+
+    /**
+     * Creates a transcoding source.
+     *
+     * @param src the media item to create the transcoding source for
+     * @param src the original (non-transcoding) source
+     *
+     * @return      the new transcoding source
+     */
+    public override Element create_source (MediaItem item,
+                                           Element   src) throws Error {
+        this.decoder = GstUtils.create_element (DECODE_BIN,
+                                                DECODE_BIN);
+        this.encoder = GstUtils.create_element (ENCODE_BIN,
+                                                ENCODE_BIN);
+
+        encoder.profile = this.get_encoding_profile ();
+        debug ("%s using the following encoding profile:",
+               this.get_class ().get_type ().name ());
+        GstUtils.dump_encoding_profile (encoder.profile);
+
+        var bin = new Bin ("transcoder-source");
+        bin.add_many (src, decoder, encoder);
+
+        src.link (decoder);
+
+        decoder.pad_added.connect (this.on_decoder_pad_added);
+        decoder.autoplug_continue.connect (this.on_autoplug_continue);
+        decoder.no_more_pads.connect (this.on_no_more_pads);
+
+        var pad = encoder.get_static_pad ("src");
+        var ghost = new GhostPad (null, pad);
+        bin.add_pad (ghost);
+
+        return bin;
+    }
+
+    /**
+     * Gets the Gst.EncodingProfile for this transcoder.
+     *
+     * @return      the Gst.EncodingProfile for this transcoder.
+     */
+    protected abstract EncodingProfile get_encoding_profile ();
+
+    private bool on_autoplug_continue (Element decodebin,
+                                       Pad     new_pad,
+                                       Caps    caps) {
+        Gst.Pad sinkpad = null;
+
+        Signal.emit_by_name (this.encoder, "request-pad", caps, out sinkpad);
+        if (sinkpad == null) {
+            return true;
+        }
+
+        return false;
+    }
+
+    private void on_decoder_pad_added (Element decodebin, Pad new_pad) {
+        Gst.Pad sinkpad;
+
+        sinkpad = this.encoder.get_compatible_pad (new_pad, null);
+
+        if (sinkpad == null) {
+            var caps = new_pad.get_caps_reffed ();
+            Signal.emit_by_name (this.encoder, "request-pad", caps, out sinkpad);
+        }
+
+        if (sinkpad == null) {
+            debug ("No compatible encodebin pad found for pad '%s', ignoring..",
+                   new_pad.name);
+
+            return;
+        }
+
+        var pad_link_ok = (new_pad.link (sinkpad) == PadLinkReturn.OK);
+        if (!pad_link_ok) {
+            warning ("Failed to link pad '%s' to '%s'",
+                     new_pad.name,
+                     sinkpad.name);
+        } else {
+            this.link_failed = false;
+        }
+
+        return;
+    }
+
+    private const string description = "Encoder and decoder are not " +
+                                       "compatible";
+
+    private void on_no_more_pads (Element decodebin) {
+        // We haven't found any pads we could link
+        if (this.link_failed) {
+            // Signalize that error
+            var bin = this.encoder.get_parent () as Bin;
+            var error = new IOError.FAILED ("Could not link");
+            var message = new Message.error (bin,
+                                             error,
+                                             description);
+
+
+            var bus = bin.get_bus ();
+            bus.post (message);
+        }
+    }
+}
diff --git a/src/librygel-server/rygel-transcode-manager.vala b/src/librygel-server/rygel-transcode-manager.vala
index 69e1f48..42a69c4 100644
--- a/src/librygel-server/rygel-transcode-manager.vala
+++ b/src/librygel-server/rygel-transcode-manager.vala
@@ -1,8 +1,10 @@
 /*
- * Copyright (C) 2009 Nokia Corporation.
+ * Copyright (C) 2009-2012 Nokia Corporation.
+ * Copyright (C) 2012 Intel Corporation.
  *
  * Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
  *                               <zeeshan ali nokia com>
+ *         Jens Georg <jensg openismus com>
  *
  * This file is part of Rygel.
  *
@@ -30,7 +32,7 @@ using Gst;
  *    - gets the appropriate transcoder given a transcoding target.
  *    - provide all possible transcoding resources for items.
  */
-internal abstract class Rygel.TranscodeManager : GLib.Object {
+public abstract class Rygel.TranscodeManager : GLib.Object {
     private ArrayList<Transcoder> transcoders;
 
     private static bool protocol_equal_func (void *a, void *b) {
diff --git a/src/librygel-server/rygel-transcoder.vala b/src/librygel-server/rygel-transcoder.vala
index 05b3a23..64d3a14 100644
--- a/src/librygel-server/rygel-transcoder.vala
+++ b/src/librygel-server/rygel-transcoder.vala
@@ -1,8 +1,10 @@
 /*
- * Copyright (C) 2009 Nokia Corporation.
+ * Copyright (C) 2009-2012 Nokia Corporation.
+ * Copyright (C) 2012 Intel Corporation.
  *
  * Author: Zeeshan Ali (Khattak) <zeeshanak gnome org>
  *                               <zeeshan ali nokia com>
+ *         Jens Georg <jensg openismus com>
  *
  * This file is part of Rygel.
  *
@@ -26,39 +28,12 @@ using GUPnP;
 
 /**
  * The base Transcoder class. Each implementation derives from it and must
- * implement get_distance and get_encoding_profile methods.
+ * implement get_distance.
  */
-internal abstract class Rygel.Transcoder : GLib.Object {
+public abstract class Rygel.Transcoder : GLib.Object {
     public string mime_type { get; protected set; }
     public string dlna_profile { get; protected set; }
     public string extension { get; protected set; }
-    public string preset { get;
-                           protected set;
-                           default =  DEFAULT_ENCODING_PRESET; }
-
-    private const string DECODE_BIN = "decodebin2";
-    private const string ENCODE_BIN = "encodebin";
-    private const string DEFAULT_ENCODING_PRESET = "Rygel DLNA preset";
-
-    dynamic Element decoder;
-    dynamic Element encoder;
-
-    private bool link_failed;
-
-    // Primary UPnP item class that this transcoder is meant for, doesn't
-    // necessarily mean it cant be used for other classes.
-    public string upnp_class { get; protected set; }
-
-    public Transcoder (string mime_type,
-                       string dlna_profile,
-                       string upnp_class,
-                       string extension) {
-        this.mime_type = mime_type;
-        this.dlna_profile = dlna_profile;
-        this.upnp_class = upnp_class;
-        this.link_failed = true;
-        this.extension = extension;
-    }
 
     /**
      * Creates a transcoding source.
@@ -68,32 +43,8 @@ internal abstract class Rygel.Transcoder : GLib.Object {
      *
      * @return      the new transcoding source
      */
-    public virtual Element create_source (MediaItem item,
-                                          Element   src) throws Error {
-        this.decoder = GstUtils.create_element (DECODE_BIN,
-                                                DECODE_BIN);
-        this.encoder = GstUtils.create_element (ENCODE_BIN,
-                                                ENCODE_BIN);
-
-        encoder.profile = this.get_encoding_profile ();
-        debug ("%s using the following encoding profile:",
-               this.get_class ().get_type ().name ());
-        GstUtils.dump_encoding_profile (encoder.profile);
-
-        var bin = new Bin ("transcoder-source");
-        bin.add_many (src, decoder, encoder);
-
-        src.link (decoder);
-
-        decoder.pad_added.connect (this.on_decoder_pad_added);
-        decoder.no_more_pads.connect (this.on_no_more_pads);
-
-        var pad = encoder.get_static_pad ("src");
-        var ghost = new GhostPad (null, pad);
-        bin.add_pad (ghost);
-
-        return bin;
-    }
+    public abstract Element create_source (MediaItem item,
+                                           Element   src) throws Error;
 
     public virtual DIDLLiteResource? add_resource (DIDLLiteItem     didl_item,
                                                    MediaItem        item,
@@ -145,65 +96,10 @@ internal abstract class Rygel.Transcoder : GLib.Object {
      */
     public abstract uint get_distance (MediaItem item);
 
-    /**
-     * Gets the Gst.EncodingProfile for this transcoder.
-     *
-     * @return      the Gst.EncodingProfile for this transcoder.
-     */
-    protected abstract EncodingProfile get_encoding_profile ();
-
     protected bool mime_type_is_a (string mime_type1, string mime_type2) {
         string content_type1 = ContentType.get_mime_type (mime_type1);
         string content_type2 = ContentType.get_mime_type (mime_type2);
 
         return ContentType.is_a (content_type1, content_type2);
     }
-
-    private void on_decoder_pad_added (Element decodebin, Pad new_pad) {
-        Gst.Pad sinkpad;
-
-        sinkpad = this.encoder.get_compatible_pad (new_pad, null);
-
-        if (sinkpad == null) {
-            var caps = new_pad.get_caps_reffed ();
-            Signal.emit_by_name (this.encoder, "request-pad", caps, out sinkpad);
-        }
-
-        if (sinkpad == null) {
-            debug ("No compatible encodebin pad found for pad '%s', ignoring..",
-                   new_pad.name);
-
-            return;
-        }
-
-        var pad_link_ok = (new_pad.link (sinkpad) == PadLinkReturn.OK);
-        if (!pad_link_ok) {
-            warning ("Failed to link pad '%s' to '%s'",
-                     new_pad.name,
-                     sinkpad.name);
-        } else {
-            this.link_failed = false;
-        }
-
-        return;
-    }
-
-    private const string description = "Encoder and decoder are not " +
-                                       "compatible";
-
-    private void on_no_more_pads (Element decodebin) {
-        // We haven't found any pads we could link
-        if (this.link_failed) {
-            // Signalize that error
-            var bin = this.encoder.get_parent () as Bin;
-            var error = new IOError.FAILED ("Could not link");
-            var message = new Message.error (bin,
-                                             error,
-                                             description);
-
-
-            var bus = bin.get_bus ();
-            bus.post (message);
-        }
-    }
 }



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