From f58dfb4517ce3fbea78ebbb06ac780ecba5c3bd8 Mon Sep 17 00:00:00 2001 From: "Zeeshan Ali (Khattak)" Date: Sat, 21 Mar 2009 13:54:30 +0000 Subject: [PATCH] Add MP2Transcoder. A new transcoding class for transcoding to mp2 audio. svn path=/trunk/; revision=691 --- src/rygel/Makefile.am | 7 ++- src/rygel/rygel-mp2-transcoder.vala | 108 ++++++++++++++++++++++++++++++++++++ 2 files changed, 113 insertions(+), 2 deletions(-) create mode 100644 src/rygel/rygel-mp2-transcoder.vala diff --git a/src/rygel/Makefile.am b/src/rygel/Makefile.am index 06cbc1c..87ee594 100644 --- a/src/rygel/Makefile.am +++ b/src/rygel/Makefile.am @@ -125,7 +125,9 @@ rygel_SOURCES = $(VAPI_SOURCE_FILES) \ rygel-media-item.c \ rygel-media-item.h \ rygel-mp2ts-transcoder.h \ - rygel-mp2ts-transcoder.c + rygel-mp2ts-transcoder.c \ + rygel-mp2-transcoder.h \ + rygel-mp2-transcoder.c rygel.stamp: $(filter %.vala,$(rygel_SOURCES)) $(VALAC) -C --vapidir=$(srcdir) \ @@ -163,7 +165,8 @@ VAPI_SOURCE_FILES = rygel-content-directory.vala \ rygel-media-item.vala \ rygel-browse.vala \ rygel-didl-lite-writer.vala \ - rygel-mp2ts-transcoder.vala + rygel-mp2ts-transcoder.vala \ + rygel-mp2-transcoder.vala rygel-1.0.vapi: $(VAPI_SOURCE_FILES) $(VALAC) -C --library=rygel-1.0 \ diff --git a/src/rygel/rygel-mp2-transcoder.vala b/src/rygel/rygel-mp2-transcoder.vala new file mode 100644 index 0000000..37e5661 --- /dev/null +++ b/src/rygel/rygel-mp2-transcoder.vala @@ -0,0 +1,108 @@ +/* + * Copyright (C) 2009 Nokia Corporation, all rights reserved. + * + * Author: Zeeshan Ali (Khattak) + * + * + * 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; + +internal class Rygel.MP2Transcoder : Gst.Bin { + private const string DECODEBIN = "decodebin2"; + private const string AUDIO_CONVERT = "audioconvert"; + private const string AUDIO_ENCODER = "twolame"; + + private dynamic Element audio_enc; + + public MP2Transcoder (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 = this.create_audio_encoder (); + + this.add_many (src, decodebin); + src.link (decodebin); + + var src_pad = this.audio_enc.get_static_pad ("src"); + var ghost = new GhostPad (null, src_pad); + this.add_pad (ghost); + + decodebin.pad_added += this.decodebin_pad_added; + } + + private void decodebin_pad_added (Element decodebin, + Pad new_pad) { + Pad enc_pad = this.audio_enc.get_compatible_pad (new_pad, null); + if (enc_pad == null) { + return; + } + + this.add_many (this.audio_enc); + + 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; + } + + this.audio_enc.sync_state_with_parent (); + } + + private Element create_audio_encoder () throws Error { + var convert = ElementFactory.make (AUDIO_CONVERT, AUDIO_CONVERT); + if (convert == null) { + throw new LiveResponseError.MISSING_PLUGIN ( + "Required element '%s' missing", + AUDIO_CONVERT); + } + + var encoder = ElementFactory.make (AUDIO_ENCODER, AUDIO_ENCODER); + if (encoder == null) { + throw new LiveResponseError.MISSING_PLUGIN ( + "Required element '%s' missing", + AUDIO_ENCODER); + } + + var bin = new Bin ("audio-encoder-bin"); + bin.add_many (convert, encoder); + + var filter = Caps.from_string ("audio/x-raw-int"); + convert.link_filtered (encoder, filter); + + var pad = convert.get_static_pad ("sink"); + var ghost = new GhostPad (null, pad); + bin.add_pad (ghost); + + pad = encoder.get_static_pad ("src"); + ghost = new GhostPad (null, pad); + bin.add_pad (ghost); + + return bin; + } + + private void post_error (Error error) { + Message msg = new Message.error (this, error, error.message); + this.post_message (msg); + } +} -- 2.7.4