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
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
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.
20 public class RecordPipeline : Gst.Pipeline {
24 Gst.Element resampler;
26 Gst.Element converter;
30 string encoder_element;
33 Gst.Query duration_query;
34 Gst.Query position_query;
40 public signal void position_duration(int64 position, int64 duration);
41 public signal void end_of_stream();
42 public signal void stream_error(string msg);
44 public RecordPipeline(string name, string location, Gst.Element src, Gst.Caps caps, string encoder_element) {
45 //this.bouncing = false;
47 this.location = location;
50 this.encoder_element = encoder_element;
51 //set the tag handling delegate
52 //this.handle_tags_delegate = this.handle_tags;
53 //set some default values
56 duration_query = new Gst.Query.duration(Gst.Format.TIME);
57 position_query = new Gst.Query.position(Gst.Format.TIME);
58 this.construct_pipeline();
61 public bool set_src(Gst.Element src) {
62 this.set_state(Gst.State.NULL);
63 if (null != this.src) {
68 this.src.link(this.queue);
72 public void clear_src() {
73 if (null != this.src) {
74 this.set_state(Gst.State.NULL);
75 this.src.unlink(this.queue);
76 this.remove(this.src);
81 public bool set_location(string location) {
82 this.set_state(Gst.State.NULL);
83 this.location = location;
84 this.filesink.set_property("location", location);
88 public string get_location() {
92 public void get_duration_info() {
94 bool duration_result,position_result;
95 Gst.Format format = Gst.Format.TIME;
96 duration_result = this.query(this.duration_query);
97 position_result = this.query(this.position_query);
98 if ( duration_result && position_result ) {
99 this.duration_query.parse_duration(out format, out this.duration);
100 this.position_query.parse_position(out format, out this.position);
101 this.position_duration(this.position,this.duration);
102 if (this.position >= this.duration) {
103 this.end_of_stream();
108 this.position_duration(Time.get_current_time() - start_time, 0);
112 public void record() {
113 start_time = Time.get_current_time();
114 this.set_state(Gst.State.PLAYING);
118 //this.end_of_stream();
119 this.set_state(Gst.State.READY);
122 private void construct_pipeline() {
125 if (null != this.src) {
129 this.converter = Gst.ElementFactory.make("audioconvert", "converter");
130 this.add(this.converter);
132 this.queue = Gst.ElementFactory.make("queue", "buffer");
133 this.add(this.queue);
135 this.resampler = Gst.ElementFactory.make("audioresample", "resampler");
136 this.resampler.set_property("quality", 10);
138 this.encoder = Gst.ElementFactory.make(encoder_element, "encoder");
139 this.add(this.encoder);
140 if (null != this.encoder) {
141 // stdout.printf("Encoder added!\n");
144 this.filesink = Gst.ElementFactory.make("filesink", "fileoutput");
145 if (null != this.filesink) {
146 this.filesink.set_property("location", location);
147 // stdout.printf("Location set!\n");
149 this.add(this.filesink);
150 // stdout.printf("Filesink added!\n");
154 if (null != this.src && this.src.link(this.queue)) {
155 // stdout.printf("Source linked!\n");
158 if (this.queue.link(this.converter)) {
159 // stdout.printf("Queue linked!\n");
162 if (this.converter.link(this.resampler)) {
163 // stdout.printf("Converter linked!\n");
166 if (this.resampler.link_filtered(this.encoder, caps)) {
167 // stdout.printf("Resampler linked!\n");
170 if (this.encoder.link(this.filesink)) {
171 // stdout.printf("Encoder linked!\n");