[gst-devel] How do u set caps for udpsrc

Puneeth puneeth.mv at globaledgesoft.com
Mon Dec 13 13:58:32 CET 2010


Hi All

I m new to gstreamer please help me to solve this bug..
sender: gst-launch -v  alsasrc  ! lamemp3enc ! rtpmpapay ! udpsink port=6969
host=192.168.0.200
Receiver: gst-launch -v udpsrc port=6969 caps="application/x-rtp,
media=(string)audio, clock-rate=(int)90000, encoding-name=(string)MPA,
payload=(int)96" ! rtpmpadepay ! mp3parse ! ffmux_mp3 ! filesink
location=file.mp3

when i m using this in command line i m able to capture raw pcm data and
encoding to mp3 format and sending and receiving through rtp and saving to
file but when i m trying with program it is giving segmentation fault while
setting capabilities using g_object_set

Here is the code where at the receiver side...any suggestions will be
greatly appreciated...
#include <gst/gst.h>
#include <glib.h>
#define caps
"application/x-rtp,media=(string)audio,clock-rate=(int)90000,encoding-name=(string)MPA,payload=(int)96"


static gboolean
bus_call (GstBus     *bus,
          GstMessage *msg,
          gpointer    data)
{
  GMainLoop *loop = (GMainLoop *) data;

  switch (GST_MESSAGE_TYPE (msg)) {

    case GST_MESSAGE_EOS:
      g_print ("End of stream\n");
      g_main_loop_quit (loop);
      break;

    case GST_MESSAGE_ERROR: {
      gchar  *debug;
      GError *error;

      gst_message_parse_error (msg, &error, &debug);
      g_free (debug);

      g_printerr ("Error: %s\n", error->message);
      g_error_free (error);

      g_main_loop_quit (loop);
      break;
    }
    default:
      break;
  }

  return TRUE;
}


static void
on_pad_added (GstElement *element,
              GstPad     *pad,
              gpointer    data)
{
  GstPad *sinkpad;
  GstElement *decoder = (GstElement *) data;

  /* We can now link this pad with the vorbis-decoder sink pad */
  g_print ("Dynamic pad created, linking demuxer/decoder\n");

  sinkpad = gst_element_get_static_pad (decoder, "sink");

  gst_pad_link (pad, sinkpad);

  gst_object_unref (sinkpad);
}



int
main (int   argc,
      char *argv[])
{
  GMainLoop *loop;

  GstElement *pipeline, *rtp, *muxer, *parse, *sink, *udp;
  GstBus *bus;

  /* Initialisation */
  gst_init (&argc, &argv);

  loop = g_main_loop_new (NULL, FALSE);

  /* Check input arguments */
  if (argc != 2) {
    g_printerr ("Usage: %s <filename>\n", argv[0]);
    return -1;
  }


  /* Create gstreamer elements */
  pipeline = gst_pipeline_new ("audio-player");
  udp   = gst_element_factory_make ("udpsrc",       "udp-src");
  rtp  = gst_element_factory_make ("rtpmpadepay",      "rtpmpa-depay");
  parse = gst_element_factory_make ("mp3parse",     "mp3-parse");
  muxer  = gst_element_factory_make ("ffmux_mp3", "ffmux-mp3");
  sink  = gst_element_factory_make ("filesink", "file-sink");

  if (!pipeline || !udp || !rtp || !parse || !muxer || !sink) {
    g_printerr ("One element could not be created. Exiting.\n");
    return -1;
  }

  /* Set up the pipeline */

  /* we set the input filename to the source element */
  g_object_set (G_OBJECT (sink), "location", argv[1], NULL);
  g_object_set (G_OBJECT (udp), "typefind", TRUE,
		  "port", 3000,
		  "caps", caps, NULL);

  /* we add a message handler */
  bus = gst_pipeline_get_bus (GST_PIPELINE (pipeline));
  gst_bus_add_watch (bus, bus_call, loop);
  gst_object_unref (bus);

  /* we add all elements into the pipeline */
  /* file-source | ogg-demuxer | vorbis-decoder | converter | alsa-output */
  gst_bin_add_many (GST_BIN (pipeline),
                    udp, rtp, parse, muxer, sink, NULL);
//  g_signal_connect (muxer, "pad-added", G_CALLBACK (on_pad_added),
decoder);
  gst_element_link_many ( udp, rtp, parse, muxer, sink, NULL);

  /* note that the demuxer will be linked to the decoder dynamically.
     The reason is that Ogg may contain various streams (for example
     audio and video). The source pad(s) will be created at run time,
     by the demuxer when it detects the amount and nature of streams.
     Therefore we connect a callback function which will be executed
     when the "pad-added" is emitted.*/


  /* Set the pipeline to "playing" state*/
  g_print ("Now playing: %s\n", argv[1]);
  gst_element_set_state (pipeline, GST_STATE_PLAYING);


  /* Iterate */
  g_print ("Running...\n");
  g_main_loop_run (loop);


  /* Out of the main loop, clean up nicely */
  g_print ("Returned, stopping playback\n");
  gst_element_set_state (pipeline, GST_STATE_NULL);

  g_print ("Deleting pipeline\n");
  gst_object_unref (GST_OBJECT (pipeline));

  return 0;
}


-- 
View this message in context: http://gstreamer-devel.966125.n4.nabble.com/How-do-u-set-caps-for-udpsrc-tp3085367p3085367.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.




More information about the gstreamer-devel mailing list