/* Demo Recorder for MAEMO 5 * Copyright (C) 2010 Dru Moore * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License version 2, * or (at your option) any later version, as published by the Free * Software Foundation * * This program 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 General Public License for more details * * You should have received a copy of the GNU 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. */ namespace IdWorks { public static class EncoderFactory { public static Gst.Bin? get_encoder_bin(string name, string encoder, string quality, string? taglist) { switch (encoder) { case "vorbisenc": return get_encoder_vorbisenc(name, quality, taglist); case "nokiaaacenc": return get_encoder_nokiaaacenc(name, quality, taglist); case "wavenc": return get_encoder_wavenc(name, quality, taglist); default: return null; } } public static Gst.Bin get_encoder_wavenc(string name, string quality, string? taglist) { // Quality ignored for now Gst.Bin enc_bin = new Gst.Bin(name); Gst.Element taginject = Gst.ElementFactory.make("taginject", "injector"); Gst.ElementFactory.make("wavenc", "encoder"); enc_bin.add(taginject); enc_bin.add(enc_bin); if (null != taglist) { taginject.set_property("tags", taglist); } taginject.link(enc_bin); Gst.GhostPad sink_pad = new Gst.GhostPad("sink", taginject.get_static_pad("sink")); enc_bin.add_pad(sink_pad); Gst.GhostPad src_pad = new Gst.GhostPad("src", enc_bin.get_static_pad("src")); enc_bin.add_pad(src_pad); return enc_bin; } public static Gst.Bin get_encoder_vorbisenc(string name, string quality, string? taglist) { double q = 1.0; switch (quality) { case "high": q = 1.0; break; case "medium": q = 0.6; break; case "low": q = 0.3; break; default: q = 1.0; break; } Gst.Bin enc_bin = new Gst.Bin(name); Gst.Element taginject = Gst.ElementFactory.make("taginject", "injector"); Gst.Element encoder = Gst.ElementFactory.make("vorbisenc", "encoder"); Gst.Element muxer = Gst.ElementFactory.make("oggmux", "muxer"); enc_bin.add(taginject); enc_bin.add(encoder); enc_bin.add(muxer); encoder.set_property("quality", q); if (null != taglist) { taginject.set_property("tags", taglist); } taginject.link(encoder); encoder.link(muxer); Gst.GhostPad sink_pad = new Gst.GhostPad("sink", taginject.get_static_pad("sink")); enc_bin.add_pad(sink_pad); Gst.GhostPad src_pad = new Gst.GhostPad("src", muxer.get_static_pad("src")); enc_bin.add_pad(src_pad); return enc_bin; } public static Gst.Bin get_encoder_nokiaaacenc(string name, string quality, string? taglist) { uint bitrate = 128000; int output_format = 1; switch (quality) { case "high": bitrate = 256000; break; case "medium": bitrate = 128000; break; case "low": bitrate = 64000; break; default: bitrate = 256000; break; } Gst.Bin enc_bin = new Gst.Bin(name); Gst.Element taginject = Gst.ElementFactory.make("taginject", "injector"); Gst.Element encoder = Gst.ElementFactory.make("nokiaaacenc", "encoder"); enc_bin.add(taginject); enc_bin.add(encoder); encoder.set_property("bitrate", bitrate); encoder.set_property("output-format", output_format); if (null != taglist) { taginject.set_property("tags", taglist); } taginject.link(encoder); Gst.GhostPad sink_pad = new Gst.GhostPad("sink", taginject.get_static_pad("sink")); enc_bin.add_pad(sink_pad); Gst.GhostPad src_pad = new Gst.GhostPad("src", encoder.get_static_pad("src")); enc_bin.add_pad(src_pad); return enc_bin; } } }