Regarding video stream receive

Shilpa Chandrappa elites.shilpa at
Mon Dec 30 03:41:33 PST 2013

As suggested I looked into appsink. Till now I was just using Gstreamer
pipelines, I have no hands-on gstreamer application development.

I looked into different sample appsink application and was trying to modify
so that it suits my requirement. But the code is giving "Internal data flow

I am still trying to understand the APIs. Can anyone tell me whats wrong
with the below code ? 

All I need is to receive data to buffer instead of file.[ gst-launch-0.10
rtsp location=rtsp://XYZ/H264 ! rtph264depay ! filesink location=XYZ.264 ]

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

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

  switch (GST_MESSAGE_TYPE (msg)) {


      g_print ("End of stream\n");
      g_main_loop_quit (loop);

      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);

  return TRUE;

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

  g_print ("Dynamic pad created, linking demuxer/decoder\n");

  sinkpad = gst_element_get_static_pad (decoder, "app_sink");

  gst_pad_link (pad, sinkpad);

  gst_object_unref (sinkpad);

static void new_buffer (GstElement *sink) {
  GstBuffer *buffer;

  g_signal_emit_by_name (sink, "pull-buffer", &buffer);
  if (buffer) {
    g_print ("*");
    gst_buffer_unref (buffer);

int main (int   argc,      char *argv[])
  gchar *video_caps_text;
  GstCaps *video_caps;
  GMainLoop *loop;
  GstCaps* udp_caps;

  GstElement *pipeline, *source, *parser, *decoder, *sink, *app_sink;
  GstBus *bus;
  guint bus_watch_id;

  gst_init (&argc, &argv);

  loop = g_main_loop_new (NULL, FALSE);

  if (argc != 2) {
    g_printerr ("Usage: %s <rtsp-url>\n", argv[0]);
    return -1;

  pipeline = gst_pipeline_new ("video-record");
  source   = gst_element_factory_make ("rtspsrc",       "file-source");
  parser  = gst_element_factory_make ("rtph264depay",      "h-parser");
  app_sink = gst_element_factory_make ("appsink", "app_sink");

  if (!pipeline || !source || !parser || !app_sink) {
    g_printerr ("One element could not be created. Exiting.\n");
    return -1;

  g_object_set (G_OBJECT (source), "location", argv[1], NULL);

 udp_caps = gst_caps_from_string("application/x-rtp");
      g_warning("Error alocating the udp caps");
      return -1;

  g_object_set (app_sink, "emit-signals", TRUE ,"caps",udp_caps,NULL);
  g_signal_connect (app_sink, "new-buffer", G_CALLBACK (new_buffer), NULL);

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

  gst_bin_add_many (GST_BIN (pipeline),
                    source, parser,app_sink, NULL);
  gst_element_link_many (source, parser,app_sink,  NULL);

  g_print ("Now playing: %s\n", argv[1]);
  gst_element_set_state (pipeline, GST_STATE_PLAYING);

  g_print ("Running...\n");
  g_main_loop_run (loop);

  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));
  g_source_remove (bus_watch_id);
  g_main_loop_unref (loop);
  return 0;

View this message in context:
Sent from the GStreamer-devel mailing list archive at

More information about the gstreamer-devel mailing list