Reworked track settings.
[demorecorder] / src / ImportBin.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 class ImportBin : Gst.Bin {
21   
22   Gst.Element decoder;
23   Gst.Element converter;
24   //Gst.Element queue;
25   Gst.GhostPad sink_pad;
26   Gst.GhostPad src_pad;
27   
28   public ImportBin(string name) {
29     this.set_name(name);
30     
31     decoder = Gst.ElementFactory.make("uridecodebin", "decoder-" + name);
32     decoder.connect("swapped-object-signal::autoplug-continue", autoplug_continue, this);
33     decoder.connect("swapped-object-signal::drained", drained, this);
34     this.add(decoder);
35     
36     converter = Gst.ElementFactory.make("audioconvert", "converter-" + name);
37     this.add(converter);
38     
39     //queue = Gst.ElementFactory.make("queue2", "queue");
40     //this.add(queue);
41     
42     //this.converter.link(this.queue);
43     
44     
45     sink_pad = new Gst.GhostPad("sink", decoder.get_static_pad("sink"));
46     this.add_pad(sink_pad);
47     src_pad = new Gst.GhostPad("src", converter.get_static_pad("src"));
48     this.add_pad(src_pad);
49     
50   }
51   
52   private bool autoplug_continue(Gst.Pad decodebin, Gst.Caps arg1, void* data) {
53     stdout.printf("autoplug continue called: %s\n", this.get_name());
54     stdout.flush();
55     Gst.PadLinkReturn ret = decodebin.link(converter.get_static_pad("sink"));
56     if (Gst.PadLinkReturn.OK != ret) {
57       stdout.printf("link failed: %s %s\n", this.get_name(), ret.to_string());
58       stdout.flush();
59     }
60     else {
61       stdout.printf("link succeded: %s\n", this.get_name());
62       stdout.flush();
63     }
64     return true;
65   }
66   
67   private void drained(Gst.Pad decodebin, void* data) {
68   }
69   
70   public new Gst.PadTemplate get_pad_template(string name) {
71     switch (name) {
72       case "src":
73         return this.converter.get_pad_template("src");
74       case "sink":
75         return this.decoder.get_pad_template("sink");
76       default:
77         return this.get_pad_template(name);
78     }
79   }
80   
81   public void play() {
82     this.set_state(Gst.State.PLAYING);
83   }
84   
85   public void pause() {
86     this.set_state(Gst.State.PAUSED);
87   }
88   
89   public void stop() {
90     this.set_state(Gst.State.READY);
91   }
92   
93   public void set_uri(string uri) {
94     stdout.printf("set_uri: %s\n", uri);
95     stdout.flush();
96     this.set_state(Gst.State.NULL);
97     decoder.set_property("uri", uri);
98   }
99   public string get_uri() {
100     GLib.Value ret = 0.0;
101     decoder.get_property("uri", ref ret);
102     return ret.get_string();
103   }
104
105 }
106
107 }