From 0b98ed32ce9db48089787f32c13c1a3db3ac36f3 Mon Sep 17 00:00:00 2001 From: Matthew Waters Date: Mon, 2 Nov 2015 23:12:19 +1100 Subject: [PATCH] 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 --- docs/libs/gst-plugins-base-libs-docs.sgml | 1 + docs/libs/gst-plugins-base-libs-sections.txt | 12 ++ gst-libs/gst/video/Makefile.am | 2 + .../video/gstvideoaffinetransformationmeta.c | 152 ++++++++++++++++++ .../video/gstvideoaffinetransformationmeta.h | 70 ++++++++ win32/common/libgstvideo.def | 4 + 6 files changed, 241 insertions(+) create mode 100644 gst-libs/gst/video/gstvideoaffinetransformationmeta.c create mode 100644 gst-libs/gst/video/gstvideoaffinetransformationmeta.h diff --git a/docs/libs/gst-plugins-base-libs-docs.sgml b/docs/libs/gst-plugins-base-libs-docs.sgml index 7767abf961..640fba0073 100644 --- a/docs/libs/gst-plugins-base-libs-docs.sgml +++ b/docs/libs/gst-plugins-base-libs-docs.sgml @@ -197,6 +197,7 @@ + diff --git a/docs/libs/gst-plugins-base-libs-sections.txt b/docs/libs/gst-plugins-base-libs-sections.txt index e437882f03..fd1e3811c9 100644 --- a/docs/libs/gst-plugins-base-libs-sections.txt +++ b/docs/libs/gst-plugins-base-libs-sections.txt @@ -2625,6 +2625,18 @@ gst_video_gl_texture_upload_meta_api_get_type gst_video_gl_texture_upload_meta_get_info +
+gstvideoaffinetransformationmeta +gst/video/gstvideoaffinetransformationmeta.h +GstVideoAffineTransformationMeta +gst_buffer_add_video_affine_transformation_meta +gst_buffer_get_video_affine_transformation_meta +gst_video_affine_transformation_meta_apply_matrix + +gst_video_affine_transformation_meta_api_get_type +gst_video_affine_transformation_meta_get_info +
+
gstvideooverlaycomposition gst/video/video-overlay-composition.h diff --git a/gst-libs/gst/video/Makefile.am b/gst-libs/gst/video/Makefile.am index 5d31fa1e80..c26be81f16 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 0000000000..c485310b56 --- /dev/null +++ b/gst-libs/gst/video/gstvideoaffinetransformationmeta.c @@ -0,0 +1,152 @@ +/* GStreamer + * Copyright (C) <2014> Collabora Ltd. + * Author: Matthieu Bouron + * Copyright (C) 2015, Matthew Waters + * + * 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 + +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 0000000000..3838a01da3 --- /dev/null +++ b/gst-libs/gst/video/gstvideoaffinetransformationmeta.h @@ -0,0 +1,70 @@ +/* GStreamer + * Copyright (C) Collabora Ltd. + * Author: Matthieu Bouron + * Copyright (C) 2015, Matthew Waters + * + * 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 +#include + +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 39b031f3ae..7b25d994eb 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