/src/libxaac/fuzzer/xaac_enc_fuzzer.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /****************************************************************************** |
2 | | * * |
3 | | * Copyright (C) 2023 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 | | /* File includes */ |
22 | | /*****************************************************************************/ |
23 | | #include <string.h> |
24 | | #include <stdio.h> |
25 | | #include <stdlib.h> |
26 | | #include <stdint.h> |
27 | | #include <fuzzer/FuzzedDataProvider.h> |
28 | | |
29 | | extern "C" { |
30 | | #include "ixheaac_type_def.h" |
31 | | #include "impd_drc_common_enc.h" |
32 | | #include "impd_drc_uni_drc.h" |
33 | | #include "impd_drc_api.h" |
34 | | #include "ixheaace_api.h" |
35 | | #include "ixheaace_loudness_measurement.h" |
36 | | } |
37 | | |
38 | | static constexpr WORD32 k_sample_rates[] = {7350, 8000, 11025, 12000, 16000, 22050, 24000, |
39 | | 32000, 44100, 48000, 64000, 88200, 96000}; |
40 | | static constexpr WORD16 k_frame_length[] = {480, 512, 768, 960, 1024}; |
41 | | |
42 | 95.6k | pVOID malloc_global(UWORD32 size, UWORD32 alignment) { |
43 | 95.6k | pVOID ptr = NULL; |
44 | 95.6k | if (posix_memalign((VOID **)&ptr, alignment, size)) { |
45 | 0 | ptr = NULL; |
46 | 0 | } |
47 | 95.6k | return ptr; |
48 | 95.6k | } |
49 | | |
50 | 83.2k | VOID free_global(pVOID ptr) { free(ptr); } |
51 | | |
52 | | static VOID ixheaace_read_drc_config_params( |
53 | | ia_drc_enc_params_struct *pstr_enc_params, ia_drc_uni_drc_config_struct *pstr_uni_drc_config, |
54 | | ia_drc_loudness_info_set_struct *pstr_enc_loudness_info_set, |
55 | | ia_drc_uni_drc_gain_ext_struct *pstr_enc_gain_extension, FuzzedDataProvider *fuzzed_data, |
56 | 6.65k | WORD32 in_ch) { |
57 | 6.65k | WORD32 n, g, s, m, ch, p; |
58 | 6.65k | WORD32 gain_set_channels; |
59 | | |
60 | 6.65k | pstr_enc_params->gain_sequence_present = fuzzed_data->ConsumeBool(); |
61 | 6.65k | pstr_enc_params->delay_mode = fuzzed_data->ConsumeBool(); |
62 | 6.65k | pstr_uni_drc_config->sample_rate_present = fuzzed_data->ConsumeBool(); |
63 | 6.65k | pstr_uni_drc_config->str_drc_coefficients_uni_drc->drc_frame_size_present = |
64 | 6.65k | fuzzed_data->ConsumeBool(); |
65 | 6.65k | pstr_uni_drc_config->loudness_info_set_present = fuzzed_data->ConsumeBool(); |
66 | | |
67 | 6.65k | pstr_uni_drc_config->drc_instructions_uni_drc_count = |
68 | 6.65k | fuzzed_data->ConsumeIntegralInRange<WORD8>(0, MAX_DRC_INSTRUCTIONS_COUNT); |
69 | 26.4k | for (n = 0; n < pstr_uni_drc_config->drc_instructions_uni_drc_count; n++) { |
70 | 19.7k | ia_drc_instructions_uni_drc *pstr_drc_instructions_uni_drc = |
71 | 19.7k | &pstr_uni_drc_config->str_drc_instructions_uni_drc[n]; |
72 | 19.7k | pstr_drc_instructions_uni_drc->drc_set_id = fuzzed_data->ConsumeIntegral<WORD8>(); |
73 | 19.7k | pstr_drc_instructions_uni_drc->downmix_id = fuzzed_data->ConsumeIntegral<WORD8>(); |
74 | 19.7k | pstr_drc_instructions_uni_drc->additional_downmix_id_present = fuzzed_data->ConsumeBool(); |
75 | 19.7k | pstr_drc_instructions_uni_drc->additional_downmix_id_count = |
76 | 19.7k | fuzzed_data->ConsumeIntegral<WORD8>(); |
77 | 19.7k | pstr_drc_instructions_uni_drc->drc_location = fuzzed_data->ConsumeIntegral<WORD8>(); |
78 | 19.7k | pstr_drc_instructions_uni_drc->depends_on_drc_set_present = fuzzed_data->ConsumeBool(); |
79 | 19.7k | pstr_drc_instructions_uni_drc->depends_on_drc_set = fuzzed_data->ConsumeIntegral<WORD8>(); |
80 | 19.7k | pstr_drc_instructions_uni_drc->no_independent_use = fuzzed_data->ConsumeBool(); |
81 | 19.7k | pstr_drc_instructions_uni_drc->drc_set_effect = fuzzed_data->ConsumeIntegral<WORD16>(); |
82 | 19.7k | pstr_drc_instructions_uni_drc->drc_set_target_loudness_present = fuzzed_data->ConsumeBool(); |
83 | 19.7k | pstr_drc_instructions_uni_drc->drc_set_target_loudness_value_upper = |
84 | 19.7k | fuzzed_data->ConsumeIntegral<WORD8>(); |
85 | 19.7k | pstr_drc_instructions_uni_drc->drc_set_target_loudness_value_lower_present = |
86 | 19.7k | fuzzed_data->ConsumeBool(); |
87 | 19.7k | pstr_drc_instructions_uni_drc->drc_set_target_loudness_value_lower = |
88 | 19.7k | fuzzed_data->ConsumeIntegral<WORD8>(); |
89 | | |
90 | 19.7k | gain_set_channels = fuzzed_data->ConsumeIntegralInRange<WORD8>(0, MAX_CHANNEL_COUNT); |
91 | 67.8k | for (ch = 0; ch < gain_set_channels; ch++) { |
92 | 48.0k | pstr_drc_instructions_uni_drc->gain_set_index[ch] = fuzzed_data->ConsumeIntegral<WORD8>(); |
93 | 48.0k | } |
94 | 129k | for (; ch < MAX_CHANNEL_COUNT; ch++) { |
95 | 110k | if (gain_set_channels > 0) { |
96 | 40.6k | pstr_drc_instructions_uni_drc->gain_set_index[ch] = |
97 | 40.6k | pstr_drc_instructions_uni_drc->gain_set_index[gain_set_channels - 1]; |
98 | 69.4k | } else { |
99 | 69.4k | pstr_drc_instructions_uni_drc->gain_set_index[ch] = 0; |
100 | 69.4k | } |
101 | 110k | } |
102 | | |
103 | 19.7k | pstr_drc_instructions_uni_drc->num_drc_channel_groups = |
104 | 19.7k | fuzzed_data->ConsumeIntegralInRange<WORD8>(0, MAX_CHANNEL_GROUP_COUNT); |
105 | 66.6k | for (g = 0; g < pstr_drc_instructions_uni_drc->num_drc_channel_groups; g++) { |
106 | 46.8k | pstr_drc_instructions_uni_drc->str_gain_modifiers[g].gain_scaling_present[0] = |
107 | 46.8k | fuzzed_data->ConsumeBool(); |
108 | 46.8k | pstr_drc_instructions_uni_drc->str_gain_modifiers[g].attenuation_scaling[0] = |
109 | 46.8k | fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
110 | 46.8k | pstr_drc_instructions_uni_drc->str_gain_modifiers[g].amplification_scaling[0] = |
111 | 46.8k | fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
112 | 46.8k | pstr_drc_instructions_uni_drc->str_gain_modifiers[g].gain_offset_present[0] = |
113 | 46.8k | fuzzed_data->ConsumeBool(); |
114 | 46.8k | pstr_drc_instructions_uni_drc->str_gain_modifiers[g].gain_offset[0] = |
115 | 46.8k | fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
116 | 46.8k | } |
117 | | |
118 | 19.7k | pstr_drc_instructions_uni_drc->limiter_peak_target_present = fuzzed_data->ConsumeBool(); |
119 | 19.7k | pstr_drc_instructions_uni_drc->limiter_peak_target = |
120 | 19.7k | fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
121 | 19.7k | pstr_drc_instructions_uni_drc->drc_instructions_type = fuzzed_data->ConsumeIntegral<WORD8>(); |
122 | 19.7k | pstr_drc_instructions_uni_drc->mae_group_id = fuzzed_data->ConsumeIntegral<WORD8>(); |
123 | 19.7k | pstr_drc_instructions_uni_drc->mae_group_preset_id = fuzzed_data->ConsumeIntegral<WORD8>(); |
124 | 19.7k | } |
125 | | |
126 | 6.65k | pstr_uni_drc_config->drc_coefficients_uni_drc_count = |
127 | 6.65k | fuzzed_data->ConsumeIntegralInRange<WORD8>(0, MAX_DRC_COEFF_COUNT); |
128 | 12.5k | for (n = 0; n < pstr_uni_drc_config->drc_coefficients_uni_drc_count; n++) { |
129 | 5.89k | ia_drc_coefficients_uni_drc_struct *pstr_drc_coefficients_uni_drc = |
130 | 5.89k | &pstr_uni_drc_config->str_drc_coefficients_uni_drc[n]; |
131 | 5.89k | pstr_drc_coefficients_uni_drc->drc_location = fuzzed_data->ConsumeIntegral<WORD8>(); |
132 | 5.89k | pstr_drc_coefficients_uni_drc->gain_set_count = |
133 | 5.89k | fuzzed_data->ConsumeIntegralInRange<WORD8>(0, GAIN_SET_COUNT_MAX); |
134 | 15.6k | for (s = 0; s < pstr_drc_coefficients_uni_drc->gain_set_count; s++) { |
135 | 9.77k | pstr_drc_coefficients_uni_drc->str_gain_set_params[s].gain_coding_profile = |
136 | 9.77k | fuzzed_data->ConsumeIntegral<WORD8>(); |
137 | 9.77k | pstr_drc_coefficients_uni_drc->str_gain_set_params[s].gain_interpolation_type = |
138 | 9.77k | fuzzed_data->ConsumeBool(); |
139 | 9.77k | pstr_drc_coefficients_uni_drc->str_gain_set_params[s].full_frame = |
140 | 9.77k | fuzzed_data->ConsumeBool(); |
141 | 9.77k | pstr_drc_coefficients_uni_drc->str_gain_set_params[s].time_alignment = |
142 | 9.77k | fuzzed_data->ConsumeBool(); |
143 | 9.77k | pstr_drc_coefficients_uni_drc->str_gain_set_params[s].time_delta_min_present = |
144 | 9.77k | fuzzed_data->ConsumeBool(); |
145 | 9.77k | pstr_drc_coefficients_uni_drc->str_gain_set_params[s].band_count = |
146 | 9.77k | fuzzed_data->ConsumeIntegralInRange<WORD8>(0, MAX_BAND_COUNT); |
147 | 9.77k | if (pstr_drc_coefficients_uni_drc->str_gain_set_params[s].band_count == 1) { |
148 | 1.87k | pstr_drc_coefficients_uni_drc->str_gain_set_params[s].gain_params[0].nb_points = |
149 | 1.87k | fuzzed_data->ConsumeIntegralInRange<WORD16>(0, MAX_GAIN_POINTS); |
150 | 1.87k | for (p = 0; |
151 | 69.0k | p < pstr_drc_coefficients_uni_drc->str_gain_set_params[s].gain_params[0].nb_points; |
152 | 67.1k | p++) { |
153 | 67.1k | pstr_drc_coefficients_uni_drc->str_gain_set_params[s].gain_params[0].gain_points[p].x = |
154 | 67.1k | fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
155 | 67.1k | pstr_drc_coefficients_uni_drc->str_gain_set_params[s].gain_params[0].gain_points[p].y = |
156 | 67.1k | fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
157 | 67.1k | } |
158 | 1.87k | pstr_drc_coefficients_uni_drc->str_gain_set_params[s].gain_params[0].width = |
159 | 1.87k | fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
160 | 1.87k | pstr_drc_coefficients_uni_drc->str_gain_set_params[s].gain_params[0].attack = |
161 | 1.87k | fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
162 | 1.87k | pstr_drc_coefficients_uni_drc->str_gain_set_params[s].gain_params[0].decay = |
163 | 1.87k | fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
164 | 1.87k | pstr_drc_coefficients_uni_drc->str_gain_set_params[s].gain_params[0].drc_characteristic = |
165 | 1.87k | fuzzed_data->ConsumeIntegral<WORD8>(); |
166 | 1.87k | pstr_drc_coefficients_uni_drc->str_gain_set_params[s] |
167 | 1.87k | .gain_params[0] |
168 | 1.87k | .crossover_freq_index = fuzzed_data->ConsumeIntegral<WORD8>(); |
169 | 7.90k | } else { |
170 | 35.5k | for (m = 0; m < pstr_drc_coefficients_uni_drc->str_gain_set_params[s].band_count; m++) { |
171 | 27.6k | pstr_drc_coefficients_uni_drc->str_gain_set_params[s].gain_params[m].nb_points = |
172 | 27.6k | fuzzed_data->ConsumeIntegralInRange<WORD16>(0, MAX_GAIN_POINTS); |
173 | 27.6k | for (p = 0; |
174 | 1.12M | p < pstr_drc_coefficients_uni_drc->str_gain_set_params[s].gain_params[m].nb_points; |
175 | 1.09M | p++) { |
176 | 1.09M | pstr_drc_coefficients_uni_drc->str_gain_set_params[s] |
177 | 1.09M | .gain_params[m] |
178 | 1.09M | .gain_points[p] |
179 | 1.09M | .x = fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
180 | 1.09M | pstr_drc_coefficients_uni_drc->str_gain_set_params[s] |
181 | 1.09M | .gain_params[m] |
182 | 1.09M | .gain_points[p] |
183 | 1.09M | .y = fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
184 | 1.09M | } |
185 | 27.6k | pstr_drc_coefficients_uni_drc->str_gain_set_params[s].gain_params[m].width = |
186 | 27.6k | fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
187 | 27.6k | pstr_drc_coefficients_uni_drc->str_gain_set_params[s].gain_params[m].attack = |
188 | 27.6k | fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
189 | 27.6k | pstr_drc_coefficients_uni_drc->str_gain_set_params[s].gain_params[m].decay = |
190 | 27.6k | fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
191 | 27.6k | pstr_drc_coefficients_uni_drc->str_gain_set_params[s].drc_band_type = |
192 | 27.6k | fuzzed_data->ConsumeBool(); |
193 | 27.6k | pstr_drc_coefficients_uni_drc->str_gain_set_params[s] |
194 | 27.6k | .gain_params[m] |
195 | 27.6k | .start_sub_band_index = fuzzed_data->ConsumeIntegral<WORD16>(); |
196 | 27.6k | pstr_drc_coefficients_uni_drc->str_gain_set_params[s] |
197 | 27.6k | .gain_params[m] |
198 | 27.6k | .drc_characteristic = fuzzed_data->ConsumeIntegral<WORD8>(); |
199 | 27.6k | pstr_drc_coefficients_uni_drc->str_gain_set_params[s] |
200 | 27.6k | .gain_params[m] |
201 | 27.6k | .crossover_freq_index = fuzzed_data->ConsumeIntegral<WORD8>(); |
202 | 27.6k | } |
203 | 7.90k | } |
204 | 9.77k | } |
205 | 5.89k | } |
206 | | |
207 | 6.65k | pstr_enc_loudness_info_set->loudness_info_count = |
208 | 6.65k | fuzzed_data->ConsumeIntegralInRange<WORD8>(0, MAX_LOUDNESS_INFO_COUNT); |
209 | 20.2k | for (n = 0; n < pstr_enc_loudness_info_set->loudness_info_count; n++) { |
210 | 13.6k | pstr_enc_loudness_info_set->str_loudness_info[n].drc_set_id = |
211 | 13.6k | fuzzed_data->ConsumeIntegral<WORD8>(); |
212 | 13.6k | pstr_enc_loudness_info_set->str_loudness_info[n].downmix_id = |
213 | 13.6k | fuzzed_data->ConsumeIntegral<WORD8>(); |
214 | 13.6k | pstr_enc_loudness_info_set->str_loudness_info[n].sample_peak_level_present = |
215 | 13.6k | fuzzed_data->ConsumeBool(); |
216 | 13.6k | if (1 == pstr_enc_loudness_info_set->str_loudness_info[n].sample_peak_level_present) { |
217 | 6.08k | pstr_enc_loudness_info_set->str_loudness_info[n].sample_peak_level = |
218 | 6.08k | fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
219 | 6.08k | } |
220 | 13.6k | pstr_enc_loudness_info_set->str_loudness_info[n].true_peak_level_present = |
221 | 13.6k | fuzzed_data->ConsumeBool(); |
222 | 13.6k | if (1 == pstr_enc_loudness_info_set->str_loudness_info[n].true_peak_level_present) { |
223 | 6.57k | pstr_enc_loudness_info_set->str_loudness_info[n].true_peak_level = |
224 | 6.57k | fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
225 | 6.57k | pstr_enc_loudness_info_set->str_loudness_info[n].true_peak_level_measurement_system = |
226 | 6.57k | fuzzed_data->ConsumeIntegral<WORD8>(); |
227 | 6.57k | pstr_enc_loudness_info_set->str_loudness_info[n].true_peak_level_reliability = |
228 | 6.57k | fuzzed_data->ConsumeIntegral<WORD8>(); |
229 | 6.57k | } |
230 | | |
231 | 13.6k | pstr_enc_loudness_info_set->str_loudness_info[n].measurement_count = |
232 | 13.6k | fuzzed_data->ConsumeIntegralInRange<WORD8>(0, MAX_MEASUREMENT_COUNT); |
233 | 85.4k | for (m = 0; m < pstr_enc_loudness_info_set->str_loudness_info[n].measurement_count; m++) { |
234 | 71.7k | pstr_enc_loudness_info_set->str_loudness_info[n].str_loudness_measure[m].method_definition = |
235 | 71.7k | fuzzed_data->ConsumeIntegral<WORD8>(); |
236 | 71.7k | pstr_enc_loudness_info_set->str_loudness_info[n].str_loudness_measure[m].method_value = |
237 | 71.7k | fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
238 | 71.7k | pstr_enc_loudness_info_set->str_loudness_info[n] |
239 | 71.7k | .str_loudness_measure[m] |
240 | 71.7k | .measurement_system = fuzzed_data->ConsumeIntegral<WORD8>(); |
241 | 71.7k | pstr_enc_loudness_info_set->str_loudness_info[n].str_loudness_measure[m].reliability = |
242 | 71.7k | fuzzed_data->ConsumeIntegral<WORD8>(); |
243 | 71.7k | } |
244 | 13.6k | } |
245 | | |
246 | 6.65k | pstr_enc_loudness_info_set->loudness_info_album_count = |
247 | 6.65k | fuzzed_data->ConsumeIntegralInRange<WORD8>(0, MAX_LOUDNESS_INFO_COUNT); |
248 | 20.8k | for (n = 0; n < pstr_enc_loudness_info_set->loudness_info_album_count; n++) { |
249 | 14.1k | pstr_enc_loudness_info_set->str_loudness_info_album[n].drc_set_id = |
250 | 14.1k | fuzzed_data->ConsumeIntegral<WORD8>(); |
251 | 14.1k | pstr_enc_loudness_info_set->str_loudness_info_album[n].downmix_id = |
252 | 14.1k | fuzzed_data->ConsumeIntegral<WORD8>(); |
253 | 14.1k | pstr_enc_loudness_info_set->str_loudness_info_album[n].sample_peak_level_present = |
254 | 14.1k | fuzzed_data->ConsumeBool(); |
255 | 14.1k | if (1 == pstr_enc_loudness_info_set->str_loudness_info_album[n].sample_peak_level_present) { |
256 | 7.07k | pstr_enc_loudness_info_set->str_loudness_info_album[n].sample_peak_level = |
257 | 7.07k | fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
258 | 7.07k | } |
259 | 14.1k | pstr_enc_loudness_info_set->str_loudness_info_album[n].true_peak_level_present = |
260 | 14.1k | fuzzed_data->ConsumeBool(); |
261 | 14.1k | if (1 == pstr_enc_loudness_info_set->str_loudness_info_album[n].true_peak_level_present) { |
262 | 7.83k | pstr_enc_loudness_info_set->str_loudness_info_album[n].true_peak_level = |
263 | 7.83k | fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
264 | 7.83k | pstr_enc_loudness_info_set->str_loudness_info_album[n].true_peak_level_measurement_system = |
265 | 7.83k | fuzzed_data->ConsumeIntegral<WORD8>(); |
266 | 7.83k | pstr_enc_loudness_info_set->str_loudness_info_album[n].true_peak_level_reliability = |
267 | 7.83k | fuzzed_data->ConsumeIntegral<WORD8>(); |
268 | 7.83k | } |
269 | | |
270 | 14.1k | pstr_enc_loudness_info_set->str_loudness_info_album[n].measurement_count = |
271 | 14.1k | fuzzed_data->ConsumeIntegralInRange<WORD8>(0, MAX_MEASUREMENT_COUNT); |
272 | 89.9k | for (m = 0; m < pstr_enc_loudness_info_set->str_loudness_info_album[n].measurement_count; |
273 | 75.7k | m++) { |
274 | 75.7k | pstr_enc_loudness_info_set->str_loudness_info_album[n] |
275 | 75.7k | .str_loudness_measure[m] |
276 | 75.7k | .method_definition = fuzzed_data->ConsumeIntegral<WORD8>(); |
277 | 75.7k | pstr_enc_loudness_info_set->str_loudness_info_album[n] |
278 | 75.7k | .str_loudness_measure[m] |
279 | 75.7k | .method_value = fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
280 | 75.7k | pstr_enc_loudness_info_set->str_loudness_info_album[n] |
281 | 75.7k | .str_loudness_measure[m] |
282 | 75.7k | .measurement_system = fuzzed_data->ConsumeIntegral<WORD8>(); |
283 | 75.7k | pstr_enc_loudness_info_set->str_loudness_info_album[n].str_loudness_measure[m].reliability = |
284 | 75.7k | fuzzed_data->ConsumeIntegral<WORD8>(); |
285 | 75.7k | } |
286 | 14.1k | } |
287 | | |
288 | 6.65k | pstr_uni_drc_config->str_channel_layout.layout_signaling_present = fuzzed_data->ConsumeBool(); |
289 | 6.65k | pstr_uni_drc_config->str_channel_layout.defined_layout = fuzzed_data->ConsumeIntegral<WORD8>(); |
290 | 6.65k | pstr_uni_drc_config->str_channel_layout.speaker_position[0] = |
291 | 6.65k | fuzzed_data->ConsumeIntegral<WORD8>(); |
292 | | |
293 | 6.65k | pstr_uni_drc_config->downmix_instructions_count = |
294 | 6.65k | fuzzed_data->ConsumeIntegralInRange<WORD8>(0, MAX_DOWNMIX_INSTRUCTION_COUNT); |
295 | 17.4k | for (n = 0; n < pstr_uni_drc_config->downmix_instructions_count; n++) { |
296 | 10.7k | pstr_uni_drc_config->str_downmix_instructions[n].target_layout = |
297 | 10.7k | fuzzed_data->ConsumeIntegral<WORD8>(); |
298 | 10.7k | pstr_uni_drc_config->str_downmix_instructions[n].downmix_coefficients_present = |
299 | 10.7k | fuzzed_data->ConsumeBool(); |
300 | 10.7k | } |
301 | | |
302 | 6.65k | pstr_uni_drc_config->drc_description_basic_present = fuzzed_data->ConsumeBool(); |
303 | 6.65k | pstr_uni_drc_config->uni_drc_config_ext_present = fuzzed_data->ConsumeBool(); |
304 | 6.65k | pstr_enc_loudness_info_set->loudness_info_set_ext_present = fuzzed_data->ConsumeBool(); |
305 | 6.65k | pstr_enc_gain_extension->uni_drc_gain_ext_present = fuzzed_data->ConsumeBool(); |
306 | | |
307 | 6.65k | if (pstr_uni_drc_config->uni_drc_config_ext_present) { |
308 | 1.69k | pstr_uni_drc_config->str_uni_drc_config_ext.uni_drc_config_ext_type[0] = UNIDRC_CONF_EXT_V1; |
309 | 1.69k | pstr_uni_drc_config->str_uni_drc_config_ext.downmix_instructions_v1_present = |
310 | 1.69k | fuzzed_data->ConsumeBool(); |
311 | 1.69k | if (pstr_uni_drc_config->str_uni_drc_config_ext.downmix_instructions_v1_present) { |
312 | | /*********** str_downmix_instructions_v1 *************/ |
313 | | |
314 | 745 | pstr_uni_drc_config->str_uni_drc_config_ext.downmix_instructions_v1_count = |
315 | 745 | fuzzed_data->ConsumeIntegralInRange<WORD8>(0, DOWNMIX_INSTRUCTIONS_COUNT_MAX); |
316 | 3.52k | for (n = 0; n < pstr_uni_drc_config->str_uni_drc_config_ext.downmix_instructions_v1_count; |
317 | 2.78k | n++) { |
318 | 2.78k | ia_drc_downmix_instructions_struct *pstr_downmix_instructions_v1 = |
319 | 2.78k | &pstr_uni_drc_config->str_uni_drc_config_ext.str_downmix_instructions_v1[n]; |
320 | 2.78k | pstr_downmix_instructions_v1->downmix_id = fuzzed_data->ConsumeIntegral<WORD8>(); |
321 | 2.78k | ; |
322 | 2.78k | pstr_downmix_instructions_v1->target_ch_count = fuzzed_data->ConsumeIntegral<WORD8>(); |
323 | 2.78k | pstr_downmix_instructions_v1->target_layout = fuzzed_data->ConsumeIntegral<WORD8>(); |
324 | 2.78k | pstr_downmix_instructions_v1->downmix_coefficients_present = fuzzed_data->ConsumeBool(); |
325 | 2.78k | if (pstr_downmix_instructions_v1->downmix_coefficients_present) { |
326 | 1.91k | FLOAT32 dwn_mix_coeff = 0.0f; |
327 | 58.7k | for (s = 0; s < pstr_downmix_instructions_v1->target_layout; s++) { |
328 | 56.8k | dwn_mix_coeff = fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
329 | 56.8k | for (ch = 0; ch < in_ch; ch++) { |
330 | 0 | pstr_downmix_instructions_v1->downmix_coeff[in_ch * s + ch] = dwn_mix_coeff; |
331 | 0 | } |
332 | 56.8k | } |
333 | 1.91k | } |
334 | 2.78k | } |
335 | 745 | } |
336 | | |
337 | 1.69k | pstr_uni_drc_config->str_uni_drc_config_ext.drc_coeffs_and_instructions_uni_drc_v1_present = |
338 | 1.69k | fuzzed_data->ConsumeBool(); |
339 | 1.69k | if (pstr_uni_drc_config->str_uni_drc_config_ext |
340 | 1.69k | .drc_coeffs_and_instructions_uni_drc_v1_present) { |
341 | | /*********** str_drc_coefficients_uni_drc_v1 *************/ |
342 | | |
343 | 1.13k | pstr_uni_drc_config->str_uni_drc_config_ext.drc_coefficients_uni_drc_v1_count = |
344 | 1.13k | fuzzed_data->ConsumeIntegralInRange<WORD8>(0, DRC_COEFFICIENTS_UNIDRC_V1_COUNT_MAX); |
345 | 1.13k | for (n = 0; |
346 | 2.26k | n < pstr_uni_drc_config->str_uni_drc_config_ext.drc_coefficients_uni_drc_v1_count; |
347 | 1.13k | n++) { |
348 | 1.13k | ia_drc_coefficients_uni_drc_struct *pstr_drc_coefficients_uni_drc_v1 = |
349 | 1.13k | &pstr_uni_drc_config->str_uni_drc_config_ext.str_drc_coefficients_uni_drc_v1[n]; |
350 | 1.13k | pstr_drc_coefficients_uni_drc_v1->drc_location = fuzzed_data->ConsumeIntegral<WORD8>(); |
351 | 1.13k | pstr_drc_coefficients_uni_drc_v1->gain_set_count = |
352 | 1.13k | fuzzed_data->ConsumeIntegralInRange<WORD8>(0, GAIN_SET_COUNT_MAX); |
353 | 5.12k | for (s = 0; s < pstr_drc_coefficients_uni_drc_v1->gain_set_count; s++) { |
354 | 3.98k | pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s].gain_coding_profile = |
355 | 3.98k | fuzzed_data->ConsumeIntegral<WORD8>(); |
356 | 3.98k | pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s].gain_interpolation_type = |
357 | 3.98k | fuzzed_data->ConsumeBool(); |
358 | 3.98k | pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s].full_frame = |
359 | 3.98k | fuzzed_data->ConsumeBool(); |
360 | 3.98k | pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s].time_alignment = |
361 | 3.98k | fuzzed_data->ConsumeBool(); |
362 | 3.98k | pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s].time_delta_min_present = |
363 | 3.98k | fuzzed_data->ConsumeBool(); |
364 | 3.98k | pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s].band_count = |
365 | 3.98k | fuzzed_data->ConsumeIntegralInRange<WORD8>(0, MAX_BAND_COUNT); |
366 | 3.98k | if (pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s].band_count == 1) { |
367 | 596 | pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s].gain_params[0].nb_points = |
368 | 596 | fuzzed_data->ConsumeIntegralInRange<WORD16>(0, MAX_GAIN_POINTS); |
369 | 21.0k | for (p = 0; p < pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s] |
370 | 21.0k | .gain_params[0] |
371 | 21.0k | .nb_points; |
372 | 20.4k | p++) { |
373 | 20.4k | pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s] |
374 | 20.4k | .gain_params[0] |
375 | 20.4k | .gain_points[p] |
376 | 20.4k | .x = fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
377 | 20.4k | pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s] |
378 | 20.4k | .gain_params[0] |
379 | 20.4k | .gain_points[p] |
380 | 20.4k | .y = fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
381 | 20.4k | } |
382 | 596 | pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s].gain_params[0].width = |
383 | 596 | fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
384 | 596 | pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s].gain_params[0].attack = |
385 | 596 | fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
386 | 596 | pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s].gain_params[0].decay = |
387 | 596 | fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
388 | 596 | pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s] |
389 | 596 | .gain_params[0] |
390 | 596 | .drc_characteristic = fuzzed_data->ConsumeIntegral<WORD8>(); |
391 | 596 | ; |
392 | 596 | pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s] |
393 | 596 | .gain_params[0] |
394 | 596 | .crossover_freq_index = fuzzed_data->ConsumeIntegral<WORD8>(); |
395 | 3.39k | } else { |
396 | 17.5k | for (m = 0; m < pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s].band_count; |
397 | 14.1k | m++) { |
398 | 14.1k | pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s].gain_params[m].nb_points = |
399 | 14.1k | fuzzed_data->ConsumeIntegralInRange<WORD16>(0, MAX_GAIN_POINTS); |
400 | 245k | for (p = 0; p < pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s] |
401 | 245k | .gain_params[m] |
402 | 245k | .nb_points; |
403 | 230k | p++) { |
404 | 230k | pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s] |
405 | 230k | .gain_params[m] |
406 | 230k | .gain_points[p] |
407 | 230k | .x = fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
408 | 230k | pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s] |
409 | 230k | .gain_params[m] |
410 | 230k | .gain_points[p] |
411 | 230k | .y = fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
412 | 230k | } |
413 | 14.1k | pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s].gain_params[m].width = |
414 | 14.1k | fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
415 | 14.1k | pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s].gain_params[m].attack = |
416 | 14.1k | fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
417 | 14.1k | pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s].gain_params[m].decay = |
418 | 14.1k | fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
419 | 14.1k | pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s].drc_band_type = 0; |
420 | 14.1k | pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s] |
421 | 14.1k | .gain_params[m] |
422 | 14.1k | .start_sub_band_index = fuzzed_data->ConsumeIntegral<WORD16>(); |
423 | 14.1k | pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s] |
424 | 14.1k | .gain_params[m] |
425 | 14.1k | .drc_characteristic = fuzzed_data->ConsumeIntegral<WORD8>(); |
426 | 14.1k | ; |
427 | 14.1k | pstr_drc_coefficients_uni_drc_v1->str_gain_set_params[s] |
428 | 14.1k | .gain_params[m] |
429 | 14.1k | .crossover_freq_index = fuzzed_data->ConsumeIntegral<WORD8>(); |
430 | 14.1k | } |
431 | 3.39k | } |
432 | 3.98k | } |
433 | 1.13k | } |
434 | | |
435 | | /*********** str_drc_instructions_uni_drc_v1 *************/ |
436 | 1.13k | pstr_uni_drc_config->str_uni_drc_config_ext.drc_instructions_uni_drc_v1_count = |
437 | 1.13k | fuzzed_data->ConsumeIntegralInRange<WORD8>(0, DRC_INSTRUCTIONS_UNIDRC_V1_COUNT_MAX); |
438 | 1.13k | for (n = 0; |
439 | 4.42k | n < pstr_uni_drc_config->str_uni_drc_config_ext.drc_instructions_uni_drc_v1_count; |
440 | 3.29k | n++) { |
441 | 3.29k | ia_drc_instructions_uni_drc *pstr_drc_instructions_uni_drc = |
442 | 3.29k | &pstr_uni_drc_config->str_uni_drc_config_ext.str_drc_instructions_uni_drc_v1[n]; |
443 | 3.29k | pstr_drc_instructions_uni_drc->drc_set_id = fuzzed_data->ConsumeIntegral<WORD8>(); |
444 | 3.29k | pstr_drc_instructions_uni_drc->downmix_id = fuzzed_data->ConsumeIntegral<WORD8>(); |
445 | 3.29k | pstr_drc_instructions_uni_drc->additional_downmix_id_present = fuzzed_data->ConsumeBool(); |
446 | 3.29k | pstr_drc_instructions_uni_drc->additional_downmix_id_count = |
447 | 3.29k | fuzzed_data->ConsumeIntegral<WORD8>(); |
448 | 3.29k | pstr_drc_instructions_uni_drc->drc_location = fuzzed_data->ConsumeIntegral<WORD8>(); |
449 | 3.29k | pstr_drc_instructions_uni_drc->depends_on_drc_set_present = fuzzed_data->ConsumeBool(); |
450 | 3.29k | pstr_drc_instructions_uni_drc->depends_on_drc_set = fuzzed_data->ConsumeIntegral<WORD8>(); |
451 | 3.29k | pstr_drc_instructions_uni_drc->no_independent_use = fuzzed_data->ConsumeBool(); |
452 | 3.29k | pstr_drc_instructions_uni_drc->drc_set_effect = fuzzed_data->ConsumeIntegral<WORD16>(); |
453 | 3.29k | pstr_drc_instructions_uni_drc->drc_set_target_loudness_present = |
454 | 3.29k | fuzzed_data->ConsumeBool(); |
455 | 3.29k | pstr_drc_instructions_uni_drc->drc_set_target_loudness_value_upper = |
456 | 3.29k | fuzzed_data->ConsumeIntegral<WORD8>(); |
457 | 3.29k | pstr_drc_instructions_uni_drc->drc_set_target_loudness_value_lower_present = |
458 | 3.29k | fuzzed_data->ConsumeBool(); |
459 | 3.29k | pstr_drc_instructions_uni_drc->drc_set_target_loudness_value_lower = |
460 | 3.29k | fuzzed_data->ConsumeIntegral<WORD8>(); |
461 | | |
462 | 3.29k | gain_set_channels = fuzzed_data->ConsumeIntegralInRange<WORD8>(0, MAX_CHANNEL_COUNT); |
463 | 14.6k | for (ch = 0; ch < gain_set_channels; ch++) { |
464 | 11.3k | pstr_drc_instructions_uni_drc->gain_set_index[ch] = |
465 | 11.3k | fuzzed_data->ConsumeIntegral<WORD8>(); |
466 | 11.3k | } |
467 | 18.3k | for (; ch < MAX_CHANNEL_COUNT; ch++) { |
468 | 15.0k | if (gain_set_channels > 0) { |
469 | 6.34k | pstr_drc_instructions_uni_drc->gain_set_index[ch] = |
470 | 6.34k | pstr_drc_instructions_uni_drc->gain_set_index[gain_set_channels - 1]; |
471 | 8.71k | } else { |
472 | 8.71k | pstr_drc_instructions_uni_drc->gain_set_index[ch] = 0; |
473 | 8.71k | } |
474 | 15.0k | } |
475 | | |
476 | 3.29k | pstr_drc_instructions_uni_drc->num_drc_channel_groups = |
477 | 3.29k | fuzzed_data->ConsumeIntegralInRange<WORD8>(0, MAX_CHANNEL_GROUP_COUNT); |
478 | 14.0k | for (g = 0; g < pstr_drc_instructions_uni_drc->num_drc_channel_groups; g++) { |
479 | 10.7k | pstr_drc_instructions_uni_drc->str_gain_modifiers[g].gain_scaling_present[0] = |
480 | 10.7k | fuzzed_data->ConsumeBool(); |
481 | 10.7k | pstr_drc_instructions_uni_drc->str_gain_modifiers[g].attenuation_scaling[0] = |
482 | 10.7k | fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
483 | 10.7k | pstr_drc_instructions_uni_drc->str_gain_modifiers[g].amplification_scaling[0] = |
484 | 10.7k | fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
485 | 10.7k | pstr_drc_instructions_uni_drc->str_gain_modifiers[g].gain_offset_present[0] = |
486 | 10.7k | fuzzed_data->ConsumeBool(); |
487 | 10.7k | pstr_drc_instructions_uni_drc->str_gain_modifiers[g].gain_offset[0] = |
488 | 10.7k | fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
489 | 10.7k | } |
490 | | |
491 | 3.29k | pstr_drc_instructions_uni_drc->limiter_peak_target_present = fuzzed_data->ConsumeBool(); |
492 | 3.29k | pstr_drc_instructions_uni_drc->limiter_peak_target = |
493 | 3.29k | fuzzed_data->ConsumeFloatingPoint<FLOAT32>(); |
494 | 3.29k | pstr_drc_instructions_uni_drc->drc_instructions_type = |
495 | 3.29k | fuzzed_data->ConsumeIntegral<WORD8>(); |
496 | 3.29k | pstr_drc_instructions_uni_drc->mae_group_id = fuzzed_data->ConsumeIntegral<WORD8>(); |
497 | 3.29k | pstr_drc_instructions_uni_drc->mae_group_preset_id = |
498 | 3.29k | fuzzed_data->ConsumeIntegral<WORD8>(); |
499 | 3.29k | } |
500 | 1.13k | } |
501 | 1.69k | } |
502 | 6.65k | } |
503 | | |
504 | | static VOID ixheaace_fuzzer_flag(ixheaace_input_config *pstr_in_cfg, |
505 | | ia_drc_input_config *pstr_drc_cfg, |
506 | 12.4k | FuzzedDataProvider *fuzzed_data, WORD32 in_ch) { |
507 | | // Set Default value for AAC config structure |
508 | | |
509 | 12.4k | pstr_in_cfg->i_bitrate = fuzzed_data->ConsumeIntegral<WORD32>(); |
510 | 12.4k | pstr_in_cfg->i_use_mps = fuzzed_data->ConsumeBool(); |
511 | 12.4k | pstr_in_cfg->i_use_adts = fuzzed_data->ConsumeBool(); |
512 | 12.4k | pstr_in_cfg->i_use_es = fuzzed_data->ConsumeBool(); |
513 | 12.4k | pstr_in_cfg->aac_config.use_tns = fuzzed_data->ConsumeBool(); |
514 | 12.4k | pstr_in_cfg->aac_config.noise_filling = fuzzed_data->ConsumeBool(); |
515 | 12.4k | pstr_in_cfg->ui_pcm_wd_sz = fuzzed_data->ConsumeIntegral<WORD8>(); |
516 | 12.4k | pstr_in_cfg->i_channels = fuzzed_data->ConsumeIntegral<WORD8>(); |
517 | 12.4k | if (fuzzed_data->ConsumeBool()) { |
518 | 9.59k | pstr_in_cfg->i_samp_freq = fuzzed_data->PickValueInArray(k_sample_rates); |
519 | 9.59k | } else { |
520 | 2.83k | pstr_in_cfg->i_samp_freq = fuzzed_data->ConsumeIntegral<UWORD32>(); |
521 | 2.83k | } |
522 | 12.4k | if (fuzzed_data->ConsumeBool()) { |
523 | 9.14k | pstr_in_cfg->frame_length = fuzzed_data->PickValueInArray(k_frame_length); |
524 | 9.14k | } else { |
525 | 3.28k | pstr_in_cfg->frame_length = fuzzed_data->ConsumeIntegral<WORD16>(); |
526 | 3.28k | } |
527 | 12.4k | pstr_in_cfg->aot = fuzzed_data->ConsumeIntegral<WORD8>(); |
528 | 12.4k | pstr_in_cfg->esbr_flag = fuzzed_data->ConsumeBool(); |
529 | 12.4k | pstr_in_cfg->aac_config.full_bandwidth = fuzzed_data->ConsumeBool(); |
530 | 12.4k | pstr_in_cfg->aac_config.bitreservoir_size = fuzzed_data->ConsumeIntegral<WORD16>(); |
531 | 12.4k | pstr_in_cfg->i_mps_tree_config = fuzzed_data->ConsumeIntegral<WORD8>(); |
532 | 12.4k | pstr_in_cfg->i_channels_mask = fuzzed_data->ConsumeIntegral<WORD8>(); |
533 | 12.4k | pstr_in_cfg->cplx_pred = fuzzed_data->ConsumeBool(); |
534 | 12.4k | pstr_in_cfg->usac_en = fuzzed_data->ConsumeBool(); |
535 | 12.4k | pstr_in_cfg->ccfl_idx = fuzzed_data->ConsumeIntegral<WORD8>(); |
536 | 12.4k | pstr_in_cfg->pvc_active = fuzzed_data->ConsumeBool(); |
537 | 12.4k | pstr_in_cfg->harmonic_sbr = fuzzed_data->ConsumeBool(); |
538 | 12.4k | pstr_in_cfg->hq_esbr = fuzzed_data->ConsumeBool(); |
539 | 12.4k | pstr_in_cfg->use_drc_element = fuzzed_data->ConsumeBool(); |
540 | 12.4k | pstr_in_cfg->inter_tes_active = fuzzed_data->ConsumeBool(); |
541 | 12.4k | pstr_in_cfg->codec_mode = fuzzed_data->ConsumeIntegral<WORD8>(); |
542 | 12.4k | pstr_in_cfg->random_access_interval = fuzzed_data->ConsumeIntegral<WORD32>(); |
543 | 12.4k | pstr_in_cfg->method_def = fuzzed_data->ConsumeIntegral<WORD32>(); |
544 | 12.4k | pstr_in_cfg->measurement_system = fuzzed_data->ConsumeIntegral<WORD32>(); |
545 | 12.4k | pstr_in_cfg->measured_loudness = fuzzed_data->ConsumeIntegral<WORD32>(); |
546 | 12.4k | pstr_in_cfg->stream_id = fuzzed_data->ConsumeIntegral<UWORD16>(); |
547 | 12.4k | pstr_in_cfg->use_delay_adjustment = fuzzed_data->ConsumeIntegral<WORD32>(); |
548 | | /* DRC */ |
549 | 12.4k | if (pstr_in_cfg->use_drc_element == 1) { |
550 | 6.65k | ixheaace_read_drc_config_params(&pstr_drc_cfg->str_enc_params, |
551 | 6.65k | &pstr_drc_cfg->str_uni_drc_config, |
552 | 6.65k | &pstr_drc_cfg->str_enc_loudness_info_set, |
553 | 6.65k | &pstr_drc_cfg->str_enc_gain_extension, fuzzed_data, in_ch); |
554 | 6.65k | } |
555 | 12.4k | } |
556 | | |
557 | | IA_ERRORCODE ia_enhaacplus_enc_pcm_data_read(std::vector<WORD8> input_vec, UWORD32 num_samples, |
558 | 40.9k | WORD32 num_channels, WORD16 **data) { |
559 | 40.9k | UWORD32 count = 0; |
560 | 40.9k | UWORD8 channel_no; |
561 | 40.9k | UWORD32 sample_no = 0; |
562 | 40.9k | UWORD32 i = 0; |
563 | 197M | while (count < num_samples) { |
564 | 197M | sample_no = (count / num_channels); |
565 | 197M | channel_no = (UWORD8)(count % num_channels); |
566 | 197M | data[channel_no][sample_no] = *input_vec.data(); |
567 | 197M | i++; |
568 | 197M | count++; |
569 | 197M | } |
570 | 40.9k | return 0; |
571 | 40.9k | } |
572 | | |
573 | | static IA_ERRORCODE ixheaace_calculate_loudness_measure(ixheaace_input_config *pstr_in_cfg, |
574 | | ixheaace_output_config *pstr_out_cfg, |
575 | 7.61k | FuzzedDataProvider *fuzzed_data) { |
576 | 7.61k | WORD32 input_size; |
577 | 7.61k | WORD32 count = 0; |
578 | 7.61k | IA_ERRORCODE err_code = 0; |
579 | 7.61k | VOID *loudness_handle = |
580 | 7.61k | malloc_global(ixheaace_loudness_info_get_handle_size(), DEFAULT_MEM_ALIGN_8); |
581 | 7.61k | if (loudness_handle == NULL) { |
582 | 0 | printf("fatal error: libxaac encoder: Memory allocation failed"); |
583 | 0 | return -1; |
584 | 0 | } |
585 | | |
586 | 7.61k | err_code = ixheaace_loudness_init_params(loudness_handle, pstr_in_cfg, pstr_out_cfg); |
587 | | |
588 | 7.61k | if (err_code) { |
589 | 1.51k | free_global(loudness_handle); |
590 | 1.51k | return -1; |
591 | 1.51k | } |
592 | 6.09k | input_size = (pstr_out_cfg->samp_freq / 10) * (pstr_in_cfg->i_channels); |
593 | 6.09k | WORD16 **samples = 0; |
594 | 6.09k | samples = |
595 | 6.09k | (WORD16 **)malloc_global(pstr_in_cfg->i_channels * sizeof(*samples), DEFAULT_MEM_ALIGN_8); |
596 | 6.09k | if (samples == NULL) { |
597 | 0 | printf("fatal error: libxaac encoder: Memory allocation failed"); |
598 | 0 | free_global(loudness_handle); |
599 | 0 | return -1; |
600 | 0 | } |
601 | 16.1k | for (count = 0; count < pstr_in_cfg->i_channels; count++) { |
602 | 10.0k | samples[count] = (WORD16 *)malloc_global( |
603 | 10.0k | (pstr_out_cfg->samp_freq / 10) * sizeof(*samples[count]), DEFAULT_MEM_ALIGN_8); |
604 | 10.0k | if (samples[count] == NULL) { |
605 | 0 | printf("fatal error: libxaac encoder: Memory allocation failed"); |
606 | 0 | while (count) { |
607 | 0 | count--; |
608 | 0 | free_global(samples[count]); |
609 | 0 | } |
610 | 0 | free_global(samples); |
611 | 0 | free_global(loudness_handle); |
612 | 0 | return -1; |
613 | 0 | } |
614 | 10.0k | memset(samples[count], 0, (pstr_out_cfg->samp_freq / 10) * sizeof(*samples[count])); |
615 | 10.0k | } |
616 | 6.09k | count = 0; |
617 | 47.0k | while (count <= fuzzed_data->remaining_bytes()) { |
618 | 40.9k | std::vector<WORD8> input_vec = fuzzed_data->ConsumeBytes<WORD8>(input_size); |
619 | 40.9k | err_code = |
620 | 40.9k | ia_enhaacplus_enc_pcm_data_read(input_vec, input_size, pstr_in_cfg->i_channels, samples); |
621 | 40.9k | if (err_code) { |
622 | 0 | for (count = 0; count < pstr_in_cfg->i_channels; count++) { |
623 | 0 | free_global(samples[count]); |
624 | 0 | } |
625 | 0 | free_global(samples); |
626 | 0 | free_global(loudness_handle); |
627 | 0 | return -1; |
628 | 0 | } |
629 | 40.9k | pstr_in_cfg->measured_loudness = ixheaace_measure_loudness(loudness_handle, samples); |
630 | 40.9k | count += input_size; |
631 | 40.9k | } |
632 | 6.09k | if (pstr_in_cfg->method_def == METHOD_DEFINITION_PROGRAM_LOUDNESS) { |
633 | 21 | pstr_in_cfg->measured_loudness = ixheaace_measure_integrated_loudness(loudness_handle); |
634 | 21 | } |
635 | 16.1k | for (count = 0; count < pstr_in_cfg->i_channels; count++) { |
636 | 10.0k | free_global(samples[count]); |
637 | 10.0k | } |
638 | 6.09k | free_global(samples); |
639 | 6.09k | free_global(loudness_handle); |
640 | 6.09k | return err_code; |
641 | 6.09k | } |
642 | | |
643 | 12.4k | extern "C" int LLVMFuzzerTestOneInput(const uint8_t *data, size_t size) { |
644 | 12.4k | FuzzedDataProvider fuzzed_data(data, size); |
645 | 12.4k | FuzzedDataProvider fuzzed_data_loudness(data, size); |
646 | | |
647 | | /* Error code */ |
648 | 12.4k | IA_ERRORCODE err_code = 0; |
649 | | |
650 | | /* API obj */ |
651 | 12.4k | pVOID pv_ia_process_api_obj; |
652 | | |
653 | 12.4k | pWORD8 pb_inp_buf = NULL; |
654 | 12.4k | WORD32 input_size = 0; |
655 | 12.4k | WORD32 read_inp_data = 1; |
656 | 12.4k | WORD32 num_proc_iterations = 0; |
657 | | |
658 | | /* ******************************************************************/ |
659 | | /* The API config structure */ |
660 | | /* ******************************************************************/ |
661 | | |
662 | 12.4k | ixheaace_user_config_struct str_enc_api{}; |
663 | | |
664 | 12.4k | ixheaace_input_config *pstr_in_cfg = &str_enc_api.input_config; |
665 | 12.4k | ixheaace_output_config *pstr_out_cfg = &str_enc_api.output_config; |
666 | 12.4k | pstr_in_cfg->pv_drc_cfg = malloc_global(sizeof(ia_drc_input_config), DEFAULT_MEM_ALIGN_8); |
667 | 12.4k | ia_drc_input_config *pstr_drc_cfg = (ia_drc_input_config *)pstr_in_cfg->pv_drc_cfg; |
668 | 12.4k | memset(pstr_drc_cfg, 0, sizeof(ia_drc_input_config)); |
669 | | |
670 | 12.4k | pstr_out_cfg->malloc_xheaace = &malloc_global; |
671 | 12.4k | pstr_out_cfg->free_xheaace = &free_global; |
672 | | |
673 | | /* ******************************************************************/ |
674 | | /* Parse input configuration parameters */ |
675 | | /* ******************************************************************/ |
676 | 12.4k | ixheaace_fuzzer_flag(pstr_in_cfg, pstr_drc_cfg, &fuzzed_data, pstr_in_cfg->i_channels); |
677 | | |
678 | | /*1st pass -> Loudness Measurement */ |
679 | 12.4k | if (pstr_in_cfg->aot == AOT_USAC || pstr_in_cfg->usac_en) { |
680 | 7.61k | err_code = |
681 | 7.61k | ixheaace_calculate_loudness_measure(pstr_in_cfg, pstr_out_cfg, &fuzzed_data_loudness); |
682 | 7.61k | if (err_code) { |
683 | 1.51k | if (pstr_drc_cfg) { |
684 | 1.51k | free(pstr_drc_cfg); |
685 | 1.51k | pstr_drc_cfg = NULL; |
686 | 1.51k | } |
687 | | /* Fatal error code */ |
688 | 1.51k | if (err_code & 0x80000000) { |
689 | 1.51k | ixheaace_delete((pVOID)pstr_out_cfg); |
690 | 1.51k | return 0; |
691 | 1.51k | } |
692 | 0 | return -1; |
693 | 1.51k | } |
694 | 7.61k | } |
695 | | |
696 | 10.9k | err_code = ixheaace_create((pVOID)pstr_in_cfg, (pVOID)pstr_out_cfg); |
697 | 10.9k | if (err_code) { |
698 | 2.33k | if (pstr_drc_cfg) { |
699 | 2.33k | free(pstr_drc_cfg); |
700 | 2.33k | pstr_drc_cfg = NULL; |
701 | 2.33k | } |
702 | | /* Fatal error code */ |
703 | 2.33k | if (err_code & 0x80000000) { |
704 | 2.06k | ixheaace_delete((pVOID)pstr_out_cfg); |
705 | 2.06k | return 0; |
706 | 2.06k | } |
707 | 2.33k | } |
708 | | |
709 | 8.85k | pv_ia_process_api_obj = pstr_out_cfg->pv_ia_process_api_obj; |
710 | 8.85k | pb_inp_buf = (pWORD8)pstr_out_cfg->mem_info_table[IA_MEMTYPE_INPUT].mem_ptr; |
711 | | |
712 | | /* End first part */ |
713 | | |
714 | | /* Second part */ |
715 | | /* Initialize process */ |
716 | | /* Get config params */ |
717 | | |
718 | 8.85k | input_size = pstr_out_cfg->input_size; |
719 | 8.85k | memset(pb_inp_buf, 0, input_size); |
720 | | |
721 | 547k | while (fuzzed_data.remaining_bytes()) { |
722 | 538k | if (read_inp_data) { |
723 | 514k | if (fuzzed_data.ConsumeBool()) { |
724 | 109k | std::vector<WORD8> input_vec = fuzzed_data.ConsumeBytes<WORD8>(input_size); |
725 | 109k | if (input_vec.size()) { |
726 | 96.4k | memcpy(pb_inp_buf, input_vec.data(), input_vec.size()); |
727 | 96.4k | } |
728 | 405k | } else { |
729 | 405k | memset(pb_inp_buf, fuzzed_data.ConsumeIntegral<WORD8>(), input_size); |
730 | 405k | } |
731 | 514k | } |
732 | 538k | ixheaace_process(pv_ia_process_api_obj, (pVOID)pstr_in_cfg, (pVOID)pstr_out_cfg); |
733 | 538k | num_proc_iterations++; |
734 | 538k | if (pstr_out_cfg->i_out_bytes == 0) { |
735 | 24.5k | read_inp_data = 0; |
736 | 514k | } else { |
737 | 514k | read_inp_data = 1; |
738 | 514k | } |
739 | | /* Stop processing after 500 frames */ |
740 | 538k | if (num_proc_iterations > 500) break; |
741 | 538k | } |
742 | | |
743 | 8.85k | ixheaace_delete((pVOID)pstr_out_cfg); |
744 | | |
745 | 8.85k | if (pstr_drc_cfg) { |
746 | 8.58k | free(pstr_drc_cfg); |
747 | 8.58k | } |
748 | 8.85k | return 0; |
749 | 10.9k | } |
750 | | |
751 | | /* End ia_main_process() */ |