Coverage Report

Created: 2026-05-21 08:06

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vlc/modules/packetizer/h264_nal.h
Line
Count
Source
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
370k
#define PROFILE_H264_HIGH                 100
35
354k
#define PROFILE_H264_HIGH_10              110
36
343k
#define PROFILE_H264_HIGH_422             122
37
341k
#define PROFILE_H264_HIGH_444             144
38
334k
#define PROFILE_H264_HIGH_444_PREDICTIVE  244
39
40
464k
#define PROFILE_H264_CAVLC_INTRA          44
41
326k
#define PROFILE_H264_SVC_BASELINE         83
42
324k
#define PROFILE_H264_SVC_HIGH             86
43
319k
#define PROFILE_H264_MVC_STEREO_HIGH      128
44
322k
#define PROFILE_H264_MVC_MULTIVIEW_HIGH   118
45
46
126k
#define PROFILE_H264_MFC_HIGH                          134
47
313k
#define PROFILE_H264_MVC_MULTIVIEW_DEPTH_HIGH          138
48
312k
#define PROFILE_H264_MVC_ENHANCED_MULTIVIEW_DEPTH_HIGH 139
49
50
21.2M
#define H264_SPS_ID_MAX (31)
51
130M
#define H264_PPS_ID_MAX (255)
52
4.56M
#define H264_SPSEXT_ID_MAX H264_SPS_ID_MAX
53
4.54M
#define H264_MAX_NUM_SPS (H264_SPS_ID_MAX + 1)
54
35.3M
#define H264_MAX_NUM_PPS (H264_PPS_ID_MAX + 1)
55
4.54M
#define H264_MAX_NUM_SPSEXT (H264_SPSEXT_ID_MAX + 1)
56
57
58
enum h264_nal_unit_type_e
59
{
60
    H264_NAL_UNKNOWN = 0,
61
    H264_NAL_SLICE   = 1,
62
    H264_NAL_SLICE_DPA   = 2,
63
    H264_NAL_SLICE_DPB   = 3,
64
    H264_NAL_SLICE_DPC   = 4,
65
    H264_NAL_SLICE_IDR   = 5,    /* ref_idc != 0 */
66
    H264_NAL_SEI         = 6,    /* ref_idc == 0 */
67
    H264_NAL_SPS         = 7,
68
    H264_NAL_PPS         = 8,
69
    H264_NAL_AU_DELIMITER= 9,
70
    /* ref_idc == 0 for 6,9,10,11,12 */
71
    H264_NAL_END_OF_SEQ  = 10,
72
    H264_NAL_END_OF_STREAM = 11,
73
    H264_NAL_FILLER_DATA = 12,
74
    H264_NAL_SPS_EXT     = 13,
75
    H264_NAL_PREFIX      = 14,
76
    H264_NAL_SUBSET_SPS  = 15,
77
    H264_NAL_DEPTH_PS    = 16,
78
    H264_NAL_RESERVED_17 = 17,
79
    H264_NAL_RESERVED_18 = 18,
80
    H264_NAL_SLICE_WP    = 19,
81
    H264_NAL_SLICE_EXT   = 20,
82
    H264_NAL_SLICE_3D_EXT= 21,
83
    H264_NAL_RESERVED_22 = 22,
84
    H264_NAL_RESERVED_23 = 23,
85
};
86
87
static inline enum h264_nal_unit_type_e h264_getNALType(const uint8_t *p)
88
3.80M
{
89
3.80M
    return (enum h264_nal_unit_type_e) (*p & 0x1f);
90
3.80M
}
avi.c:h264_getNALType
Line
Count
Source
88
25
{
89
25
    return (enum h264_nal_unit_type_e) (*p & 0x1f);
90
25
}
Unexecuted instantiation: h26x.c:h264_getNALType
h264.c:h264_getNALType
Line
Count
Source
88
3.11M
{
89
3.11M
    return (enum h264_nal_unit_type_e) (*p & 0x1f);
90
3.11M
}
h264_nal.c:h264_getNALType
Line
Count
Source
88
695k
{
89
695k
    return (enum h264_nal_unit_type_e) (*p & 0x1f);
90
695k
}
Unexecuted instantiation: h264_slice.c:h264_getNALType
91
92
typedef struct h264_sequence_parameter_set_t h264_sequence_parameter_set_t;
93
typedef struct h264_picture_parameter_set_t h264_picture_parameter_set_t;
94
typedef struct h264_sequence_parameter_set_extension_t h264_sequence_parameter_set_extension_t;
95
96
bool h264_get_xps_id(const uint8_t *p_nalbuf, size_t i_nalbuf, uint8_t *pi_id);
97
98
h264_sequence_parameter_set_t * h264_decode_sps( const uint8_t *, size_t, bool );
99
h264_picture_parameter_set_t *  h264_decode_pps( const uint8_t *, size_t, bool );
100
h264_sequence_parameter_set_extension_t * h264_decode_sps_extension( const uint8_t *, size_t, bool );
101
102
void h264_release_sps( h264_sequence_parameter_set_t * );
103
void h264_release_pps( h264_picture_parameter_set_t * );
104
void h264_release_sps_extension( h264_sequence_parameter_set_extension_t * );
105
106
uint8_t h264_get_sps_id( const h264_sequence_parameter_set_t * );
107
uint8_t h264_get_pps_sps_id( const h264_picture_parameter_set_t * );
108
109
struct h264_sequence_parameter_set_t
110
{
111
    uint8_t i_id;
112
    uint8_t i_profile, i_level;
113
    uint8_t i_constraint_set_flags;
114
    /* according to avcC, 3 bits max for those */
115
    uint8_t i_chroma_idc;
116
    uint8_t i_bit_depth_luma;
117
    uint8_t i_bit_depth_chroma;
118
    uint8_t b_separate_colour_planes_flag;
119
120
    uint32_t pic_width_in_mbs_minus1;
121
    uint32_t pic_height_in_map_units_minus1;
122
    struct
123
    {
124
        uint32_t left_offset;
125
        uint32_t right_offset;
126
        uint32_t top_offset;
127
        uint32_t bottom_offset;
128
    } frame_crop;
129
    uint8_t frame_mbs_only_flag;
130
    uint8_t mb_adaptive_frame_field_flag;
131
    int i_log2_max_frame_num;
132
    int i_pic_order_cnt_type;
133
    int i_delta_pic_order_always_zero_flag;
134
    int32_t offset_for_non_ref_pic;
135
    int32_t offset_for_top_to_bottom_field;
136
    int i_num_ref_frames_in_pic_order_cnt_cycle;
137
    int32_t offset_for_ref_frame[255];
138
    int i_log2_max_pic_order_cnt_lsb;
139
140
    bool vui_parameters_present_flag;
141
    struct {
142
        int i_sar_num, i_sar_den;
143
        struct {
144
            bool b_full_range;
145
            uint8_t i_colour_primaries;
146
            uint8_t i_transfer_characteristics;
147
            uint8_t i_matrix_coefficients;
148
        } colour;
149
        bool b_timing_info_present_flag;
150
        uint32_t i_num_units_in_tick;
151
        uint32_t i_time_scale;
152
        bool b_fixed_frame_rate;
153
        bool b_pic_struct_present_flag;
154
        bool b_hrd_parameters_present_flag; /* CpbDpbDelaysPresentFlag */
155
        uint8_t i_cpb_removal_delay_length_minus1;
156
        uint8_t i_dpb_output_delay_length_minus1;
157
158
        /* restrictions */
159
        uint8_t b_bitstream_restriction_flag;
160
        uint8_t i_max_num_reorder_frames;
161
        uint8_t i_max_dec_frame_buffering;
162
    } vui;
163
};
164
165
struct h264_picture_parameter_set_t
166
{
167
    uint8_t i_id;
168
    uint8_t i_sps_id;
169
    uint8_t i_pic_order_present_flag;
170
    uint8_t i_redundant_pic_present_flag;
171
    uint8_t weighted_pred_flag;
172
    uint8_t weighted_bipred_idc;
173
    uint32_t num_ref_idx_l01_default_active_minus1[2];
174
};
175
176
struct h264_sequence_parameter_set_extension_t
177
{
178
    uint8_t i_sps_id;
179
};
180
181
/*
182
    AnnexB : [\x00] \x00 \x00 \x01 Prefixed NAL
183
    AVC Sample format : NalLengthSize encoded size prefixed NAL
184
    avcC: AVCDecoderConfigurationRecord combining SPS & PPS in AVC Sample Format
185
*/
186
187
0
#define H264_MIN_AVCC_SIZE 7
188
189
bool h264_isavcC( const uint8_t *, size_t );
190
191
/* Convert AVC Sample format to Annex B in-place */
192
void h264_AVC_to_AnnexB( uint8_t *p_buf, uint32_t i_len,
193
                         uint8_t i_nal_length_size );
