gst_plugins_base/gst/playback/test5.c
changeset 0 0e761a78d257
child 8 4a7fac7dd34a
equal deleted inserted replaced
-1:000000000000 0:0e761a78d257
       
     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 #include <unistd.h>
       
    20 #include <stdlib.h>             /* exit */
       
    21 #include <gst/gst.h>
       
    22 
       
    23 static GMainLoop *loop;
       
    24 
       
    25 static void
       
    26 new_pad (GstElement * element, GstPad * pad, gboolean last, GstElement * sink)
       
    27 {
       
    28   g_print ("New pad...\n");
       
    29 }
       
    30 
       
    31 static void
       
    32 no_more_pads (GstElement * element)
       
    33 {
       
    34   g_print ("No more pads...\n");
       
    35   g_main_loop_quit (loop);
       
    36 }
       
    37 
       
    38 static gboolean
       
    39 start_finding (GstElement * pipeline)
       
    40 {
       
    41   GstStateChangeReturn res;
       
    42 
       
    43   g_print ("finding caps...\n");
       
    44   res = gst_element_set_state (pipeline, GST_STATE_PAUSED);
       
    45   if (res == GST_STATE_CHANGE_FAILURE) {
       
    46     g_print ("could not pause\n");
       
    47     exit (-1);
       
    48   }
       
    49   return FALSE;
       
    50 }
       
    51 
       
    52 static void
       
    53 dump_element_stats (GstElement * element)
       
    54 {
       
    55   GstIterator *it;
       
    56   gpointer data;
       
    57 
       
    58   it = gst_element_iterate_src_pads (element);
       
    59   while (gst_iterator_next (it, &data) == GST_ITERATOR_OK) {
       
    60     GstPad *pad = GST_PAD (data);
       
    61     GstCaps *caps;
       
    62     gchar *str;
       
    63     GstQuery *query;
       
    64 
       
    65     g_print ("stream %s:\n", GST_OBJECT_NAME (pad));
       
    66 
       
    67     caps = gst_pad_get_caps (pad);
       
    68     str = gst_caps_to_string (caps);
       
    69     g_print (" caps: %s\n", str);
       
    70     g_free (str);
       
    71     gst_caps_unref (caps);
       
    72 
       
    73     query = gst_query_new_duration (GST_FORMAT_TIME);
       
    74     if (gst_pad_query (pad, query)) {
       
    75       gint64 duration;
       
    76 
       
    77       gst_query_parse_duration (query, NULL, &duration);
       
    78 
       
    79       g_print (" duration: %" GST_TIME_FORMAT "\n", GST_TIME_ARGS (duration));
       
    80     }
       
    81     gst_query_unref (query);
       
    82 
       
    83     gst_object_unref (pad);
       
    84   }
       
    85   gst_iterator_free (it);
       
    86 }
       
    87 
       
    88 gint
       
    89 main (gint argc, gchar * argv[])
       
    90 {
       
    91   GstElement *pipeline, *filesrc, *decodebin;
       
    92 
       
    93   gst_init (&argc, &argv);
       
    94 
       
    95   pipeline = gst_pipeline_new ("pipeline");
       
    96 
       
    97   filesrc = gst_element_factory_make ("filesrc", "filesrc");
       
    98   g_assert (filesrc);
       
    99 
       
   100   decodebin = gst_element_factory_make ("decodebin", "decodebin");
       
   101   g_assert (decodebin);
       
   102 
       
   103   g_signal_connect (G_OBJECT (decodebin), "new-decoded-pad",
       
   104       G_CALLBACK (new_pad), NULL);
       
   105   g_signal_connect (G_OBJECT (decodebin), "no-more-pads",
       
   106       G_CALLBACK (no_more_pads), NULL);
       
   107 
       
   108   gst_bin_add_many (GST_BIN (pipeline), filesrc, decodebin, NULL);
       
   109   gst_element_link (filesrc, decodebin);
       
   110 
       
   111   if (argc < 2) {
       
   112     g_print ("usage: %s <uri>\n", argv[0]);
       
   113     exit (-1);
       
   114   }
       
   115   g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
       
   116 
       
   117   /* event based programming approach */
       
   118   loop = g_main_loop_new (NULL, TRUE);
       
   119   g_idle_add ((GSourceFunc) start_finding, pipeline);
       
   120   g_main_loop_run (loop);
       
   121 
       
   122   dump_element_stats (decodebin);
       
   123 
       
   124   return 0;
       
   125 }