blob: 15f1c007566111c12098f693f44c9ce518148d11 [file] [log] [blame]
Hamsalekha S8d3d3032015-03-13 21:24:58 +05301/******************************************************************************
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
68WORD32 ih264d_parse_hrd_parametres(hrd_t *ps_hrd,
69 dec_bit_stream_t *ps_bitstrm)
70{
71 UWORD8 u1_index;
72 UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
73 UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
74
75 ps_hrd->u4_cpb_cnt = 1
76 + ih264d_uev(pu4_bitstrm_ofst, pu4_bitstrm_buf);
77 if(ps_hrd->u4_cpb_cnt > 31)
78 return ERROR_INV_SPS_PPS_T;
79 ps_hrd->u1_bit_rate_scale = ih264d_get_bits_h264(ps_bitstrm, 4);
80 ps_hrd->u1_cpb_size_scale = ih264d_get_bits_h264(ps_bitstrm, 4);
81
82 for(u1_index = 0; u1_index < (UWORD8)ps_hrd->u4_cpb_cnt; u1_index++)
83 {
84 ps_hrd->u4_bit_rate[u1_index] = 1
85 + ih264d_uev(pu4_bitstrm_ofst,
86 pu4_bitstrm_buf);
87 ps_hrd->u4_cpb_size[u1_index] = 1
88 + ih264d_uev(pu4_bitstrm_ofst,
89 pu4_bitstrm_buf);
90 ps_hrd->u1_cbr_flag[u1_index] = ih264d_get_bits_h264(ps_bitstrm, 1);
91 }
92
93 ps_hrd->u1_initial_cpb_removal_delay = 1
94 + ih264d_get_bits_h264(ps_bitstrm, 5);
95 ps_hrd->u1_cpb_removal_delay_length = 1
96 + ih264d_get_bits_h264(ps_bitstrm, 5);
97 ps_hrd->u1_dpb_output_delay_length = 1
98 + ih264d_get_bits_h264(ps_bitstrm, 5);
99 ps_hrd->u1_time_offset_length = ih264d_get_bits_h264(ps_bitstrm, 5);
100
101 return OK;
102}
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
125WORD32 ih264d_parse_vui_parametres(vui_t *ps_vu4,
126 dec_bit_stream_t *ps_bitstrm)
127{
128 UWORD8 u4_bits;
129 UWORD32 *pu4_bitstrm_ofst = &ps_bitstrm->u4_ofst;
130 UWORD32 *pu4_bitstrm_buf = ps_bitstrm->pu4_buffer;
131 WORD32 ret;
132
133 u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
134 if(u4_bits)
135 {
136 u4_bits = ih264d_get_bits_h264(ps_bitstrm, 8);
137 ps_vu4->u1_aspect_ratio_idc = (UWORD8)u4_bits;
138 if(VUI_EXTENDED_SAR == u4_bits)
139 {
140 ps_vu4->u2_sar_width = ih264d_get_bits_h264(ps_bitstrm, 16);
141 ps_vu4->u2_sar_height = ih264d_get_bits_h264(ps_bitstrm, 16);
142 }
143 }
144
145 u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
146 if(u4_bits)
147 {
148 ps_vu4->u1_overscan_appropriate_flag = ih264d_get_bits_h264(
149 ps_bitstrm, 1);
150 }
151 u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
Harish Mahendrakar871f0612016-06-27 14:15:39 +0530152 /* Initialize to unspecified (5 for video_format and
153 2 for colour_primaries, tfr_chars, matrix_coeffs */
154 ps_vu4->u1_video_format = 5;
155 ps_vu4->u1_video_full_range_flag = 0;
156 ps_vu4->u1_colour_primaries = 2;
157 ps_vu4->u1_tfr_chars = 2;
158 ps_vu4->u1_matrix_coeffs = 2;
159
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530160 if(u4_bits)
161 {
162 ps_vu4->u1_video_format = ih264d_get_bits_h264(ps_bitstrm, 3);
163 ps_vu4->u1_video_full_range_flag = ih264d_get_bits_h264(ps_bitstrm,
164 1);
165 u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
166 if(u4_bits)
167 {
168 ps_vu4->u1_colour_primaries = ih264d_get_bits_h264(ps_bitstrm,
169 8);
170 ps_vu4->u1_tfr_chars = ih264d_get_bits_h264(ps_bitstrm, 8);
171 ps_vu4->u1_matrix_coeffs = ih264d_get_bits_h264(ps_bitstrm, 8);
172 }
173 }
174
175 u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
176 if(u4_bits)
177 {
178 ps_vu4->u1_cr_top_field = ih264d_uev(pu4_bitstrm_ofst,
179 pu4_bitstrm_buf);
180 ps_vu4->u1_cr_bottom_field = ih264d_uev(pu4_bitstrm_ofst,
181 pu4_bitstrm_buf);
182 }
183
184 u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
185 if(u4_bits)
186 {
187 ps_vu4->u4_num_units_in_tick = ih264d_get_bits_h264(ps_bitstrm, 32);
188 ps_vu4->u4_time_scale = ih264d_get_bits_h264(ps_bitstrm, 32);
189 ps_vu4->u1_fixed_frame_rate_flag = ih264d_get_bits_h264(ps_bitstrm,
190 1);
191 }
192
193 u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
194 ps_vu4->u1_nal_hrd_params_present = u4_bits;
195 if(u4_bits)
196 {
197 ret = ih264d_parse_hrd_parametres(&ps_vu4->s_nal_hrd, ps_bitstrm);
198 if(ret != OK)
199 return ret;
200 }
201 u4_bits = ih264d_get_bits_h264(ps_bitstrm, 1);
202 ps_vu4->u1_vcl_hrd_params_present = u4_bits;
203 if(u4_bits)
204 {
205 ret = ih264d_parse_hrd_parametres(&ps_vu4->s_vcl_hrd, ps_bitstrm);
206 if(ret != OK)
207 return ret;
208 }
209
210 if(ps_vu4->u1_nal_hrd_params_present || u4_bits)
211 {
212 ps_vu4->u1_low_delay_hrd_flag = ih264d_get_bits_h264(ps_bitstrm, 1);
213 }
214 ps_vu4->u1_pic_struct_present_flag = ih264d_get_bits_h264(ps_bitstrm, 1);
215
Harish Mahendrakar34b3e472015-08-04 09:55:15 +0530216 ps_vu4->u1_bitstream_restriction_flag = ih264d_get_bits_h264(ps_bitstrm, 1);
217
218 if(ps_vu4->u1_bitstream_restriction_flag)
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530219 {
220 ps_vu4->u1_mv_over_pic_boundaries_flag = ih264d_get_bits_h264(
221 ps_bitstrm, 1);
222 ps_vu4->u4_max_bytes_per_pic_denom = ih264d_uev(pu4_bitstrm_ofst,
223 pu4_bitstrm_buf);
224 ps_vu4->u4_max_bits_per_mb_denom = ih264d_uev(pu4_bitstrm_ofst,
225 pu4_bitstrm_buf);
226 ps_vu4->u4_log2_max_mv_length_horz = ih264d_uev(pu4_bitstrm_ofst,
227 pu4_bitstrm_buf);
228 ps_vu4->u4_log2_max_mv_length_vert = ih264d_uev(pu4_bitstrm_ofst,
229 pu4_bitstrm_buf);
230 ps_vu4->u4_num_reorder_frames = ih264d_uev(pu4_bitstrm_ofst,
231 pu4_bitstrm_buf);
232 ps_vu4->u4_max_dec_frame_buffering = ih264d_uev(pu4_bitstrm_ofst,
233 pu4_bitstrm_buf);
Ritu Baldwa0e4598c2018-03-28 10:38:33 +0530234 if((ps_vu4->u4_max_dec_frame_buffering > (H264_MAX_REF_PICS * 2)) ||
235 (ps_vu4->u4_num_reorder_frames > ps_vu4->u4_max_dec_frame_buffering))
236 {
237 return ERROR_INV_SPS_PPS_T;
238 }
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530239 }
240 else
241 {
242 /* Setting this to a large value if not present */
243 ps_vu4->u4_num_reorder_frames = 64;
Harish Mahendrakar34b3e472015-08-04 09:55:15 +0530244 ps_vu4->u4_max_dec_frame_buffering = 64;
Hamsalekha S8d3d3032015-03-13 21:24:58 +0530245 }
246
247 return OK;
248}