Coverage Report

Created: 2023-06-07 06:30

/src/vlc/modules/packetizer/h264_nal.h
Line
Count
Source (jump to first uncovered line)
1
/*****************************************************************************
2
 * Copyright © 2010-2014 VideoLAN
3
 *
4
 * Authors: Jean-Baptiste Kempf <jb@videolan.org>
5
 *
6
 * This program is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU Lesser General Public License as published by
8
 * the Free Software Foundation; either version 2.1 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public License
17
 * along with this program; if not, write to the Free Software Foundation,
18
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19
 *****************************************************************************/
20
#ifndef H264_NAL_H
21
# define H264_NAL_H
22
23
# include <vlc_common.h>
24
# include <vlc_es.h>
25
# include <vlc_bits.h>
26
27
#ifdef __cplusplus
28
extern "C" {
29
#endif
30
31
0
#define PROFILE_H264_BASELINE             66
32
#define PROFILE_H264_MAIN                 77
33
#define PROFILE_H264_EXTENDED             88
34
0
#define PROFILE_H264_HIGH                 100
35
0
#define PROFILE_H264_HIGH_10              110
36
0
#define PROFILE_H264_HIGH_422             122
37
0
#define PROFILE_H264_HIGH_444             144
38
0
#define PROFILE_H264_HIGH_444_PREDICTIVE  244
39
40
0
#define PROFILE_H264_CAVLC_INTRA          44
41
0
#define PROFILE_H264_SVC_BASELINE         83
42
0
#define PROFILE_H264_SVC_HIGH             86
43
0
#define PROFILE_H264_MVC_STEREO_HIGH      128
44
0
#define PROFILE_H264_MVC_MULTIVIEW_HIGH   118
45
46
0
#define PROFILE_H264_MFC_HIGH                          134
47
0
#define PROFILE_H264_MVC_MULTIVIEW_DEPTH_HIGH          138
48
0
#define PROFILE_H264_MVC_ENHANCED_MULTIVIEW_DEPTH_HIGH 139
49
50
0
#define H264_SPS_ID_MAX (31)
51
0
#define H264_PPS_ID_MAX (255)
52
0
#define H264_SPSEXT_ID_MAX H264_SPS_ID_MAX
53
54
enum h264_nal_unit_type_e
55
{
56
    H264_NAL_UNKNOWN = 0,
57
    H264_NAL_SLICE   = 1,
58
    H264_NAL_SLICE_DPA   = 2,
59
    H264_NAL_SLICE_DPB   = 3,
60
    H264_NAL_SLICE_DPC   = 4,
61
    H264_NAL_SLICE_IDR   = 5,    /* ref_idc != 0 */
62
    H264_NAL_SEI         = 6,    /* ref_idc == 0 */
63
    H264_NAL_SPS         = 7,
64
    H264_NAL_PPS         = 8,
65
    H264_NAL_AU_DELIMITER= 9,
66
    /* ref_idc == 0 for 6,9,10,11,12 */
67
    H264_NAL_END_OF_SEQ  = 10,
68
    H264_NAL_END_OF_STREAM = 11,
69
    H264_NAL_FILLER_DATA = 12,
70
    H264_NAL_SPS_EXT     = 13,
71
    H264_NAL_PREFIX      = 14,
72
    H264_NAL_SUBSET_SPS  = 15,
73
    H264_NAL_DEPTH_PS    = 16,
74
    H264_NAL_RESERVED_17 = 17,
75
    H264_NAL_RESERVED_18 = 18,
76
    H264_NAL_SLICE_WP    = 19,
77
    H264_NAL_SLICE_EXT   = 20,
78
    H264_NAL_SLICE_3D_EXT= 21,
79
    H264_NAL_RESERVED_22 = 22,
80
    H264_NAL_RESERVED_23 = 23,
81
};
82
83
static inline enum h264_nal_unit_type_e h264_getNALType(const uint8_t *p)
84
0
{
85
0
    return (enum h264_nal_unit_type_e) (*p & 0x1f);
86
0
}
Unexecuted instantiation: avi.c:h264_getNALType
Unexecuted instantiation: h26x.c:h264_getNALType
Unexecuted instantiation: h264.c:h264_getNALType
Unexecuted instantiation: h264_nal.c:h264_getNALType
Unexecuted instantiation: h264_slice.c:h264_getNALType
87
88
typedef struct h264_sequence_parameter_set_t h264_sequence_parameter_set_t;
89
typedef struct h264_picture_parameter_set_t h264_picture_parameter_set_t;
90
typedef struct h264_sequence_parameter_set_extension_t h264_sequence_parameter_set_extension_t;
91
92
h264_sequence_parameter_set_t * h264_decode_sps( const uint8_t *, size_t, bool );
93
h264_picture_parameter_set_t *  h264_decode_pps( const uint8_t *, size_t, bool );
94
h264_sequence_parameter_set_extension_t * h264_decode_sps_extension( const uint8_t *, size_t, bool );
95
96
void h264_release_sps( h264_sequence_parameter_set_t * );
97
void h264_release_pps( h264_picture_parameter_set_t * );
98
void h264_release_sps_extension( h264_sequence_parameter_set_extension_t * );
99
100
struct h264_sequence_parameter_set_t
101
{
102
    uint8_t i_id;
103
    uint8_t i_profile, i_level;
104
    uint8_t i_constraint_set_flags;
105
    /* according to avcC, 3 bits max for those */
106
    uint8_t i_chroma_idc;
107
    uint8_t i_bit_depth_luma;
108
    uint8_t i_bit_depth_chroma;
109
    uint8_t b_separate_colour_planes_flag;
110
111
    uint32_t pic_width_in_mbs_minus1;
112
    uint32_t pic_height_in_map_units_minus1;
113
    struct
114
    {
115
        uint32_t left_offset;
116
        uint32_t right_offset;
117
        uint32_t top_offset;
118
        uint32_t bottom_offset;
119
    } frame_crop;
120
    uint8_t frame_mbs_only_flag;
121
    uint8_t mb_adaptive_frame_field_flag;
122
    int i_log2_max_frame_num;
123
    int i_pic_order_cnt_type;
124
    int i_delta_pic_order_always_zero_flag;
125
    int32_t offset_for_non_ref_pic;
126
    int32_t offset_for_top_to_bottom_field;
127
    int i_num_ref_frames_in_pic_order_cnt_cycle;
128
    int32_t offset_for_ref_frame[255];
129
    int i_log2_max_pic_order_cnt_lsb;
130
131
    struct {
132
        bool b_valid;
133
        int i_sar_num, i_sar_den;
134
        struct {
135
            bool b_full_range;
136
            uint8_t i_colour_primaries;
137
            uint8_t i_transfer_characteristics;
138
            uint8_t i_matrix_coefficients;
139
        } colour;
140
        bool b_timing_info_present_flag;
141
        uint32_t i_num_units_in_tick;
142
        uint32_t i_time_scale;
143
        bool b_fixed_frame_rate;
144
        bool b_pic_struct_present_flag;
145
        bool b_hrd_parameters_present_flag; /* CpbDpbDelaysPresentFlag */
146
        uint8_t i_cpb_removal_delay_length_minus1;
147
        uint8_t i_dpb_output_delay_length_minus1;
148
149
        /* restrictions */
150
        uint8_t b_bitstream_restriction_flag;
151
        uint8_t i_max_num_reorder_frames;
152
    } vui;
153
};
154
155
struct h264_picture_parameter_set_t
156
{
157
    uint8_t i_id;
158
    uint8_t i_sps_id;
159
    uint8_t i_pic_order_present_flag;
160
    uint8_t i_redundant_pic_present_flag;
161
    uint8_t weighted_pred_flag;
162
    uint8_t weighted_bipred_idc;
163
};
164
165
struct h264_sequence_parameter_set_extension_t
166
{
167
    uint8_t i_sps_id;
168
};
169
170
/*
171
    AnnexB : [\x00] \x00 \x00 \x01 Prefixed NAL
172
    AVC Sample format : NalLengthSize encoded size prefixed NAL
173
    avcC: AVCDecoderConfigurationRecord combining SPS & PPS in AVC Sample Format
174
*/
175
176
0
#define H264_MIN_AVCC_SIZE 7
177
178
bool h264_isavcC( const uint8_t *, size_t );
179
180
/* Convert AVC Sample format to Annex B in-place */
181
void h264_AVC_to_AnnexB( uint8_t *p_buf, uint32_t i_len,
182
                         uint8_t i_nal_length_size );
183
184
/* Get the First SPS/PPS NAL pointers from an Annex B buffer
185
 * Returns TRUE if a SPS and/or a PPS is found */
186
bool h264_AnnexB_get_spspps( const uint8_t *p_buf, size_t i_buf,
187
                             const uint8_t **pp_sps, size_t *p_sps_size,
188
                             const uint8_t **pp_pps, size_t *p_pps_size,
189
                             const uint8_t **pp_ext, size_t *p_ext_size );
190
191
/* Create a AVCDecoderConfigurationRecord from non prefixed SPS/PPS
192
 * Returns a valid block_t on success, must be freed with block_Release */
193
block_t *h264_NAL_to_avcC( uint8_t i_nal_length_size,
194
                           const uint8_t **pp_sps_buf,
195
                           const size_t *p_sps_size, uint8_t i_sps_count,
196
                           const uint8_t **pp_pps_buf,
197
                           const size_t *p_pps_size, uint8_t i_pps_count,
198
                           const uint8_t **pp_sps_ext_buf,
199
                           const size_t *p_sps_ext_size, uint8_t i_sps_ext_count);
200
201
/* Convert AVCDecoderConfigurationRecord SPS/PPS to Annex B format */
202
uint8_t * h264_avcC_to_AnnexB_NAL( const uint8_t *p_buf, size_t i_buf,
203
                                   size_t *pi_result, uint8_t *pi_nal_length_size );
204
205
bool h264_get_dpb_values( const h264_sequence_parameter_set_t *,
206
                          uint8_t *pi_depth, unsigned *pi_delay );
207
208
bool h264_get_picture_size( const h264_sequence_parameter_set_t *, unsigned *p_w, unsigned *p_h,
209
                            unsigned *p_vw, unsigned *p_vh );
210
bool h264_get_chroma_luma( const h264_sequence_parameter_set_t *, uint8_t *pi_chroma_format,
211
                           uint8_t *pi_depth_luma, uint8_t *pi_depth_chroma );
212
bool h264_get_colorimetry( const h264_sequence_parameter_set_t *p_sps,
213
                           video_color_primaries_t *p_primaries,
214
                           video_transfer_func_t *p_transfer,
215
                           video_color_space_t *p_colorspace,
216
                           video_color_range_t *p_full_range );
217
218
/* Get level and Profile from DecoderConfigurationRecord */
219
bool h264_get_profile_level(const es_format_t *p_fmt, uint8_t *pi_profile,
220
                            uint8_t *pi_level, uint8_t *p_nal_length_size);
221
222
typedef struct
223
{
224
    unsigned i_frames;
225
} h264_sei_recovery_point_t;
226
227
bool h264_decode_sei_recovery_point( bs_t *, h264_sei_recovery_point_t * );
228
229
#ifdef __cplusplus
230
}
231
#endif
232
233
#endif /* H264_NAL_H */