vaapipostproc: set early properties restrictions
authorVíctor Manuel Jáquez Leal <victorx.jaquez@intel.com>
Thu, 5 May 2016 10:07:59 +0000 (12:07 +0200)
committerVíctor Manuel Jáquez Leal <victorx.jaquez@intel.com>
Mon, 9 May 2016 12:56:03 +0000 (14:56 +0200)
When running transform_caps() vmethod, returning the srcpad caps, the caps are
early restricted to the element properties set: width, height, format and
force keep aspect.

A new file was added gstvaapipostprocutil.{c,h} where the utilities functions
are stored.

https://bugzilla.gnome.org/show_bug.cgi?id=758548

gst/vaapi/Makefile.am
gst/vaapi/gstvaapipostproc.c
gst/vaapi/gstvaapipostprocutil.c [new file with mode: 0644]
gst/vaapi/gstvaapipostprocutil.h [new file with mode: 0644]

index 21eef47..3e54a41 100644 (file)
@@ -46,6 +46,7 @@ libgstvaapi_source_c = \
        gstvaapipluginbase.c    \
        gstvaapipluginutil.c    \
        gstvaapipostproc.c      \
+       gstvaapipostprocutil.c  \
        gstvaapisink.c          \
        gstvaapivideobuffer.c   \
        gstvaapivideocontext.c  \
@@ -62,6 +63,7 @@ libgstvaapi_source_h = \
        gstvaapipluginbase.h    \
        gstvaapipluginutil.h    \
        gstvaapipostproc.h      \
+       gstvaapipostprocutil.h  \
        gstvaapisink.h          \
        gstvaapivideobuffer.h   \
        gstvaapivideocontext.h  \
index 8672f8a..6e24a87 100644 (file)
@@ -39,6 +39,7 @@
 #include <gst/video/video.h>
 
 #include "gstvaapipostproc.h"
+#include "gstvaapipostprocutil.h"
 #include "gstvaapipluginutil.h"
 #include "gstvaapivideobuffer.h"
 #include "gstvaapivideobufferpool.h"
@@ -118,10 +119,6 @@ enum
   PROP_SKIN_TONE_ENHANCEMENT,
 };
 
-#define DEFAULT_FORMAT                  GST_VIDEO_FORMAT_ENCODED
-#define DEFAULT_DEINTERLACE_MODE        GST_VAAPI_DEINTERLACE_MODE_AUTO
-#define DEFAULT_DEINTERLACE_METHOD      GST_VAAPI_DEINTERLACE_METHOD_BOB
-
 #define GST_VAAPI_TYPE_DEINTERLACE_MODE \
     gst_vaapi_deinterlace_mode_get_type()
 
