[rygel] core: Unified encodebin-based transcoding



commit 3f2ecfe814154ddf0efea5e4a7ef67d3a543b148
Author: Luis de Bethencourt <luis debethencourt com>
Date:   Mon Mar 14 18:28:05 2011 +0100

    core: Unified encodebin-based transcoding
    
    Move the core of transcoding into the base transcoder class so each
    transcoder then simply has to provide an encoding profile (as a
    GstEncodingProfile) and not have to create the static pipelines etc.
    
    Co-author: Zeeshan Ali (Khattak) <zeeshanak gnome org>

 po/POTFILES.in                          |    3 -
 po/POTFILES.skip                        |    3 -
 src/rygel/Makefile.am                   |    3 -
 src/rygel/rygel-gst-utils.vala          |    5 -
 src/rygel/rygel-l16-transcoder-bin.vala |   72 ------------------
 src/rygel/rygel-l16-transcoder.vala     |   79 +++++---------------
 src/rygel/rygel-mp2ts-transcoder.vala   |  123 ++++++++-----------------------
 src/rygel/rygel-mp3-transcoder.vala     |   57 +--------------
 src/rygel/rygel-transcode-manager.vala  |    2 +-
 src/rygel/rygel-transcoder.vala         |   74 +++++++++++++++++-
 src/rygel/rygel-wma-transcoder-bin.vala |   66 ----------------
 src/rygel/rygel-wma-transcoder.vala     |   40 ++--------
 src/rygel/rygel-wmv-transcoder-bin.vala |  106 --------------------------
 src/rygel/rygel-wmv-transcoder.vala     |   65 +++++++----------
 14 files changed, 157 insertions(+), 541 deletions(-)
---
diff --git a/po/POTFILES.in b/po/POTFILES.in
index 99a4487..2f09bd1 100644
--- a/po/POTFILES.in
+++ b/po/POTFILES.in
@@ -98,7 +98,6 @@ src/rygel/rygel-icon-info.vala
 src/rygel/rygel-import-resource.vala
 src/rygel/rygel-item-creator.vala
 src/rygel/rygel-item-destroyer.vala
-src/rygel/rygel-l16-transcoder-bin.vala
 src/rygel/rygel-l16-transcoder.vala
 src/rygel/rygel-log-handler.vala
 src/rygel/rygel-logical-expression.vala
@@ -136,9 +135,7 @@ src/rygel/rygel-thumbnail.vala
 src/rygel/rygel-transcode-manager.vala
 src/rygel/rygel-transcoder.vala
 src/rygel/rygel-user-config.vala
-src/rygel/rygel-wma-transcoder-bin.vala
 src/rygel/rygel-wma-transcoder.vala
-src/rygel/rygel-wmv-transcoder-bin.vala
 src/rygel/rygel-wmv-transcoder.vala
 src/rygel/rygel-xbox-hacks.vala
 src/rygel/rygel-changelog.vala
diff --git a/po/POTFILES.skip b/po/POTFILES.skip
index 0aad253..c49ab2d 100644
--- a/po/POTFILES.skip
+++ b/po/POTFILES.skip
@@ -58,7 +58,6 @@ src/rygel/rygel-http-transcode-handler.c
 src/rygel/rygel-import-resource.c
 src/rygel/rygel-item-creator.c
 src/rygel/rygel-item-destroyer.c
-src/rygel/rygel-l16-transcoder-bin.c
 src/rygel/rygel-http-response.c
 src/rygel/rygel-log-handler.c
 src/rygel/rygel-main.c
@@ -79,8 +78,6 @@ src/rygel/rygel-subtitle-manager.c
 src/rygel/rygel-thumbnailer.c
 src/rygel/rygel-transcode-manager.c
 src/rygel/rygel-user-config.c
-src/rygel/rygel-wma-transcoder-bin.c
-src/rygel/rygel-wmv-transcoder-bin.c
 src/rygel/rygel-xbox-hacks.c
 src/rygel/rygel-changelog.c
 src/rygel/rygel-media-query-action.c
