unexpected result when writing to GstBuffer
Michael Gruner
michael.gruner at ridgerun.com
Thu Apr 18 06:45:30 UTC 2019
Hi
On one hand, “guint8 data[]” is allocated in the stack, so it is local to the current function. Contents may change as soon as the function ends. That would explain why the copy works. Try allocating it on the heap.
On the other hand, I believe “get_buffer_new_and_alloc” is deprecated. You may take a look at “gst_buffer_new_allocate”, or if you want to wrap a pointer “gst_buffer_new_wrapped” and “gst_buffer_new_wrapped_full”. There is no need to allocate a memory if you are inserting a wrapped memory later.
https://developer.gnome.org/gstreamer/stable/gstreamer-GstBuffer.html#gst-buffer-new-wrapped-full
Michael
www.ridgerun.com
> On Apr 18, 2019, at 12:32 AM, longkas <longkas at gmail.com> wrote:
>
> Hello,
> I'm writing a simple test of appsrc, the appsrc generates 1x1 BGRA pixels
> with framerate 1/1:
>
> ----------------------------------------
> GstCaps *srcCaps;
> srcCaps = gst_caps_new_simple("video/x-raw",
> "width", G_TYPE_INT, 1,
> "height", G_TYPE_INT, 1,
> "format", G_TYPE_STRING, "BGRA",
> "framerate", GST_TYPE_FRACTION, 1, 1,
> NULL);
> gst_app_src_set_caps(appSrc, srcCaps);
> ----------------------------------------
>
> the need_data callback will push a red color pixel when be invoked, but it
> displays pink instead of red color on the screen:
>
> ----------------------------------------
> void cb_need_data(GstAppSrc *src, guint length, gpointer user_data) {
> GstBuffer *buffer;
> guint8 data[] = {0, 0, 255, 255}; //red color in BGRA
> buffer = gst_buffer_new_and_alloc(4); // 4 bytes for 1x1 pixel
> gst_buffer_insert_memory(buffer, 0,
> gst_memory_new_wrapped(GST_MEMORY_FLAG_READONLY, &data[0], 4, 0, 4, NULL,
> NULL));
> //set time and duration
> ...
> }
> ----------------------------------------
>
> if I write buffer one by one, I do get the red color as expected
>
> ----------------------------------------
> for(int i=0; i < 4; i++) {
> gst_buffer_memset(buffer, i, data[i], 1);
> }
> ----------------------------------------
>
> need advice how to use gst_memory_new_wrapped, thanks
>
>
>
>
>
>
> --
> Sent from: http://gstreamer-devel.966125.n4.nabble.com/
> _______________________________________________
> gstreamer-devel mailing list
> gstreamer-devel at lists.freedesktop.org
> https://lists.freedesktop.org/mailman/listinfo/gstreamer-devel
More information about the gstreamer-devel
mailing list