summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorHyunjun Ko <zzoon@igalia.com>2016-09-22 16:33:06 +0900
committerVíctor Manuel Jáquez Leal <victorx.jaquez@intel.com>2016-09-22 14:19:05 +0200
commitf974c91d73b669e90cfaeed095c8e6f7dbee9103 (patch)
tree89bdfa8dd9704d6b251f3fb843055525cd4959f0
parent0fae277d34cd2db89c9c7be45f41684f1040052f (diff)
libs: vaapitexturemap: implement GstVaapiTextureMap
Implement GstVaapiTextureMap object, which caches VAAPI textures, so them can be reused. Internally it is a hash table. Note that it is GstObject based rather than GstVaapiObject, as part of the future converstion to GstObject of most of the code. https://bugzilla.gnome.org/show_bug.cgi?id=769293 Signed-off-by: Víctor Manuel Jáquez Leal <victorx.jaquez@intel.com>
-rw-r--r--gst-libs/gst/vaapi/Makefile.am2
-rw-r--r--gst-libs/gst/vaapi/gstvaapitexturemap.c163
-rw-r--r--gst-libs/gst/vaapi/gstvaapitexturemap.h58
3 files changed, 223 insertions, 0 deletions
diff --git a/gst-libs/gst/vaapi/Makefile.am b/gst-libs/gst/vaapi/Makefile.am
index fc97c944..43a7772a 100644
--- a/gst-libs/gst/vaapi/Makefile.am
+++ b/gst-libs/gst/vaapi/Makefile.am
@@ -73,6 +73,7 @@ libgstvaapi_source_c = \
gstvaapisurfacepool.c \
gstvaapisurfaceproxy.c \
gstvaapitexture.c \
+ gstvaapitexturemap.c \
gstvaapiutils.c \
gstvaapiutils_core.c \
gstvaapiutils_h264.c \
@@ -105,6 +106,7 @@ libgstvaapi_source_h = \
gstvaapisurfacepool.h \
gstvaapisurfaceproxy.h \
gstvaapitexture.h \
+ gstvaapitexturemap.h \
gstvaapitypes.h \
gstvaapiutils_h264.h \
gstvaapiutils_h265.h \
diff --git a/gst-libs/gst/vaapi/gstvaapitexturemap.c b/gst-libs/gst/vaapi/gstvaapitexturemap.c
new file mode 100644
index 00000000..cb832dad
--- /dev/null
+++ b/gst-libs/gst/vaapi/gstvaapitexturemap.c
@@ -0,0 +1,163 @@
+/*
+ * gstvaapitexture.c - VA texture Hash map
+ *
+ * Copyright (C) 2016 Intel Corporation
+ * Copyright (C) 2016 Igalia S.L.
+ *
+ * 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
+ */
+
+/**
+ * SECTION:gstvaapitexturemap
+ * @short_description: VA/GLX/EGL texture hash map abstraction
+ */
+
+#include "gstvaapitexturemap.h"
+
+#define DEBUG 1
+#include "gstvaapidebug.h"
+
+/**
+ * GstVaapiTextureMap:
+ *
+ * Base class for API-dependent texture map.
+ */
+struct _GstVaapiTextureMap {
+ GstObject parent_instance;
+
+ /*< private >*/
+ GHashTable *texture_map;
+};
+
+/**
+ * GstVaapiTextureMapClass:
+ *
+ * Base class for API-dependent texture map.
+ */
+struct _GstVaapiTextureMapClass {
+ GstObjectClass parent_class;
+};
+
+#define MAX_NUM_TEXTURE 10
+
+G_DEFINE_TYPE (GstVaapiTextureMap, gst_vaapi_texture_map, GST_TYPE_OBJECT);
+
+static void
+gst_vaapi_texture_map_init (GstVaapiTextureMap * map)
+{
+ map->texture_map =
+ g_hash_table_new_full (g_direct_hash, g_direct_equal, NULL,
+ (GDestroyNotify) gst_vaapi_texture_unref);
+}
+
+static void
+gst_vaapi_texture_map_finalize (GObject * object)
+{
+ GstVaapiTextureMap *map = GST_VAAPI_TEXTURE_MAP (object);
+
+ if (map->texture_map) {
+ g_hash_table_remove_all (map->texture_map);
+ g_hash_table_destroy (map->texture_map);
+ }
+
+ G_OBJECT_CLASS (gst_vaapi_texture_map_parent_class)->finalize (object);
+}
+
+static void
+gst_vaapi_texture_map_class_init (GstVaapiTextureMapClass * klass)
+{
+ GObjectClass *const object_class = G_OBJECT_CLASS (klass);
+
+ object_class->finalize = gst_vaapi_texture_map_finalize;
+}
+
+/**
+ * gst_vaapi_texture_map_new:
+ *
+ * Creates a texture hash map.
+ *
+ * Return value: the newly created #GstVaapiTextureMap object
+ */
+GstVaapiTextureMap *
+gst_vaapi_texture_map_new (void)
+{
+ GstVaapiTextureMap *map;
+
+ map = g_object_new (GST_TYPE_VAAPI_TEXTURE_MAP, NULL);
+ return map;
+}
+
+/**
+ * gst_vaapi_texture_map_add:
+ * @map: a #GstVaapiTextureMap instance
+ * @texture: a #GstVaapiTexture instance to add
+ * @id: the id of the GLTexture
+ *
+ * Adds @texture into the @map table.
+ *
+ * Returns: %TRUE if @texture was inserted correctly.
+ **/
+gboolean
+gst_vaapi_texture_map_add (GstVaapiTextureMap * map, GstVaapiTexture * texture,
+ guint id)
+{
+ g_return_val_if_fail (map != NULL, FALSE);
+ g_return_val_if_fail (map->texture_map != NULL, FALSE);
+ g_return_val_if_fail (texture != NULL, FALSE);
+
+ if (g_hash_table_size (map->texture_map) > MAX_NUM_TEXTURE) {
+ GST_WARNING ("Texture map is full");
+ return FALSE;
+ }
+
+ g_hash_table_insert (map->texture_map, GUINT_TO_POINTER (id), texture);
+
+ return TRUE;
+}
+
+/**
+ * gst_vaapi_texture_map_lookup:
+ * @map: a #GstVaapiTextureMap instance
+ * @id: the id of the GLTexture
+ *
+ * Search for the #GstVaapiTexture associated with the GLTexture @id
+ * in the @map.
+ *
+ * Returns: a pointer to #GstVaapiTexture if found; otherwise %NULL.
+ **/
+GstVaapiTexture *
+gst_vaapi_texture_map_lookup (GstVaapiTextureMap * map, guint id)
+{
+ g_return_val_if_fail (map != NULL, NULL);
+ g_return_val_if_fail (map->texture_map != NULL, NULL);
+
+ return g_hash_table_lookup (map->texture_map, GUINT_TO_POINTER (id));
+}
+
+/**
+ * gst_vaapi_texture_map_reset:
+ * @map: a #GstVaapiTextureMap instance
+ *
+ * Removes all the #GstVaapiTexture in the @map.
+ **/
+void
+gst_vaapi_texture_map_reset (GstVaapiTextureMap * map)
+{
+ g_return_if_fail (map != NULL);
+ g_return_if_fail (map->texture_map != NULL);
+
+ g_hash_table_remove_all (map->texture_map);
+}
diff --git a/gst-libs/gst/vaapi/gstvaapitexturemap.h b/gst-libs/gst/vaapi/gstvaapitexturemap.h
new file mode 100644
index 00000000..e74fedf8
--- /dev/null
+++ b/gst-libs/gst/vaapi/gstvaapitexturemap.h
@@ -0,0 +1,58 @@
+/*
+ * gstvaapitexturemap.h - VA texture Hash map
+ *
+ * Copyright (C) 2016 Intel Corporation
+ * Copyright (C) 2016 Igalia S.L.
+ *
+ * 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_TEXTURE_MAP_H
+#define GST_VAAPI_TEXTURE_MAP_H
+
+#include <gst/vaapi/gstvaapitexture.h>
+
+G_BEGIN_DECLS
+
+typedef struct _GstVaapiTextureMap GstVaapiTextureMap;
+typedef struct _GstVaapiTextureMapClass GstVaapiTextureMapClass;
+
+#define GST_TYPE_VAAPI_TEXTURE_MAP \
+ (gst_vaapi_texture_map_get_type ())
+#define GST_VAAPI_TEXTURE_MAP(obj) \
+ (G_TYPE_CHECK_INSTANCE_CAST ((obj), GST_TYPE_VAAPI_TEXTURE_MAP, GstVaapiTextureMap))
+
+GstVaapiTextureMap *
+gst_vaapi_texture_map_new (void);
+
+gboolean
+gst_vaapi_texture_map_add (GstVaapiTextureMap * map,
+ GstVaapiTexture * texture,
+ guint id);
+
+GstVaapiTexture *
+gst_vaapi_texture_map_lookup (GstVaapiTextureMap * map,
+ guint id);
+
+void
+gst_vaapi_texture_map_reset (GstVaapiTextureMap * map);
+
+GType
+gst_vaapi_texture_map_get_type (void) G_GNUC_CONST;
+
+G_END_DECLS
+
+#endif /* GST_VAAPI_TEXTURE_MAP_H */