2 * Copyright (C) 2003 Julien Moutte <julien@moutte.net>
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.
20 #include <gst/play/play.h>
21 #include <gst/gconf/gconf.h>
23 static GMainLoop *loop = NULL;
24 static gint64 length = 0;
27 print_tag (const GstTagList * list, const gchar * tag, gpointer unused)
31 count = gst_tag_list_get_tag_size (list, tag);
33 for (i = 0; i < count; i++) {
36 if (gst_tag_get_type (tag) == G_TYPE_STRING) {
37 if (!gst_tag_list_get_string_index (list, tag, i, &str))
38 g_assert_not_reached ();
41 g_strdup_value_contents (gst_tag_list_get_value_index (list, tag, i));
45 g_print ("%15s: %s\n", gst_tag_get_nick (tag), str);
47 g_print (" : %s\n", str);
55 got_found_tag (GstPlay * play, GstElement * source, GstTagList * tag_list)
57 gst_tag_list_foreach (tag_list, print_tag, NULL);
61 got_time_tick (GstPlay * play, gint64 time_nanos)
63 g_print ("time tick %f\n", time_nanos / (float) GST_SECOND);
67 got_stream_length (GstPlay * play, gint64 length_nanos)
69 g_print ("got length %" G_GUINT64_FORMAT "\n", length_nanos);
70 length = length_nanos;
74 got_video_size (GstPlay * play, gint width, gint height)
76 g_print ("got video size %d, %d\n", width, height);
80 got_eos (GstPlay * play)
82 g_print ("End Of Stream\n");
83 g_main_loop_quit (loop);
87 seek_timer (GstPlay * play)
89 gst_play_seek_to_time (play, length / 2);
94 main (int argc, char *argv[])
97 GstElement *data_src, *video_sink, *audio_sink, *vis_element;
100 /* Initing GStreamer library */
101 gst_init (&argc, &argv);
104 g_print ("usage: %s <video filename>\n", argv[0]);
108 loop = g_main_loop_new (NULL, FALSE);
110 /* Creating the GstPlay object */
111 play = gst_play_new (&error);
113 g_print ("Error: could not create play object:\n%s\n", error->message);
114 g_error_free (error);
118 /* Getting default audio and video plugins from GConf */
119 vis_element = gst_element_factory_make ("goom", "vis_element");
120 data_src = gst_element_factory_make ("gnomevfssrc", "source");
122 audio_sink = gst_gconf_get_default_audio_sink ();
123 if (!GST_IS_ELEMENT (audio_sink))
124 g_error ("Could not get default audio sink from GConf");
125 video_sink = gst_gconf_get_default_video_sink ();
126 if (!GST_IS_ELEMENT (video_sink))
127 g_error ("Could not get default video sink from GConf");
130 /* Let's send them to GstPlay object */
131 if (!gst_play_set_audio_sink (play, audio_sink))
132 g_warning ("Could not set audio sink");
133 if (!gst_play_set_video_sink (play, video_sink))
134 g_warning ("Could not set video sink");
135 if (!gst_play_set_data_src (play, data_src))
136 g_warning ("Could not set data src");
137 if (!gst_play_set_visualization (play, vis_element))
138 g_warning ("Could not set visualisation");
140 /* Setting location we want to play */
141 if (!gst_play_set_location (play, argv[1]))
142 g_warning ("Could not set location");
144 /* Uncomment that line to get an XML dump of the pipeline */
145 /* gst_xml_write_file (GST_ELEMENT (play), stdout); */
147 g_signal_connect (G_OBJECT (play), "time_tick",
148 G_CALLBACK (got_time_tick), NULL);
149 g_signal_connect (G_OBJECT (play), "stream_length",
150 G_CALLBACK (got_stream_length), NULL);
151 g_signal_connect (G_OBJECT (play), "have_video_size",
152 G_CALLBACK (got_video_size), NULL);
153 g_signal_connect (G_OBJECT (play), "found_tag",
154 G_CALLBACK (got_found_tag), NULL);
155 g_signal_connect (G_OBJECT (play), "error",
156 G_CALLBACK (gst_element_default_error), NULL);
157 g_signal_connect (G_OBJECT (play), "eos", G_CALLBACK (got_eos), NULL);
159 /* Change state to PLAYING */
160 if (gst_element_set_state (GST_ELEMENT (play),
161 GST_STATE_PLAYING) == GST_STATE_CHANGE_FAILURE)
162 g_error ("Could not set state to PLAYING");
164 g_timeout_add (20000, (GSourceFunc) seek_timer, play);
166 g_main_loop_run (loop);
168 g_print ("setting pipeline to ready\n");
170 gst_element_set_state (GST_ELEMENT (play), GST_STATE_READY);
173 gst_object_unref (GST_OBJECT (play)); */