diff --git a/src/rygel/Makefile.am b/src/rygel/Makefile.am
index 0b11356..a3b1f99 100644
--- a/src/rygel/Makefile.am
+++ b/src/rygel/Makefile.am
@@ -95,11 +95,8 @@ VAPI_SOURCE_FILES = \
 	rygel-mp2ts-transcoder.vala \
 	rygel-mp3-transcoder.vala \
 	rygel-l16-transcoder.vala \
-	rygel-l16-transcoder-bin.vala \
 	rygel-wma-transcoder.vala \
-	rygel-wma-transcoder-bin.vala \
 	rygel-wmv-transcoder.vala \
-	rygel-wmv-transcoder-bin.vala \
 	rygel-gst-utils.vala \
 	rygel-media-receiver-registrar.vala \
 	rygel-log-handler.vala \
diff --git a/src/rygel/rygel-gst-utils.vala b/src/rygel/rygel-gst-utils.vala
index 45521a8..6232baf 100644
--- a/src/rygel/rygel-gst-utils.vala
+++ b/src/rygel/rygel-gst-utils.vala
@@ -42,11 +42,6 @@ internal abstract class Rygel.GstUtils {
         return element;
     }
 
-    public static void post_error (Element dest, Error error) {
-        Message msg = new Message.error (dest, error, error.message);
-        dest.post_message (msg);
-    }
-
     public static ClockTime time_from_string (string str) {
         uint64 hours, minutes, seconds;
 
diff --git a/src/rygel/rygel-l16-transcoder.vala b/src/rygel/rygel-l16-transcoder.vala
index ac9bbff..1041aee 100644
--- a/src/rygel/rygel-l16-transcoder.vala
+++ b/src/rygel/rygel-l16-transcoder.vala
@@ -24,14 +24,8 @@ using Gst;
 using GUPnP;
 using Gee;
 
-internal enum Endianness {
-    LITTLE = ByteOrder.LITTLE_ENDIAN,
-    BIG = ByteOrder.BIG_ENDIAN
-}
-
 /**
- * Transcoder for linear PCM audio (LPCM). This element uses L16TrancoderBin for
- * actual transcoding.
+ * Transcoder for linear PCM audio (LPCM).
  */
 internal class Rygel.L16Transcoder : Rygel.Transcoder {
     private const int CHANNELS = 2;
@@ -39,28 +33,14 @@ internal class Rygel.L16Transcoder : Rygel.Transcoder {
     private const int WIDTH = 16;
     private const int DEPTH = 16;
     private const bool SIGNED = true;
+    private const int ENDIANNESS = 1234;
 
-    private Endianness endianness;
-
-    private const string AUDIO_CONVERT = "audioconvert";
-    private const string AUDIO_RESAMPLE = "audioresample";
-    private const string AUDIO_RATE = "audiorate";
-    private const string CAPS_FILTER = "capsfilter";
-
-    public L16Transcoder (Endianness endianness) {
+    public L16Transcoder () {
         var mime_type = "audio/L" + L16Transcoder.WIDTH.to_string () +
                         ";rate=" + L16Transcoder.FREQUENCY.to_string () +
                         ";channels=" + L16Transcoder.CHANNELS.to_string ();
 
         base (mime_type, "LPCM", AudioItem.UPNP_CLASS);
-
-        this.endianness = endianness;
-    }
-
-    public override Element create_source (MediaItem item,
-                                           Element   src)
-                                           throws Error {
-        return new L16TranscoderBin (item, src, this);
     }
 
     public override DIDLLiteResource? add_resource (DIDLLiteItem     didl_item,
@@ -105,43 +85,20 @@ internal class Rygel.L16Transcoder : Rygel.Transcoder {
         return distance;
     }
 
-    public Element create_encoder (MediaItem item,
-                                   string?   src_pad_name,
-                                   string?   sink_pad_name)
-                                   throws Error {
-        dynamic Element convert1 = GstUtils.create_element (AUDIO_CONVERT,
-                                                            null);
-        dynamic Element resample = GstUtils.create_element (AUDIO_RESAMPLE,
-                                                            AUDIO_RESAMPLE);
-        dynamic Element audiorate = GstUtils.create_element (AUDIO_RATE, null);
-        dynamic Element convert2 = GstUtils.create_element (AUDIO_CONVERT,
-                                                            null);
-        dynamic Element capsfilter = GstUtils.create_element (CAPS_FILTER,
-                                                              CAPS_FILTER);
-
-        var bin = new Bin ("l16-encoder-bin");
-        bin.add_many (convert1, resample, audiorate, convert2, capsfilter);
-
-        capsfilter.caps = new Caps.simple (
-                                    "audio/x-raw-int",
-                                    "channels", typeof (int), CHANNELS,
-                                    "rate",  typeof (int), FREQUENCY,
-                                    "width", typeof (int), WIDTH,
-                                    "depth", typeof (int), DEPTH,
-                                    "signed", typeof (bool), SIGNED,
-                                    "endianness", typeof (int),
-                                    this.endianness);
-
-        convert1.link_many (resample, audiorate, convert2, capsfilter);
-
-        var pad = convert1.get_static_pad ("sink");
-        var ghost = new GhostPad (sink_pad_name, pad);
-        bin.add_pad (ghost);
-
-        pad = capsfilter.get_static_pad ("src");
-        ghost = new GhostPad (src_pad_name, pad);
-        bin.add_pad (ghost);
-
-        return bin;
+    protected override EncodingProfile get_encoding_profile () {
+        var caps_str = "audio/x-raw-int" +
+                       ",channels=" + CHANNELS.to_string () +
+                       ",rate=" +  FREQUENCY.to_string () +
+                       ",width=" + WIDTH.to_string () +
+                       ",depth=" + DEPTH.to_string () +
+                       ",signed=" + SIGNED.to_string () +
+                       ",endianness=" + ENDIANNESS.to_string();
+        var format = Caps.from_string (caps_str);
+
+        var encoding_profile =  new EncodingAudioProfile (format,
+                                                          null,
+                                                          null,
+                                                          1);
+        return encoding_profile;
     }
 }
diff --git a/src/rygel/rygel-mp2ts-transcoder.vala b/src/rygel/rygel-mp2ts-transcoder.vala
index f077a48..af53c08 100644
--- a/src/rygel/rygel-mp2ts-transcoder.vala
+++ b/src/rygel/rygel-mp2ts-transcoder.vala
@@ -43,9 +43,6 @@ internal class Rygel.MP2TSTranscoder : Rygel.Transcoder {
     private const string[] PROFILES = {"MPEG_TS_SD_EU_ISO", "MPEG_TS_HD_NA_ISO"};
     private const int BITRATE = 3000000;
 
-    private const string DECODE_BIN = "decodebin2";
-    private const string ENCODE_BIN = "encodebin";
-
     private MP2TSProfile profile;
 
     public MP2TSTranscoder (MP2TSProfile profile) {
@@ -54,30 +51,6 @@ internal class Rygel.MP2TSTranscoder : Rygel.Transcoder {
         this.profile = profile;
     }
 
-    public override Element create_source (MediaItem item,
-                                           Element   src)
-                                           throws Error {
-        dynamic Element decoder = GstUtils.create_element (DECODE_BIN,
-                                                           DECODE_BIN);
-        dynamic Element encoder = GstUtils.create_element (ENCODE_BIN,
-                                                           ENCODE_BIN);
-
-        encoder.profile = this.get_encoding_profile ();
-
-        var bin = new Bin ("mp2-ts-transcoder-bin");
-        bin.add_many (src, decoder, encoder);
-
-        src.link (decoder);
-
-        decoder.pad_added.connect (this.on_decoder_pad_added);
-
-        var pad = encoder.get_static_pad ("src");
-        var ghost = new GhostPad (null, pad);
-        bin.add_pad (ghost);
-
-        return bin;
-    }
-
     public override DIDLLiteResource? add_resource (DIDLLiteItem     didl_item,
                                                     MediaItem        item,
                                                     TranscodeManager manager)
@@ -116,72 +89,40 @@ internal class Rygel.MP2TSTranscoder : Rygel.Transcoder {
         return distance;
     }
 
-    private void on_decoder_pad_added (Element decodebin, Pad new_pad) {
-        var bin = decodebin.get_parent () as Bin;
-        assert (bin != null);
-
-        var encoder = bin.get_by_name (ENCODE_BIN);
-        assert (encoder != null);
-
-        var encoder_pad = encoder.get_compatible_pad (new_pad, null);
-        if (encoder_pad == null) {
-            debug ("No compatible encodebin pad found for pad '%s', ignoring..",
-                   new_pad.name);
-            return;
-        } else {
-            debug ("pad '%s' with caps '%s' is compatible with '%s'",
-                   new_pad.name,
-                   new_pad.get_caps ().to_string (),
-                   encoder_pad.name);
-        }
-
-        if (new_pad.link (encoder_pad) != PadLinkReturn.OK) {
-            var error = new GstError.LINK (_("Failed to link pad %s to %s"),
-                                           new_pad.name,
-                                           encoder_pad.name);
-            GstUtils.post_error (bin, error);
-        }
-    }
-
-    private EncodingContainerProfile get_encoding_profile () {
-        var container_format = Caps.from_string ("video/mpegts," +
-                                                 "systemstream=true," +
-                                                 "packetsize=188");
-
-        var enc_container_profile = new EncodingContainerProfile
-                                        ("mpeg-ts-profile",
-                                         null,
-                                         container_format,
-                                         null);
-
-        enc_container_profile.add_profile (this.get_video_profile ());
-        enc_container_profile.add_profile (this.get_audio_profile ());
-
-        return enc_container_profile;
-    }
-
-    private EncodingVideoProfile get_video_profile () {
-        var format = Caps.from_string ("video/mpeg," +
-                                       "mpegversion=2," +
-                                       "systemstream=false," +
-                                       "framerate=(fraction)25/1");
-        var restriction = Caps.from_string
-                                        ("video/x-raw-yuv,width=" +
-                                         WIDTH[this.profile].to_string () +
-                                         ",height=" +
-                                         HEIGHT[this.profile].to_string () +
-                                         ",framerate=(fraction)" +
-                                         FRAME_RATE[this.profile].to_string () +
-                                         "/1");
+    protected override EncodingProfile get_encoding_profile () {
+        var cont_format = Caps.from_string ("video/mpegts," +
+                                            "systemstream=true," +
+                                            "packetsize=188");
+
+        var video_format = Caps.from_string ("video/mpeg," +
+                                             "mpegversion=2," +
+                                             "systemstream=false," +
+                                             "framerate=(fraction)25/1");
+        var video_restriction = Caps.from_string
+                                            ("video/x-raw-yuv," +
+                                             "framerate=(fraction)25/1," +
+                                             "width=720," +
+                                             "height=576");
+
+        var audio_format = Caps.from_string ("audio/mpeg, mpegversion=(int)4");
+
+        var enc_container_profile = new EncodingContainerProfile ("container",
+                                                                  null,
+                                                                  cont_format,
+                                                                  null);
+        var enc_video_profile = new EncodingVideoProfile (video_format,
+                                                          null,
+                                                          video_restriction,
+                                                          1);
+        var enc_audio_profile = new EncodingAudioProfile (audio_format,
+                                                          null,
+                                                          null,
+                                                          1);
 
         // FIXME: We should use the preset to set bitrate
-        return new EncodingVideoProfile (format, null, restriction, 1);
-    }
+        enc_container_profile.add_profile (enc_video_profile);
+        enc_container_profile.add_profile (enc_audio_profile);
 
-    private EncodingAudioProfile get_audio_profile () {
-        var format = Caps.from_string ("audio/mpeg,mpegversion=4");
-
-        // FIXME: We should use the preset to set bitrate
-        return new EncodingAudioProfile (format, null, null, 1);
+        return enc_container_profile;
     }
 }
diff --git a/src/rygel/rygel-mp3-transcoder.vala b/src/rygel/rygel-mp3-transcoder.vala
index 39490f4..5eee0cf 100644
--- a/src/rygel/rygel-mp3-transcoder.vala
+++ b/src/rygel/rygel-mp3-transcoder.vala
@@ -30,37 +30,10 @@ using Gee;
 internal class Rygel.MP3Transcoder : Rygel.Transcoder {
     public const int BITRATE = 256;
 
-    private const string DECODE_BIN = "decodebin2";
-    private const string ENCODE_BIN = "encodebin";
-
     public MP3Transcoder () {
         base ("audio/mpeg", "MP3", AudioItem.UPNP_CLASS);
     }
 
-    public override Element create_source (MediaItem item,
-                                           Element   src)
-                                           throws Error {
-        dynamic Element decoder = GstUtils.create_element (DECODE_BIN,
-                                                           DECODE_BIN);
-        dynamic Element encoder = GstUtils.create_element (ENCODE_BIN,
-                                                           ENCODE_BIN);
-
-        encoder.profile = this.get_encoding_profile ();
-
-        var bin = new Bin ("mp3-transcoder-bin");
-        bin.add_many (src, decoder, encoder);
-
-        src.link (decoder);
-
-        decoder.pad_added.connect (this.on_decoder_pad_added);
-
-        var pad = encoder.get_static_pad ("src");
-        var ghost = new GhostPad (null, pad);
-        bin.add_pad (ghost);
-
-        return bin;
-    }
-
     public override DIDLLiteResource? add_resource (DIDLLiteItem     didl_item,
                                                     MediaItem        item,
                                                     TranscodeManager manager)
@@ -90,35 +63,7 @@ internal class Rygel.MP3Transcoder : Rygel.Transcoder {
         return distance;
     }
 
-    private void on_decoder_pad_added (Element decodebin, Pad new_pad) {
-        var bin = decodebin.get_parent () as Bin;
-        assert (bin != null);
-
-        var encoder = bin.get_by_name (ENCODE_BIN);
-        assert (encoder != null);
-
-        var encoder_pad = encoder.get_compatible_pad (new_pad, null);
-        if (encoder_pad == null) {
-            debug ("No compatible encodebin pad found for pad '%s', ignoring..",
-                   new_pad.name);
-
-            return;
-        } else {
-            debug ("pad '%s' with caps '%s' is compatible with '%s'",
-                   new_pad.name,
-                   new_pad.get_caps ().to_string (),
-                   encoder_pad.name);
-        }
-
-        if (new_pad.link (encoder_pad) != PadLinkReturn.OK) {
-            var error = new GstError.LINK (_("Failed to link pad %s to %s"),
-                                           new_pad.name,
-                                           encoder_pad.name);
-            GstUtils.post_error (bin, error);
-        }
-    }
-
-    private EncodingProfile get_encoding_profile () {
+    protected override EncodingProfile get_encoding_profile () {
         var format = Caps.from_string ("audio/mpeg,mpegversion=1,layer=3");
         // FIXME: We should use the preset to set bitrate
         var encoding_profile = new EncodingAudioProfile (format, null, null, 1);
diff --git a/src/rygel/rygel-transcode-manager.vala b/src/rygel/rygel-transcode-manager.vala
index 08ab9b9..8a3c17f 100644
--- a/src/rygel/rygel-transcode-manager.vala
+++ b/src/rygel/rygel-transcode-manager.vala
@@ -65,7 +65,7 @@ internal abstract class Rygel.TranscodeManager : GLib.Object {
 
         if (transcoding) {
             if (lpcm_transcoder) {
-                transcoders.add (new L16Transcoder (Endianness.BIG));
+                transcoders.add (new L16Transcoder ());
             }
 
             if (mp3_transcoder) {
diff --git a/src/rygel/rygel-transcoder.vala b/src/rygel/rygel-transcoder.vala
index 5ab805c..cade284 100644
--- a/src/rygel/rygel-transcoder.vala
+++ b/src/rygel/rygel-transcoder.vala
@@ -27,11 +27,15 @@ using Gee;
 
 /**
  * The base Transcoder class. Each implementation derives from it and must
- * at least implement create_source method.
+ * implement get_distance and get_encoding_profile methods.
  */
 internal abstract class Rygel.Transcoder : GLib.Object {
     public string mime_type { get; protected set; }
     public string dlna_profile { get; protected set; }
+    public Gst.Caps decoder_caps;
+
+    private const string DECODE_BIN = "decodebin2";
+    private const string ENCODE_BIN = "encodebin";
 
     // Primary UPnP item class that this transcoder is meant for, doesn't
     // necessarily mean it cant be used for other classes.
@@ -53,8 +57,29 @@ internal abstract class Rygel.Transcoder : GLib.Object {
      *
      * @return      the new transcoding source
      */
-    public abstract Element create_source (MediaItem item,
-                                           Element   src) throws Error;
+    public virtual Element create_source (MediaItem item,
+                                          Element   src) throws Error {
+        dynamic Element decoder = GstUtils.create_element (DECODE_BIN,
+                                                           DECODE_BIN);
+        dynamic Element encoder = GstUtils.create_element (ENCODE_BIN,
+                                                           ENCODE_BIN);
+
+        encoder.profile = this.get_encoding_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);
+
+        var pad = encoder.get_static_pad ("src");
+        var ghost = new GhostPad (null, pad);
+        bin.add_pad (ghost);
+
+        return bin;
+    }
 
     public virtual DIDLLiteResource? add_resource (DIDLLiteItem     didl_item,
                                                    MediaItem        item,
@@ -105,11 +130,52 @@ 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 bool on_autoplug_continue (Element decodebin,
+                                       Pad     new_pad,
+                                       Caps    caps) {
+        this.decoder_caps = caps;
+        return !this.connect_decoder_pad (decodebin, new_pad);
+    }
+
+    private void on_decoder_pad_added (Element decodebin, Pad new_pad) {
+        this.connect_decoder_pad (decodebin, new_pad);
+    }
+
+    private bool connect_decoder_pad (Element decodebin, Pad new_pad) {
+        var bin = decodebin.get_parent () as Bin;
+        assert (bin != null);
+
+        var encoder = bin.get_by_name (ENCODE_BIN);
+        assert (encoder != null);
+
+        Gst.Pad encoder_pad = null;
+        encoder_pad = encoder.get_compatible_pad (new_pad, null);
+        if (encoder_pad == null) {
+            debug ("No compatible encodebin pad found for pad '%s', ignoring..",
+                   new_pad.name);
+
+            return false;
+        } else {
+            debug ("pad '%s' with caps '%s' is compatible with '%s'",
+                   new_pad.name,
+                   this.decoder_caps.to_string (),
+                   encoder_pad.name);
+        }
+
+        return new_pad.link (encoder_pad) == PadLinkReturn.OK;
+    }
+}
diff --git a/src/rygel/rygel-wma-transcoder.vala b/src/rygel/rygel-wma-transcoder.vala
index 30652a0..d054f33 100644
--- a/src/rygel/rygel-wma-transcoder.vala
+++ b/src/rygel/rygel-wma-transcoder.vala
@@ -31,12 +31,6 @@ internal class Rygel.WMATranscoder : Rygel.Transcoder {
         base ("audio/x-wma", "WMA", AudioItem.UPNP_CLASS);
     }
 
-    public override Element create_source (MediaItem item,
-                                           Element   src)
-                                           throws Error {
-        return new WMATranscoderBin (item, src, this);
-    }
-
     public override DIDLLiteResource? add_resource (DIDLLiteItem     didl_item,
                                                     MediaItem        item,
                                                     TranscodeManager manager)
@@ -66,32 +60,14 @@ internal class Rygel.WMATranscoder : Rygel.Transcoder {
         return distance;
     }
 
-    public Element create_encoder (MediaItem item,
-                                   string?   src_pad_name,
-                                   string?   sink_pad_name)
-                                   throws Error {
-        var l16_transcoder = new L16Transcoder (Endianness.LITTLE);
-        dynamic Element convert = l16_transcoder.create_encoder (
-                                       item,
-                                       null,
-                                       CONVERT_SINK_PAD);
-
-        dynamic Element encoder = GstUtils.create_element ("ffenc_wmav2",
-                                                           "ffenc_wmav2");
-        encoder.bitrate = BITRATE * 1000;
-
-        var bin = new Bin("wma-encoder-bin");
-        bin.add_many (convert, encoder);
-        convert.link (encoder);
-
-        var pad = convert.get_static_pad (CONVERT_SINK_PAD);
-        var ghost = new GhostPad (sink_pad_name, pad);
-        bin.add_pad (ghost);
-
-        pad = encoder.get_static_pad ("src");
-        ghost = new GhostPad (src_pad_name, pad);
-        bin.add_pad (ghost);
+    protected override EncodingProfile get_encoding_profile () {
+        var format = Caps.from_string ("video/x-ms-asf");
+        // FIXME: We should use the preset to set bitrate
+        var encoding_profile = new EncodingAudioProfile (format,
+                                                         null,
+                                                         null,
+                                                         1);
 
-        return bin;
+        return encoding_profile;
     }
 }
diff --git a/src/rygel/rygel-wmv-transcoder.vala b/src/rygel/rygel-wmv-transcoder.vala
index 18a4744..9f93a99 100644
--- a/src/rygel/rygel-wmv-transcoder.vala
+++ b/src/rygel/rygel-wmv-transcoder.vala
@@ -23,24 +23,14 @@ using Gst;
 using GUPnP;
 
 internal class Rygel.WMVTranscoder : Rygel.Transcoder {
-    private const int VIDEO_BITRATE = 1200;
     private const int BITRATE = 1200000;
-
-    private const string VIDEO_ENCODER = "ffenc_wmv1";
-    private const string COLORSPACE_CONVERT = "ffmpegcolorspace";
-    private const string VIDEO_RATE = "videorate";
-    private const string VIDEO_SCALE = "videoscale";
+    private const int VIDEO_BITRATE = 1200;
+    private const int AUDIO_BITRATE = 64;
 
     public WMVTranscoder () {
         base ("video/x-ms-wmv", "WMVHIGH_FULL", VideoItem.UPNP_CLASS);
     }
 
-    public override Element create_source (MediaItem item,
-                                           Element   src)
-                                           throws Error {
-        return new WMVTranscoderBin (item, src, this);
-    }
-
     public override DIDLLiteResource? add_resource (DIDLLiteItem     didl_item,
                                                     MediaItem        item,
                                                     TranscodeManager manager)
@@ -53,7 +43,7 @@ internal class Rygel.WMVTranscoder : Rygel.Transcoder {
 
         resource.width = video_item.width;
         resource.height = video_item.height;
-        resource.bitrate = (VIDEO_BITRATE + WMATranscoder.BITRATE) * 1000 / 8;
+        resource.bitrate = (VIDEO_BITRATE + AUDIO_BITRATE) * 1000 / 8;
 
         return resource;
     }
@@ -73,30 +63,29 @@ internal class Rygel.WMVTranscoder : Rygel.Transcoder {
         return distance;
     }
 
-    public Element create_encoder (MediaItem item,
-                                   string?   src_pad_name,
-                                   string?   sink_pad_name)
-                                   throws Error {
-        var convert = GstUtils.create_element (COLORSPACE_CONVERT,
-                                               COLORSPACE_CONVERT);
-        dynamic Element encoder = GstUtils.create_element (VIDEO_ENCODER,
-                                                           VIDEO_ENCODER);
-
-        encoder.bitrate = (int) VIDEO_BITRATE * 1000;
-
-        var bin = new Bin ("video-encoder-bin");
-        bin.add_many (convert, encoder);
-        convert.link (encoder);
-
-        var pad = convert.get_static_pad ("sink");
-        var ghost = new GhostPad (sink_pad_name, pad);
-        bin.add_pad (ghost);
-
-        pad = encoder.get_static_pad ("src");
-        ghost = new GhostPad (src_pad_name, pad);
-        bin.add_pad (ghost);
-
-        return bin;
+    protected override EncodingProfile get_encoding_profile () {
+        var container_format = Caps.from_string ("video/x-ms-asf,parsed=true");
+
+        var video_format = Caps.from_string ("video/x-wmv,wmvversion=1");
+        var audio_format = Caps.from_string ("audio/x-wma,channels=2,wmaversion=1");
+
+        var enc_container_profile = new EncodingContainerProfile("container",
+                                                                 null,
+                                                                 container_format,
+                                                                 null);
+        var enc_video_profile = new EncodingVideoProfile (video_format,
+                                                          null,
+                                                          null,
+                                                          1);
+        var enc_audio_profile = new EncodingAudioProfile (audio_format,
+                                                          null,
+                                                          null,
+                                                          1);
+
+        // FIXME: We should use the preset to set bitrate
+        enc_container_profile.add_profile (enc_video_profile);
+        enc_container_profile.add_profile (enc_audio_profile);
+
+        return enc_container_profile;
     }
-
 }



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