h264 streaming - byte buffer a source

thegoodgiant giorgioscibilia at gmail.com
Fri Jul 26 06:15:19 PDT 2013

Hi all, 
I am new here and also new to GStreamer so, sorry for the probablty-stupid

I am developing a C application under linux that receives an h.264 stream
(from a device over local wifi) and should play it. There's a method called
every time there is new data available (in the form of an uint8_t pointer).
This should be my data source, but I have some issues: my compiles and runs
with no errors, but I see no video :)

I had a look at  this manual
and googled in order  to be a bit confident with the environment/APIs.
As a first step I realized (copy/pasted from various internet pages and
adjusted to my use case) a sw that plays a video file in the exact format I
need (It uses playbin).

Now I am trying without success to make the same exact thing, but changing
the source. 
Inside my code I have a method that is called every time new data is ready
to be visualized, it's something like:

void data_available(uint8_t *inPtr, size_t size){
   play_data(inPtr, size)

I have implemented two more methods: "init_stream()" that should init the
pipeline and "play_data(void* inPtr, size_t len)" that shuld push new data.
I'm trying to use appsrc in push mode, so what I do is initializing the
pipeline (init_stream called in the main loop) and then simply pushing new
data every time they are available (play_data is called inside

Below you can find my current init_stream and play_data implementation. Can
you please tell me what am I doing wrong?

int init_stream()
  GstBus *bus;

  gst_init (NULL, NULL);
  fprintf(stderr, "gst_init done\n");

  /* create a mainloop to get messages */
    app->loop = g_main_loop_new (NULL, TRUE);
    fprintf(stderr, "app loop initialized\n");

    app->pipeline = gst_parse_launch("appsrc name=mysource ! h264parse !
mfw_vpudecoder ! mfw_v4lsin", NULL);

    app->appsrc = gst_bin_get_by_name (GST_BIN(app->pipeline), "mysource");
      gst_app_src_set_stream_type(app->appsrc, GST_APP_STREAM_TYPE_STREAM);

//      gst_app_src_set_emit_signals(app->appsrc, TRUE);
      fprintf(stderr, "Pipeline and appsrc initialized\n");

    	/* Create Bus from pipeline */
        bus = gst_pipeline_get_bus(app->pipeline);
         fprintf(stderr, "bus created\n");

         /* add watch for messages */
         gst_bus_add_watch (bus, (GstBusFunc) bus_message, app);
        fprintf(stderr, "bus_add_watch done\n");

        GstCaps* video_caps = gst_caps_new_simple ("video/x-h264",
                                         "width", G_TYPE_INT, 800,
                                         "height", G_TYPE_INT, 480,
                                         "framerate", GST_TYPE_FRACTION, 25,
                                         1, NULL);

     gst_app_src_set_caps(GST_APP_SRC(app->appsrc), video_caps);

  /* go to playing and wait in a mainloop. */
  gst_element_set_state ((GstElement*) app->pipeline, GST_STATE_PLAYING);
  fprintf(stderr, "gst_element_set_state play\n");

  /* this mainloop is stopped when we receive an error or EOS */
  g_main_loop_run (app->loop);
  fprintf(stderr, "g_main_loop_run called\n");

  gst_element_set_state ((GstElement*) app->pipeline, GST_STATE_NULL);

  fprintf(stderr, "gst_element_set_state GST_STATE_NULL\n");

  /* free the file */
//  g_mapped_file_unref (app->file);

  gst_object_unref (bus);
  g_main_loop_unref (app->loop);

  return 0;

void play_data(void *inBuf ,  size_t len) {

	static gboolean white = FALSE;
	static GstClockTime timestamp = 0;
	GstBuffer *buffer;
	guint size;
	GstFlowReturn ret_;
	size = len;

	buffer =  gst_buffer_new();
	GST_BUFFER_SIZE(buffer) = len;

	GstCaps* caps = gst_caps_new_simple ("video/x-h264",
		                                         "width", G_TYPE_INT, 800,
		                                         "height", G_TYPE_INT, 480,
		                                         "framerate", GST_TYPE_FRACTION,

	 gst_buffer_set_caps(buffer, caps);

	GST_BUFFER_TIMESTAMP (buffer) = timestamp;

	GST_BUFFER_DURATION (buffer) = gst_util_uint64_scale_int (1, GST_SECOND,

	timestamp += GST_BUFFER_DURATION (buffer);

	g_signal_emit_by_name (app->appsrc, "push-buffer", buffer, &ret_);

	if (ret_ != GST_FLOW_OK) {

	/* something wrong, stop pushing */

	g_main_loop_quit (app->loop);


View this message in context: http://gstreamer-devel.966125.n4.nabble.com/h264-streaming-byte-buffer-a-source-tp4661283.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.

More information about the gstreamer-devel mailing list