Adding first code drop
[demorecorder] / src / RecordPipeline_Old.vala
diff --git a/src/RecordPipeline_Old.vala b/src/RecordPipeline_Old.vala
new file mode 100644 (file)
index 0000000..8d04703
--- /dev/null
@@ -0,0 +1,132 @@
+/*  Demo Recorder for MAEMO 5
+*   Copyright (C) 2010 Dru Moore <usr@dru-id.co.uk>
+*   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 class RecordPipeline_Old : Object {
+
+  Gst.Pipeline pipeline;
+  Gst.Element src;
+  Gst.Element decoder;
+  Gst.Element converter;
+  Gst.Element queue;
+  Gst.Element sink;
+  Gst.Element resampler;
+  Gst.Element encoder;
+  Gst.Element filesink;
+  string name;
+  string location;
+  Gst.Caps caps;
+  Gst.Query duration_query;
+  Gst.Query position_query;
+  int64 position;
+  int64 duration;
+  
+  public signal void position_duration(int64 position, int64 duration);
+  public signal void tag_parsed(string tag, string val);
+  public signal void end_of_stream();
+  public signal void stream_error(string msg);
+  
+  public RecordPipeline_Old(string name, string location, Gst.Caps caps) {
+    this.name = name;
+    this.location = location;
+    this.caps = caps;
+    //set the tag handling delegate
+    //this.handle_tags_delegate = this.handle_tags;
+    //set some default values
+    this.position=0;
+    this.duration=0;
+    this.construct_pipeline(this.name, this.location, this.caps);
+    //define the queries
+    //duration_query = new Gst.Query.duration(Gst.Format.TIME);
+    //position_query = new Gst.Query.position(Gst.Format.TIME);
+  }
+  
+  public string get_location() {
+    return this.location;
+  }
+  
+  public void record() {
+    this.pipeline.set_state(Gst.State.PLAYING);
+  }
+  
+  public void stop() {
+    this.end_of_stream();
+    this.pipeline.set_state(Gst.State.READY);
+  }
+  
+  private void construct_pipeline(string name, string location, Gst.Caps caps) {
+    pipeline = new Gst.Pipeline(name);
+    
+    this.src = Gst.ElementFactory.make("pulsesrc", "input");
+    src.set_property("device", "source.hw0");
+    this.pipeline.add(this.src);
+    
+    this.converter = Gst.ElementFactory.make("audioconvert", "converter");
+    this.pipeline.add(this.converter);
+    
+    this.queue = Gst.ElementFactory.make("queue", "buffer");
+    this.pipeline.add(this.queue);
+    
+    this.resampler = Gst.ElementFactory.make("audioresample", "resampler");
+    this.resampler.set_property("quality", 10);
+    this.pipeline.add(resampler);
+    this.encoder = Gst.ElementFactory.make("wavenc", "encoder");
+    this.pipeline.add(this.encoder);
+    if (null != this.encoder) {
+      stdout.printf("Encoder added!\n");
+      stdout.flush();
+    }
+    this.filesink = Gst.ElementFactory.make("filesink", "fileoutput");
+    if (null != this.filesink) {
+      this.filesink.set_property("location", location);
+      stdout.printf("Location set!\n");
+      stdout.flush();
+      this.pipeline.add(this.filesink);
+      stdout.printf("Filesink added!\n");
+      stdout.flush();
+    }
+    /*if (this.converter.link(this.resampler)) {
+      stdout.printf("Converter linked!\n");
+      stdout.flush();
+    }*/
+    if (this.src.link(this.queue)) {
+      stdout.printf("Source linked!\n");
+      stdout.flush();
+    }
+    if (this.queue.link(this.converter)) {
+      stdout.printf("Queue linked!\n");
+      stdout.flush();
+    }
+    if (this.converter.link(this.resampler)) {
+      stdout.printf("Converter linked!\n");
+      stdout.flush();
+    }
+    if (this.resampler.link_filtered(this.encoder, caps)) {
+      stdout.printf("Resampler linked!\n");
+      stdout.flush();
+    }
+    if (this.encoder.link(this.filesink)) {
+      stdout.printf("Encoder linked!\n");
+      stdout.flush();
+    }
+  }
+  
+  
+}
+
+}
\ No newline at end of file