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 PlayPipeline : Gst.Pipeline {
23 Gst.Element sink_element;
24 Gst.Query duration_query;
25 Gst.Query position_query;
29 public signal void position_duration(int64 position, int64 duration);
30 public signal void end_of_stream();
31 public signal void stream_error(string msg);
33 public PlayPipeline(string name, Gst.Element src) {
34 //set the tag handling delegate
35 //set some default values
42 duration_query = new Gst.Query.duration(Gst.Format.TIME);
43 position_query = new Gst.Query.position(Gst.Format.TIME);
48 public bool set_src(MixerBin src) {
49 this.set_state(Gst.State.NULL);
50 if (null != this.src) {
55 this.src.link(this.sink_element);
59 public void clear_src() {
60 if (null != this.src) {
61 this.set_state(Gst.State.NULL);
62 this.src.unlink(this.sink_element);
63 this.remove(this.src);
68 private void construct_pipeline() {
69 if (null != this.src) {
72 sink_element = Gst.ElementFactory.make("autoaudiosink", "output");
73 this.add(sink_element);
75 if (null != this.src) {
76 if (!src.link(sink_element)) {
77 stdout.printf("failed to link src to sink\n");
80 Gst.Bus bus = this.src.get_bus();
81 bus.add_signal_watch();
82 bus.connect("message:eos", bus_callback, this);
83 bus.connect("message:error", bus_callback, this);
84 bus.connect("message:state-changed", bus_callback, this);
85 uint watch_id = bus.add_watch(bus_callback);
88 public bool bus_callback (Gst.Bus bus, Gst.Message message) {
89 stdout.printf("bus_callback\n");
91 switch (message.type) {
92 case Gst.MessageType.ERROR:
95 message.parse_error (out err, out debug);
96 stdout.printf("%s\n", err.message);
98 stream_error(err.message);
100 case Gst.MessageType.EOS:
101 stdout.printf ("end of stream\n");
105 case Gst.MessageType.STATE_CHANGED:
109 message.parse_state_changed (out oldstate, out newstate, out pending);
110 stdout.printf ("%s->%s:%s\n", oldstate.to_string(), newstate.to_string(), pending.to_string());
119 public void get_duration_info() {
120 bool duration_result,position_result;
121 Gst.Format format = Gst.Format.TIME;
122 duration_result = this.query(this.duration_query);
123 position_result = this.query(this.position_query);
124 if ( duration_result && position_result ) {
125 this.duration_query.parse_duration(out format, out this.duration);
126 this.position_query.parse_position(out format, out this.position);
127 this.position_duration(this.position,this.duration);
132 this.set_state(Gst.State.PLAYING);
135 public void pause() {
136 this.set_state(Gst.State.PAUSED);
140 this.set_state(Gst.State.READY);
144 public void move_to(int64 newloc) {
145 if (0 > newloc) newloc = 0;
146 //this.src.move_to(newloc);
150 public void seek(int percent) {
151 move_to((int64) this.position + (this.duration * percent / 100));
154 public void seek_forward(int percent) {
158 public void seek_backward(int percent) {