Reworked track settings.
[demorecorder] / src / EncoderFactory.vala
1 /*  Demo Recorder for MAEMO 5
2 *   Copyright (C) 2010 Dru Moore <usr@dru-id.co.uk>
3 *   This program is free software; you can redistribute it and/or modify
4 *   it under the terms of the GNU General Public License version 2,
5 *   or (at your option) any later version, as published by the Free
6 *   Software Foundation
7 *
8 *   This program is distributed in the hope that it will be useful,
9 *   but WITHOUT ANY WARRANTY; without even the implied warranty of
10 *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11 *   GNU General Public License for more details
12 *
13 *   You should have received a copy of the GNU General Public
14 *   License along with this program; if not, write to the
15 *   Free Software Foundation, Inc.,
16 *   51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
17 */
18 namespace IdWorks {
19
20 public static class EncoderFactory {
21
22   public static Gst.Bin? get_encoder_bin(string name, string encoder, string quality, string? taglist) {
23     switch (encoder) {
24       case "vorbisenc":
25         return get_encoder_vorbisenc(name, quality, taglist);
26       case "nokiaaacenc":
27         return get_encoder_nokiaaacenc(name, quality, taglist);
28       case "wavenc":
29         return get_encoder_wavenc(name, quality, taglist);
30       default:
31         return null;
32     }
33   }
34   
35   public static Gst.Bin get_encoder_wavenc(string name, string quality, string? taglist) {
36     // Quality ignored for now
37     Gst.Bin enc_bin = new Gst.Bin(name);
38     Gst.Element taginject = Gst.ElementFactory.make("taginject", "injector");
39     Gst.ElementFactory.make("wavenc", "encoder");
40     enc_bin.add(taginject);
41     enc_bin.add(enc_bin);
42     if (null != taglist) {
43       taginject.set_property("tags", taglist);
44     }
45     taginject.link(enc_bin);
46     Gst.GhostPad sink_pad = new Gst.GhostPad("sink", taginject.get_static_pad("sink"));
47     enc_bin.add_pad(sink_pad);
48     Gst.GhostPad src_pad = new Gst.GhostPad("src", enc_bin.get_static_pad("src"));
49     enc_bin.add_pad(src_pad);
50     return enc_bin;
51   }
52   
53   public static Gst.Bin get_encoder_vorbisenc(string name, string quality, string? taglist) {
54     double q = 1.0;
55     switch (quality) {
56       case "high":
57         q = 1.0;
58         break;
59       case "medium":
60         q = 0.6;
61         break;
62       case "low":
63         q = 0.3;
64         break;
65       default:
66         q = 1.0;
67         break;
68     }
69     Gst.Bin enc_bin = new Gst.Bin(name);
70     Gst.Element taginject = Gst.ElementFactory.make("taginject", "injector");
71     Gst.Element encoder = Gst.ElementFactory.make("vorbisenc", "encoder");
72     Gst.Element muxer = Gst.ElementFactory.make("oggmux", "muxer");
73     enc_bin.add(taginject);
74     enc_bin.add(encoder);
75     enc_bin.add(muxer);
76     encoder.set_property("quality", q);
77     if (null != taglist) {
78       taginject.set_property("tags", taglist);
79     }
80     taginject.link(encoder);
81     encoder.link(muxer);
82     Gst.GhostPad sink_pad = new Gst.GhostPad("sink", taginject.get_static_pad("sink"));
83     enc_bin.add_pad(sink_pad);
84     Gst.GhostPad src_pad = new Gst.GhostPad("src", muxer.get_static_pad("src"));
85     enc_bin.add_pad(src_pad);
86     return enc_bin;
87   }
88   
89   public static Gst.Bin get_encoder_nokiaaacenc(string name, string quality, string? taglist) {
90     uint bitrate = 128000;
91     int output_format = 1;
92     switch (quality) {
93       case "high":
94         bitrate = 256000;
95         break;
96       case "medium":
97         bitrate = 128000;
98         break;
99       case "low":
100         bitrate = 64000;
101         break;
102       default:
103         bitrate = 256000;
104         break;
105     }
106     Gst.Bin enc_bin = new Gst.Bin(name);
107     Gst.Element taginject = Gst.ElementFactory.make("taginject", "injector");
108     Gst.Element encoder = Gst.ElementFactory.make("nokiaaacenc", "encoder");
109     enc_bin.add(taginject);
110     enc_bin.add(encoder);
111     encoder.set_property("bitrate", bitrate);
112     encoder.set_property("output-format", output_format);
113     if (null != taglist) {
114       taginject.set_property("tags", taglist);
115     }
116     taginject.link(encoder);
117     Gst.GhostPad sink_pad = new Gst.GhostPad("sink", taginject.get_static_pad("sink"));
118     enc_bin.add_pad(sink_pad);
119     Gst.GhostPad src_pad = new Gst.GhostPad("src", encoder.get_static_pad("src"));
120     enc_bin.add_pad(src_pad);
121     return enc_bin;
122   }
123
124 }
125
126 }