Coverage Report

Created: 2025-07-23 07:11

/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
179k
#define PROFILE_H264_HIGH                 100
35
160k
#define PROFILE_H264_HIGH_10              110
36
159k
#define PROFILE_H264_HIGH_422             122
37
158k
#define PROFILE_H264_HIGH_444             144
38
154k
#define PROFILE_H264_HIGH_444_PREDICTIVE  244
39
40
203k
#define PROFILE_H264_CAVLC_INTRA          44
41
148k
#define PROFILE_H264_SVC_BASELINE         83
42
147k
#define PROFILE_H264_SVC_HIGH             86
43
144k
#define PROFILE_H264_MVC_STEREO_HIGH      128
44
147k
#define PROFILE_H264_MVC_MULTIVIEW_HIGH   118
45
46
53.5k
#define PROFILE_H264_MFC_HIGH                          134
47
144k
#define PROFILE_H264_MVC_MULTIVIEW_DEPTH_HIGH          138
48
143k
#define PROFILE_H264_MVC_ENHANCED_MULTIVIEW_DEPTH_HIGH 139
49
50
5.38M
#define H264_SPS_ID_MAX (31)
51
42.7M
#define H264_PPS_ID_MAX (255)
52
906k
#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
1.19M
{
85
1.19M
    return (enum h264_nal_unit_type_e) (*p & 0x1f);
86
1.19M
}
avi.c:h264_getNALType
Line
Count
Source
84
332
{
85
332
    return (enum h264_nal_unit_type_e) (*p & 0x1f);
86
332
}
Unexecuted instantiation: h26x.c:h264_getNALType
h264.c:h264_getNALType
Line
Count
Source
84
970k
{
85
970k
    return (enum h264_nal_unit_type_e) (*p & 0x1f);
86
970k
}
h264_nal.c:h264_getNALType
Line
Count
Source
84
223k
{
85
223k
    return (enum h264_nal_unit_type_e) (*p & 0x1f);
86
223k
}
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
bool h264_get_xps_id(const uint8_t *p_nalbuf, size_t i_nalbuf, uint8_t *pi_id);
93
94
h264_sequence_parameter_set_t * h264_decode_sps( const uint8_t *, size_t, bool );
95
h264_picture_parameter_set_t *  h264_decode_pps( const uint8_t *, size_t, bool );
96
h264_sequence_parameter_set_extension_t * h264_decode_sps_extension( const uint8_t *, size_t, bool );
97
98
void h264_release_sps( h264_sequence_parameter_set_t * );
99
void h264_release_pps( h264_picture_parameter_set_t * );
100
void h264_release_sps_extension( h264_sequence_parameter_set_extension_t * );
101
102
uint8_t h264_get_sps_id( const h264_sequence_parameter_set_t * );
103
uint8_t h264_get_pps_sps_id( const h264_picture_parameter_set_t * );
104
105
struct h264_sequence_parameter_set_t
106
{
107
    uint8_t i_id;
108
    uint8_t i_profile, i_level;
109
    uint8_t i_constraint_set_flags;
110
    /* according to avcC, 3 bits max for those */
111
    uint8_t i_chroma_idc;
112
    uint8_t i_bit_depth_luma;
113
    uint8_t i_bit_depth_chroma;
114
    uint8_t b_separate_colour_planes_flag;
115
116
    uint32_t pic_width_in_mbs_minus1;
117
    uint32_t pic_height_in_map_units_minus1;
118
    struct
119
    {
120
        uint32_t left_offset;
121
        uint32_t right_offset;
122
        uint32_t top_offset;
123
        uint32_t bottom_offset;
124
    } frame_crop;
125
    uint8_t frame_mbs_only_flag;
126
    uint8_t mb_adaptive_frame_field_flag;
127
    int i_log2_max_frame_num;
128
    int i_pic_order_cnt_type;
129
    int i_delta_pic_order_always_zero_flag;
130
    int32_t offset_for_non_ref_pic;
131
    int32_t offset_for_top_to_bottom_field;
132
    int i_num_ref_frames_in_pic_order_cnt_cycle;
133
    int32_t offset_for_ref_frame[255];
134
    int i_log2_max_pic_order_cnt_lsb;
135
136
    bool vui_parameters_present_flag;
137
    struct {
138
        int i_sar_num, i_sar_den;
139
        struct {
140
            bool b_full_range;
141
            uint8_t i_colour_primaries;
142
            uint8_t i_transfer_characteristics;
143
            uint8_t i_matrix_coefficients;
144
        } colour;
145
        bool b_timing_info_present_flag;
146
        uint32_t i_num_units_in_tick;
147
        uint32_t i_time_scale;
148
        bool b_fixed_frame_rate;
149
        bool b_pic_struct_present_flag;
150
        bool b_hrd_parameters_present_flag; /* CpbDpbDelaysPresentFlag */
151
        uint8_t i_cpb_removal_delay_length_minus1;
152
        uint8_t i_dpb_output_delay_length_minus1;
153
154
        /* restrictions */
155
        uint8_t b_bitstream_restriction_flag;
156
        uint8_t i_max_num_reorder_frames;
157
        uint8_t i_max_dec_frame_buffering;
158
    } vui;
159
};
160
161
struct h264_picture_parameter_set_t
162
{
163
    uint8_t i_id;
164
    uint8_t i_sps_id;
165
    uint8_t i_pic_order_present_flag;
166
    uint8_t i_redundant_pic_present_flag;
167
    uint8_t weighted_pred_flag;
168
    uint8_t weighted_bipred_idc;
169
    uint32_t num_ref_idx_l01_default_active_minus1[2];
170
};
171
172
struct h264_sequence_parameter_set_extension_t
173
{
174
    uint8_t i_sps_id;
175
};
176
177
/*
178
    AnnexB : [\x00] \x00 \x00 \x01 Prefixed NAL
179
    AVC Sample format : NalLengthSize encoded size prefixed NAL
180
    avcC: AVCDecoderConfigurationRecord combining SPS & PPS in AVC Sample Format
181
*/
182
183
0
#define H264_MIN_AVCC_SIZE 7
184
185
bool h264_isavcC( const uint8_t *, size_t );
186
187
/* Convert AVC Sample format to Annex B in-place */
188
void h264_AVC_to_AnnexB( uint8_t *p_buf, uint32_t i_len,
189
                         uint8_t i_nal_length_size );
