--- /dev/null
+/* 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 PlayPipeline : Gst.Pipeline {
+
+ Gst.Element src;
+ Gst.Element sink_element;
+ Gst.Query duration_query;
+ Gst.Query position_query;
+ int64 position;
+ int64 duration;
+
+ public signal void position_duration(int64 position, int64 duration);
+ public signal void end_of_stream();
+ public signal void stream_error(string msg);
+
+ public PlayPipeline(string name, Gst.Element src) {
+ //set the tag handling delegate
+ //set some default values
+ this.name = name;
+ this.src = src;
+ this.position = 0;
+ this.duration = 0;
+ //this.name = name;
+ //define the queries
+ duration_query = new Gst.Query.duration(Gst.Format.TIME);
+ position_query = new Gst.Query.position(Gst.Format.TIME);
+
+ construct_pipeline();
+ }
+
+ public bool set_src(MixerBin src) {
+ this.set_state(Gst.State.NULL);
+ if (null != this.src) {
+ clear_src();
+ }
+ this.src = src;
+ this.add(this.src);
+ this.src.link(this.sink_element);
+ return true;
+ }
+
+ public void clear_src() {
+ if (null != this.src) {
+ this.set_state(Gst.State.NULL);
+ this.src.unlink(this.sink_element);
+ this.remove(this.src);
+ this.src = null;
+ }
+ }
+
+ private void construct_pipeline() {
+ if (null != this.src) {
+ this.add(src);
+ }
+ sink_element = Gst.ElementFactory.make("autoaudiosink", "output");
+ this.add(sink_element);
+
+ if (null != this.src) {
+ if (!src.link(sink_element)) {
+ stdout.printf("failed to link src to sink\n");
+ stdout.flush();}
+ }
+ Gst.Bus bus = this.src.get_bus();
+ bus.add_signal_watch();
+ bus.connect("message:eos", bus_callback, this);
+ bus.connect("message:error", bus_callback, this);
+ bus.connect("message:state-changed", bus_callback, this);
+ uint watch_id = bus.add_watch(bus_callback);
+ }
+
+ public bool bus_callback (Gst.Bus bus, Gst.Message message) {
+ stdout.printf("bus_callback\n");
+ stdout.flush();
+ switch (message.type) {
+ case Gst.MessageType.ERROR:
+ GLib.Error err;
+ string debug;
+ message.parse_error (out err, out debug);
+ stdout.printf("%s\n", err.message);
+ stdout.flush();
+ stream_error(err.message);
+ break;
+ case Gst.MessageType.EOS:
+ stdout.printf ("end of stream\n");
+ stdout.flush();
+ end_of_stream();
+ break;
+ case Gst.MessageType.STATE_CHANGED:
+ Gst.State oldstate;
+ Gst.State newstate;
+ Gst.State pending;
+ message.parse_state_changed (out oldstate, out newstate, out pending);
+ stdout.printf ("%s->%s:%s\n", oldstate.to_string(), newstate.to_string(), pending.to_string());
+ stdout.flush();
+ break;
+ default:
+ break;
+ }
+ return false;
+ }
+
+ public void get_duration_info() {
+ 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);
+ }
+ }
+
+ public void play() {
+ this.set_state(Gst.State.PLAYING);
+ }
+
+ public void pause() {
+ this.set_state(Gst.State.PAUSED);
+ }
+
+ public void stop() {
+ this.set_state(Gst.State.READY);
+ clear_src();
+ }
+ /*
+ public void move_to(int64 newloc) {
+ if (0 > newloc) newloc = 0;
+ //this.src.move_to(newloc);
+ //this.play();
+ }
+
+ public void seek(int percent) {
+ move_to((int64) this.position + (this.duration * percent / 100));
+ }
+
+ public void seek_forward(int percent) {
+ seek(percent);
+ }
+
+ public void seek_backward(int percent) {
+ seek(-percent);
+ }
+ */
+}
+
+}
\ No newline at end of file