gst-plugins-mythtv/tests/mythtvsrc-test.c
author rosfran
Mon Dec 18 22:18:57 2006 +0000 (2006-12-18)
branchtrunk
changeset 223 657379d8f3b6
parent 13 f3cdc7844178
permissions -rwxr-xr-x
[svn r224] Fixed problem on g_time_val_* functions.
     1 #include <gst/gst.h>
     2 
     3 static gboolean
     4 bus_call (GstBus     *bus,
     5 	  GstMessage *msg,
     6 	  gpointer    data)
     7 {
     8   GMainLoop *loop = data;
     9 
    10   switch (GST_MESSAGE_TYPE (msg)) {
    11     case GST_MESSAGE_EOS:
    12       g_print ("End-of-stream\n");
    13       g_main_loop_quit (loop);
    14       break;
    15     case GST_MESSAGE_ERROR: {
    16       gchar *debug;
    17       GError *err;
    18 
    19       gst_message_parse_error (msg, &err, &debug);
    20       g_free (debug);
    21 
    22       g_print ("Error: %s\n", err->message);
    23       g_error_free (err);
    24 
    25       g_main_loop_quit (loop);
    26       break;
    27     }
    28     default:
    29       break;
    30   }
    31 
    32   return TRUE;
    33 }
    34 
    35 gint
    36 main (gint   argc,
    37       gchar *argv[])
    38 {
    39   GstElement *pipeline, *filesrc, *decoder, *filter, *sink;
    40   GMainLoop *loop;
    41 
    42   /* initialization */
    43   gst_init (&argc, &argv);
    44   loop = g_main_loop_new (NULL, FALSE);
    45   if (argc != 2) {
    46     g_print ("Usage: %s <myth uri>\n", argv[0]);
    47     return 01;
    48   }
    49 
    50   /* create elements */
    51   pipeline = gst_pipeline_new ("mythtvsrc_pipeline");
    52   gst_bus_add_watch (gst_pipeline_get_bus (GST_PIPELINE (pipeline)),
    53 		     bus_call, loop);
    54 
    55   filesrc  = gst_element_factory_make ("mythtvsrc", "mythtvsrc");
    56   decoder  = gst_element_factory_make ("mad", "my_decoder");
    57   filter   = gst_element_factory_make ("my_filter", "my_filter");
    58   sink     = gst_element_factory_make ("osssink", "audiosink");
    59   if (!sink || !decoder) {
    60     g_print ("Decoder or output could not be found - check your install\n");
    61     return -1;
    62   } else if (!filter) {
    63     g_print ("Your self-written filter could not be found. Make sure it "
    64              "is installed correctly in $(libdir)/gstreamer-0.9/ and that "
    65              "you've ran gst-register-0.9 to register it. Check availability "
    66              "of the plugin afterwards using \"gst-inspect-0.9 my_filter\"");
    67     return -1;
    68   }
    69 
    70   g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
    71 
    72   /* link everything together */
    73   gst_element_link_many (filesrc, decoder, filter, sink, NULL);
    74   gst_bin_add_many (GST_BIN (pipeline), filesrc, decoder, filter, sink, NULL);
    75 
    76   /* run */
    77   gst_element_set_state (pipeline, GST_STATE_PLAYING);
    78   g_main_loop_run (loop);
    79 
    80   /* clean up */
    81   gst_element_set_state (pipeline, GST_STATE_NULL);
    82   gst_object_unref (GST_OBJECT (pipeline));
    83 
    84   return 0;
    85 }