vaapivideomemory: disallow memory shares across buffers, use a copy.

Forbid shares of GstMemory instances, and rather make copy of it. This
effectively copies the GstMemory structure and enclosed metadata, but
this does not copy the VA surface contents itself. It should though.

This fixes preroll and makes sure to not download garbage for the first
frame when a SW rendering sink is used.
This commit is contained in:
Gwenole Beauchesne 2014-07-24 11:58:29 +02:00
parent 3a762284a2
commit e0e869f536

View file

@ -269,8 +269,9 @@ gst_vaapi_video_memory_new(GstAllocator *base_allocator,
return NULL;
vip = &allocator->image_info;
gst_memory_init(&mem->parent_instance, 0, gst_object_ref(allocator), NULL,
GST_VIDEO_INFO_SIZE(vip), 0, 0, GST_VIDEO_INFO_SIZE(vip));
gst_memory_init(&mem->parent_instance, GST_MEMORY_FLAG_NO_SHARE,
gst_object_ref(allocator), NULL, GST_VIDEO_INFO_SIZE(vip), 0,
0, GST_VIDEO_INFO_SIZE(vip));
mem->proxy = NULL;
mem->surface_info = &allocator->surface_info;
@ -417,13 +418,22 @@ static GstVaapiVideoMemory *
gst_vaapi_video_memory_copy(GstVaapiVideoMemory *mem,
gssize offset, gssize size)
{
GstVaapiVideoMeta *meta;
GstMemory *out_mem;
gsize maxsize;
if (offset != 0 || size != -1)
/* XXX: this implements a soft-copy, i.e. underlying VA surfaces
are not copied */
(void)gst_memory_get_sizes(GST_MEMORY_CAST(mem), NULL, &maxsize);
if (offset != 0 || (size != -1 && (gsize)size != maxsize))
goto error_unsupported;
out_mem = gst_vaapi_video_memory_new(mem->parent_instance.allocator,
mem->meta);
meta = gst_vaapi_video_meta_copy(mem->meta);
if (!meta)
goto error_allocate_memory;
out_mem = gst_vaapi_video_memory_new(GST_MEMORY_CAST(mem)->allocator, meta);
gst_vaapi_video_meta_unref(meta);
if (!out_mem)
goto error_allocate_memory;
return GST_VAAPI_VIDEO_MEMORY_CAST(out_mem);