plugins: add GstVaapiVideoMemory and GstVaapiVideoBufferPool objects.
authorSreerenj Balachandran <sreerenj.balachandran@intel.com>
Thu, 8 Nov 2012 14:41:22 +0000 (16:41 +0200)
committerGwenole Beauchesne <gwenole.beauchesne@intel.com>
Wed, 10 Apr 2013 12:58:16 +0000 (14:58 +0200)
Add initial support for GstVaapiVideoMemory backed buffer pool. The memory
object currently holds a reference to GstVaapiVideoMeta.

Signed-off-by: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
gst/vaapi/Makefile.am
gst/vaapi/gstvaapivideobufferpool.c [new file with mode: 0644]
gst/vaapi/gstvaapivideobufferpool.h [new file with mode: 0644]
gst/vaapi/gstvaapivideomemory.c [new file with mode: 0644]
gst/vaapi/gstvaapivideomemory.h [new file with mode: 0644]

index e8d6633..dd730bb 100644 (file)
@@ -53,6 +53,16 @@ libgstvaapi_source_c         += gstvaapivideoconverter_glx.c
 libgstvaapi_source_h           += gstvaapivideoconverter_glx.h
 endif
 
+libgstvaapi_source_c += \
+       gstvaapivideobufferpool.c \
+       gstvaapivideomemory.c   \
+       $(NULL)
+
+libgstvaapi_source_h += \
+       gstvaapivideobufferpool.h \
+       gstvaapivideomemory.h   \
+       $(NULL)
+
 libgstvaapi_la_SOURCES         = $(libgstvaapi_source_c)
 noinst_HEADERS                 = $(libgstvaapi_source_h)
 
