  #include <string.h>
  #include <math.h>
  #include <gst/gst.h>

 static gboolean bus_event_callback (GstBus *bus, GstMessage *msg, gpointer data) {

      GMainLoop *loop = (GMainLoop *) data;

     switch (GST_MESSAGE_TYPE(msg)) {
      case GST_MESSAGE_EOS:
          g_print("FinDeStream\n");
          g_main_loop_quit(loop);
          break;
      case GST_MESSAGE_ERROR: {
          gchar *debug;
          GError *err;
          gst_message_parse_error(msg, &err, &debug);
          g_free (debug);
          g_print ("Error: %s\n", err>message);
          g_error_free (err);
          g_main_loop_quit(loop);
          break;
      }
      default:
          break;
      }

     return TRUE;
  }

 int main (int argc, char *argv) {
      GMainLoop *loop;
      GstElement *pipeline, *dccpclientsrc, *decodebin, *alsasink;
      GstBus *bus;

     /* inicializar GStreamer */
      gst_init (&argc, &argv);
      loop = g_main_loop_new(NULL, FALSE);

     /* comprobar argumentos de entrada */
      if (argc != 3) {
          g_print ("Usage: %s Servidor Puerto\n", argv[0]);
          return 1;
      }

     /* crear los elementos */
      pipeline = gst_pipeline_new ("audiosender");
      dccpclientsrc = gst_element_factory_make("dccpclientsrc", "clientsource");
      decodebin = gst_element_factory_make ("decodebin", "decodebin");
      alsasink = gst_element_factory_make ("alsasink", "alsasink");

     if (!pipeline || !alsasink || !decodebin || !dccpclientsrc) {
          g_print ("No se pudo crear instancia de uno o más elementos\n");
          return 1;
      }

     // configurar el host y el puerto en que está el servidor a la espera
      g_object_set (G_OBJECT(dccpclientsrc), "host", argv[1], NULL);
      g_object_set (G_OBJECT(dccpclientsrc), "port", atoi(argv[2]), NULL);

     /* poner todos los elementos en un bin */
      gst_bin_add_many (GST_BIN(pipeline), dccpclientsrc, decodebin, alsasink, NULL);

     gst_element_link_many(dccpclientsrc, decodebin, alsasink, NULL);

     bus = gst_pipeline_get_bus(GST_PIPELINE (pipeline));
      gst_bus_add_watch (bus, bus_event_callback, loop);
      gst_object_unref (bus);

     /* Poner en modo "reproduciendo" e iterar */
      g_print ("REPRODUCIENDO\n");
      gst_element_set_state(pipeline, GST_STATE_PLAYING);
      g_print ("En ejecución\n");
      g_main_loop_run (loop);

     /* Limpiar correctamente */
      g_print ("Deteniendo la reproducción\n");
      gst_element_set_state(pipeline, GST_STATE_NULL);
      g_print ("Eliminando la tubería\n");
      gst_object_unref (GST_OBJECT (pipeline));

     return 0;
  }

