Coverage Report

Created: 2025-10-13 06:34

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libavc/decoder/ih264d_vui.c
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2015 The Android Open Source Project
4
 *
5
 * Licensed under the Apache License, Version 2.0 (the "License");
6
 * you may not use this file except in compliance with the License.
7
 * You may obtain a copy of the License at:
8
 *
9
 * http://www.apache.org/licenses/LICENSE-2.0
10
 *
11
 * Unless required by applicable law or agreed to in writing, software
12
 * distributed under the License is distributed on an "AS IS" BASIS,
13
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14
 * See the License for the specific language governing permissions and
15
 * limitations under the License.
16
 *
17
 *****************************************************************************
18
 * Originally developed and contributed by Ittiam Systems Pvt. Ltd, Bangalore
19
*/
20
21
/*****************************************************************************/
22
/*                                                                           */
23
/*  File Name         : ih264d_vui.c                                                */
24
/*                                                                           */
25
/*  Description       : This file contains routines to parse VUI NAL's       */
26
/*                                                                           */
27
/*  List of Functions : <List the functions defined in this file>            */
28
/*                                                                           */
29
/*  Issues / Problems : None                                                 */
30
/*                                                                           */
31
/*  Revision History  :                                                      */
32
/*                                                                           */
33
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
34
/*         25 05 2005   NS              Draft                                */
35
/*                                                                           */
36
/*****************************************************************************/
37
38
#include "ih264_typedefs.h"
39
#include "ih264_macros.h"
40
#include "ih264_platform_macros.h"
41
#include "ih264d_vui.h"
42
#include "ih264d_bitstrm.h"
43
#include "ih264d_parse_cavlc.h"
44
#include "ih264d_structs.h"
45
#include "ih264d_error_handler.h"
46
47
/*****************************************************************************/
48
/*                                                                           */
49
/*  Function Name : ih264d_parse_hrd_parametres                                     */
50
/*                                                                           */
51
/*  Description   : This function parses hrd_t parametres                      */
52
/*  Inputs        : ps_hrd          pointer to HRD params                    */
53
/*                  ps_bitstrm   Bitstream                                */
54
/*  Globals       : None                                                     */
55
/*  Processing    : Parses HRD params                                        */
56
/*  Outputs       : None                                                     */
57
/*  Returns       : None                                                     */
58
/*                                                                           */
59
/*  Issues        : None                                                     */
60
/*                                                                           */
61
/*  Revision History:                                                        */
62
/*                                                                           */
63
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
64
/*         06 05 2002   NS              Draft                                */
65
/*                                                                           */
66
/*****************************************************************************/
67
68
WORD32 ih264d_parse_hrd_parametres(hrd_t *ps_hrd,
69
                                   dec_bit_stream_t *ps_bitstrm)
70
4.30k
{
71
4.30k
    UWORD8 u1_index;
72
4.30k
    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
73
4.30k
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
74
75
4.30k
    ps_hrd->u4_cpb_cnt = 1
76
4.30k
                    + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
77
4.30k
    if(ps_hrd->u4_cpb_cnt > 31)
78
312
        return ERROR_INV_SPS_PPS_T;
79
3.98k
    ps_hrd->u1_bit_rate_scale = ih264d_get_bits_h264(ps_bitstrm, 4);
80
3.98k
    ps_hrd->u1_cpb_size_scale = ih264d_get_bits_h264(ps_bitstrm, 4);
81
82
15.0k
    for(u1_index = 0; u1_index < (UWORD8)ps_hrd->u4_cpb_cnt; u1_index++)
83
11.0k
    {
84
11.0k
        ps_hrd->u4_bit_rate[u1_index] = 1
85
11.0k
                        + ih264d_uev(pu4_bitstrm_ofst,
86
11.0k
                                     pu4_bitstrm_buf);
87
11.0k
        ps_hrd->u4_cpb_size[u1_index] = 1
88
11.0k
                        + ih264d_uev(pu4_bitstrm_ofst,
89
11.0k
                                     pu4_bitstrm_buf);
90
11.0k
        ps_hrd->u1_cbr_flag[u1_index] = ih264d_get_bits_h264(ps_bitstrm, 1);
91
11.0k
    }
92
93
3.98k
    ps_hrd->u1_initial_cpb_removal_delay = 1
94
3.98k
                    + ih264d_get_bits_h264(ps_bitstrm, 5);
95
3.98k
    ps_hrd->u1_cpb_removal_delay_length = 1
96
3.98k
                    + ih264d_get_bits_h264(ps_bitstrm, 5);
97
3.98k
    ps_hrd->u1_dpb_output_delay_length = 1
98
3.98k
                    + ih264d_get_bits_h264(ps_bitstrm, 5);
99
3.98k
    ps_hrd->u1_time_offset_length = ih264d_get_bits_h264(ps_bitstrm, 5);
100
101
3.98k
    return OK;
102
4.30k
}
103
104
/*****************************************************************************/
105
/*                                                                           */
106
/*  Function Name : ih264d_parse_vui_parametres                                     */
107
/*                                                                           */
108
/*  Description   : This function parses VUI NALs.                           */
109
/*  Inputs        : ps_vu4          pointer to VUI params                    */
110
/*                  ps_bitstrm   Bitstream                                */
111
/*  Globals       : None                                                     */
112
/*  Processing    : Parses VUI NAL's units and stores the info               */
113
/*  Outputs       : None                                                     */
114
/*  Returns       : None                                                     */
115
/*                                                                           */
116
/*  Issues        : None                                                     */
117
/*                                                                           */
118
/*  Revision History:                                                        */
119
/*                                                                           */
120
/*         DD MM YYYY   Author(s)       Changes (Describe the changes made)  */
121
/*         06 05 2002   NS              Draft                                */
122
/*                                                                           */
123
/*****************************************************************************/
124
125
WORD32 ih264d_parse_vui_parametres(vui_t *ps_vu4,
126
                                   dec_bit_stream_t *ps_bitstrm)