190
191
/* Get the First SPS/PPS NAL pointers from an Annex B buffer
192
 * Returns TRUE if a SPS and/or a PPS is found */
193
bool h264_AnnexB_get_spspps( const uint8_t *p_buf, size_t i_buf,
194
                             const uint8_t **pp_sps, size_t *p_sps_size,
195
                             const uint8_t **pp_pps, size_t *p_pps_size,
196
                             const uint8_t **pp_ext, size_t *p_ext_size );
197
198
/* Create a AVCDecoderConfigurationRecord from non prefixed SPS/PPS
199
 * Returns a valid block_t on success, must be freed with block_Release */
200
block_t *h264_NAL_to_avcC( uint8_t i_nal_length_size,
201
                           const uint8_t **pp_sps_buf,
202
                           const size_t *p_sps_size, uint8_t i_sps_count,
203
                           const uint8_t **pp_pps_buf,
204
                           const size_t *p_pps_size, uint8_t i_pps_count,
205
                           const uint8_t **pp_sps_ext_buf,
206
                           const size_t *p_sps_ext_size, uint8_t i_sps_ext_count);
207
208
/* Convert AVCDecoderConfigurationRecord SPS/PPS to Annex B format */
209
uint8_t * h264_avcC_to_AnnexB_NAL( const uint8_t *p_buf, size_t i_buf,
210
                                   size_t *pi_result, uint8_t *pi_nal_length_size );
211
212
bool h264_get_dpb_values( const h264_sequence_parameter_set_t *,
213
                          uint8_t *pi_max_num_reorder, uint8_t *pi_max_dec_buffering );
214
215
unsigned h264_get_max_frame_num( const h264_sequence_parameter_set_t * );
216
bool h264_is_frames_only( const h264_sequence_parameter_set_t * );
217
bool h264_using_adaptive_frames( const h264_sequence_parameter_set_t * );
218
219
bool h264_get_sps_profile_tier_level( const h264_sequence_parameter_set_t *,
220
                                     uint8_t *pi_profile, uint8_t *pi_level );
221
bool h264_get_picture_size( const h264_sequence_parameter_set_t *,
222
                            unsigned *p_ox, unsigned *p_oy,
223
                            unsigned *p_w, unsigned *p_h,
224
                            unsigned *p_vw, unsigned *p_vh );
225
bool h264_get_frame_rate( const h264_sequence_parameter_set_t *,
226
                          unsigned *pi_num, unsigned *pi_den );
227
bool h264_get_aspect_ratio( const h264_sequence_parameter_set_t *,
228
                           unsigned *pi_num, unsigned *pi_den );
229
bool h264_get_chroma_luma( const h264_sequence_parameter_set_t *, uint8_t *pi_chroma_format,
230
                           uint8_t *pi_depth_luma, uint8_t *pi_depth_chroma );
231
bool h264_get_colorimetry( const h264_sequence_parameter_set_t *p_sps,
232
                           video_color_primaries_t *p_primaries,
233
                           video_transfer_func_t *p_transfer,
234
                           video_color_space_t *p_colorspace,
235
                           video_color_range_t *p_full_range );
236
237
/* Get level and Profile from DecoderConfigurationRecord */
238
bool h264_get_profile_level(const es_format_t *p_fmt, uint8_t *pi_profile,
239
                            uint8_t *pi_level, uint8_t *p_nal_length_size);
240
241
typedef struct
242
{
243
    unsigned i_frames;
244
} h264_sei_recovery_point_t;
245
246
bool h264_decode_sei_recovery_point( bs_t *, h264_sei_recovery_point_t * );
247
bool h264_decode_sei_pic_timing(  bs_t *, const h264_sequence_parameter_set_t *,
248
                                  uint8_t *, uint8_t *  );
249
250
251
#ifdef __cplusplus
252
}
253
#endif
254
255
#endif /* H264_NAL_H */