2 * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
4 * This library is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU Library General Public
6 * License as published by the Free Software Foundation; either
7 * version 2 of the License, or (at your option) any later version.
9 * This library is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * Library General Public License for more details.
14 * You should have received a copy of the GNU Library General Public
15 * License along with this library; if not, write to the
16 * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17 * Boston, MA 02111-1307, USA.
23 warning_cb (GstBus * bus, GstMessage * msg, gpointer foo)
28 gst_message_parse_warning (msg, &err, &dbg);
30 g_printerr ("WARNING: %s (%s)\n", err->message, (dbg) ? dbg : "no details");
37 error_cb (GstBus * bus, GstMessage * msg, GMainLoop * main_loop)
42 gst_message_parse_error (msg, &err, &dbg);
44 g_printerr ("ERROR: %s (%s)\n", err->message, (dbg) ? dbg : "no details");
46 g_main_loop_quit (main_loop);
53 eos_cb (GstBus * bus, GstMessage * msg, GMainLoop * main_loop)
56 g_main_loop_quit (main_loop);
60 state_cb (GstBus * bus, GstMessage * msg, GstElement * pipeline)
62 if (msg->src == GST_OBJECT (pipeline)) {
63 GstState old_state, new_state, pending_state;
65 gst_message_parse_state_changed (msg, &old_state, &new_state,
67 if (new_state == GST_STATE_PLAYING) {
68 g_print ("Decoding ...\n");
74 new_decoded_pad_cb (GstElement * decodebin, GstPad * pad, gboolean last,
75 GstElement * pipeline)
81 fakesink = gst_element_factory_make ("fakesink", NULL);
82 fakesink_pad = gst_element_get_static_pad (fakesink, "sink");
84 gst_bin_add (GST_BIN (pipeline), fakesink);
86 /* this doesn't really seem right, but it makes things work for me */
87 gst_element_set_state (fakesink, GST_STATE_PLAYING);
89 ret = gst_pad_link (pad, fakesink_pad);
90 if (!GST_PAD_LINK_SUCCESSFUL (ret)) {
91 g_printerr ("Failed to link %s:%s to %s:%s (ret = %d)\n",
92 GST_DEBUG_PAD_NAME (pad), GST_DEBUG_PAD_NAME (fakesink_pad), ret);
94 g_printerr ("Linked %s:%s to %s:%s\n", GST_DEBUG_PAD_NAME (pad),
95 GST_DEBUG_PAD_NAME (fakesink_pad));
98 gst_object_unref (fakesink_pad);
102 main (gint argc, gchar * argv[])
106 GstElement *pipeline;
107 GstStateChangeReturn res;
111 gst_init (&argc, &argv);
114 g_printerr ("Decode file from start to end.\n");
115 g_printerr ("Usage: %s URI\n\n", argv[0]);
119 loop = g_main_loop_new (NULL, TRUE);
121 pipeline = gst_pipeline_new ("pipeline");
123 bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
124 gst_bus_add_signal_watch (bus);
126 g_signal_connect (bus, "message::eos", G_CALLBACK (eos_cb), loop);
127 g_signal_connect (bus, "message::error", G_CALLBACK (error_cb), loop);
128 g_signal_connect (bus, "message::warning", G_CALLBACK (warning_cb), NULL);
129 g_signal_connect (bus, "message::state-changed", G_CALLBACK (state_cb),
132 source = gst_element_factory_make ("gnomevfssrc", "source");
135 if (argv[1] && strstr (argv[1], "://") != NULL) {
136 g_object_set (G_OBJECT (source), "location", argv[1], NULL);
137 } else if (argv[1]) {
138 gchar *uri = g_strdup_printf ("file://%s", argv[1]);
140 g_object_set (G_OBJECT (source), "location", uri, NULL);
144 decoder = gst_element_factory_make ("decodebin", "decoder");
147 gst_bin_add (GST_BIN (pipeline), source);
148 gst_bin_add (GST_BIN (pipeline), decoder);
150 gst_element_link_pads (source, "src", decoder, "sink");
152 g_signal_connect (decoder, "new-decoded-pad",
153 G_CALLBACK (new_decoded_pad_cb), pipeline);
155 res = gst_element_set_state (pipeline, GST_STATE_PLAYING);
156 if (res == GST_STATE_CHANGE_FAILURE) {
157 g_print ("could not play\n");
161 g_main_loop_run (loop);
164 gst_element_set_state (pipeline, GST_STATE_NULL);
165 gst_object_unref (pipeline);
166 gst_object_unref (bus);