rygel r659 - trunk/src/rygel



Author: zeeshanak
Date: Sun Mar 15 19:01:09 2009
New Revision: 659
URL: http://svn.gnome.org/viewvc/rygel?rev=659&view=rev

Log:
Add TranscodeSrc.

A gst source bin that is supposed to transcode any media (uses decodebin2) to
mpeg transport stream. Currently it will just use hard-coded encoders and
muxer.

Added:
   trunk/src/rygel/rygel-transcode-src.vala
Modified:
   trunk/src/rygel/Makefile.am

Modified: trunk/src/rygel/Makefile.am
==============================================================================
--- trunk/src/rygel/Makefile.am	(original)
+++ trunk/src/rygel/Makefile.am	Sun Mar 15 19:01:09 2009
@@ -119,7 +119,10 @@
 		rygel-simple-async-result.c \
 		rygel-simple-async-result.h \
 		rygel-media-item.c \
-		rygel-media-item.h
+		rygel-media-item.h \
+		rygel-transcode-src.h \
+		rygel-transcode-src.c \
+		rygel-transcode-src.vala
 
 rygel.stamp: $(filter %.vala,$(rygel_SOURCES))
 	$(VALAC) -C --vapidir=$(srcdir) \

Added: trunk/src/rygel/rygel-transcode-src.vala
==============================================================================
--- (empty file)
+++ trunk/src/rygel/rygel-transcode-src.vala	Sun Mar 15 19:01:09 2009
@@ -0,0 +1,103 @@
+/*
+ * Copyright (C) 2009 Nokia Corporation, all rights reserved.
+ *
+ * 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;
+
+public class Rygel.TranscodeSrc : Gst.Bin {
+   private const string DECODEBIN = "decodebin2";
+   private const string AUDIO_ENCODER = "ffenc_mp2";
+   private const string VIDEO_ENCODER = "ffenc_mpeg2video";
+   private const string MUXER = "mpegtsmux";
+
+   private dynamic Element audio_enc;
+   private dynamic Element video_enc;
+   private dynamic Element muxer;
+
+   public TranscodeSrc (Element src) throws Error {
+        Element decodebin = ElementFactory.make (DECODEBIN, DECODEBIN);
+        if (decodebin == null) {
+            throw new LiveResponseError.MISSING_PLUGIN (
+                                    "Required element '%s' missing", DECODEBIN);
+        }
+
+        this.audio_enc = ElementFactory.make (AUDIO_ENCODER, AUDIO_ENCODER);
+        if (audio_enc == null) {
+            throw new LiveResponseError.MISSING_PLUGIN (
+                                    "Required element '%s' missing",
+                                    AUDIO_ENCODER);
+        }
+
+        this.video_enc = ElementFactory.make (VIDEO_ENCODER, VIDEO_ENCODER);
+        if (video_enc == null) {
+            throw new LiveResponseError.MISSING_PLUGIN (
+                                    "Required element '%s' missing",
+                                    VIDEO_ENCODER);
+        }
+
+        this.muxer = ElementFactory.make (MUXER, MUXER);
+        if (muxer == null) {
+            throw new LiveResponseError.MISSING_PLUGIN (
+                                    "Required element '%s' missing",
+                                    MUXER);
+        }
+
+        this.add_many (src, decodebin, this.muxer);
+        src.link (decodebin);
+
+        decodebin.pad_added += this.decodebin_pad_added;
+   }
+
+   private void decodebin_pad_added (Element decodebin,
+                                     Pad     new_pad) {
+        var caps = new_pad.get_caps ();
+
+        Pad enc_pad = this.audio_enc.get_compatible_pad (new_pad, caps);
+        if (enc_pad == null) {
+            // Try video encoder
+            enc_pad = this.video_enc.get_compatible_pad (new_pad, caps);
+        }
+
+        if (enc_pad == null) {
+            return;
+        }
+
+        if (new_pad.link (enc_pad) != PadLinkReturn.OK) {
+            this.post_error (new LiveResponseError.LINK (
+                                            "Failed to link pad %s to %s",
+                                            new_pad.name,
+                                            enc_pad.name));
+            return;
+        }
+
+        var encoder = enc_pad.get_parent_element ();
+
+        this.add_many (encoder);
+        encoder.link (this.muxer);
+        encoder.sync_state_with_parent ();
+    }
+
+    private void post_error (Error error) {
+        Message msg = new Message.error (this, error, error.message);
+        this.post_message (msg);
+    }
+}



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