gst-plugins-mythtv/mythtvsrc-test.c
branchtrunk
changeset 12 343d4e3c03ab
parent 2 bd3829c2e9c9
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/gst-plugins-mythtv/mythtvsrc-test.c	Tue Sep 26 15:30:52 2006 +0100
     1.3 @@ -0,0 +1,85 @@
     1.4 +#include <gst/gst.h>
     1.5 +
     1.6 +static gboolean
     1.7 +bus_call (GstBus     *bus,
     1.8 +	  GstMessage *msg,
     1.9 +	  gpointer    data)
    1.10 +{
    1.11 +  GMainLoop *loop = data;
    1.12 +
    1.13 +  switch (GST_MESSAGE_TYPE (msg)) {
    1.14 +    case GST_MESSAGE_EOS:
    1.15 +      g_print ("End-of-stream\n");
    1.16 +      g_main_loop_quit (loop);
    1.17 +      break;
    1.18 +    case GST_MESSAGE_ERROR: {
    1.19 +      gchar *debug;
    1.20 +      GError *err;
    1.21 +
    1.22 +      gst_message_parse_error (msg, &err, &debug);
    1.23 +      g_free (debug);
    1.24 +
    1.25 +      g_print ("Error: %s\n", err->message);
    1.26 +      g_error_free (err);
    1.27 +
    1.28 +      g_main_loop_quit (loop);
    1.29 +      break;
    1.30 +    }
    1.31 +    default:
    1.32 +      break;
    1.33 +  }
    1.34 +
    1.35 +  return TRUE;
    1.36 +}
    1.37 +
    1.38 +gint
    1.39 +main (gint   argc,
    1.40 +      gchar *argv[])
    1.41 +{
    1.42 +  GstElement *pipeline, *filesrc, *decoder, *filter, *sink;
    1.43 +  GMainLoop *loop;
    1.44 +
    1.45 +  /* initialization */
    1.46 +  gst_init (&argc, &argv);
    1.47 +  loop = g_main_loop_new (NULL, FALSE);
    1.48 +  if (argc != 2) {
    1.49 +    g_print ("Usage: %s <myth uri>\n", argv[0]);
    1.50 +    return 01;
    1.51 +  }
    1.52 +
    1.53 +  /* create elements */
    1.54 +  pipeline = gst_pipeline_new ("mythtvsrc_pipeline");
    1.55 +  gst_bus_add_watch (gst_pipeline_get_bus (GST_PIPELINE (pipeline)),
    1.56 +		     bus_call, loop);
    1.57 +
    1.58 +  filesrc  = gst_element_factory_make ("mythtvsrc", "mythtvsrc");
    1.59 +  decoder  = gst_element_factory_make ("mad", "my_decoder");
    1.60 +  filter   = gst_element_factory_make ("my_filter", "my_filter");
    1.61 +  sink     = gst_element_factory_make ("osssink", "audiosink");
    1.62 +  if (!sink || !decoder) {
    1.63 +    g_print ("Decoder or output could not be found - check your install\n");
    1.64 +    return -1;
    1.65 +  } else if (!filter) {
    1.66 +    g_print ("Your self-written filter could not be found. Make sure it "
    1.67 +             "is installed correctly in $(libdir)/gstreamer-0.9/ and that "
    1.68 +             "you've ran gst-register-0.9 to register it. Check availability "
    1.69 +             "of the plugin afterwards using \"gst-inspect-0.9 my_filter\"");
    1.70 +    return -1;
    1.71 +  }
    1.72 +
    1.73 +  g_object_set (G_OBJECT (filesrc), "location", argv[1], NULL);
    1.74 +
    1.75 +  /* link everything together */
    1.76 +  gst_element_link_many (filesrc, decoder, filter, sink, NULL);
    1.77 +  gst_bin_add_many (GST_BIN (pipeline), filesrc, decoder, filter, sink, NULL);
    1.78 +
    1.79 +  /* run */
    1.80 +  gst_element_set_state (pipeline, GST_STATE_PLAYING);
    1.81 +  g_main_loop_run (loop);
    1.82 +
    1.83 +  /* clean up */
    1.84 +  gst_element_set_state (pipeline, GST_STATE_NULL);
    1.85 +  gst_object_unref (GST_OBJECT (pipeline));
    1.86 +
    1.87 +  return 0;
    1.88 +}