@@ -1076,7 +1073,7 @@ gst_vaapipostproc_transform_caps_impl (GstBaseTransform * trans,
   if (!gst_caps_is_fixed (caps)) {
     if (!ensure_allowed_srcpad_caps (postproc))
       return NULL;
-    return gst_caps_ref (postproc->allowed_srcpad_caps);
+    return gst_vaapipostproc_transform_srccaps (postproc);
   }
 
   /* Generate the expected src pad caps, from the current fixated
diff --git a/gst/vaapi/gstvaapipostprocutil.c b/gst/vaapi/gstvaapipostprocutil.c
new file mode 100644 (file)
index 0000000..b2a64d9
--- /dev/null
@@ -0,0 +1,126 @@
+/*
+ *  gstvaapipostprocutil.h - VA-API video post processing utilities
+ *
+ *  Copyright (C) 2016 Intel Corporation
+ *    Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
+ *    Author: Victor Jaquez <victorx.jaquez@intel.com>
+ *
+ *  This program 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 program 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 program; if not, write to the Free
+ *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ *  Boston, MA 02110-1301 USA
+ */
+
+#include "gstvaapipostprocutil.h"
+#include "gstvaapipluginutil.h"
+
+/* if format property is set */
+static void
+_transform_format (GstVaapiPostproc * postproc, GstCapsFeatures * features,
+    GstStructure * structure)
+{
+  GValue value = G_VALUE_INIT;
+
+  if (postproc->format == DEFAULT_FORMAT)
+    return;
+
+  if (!gst_caps_features_is_equal (features,
+          GST_CAPS_FEATURES_MEMORY_SYSTEM_MEMORY)
+      && !gst_caps_features_contains (features,
+          GST_CAPS_FEATURE_MEMORY_VAAPI_SURFACE))
+    return;
+
+  if (!gst_vaapi_value_set_format (&value, postproc->format))
+    return;
+
+  gst_structure_set_value (structure, "format", &value);
+}
+
+static void
+_set_int (GValue * value, gint val)
+{
+  g_value_init (value, G_TYPE_INT);
+  g_value_set_int (value, val);
+}
+
+static void
+_set_int_range (GValue * value)
+{
+  g_value_init (value, GST_TYPE_INT_RANGE);
+  gst_value_set_int_range (value, 1, G_MAXINT);
+}
+
+static void
+_transform_frame_size (GstVaapiPostproc * postproc, GstStructure * structure)
+{
+  GValue width = G_VALUE_INIT;
+  GValue height = G_VALUE_INIT;
+
+  if (postproc->width && postproc->height) {
+    _set_int (&width, postproc->width);
+    _set_int (&height, postproc->height);
+  } else if (postproc->width) {
+    _set_int (&width, postproc->width);
+    _set_int_range (&height);
+  } else if (postproc->height) {
+    _set_int_range (&width);
+    _set_int (&height, postproc->height);
+  } else {
+    _set_int_range (&width);
+    _set_int_range (&height);
+  }
+
+  gst_structure_set_value (structure, "width", &width);
+  gst_structure_set_value (structure, "height", &height);
+}
+
+/**
+ * gst_vaapipostproc_transform_srccaps:
+ * @postproc: a #GstVaapiPostproc instance
+ *
+ * Early apply transformation of the src pad caps according to the set
+ * properties.
+ *
+ * Returns: A new allocated #GstCaps
+ **/
+GstCaps *
+gst_vaapipostproc_transform_srccaps (GstVaapiPostproc * postproc)
+{
+  GstCaps *out_caps;
+  GstStructure *structure;
+  GstCapsFeatures *features;
+  gint i, n;
+
+  out_caps = gst_caps_new_empty ();
+  n = gst_caps_get_size (postproc->allowed_srcpad_caps);
+
+  for (i = 0; i < n; i++) {
+    structure = gst_caps_get_structure (postproc->allowed_srcpad_caps, i);
+    features = gst_caps_get_features (postproc->allowed_srcpad_caps, i);
+
+    /* make copy */
+    structure = gst_structure_copy (structure);
+
+    if (postproc->keep_aspect)
+      gst_structure_set (structure, "pixel-aspect-ratio", GST_TYPE_FRACTION, 1,
+          1, NULL);
+
+    _transform_format (postproc, features, structure);
+    _transform_frame_size (postproc, structure);
+
+    gst_caps_append_structure_full (out_caps, structure,
+        gst_caps_features_copy (features));
+  }
+
+  return out_caps;
+}
diff --git a/gst/vaapi/gstvaapipostprocutil.h b/gst/vaapi/gstvaapipostprocutil.h
new file mode 100644 (file)
index 0000000..70f6d97
--- /dev/null
@@ -0,0 +1,39 @@
+/*
+ *  gstvaapipostprocutil.h - VA-API video post processing utilities
+ *
+ *  Copyright (C) 2016 Intel Corporation
+ *    Author: Gwenole Beauchesne <gwenole.beauchesne@intel.com>
+ *    Author: Victor Jaquez <victorx.jaquez@intel.com>
+ *
+ *  This program 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 program 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 program; if not, write to the Free
+ *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
+ *  Boston, MA 02110-1301 USA
+ */
+
+#ifndef GST_VAAPIPOSTPROCUTIL_H
+#define GST_VAAPIPOSTPROCUTIL_H
+
+#include "gstvaapipostproc.h"
+
+G_BEGIN_DECLS
+
+#define DEFAULT_FORMAT                  GST_VIDEO_FORMAT_ENCODED
+#define DEFAULT_DEINTERLACE_MODE        GST_VAAPI_DEINTERLACE_MODE_AUTO
+#define DEFAULT_DEINTERLACE_METHOD      GST_VAAPI_DEINTERLACE_METHOD_BOB
+
+GstCaps *gst_vaapipostproc_transform_srccaps (GstVaapiPostproc * postproc);
+
+G_END_DECLS
+
+#endif /* GST_VAAPIPOSTPROCUTIL_H */