[gst-devel] appsrc push to filesink problem

confused buteo.rg at googlemail.com
Tue May 18 12:07:30 CEST 2010


...excuse me , here's a more readable version.

Hi all,

I am trying to use appsrc gstappsrc/gstappbuffer to push live encoded TS
data from a video capture card; The idea is to capture the data, and then
pass it on to gstreamer decode pipeline using appsrc push method.

I have attached an example which will work in a similar way, i.e. read data
to buffer and pass it to pipeline via GstBuffer. The program doesn't always
work, i.e. changing the filesink output filename causes the program to
behave differently; either the output file is empty, or sometimes it works.

I have been unable to find documentation on the following
gst_app_buffer_new(...) function. Please can anybody help in explaining this
function, and in particular, the correct way to free memory and unref the
GstBuffer?

Many thanks,
Richard

#include <gst/gst.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <gst/app/gstappsrc.h>
#include <gst/app/gstappbuffer.h>
#include <gst/app/gstappsink.h>

const int READBUF = 188*1000;
typedef struct _App App;
struct _App
{
  GstElement *pipe;
  GstElement *src;
  GstElement *id;
  GstElement *sink;
};

App s_app;

static void finalize (void *priv);

int
main (int argc, char *argv[])
{
  GstBuffer *buf;
  char *data;
  FILE *fp = NULL;
  size_t bytes_read=0;
  App *app = &s_app;
  int bytetotal = 0;

  gst_init (&argc, &argv);

  app->pipe = gst_pipeline_new (NULL);
  g_assert (app->pipe);

  app->src = gst_element_factory_make ("appsrc", NULL);
  g_assert (app->src);
  gst_bin_add (GST_BIN (app->pipe), app->src);

    app->id = gst_element_factory_make ("identity", NULL);
  g_assert (app->id);
  gst_bin_add (GST_BIN (app->pipe), app->id);

  app->sink = gst_element_factory_make ("filesink", NULL);
  g_object_set (G_OBJECT (app->sink), "location",
"/home/richard/Desktop/test.ts", NULL);
  g_assert (app->sink);
  gst_bin_add (GST_BIN (app->pipe), app->sink);

  gst_element_link (app->src, app->id);
  gst_element_link (app->id, app->sink);

  printf("Setting PIPELINE to PLAY.......\n");

  gst_element_set_state (app->pipe, GST_STATE_PLAYING);
  fp =
fopen("/home/richard/Desktop/test_noise_x264enc_width80_height60_br512Mbps.ts",
"r");
  if (fp==NULL)
  {
      g_print ("File open error\n");
      exit(-1);
  }
  data=(char *)malloc(READBUF);
  bytes_read = fread(data, 1, READBUF,  fp);
  bytetotal += bytes_read;
  printf(" Bytes read : %d\n", bytes_read);
  while(bytes_read == READBUF)
  {
    buf = gst_app_buffer_new (data, READBUF, finalize, data);
    gst_app_src_push_buffer (GST_APP_SRC (app->src), buf);
    bytes_read = fread(data, 1, READBUF,  fp);
    bytetotal += bytes_read;
    printf("Bytes read : %d - total : %d\n", bytes_read, bytetotal);
    if (bytes_read != READBUF)
    {//push the last buffer
        g_print ("Reached eof\n");
        buf = gst_app_buffer_new (data, bytes_read, finalize, data);
        gst_app_src_push_buffer (GST_APP_SRC (app->src), buf);
    }
  }
  gst_app_src_end_of_stream (GST_APP_SRC (app->src));

  gst_element_set_state (app->pipe, GST_STATE_NULL);
//  g_object_unref (buf);
  free(data);
  return 0;
}

static void
finalize (void *priv)
{
//  printf ("\nfreeing buffer for pointer %p\n", priv);
//  free (priv);
}
-- 
View this message in context: http://gstreamer-devel.966125.n4.nabble.com/appsrc-push-to-filesink-problem-tp2221022p2221033.html
Sent from the GStreamer-devel mailing list archive at Nabble.com.




More information about the gstreamer-devel mailing list