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