diff --git a/gst/vaapi/gstvaapivideobufferpool.c b/gst/vaapi/gstvaapivideobufferpool.c
new file mode 100644 (file)
index 0000000..06e8d85
--- /dev/null
@@ -0,0 +1,283 @@
+/*
+ *  gstvaapivideobufferpool.c - Gstreamer/VA video buffer pool
+ *
+ *  Copyright (C) 2013 Intel Corporation
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1
+ *  of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free
+ *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ *  Boston, MA 02110-1301 USA
+ */
+
+#include "gst/vaapi/sysdeps.h"
+#include "gstvaapivideobufferpool.h"
+#include "gstvaapivideobuffer.h"
+#include "gstvaapivideomemory.h"
+
+GST_DEBUG_CATEGORY_STATIC(gst_debug_vaapivideopool);
+#define GST_CAT_DEFAULT gst_debug_vaapivideopool
+
+G_DEFINE_TYPE(GstVaapiVideoBufferPool,
+              gst_vaapi_video_buffer_pool,
+              GST_TYPE_BUFFER_POOL)
+
+enum {
+    PROP_0,
+
+    PROP_DISPLAY,
+};
+
+struct _GstVaapiVideoBufferPoolPrivate {
+    GstAllocator       *allocator;
+    GstVaapiDisplay    *display;
+    guint               has_video_meta  : 1;
+};
+
+#define GST_VAAPI_VIDEO_BUFFER_POOL_GET_PRIVATE(obj)    \
+    (G_TYPE_INSTANCE_GET_PRIVATE((obj),                 \
+        GST_VAAPI_TYPE_VIDEO_BUFFER_POOL,               \
+        GstVaapiVideoBufferPoolPrivate))
+
+static void
+gst_vaapi_video_buffer_pool_finalize(GObject *object)
+{
+    GstVaapiVideoBufferPoolPrivate * const priv =
+        GST_VAAPI_VIDEO_BUFFER_POOL(object)->priv;
+
+    G_OBJECT_CLASS(gst_vaapi_video_buffer_pool_parent_class)->finalize(object);
+
+    g_clear_object(&priv->display);
+    g_clear_object(&priv->allocator);
+}
+
+static void
+gst_vaapi_video_buffer_pool_set_property(GObject *object, guint prop_id,
+    const GValue *value, GParamSpec *pspec)
+{
+    GstVaapiVideoBufferPoolPrivate * const priv =
+        GST_VAAPI_VIDEO_BUFFER_POOL(object)->priv;
+
+    switch (prop_id) {
+    case PROP_DISPLAY:
+        priv->display = g_object_ref(g_value_get_object(value));
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+        break;
+    }
+}
+
+static void
+gst_vaapi_video_buffer_pool_get_property(GObject *object, guint prop_id,
+    GValue *value, GParamSpec *pspec)
+{
+    GstVaapiVideoBufferPoolPrivate * const priv =
+        GST_VAAPI_VIDEO_BUFFER_POOL(object)->priv;
+
+    switch (prop_id) {
+    case PROP_DISPLAY:
+        g_value_set_object(value, priv->display);
+        break;
+    default:
+        G_OBJECT_WARN_INVALID_PROPERTY_ID(object, prop_id, pspec);
+        break;
+    }
+}
+
+static const gchar **
+gst_vaapi_video_buffer_pool_get_options(GstBufferPool *pool)
+{
+    static const gchar *g_options[] = {
+        GST_BUFFER_POOL_OPTION_VIDEO_META,
+        GST_BUFFER_POOL_OPTION_VAAPI_VIDEO_META,
+        NULL,
+    };
+    return g_options;
+}
+
+static gboolean
+gst_vaapi_video_buffer_pool_set_config(GstBufferPool *pool,
+    GstStructure *config)
+{
+    GstVaapiVideoBufferPoolPrivate * const priv =
+        GST_VAAPI_VIDEO_BUFFER_POOL(pool)->priv;
+    GstCaps *caps = NULL;
+
+    if (!gst_buffer_pool_config_get_params(config, &caps, NULL, NULL, NULL))
+        goto error_invalid_config;
+    if (!caps)
+        goto error_no_caps;
+
+    g_clear_object(&priv->allocator);
+    priv->allocator = gst_vaapi_video_allocator_new(priv->display, caps);
+    if (!priv->allocator)
+        goto error_create_allocator;
+
+    if (!gst_buffer_pool_config_has_option(config,
+            GST_BUFFER_POOL_OPTION_VAAPI_VIDEO_META))
+        goto error_no_vaapi_video_meta_option;
+
+    priv->has_video_meta = gst_buffer_pool_config_has_option(config,
+        GST_BUFFER_POOL_OPTION_VIDEO_META);
+
+    return GST_BUFFER_POOL_CLASS(gst_vaapi_video_buffer_pool_parent_class)->
+        set_config(pool, config);
+
+    /* ERRORS */
+error_invalid_config:
+    {
+        GST_ERROR("invalid config");
+        return FALSE;
+    }
+error_no_caps:
+    {
+        GST_ERROR("no caps in config");
+        return FALSE;
+    }
+error_create_allocator:
+    {
+        GST_ERROR("failed to create GstVaapiVideoAllocator object");
+        return FALSE;
+    }
+error_no_vaapi_video_meta_option:
+    {
+        GST_ERROR("no GstVaapiVideoMeta option");
+        return FALSE;
+    }
+}
+
+static GstFlowReturn
+gst_vaapi_video_buffer_pool_alloc_buffer(GstBufferPool *pool,
+    GstBuffer **out_buffer_ptr, GstBufferPoolAcquireParams *params)
+{
+    GstVaapiVideoBufferPoolPrivate * const priv =
+        GST_VAAPI_VIDEO_BUFFER_POOL(pool)->priv;
+    GstVaapiVideoMeta *meta;
+    GstMemory *mem;
+    GstBuffer *buffer;
+
+    if (!priv->allocator)
+        goto error_no_allocator;
+
+    meta = gst_vaapi_video_meta_new(priv->display);
+    if (!meta)
+        goto error_create_meta;
+
+    buffer = gst_vaapi_video_buffer_new(meta);
+    if (!buffer)
+        goto error_create_buffer;
+
+    mem = gst_vaapi_video_memory_new(priv->allocator, meta);
+    if (!mem)
+        goto error_create_memory;
+    gst_vaapi_video_meta_unref(meta);
+    gst_buffer_append_memory(buffer, mem);
+
+    if (priv->has_video_meta) {
+        GstVideoInfo * const vip =
+            &GST_VAAPI_VIDEO_ALLOCATOR_CAST(priv->allocator)->video_info;
+
+        gst_buffer_add_video_meta(buffer, 0, GST_VIDEO_INFO_FORMAT(vip),
+            GST_VIDEO_INFO_WIDTH(vip), GST_VIDEO_INFO_HEIGHT(vip));
+    }
+
+    *out_buffer_ptr = buffer;
+    return GST_FLOW_OK;
+
+    /* ERRORS */
+error_no_allocator:
+    {
+        GST_ERROR("no GstAllocator in buffer pool");
+        return GST_FLOW_ERROR;
+    }
+error_create_meta:
+    {
+        GST_ERROR("failed to allocate vaapi video meta");
+        return GST_FLOW_ERROR;
+    }
+error_create_buffer:
+    {
+        GST_ERROR("failed to create video buffer");
+        gst_vaapi_video_meta_unref(meta);
+        return GST_FLOW_ERROR;
+    }
+error_create_memory:
+    {
+        GST_ERROR("failed to create video memory");
+        gst_buffer_unref(buffer);
+        gst_vaapi_video_meta_unref(meta);
+        return GST_FLOW_ERROR;
+    }
+}
+
+static void
+gst_vaapi_video_buffer_pool_reset_buffer(GstBufferPool *pool, GstBuffer *buffer)
+{
+    GstVaapiVideoMeta * const meta = gst_buffer_get_vaapi_video_meta(buffer);
+
+    /* Release the underlying surface proxy */
+    gst_vaapi_video_meta_set_surface_proxy(meta, NULL);
+
+    GST_BUFFER_POOL_CLASS(gst_vaapi_video_buffer_pool_parent_class)->
+        reset_buffer(pool, buffer);
+}
+
+static void
+gst_vaapi_video_buffer_pool_class_init(GstVaapiVideoBufferPoolClass *klass)
+{
+    GObjectClass * const object_class = G_OBJECT_CLASS(klass);
+    GstBufferPoolClass * const pool_class = GST_BUFFER_POOL_CLASS(klass);
+
+    GST_DEBUG_CATEGORY_INIT(gst_debug_vaapivideopool,
+        "vaapivideopool", 0, "VA-API video pool");
+
+    g_type_class_add_private(klass, sizeof(GstVaapiVideoBufferPoolPrivate));
+
+    object_class->finalize      = gst_vaapi_video_buffer_pool_finalize;
+    object_class->set_property  = gst_vaapi_video_buffer_pool_set_property;
+    object_class->get_property  = gst_vaapi_video_buffer_pool_get_property;
+    pool_class->get_options     = gst_vaapi_video_buffer_pool_get_options;
+    pool_class->set_config      = gst_vaapi_video_buffer_pool_set_config;
+    pool_class->alloc_buffer    = gst_vaapi_video_buffer_pool_alloc_buffer;
+    pool_class->reset_buffer    = gst_vaapi_video_buffer_pool_reset_buffer;
+
+    /**
+     * GstVaapiVideoBufferPool:display:
+     *
+     * The #GstVaapiDisplay this object is bound to.
+     */
+    g_object_class_install_property
+        (object_class,
+         PROP_DISPLAY,
+         g_param_spec_object("display",
+                             "Display",
+                             "The GstVaapiDisplay to use for this video pool",
+                             GST_VAAPI_TYPE_DISPLAY,
+                             G_PARAM_READWRITE|G_PARAM_CONSTRUCT_ONLY));
+}
+
+static void
+gst_vaapi_video_buffer_pool_init(GstVaapiVideoBufferPool *pool)
+{
+    GstVaapiVideoBufferPoolPrivate * const priv =
+        GST_VAAPI_VIDEO_BUFFER_POOL_GET_PRIVATE(pool);
+
+    pool->priv = priv;
+}
+
+GstBufferPool *
+gst_vaapi_video_buffer_pool_new(GstVaapiDisplay *display)
+{
+    return g_object_new(GST_VAAPI_TYPE_VIDEO_BUFFER_POOL,
+        "display", display, NULL);
+}
diff --git a/gst/vaapi/gstvaapivideobufferpool.h b/gst/vaapi/gstvaapivideobufferpool.h
new file mode 100644 (file)
index 0000000..5b391e7
--- /dev/null
@@ -0,0 +1,91 @@
+/*
+ *  gstvaapivideobufferpool.h - Gstreamer/VA video buffer pool
+ *
+ *  Copyright (C) 2013 Intel Corporation
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1
+ *  of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free
+ *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ *  Boston, MA 02110-1301 USA
+ */
+
+#ifndef GST_VAAPI_VIDEO_BUFFER_POOL_H
+#define GST_VAAPI_VIDEO_BUFFER_POOL_H
+
+#include <gst/video/gstvideopool.h>
+#include <gst/vaapi/gstvaapidisplay.h>
+
+G_BEGIN_DECLS
+
+#define GST_VAAPI_TYPE_VIDEO_BUFFER_POOL \
+    (gst_vaapi_video_buffer_pool_get_type())
+
+#define GST_VAAPI_VIDEO_BUFFER_POOL(obj)                \
+    (G_TYPE_CHECK_INSTANCE_CAST((obj),                  \
+        GST_VAAPI_TYPE_VIDEO_BUFFER_POOL,               \
+        GstVaapiVideoBufferPool))
+
+#define GST_VAAPI_VIDEO_BUFFER_POOL_CLASS(klass)        \
+    (G_TYPE_CHECK_CLASS_CAST((klass),                   \
+        GST_VAAPI_TYPE_VIDEO_BUFFER_POOL,               \
+        GstVaapiVideoBufferPoolClass))
+
+#define GST_VAAPI_IS_VIDEO_BUFFER_POOL(obj) \
+    (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_VIDEO_BUFFER_POOL))
+
+#define GST_VAAPI_IS_VIDEO_BUFFER_POOL_CLASS(klass) \
+    (G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_VIDEO_BUFFER_POOL))
+
+typedef struct _GstVaapiVideoBufferPool         GstVaapiVideoBufferPool;
+typedef struct _GstVaapiVideoBufferPoolClass    GstVaapiVideoBufferPoolClass;
+typedef struct _GstVaapiVideoBufferPoolPrivate  GstVaapiVideoBufferPoolPrivate;
+
+/**
+ * GST_BUFFER_POOL_OPTION_VAAPI_VIDEO_META:
+ *
+ * An option that can be activated on bufferpool to request vaapi
+ * video metadata on buffers from the pool.
+ */
+#define GST_BUFFER_POOL_OPTION_VAAPI_VIDEO_META "GstBufferPoolOptionVaapiVideoMeta"
+
+/**
+ * GstVaapiVideoBufferPool:
+ *
+ * A VA video buffer pool object.
+ */
+struct _GstVaapiVideoBufferPool {
+    GstBufferPool parent_instance;
+
+    /*< private >*/
+    GstVaapiVideoBufferPoolPrivate *priv;
+};
+
+/**
+ * GstVaapiVideoBufferPoolClass:
+ *
+ * A VA video buffer pool class.
+ */
+struct _GstVaapiVideoBufferPoolClass {
+    GstBufferPoolClass parent_class;
+};
+
+GType
+gst_vaapi_video_buffer_pool_get_type(void) G_GNUC_CONST;
+
+G_GNUC_INTERNAL
+GstBufferPool *
+gst_vaapi_video_buffer_pool_new(GstVaapiDisplay *display) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* GST_VAAPI_VIDEO_BUFFER_POOL_H */
diff --git a/gst/vaapi/gstvaapivideomemory.c b/gst/vaapi/gstvaapivideomemory.c
new file mode 100644 (file)
index 0000000..d016c12
--- /dev/null
@@ -0,0 +1,177 @@
+/*
+ *  gstvaapivideomemory.c - Gstreamer/VA video memory
+ *
+ *  Copyright (C) 2013 Intel Corporation
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1
+ *  of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free
+ *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ *  Boston, MA 02110-1301 USA
+ */
+
+#include "gst/vaapi/sysdeps.h"
+#include "gstvaapivideomemory.h"
+
+GST_DEBUG_CATEGORY_STATIC(gst_debug_vaapivideomemory);
+#define GST_CAT_DEFAULT gst_debug_vaapivideomemory
+
+/* ------------------------------------------------------------------------ */
+/* --- GstVaapiVideoMemory                                              --- */
+/* ------------------------------------------------------------------------ */
+
+GstMemory *
+gst_vaapi_video_memory_new(GstAllocator *base_allocator,
+    GstVaapiVideoMeta *meta)
+{
+    GstVaapiVideoAllocator * const allocator =
+        GST_VAAPI_VIDEO_ALLOCATOR_CAST(base_allocator);
+    const GstVideoInfo *vip;
+    GstVaapiVideoMemory *mem;
+
+    mem = g_slice_new(GstVaapiVideoMemory);
+    if (!mem)
+        return NULL;
+
+    vip = &allocator->video_info;
+    gst_memory_init(&mem->parent_instance, 0, base_allocator, NULL,
+        GST_VIDEO_INFO_SIZE(vip), 0, 0, GST_VIDEO_INFO_SIZE(vip));
+
+    mem->meta = gst_vaapi_video_meta_ref(meta);
+    return GST_MEMORY_CAST(mem);
+}
+
+static void
+gst_vaapi_video_memory_free(GstVaapiVideoMemory *mem)
+{
+    gst_vaapi_video_meta_unref(mem->meta);
+    g_slice_free(GstVaapiVideoMemory, mem);
+}
+
+static gpointer
+gst_vaapi_video_memory_map(GstVaapiVideoMemory *mem, gsize maxsize, guint flags)
+{
+    GST_FIXME("unimplemented GstVaapiVideoAllocator::mem_map() hook");
+    return NULL;
+}
+
+static void
+gst_vaapi_video_memory_unmap(GstVaapiVideoMemory *mem)
+{
+    GST_FIXME("unimplemented GstVaapiVideoAllocator::mem_unmap() hook");
+}
+
+static GstVaapiVideoMemory *
+gst_vaapi_video_memory_copy(GstVaapiVideoMemory *mem,
+    gssize offset, gssize size)
+{
+    GST_FIXME("unimplemented GstVaapiVideoAllocator::mem_copy() hook");
+    return NULL;
+}
+
+static GstVaapiVideoMemory *
+gst_vaapi_video_memory_share(GstVaapiVideoMemory *mem,
+    gssize offset, gssize size)
+{
+    GST_FIXME("unimplemented GstVaapiVideoAllocator::mem_share() hook");
+    return NULL;
+}
+
+static gboolean
+gst_vaapi_video_memory_is_span(GstVaapiVideoMemory *mem1,
+    GstVaapiVideoMemory *mem2, gsize *offset_ptr)
+{
+    GST_FIXME("unimplemented GstVaapiVideoAllocator::mem_is_span() hook");
+    return FALSE;
+}
+
+/* ------------------------------------------------------------------------ */
+/* --- GstVaapiVideoAllocator                                           --- */
+/* ------------------------------------------------------------------------ */
+
+#define GST_VAAPI_VIDEO_ALLOCATOR_CLASS(klass)  \
+    (G_TYPE_CHECK_CLASS_CAST((klass),           \
+        GST_VAAPI_TYPE_VIDEO_ALLOCATOR,         \
+        GstVaapiVideoAllocatorClass))
+
+#define GST_VAAPI_IS_VIDEO_ALLOCATOR_CLASS(klass) \
+    (G_TYPE_CHECK_CLASS_TYPE((klass), GST_VAAPI_TYPE_VIDEO_ALLOCATOR))
+
+G_DEFINE_TYPE(GstVaapiVideoAllocator,
+              gst_vaapi_video_allocator,
+              GST_TYPE_ALLOCATOR)
+
+static GstMemory *
+gst_vaapi_video_allocator_alloc(GstAllocator *allocator, gsize size,
+    GstAllocationParams *params)
+{
+    g_warning("use gst_vaapi_video_memory_new() to allocate from "
+        "GstVaapiVideoMemory allocator");
+
+    return NULL;
+}
+
+static void
+gst_vaapi_video_allocator_free(GstAllocator *allocator, GstMemory *mem)
+{
+    gst_vaapi_video_memory_free(GST_VAAPI_VIDEO_MEMORY_CAST(mem));
+}
+
+static void
+gst_vaapi_video_allocator_class_init(GstVaapiVideoAllocatorClass *klass)
+{
+    GstAllocatorClass * const allocator_class = GST_ALLOCATOR_CLASS(klass);
+
+    GST_DEBUG_CATEGORY_INIT(gst_debug_vaapivideomemory,
+        "vaapivideomemory", 0, "VA-API video memory allocator");
+
+    allocator_class->alloc      = gst_vaapi_video_allocator_alloc;
+    allocator_class->free       = gst_vaapi_video_allocator_free;
+}
+
+static void
+gst_vaapi_video_allocator_init(GstVaapiVideoAllocator *allocator)
+{
+    GstAllocator * const base_allocator = GST_ALLOCATOR_CAST(allocator);
+
+    base_allocator->mem_type = GST_VAAPI_VIDEO_MEMORY_NAME;
+    base_allocator->mem_map = (GstMemoryMapFunction)
+        gst_vaapi_video_memory_map;
+    base_allocator->mem_unmap = (GstMemoryUnmapFunction)
+        gst_vaapi_video_memory_unmap;
+    base_allocator->mem_copy = (GstMemoryCopyFunction)
+        gst_vaapi_video_memory_copy;
+    base_allocator->mem_share = (GstMemoryShareFunction)
+        gst_vaapi_video_memory_share;
+    base_allocator->mem_is_span = (GstMemoryIsSpanFunction)
+        gst_vaapi_video_memory_is_span;
+}
+
+GstAllocator *
+gst_vaapi_video_allocator_new(GstVaapiDisplay *display, GstCaps *caps)
+{
+    GstVaapiVideoAllocator *allocator;
+    GstVideoInfo *vip;
+
+    g_return_val_if_fail(GST_VAAPI_IS_DISPLAY(display), NULL);
+    g_return_val_if_fail(GST_IS_CAPS(caps), NULL);
+
+    allocator = g_object_new(GST_VAAPI_TYPE_VIDEO_ALLOCATOR, NULL);
+    if (!allocator)
+        return NULL;
+
+    vip = &allocator->video_info;
+    gst_video_info_init(vip);
+    gst_video_info_from_caps(vip, caps);
+
+    return GST_ALLOCATOR_CAST(allocator);
+}
diff --git a/gst/vaapi/gstvaapivideomemory.h b/gst/vaapi/gstvaapivideomemory.h
new file mode 100644 (file)
index 0000000..447dd93
--- /dev/null
@@ -0,0 +1,113 @@
+/*
+ *  gstvaapivideomemory.h - Gstreamer/VA video memory
+ *
+ *  Copyright (C) 2013 Intel Corporation
+ *
+ *  This library is free software; you can redistribute it and/or
+ *  modify it under the terms of the GNU Lesser General Public License
+ *  as published by the Free Software Foundation; either version 2.1
+ *  of the License, or (at your option) any later version.
+ *
+ *  This library is distributed in the hope that it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
+ *  Lesser General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public
+ *  License along with this library; if not, write to the Free
+ *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ *  Boston, MA 02110-1301 USA
+ */
+
+#ifndef GST_VAAPI_VIDEO_MEMORY_H
+#define GST_VAAPI_VIDEO_MEMORY_H
+
+#include <gst/gstallocator.h>
+#include <gst/video/video-info.h>
+#include <gst/vaapi/gstvaapidisplay.h>
+#include "gstvaapivideometa.h"
+
+G_BEGIN_DECLS
+
+typedef struct _GstVaapiVideoMemory             GstVaapiVideoMemory;
+typedef struct _GstVaapiVideoAllocator          GstVaapiVideoAllocator;
+typedef struct _GstVaapiVideoAllocatorClass     GstVaapiVideoAllocatorClass;
+
+/* ------------------------------------------------------------------------ */
+/* --- GstVaapiVideoMemory                                              --- */
+/* ------------------------------------------------------------------------ */
+
+#define GST_VAAPI_VIDEO_MEMORY_CAST(mem) \
+    ((GstVaapiVideoMemory *)(mem))
+
+#define GST_VAAPI_VIDEO_MEMORY_NAME             "GstVaapiVideoMemory"
+
+/**
+ * GstVaapiVideoMemory:
+ *
+ * A VA video memory object holder, including VA surfaces, images and
+ * proxies.
+ */
+struct _GstVaapiVideoMemory {
+    GstMemory parent_instance;
+
+    /*< private >*/
+    GstVaapiVideoMeta  *meta;
+};
+
+G_GNUC_INTERNAL
+GstMemory *
+gst_vaapi_video_memory_new(GstAllocator *allocator, GstVaapiVideoMeta *meta);
+
+/* ------------------------------------------------------------------------ */
+/* --- GstVaapiVideoAllocator                                           --- */
+/* ------------------------------------------------------------------------ */
+
+#define GST_VAAPI_VIDEO_ALLOCATOR_CAST(allocator) \
+    ((GstVaapiVideoAllocator *)(allocator))
+
+#define GST_VAAPI_TYPE_VIDEO_ALLOCATOR \
+    (gst_vaapi_video_allocator_get_type())
+
+#define GST_VAAPI_VIDEO_ALLOCATOR(obj)          \
+    (G_TYPE_CHECK_INSTANCE_CAST((obj),          \
+        GST_VAAPI_TYPE_VIDEO_ALLOCATOR,         \
+        GstVaapiVideoAllocator))
+
+#define GST_VAAPI_IS_VIDEO_ALLOCATOR(obj) \
+    (G_TYPE_CHECK_INSTANCE_TYPE((obj), GST_VAAPI_TYPE_VIDEO_ALLOCATOR))
+
+#define GST_VAAPI_VIDEO_ALLOCATOR_NAME          "GstVaapiVideoAllocator"
+
+/**
+ * GstVaapiVideoAllocator:
+ *
+ * A VA video memory allocator object.
+ */
+struct _GstVaapiVideoAllocator {
+    GstAllocator parent_instance;
+
+    /*< private >*/
+    GstVideoInfo        video_info;
+};
+
+/**
+ * GstVaapiVideoAllocatorClass:
+ *
+ * A VA video memory allocator class.
+ */
+struct _GstVaapiVideoAllocatorClass {
+    GstAllocatorClass parent_class;
+};
+
+G_GNUC_INTERNAL
+GType
+gst_vaapi_video_allocator_get_type(void) G_GNUC_CONST;
+
+G_GNUC_INTERNAL
+GstAllocator *
+gst_vaapi_video_allocator_new(GstVaapiDisplay *display, GstCaps *caps);
+
+G_END_DECLS
+
+#endif /* GST_VAAPI_VIDEO_MEMORY_H */