3

I am trying to copy from the original buffer buf (in the chain function) to another buffer created using:

GstBuffer *buffer;
glong size;

size = GST_BUFFER_SIZE(buf);
buffer = gst_buffer_new ();
GST_BUFFER_SIZE (buffer) = size;
GST_BUFFER_MALLOCDATA (buffer) = g_malloc (size);
GST_BUFFER_DATA (buffer) = GST_BUFFER_MALLOCDATA (buffer);
memcpy(buffer,buf,size);

But I get a segmentation fault. Is there anything wrong here?

Jorge Castro
  • 71,754
varun
  • 31

2 Answers2

3

Rather than writing to the data the GstBuffer is managing, you're overwriting the GstBuffer object itself with your final memcpy call. Instead, you want to write to GST_BUFFER_DATA (buffer).

With that said if you just want a new buffer with the same data, it would seem easier to just use the gst_buffer_copy() function.

0
GstBuffer *buffer;
glong size;
size = GST_BUFFER_SIZE(inp);
buffer = gst_buffer_new();
GST_BUFFER_SIZE(buffer) = size;
GST_BUFFER_MALLOCDATA(buffer) = g_malloc(size);
GST_BUFFER_DATA(buffer) = GST_BUFFER_MALLOCDATA(buffer);
buffer = GST_BUFFER_DATA(inp);

// Now you can use the data pointed by buffer to say write it in a file using fwrite

Deepak
  • 1