1 /*
2  *  gstvaapiutils_h26x_priv.h - H.26x related utilities
3  *
4  *  Copyright (C) 2011-2014 Intel Corporation
5  *    Author: Gwenole Beauchesne
6  *  Copyright (C) 2017 Intel Corporation
7  *    Author: Hyunjun Ko <zzoon@igalia.com>
8  *
9  *  This library is free software; you can redistribute it and/or
10  *  modify it under the terms of the GNU Lesser General Public License
11  *  as published by the Free Software Foundation; either version 2.1
12  *  of the License, or (at your option) any later version.
13  *
14  *  This library is distributed in the hope that it will be useful,
15  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
16  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
17  *  Lesser General Public License for more details.
18  *
19  *  You should have received a copy of the GNU Lesser General Public
20  *  License along with this library; if not, write to the Free
21  *  Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
22  *  Boston, MA 02110-1301 USA
23  */
24 
25 #ifndef GST_VAAPI_UTILS_H26X_PRIV_H
26 #define GST_VAAPI_UTILS_H26X_PRIV_H
27 
28 #include <gst/base/gstbitwriter.h>
29 
30 G_BEGIN_DECLS
31 
32 /* Default CPB length (in milliseconds) */
33 #define DEFAULT_CPB_LENGTH 1500
34 
35 /* Scale factor for CPB size (HRD cpb_size_scale: min = 4) */
36 #define SX_CPB_SIZE 4
37 
38 /* Scale factor for bitrate (HRD bit_rate_scale: min = 6) */
39 #define SX_BITRATE 6
40 
41 /* Define default rate control mode ("constant-qp") */
42 #define DEFAULT_RATECONTROL GST_VAAPI_RATECONTROL_CQP
43 
44 /* ------------------------------------------------------------------------- */
45 /* --- H.264/265 Bitstream Writer                                            --- */
46 /* ------------------------------------------------------------------------- */
47 
48 #define WRITE_UINT32(bs, val, nbits)                            \
49   G_STMT_START {                                                \
50     if (!gst_bit_writer_put_bits_uint32 (bs, val, nbits)) {     \
51       GST_WARNING ("failed to write uint32, nbits: %d", nbits); \
52       goto bs_error;                                            \
53     }                                                           \
54   } G_STMT_END
55 
56 #define WRITE_UE(bs, val)                       \
57   G_STMT_START {                                \
58     if (!bs_write_ue (bs, val)) {               \
59       GST_WARNING ("failed to write ue(v)");    \
60       goto bs_error;                            \
61     }                                           \
62   } G_STMT_END
63 
64 #define WRITE_SE(bs, val)                       \
65   G_STMT_START {                                \
66     if (!bs_write_se (bs, val)) {               \
67       GST_WARNING ("failed to write se(v)");    \
68       goto bs_error;                            \
69     }                                           \
70   } G_STMT_END
71 
72 G_GNUC_INTERNAL
73 gboolean
74 bs_write_ue (GstBitWriter * bs, guint32 value);
75 
76 G_GNUC_INTERNAL
77 gboolean
78 bs_write_se (GstBitWriter * bs, gint32 value);
79 
80 /* Write nal unit, applying emulation prevention bytes */
81 G_GNUC_INTERNAL
82 gboolean
83 gst_vaapi_utils_h26x_write_nal_unit (GstBitWriter * bs, guint8 * nal, guint nal_size);
84 
85 G_END_DECLS
86 
87 #endif /* GST_VAAPI_UTILS_H26X_PRIV_H */
88