libs: utils: h26x: create vaapiutils_h26x

Since there is duplicated code in h264/265 encoder, we could
refactor it to avoid duplicated code.

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

Signed-off-by: Víctor Manuel Jáquez Leal <victorx.jaquez@intel.com>
This commit is contained in:
Hyunjun Ko 2017-03-17 16:49:41 +09:00 committed by Víctor Manuel Jáquez Leal
parent 257cfb61fe
commit 49b370ed60
6 changed files with 145 additions and 150 deletions

View file

@ -78,6 +78,7 @@ libgstvaapi_source_c = \
gstvaapiutils_core.c \ gstvaapiutils_core.c \
gstvaapiutils_h264.c \ gstvaapiutils_h264.c \
gstvaapiutils_h265.c \ gstvaapiutils_h265.c \
gstvaapiutils_h26x.c \
gstvaapiutils_mpeg2.c \ gstvaapiutils_mpeg2.c \
gstvaapivalue.c \ gstvaapivalue.c \
gstvaapivideopool.c \ gstvaapivideopool.c \
@ -142,6 +143,7 @@ libgstvaapi_source_priv_h = \
gstvaapiutils_core.h \ gstvaapiutils_core.h \
gstvaapiutils_h264_priv.h \ gstvaapiutils_h264_priv.h \
gstvaapiutils_h265_priv.h \ gstvaapiutils_h265_priv.h \
gstvaapiutils_h26x_priv.h \
gstvaapiutils_mpeg2_priv.h \ gstvaapiutils_mpeg2_priv.h \
gstvaapivideopool_priv.h \ gstvaapivideopool_priv.h \
gstvaapiwindow_priv.h \ gstvaapiwindow_priv.h \

View file

@ -36,6 +36,7 @@
#include "gstvaapiencoder_h264.h" #include "gstvaapiencoder_h264.h"
#include "gstvaapiutils_h264.h" #include "gstvaapiutils_h264.h"
#include "gstvaapiutils_h264_priv.h" #include "gstvaapiutils_h264_priv.h"
#include "gstvaapiutils_h26x_priv.h"
#include "gstvaapicodedbufferproxy_priv.h" #include "gstvaapicodedbufferproxy_priv.h"
#include "gstvaapisurface.h" #include "gstvaapisurface.h"
@ -49,21 +50,6 @@
/* Define the maximum value for view-id */ /* Define the maximum value for view-id */
#define MAX_VIEW_ID 1023 #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 */ /* Supported set of VA rate controls, within this implementation */
#define SUPPORTED_RATECONTROLS \ #define SUPPORTED_RATECONTROLS \
(GST_VAAPI_RATECONTROL_MASK (CQP) | \ (GST_VAAPI_RATECONTROL_MASK (CQP) | \
@ -200,66 +186,6 @@ h264_get_cpb_nal_factor (GstVaapiProfile profile)
return f; 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 */ /* Write the NAL unit header */
static gboolean static gboolean
bs_write_nal_header (GstBitWriter * bs, guint32 nal_ref_idc, bs_write_nal_header (GstBitWriter * bs, guint32 nal_ref_idc,

View file

@ -36,27 +36,13 @@
#include "gstvaapiencoder_h265.h" #include "gstvaapiencoder_h265.h"
#include "gstvaapiutils_h265.h" #include "gstvaapiutils_h265.h"
#include "gstvaapiutils_h265_priv.h" #include "gstvaapiutils_h265_priv.h"
#include "gstvaapiutils_h26x_priv.h"
#include "gstvaapicodedbufferproxy_priv.h" #include "gstvaapicodedbufferproxy_priv.h"
#include "gstvaapisurface.h" #include "gstvaapisurface.h"
#define DEBUG 1 #define DEBUG 1
#include "gstvaapidebug.h" #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 */ /* Supported set of VA rate controls, within this implementation */
#define SUPPORTED_RATECONTROLS \ #define SUPPORTED_RATECONTROLS \
(GST_VAAPI_RATECONTROL_MASK (CQP)) | \ (GST_VAAPI_RATECONTROL_MASK (CQP)) | \
@ -205,66 +191,6 @@ h265_get_log2_max_pic_order_cnt (guint num)
return ret; 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 */ /* Write the NAL unit header */
static gboolean static gboolean
bs_write_nal_header (GstBitWriter * bs, guint32 nal_unit_type) bs_write_nal_header (GstBitWriter * bs, guint32 nal_unit_type)

View file

@ -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;
}

View file

@ -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 <gst/base/gstbitwriter.h>
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 */

View file

@ -32,6 +32,7 @@ gstlibvaapi_sources = [
'gstvaapiutils_core.c', 'gstvaapiutils_core.c',
'gstvaapiutils_h264.c', 'gstvaapiutils_h264.c',
'gstvaapiutils_h265.c', 'gstvaapiutils_h265.c',
'gstvaapiutils_h26x.c',
'gstvaapiutils_mpeg2.c', 'gstvaapiutils_mpeg2.c',
'gstvaapivalue.c', 'gstvaapivalue.c',
'gstvaapivideopool.c', 'gstvaapivideopool.c',