194
195
/* Get the First SPS/PPS NAL pointers from an Annex B buffer
196
 * Returns TRUE if a SPS and/or a PPS is found */
197
bool h264_AnnexB_get_spspps( const uint8_t *p_buf, size_t i_buf,
198
                             const uint8_t **pp_sps, size_t *p_sps_size,
199
                             const uint8_t **pp_pps, size_t *p_pps_size,
200
                             const uint8_t **pp_ext, size_t *p_ext_size );
201
202
/* Create a AVCDecoderConfigurationRecord from non prefixed SPS/PPS
203
 * Returns a valid block_t on success, must be freed with block_Release */
204
block_t *h264_NAL_to_avcC( uint8_t i_nal_length_size,
205
                           const uint8_t **pp_sps_buf,
206
                           const size_t *p_sps_size, uint8_t i_sps_count,
207
                           const uint8_t **pp_pps_buf,
208
                           const size_t *p_pps_size, uint8_t i_pps_count,
209
                           const uint8_t **pp_sps_ext_buf,
210
                           const size_t *p_sps_ext_size, uint8_t i_sps_ext_count);
211
212
/* Convert AVCDecoderConfigurationRecord SPS/PPS to Annex B format */
213
bool h264_avcC_to_AnnexB_NAL( const uint8_t *p_buf, size_t i_buf,
214
                              uint8_t **pp_result, size_t *pi_result,
215
                              uint8_t *pi_nal_length_size );
