mirror of
https://gitlab.freedesktop.org/gstreamer/gstreamer.git
synced 2025-01-25 08:38:21 +00:00
va: allocator: Use GstVaSurfaceCopy.
Part-of: <https://gitlab.freedesktop.org/gstreamer/gstreamer/-/merge_requests/1023>
This commit is contained in:
parent
ffa2522fc0
commit
cf751d54a9
1 changed files with 26 additions and 17 deletions
|
@ -28,6 +28,7 @@
|
||||||
#include <unistd.h>
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "gstvacaps.h"
|
#include "gstvacaps.h"
|
||||||
|
#include "gstvasurfacecopy.h"
|
||||||
#include "gstvavideoformat.h"
|
#include "gstvavideoformat.h"
|
||||||
#include "vasurfaceimage.h"
|
#include "vasurfaceimage.h"
|
||||||
|
|
||||||
|
@ -787,6 +788,8 @@ struct _GstVaAllocator
|
||||||
GstVideoInfo info;
|
GstVideoInfo info;
|
||||||
guint usage_hint;
|
guint usage_hint;
|
||||||
|
|
||||||
|
GstVaSurfaceCopy *copy;
|
||||||
|
|
||||||
GstVaMemoryPool pool;
|
GstVaMemoryPool pool;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -818,6 +821,7 @@ gst_va_allocator_finalize (GObject * object)
|
||||||
{
|
{
|
||||||
GstVaAllocator *self = GST_VA_ALLOCATOR (object);
|
GstVaAllocator *self = GST_VA_ALLOCATOR (object);
|
||||||
|
|
||||||
|
g_clear_pointer (&self->copy, gst_va_surface_copy_free);
|
||||||
gst_va_memory_pool_finalize (&self->pool);
|
gst_va_memory_pool_finalize (&self->pool);
|
||||||
g_clear_pointer (&self->surface_formats, g_array_unref);
|
g_clear_pointer (&self->surface_formats, g_array_unref);
|
||||||
gst_clear_object (&self->display);
|
gst_clear_object (&self->display);
|
||||||
|
@ -1137,14 +1141,15 @@ _va_share (GstMemory * mem, gssize offset, gssize size)
|
||||||
return GST_MEMORY_CAST (sub);
|
return GST_MEMORY_CAST (sub);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* XXX(victor): deep copy implementation. A further optimization can
|
/* XXX(victor): deep copy implementation. */
|
||||||
* be done with vaCopy() from libva 2.12 */
|
|
||||||
static GstMemory *
|
static GstMemory *
|
||||||
_va_copy (GstMemory * mem, gssize offset, gssize size)
|
_va_copy (GstMemory * mem, gssize offset, gssize size)
|
||||||
{
|
{
|
||||||
GstMemory *copy;
|
GstMemory *copy;
|
||||||
GstMapInfo sinfo, dinfo;
|
GstMapInfo sinfo, dinfo;
|
||||||
GstVaAllocator *va_allocator = GST_VA_ALLOCATOR (mem->allocator);
|
GstVaAllocator *va_allocator = GST_VA_ALLOCATOR (mem->allocator);
|
||||||
|
GstVaMemory *va_copy, *va_mem = (GstVaMemory *) mem;
|
||||||
|
gsize mem_size;
|
||||||
|
|
||||||
GST_DEBUG ("%p: copy %" G_GSSIZE_FORMAT ", %" G_GSIZE_FORMAT, mem, offset,
|
GST_DEBUG ("%p: copy %" G_GSSIZE_FORMAT ", %" G_GSIZE_FORMAT, mem, offset,
|
||||||
size);
|
size);
|
||||||
|
@ -1165,25 +1170,27 @@ _va_copy (GstMemory * mem, gssize offset, gssize size)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gst_memory_map (mem, &sinfo, GST_MAP_READ))
|
va_copy = (GstVaMemory *) copy;
|
||||||
return NULL;
|
mem_size = gst_memory_get_sizes (mem, NULL, NULL);
|
||||||
|
|
||||||
if (size == -1)
|
if (size == -1)
|
||||||
size = sinfo.size > offset ? sinfo.size - offset : 0;
|
size = mem_size > offset ? mem_size - offset : 0;
|
||||||
|
|
||||||
if (offset == 0 && size == sinfo.size) {
|
if (offset == 0 && size == mem_size) {
|
||||||
GstVaMemory *va_mem = (GstVaMemory *) mem;
|
if (!va_allocator->copy) {
|
||||||
GstVaMemory *va_copy = (GstVaMemory *) copy;
|
va_allocator->copy =
|
||||||
|
gst_va_surface_copy_new (va_allocator->display, &va_allocator->info);
|
||||||
if (!va_mem->is_derived) {
|
|
||||||
if (va_put_image (va_allocator->display, va_copy->surface,
|
|
||||||
&va_mem->image)) {
|
|
||||||
GST_LOG ("shallow copy of %#x to %#x", va_mem->surface,
|
|
||||||
va_copy->surface);
|
|
||||||
gst_memory_unmap (mem, &sinfo);
|
|
||||||
return copy;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (va_allocator->copy
|
||||||
|
&& gst_va_surface_copy (va_allocator->copy, va_copy->surface,
|
||||||
|
va_mem->surface)) {
|
||||||
|
return copy;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (!gst_memory_map (mem, &sinfo, GST_MAP_READ)) {
|
||||||
|
GST_WARNING ("failed to map memory to copy");
|
||||||
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (!gst_memory_map (copy, &dinfo, GST_MAP_WRITE)) {
|
if (!gst_memory_map (copy, &dinfo, GST_MAP_WRITE)) {
|
||||||
|
@ -1408,6 +1415,8 @@ gst_va_allocator_set_format (GstAllocator * allocator, GstVideoInfo * info,
|
||||||
self->usage_hint = usage_hint;
|
self->usage_hint = usage_hint;
|
||||||
self->info = *info;
|
self->info = *info;
|
||||||
|
|
||||||
|
g_clear_pointer (&self->copy, gst_va_surface_copy_free);
|
||||||
|
|
||||||
ret = gst_va_allocator_try (allocator);
|
ret = gst_va_allocator_try (allocator);
|
||||||
if (ret)
|
if (ret)
|
||||||
*info = self->info;
|
*info = self->info;
|
||||||
|
|
Loading…
Reference in a new issue