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>
22 static GMainLoop *loop = NULL;
23 static gint64 length = 0;
26 print_tag (const GstTagList *list, const gchar *tag, gpointer unused)
30 count = gst_tag_list_get_tag_size (list, tag);
32 for (i = 0; i < count; i++) {
35 if (gst_tag_get_type (tag) == G_TYPE_STRING) {
36 g_assert (gst_tag_list_get_string_index (list, tag, i, &str));
38 str = g_strdup_value_contents (
39 gst_tag_list_get_value_index (list, tag, i));
43 g_print ("%15s: %s\n", gst_tag_get_nick (tag), str);
45 g_print (" : %s\n", str);
53 got_found_tag (GstPlay *play,GstElement *source, GstTagList *tag_list)
55 gst_tag_list_foreach (tag_list, print_tag, NULL);
59 got_time_tick (GstPlay *play, gint64 time_nanos)
61 g_print ("time tick %llu\n", time_nanos);
65 got_stream_length (GstPlay *play, gint64 length_nanos)
67 g_print ("got length %llu\n", length_nanos);
68 length = length_nanos;
72 got_video_size (GstPlay *play, gint width, gint height)
74 g_print ("got video size %d, %d\n", width, height);
78 got_eos (GstPlay *play)
80 g_main_loop_quit (loop);
84 seek_timer (GstPlay *play)
86 gst_play_seek_to_time (play, length / 2);
91 idle_iterate (GstPlay *play)
93 gst_bin_iterate (GST_BIN (play));
94 return (GST_STATE (GST_ELEMENT (play)) == GST_STATE_PLAYING);
98 main (int argc, char *argv[])
101 GstElement *data_src, *video_sink, *audio_sink, *vis_element;
104 /* Initing GStreamer library */
105 gst_init (&argc, &argv);
108 g_print ("usage: %s <video filename>\n", argv[0]);
112 loop = g_main_loop_new (NULL, FALSE);
114 /* Creating the GstPlay object */
115 play = gst_play_new (&error);
118 g_print ("Error: could not create play object:\n%s\n", error->message);
119 g_error_free (error);
123 /* Getting default audio and video plugins from GConf */
124 audio_sink = gst_element_factory_make ("osssink", "audio_sink");
125 video_sink = gst_element_factory_make ("ximagesink", "video_sink");
126 vis_element = gst_element_factory_make ("goom", "vis_element");
127 data_src = gst_element_factory_make ("gnomevfssrc", "source");
129 /* Let's send them to GstPlay object */
130 gst_play_set_audio_sink (play, audio_sink);
131 gst_play_set_video_sink (play, video_sink);
132 gst_play_set_data_src (play, data_src);
133 gst_play_set_visualization (play, vis_element);
135 /* Setting location we want to play */
136 gst_play_set_location (play, argv[1]);
138 /* Uncomment that line to get an XML dump of the pipeline */
139 /* gst_xml_write_file (GST_ELEMENT (play), stdout); */
141 g_signal_connect (G_OBJECT (play), "time_tick",
142 G_CALLBACK (got_time_tick), NULL);
143 g_signal_connect (G_OBJECT (play), "stream_length",
144 G_CALLBACK (got_stream_length), NULL);
145 g_signal_connect (G_OBJECT (play), "have_video_size",
146 G_CALLBACK (got_video_size), NULL);
147 g_signal_connect (G_OBJECT (play), "found_tag",
148 G_CALLBACK (got_found_tag), NULL);
149 g_signal_connect (G_OBJECT (play), "eos",
150 G_CALLBACK (got_eos), NULL);
152 /* Change state to PLAYING */
153 gst_element_set_state (GST_ELEMENT (play), GST_STATE_PLAYING);
155 g_idle_add ((GSourceFunc) idle_iterate, play);
156 g_timeout_add (20000, (GSourceFunc) seek_timer, play);
158 g_main_loop_run (loop);
160 gst_element_set_state (GST_ELEMENT (play), GST_STATE_READY);
163 gst_object_unref (GST_OBJECT (play));