Coverage Report

Created: 2026-01-09 06:17

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