127
9.27k
{
128
9.27k
    UWORD8 u4_bits;
129
9.27k
    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
130
9.27k
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
131
9.27k
    WORD32 ret;
132
133
9.27k
    u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
134
9.27k
    if(u4_bits)
135
6.63k
    {
136
6.63k
        u4_bits = ih264d_get_bits_h264(ps_bitstrm, 8);
137
6.63k
        ps_vu4->u1_aspect_ratio_idc = (UWORD8)u4_bits;
138
6.63k
        if(VUI_EXTENDED_SAR == u4_bits)
139
3.40k
        {
140
3.40k
            ps_vu4->u2_sar_width = ih264d_get_bits_h264(ps_bitstrm, 16);
141
3.40k
            ps_vu4->u2_sar_height = ih264d_get_bits_h264(ps_bitstrm, 16);
142
3.40k
        }
143
6.63k
    }
144
145
9.27k
    u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
146
9.27k
    if(u4_bits)
147
2.20k
    {
148
2.20k
        ps_vu4->u1_overscan_appropriate_flag = ih264d_get_bits_h264(
149
2.20k
                        ps_bitstrm, 1);
150
2.20k
    }
151
9.27k
    u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
152
    /* Initialize to unspecified (5 for video_format and
153
       2 for colour_primaries, tfr_chars, matrix_coeffs  */
154
9.27k
    ps_vu4->u1_video_format = 5;
155
9.27k
    ps_vu4->u1_video_full_range_flag = 0;
156
9.27k
    ps_vu4->u1_colour_primaries = 2;
157
9.27k
    ps_vu4->u1_tfr_chars = 2;
158
9.27k
    ps_vu4->u1_matrix_coeffs = 2;
159
160
9.27k
    if(u4_bits)
161
2.11k
    {
162
2.11k
        ps_vu4->u1_video_format = ih264d_get_bits_h264(ps_bitstrm, 3);
163
2.11k
        ps_vu4->u1_video_full_range_flag = ih264d_get_bits_h264(ps_bitstrm,
164
2.11k
                                                                1);
165
2.11k
        u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
166
2.11k
        if(u4_bits)
167
1.26k
        {
168
1.26k
            ps_vu4->u1_colour_primaries = ih264d_get_bits_h264(ps_bitstrm,
169
1.26k
                                                               8);
170
1.26k
            ps_vu4->u1_tfr_chars = ih264d_get_bits_h264(ps_bitstrm, 8);
171
1.26k
            ps_vu4->u1_matrix_coeffs = ih264d_get_bits_h264(ps_bitstrm, 8);
172
1.26k
        }
173
2.11k
    }
174
175
9.27k
    u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
176
9.27k
    if(u4_bits)
177
1.56k
    {
178
1.56k
        ps_vu4->u1_cr_top_field = ih264d_uev(pu4_bitstrm_ofst,
179
1.56k
                                             pu4_bitstrm_buf);
180
1.56k
        ps_vu4->u1_cr_bottom_field = ih264d_uev(pu4_bitstrm_ofst,
181
1.56k
                                                pu4_bitstrm_buf);
182
1.56k
    }
183
184
9.27k
    u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
185
9.27k
    if(u4_bits)
186
960
    {
187
960
        ps_vu4->u4_num_units_in_tick = ih264d_get_bits_h264(ps_bitstrm, 32);
188
960
        ps_vu4->u4_time_scale = ih264d_get_bits_h264(ps_bitstrm, 32);
189
960
        ps_vu4->u1_fixed_frame_rate_flag = ih264d_get_bits_h264(ps_bitstrm,
190
960
                                                                1);
191
960
    }
192
193
9.27k
    u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
194
9.27k
    ps_vu4->u1_nal_hrd_params_present = u4_bits;
195
9.27k
    if(u4_bits)
196
1.52k
    {
197
1.52k
        ret = ih264d_parse_hrd_parametres(&ps_vu4->s_nal_hrd, ps_bitstrm);
198
1.52k
        if(ret != OK)
199
76
            return ret;
200
1.52k
    }
201
9.19k
    u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
202
9.19k
    ps_vu4->u1_vcl_hrd_params_present = u4_bits;
203
9.19k
    if(u4_bits)
204
1.81k
    {
205
1.81k
        ret = ih264d_parse_hrd_parametres(&ps_vu4->s_vcl_hrd, ps_bitstrm);
206
1.81k
        if(ret != OK)
207
102
            return ret;
208
1.81k
    }
209
210
9.09k
    if(ps_vu4->u1_nal_hrd_params_present || u4_bits)
211
2.19k
    {
212
2.19k
        ps_vu4->u1_low_delay_hrd_flag = ih264d_get_bits_h264(ps_bitstrm, 1);
213
2.19k
    }
214
9.09k
    ps_vu4->u1_pic_struct_present_flag = ih264d_get_bits_h264(ps_bitstrm, 1);
215
216
9.09k
    ps_vu4->u1_bitstream_restriction_flag = ih264d_get_bits_h264(ps_bitstrm, 1);
217
218
9.09k
    if(ps_vu4->u1_bitstream_restriction_flag)
219
1.70k
    {
220
1.70k
        ps_vu4->u1_mv_over_pic_boundaries_flag = ih264d_get_bits_h264(
221
1.70k
                        ps_bitstrm, 1);
222
1.70k
        ps_vu4->u4_max_bytes_per_pic_denom = ih264d_uev(pu4_bitstrm_ofst,
223
1.70k
                                                        pu4_bitstrm_buf);
224
1.70k
        ps_vu4->u4_max_bits_per_mb_denom = ih264d_uev(pu4_bitstrm_ofst,
225
1.70k
                                                      pu4_bitstrm_buf);
226
1.70k
        ps_vu4->u4_log2_max_mv_length_horz = ih264d_uev(pu4_bitstrm_ofst,
227
1.70k
                                                        pu4_bitstrm_buf);
228
1.70k
        ps_vu4->u4_log2_max_mv_length_vert = ih264d_uev(pu4_bitstrm_ofst,
229
1.70k
                                                        pu4_bitstrm_buf);
230
1.70k
        ps_vu4->u4_num_reorder_frames = ih264d_uev(pu4_bitstrm_ofst,
231
1.70k
                                                   pu4_bitstrm_buf);
232
1.70k
        ps_vu4->u4_max_dec_frame_buffering = ih264d_uev(pu4_bitstrm_ofst,
233
1.70k
                                                        pu4_bitstrm_buf);
234
1.70k
        if((ps_vu4->u4_max_dec_frame_buffering > (H264_MAX_REF_PICS * 2)) ||
235
1.59k
           (ps_vu4->u4_num_reorder_frames > ps_vu4->u4_max_dec_frame_buffering))
236
273
        {
237
273
            return ERROR_INV_SPS_PPS_T;
238
273
        }
239
1.70k
    }
240
7.39k
    else
241
7.39k
    {
242
        /* Setting this to a large value if not present */
243
7.39k
        ps_vu4->u4_num_reorder_frames = 64;
244
7.39k
        ps_vu4->u4_max_dec_frame_buffering = 64;
245
7.39k
    }
246
247
8.82k
    return OK;
248
9.09k
}