summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMatthew Waters <matthew@centricular.com>2015-11-02 23:12:19 +1100
committerMatthew Waters <matthew@centricular.com>2015-11-11 00:19:25 +1100
commit0b98ed32ce9db48089787f32c13c1a3db3ac36f3 (patch)
tree6d8ec906ab60504e2b0c92349bdb600e4b945d0e
parentff6d1a2a25b247688f38e117782a6b43d525706a (diff)
videometa: add GstVideoAffineTransformationMeta
Adds a simple 4x4 affine transformations meta for passing arbitrary transformations on buffers. Based on patch by Matthieu Bouron https://bugzilla.gnome.org/show_bug.cgi?id=731791
-rw-r--r--docs/libs/gst-plugins-base-libs-docs.sgml1
-rw-r--r--docs/libs/gst-plugins-base-libs-sections.txt12
-rw-r--r--gst-libs/gst/video/Makefile.am2
-rw-r--r--gst-libs/gst/video/gstvideoaffinetransformationmeta.c152
-rw-r--r--gst-libs/gst/video/gstvideoaffinetransformationmeta.h70
-rw-r--r--win32/common/libgstvideo.def4
6 files changed, 241 insertions, 0 deletions
diff --git a/docs/libs/gst-plugins-base-libs-docs.sgml b/docs/libs/gst-plugins-base-libs-docs.sgml
index 7767abf96..640fba007 100644
--- a/docs/libs/gst-plugins-base-libs-docs.sgml
+++ b/docs/libs/gst-plugins-base-libs-docs.sgml
@@ -197,6 +197,7 @@
</para>
<xi:include href="xml/gstvideo.xml" />
<xi:include href="xml/gstvideometa.xml" />
+ <xi:include href="xml/gstvideoaffinetransformationmeta.xml" />
<xi:include href="xml/gstvideooverlaycomposition.xml" />
<xi:include href="xml/gstvideofilter.xml" />
<xi:include href="xml/gstvideodither.xml" />
diff --git a/docs/libs/gst-plugins-base-libs-sections.txt b/docs/libs/gst-plugins-base-libs-sections.txt
index e437882f0..fd1e3811c 100644
--- a/docs/libs/gst-plugins-base-libs-sections.txt
+++ b/docs/libs/gst-plugins-base-libs-sections.txt
@@ -2626,6 +2626,18 @@ gst_video_gl_texture_upload_meta_get_info
</SECTION>
<SECTION>
+<FILE>gstvideoaffinetransformationmeta</FILE>
+<INCLUDE>gst/video/gstvideoaffinetransformationmeta.h</INCLUDE>
+GstVideoAffineTransformationMeta
+gst_buffer_add_video_affine_transformation_meta
+gst_buffer_get_video_affine_transformation_meta
+gst_video_affine_transformation_meta_apply_matrix
+<SUBSECTION Standard>
+gst_video_affine_transformation_meta_api_get_type
+gst_video_affine_transformation_meta_get_info
+</SECTION>
+
+<SECTION>
<FILE>gstvideooverlaycomposition</FILE>
<INCLUDE>gst/video/video-overlay-composition.h</INCLUDE>
<SUBSECTION composition>
diff --git a/gst-libs/gst/video/Makefile.am b/gst-libs/gst/video/Makefile.am
index 5d31fa1e8..c26be81f1 100644
--- a/gst-libs/gst/video/Makefile.am
+++ b/gst-libs/gst/video/Makefile.am
@@ -35,6 +35,7 @@ libgstvideo_@GST_API_VERSION@_la_SOURCES = \
gstvideosink.c \
gstvideofilter.c \
convertframe.c \
+ gstvideoaffinetransformationmeta.c \
gstvideometa.c \
gstvideopool.c \
videoorientation.c \
@@ -69,6 +70,7 @@ libgstvideo_@GST_API_VERSION@include_HEADERS = \
gstvideosink.h \
gstvideofilter.h \
gstvideometa.h \
+ gstvideoaffinetransformationmeta.h \
gstvideopool.h \
videoorientation.h \
videooverlay.h \
diff --git a/gst-libs/gst/video/gstvideoaffinetransformationmeta.c b/gst-libs/gst/video/gstvideoaffinetransformationmeta.c
new file mode 100644
index 000000000..c485310b5
--- /dev/null
+++ b/gst-libs/gst/video/gstvideoaffinetransformationmeta.c
@@ -0,0 +1,152 @@
+/* GStreamer
+ * Copyright (C) <2014> Collabora Ltd.
+ * Author: Matthieu Bouron <matthieu.bouron@gmail.com>
+ * Copyright (C) 2015, Matthew Waters <matthew@centricular.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#include "gstvideoaffinetransformationmeta.h"
+
+#include <string.h>
+
+GType
+gst_video_affine_transformation_meta_api_get_type (void)
+{
+ static volatile GType type = 0;
+ static const gchar *tags[] =
+ { GST_META_TAG_VIDEO_STR, GST_META_TAG_VIDEO_ORIENTATION_STR,
+ GST_META_TAG_VIDEO_ORIENTATION_STR, NULL
+ };
+
+ if (g_once_init_enter (&type)) {
+ GType _type =
+ gst_meta_api_type_register ("GstVideoAffineTransformationAPI", tags);
+ g_once_init_leave (&type, _type);
+ }
+ return type;
+}
+
+static gboolean
+gst_video_affine_transformation_meta_transform (GstBuffer * dest,
+ GstMeta * meta, GstBuffer * buffer, GQuark type, gpointer data)
+{
+ GstVideoAffineTransformationMeta *dmeta, *smeta;
+
+ smeta = (GstVideoAffineTransformationMeta *) meta;
+
+ if (GST_META_TRANSFORM_IS_COPY (type)) {
+ dmeta =
+ (GstVideoAffineTransformationMeta *) gst_buffer_add_meta (dest,
+ GST_VIDEO_AFFINE_TRANSFORMATION_META_INFO, NULL);
+
+ if (!dmeta)
+ return FALSE;
+
+ memcpy (dmeta->matrix, smeta->matrix, sizeof (dmeta->matrix[0]) * 16);
+ }
+ return TRUE;
+}
+
+static gboolean
+gst_video_affine_transformation_meta_init (GstMeta * meta, gpointer params,
+ GstBuffer * buffer)
+{
+ GstVideoAffineTransformationMeta *af_meta =
+ (GstVideoAffineTransformationMeta *) meta;
+ gfloat matrix[] = {
+ 1.0f, 0.0f, 0.0f, 0.0f,
+ 0.0f, 1.0f, 0.0f, 0.0f,
+ 0.0f, 0.0f, 1.0f, 0.0f,
+ 0.0f, 0.0f, 0.0f, 1.0f
+ };
+
+ memcpy (af_meta->matrix, matrix, sizeof (matrix[0]) * 16);
+
+ return TRUE;
+}
+
+const GstMetaInfo *
+gst_video_affine_transformation_meta_get_info (void)
+{
+ static const GstMetaInfo *info = NULL;
+
+ if (g_once_init_enter (&info)) {
+ const GstMetaInfo *meta =
+ gst_meta_register (GST_VIDEO_AFFINE_TRANSFORMATION_META_API_TYPE,
+ "GstVideoAffineTransformationMeta",
+ sizeof (GstVideoAffineTransformationMeta),
+ gst_video_affine_transformation_meta_init,
+ NULL,
+ gst_video_affine_transformation_meta_transform);
+ g_once_init_leave (&info, meta);
+ }
+ return info;
+}
+
+/**
+ * gst_buffer_add_video_affine_transformation_meta
+ * @buffer: a #GstBuffer
+ *
+ * Attaches GstVideoAffineTransformationMeta metadata to @buffer with
+ * the given parameters.
+ *
+ * Returns: the #GstVideoAffineTransformationMeta on @buffer.
+ *
+ * Since: 1.8
+ */
+GstVideoAffineTransformationMeta *
+gst_buffer_add_video_affine_transformation_meta (GstBuffer * buffer)
+{
+ GstVideoAffineTransformationMeta *meta;
+
+ g_return_val_if_fail (buffer != NULL, NULL);
+
+ meta =
+ (GstVideoAffineTransformationMeta *) gst_buffer_add_meta (buffer,
+ GST_VIDEO_AFFINE_TRANSFORMATION_META_INFO, NULL);
+
+ if (!meta)
+ return NULL;
+
+ return meta;
+}
+
+/**
+ * gst_video_affine_transformation_meta_apply_matrix:
+ * @meta: a #GstVideoAffineTransformationMeta
+ * @matrix: a 4x4 transformation matrix to be applied
+ *
+ * Apply a transformation using the given 4x4 transformation matrix
+ *
+ * Since: 1.8
+ */
+void gst_video_affine_transformation_meta_apply_matrix
+ (GstVideoAffineTransformationMeta * meta, const gfloat matrix[16])
+{
+ gfloat res[16] = { 0.0f };
+ int i, j, k;
+
+ for (i = 0; i < 4; i++) {
+ for (j = 0; j < 4; j++) {
+ for (k = 0; k < 4; k++) {
+ res[i + (j * 4)] += meta->matrix[i + (k * 4)] * matrix[k + (j * 4)];
+ }
+ }
+ }
+
+ memcpy (meta->matrix, res, sizeof (meta->matrix[0]) * 16);
+}
diff --git a/gst-libs/gst/video/gstvideoaffinetransformationmeta.h b/gst-libs/gst/video/gstvideoaffinetransformationmeta.h
new file mode 100644
index 000000000..3838a01da
--- /dev/null
+++ b/gst-libs/gst/video/gstvideoaffinetransformationmeta.h
@@ -0,0 +1,70 @@
+/* GStreamer
+ * Copyright (C) Collabora Ltd.
+ * Author: Matthieu Bouron <matthieu.bouron@collabora.com>
+ * Copyright (C) 2015, Matthew Waters <matthew@centricular.com>
+ *
+ * This library is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU Library General Public
+ * License as published by the Free Software Foundation; either
+ * version 2 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
+ * Library General Public License for more details.
+ *
+ * You should have received a copy of the GNU Library General Public
+ * License along with this library; if not, write to the
+ * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
+ * Boston, MA 02110-1301, USA.
+ */
+
+#ifndef __GST_VIDEO_AFFINE_TRANSFORMATION_META_H__
+#define __GST_VIDEO_AFFINE_TRANSFORMATION_META_H__
+
+#include <gst/gst.h>
+#include <gst/video/video.h>
+
+G_BEGIN_DECLS
+
+#define GST_VIDEO_AFFINE_TRANSFORMATION_META_API_TYPE (gst_video_affine_transformation_meta_api_get_type())
+#define GST_VIDEO_AFFINE_TRANSFORMATION_META_INFO (gst_video_affine_transformation_meta_get_info())
+
+typedef struct _GstVideoAffineTransformationMeta GstVideoAffineTransformationMeta;
+typedef gboolean (*GstVideoAffineTransformationGetMatrix) (GstVideoAffineTransformationMeta * meta, gfloat * matrix);
+
+#define GST_CAPS_FEATURE_META_GST_VIDEO_AFFINE_TRANSFORMATION_META "meta:GstVideoAffineTransformation"
+#define GST_BUFFER_POOL_OPTION_VIDEO_AFFINE_TRANSFORMATION_META "GstBufferPoolOptionVideoAffineTransformation"
+
+/**
+ * GstVideoAffineTransformation:
+ * @meta: parent #GstMeta
+ * @matrix: the column-major 4x4 transformation matrix
+ *
+ * Extra buffer metadata for performing an affine transformation using a 4x4
+ * matrix. The transformation matrix can be composed with
+ * gst_video_affine_transformation_meta_apply_matrix().
+ *
+ * Since: 1.8
+ */
+
+struct _GstVideoAffineTransformationMeta
+{
+ GstMeta meta;
+
+ gfloat matrix[16];
+};
+
+GType gst_video_affine_transformation_meta_api_get_type (void);
+const GstMetaInfo *gst_video_affine_transformation_meta_get_info (void);
+
+#define gst_buffer_get_video_affine_transformation_meta(b) \
+ ((GstVideoAffineTransformationMeta *)gst_buffer_get_meta((b),GST_VIDEO_AFFINE_TRANSFORMATION_META_API_TYPE))
+GstVideoAffineTransformationMeta *gst_buffer_add_video_affine_transformation_meta (GstBuffer * buffer);
+
+void gst_video_affine_transformation_meta_apply_matrix (GstVideoAffineTransformationMeta * meta,
+ const gfloat matrix[16]);
+
+G_END_DECLS
+
+#endif /* __GST_VIDEO_AFFINE_TRANSFORMATION_META_H__ */
diff --git a/win32/common/libgstvideo.def b/win32/common/libgstvideo.def
index 39b031f3a..7b25d994e 100644
--- a/win32/common/libgstvideo.def
+++ b/win32/common/libgstvideo.def
@@ -1,5 +1,6 @@
EXPORTS
_gst_video_decoder_error
+ gst_buffer_add_video_affine_transformation_meta
gst_buffer_add_video_gl_texture_upload_meta
gst_buffer_add_video_meta
gst_buffer_add_video_meta_full
@@ -51,6 +52,9 @@ EXPORTS
gst_navigation_send_event
gst_navigation_send_key_event
gst_navigation_send_mouse_event
+ gst_video_affine_transformation_meta_api_get_type
+ gst_video_affine_transformation_meta_apply_matrix
+ gst_video_affine_transformation_meta_get_info
gst_video_alignment_reset
gst_video_alpha_mode_get_type
gst_video_blend