Coverage Report

Created: 2026-08-13 07:21

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
7.79k
{
71
7.79k
    UWORD8 u1_index;
72
7.79k
    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
73
7.79k
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
74
75
7.79k
    ps_hrd->u4_cpb_cnt = 1
76
7.79k
                    + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
77
7.79k
    if(ps_hrd->u4_cpb_cnt > 31)
78
413
        return ERROR_INV_SPS_PPS_T;
79
7.38k
    ps_hrd->u1_bit_rate_scale = ih264d_get_bits_h264(ps_bitstrm, 4);
80
7.38k
    ps_hrd->u1_cpb_size_scale = ih264d_get_bits_h264(ps_bitstrm, 4);
81
82
26.9k
    for(u1_index = 0; u1_index < (UWORD8)ps_hrd->u4_cpb_cnt; u1_index++)
83
19.5k
    {
84
19.5k
        ps_hrd->u4_bit_rate[u1_index] = 1
85
19.5k
                        + ih264d_uev(pu4_bitstrm_ofst,
86
19.5k
                                     pu4_bitstrm_buf);
87
19.5k
        ps_hrd->u4_cpb_size[u1_index] = 1
88
19.5k
                        + ih264d_uev(pu4_bitstrm_ofst,
89
19.5k
                                     pu4_bitstrm_buf);
90
19.5k
        ps_hrd->u1_cbr_flag[u1_index] = ih264d_get_bits_h264(ps_bitstrm, 1);
91
19.5k
    }
92
93
7.38k
    ps_hrd->u1_initial_cpb_removal_delay = 1
94
7.38k
                    + ih264d_get_bits_h264(ps_bitstrm, 5);
95
7.38k
    ps_hrd->u1_cpb_removal_delay_length = 1
96
7.38k
                    + ih264d_get_bits_h264(ps_bitstrm, 5);
97
7.38k
    ps_hrd->u1_dpb_output_delay_length = 1
98
7.38k
                    + ih264d_get_bits_h264(ps_bitstrm, 5);
99
7.38k
    ps_hrd->u1_time_offset_length = ih264d_get_bits_h264(ps_bitstrm, 5);
100
101
7.38k
    return OK;
102
7.79k
}
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
16.7k
{
128
16.7k
    UWORD8 u4_bits;
129
16.7k
    UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
130
16.7k
    UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
131
16.7k
    WORD32 ret;
132
133
16.7k
    u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
134
16.7k
    if(u4_bits)
135
9.03k
    {
136
9.03k
        u4_bits = ih264d_get_bits_h264(ps_bitstrm, 8);
137
9.03k
        ps_vu4->u1_aspect_ratio_idc = (UWORD8)u4_bits;
138
9.03k
        if(VUI_EXTENDED_SAR == u4_bits)
139
3.39k
        {
140
3.39k
            ps_vu4->u2_sar_width = ih264d_get_bits_h264(ps_bitstrm, 16);
141
3.39k
            ps_vu4->u2_sar_height = ih264d_get_bits_h264(ps_bitstrm, 16);
142
3.39k
        }
143
9.03k
    }
144
145
16.7k
    u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
146
16.7k
    if(u4_bits)
147
4.22k
    {
148
4.22k
        ps_vu4->u1_overscan_appropriate_flag = ih264d_get_bits_h264(
149
4.22k
                        ps_bitstrm, 1);
150
4.22k
    }
151
16.7k
    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
16.7k
    ps_vu4->u1_video_format = 5;
155
16.7k
    ps_vu4->u1_video_full_range_flag = 0;
156
16.7k
    ps_vu4->u1_colour_primaries = 2;
157
16.7k
    ps_vu4->u1_tfr_chars = 2;
158
16.7k
    ps_vu4->u1_matrix_coeffs = 2;
159
160
16.7k
    if(u4_bits)
161
6.22k
    {
162
6.22k
        ps_vu4->u1_video_format = ih264d_get_bits_h264(ps_bitstrm, 3);
163
6.22k
        ps_vu4->u1_video_full_range_flag = ih264d_get_bits_h264(ps_bitstrm,
164
6.22k
                                                                1);
165
6.22k
        u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
166
6.22k
        if(u4_bits)
167
2.59k
        {
168
2.59k
            ps_vu4->u1_colour_primaries = ih264d_get_bits_h264(ps_bitstrm,
169
2.59k
                                                               8);
170
2.59k
            ps_vu4->u1_tfr_chars = ih264d_get_bits_h264(ps_bitstrm, 8);
171
2.59k
            ps_vu4->u1_matrix_coeffs = ih264d_get_bits_h264(ps_bitstrm, 8);
172
2.59k
        }
173
6.22k
    }
174
175
16.7k
    u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
176
16.7k
    if(u4_bits)
177
3.13k
    {
178
3.13k
        ps_vu4->u1_cr_top_field = ih264d_uev(pu4_bitstrm_ofst,
179
3.13k
                                             pu4_bitstrm_buf);
180
3.13k
        ps_vu4->u1_cr_bottom_field = ih264d_uev(pu4_bitstrm_ofst,
181
3.13k
                                                pu4_bitstrm_buf);
182
3.13k
    }
183
184
16.7k
    u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
185
16.7k
    if(u4_bits)
186
2.00k
    {
187
2.00k
        ps_vu4->u4_num_units_in_tick = ih264d_get_bits_h264(ps_bitstrm, 32);
188
2.00k
        ps_vu4->u4_time_scale = ih264d_get_bits_h264(ps_bitstrm, 32);
189
2.00k
        ps_vu4->u1_fixed_frame_rate_flag = ih264d_get_bits_h264(ps_bitstrm,
190
2.00k
                                                                1);
191
2.00k
    }
192
193
16.7k
    u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
194
16.7k
    ps_vu4->u1_nal_hrd_params_present = u4_bits;
195
16.7k
    if(u4_bits)
196
2.57k
    {
197
2.57k
        ret = ih264d_parse_hrd_parametres(&ps_vu4->s_nal_hrd, ps_bitstrm);
198
2.57k
        if(ret != OK)
199
99
            return ret;
200
2.57k
    }
201
16.6k
    u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
202
16.6k
    ps_vu4->u1_vcl_hrd_params_present = u4_bits;
203
16.6k
    if(u4_bits)
204
2.62k
    {
205
2.62k
        ret = ih264d_parse_hrd_parametres(&ps_vu4->s_vcl_hrd, ps_bitstrm);
206
2.62k
        if(ret != OK)
207
159
            return ret;
208
2.62k
    }
209
210
16.4k
    if(ps_vu4->u1_nal_hrd_params_present || u4_bits)
211
3.52k
    {
212
3.52k
        ps_vu4->u1_low_delay_hrd_flag = ih264d_get_bits_h264(ps_bitstrm, 1);
213
3.52k
    }
214
16.4k
    ps_vu4->u1_pic_struct_present_flag = ih264d_get_bits_h264(ps_bitstrm, 1);
215
216
16.4k
    ps_vu4->u1_bitstream_restriction_flag = ih264d_get_bits_h264(ps_bitstrm, 1);
217
218
16.4k
    if(ps_vu4->u1_bitstream_restriction_flag)
219
4.57k
    {
220
4.57k
        ps_vu4->u1_mv_over_pic_boundaries_flag = ih264d_get_bits_h264(
221
4.57k
                        ps_bitstrm, 1);
222
4.57k
        ps_vu4->u4_max_bytes_per_pic_denom = ih264d_uev(pu4_bitstrm_ofst,
223
4.57k
                                                        pu4_bitstrm_buf);
224
4.57k
        ps_vu4->u4_max_bits_per_mb_denom = ih264d_uev(pu4_bitstrm_ofst,
225
4.57k
                                                      pu4_bitstrm_buf);
226
4.57k
        ps_vu4->u4_log2_max_mv_length_horz = ih264d_uev(pu4_bitstrm_ofst,
227
4.57k
                                                        pu4_bitstrm_buf);
228
4.57k
        ps_vu4->u4_log2_max_mv_length_vert = ih264d_uev(pu4_bitstrm_ofst,
229
4.57k
                                                        pu4_bitstrm_buf);
230
4.57k
        ps_vu4->u4_num_reorder_frames = ih264d_uev(pu4_bitstrm_ofst,
231
4.57k
                                                   pu4_bitstrm_buf);
232
4.57k
        ps_vu4->u4_max_dec_frame_buffering = ih264d_uev(pu4_bitstrm_ofst,
233
4.57k
                                                        pu4_bitstrm_buf);
234
4.57k
        if((ps_vu4->u4_max_dec_frame_buffering > (H264_MAX_REF_PICS * 2)) ||
235
4.34k
           (ps_vu4->u4_num_reorder_frames > ps_vu4->u4_max_dec_frame_buffering))
236
404
        {
237
404
            return ERROR_INV_SPS_PPS_T;
238
404
        }
239
4.57k
    }
240
11.9k
    else
241
11.9k
    {
242
        /* Setting this to a large value if not present */
243
11.9k
        ps_vu4->u4_num_reorder_frames = 64;
244
11.9k
        ps_vu4->u4_max_dec_frame_buffering = 64;
245
11.9k
    }
246
247
16.0k
    return OK;
248
16.4k
}