Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question

2 Answers 2

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.

share|improve this answer
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

share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.