216
217
bool h264_get_dpb_values( const h264_sequence_parameter_set_t *,
218
                          uint8_t *pi_max_num_reorder, uint8_t *pi_max_dec_buffering );
219
220
unsigned h264_get_max_frame_num( const h264_sequence_parameter_set_t * );
221
bool h264_is_frames_only( const h264_sequence_parameter_set_t * );
222
bool h264_using_adaptive_frames( const h264_sequence_parameter_set_t * );
223
224
bool h264_get_sps_profile_tier_level( const h264_sequence_parameter_set_t *,
225
                                     uint8_t *pi_profile, uint8_t *pi_level );
226
bool h264_get_picture_size( const h264_sequence_parameter_set_t *,
227
                            unsigned *p_ox, unsigned *p_oy,
228
                            unsigned *p_w, unsigned *p_h,
229
                            unsigned *p_vw, unsigned *p_vh );
230
bool h264_get_frame_rate( const h264_sequence_parameter_set_t *,
231
                          unsigned *pi_num, unsigned *pi_den );
232
bool h264_get_aspect_ratio( const h264_sequence_parameter_set_t *,
233
                           unsigned *pi_num, unsigned *pi_den );
234
bool h264_get_chroma_luma( const h264_sequence_parameter_set_t *, uint8_t *pi_chroma_format,
235
                           uint8_t *pi_depth_luma, uint8_t *pi_depth_chroma );
236
bool h264_get_colorimetry( const h264_sequence_parameter_set_t *p_sps,
237
                           video_color_primaries_t *p_primaries,
238
                           video_transfer_func_t *p_transfer,
239
                           video_color_space_t *p_colorspace,
240
                           video_color_range_t *p_full_range );
241
242
/* Get level and Profile from DecoderConfigurationRecord */
243
bool h264_get_profile_level(const es_format_t *p_fmt, uint8_t *pi_profile,
244
                            uint8_t *pi_level, uint8_t *p_nal_length_size);
245
246
typedef struct
247
{
248
    unsigned i_frames;
249
} h264_sei_recovery_point_t;
250
251
bool h264_decode_sei_recovery_point( bs_t *, h264_sei_recovery_point_t * );
252
bool h264_decode_sei_pic_timing(  bs_t *, const h264_sequence_parameter_set_t *,
253
                                  uint8_t *, uint8_t *  );
254
255
256
#ifdef __cplusplus
257
}
258
#endif
259
260
#endif /* H264_NAL_H */