tests: playback: include stdlib.h unconditionally
[platform/upstream/gstreamer.git] / tests / icles / playback / test5.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., 51 Franklin St, Fifth Floor,
17  * Boston, MA 02110-1301, USA.
18  */
19 #ifdef HAVE_CONFIG_H
20 #include "config.h"
21 #endif
22
23 #include <stdlib.h>             /* exit */
24
25 #include <gst/gst.h>
26
27 static GMainLoop *loop;
28
29 static void
30 pad_added_cb (GstElement * element, GstPad * pad, GstElement * sink)
31 {
32   g_print ("New pad...\n");
33 }
34
35 static void
36 no_more_pads (GstElement * element)
37 {
38   g_print ("No more pads...\n");
39   g_main_loop_quit (loop);
40 }
41
42 static gboolean
43 start_finding (GstElement * pipeline)
44 {
45   GstStateChangeReturn res;
46
47   g_print ("finding caps...\n");
48   res = gst_element_set_state (pipeline, GST_STATE_PAUSED);
49   if (res == GST_STATE_CHANGE_FAILURE) {
50     g_print ("could not pause\n");
51     exit (-1);
52   }
53   return FALSE;
54 }
55
56 static void
57 dump_element_stats (GstElement * element)
58 {
59   GstIterator *it;
60   GValue data = { 0, };
61
62   it = gst_element_iterate_src_pads (element);
63   while (gst_iterator_next (it, &data) == GST_ITERATOR_OK) {
64     GstPad *pad = g_value_get_object (&data);
65     GstCaps *caps;
66     gchar *str;
67     GstQuery *query;
68
69     g_print ("stream %s:\n", GST_OBJECT_NAME (pad));
70
71     caps = gst_pad_query_caps (pad, NULL);
72     str = gst_caps_to_string (caps);
73     g_print (" caps: %s\n", str);
74     g_free (str);
75     gst_caps_unref (caps);
76
77     query = gst_query_new_duration (GST_FORMAT_TIME);
78     if (gst_pad_query (pad, query)) {
79       gint64 duration;
80
81       gst_query_parse_duration (query, NULL, &duration);
82
83       g_print (" duration: %" GST_TIME_FORMAT "\n", GST_TIME_ARGS (duration));
84     }
85     gst_query_unref (query);
86
87     g_value_reset (&data);
88   }
89   g_value_unset (&data);
90   gst_iterator_free (it);
91 }
92
93 gint
94 main (gint argc, gchar * argv[])
95 {
96   GstElement *pipeline, *filesrc, *decodebin;
97
98   gst_init (&argc, &argv);
99
100   pipeline = gst_pipeline_new ("pipeline");
101
102   filesrc = gst_element_factory_make ("filesrc", "filesrc");
103   g_assert (filesrc);
104
105   decodebin = gst_element_factory_make ("decodebin", "decodebin");
106   g_assert (decodebin);
107
108   g_signal_connect (G_OBJECT (decodebin), "pad-added",
109       G_CALLBACK (pad_added_cb), NULL);
110   g_signal_connect (G_OBJECT (decodebin), "no-more-pads",
111       G_CALLBACK (no_more_pads), NULL);
112
113   gst_bin_add_many (GST_BIN (pipeline), filesrc, decodebin, NULL);
114   gst_element_link (filesrc, decodebin);
115
116   if (argc < 2) {
117     g_print ("usage: %s <uri>\n", argv[0]);
118     exit (-1);
119   }
120
121   if (!g_str_has_prefix (argv[1], "file://")) {
122     g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
123   } else {
124     g_object_set (G_OBJECT (filesrc), "location", argv[1] + 7, NULL);
125   }
126
127   /* event based programming approach */
128   loop = g_main_loop_new (NULL, TRUE);
129   g_idle_add ((GSourceFunc) start_finding, pipeline);
130   g_main_loop_run (loop);
131
132   dump_element_stats (decodebin);
133
134   return 0;
135 }