diff --git a/gst-libs/gst/vaapi/Makefile.am b/gst-libs/gst/vaapi/Makefile.am index 1159928da4..50bdef8e58 100644 --- a/gst-libs/gst/vaapi/Makefile.am +++ b/gst-libs/gst/vaapi/Makefile.am @@ -78,6 +78,7 @@ libgstvaapi_source_c = \ gstvaapiutils_core.c \ gstvaapiutils_h264.c \ gstvaapiutils_h265.c \ + gstvaapiutils_h26x.c \ gstvaapiutils_mpeg2.c \ gstvaapivalue.c \ gstvaapivideopool.c \ @@ -142,6 +143,7 @@ libgstvaapi_source_priv_h = \ gstvaapiutils_core.h \ gstvaapiutils_h264_priv.h \ gstvaapiutils_h265_priv.h \ + gstvaapiutils_h26x_priv.h \ gstvaapiutils_mpeg2_priv.h \ gstvaapivideopool_priv.h \ gstvaapiwindow_priv.h \ diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_h264.c b/gst-libs/gst/vaapi/gstvaapiencoder_h264.c index 450d43598b..801a721f7c 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder_h264.c +++ b/gst-libs/gst/vaapi/gstvaapiencoder_h264.c @@ -36,6 +36,7 @@ #include "gstvaapiencoder_h264.h" #include "gstvaapiutils_h264.h" #include "gstvaapiutils_h264_priv.h" +#include "gstvaapiutils_h26x_priv.h" #include "gstvaapicodedbufferproxy_priv.h" #include "gstvaapisurface.h" @@ -49,21 +50,6 @@ /* Define the maximum value for view-id */ #define MAX_VIEW_ID 1023 -/* Define the maximum IDR period */ -#define MAX_IDR_PERIOD 512 - -/* Default CPB length (in milliseconds) */ -#define DEFAULT_CPB_LENGTH 1500 - -/* Scale factor for CPB size (HRD cpb_size_scale: min = 4) */ -#define SX_CPB_SIZE 4 - -/* Scale factor for bitrate (HRD bit_rate_scale: min = 6) */ -#define SX_BITRATE 6 - -/* Define default rate control mode ("constant-qp") */ -#define DEFAULT_RATECONTROL GST_VAAPI_RATECONTROL_CQP - /* Supported set of VA rate controls, within this implementation */ #define SUPPORTED_RATECONTROLS \ (GST_VAAPI_RATECONTROL_MASK (CQP) | \ @@ -200,66 +186,6 @@ h264_get_cpb_nal_factor (GstVaapiProfile profile) return f; } -/* ------------------------------------------------------------------------- */ -/* --- H.264 Bitstream Writer --- */ -/* ------------------------------------------------------------------------- */ - -#define WRITE_UINT32(bs, val, nbits) do { \ - if (!gst_bit_writer_put_bits_uint32 (bs, val, nbits)) { \ - GST_WARNING ("failed to write uint32, nbits: %d", nbits); \ - goto bs_error; \ - } \ - } while (0) - -#define WRITE_UE(bs, val) do { \ - if (!bs_write_ue (bs, val)) { \ - GST_WARNING ("failed to write ue(v)"); \ - goto bs_error; \ - } \ - } while (0) - -#define WRITE_SE(bs, val) do { \ - if (!bs_write_se (bs, val)) { \ - GST_WARNING ("failed to write se(v)"); \ - goto bs_error; \ - } \ - } while (0) - -/* Write an unsigned integer Exp-Golomb-coded syntax element. i.e. ue(v) */ -static gboolean -bs_write_ue (GstBitWriter * bs, guint32 value) -{ - guint32 size_in_bits = 0; - guint32 tmp_value = ++value; - - while (tmp_value) { - ++size_in_bits; - tmp_value >>= 1; - } - if (size_in_bits > 1 - && !gst_bit_writer_put_bits_uint32 (bs, 0, size_in_bits - 1)) - return FALSE; - if (!gst_bit_writer_put_bits_uint32 (bs, value, size_in_bits)) - return FALSE; - return TRUE; -} - -/* Write a signed integer Exp-Golomb-coded syntax element. i.e. se(v) */ -static gboolean -bs_write_se (GstBitWriter * bs, gint32 value) -{ - guint32 new_val; - - if (value <= 0) - new_val = -(value << 1); - else - new_val = (value << 1) - 1; - - if (!bs_write_ue (bs, new_val)) - return FALSE; - return TRUE; -} - /* Write the NAL unit header */ static gboolean bs_write_nal_header (GstBitWriter * bs, guint32 nal_ref_idc, diff --git a/gst-libs/gst/vaapi/gstvaapiencoder_h265.c b/gst-libs/gst/vaapi/gstvaapiencoder_h265.c index 39fca6c6b6..e156fdbb49 100644 --- a/gst-libs/gst/vaapi/gstvaapiencoder_h265.c +++ b/gst-libs/gst/vaapi/gstvaapiencoder_h265.c @@ -36,27 +36,13 @@ #include "gstvaapiencoder_h265.h" #include "gstvaapiutils_h265.h" #include "gstvaapiutils_h265_priv.h" +#include "gstvaapiutils_h26x_priv.h" #include "gstvaapicodedbufferproxy_priv.h" #include "gstvaapisurface.h" #define DEBUG 1 #include "gstvaapidebug.h" -/* Define the maximum IDR period */ -#define MAX_IDR_PERIOD 512 - -/* Default CPB length (in milliseconds) */ -#define DEFAULT_CPB_LENGTH 1500 - -/* Scale factor for bitrate (HRD bit_rate_scale: min = 6) */ -#define SX_BITRATE 6 - -/* Scale factor for CPB size (HRD cpb_size_scale: min = 4) */ -#define SX_CPB_SIZE 4 - -/* Define default rate control mode ("constant-qp") */ -#define DEFAULT_RATECONTROL GST_VAAPI_RATECONTROL_CQP - /* Supported set of VA rate controls, within this implementation */ #define SUPPORTED_RATECONTROLS \ (GST_VAAPI_RATECONTROL_MASK (CQP)) | \ @@ -205,66 +191,6 @@ h265_get_log2_max_pic_order_cnt (guint num) return ret; } -/* ------------------------------------------------------------------------- */ -/* --- H.265 Bitstream Writer --- */ -/* ------------------------------------------------------------------------- */ - -#define WRITE_UINT32(bs, val, nbits) do { \ - if (!gst_bit_writer_put_bits_uint32 (bs, val, nbits)) { \ - GST_WARNING ("failed to write uint32, nbits: %d", nbits); \ - goto bs_error; \ - } \ - } while (0) - -#define WRITE_UE(bs, val) do { \ - if (!bs_write_ue (bs, val)) { \ - GST_WARNING ("failed to write ue(v)"); \ - goto bs_error; \ - } \ - } while (0) - -#define WRITE_SE(bs, val) do { \ - if (!bs_write_se (bs, val)) { \ - GST_WARNING ("failed to write se(v)"); \ - goto bs_error; \ - } \ - } while (0) - -/* Write an unsigned integer Exp-Golomb-coded syntax element. i.e. ue(v) */ -static gboolean -bs_write_ue (GstBitWriter * bs, guint32 value) -{ - guint32 size_in_bits = 0; - guint32 tmp_value = ++value; - - while (tmp_value) { - ++size_in_bits; - tmp_value >>= 1; - } - if (size_in_bits > 1 - && !gst_bit_writer_put_bits_uint32 (bs, 0, size_in_bits - 1)) - return FALSE; - if (!gst_bit_writer_put_bits_uint32 (bs, value, size_in_bits)) - return FALSE; - return TRUE; -} - -/* Write a signed integer Exp-Golomb-coded syntax element. i.e. se(v) */ -static gboolean -bs_write_se (GstBitWriter * bs, gint32 value) -{ - guint32 new_val; - - if (value <= 0) - new_val = -(value << 1); - else - new_val = (value << 1) - 1; - - if (!bs_write_ue (bs, new_val)) - return FALSE; - return TRUE; -} - /* Write the NAL unit header */ static gboolean bs_write_nal_header (GstBitWriter * bs, guint32 nal_unit_type) diff --git a/gst-libs/gst/vaapi/gstvaapiutils_h26x.c b/gst-libs/gst/vaapi/gstvaapiutils_h26x.c new file mode 100644 index 0000000000..717be39339 --- /dev/null +++ b/gst-libs/gst/vaapi/gstvaapiutils_h26x.c @@ -0,0 +1,58 @@ +/* + * gstvaapiutils_h26x.c - H.26x related utilities + * + * Copyright (C) 2011-2014 Intel Corporation + * Author: Gwenole Beauchesne + * + * 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 "gstvaapiutils_h26x_priv.h" + +/* Write an unsigned integer Exp-Golomb-coded syntax element. i.e. ue(v) */ +gboolean +bs_write_ue (GstBitWriter * bs, guint32 value) +{ + guint32 size_in_bits = 0; + guint32 tmp_value = ++value; + + while (tmp_value) { + ++size_in_bits; + tmp_value >>= 1; + } + if (size_in_bits > 1 + && !gst_bit_writer_put_bits_uint32 (bs, 0, size_in_bits - 1)) + return FALSE; + if (!gst_bit_writer_put_bits_uint32 (bs, value, size_in_bits)) + return FALSE; + return TRUE; +} + +/* Write a signed integer Exp-Golomb-coded syntax element. i.e. se(v) */ +gboolean +bs_write_se (GstBitWriter * bs, gint32 value) +{ + guint32 new_val; + + if (value <= 0) + new_val = -(value << 1); + else + new_val = (value << 1) - 1; + + if (!bs_write_ue (bs, new_val)) + return FALSE; + return TRUE; +} diff --git a/gst-libs/gst/vaapi/gstvaapiutils_h26x_priv.h b/gst-libs/gst/vaapi/gstvaapiutils_h26x_priv.h new file mode 100644 index 0000000000..a1ede90520 --- /dev/null +++ b/gst-libs/gst/vaapi/gstvaapiutils_h26x_priv.h @@ -0,0 +1,82 @@ +/* + * gstvaapiutils_h26x_priv.h - H.26x related utilities + * + * Copyright (C) 2011-2014 Intel Corporation + * Author: Gwenole Beauchesne + * + * 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_UTILS_H26X_PRIV_H +#define GST_VAAPI_UTILS_H26X_PRIV_H + +#include + +G_BEGIN_DECLS + +/* Define the maximum IDR period */ +#define MAX_IDR_PERIOD 512 + +/* Default CPB length (in milliseconds) */ +#define DEFAULT_CPB_LENGTH 1500 + +/* Scale factor for CPB size (HRD cpb_size_scale: min = 4) */ +#define SX_CPB_SIZE 4 + +/* Scale factor for bitrate (HRD bit_rate_scale: min = 6) */ +#define SX_BITRATE 6 + +/* Define default rate control mode ("constant-qp") */ +#define DEFAULT_RATECONTROL GST_VAAPI_RATECONTROL_CQP + +/* ------------------------------------------------------------------------- */ +/* --- H.264/265 Bitstream Writer --- */ +/* ------------------------------------------------------------------------- */ + +#define WRITE_UINT32(bs, val, nbits) \ + G_STMT_START { \ + if (!gst_bit_writer_put_bits_uint32 (bs, val, nbits)) { \ + GST_WARNING ("failed to write uint32, nbits: %d", nbits); \ + goto bs_error; \ + } \ + } G_STMT_END + +#define WRITE_UE(bs, val) \ + G_STMT_START { \ + if (!bs_write_ue (bs, val)) { \ + GST_WARNING ("failed to write ue(v)"); \ + goto bs_error; \ + } \ + } G_STMT_END + +#define WRITE_SE(bs, val) \ + G_STMT_START { \ + if (!bs_write_se (bs, val)) { \ + GST_WARNING ("failed to write se(v)"); \ + goto bs_error; \ + } \ + } G_STMT_END + + +gboolean +bs_write_ue (GstBitWriter * bs, guint32 value); + +gboolean +bs_write_se (GstBitWriter * bs, gint32 value); + +G_END_DECLS + +#endif /* GST_VAAPI_UTILS_H26X_PRIV_H */ diff --git a/gst-libs/gst/vaapi/meson.build b/gst-libs/gst/vaapi/meson.build index 7f9ff0275c..55bb5c76e8 100644 --- a/gst-libs/gst/vaapi/meson.build +++ b/gst-libs/gst/vaapi/meson.build @@ -32,6 +32,7 @@ gstlibvaapi_sources = [ 'gstvaapiutils_core.c', 'gstvaapiutils_h264.c', 'gstvaapiutils_h265.c', + 'gstvaapiutils_h26x.c', 'gstvaapiutils_mpeg2.c', 'gstvaapivalue.c', 'gstvaapivideopool.c',