Added gst-plugins-base-subtitles0.10-0.10.34 for Meego Harmattan 1.2
[mafwsubrenderer] / gst-plugins-base-subtitles0.10 / tests / icles / playback / test6.c
1 /* GStreamer
2  * Copyright (C) <1999> Erik Walthinsen <omega@cse.ogi.edu>
3  *
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.
8  *
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.
13  *
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.
18  */
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22 #ifdef HAVE_UNISTD_H
23 #include <unistd.h>
24 #endif
25 #ifdef HAVE_STDLIB_H
26 #include <stdlib.h>             /* exit */
27 #endif
28 #include <gst/gst.h>
29
30 static void
31 new_decoded_pad_cb (GstElement * decodebin, GstPad * new_pad, gboolean last,
32     GstElement * pipeline)
33 {
34   GstElement *fakesink;
35   GstPad *sinkpad;
36
37   fakesink = gst_element_factory_make ("fakesink", NULL);
38   gst_bin_add (GST_BIN (pipeline), fakesink);
39
40   sinkpad = gst_element_get_static_pad (fakesink, "sink");
41   if (GST_PAD_LINK_FAILED (gst_pad_link (new_pad, sinkpad))) {
42     g_warning ("Failed to link %s:%s to %s:%s", GST_DEBUG_PAD_NAME (new_pad),
43         GST_DEBUG_PAD_NAME (sinkpad));
44     gst_bin_remove (GST_BIN (pipeline), fakesink);
45   } else {
46     gst_element_set_state (fakesink, GST_STATE_PAUSED);
47   }
48 }
49
50 static void
51 show_error (const gchar * errmsg, GstBus * bus)
52 {
53   GstMessage *msg;
54   GError *err = NULL;
55   gchar *dbg = NULL;
56
57   msg = gst_bus_poll (bus, GST_MESSAGE_ERROR, 0);
58   if (msg) {
59     g_assert (GST_MESSAGE_TYPE (msg) == GST_MESSAGE_ERROR);
60
61     gst_message_parse_error (msg, &err, &dbg);
62   }
63
64   g_print ("ERROR: %s\n", errmsg);
65   g_print ("       %s\n", (err) ? err->message : "");
66   if (dbg) {
67     g_print ("\ndebug: %s\n\n", dbg);
68     g_free (dbg);
69   }
70
71   if (err)
72     g_error_free (err);
73 }
74
75 gint
76 main (gint argc, gchar * argv[])
77 {
78   GstElement *pipeline, *filesrc, *decodebin;
79   GstStateChangeReturn res;
80   GstIterator *it;
81   GstBus *bus;
82   gpointer data;
83
84   gst_init (&argc, &argv);
85
86   pipeline = gst_pipeline_new ("pipeline");
87
88   filesrc = gst_element_factory_make ("filesrc", "filesrc");
89   g_assert (filesrc);
90
91   decodebin = gst_element_factory_make ("decodebin", "decodebin");
92   g_assert (decodebin);
93
94   gst_bin_add_many (GST_BIN (pipeline), filesrc, decodebin, NULL);
95   gst_element_link (filesrc, decodebin);
96
97   if (argc < 2) {
98     g_print ("usage: %s <filenames>\n", argv[0]);
99     exit (-1);
100   }
101
102   if (!g_str_has_prefix (argv[1], "file://")) {
103     g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
104   } else {
105     g_object_set (G_OBJECT (filesrc), "location", argv[1] + 7, NULL);
106   }
107
108   /* we've got to connect fakesinks to newly decoded pads to make sure
109    * buffers have actually been flowing over those pads and caps have
110    * been set on them. decodebin might insert internal queues and
111    * without fakesinks it's pot-luck what caps we get from the pad, because
112    * it depends on whether the queues have started pushing buffers yet or not.
113    * With fakesinks we make sure that the pipeline doesn't go to PAUSED state
114    * before each fakesink has a buffer queued. */
115   g_signal_connect (decodebin, "new-decoded-pad",
116       G_CALLBACK (new_decoded_pad_cb), pipeline);
117
118   bus = gst_element_get_bus (pipeline);
119
120   g_print ("pause..\n");
121   res = gst_element_set_state (pipeline, GST_STATE_PAUSED);
122   if (res == GST_STATE_CHANGE_FAILURE) {
123     show_error ("Could not go to PAUSED state", bus);
124     exit (-1);
125   }
126   g_print ("waiting..\n");
127   res = gst_element_get_state (pipeline, NULL, NULL, GST_CLOCK_TIME_NONE);
128   if (res != GST_STATE_CHANGE_SUCCESS) {
129     show_error ("Failed to complete state change to PAUSED", bus);
130     exit (-1);
131   }
132   g_print ("stats..\n");
133
134   it = gst_element_iterate_src_pads (decodebin);
135   while (gst_iterator_next (it, &data) == GST_ITERATOR_OK) {
136     GstPad *pad = GST_PAD (data);
137     GstCaps *caps;
138     gchar *str;
139     GstQuery *query;
140
141     g_print ("stream %s:\n", GST_OBJECT_NAME (pad));
142
143     caps = gst_pad_get_caps (pad);
144     str = gst_caps_to_string (caps);
145     g_print (" caps: %s\n", str);
146     g_free (str);
147     gst_caps_unref (caps);
148
149     query = gst_query_new_duration (GST_FORMAT_TIME);
150     if (gst_pad_query (pad, query)) {
151       gint64 duration;
152
153       gst_query_parse_duration (query, NULL, &duration);
154
155       g_print (" duration: %" GST_TIME_FORMAT "\n", GST_TIME_ARGS (duration));
156     }
157     gst_query_unref (query);
158
159     gst_object_unref (pad);
160   }
161   gst_iterator_free (it);
162
163   return 0;
164 }