From 0b91ebeb2c3e17f81bed8053cb6ddf84af45b6cf Mon Sep 17 00:00:00 2001 From: Sreerenj Balachandran Date: Wed, 9 Aug 2017 14:22:12 -0700 Subject: [PATCH] FEI: libs: add H264 fei specific utility functions Added enum/flag type definitions for a number of FEI input and output parameters. Original author of the patch: Wang, Yi https://bugzilla.gnome.org/show_bug.cgi?id=785712 https://bugzilla.gnome.org/show_bug.cgi?id=784667 Signed-off-by: Wang, Yi Signed-off-by: Sreerenj Balachandran --- gst-libs/gst/vaapi/Makefile.am | 13 ++ gst-libs/gst/vaapi/gstvaapifeiutils_h264.c | 222 +++++++++++++++++++++ gst-libs/gst/vaapi/gstvaapifeiutils_h264.h | 215 ++++++++++++++++++++ 3 files changed, 450 insertions(+) create mode 100644 gst-libs/gst/vaapi/gstvaapifeiutils_h264.c create mode 100644 gst-libs/gst/vaapi/gstvaapifeiutils_h264.h diff --git a/gst-libs/gst/vaapi/Makefile.am b/gst-libs/gst/vaapi/Makefile.am index f7da153ce3..803857c417 100644 --- a/gst-libs/gst/vaapi/Makefile.am +++ b/gst-libs/gst/vaapi/Makefile.am @@ -237,6 +237,17 @@ libgstvaapi_source_c += $(libgstvaapi_vp9enc_source_c) libgstvaapi_source_h += $(libgstvaapi_vp9enc_source_h) endif +libgstvaapi_h264feienc_source_c = \ + gstvaapifeiutils_h264.c \ + $(NULL) +libgstvaapi_h264feienc_source_h = \ + gstvaapifeiutils_h264.h \ + $(NULL) +if USE_H264_FEI_ENCODER +libgstvaapi_source_c += $(libgstvaapi_h264feienc_source_c) +libgstvaapi_source_h += $(libgstvaapi_h264feienc_source_h) +endif + libgstvaapi_drm_source_c = \ gstvaapidisplay_drm.c \ gstvaapiwindow_drm.c \ @@ -523,6 +534,8 @@ EXTRA_DIST = \ $(libgstvaapi_egl_source_c) \ $(libgstvaapi_egl_source_h) \ $(libgstvaapi_egl_source_priv_h) \ + $(libgstvaapi_h264feienc_source_h) \ + $(libgstvaapi_h264feienc_source_c) \ $(NULL) -include $(top_srcdir)/git.mk diff --git a/gst-libs/gst/vaapi/gstvaapifeiutils_h264.c b/gst-libs/gst/vaapi/gstvaapifeiutils_h264.c new file mode 100644 index 0000000000..38411a7268 --- /dev/null +++ b/gst-libs/gst/vaapi/gstvaapifeiutils_h264.c @@ -0,0 +1,222 @@ +/* + * gstvaapifeiutils_h264_fei.c - Fei related utilities for H264 + * + * Copyright (C) 2016-2018 Intel Corporation + * Author: Wang, Yi + * Author: Sreerenj Balachandran + * + * 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 "sysdeps.h" +#include + +#include "gstvaapifeiutils_h264.h" + +/* FeiFixme: This is common fei modes for all codecs, + * move to a generic header file */ +/* --- GstVaapiFeiMode --- */ +GType +gst_vaapi_fei_mode_get_type (void) +{ + static volatile gsize g_type = 0; + + static const GFlagsValue encoding_mode_values[] = { + {GST_VAAPI_FEI_MODE_ENC, + "ENC Mode", "ENC"}, + {GST_VAAPI_FEI_MODE_PAK, + "PAK Mode", "PAK"}, + {GST_VAAPI_FEI_MODE_ENC_PAK, + "ENC_PAK Mode", "ENC_PAK"}, + {0, NULL, NULL}, + }; + + if (g_once_init_enter (&g_type)) { + GType type = + g_flags_register_static ("GstVaapiFeiMode", encoding_mode_values); + g_once_init_leave (&g_type, type); + } + return g_type; +} + +/* --- GstVaapiFeiH264SearchPath --- */ +GType +gst_vaapi_fei_h264_search_path_get_type (void) +{ + static volatile gsize g_type = 0; + + static const GEnumValue search_path_values[] = { + {GST_VAAPI_FEI_H264_FULL_SEARCH_PATH, + "full search path", "full"}, + {GST_VAAPI_FEI_H264_DIAMOND_SEARCH_PATH, + "diamond search path", "diamond"}, + {0, NULL, NULL}, + }; + + if (g_once_init_enter (&g_type)) { + GType type = g_enum_register_static ("GstVaapiFeiH264SearchPath", + search_path_values); + g_once_init_leave (&g_type, type); + } + return g_type; +} + +/* --- GstVaapiFeiH264SearchWindow --- */ +GType +gst_vaapi_fei_h264_search_window_get_type (void) +{ + static volatile gsize g_type = 0; + + static const GEnumValue search_window_values[] = { + {GST_VAAPI_FEI_H264_SEARCH_WINDOW_NONE, + "not use predefined search window", "none"}, + {GST_VAAPI_FEI_H264_SEARCH_WINDOW_TINY, + "4 SUs 24x24 window diamond search", "tiny"}, + {GST_VAAPI_FEI_H264_SEARCH_WINDOW_SMALL, + "9 SUs 28x28 window diamond search", "small"}, + {GST_VAAPI_FEI_H264_SEARCH_WINDOW_DIAMOND, + "16 SUs 48x40 window diamond search", "diamond"}, + {GST_VAAPI_FEI_H264_SEARCH_WINDOW_LARGE_DIAMOND, + "32 SUs 48x40 window diamond search", "large diamond"}, + {GST_VAAPI_FEI_H264_SEARCH_WINDOW_EXHAUSTIVE, + "48 SUs 48x40 window full search", "exhaustive"}, + {GST_VAAPI_FEI_H264_SEARCH_WINDOW_HORI_DIAMOND, + "16 SUs 64x32 window diamond search", "horizon diamond"}, + {GST_VAAPI_FEI_H264_SEARCH_WINDOW_HORI_LARGE_DIAMOND, + "32 SUs 64x32 window diamond search", "horizon large diamond"}, + {GST_VAAPI_FEI_H264_SEARCH_WINDOW_HORI_EXHAUSTIVE, + "48 SUs 64x32 window full search", "horizon exhaustive"}, + {0, NULL, NULL}, + }; + + if (g_once_init_enter (&g_type)) { + GType type = g_enum_register_static ("GstVaapiFeiH264SearchWindow", + search_window_values); + g_once_init_leave (&g_type, type); + } + return g_type; +} + +/* --- GstVaapiFeiH264SubPelMode --- */ +GType +gst_vaapi_fei_h264_sub_pel_mode_get_type (void) +{ + static volatile gsize g_type = 0; + + static const GEnumValue sub_pel_mode_values[] = { + {GST_VAAPI_FEI_H264_INTEGER_ME, + "integer mode searching", "integer"}, + {GST_VAAPI_FEI_H264_HALF_ME, + "half-pel mode searching", "half"}, + {GST_VAAPI_FEI_H264_QUARTER_ME, + "quarter-pel mode searching", "quarter"}, + {0, NULL, NULL}, + }; + + if (g_once_init_enter (&g_type)) { + GType type = g_enum_register_static ("GstVaapiFeiH264SubPelMode", + sub_pel_mode_values); + g_once_init_leave (&g_type, type); + } + return g_type; +} + +/* --- GstVaapiFeiH264SadMode --- */ +GType +gst_vaapi_fei_h264_sad_mode_get_type (void) +{ + static volatile gsize g_type = 0; + + static const GEnumValue sad_mode_values[] = { + {GST_VAAPI_FEI_H264_SAD_NONE_TRANS, + "none transform adjusted", "none"}, + {GST_VAAPI_FEI_H264_SAD_HAAR_TRANS, + "Haar transform adjusted", "haar"}, + {0, NULL, NULL}, + }; + + if (g_once_init_enter (&g_type)) { + GType type = + g_enum_register_static ("GstVaapiFeiH264SadMode", sad_mode_values); + g_once_init_leave (&g_type, type); + } + return g_type; +} + +/* --- GstVaapiFeiH264IntraPartMask --- */ +GType +gst_vaapi_fei_h264_intra_part_mask_get_type (void) +{ + static volatile gsize g_type = 0; + + static const GFlagsValue intra_part_mask_values[] = { + {GST_VAAPI_FEI_H264_DISABLE_INTRA_NONE, + "enable all intra mode", "enable all"}, + {GST_VAAPI_FEI_H264_DISABLE_INTRA_16x16, + "luma_intra_16x16 disabled", "intra16x16 disabled"}, + {GST_VAAPI_FEI_H264_DISABLE_INTRA_8x8, + "luma_intra_8x8 disabled", "intra8x8 disabled"}, + {GST_VAAPI_FEI_H264_DISABLE_INTRA_4x4, + "luma_intra_4x4 disabled", "intra4x4 disabled"}, + {0, NULL, NULL}, + }; + + if (g_once_init_enter (&g_type)) { + GType type = g_flags_register_static ("GstVaapiFeiH264IntraPartMask", + intra_part_mask_values); + g_once_init_leave (&g_type, type); + } + return g_type; +} + +/* --- GstVaapiFeiH264SubMbPartMask --- */ +GType +gst_vaapi_fei_h264_sub_mb_part_mask_get_type (void) +{ + static volatile gsize g_type = 0; + + static const GFlagsValue sub_mb_part_mask_values[] = { + {GST_VAAPI_FEI_H264_DISABLE_SUB_MB_PART_MASK_NONE, + "enable all subpartitions", "enable all"}, + {GST_VAAPI_FEI_H264_DISABLE_SUB_MB_PART_MASK_16x16, + "16x16 sub-macroblock disabled", "16x16 submb part disabled"}, + {GST_VAAPI_FEI_H264_DISABLE_SUB_MB_PART_MASK_2x16x8, + "2x(16x8) sub-macroblock within 16x16 disabled", + "16x8 submb part disabled"}, + {GST_VAAPI_FEI_H264_DISABLE_SUB_MB_PART_MASK_2x8x16, + "2x(8x16) sub-macroblock within 16x16 disabled", + "8x16 submb part disabled"}, + {GST_VAAPI_FEI_H264_DISABLE_SUB_MB_PART_MASK_1x8x8, + "1x(8x8) sub-partition for 4x(8x8) within 16x16 disabled", + "8x8 submb part disabled"}, + {GST_VAAPI_FEI_H264_DISABLE_SUB_MB_PART_MASK_2x8x4, + "2x(8x4) sub-partition for 4x(8x8) within 16x16 disabled", + "8x4 submb part disabled"}, + {GST_VAAPI_FEI_H264_DISABLE_SUB_MB_PART_MASK_2x4x8, + "2x(4x8) sub-partition for 4x(8x8) within 16x16 disabled", + "4x8 submb part disabled"}, + {GST_VAAPI_FEI_H264_DISABLE_SUB_MB_PART_MASK_4x4x4, + "4x(4x4) sub-partition for 4x(8x8) within 16x16 disabled", + "4x4 submb part disabled"}, + {0, NULL, NULL}, + }; + + if (g_once_init_enter (&g_type)) { + GType type = g_flags_register_static ("GstVaapiFeiH264SubMbPartMask", + sub_mb_part_mask_values); + g_once_init_leave (&g_type, type); + } + return g_type; +} diff --git a/gst-libs/gst/vaapi/gstvaapifeiutils_h264.h b/gst-libs/gst/vaapi/gstvaapifeiutils_h264.h new file mode 100644 index 0000000000..a0eeb699c9 --- /dev/null +++ b/gst-libs/gst/vaapi/gstvaapifeiutils_h264.h @@ -0,0 +1,215 @@ +/* + * gstvaapifeiutils_h264.h - FEI related utilities for H264 + * + * Copyright (C) 2016-2018 Intel Corporation + * Author: Wang, Yi + * Author: Sreerenj Balachandran + * + * 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_FEI_UTILS_H264_H +#define GST_VAAPI_FEI_UTILS_H264_H + +#include + +G_BEGIN_DECLS + +typedef struct _GstVaapiFeiInfoToPakH264 GstVaapiFeiInfoToPakH264; + +/* Structure useful for FEI ENC+PAK mode */ +struct _GstVaapiFeiInfoToPakH264 +{ + VAEncSequenceParameterBufferH264 h264_enc_sps; + VAEncPictureParameterBufferH264 h264_enc_pps; + GArray *h264_slice_headers; + guint h264_slice_num; +}; + +/******************* Common FEI enum definition for all codecs ***********/ +/* FeiFixme: This should be a common fei mode for all codecs, + * move to a common header file */ +#define GST_VAAPI_FEI_MODE_DEFAULT GST_VAAPI_FEI_MODE_ENC_PAK +typedef enum +{ + GST_VAAPI_FEI_MODE_ENC = (1 << 0), + GST_VAAPI_FEI_MODE_PAK = (1 << 1), + GST_VAAPI_FEI_MODE_ENC_PAK = (1 << 2) +} GstVaapiFeiMode; +/** +* GST_VAAPI_TYPE_FEI_MODE: +* +* A type that represents the fei encoding mode. +* +* Return value: the #GType of GstVaapiFeiMode +*/ +#define GST_VAAPI_TYPE_FEI_MODE (gst_vaapi_fei_mode_get_type()) + + +/******************* H264 Specific FEI enum definitions ***********/ + +typedef enum +{ + GST_VAAPI_FEI_H264_FULL_SEARCH_PATH = 0, + GST_VAAPI_FEI_H264_DIAMOND_SEARCH_PATH, +} GstVaapiFeiH264SearchPath; + +typedef enum +{ + GST_VAAPI_FEI_H264_SEARCH_WINDOW_NONE = 0, + GST_VAAPI_FEI_H264_SEARCH_WINDOW_TINY, + GST_VAAPI_FEI_H264_SEARCH_WINDOW_SMALL, + GST_VAAPI_FEI_H264_SEARCH_WINDOW_DIAMOND, + GST_VAAPI_FEI_H264_SEARCH_WINDOW_LARGE_DIAMOND, + GST_VAAPI_FEI_H264_SEARCH_WINDOW_EXHAUSTIVE, + GST_VAAPI_FEI_H264_SEARCH_WINDOW_HORI_DIAMOND, + GST_VAAPI_FEI_H264_SEARCH_WINDOW_HORI_LARGE_DIAMOND, + GST_VAAPI_FEI_H264_SEARCH_WINDOW_HORI_EXHAUSTIVE, +} GstVaapiFeiH264SearchWindow; + +typedef enum +{ + GST_VAAPI_FEI_H264_INTEGER_ME = 0, + GST_VAAPI_FEI_H264_HALF_ME = 1, + GST_VAAPI_FEI_H264_QUARTER_ME = 3, +} GstVaapiFeiH264SubPelMode; + +typedef enum +{ + GST_VAAPI_FEI_H264_SAD_NONE_TRANS = 0, + GST_VAAPI_FEI_H264_SAD_HAAR_TRANS = 2, +} GstVaapiFeiH264SadMode; + +typedef enum +{ + GST_VAAPI_FEI_H264_DISABLE_INTRA_NONE = 0, + GST_VAAPI_FEI_H264_DISABLE_INTRA_16x16 = (1 << 0), + GST_VAAPI_FEI_H264_DISABLE_INTRA_8x8 = (1 << 1), + GST_VAAPI_FEI_H264_DISABLE_INTRA_4x4 = (1 << 2), +} GstVaapiFeiH264IntraPartMask; + +typedef enum +{ + GST_VAAPI_FEI_H264_DISABLE_SUB_MB_PART_MASK_NONE = 0, + GST_VAAPI_FEI_H264_DISABLE_SUB_MB_PART_MASK_16x16 = (1 << 1), + GST_VAAPI_FEI_H264_DISABLE_SUB_MB_PART_MASK_2x16x8 = (1 << 2), + GST_VAAPI_FEI_H264_DISABLE_SUB_MB_PART_MASK_2x8x16 = (1 << 3), + GST_VAAPI_FEI_H264_DISABLE_SUB_MB_PART_MASK_1x8x8 = (1 << 4), + GST_VAAPI_FEI_H264_DISABLE_SUB_MB_PART_MASK_2x8x4 = (1 << 5), + GST_VAAPI_FEI_H264_DISABLE_SUB_MB_PART_MASK_2x4x8 = (1 << 6), + GST_VAAPI_FEI_H264_DISABLE_SUB_MB_PART_MASK_4x4x4 = (1 << 7), +} GstVaapiFeiH264SubMbPartMask; + +#define GST_VAAPI_FEI_H264_SEARCH_PATH_DEFAULT \ + GST_VAAPI_FEI_H264_FULL_SEARCH_PATH +#define GST_VAAPI_FEI_H264_SEARCH_WINDOW_DEFAULT \ + GST_VAAPI_FEI_H264_SEARCH_WINDOW_NONE +#define GST_VAAPI_FEI_H264_SUB_PEL_MODE_DEFAULT \ + GST_VAAPI_FEI_H264_INTEGER_ME +#define GST_VAAPI_FEI_H264_SAD_MODE_DEFAULT \ + GST_VAAPI_FEI_H264_SAD_NONE_TRANS +#define GST_VAAPI_FEI_H264_INTRA_PART_MASK_DEFAULT \ + GST_VAAPI_FEI_H264_DISABLE_INTRA_NONE +#define GST_VAAPI_FEI_H264_SUB_MB_PART_MASK_DEFAULT \ + GST_VAAPI_FEI_H264_DISABLE_SUB_MB_PART_MASK_NONE +#define GST_VAAPI_FEI_H264_SEARCH_PATH_LENGTH_DEFAULT 32 +#define GST_VAAPI_FEI_H264_REF_WIDTH_DEFAULT 32 +#define GST_VAAPI_FEI_H264_REF_HEIGHT_DEFAULT 32 + +/** +* GST_VAAPI_TYPE_FEI_H264_SEARCH_PATH: +* +* A type that represents the fei control param: search path. +* +* Return value: the #GType of GstVaapiFeiSearchPath +*/ +#define GST_VAAPI_TYPE_FEI_H264_SEARCH_PATH gst_vaapi_fei_h264_search_path_get_type() + +/** +* GST_VAAPI_TYPE_FEI_H264_SEARCH_WINDOW: +* +* A type that represents the fei control param: search window. +* +* Return value: the #GType of GstVaapiFeiSearchWindow +*/ +#define GST_VAAPI_TYPE_FEI_H264_SEARCH_WINDOW gst_vaapi_fei_h264_search_window_get_type() + +/** +* GST_VAAPI_TYPE_FEI_H264_SAD_MODE: +* +* A type that represents the fei control param: sad mode. +* +* Return value: the #GType of GstVaapiFeiSadMode +*/ +#define GST_VAAPI_TYPE_FEI_H264_SAD_MODE gst_vaapi_fei_h264_sad_mode_get_type() + +/** +* GST_VAAPI_TYPE_FEI_H264_INTRA_PART_MASK: +* +* A type that represents the fei control param: intra part mask. +* +* Return value: the #GType of GstVaapiFeiIntaPartMask +*/ +#define GST_VAAPI_TYPE_FEI_H264_INTRA_PART_MASK gst_vaapi_fei_h264_intra_part_mask_get_type() + +/** +* GST_VAAPI_TYPE_FEI_H264_SUB_PEL_MODE: +* +* A type that represents the fei control param: sub pel mode. +* +* Return value: the #GType of GstVaapiFeiSubPelMode +*/ +#define GST_VAAPI_TYPE_FEI_H264_SUB_PEL_MODE gst_vaapi_fei_h264_sub_pel_mode_get_type() + +/** +* GST_VAAPI_TYPE_FEI_H264_SUB_MB_PART_MASK: +* +* A type that represents the fei control param: sub maroclock partition mask. +* +* Return value: the #GType of GstVaapiFeiH264SubMbPartMask +*/ +#define GST_VAAPI_TYPE_FEI_H264_SUB_MB_PART_MASK gst_vaapi_fei_h264_sub_mb_part_mask_get_type() + +GType +gst_vaapi_fei_mode_get_type (void) + G_GNUC_CONST; + +GType +gst_vaapi_fei_h264_search_path_get_type (void) + G_GNUC_CONST; + +GType +gst_vaapi_fei_h264_search_window_get_type (void) + G_GNUC_CONST; + +GType +gst_vaapi_fei_h264_sad_mode_get_type (void) + G_GNUC_CONST; + +GType +gst_vaapi_fei_h264_sub_pel_mode_get_type (void) + G_GNUC_CONST; + +GType +gst_vaapi_fei_h264_intra_part_mask_get_type (void) + G_GNUC_CONST; + +GType +gst_vaapi_fei_h264_sub_mb_part_mask_get_type (void) + G_GNUC_CONST; + +G_END_DECLS +#endif /* GST_VAAPI_UTILS_FEI_H264_H */