X-Git-Url: http://git.maemo.org/git/?p=demorecorder;a=blobdiff_plain;f=src%2FRecordPipeline.vala;fp=src%2FRecordPipeline.vala;h=c90593f5e0bc03c44c291b5d77d6805c86f81ec4;hp=0000000000000000000000000000000000000000;hb=804630a4e0d41b182d8540f2aec69cf25ca0acfd;hpb=753fb925588aeeacdd74a163672acf2bf362a99e diff --git a/src/RecordPipeline.vala b/src/RecordPipeline.vala new file mode 100644 index 0000000..c90593f --- /dev/null +++ b/src/RecordPipeline.vala @@ -0,0 +1,179 @@ +/* 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 class RecordPipeline : Gst.Pipeline { + + Gst.Element src; + Gst.Element queue; + Gst.Element resampler; + Gst.Element encoder; + Gst.Element converter; + Gst.Element filesink; + //string name; + string location; + string encoder_element; + Gst.Caps caps; + int64 start_time; + Gst.Query duration_query; + Gst.Query position_query; + int64 position; + int64 duration; + + public bool bouncing; + + public signal void position_duration(int64 position, int64 duration); + public signal void end_of_stream(); + public signal void stream_error(string msg); + + public RecordPipeline(string name, string location, Gst.Element src, Gst.Caps caps, string encoder_element) { + //this.bouncing = false; + this.name = name; + this.location = location; + this.caps = caps; + this.src = src; + this.encoder_element = encoder_element; + //set the tag handling delegate + //this.handle_tags_delegate = this.handle_tags; + //set some default values + this.start_time = 0; + //define the queries + duration_query = new Gst.Query.duration(Gst.Format.TIME); + position_query = new Gst.Query.position(Gst.Format.TIME); + this.construct_pipeline(); + } + + public bool set_src(Gst.Element src) { + this.set_state(Gst.State.NULL); + if (null != this.src) { + clear_src(); + } + this.src = src; + this.add(this.src); + this.src.link(this.queue); + return true; + } + + public void clear_src() { + if (null != this.src) { + this.set_state(Gst.State.NULL); + this.src.unlink(this.queue); + this.remove(this.src); + this.src = null; + } + } + + public bool set_location(string location) { + this.set_state(Gst.State.NULL); + this.location = location; + this.filesink.set_property("location", location); + return true; + } + + public string get_location() { + return this.location; + } + + public void get_duration_info() { + if (bouncing) { + bool duration_result,position_result; + Gst.Format format = Gst.Format.TIME; + duration_result = this.query(this.duration_query); + position_result = this.query(this.position_query); + if ( duration_result && position_result ) { + this.duration_query.parse_duration(out format, out this.duration); + this.position_query.parse_position(out format, out this.position); + this.position_duration(this.position,this.duration); + if (this.position >= this.duration) { + this.end_of_stream(); + } + } + } + else { + this.position_duration(Time.get_current_time() - start_time, 0); + } + } + + public void record() { + start_time = Time.get_current_time(); + this.set_state(Gst.State.PLAYING); + } + + public void stop() { + //this.end_of_stream(); + this.set_state(Gst.State.READY); + } + + private void construct_pipeline() { + //this.name= name; + + if (null != this.src) { + this.add(this.src); + } + + this.converter = Gst.ElementFactory.make("audioconvert", "converter"); + this.add(this.converter); + + this.queue = Gst.ElementFactory.make("queue", "buffer"); + this.add(this.queue); + + this.resampler = Gst.ElementFactory.make("audioresample", "resampler"); + this.resampler.set_property("quality", 10); + this.add(resampler); + this.encoder = Gst.ElementFactory.make(encoder_element, "encoder"); + this.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.add(this.filesink); +// stdout.printf("Filesink added!\n"); +// stdout.flush(); + } + + if (null != this.src && 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