Coverage Report

Created: 2026-01-17 06:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libxaac/fuzzer/xaac_dec_fuzzer.cpp
Line
Count
Source
1
/******************************************************************************
2
 *
3
 * Copyright (C) 2019 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
#include <stddef.h>
22
#include <stdint.h>
23
#include <stdio.h>
24
#include <stdlib.h>
25
#include <string.h>
26
27
#include <vector>
28
29
#include "ixheaac_type_def.h"
30
#include "ixheaac_error_standards.h"
31
#include "ixheaacd_error_handler.h"
32
#include "ixheaacd_apicmd_standards.h"
33
#include "ixheaacd_memory_standards.h"
34
#include "ixheaacd_aac_config.h"
35
36
#include "impd_apicmd_standards.h"
37
#include "impd_drc_config_params.h"
38
39
/* 64*-0.25dB = -16 dB below full scale for mobile conf */
40
#define DRC_DEFAULT_MOBILE_REF_LEVEL 64
41
/* maximum compression of dynamic range for mobile conf */
42
#define DRC_DEFAULT_MOBILE_DRC_CUT 127
43
/* maximum compression of dynamic range for mobile conf */
44
#define DRC_DEFAULT_MOBILE_DRC_BOOST 127
45
/* switch for heavy compression for mobile conf */
46
#define DRC_DEFAULT_MOBILE_DRC_HEAVY 1
47
/* encoder target level; -1 => the value is unknown, otherwise dB \
48
             step value (e.g. 64 for -16 dB) */
49
#define DRC_DEFAULT_MOBILE_ENC_LEVEL (-1)
50
51
20.3k
#define MAX_CHANNEL_COUNT 8
52
53
#define MAX_MEM_ALLOCS 100
54
55
40.7k
#define IA_MAX_OUTPUT_PCM_SIZE (3)
56
40.7k
#define IA_MAX_USAC_CH (2)
57
40.7k
#define IA_MAX_OUT_SAMPLES_PER_FRAME (4096)
58
59
#define IA_DRC_DEC_IN_OUT_BUF_SIZE \
60
40.7k
  (IA_MAX_USAC_CH * IA_MAX_OUT_SAMPLES_PER_FRAME * IA_MAX_OUTPUT_PCM_SIZE)
61
62
class Codec {
63
 public:
64
  IA_ERRORCODE initDecoder(const uint8_t* data, size_t size, bool isADTS);
65
  IA_ERRORCODE initXAACDecoder(bool isADTS);
66
  IA_ERRORCODE initXAACDrc(const uint8_t* data, size_t size);
67
  IA_ERRORCODE deInitXAACDecoder();
68
  IA_ERRORCODE deInitMPEGDDDrc();
69
  IA_ERRORCODE configXAACDecoder(uint8_t* inBuffer, uint32_t inBufferLength,
70
                                 int32_t* bytesConsumed);
71
  IA_ERRORCODE initMPEGDDDrc();
72
  int configMPEGDDrc();
73
  IA_ERRORCODE decodeXAACStream(uint8_t* inBuffer, uint32_t inBufferLength,
74
                                int32_t* bytesConsumed, int32_t* outBytes);
75
  IA_ERRORCODE getXAACStreamInfo();
76
  IA_ERRORCODE setXAACDRCInfo(int32_t drcCut, int32_t drcBoost,
77
                              int32_t drcRefLevel, int32_t drcHeavyCompression,
78
                              int32_t drEffectType);
79
80
 private:
81
  void* mXheaacCodecHandle;
82
  void* mMpegDDrcHandle;
83
  uint32_t mInputBufferSize;
84
  uint32_t mOutputFrameLength;
85
  int8_t* mInputBuffer;
86
  int8_t* mOutputBuffer;
87
  int32_t mSampFreq;
88
  int32_t mNumChannels;
89
  int32_t mPcmWdSz;
90
  int32_t mChannelMask;
91
  bool mIsCodecInitialized;
92
  bool mIsCodecConfigFlushRequired;
93
  int8_t* mDrcInBuf;
94
  int8_t* mDrcOutBuf;
95
  int32_t mMpegDDRCPresent;
96
  int32_t mDRCFlag;
97
98
  std::vector<void*> mMemoryVec;
99
  std::vector<void*> mDrcMemoryVec;
100
};
101
102
extern "C" IA_ERRORCODE ixheaacd_dec_api(pVOID p_ia_module_obj, WORD32 i_cmd,
103
                                         WORD32 i_idx, pVOID pv_value);
104
extern "C" IA_ERRORCODE ia_drc_dec_api(pVOID p_ia_module_obj, WORD32 i_cmd,
105
                                       WORD32 i_idx, pVOID pv_value);
106
extern "C" IA_ERRORCODE ixheaacd_get_config_param(pVOID p_ia_process_api_obj,
107
                                                  pWORD32 pi_samp_freq,
108
                                                  pWORD32 pi_num_chan,
109
                                                  pWORD32 pi_pcm_wd_sz,
110
                                                  pWORD32 pi_channel_mask);
111
112
23.4k
IA_ERRORCODE Codec::initXAACDecoder(bool isADTS) {
113
  /* First part                                        */
114
  /* Error Handler Init                                */
115
  /* Get Library Name, Library Version and API Version */
116
  /* Initialize API structure + Default config set     */
117
  /* Set config params from user                       */
118
  /* Initialize memory tables                          */
119
  /* Get memory information and allocate memory        */
120
121
23.4k
  mInputBufferSize = 0;
122
23.4k
  mInputBuffer = nullptr;
123
23.4k
  mOutputBuffer = nullptr;
124
  /* Process struct initing end */
125
126
  /* ******************************************************************/
127
  /* Initialize API structure and set config params to default        */
128
  /* ******************************************************************/
129
  /* API size */
130
23.4k
  uint32_t pui_api_size;
131
  /* Get the API size */
132
23.4k
  IA_ERRORCODE err_code =
133
23.4k
      ixheaacd_dec_api(nullptr, IA_API_CMD_GET_API_SIZE, 0, &pui_api_size);
134
135
  /* Allocate memory for API */
136
23.4k
  mXheaacCodecHandle = malloc(pui_api_size);
137
23.4k
  if (!mXheaacCodecHandle) {
138
0
    return IA_FATAL_ERROR;
139
0
  }
140
23.4k
  mMemoryVec.push_back(mXheaacCodecHandle);
141
142
  /* Set the config params to default values */
143
23.4k
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_INIT,
144
23.4k
                              IA_CMD_TYPE_INIT_API_PRE_CONFIG_PARAMS, nullptr);
145
146
  /* Get the API size */
147
23.4k
  err_code = ia_drc_dec_api(nullptr, IA_API_CMD_GET_API_SIZE, 0, &pui_api_size);
148
149
  /* Allocate memory for API */
150
23.4k
  mMpegDDrcHandle = malloc(pui_api_size);
151
23.4k
  if (!mMpegDDrcHandle) {
152
0
    return IA_FATAL_ERROR;
153
0
  }
154
23.4k
  mMemoryVec.push_back(mMpegDDrcHandle);
155
156
  /* Set the config params to default values */
157
23.4k
  err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT,
158
23.4k
                            IA_CMD_TYPE_INIT_API_PRE_CONFIG_PARAMS, nullptr);
159
160
  /* ******************************************************************/
161
  /* Set config parameters                                            */
162
  /* ******************************************************************/
163
23.4k
  uint32_t ui_mp4_flag = isADTS ? 0 : 1;
164
23.4k
  err_code =
165
23.4k
      ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
166
23.4k
                       IA_ENHAACPLUS_DEC_CONFIG_PARAM_ISMP4, &ui_mp4_flag);
167
168
  /* ******************************************************************/
169
  /* Initialize Memory info tables                                    */
170
  /* ******************************************************************/
171
23.4k
  uint32_t ui_proc_mem_tabs_size;
172
23.4k
  pVOID pv_alloc_ptr;
173
  /* Get memory info tables size */
174
23.4k
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_MEMTABS_SIZE,
175
23.4k
                              0, &ui_proc_mem_tabs_size);
176
177
23.4k
  pv_alloc_ptr = malloc(ui_proc_mem_tabs_size);
178
23.4k
  if (!pv_alloc_ptr) {
179
0
    return IA_FATAL_ERROR;
180
0
  }
181
23.4k
  mMemoryVec.push_back(pv_alloc_ptr);
182
183
  /* Set pointer for process memory tables    */
184
23.4k
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_MEMTABS_PTR, 0,
185
23.4k
                              pv_alloc_ptr);
186
187
  /* initialize the API, post config, fill memory tables  */
188
23.4k
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_INIT,
189
23.4k
                              IA_CMD_TYPE_INIT_API_POST_CONFIG_PARAMS, nullptr);
190
191
  /* ******************************************************************/
192
  /* Allocate Memory with info from library                           */
193
  /* ******************************************************************/
194
  /* There are four different types of memories, that needs to be allocated */
195
  /* persistent,scratch,input and output */
196
117k
  for (int i = 0; i < 4; i++) {
197
93.6k
    int ui_size = 0, ui_alignment = 0, ui_type = 0;
198
199
    /* Get memory size */
200
93.6k
    err_code = ixheaacd_dec_api(mXheaacCodecHandle,
201
93.6k
                                IA_API_CMD_GET_MEM_INFO_SIZE, i, &ui_size);
202
203
    /* Get memory alignment */
204
93.6k
    err_code =
205
93.6k
        ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_MEM_INFO_ALIGNMENT,
206
93.6k
                         i, &ui_alignment);
207
208
    /* Get memory type */
209
93.6k
    err_code = ixheaacd_dec_api(mXheaacCodecHandle,
210
93.6k
                                IA_API_CMD_GET_MEM_INFO_TYPE, i, &ui_type);
211
212
93.6k
    pv_alloc_ptr = NULL;
213
93.6k
    ui_alignment = (ui_alignment + sizeof(void *) - 1) / sizeof(void *);
214
93.6k
    ui_alignment = ui_alignment * sizeof(void *);
215
93.6k
    if (0 != posix_memalign(&pv_alloc_ptr, ui_alignment, ui_size)) {
216
0
      return IA_FATAL_ERROR;
217
0
    }
218
93.6k
    if (!pv_alloc_ptr) {
219
0
      return IA_FATAL_ERROR;
220
0
    }
221
93.6k
    mMemoryVec.push_back(pv_alloc_ptr);
222
223
    /* Set the buffer pointer */
224
93.6k
    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_MEM_PTR, i,
225
93.6k
                                pv_alloc_ptr);
226
227
93.6k
    if (ui_type == IA_MEMTYPE_INPUT) {
228
23.4k
      mInputBuffer = (pWORD8)pv_alloc_ptr;
229
23.4k
      mInputBufferSize = ui_size;
230
23.4k
    }
231
93.6k
    if (ui_type == IA_MEMTYPE_OUTPUT) mOutputBuffer = (pWORD8)pv_alloc_ptr;
232
93.6k
  }
233
  /* End first part */
234
235
23.4k
  return IA_NO_ERROR;
236
23.4k
}
237
enum {
238
  DRC_TARGET_LEVEL_OFFSET = 6,
239
  DRC_ATTENUATION_OFFSET,
240
  DRC_BOOST_OFFSET,
241
  DRC_COMPRESS_OFFSET,
242
  DRC_EFFECT_OFFSET
243
#ifdef LOUDNESS_LEVELING_SUPPORT
244
  ,
245
  DRC_LOUDNESS_LEVELING_OFFSET
246
#endif
247
};
248
249
23.4k
IA_ERRORCODE Codec::initXAACDrc(const uint8_t* data, size_t size) {
250
23.4k
  IA_ERRORCODE err_code = IA_NO_ERROR;
251
23.4k
  unsigned int ui_drc_val;
252
  //  DRC_PRES_MODE_WRAP_DESIRED_TARGET
253
23.4k
  size_t targetLevelOffset =
254
23.4k
      std::min((size_t)DRC_TARGET_LEVEL_OFFSET, size - 1);
255
23.4k
  int32_t targetRefLevel = data[targetLevelOffset];
256
257
23.4k
  ui_drc_val = (unsigned int)targetRefLevel;
258
23.4k
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
259
23.4k
                              IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_TARGET_LEVEL,
260
23.4k
                              &ui_drc_val);
261
262
  /* Use ui_drc_val from PROP_DRC_OVERRIDE_REF_LEVEL or
263
   * DRC_DEFAULT_MOBILE_REF_LEVEL
264
   * for IA_ENHAACPLUS_DEC_DRC_TARGET_LOUDNESS too */
265
23.4k
  err_code =
266
23.4k
      ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
267
23.4k
                       IA_ENHAACPLUS_DEC_DRC_TARGET_LOUDNESS, &ui_drc_val);
268
269
23.4k
  size_t attenuationOffset = std::min((size_t)DRC_ATTENUATION_OFFSET, size - 1);
270
23.4k
  int32_t attenuationFactor = data[attenuationOffset];
271
272
23.4k
  ui_drc_val = (unsigned int)attenuationFactor;
273
23.4k
  err_code =
274
23.4k
      ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
275
23.4k
                       IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_CUT, &ui_drc_val);
276
277
  //  DRC_PRES_MODE_WRAP_DESIRED_BOOST_FACTOR
278
23.4k
  size_t boostOffset = std::min((size_t)DRC_BOOST_OFFSET, size - 1);
279
23.4k
  int32_t boostFactor = data[boostOffset];
280
281
23.4k
  ui_drc_val = (unsigned int)boostFactor;
282
23.4k
  err_code =
283
23.4k
      ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
284
23.4k
                       IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_BOOST, &ui_drc_val);
285
286
  //  DRC_PRES_MODE_WRAP_DESIRED_HEAVY
287
23.4k
  size_t compressOffset = std::min((size_t)DRC_COMPRESS_OFFSET, size - 1);
288
23.4k
  int32_t compressMode = data[compressOffset];
289
23.4k
  ui_drc_val = (unsigned int)compressMode;
290
291
23.4k
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
292
23.4k
                              IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_HEAVY_COMP,
293
23.4k
                              &ui_drc_val);
294
295
  // AAC_UNIDRC_SET_EFFECT
296
23.4k
  size_t effectOffset = std::min((size_t)DRC_EFFECT_OFFSET, size - 1);
297
23.4k
  int32_t effectType = data[effectOffset];
298
23.4k
  ui_drc_val = (unsigned int)effectType;
299
23.4k
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
300
23.4k
                              IA_ENHAACPLUS_DEC_DRC_EFFECT_TYPE, &ui_drc_val);
301
302
23.4k
#ifdef LOUDNESS_LEVELING_SUPPORT
303
  // DRC_LOUDNESS_LEVELING_FLAG
304
23.4k
  size_t flagOffset = std::min((size_t)DRC_LOUDNESS_LEVELING_OFFSET, size - 1);
305
23.4k
  uint8_t loudnessFlag = data[flagOffset];
306
23.4k
  ui_drc_val = (unsigned int)loudnessFlag;
307
23.4k
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
308
23.4k
                              IA_XHEAAC_DEC_CONFIG_PARAM_DRC_LOUDNESS_LEVELING, &ui_drc_val);
309
23.4k
#endif
310
311
23.4k
  return IA_NO_ERROR;
312
23.4k
}
313
314
23.4k
IA_ERRORCODE Codec::deInitXAACDecoder() {
315
  /* Error code */
316
23.4k
  IA_ERRORCODE err_code = IA_NO_ERROR;
317
318
23.4k
  if (mXheaacCodecHandle) {
319
    /* Tell that the input is over in this buffer */
320
23.4k
    err_code =
321
23.4k
        ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_INPUT_OVER, 0, nullptr);
322
23.4k
  }
323
324
  /* Irrespective of error returned in IA_API_CMD_INPUT_OVER, free allocated
325
   * memory */
326
184k
  for (void* buf : mMemoryVec) {
327
184k
    if (buf) free(buf);
328
184k
  }
329
23.4k
  mMemoryVec.clear();
330
23.4k
  mXheaacCodecHandle = nullptr;
331
332
23.4k
  return err_code;
333
23.4k
}
334
335
43.7k
IA_ERRORCODE Codec::deInitMPEGDDDrc() {
336
81.4k
  for (void* buf : mDrcMemoryVec) {
337
81.4k
    if (buf) free(buf);
338
81.4k
  }
339
43.7k
  mDrcMemoryVec.clear();
340
43.7k
  return IA_NO_ERROR;
341
43.7k
}
342
343
IA_ERRORCODE Codec::configXAACDecoder(uint8_t* inBuffer,
344
                                      uint32_t inBufferLength,
345
37.5k
                                      int32_t* bytesConsumed) {
346
37.5k
  if (mInputBufferSize < inBufferLength) {
347
2.21k
    inBufferLength = mInputBufferSize;
348
2.21k
  }
349
  /* Copy the buffer passed by Android plugin to codec input buffer */
350
37.5k
  memcpy(mInputBuffer, inBuffer, inBufferLength);
351
352
  /* Set number of bytes to be processed */
353
37.5k
  IA_ERRORCODE err_code = ixheaacd_dec_api(
354
37.5k
      mXheaacCodecHandle, IA_API_CMD_SET_INPUT_BYTES, 0, &inBufferLength);
355
356
37.5k
  if (mIsCodecConfigFlushRequired) {
357
    /* If codec is already initialized, then GA header is passed again */
358
    /* Need to call the Flush API instead of INIT_PROCESS */
359
0
    mIsCodecInitialized =
360
0
        false; /* Codec needs to be Reinitialized after flush */
361
0
    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_INIT,
362
0
                                IA_CMD_TYPE_GA_HDR, nullptr);
363
364
37.5k
  } else {
365
    /* Initialize the process */
366
37.5k
    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_INIT,
367
37.5k
                                IA_CMD_TYPE_INIT_PROCESS, nullptr);
368
37.5k
  }
369
370
37.5k
  uint32_t ui_init_done;
371
  /* Checking for end of initialization */
372
37.5k
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_INIT,
373
37.5k
                              IA_CMD_TYPE_INIT_DONE_QUERY, &ui_init_done);
374
375
  /* How much buffer is used in input buffers */
376
37.5k
  err_code = ixheaacd_dec_api(
377
37.5k
      mXheaacCodecHandle, IA_API_CMD_GET_CURIDX_INPUT_BUF, 0, bytesConsumed);
378
379
37.5k
  if (ui_init_done) {
380
20.3k
    err_code = getXAACStreamInfo();
381
382
20.3k
    mIsCodecInitialized = true;
383
384
20.3k
    err_code = configMPEGDDrc();
385
20.3k
  }
386
387
37.5k
  return IA_NO_ERROR;
388
37.5k
}
389
20.3k
IA_ERRORCODE Codec::initMPEGDDDrc() {
390
20.3k
  IA_ERRORCODE err_code = IA_NO_ERROR;
391
392
61.0k
  for (int i = 0; i < (WORD32)2; i++) {
393
40.7k
    WORD32 ui_size, ui_alignment, ui_type;
394
40.7k
    pVOID pv_alloc_ptr;
395
396
    /* Get memory size */
397
40.7k
    err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_GET_MEM_INFO_SIZE, i,
398
40.7k
                              &ui_size);
399
400
    /* Get memory alignment */
401
40.7k
    err_code = ia_drc_dec_api(
402
40.7k
        mMpegDDrcHandle, IA_API_CMD_GET_MEM_INFO_ALIGNMENT, i, &ui_alignment);
403
404
    /* Get memory type */
405
40.7k
    err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_GET_MEM_INFO_TYPE, i,
406
40.7k
                              &ui_type);
407
408
40.7k
    pv_alloc_ptr = malloc(ui_size);
409
40.7k
    if (pv_alloc_ptr == nullptr) {
410
0
      return IA_FATAL_ERROR;
411
0
    }
412
40.7k
    mDrcMemoryVec.push_back(pv_alloc_ptr);
413
414
    /* Set the buffer pointer */
415
40.7k
    err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_MEM_PTR, i,
416
40.7k
                              pv_alloc_ptr);
417
40.7k
  }
418
419
20.3k
  mDrcInBuf = (int8_t*)malloc(IA_DRC_DEC_IN_OUT_BUF_SIZE);
420
20.3k
  if (mDrcInBuf == nullptr) {
421
0
    return IA_FATAL_ERROR;
422
0
  }
423
20.3k
  mDrcMemoryVec.push_back(mDrcInBuf);
424
425
20.3k
  err_code =
426
20.3k
      ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_MEM_PTR, 2, mDrcInBuf);
427
428
20.3k
  mDrcOutBuf = (int8_t*)malloc(IA_DRC_DEC_IN_OUT_BUF_SIZE);
429
20.3k
  if (mDrcOutBuf == nullptr) {
430
0
    return IA_FATAL_ERROR;
431
0
  }
432
20.3k
  mDrcMemoryVec.push_back(mDrcOutBuf);
433
434
20.3k
  err_code =
435
20.3k
      ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_MEM_PTR, 3, mDrcOutBuf);
436
437
20.3k
  return IA_NO_ERROR;
438
20.3k
}
439
20.3k
int Codec::configMPEGDDrc() {
440
20.3k
  IA_ERRORCODE err_code = IA_NO_ERROR;
441
20.3k
  int i_effect_type;
442
20.3k
  int i_loud_norm;
443
20.3k
  int i_target_loudness;
444
20.3k
  unsigned int i_sbr_mode;
445
20.3k
  uint32_t ui_proc_mem_tabs_size = 0;
446
20.3k
  pVOID pv_alloc_ptr = NULL;
447
448
  /* Sampling Frequency */
449
20.3k
  err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
450
20.3k
                            IA_DRC_DEC_CONFIG_PARAM_SAMP_FREQ, &mSampFreq);
451
452
  /* Total Number of Channels */
453
20.3k
  err_code =
454
20.3k
      ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
455
20.3k
                     IA_DRC_DEC_CONFIG_PARAM_NUM_CHANNELS, &mNumChannels);
456
457
  /* PCM word size  */
458
20.3k
  err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
459
20.3k
                            IA_DRC_DEC_CONFIG_PARAM_PCM_WDSZ, &mPcmWdSz);
460
461
  /*Set Effect Type*/
462
20.3k
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
463
20.3k
                              IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_EFFECT_TYPE,
464
20.3k
                              &i_effect_type);
465
466
20.3k
  err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
467
20.3k
                            IA_DRC_DEC_CONFIG_DRC_EFFECT_TYPE, &i_effect_type);
468
469
  /*Set target loudness */
470
20.3k
  err_code = ixheaacd_dec_api(
471
20.3k
      mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
472
20.3k
      IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_TARGET_LOUDNESS, &i_target_loudness);
473
474
20.3k
  err_code =
475
20.3k
      ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
476
20.3k
                     IA_DRC_DEC_CONFIG_DRC_TARGET_LOUDNESS, &i_target_loudness);
477
478
  /*Set loud_norm_flag*/
479
20.3k
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
480
20.3k
                              IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_LOUD_NORM,
481
20.3k
                              &i_loud_norm);
482
483
20.3k
  err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
484
20.3k
                            IA_DRC_DEC_CONFIG_DRC_LOUD_NORM, &i_loud_norm);
485
486
20.3k
  err_code =
487
20.3k
      ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
488
20.3k
                       IA_ENHAACPLUS_DEC_CONFIG_PARAM_SBR_MODE, &i_sbr_mode);
489
490
  /* Get memory info tables size */
491
20.3k
  err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_GET_MEMTABS_SIZE, 0,
492
20.3k
                            &ui_proc_mem_tabs_size);
493
494
20.3k
  pv_alloc_ptr = malloc(ui_proc_mem_tabs_size);
495
20.3k
  if (pv_alloc_ptr == NULL) {
496
0
    return IA_FATAL_ERROR;
497
0
  }
498
20.3k
  memset(pv_alloc_ptr, 0, ui_proc_mem_tabs_size);
499
20.3k
  mMemoryVec.push_back(pv_alloc_ptr);
500
501
  /* Set pointer for process memory tables */
502
20.3k
  err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_MEMTABS_PTR, 0,
503
20.3k
                            pv_alloc_ptr);
504
505
20.3k
  err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT,
506
20.3k
                            IA_CMD_TYPE_INIT_API_POST_CONFIG_PARAMS, nullptr);
507
508
  /* Free any memory that is allocated for MPEG D Drc so far */
509
20.3k
  deInitMPEGDDDrc();
510
511
20.3k
  err_code = initMPEGDDDrc();
512
20.3k
  if (err_code != IA_NO_ERROR) {
513
0
    deInitMPEGDDDrc();
514
0
    return err_code;
515
0
  }
516
517
  /* DRC buffers
518
      buf[0] - contains extension element pay load loudness related
519
      buf[1] - contains extension element pay load*/
520
20.3k
  {
521
20.3k
    VOID* p_array[2][16];
522
20.3k
    WORD32 ii;
523
20.3k
    WORD32 buf_sizes[2][16];
524
20.3k
    WORD32 num_elements;
525
20.3k
    WORD32 num_config_ext;
526
20.3k
    WORD32 bit_str_fmt = 1;
527
528
20.3k
    WORD32 uo_num_chan;
529
530
20.3k
    memset(buf_sizes, 0, 32 * sizeof(WORD32));
531
532
20.3k
    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
533
20.3k
                                IA_ENHAACPLUS_DEC_CONFIG_EXT_ELE_BUF_SIZES,
534
20.3k
                                &buf_sizes[0][0]);
535
536
20.3k
    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
537
20.3k
                                IA_ENHAACPLUS_DEC_CONFIG_EXT_ELE_PTR, &p_array);
538
539
20.3k
    err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT,
540
20.3k
                              IA_CMD_TYPE_INIT_SET_BUFF_PTR, nullptr);
541
542
20.3k
    err_code =
543
20.3k
        ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
544
20.3k
                         IA_ENHAACPLUS_DEC_CONFIG_NUM_ELE, &num_elements);
545
546
20.3k
    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
547
20.3k
                                IA_ENHAACPLUS_DEC_CONFIG_NUM_CONFIG_EXT,
548
20.3k
                                &num_config_ext);
549
550
29.1k
    for (ii = 0; ii < num_config_ext; ii++) {
551
      /*copy loudness bitstream*/
552
8.83k
      if (buf_sizes[0][ii] > 0) {
553
1.12k
        memcpy(mDrcInBuf, p_array[0][ii], buf_sizes[0][ii]);
554
555
        /*Set bitstream_split_format */
556
1.12k
        err_code =
557
1.12k
            ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
558
1.12k
                           IA_DRC_DEC_CONFIG_PARAM_BITS_FORMAT, &bit_str_fmt);
559
560
        /* Set number of bytes to be processed */
561
1.12k
        err_code =
562
1.12k
            ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_INPUT_BYTES_IL_BS, 0,
563
1.12k
                           &buf_sizes[0][ii]);
564
565
        /* Execute process */
566
1.12k
        err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT,
567
1.12k
                                  IA_CMD_TYPE_INIT_CPY_IL_BSF_BUFF, nullptr);
568
569
1.12k
        mDRCFlag = 1;
570
1.12k
      }
571
8.83k
    }
572
573
37.9k
    for (ii = 0; ii < num_elements; ii++) {
574
      /*copy config bitstream*/
575
17.5k
      if (buf_sizes[1][ii] > 0) {
576
1.55k
        memcpy(mDrcInBuf, p_array[1][ii], buf_sizes[1][ii]);
577
        /* Set number of bytes to be processed */
578
579
        /*Set bitstream_split_format */
580
1.55k
        err_code =
581
1.55k
            ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
582
1.55k
                           IA_DRC_DEC_CONFIG_PARAM_BITS_FORMAT, &bit_str_fmt);
583
584
1.55k
        err_code =
585
1.55k
            ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_INPUT_BYTES_IC_BS, 0,
586
1.55k
                           &buf_sizes[1][ii]);
587
588
        /* Execute process */
589
1.55k
        err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT,
590
1.55k
                                  IA_CMD_TYPE_INIT_CPY_IC_BSF_BUFF, nullptr);
591
592
1.55k
        mDRCFlag = 1;
593
1.55k
      }
594
17.5k
    }
595
596
20.3k
    if (mDRCFlag == 1) {
597
2.02k
      mMpegDDRCPresent = 1;
598
18.3k
    } else {
599
18.3k
      mMpegDDRCPresent = 0;
600
18.3k
    }
601
602
    /*Read interface buffer config file bitstream*/
603
20.3k
    if (mMpegDDRCPresent == 1) {
604
2.02k
      WORD32 interface_is_present = 1;
605
606
2.02k
      if (i_sbr_mode != 0) {
607
926
        if (i_sbr_mode == 1) {
608
876
          mOutputFrameLength = 2048;
609
876
        } else if (i_sbr_mode == 3) {
610
50
          mOutputFrameLength = 4096;
611
50
        } else {
612
0
          mOutputFrameLength = 1024;
613
0
        }
614
1.09k
      } else {
615
1.09k
        mOutputFrameLength = 4096;
616
1.09k
      }
617
618
2.02k
      err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
619
2.02k
                                IA_DRC_DEC_CONFIG_PARAM_FRAME_SIZE,
620
2.02k
                                (WORD32*)&mOutputFrameLength);
621
622
2.02k
      err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
623
2.02k
                                IA_DRC_DEC_CONFIG_PARAM_INT_PRESENT,
624
2.02k
                                &interface_is_present);
625
626
      /* Execute process */
627
2.02k
      err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT,
628
2.02k
                                IA_CMD_TYPE_INIT_CPY_IN_BSF_BUFF, nullptr);
629
630
2.02k
      err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT,
631
2.02k
                                IA_CMD_TYPE_INIT_PROCESS, nullptr);
632
633
2.02k
      err_code =
634
2.02k
          ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_GET_CONFIG_PARAM,
635
2.02k
                         IA_DRC_DEC_CONFIG_PARAM_NUM_CHANNELS, &uo_num_chan);
636
2.02k
    }
637
20.3k
  }
638
639
20.3k
  return err_code;
640
20.3k
}
641
23.4k
IA_ERRORCODE Codec::initDecoder(const uint8_t* data, size_t size, bool isADTS) {
642
23.4k
  IA_ERRORCODE err_code = IA_NO_ERROR;
643
644
23.4k
  err_code = initXAACDecoder(isADTS);
645
23.4k
  if (err_code != IA_NO_ERROR) {
646
    /* Call deInit to free any allocated memory */
647
0
    deInitXAACDecoder();
648
0
    return IA_FATAL_ERROR;
649
0
  }
650
651
23.4k
  err_code = initXAACDrc(data, size);
652
653
23.4k
  return IA_NO_ERROR;
654
23.4k
}
655
IA_ERRORCODE Codec::decodeXAACStream(uint8_t* inBuffer, uint32_t inBufferLength,
656
                                     int32_t* bytesConsumed,
657
527k
                                     int32_t* outBytes) {
658
527k
  if (mInputBufferSize < inBufferLength) {
659
227k
    inBufferLength = mInputBufferSize;
660
227k
  }
661
  /* If codec is not initialized, call configXAACDecoder decoder again */
662
527k
  if (!mIsCodecInitialized) {
663
14.1k
    configXAACDecoder(inBuffer, inBufferLength, bytesConsumed);
664
14.1k
  }
665
  /* Copy the buffer passed by Android plugin to codec input buffer */
666
527k
  memcpy(mInputBuffer, inBuffer, inBufferLength);
667
668
  /* Set number of bytes to be processed */
669
527k
  IA_ERRORCODE err_code = ixheaacd_dec_api(
670
527k
      mXheaacCodecHandle, IA_API_CMD_SET_INPUT_BYTES, 0, &inBufferLength);
671
672
  /* Execute process */
673
527k
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_EXECUTE,
674
527k
                              IA_CMD_TYPE_DO_EXECUTE, nullptr);
675
676
  /* Checking for end of processing */
677
527k
  uint32_t ui_exec_done;
678
527k
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_EXECUTE,
679
527k
                              IA_CMD_TYPE_DONE_QUERY, &ui_exec_done);
680
681
527k
  if (ui_exec_done != 1) {
682
527k
    VOID* p_array;        // ITTIAM:buffer to handle gain payload
683
527k
    WORD32 buf_size = 0;  // ITTIAM:gain payload length
684
527k
    WORD32 bit_str_fmt = 1;
685
527k
    WORD32 gain_stream_flag = 1;
686
687
527k
    err_code =
688
527k
        ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
689
527k
                         IA_ENHAACPLUS_DEC_CONFIG_GAIN_PAYLOAD_LEN, &buf_size);
690
691
527k
    err_code =
692
527k
        ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
693
527k
                         IA_ENHAACPLUS_DEC_CONFIG_GAIN_PAYLOAD_BUF, &p_array);
694
695
527k
    if (buf_size > 0) {
696
      /*Set bitstream_split_format */
697
2.76k
      err_code =
698
2.76k
          ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
699
2.76k
                         IA_DRC_DEC_CONFIG_PARAM_BITS_FORMAT, &bit_str_fmt);
700
701
2.76k
      memcpy(mDrcInBuf, p_array, buf_size);
702
      /* Set number of bytes to be processed */
703
2.76k
      err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_INPUT_BYTES_BS,
704
2.76k
                                0, &buf_size);
705
706
2.76k
      err_code =
707
2.76k
          ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
708
2.76k
                         IA_DRC_DEC_CONFIG_GAIN_STREAM_FLAG, &gain_stream_flag);
709
710
      /* Execute process */
711
2.76k
      err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT,
712
2.76k
                                IA_CMD_TYPE_INIT_CPY_BSF_BUFF, nullptr);
713
714
2.76k
      mMpegDDRCPresent = 1;
715
2.76k
    }
716
527k
  }
717
718
  /* How much buffer is used in input buffers */
719
527k
  err_code = ixheaacd_dec_api(
720
527k
      mXheaacCodecHandle, IA_API_CMD_GET_CURIDX_INPUT_BUF, 0, bytesConsumed);
721
722
  /* Get the output bytes */
723
527k
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_OUTPUT_BYTES,
724
527k
                              0, outBytes);
725
726
527k
  if (mMpegDDRCPresent == 1) {
727
47.6k
    memcpy(mDrcInBuf, mOutputBuffer, *outBytes);
728
47.6k
    err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_INPUT_BYTES, 0,
729
47.6k
                              outBytes);
730
731
47.6k
    err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_EXECUTE,
732
47.6k
                              IA_CMD_TYPE_DO_EXECUTE, nullptr);
733
734
47.6k
    memcpy(mOutputBuffer, mDrcOutBuf, *outBytes);
735
47.6k
  }
736
527k
  return IA_NO_ERROR;
737
527k
}
738
739
20.3k
IA_ERRORCODE Codec::getXAACStreamInfo() {
740
20.3k
  IA_ERRORCODE err_code = IA_NO_ERROR;
741
742
  /* Sampling frequency */
743
20.3k
  err_code =
744
20.3k
      ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
745
20.3k
                       IA_ENHAACPLUS_DEC_CONFIG_PARAM_SAMP_FREQ, &mSampFreq);
746
747
  /* Total Number of Channels */
748
20.3k
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
749
20.3k
                              IA_ENHAACPLUS_DEC_CONFIG_PARAM_NUM_CHANNELS,
750
20.3k
                              &mNumChannels);
751
752
20.3k
  if (mNumChannels > MAX_CHANNEL_COUNT) {
753
0
    return IA_FATAL_ERROR;
754
0
  }
755
756
  /* PCM word size */
757
20.3k
  err_code =
758
20.3k
      ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
759
20.3k
                       IA_ENHAACPLUS_DEC_CONFIG_PARAM_PCM_WDSZ, &mPcmWdSz);
760
761
20.3k
  if ((mPcmWdSz / 8) != 2) {
762
0
    return IA_FATAL_ERROR;
763
0
  }
764
765
  /* channel mask to tell the arrangement of channels in bit stream */
766
20.3k
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
767
20.3k
                              IA_ENHAACPLUS_DEC_CONFIG_PARAM_CHANNEL_MASK,
768
20.3k
                              &mChannelMask);
769
770
  /* Channel mode to tell MONO/STEREO/DUAL-MONO/NONE_OF_THESE */
771
20.3k
  uint32_t ui_channel_mode;
772
20.3k
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
773
20.3k
                              IA_ENHAACPLUS_DEC_CONFIG_PARAM_CHANNEL_MODE,
774
20.3k
                              &ui_channel_mode);
775
776
  /* Channel mode to tell SBR PRESENT/NOT_PRESENT */
777
20.3k
  uint32_t ui_sbr_mode;
778
20.3k
  err_code =
779
20.3k
      ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
780
20.3k
                       IA_ENHAACPLUS_DEC_CONFIG_PARAM_SBR_MODE, &ui_sbr_mode);
781
782
  /* mOutputFrameLength = 1024 * (1 + SBR_MODE) for AAC */
783
  /* For USAC it could be 1024 * 3 , support to query  */
784
  /* not yet added in codec                            */
785
20.3k
  mOutputFrameLength = 1024 * (1 + ui_sbr_mode);
786
787
20.3k
  return IA_NO_ERROR;
788
20.3k
}
789
790
IA_ERRORCODE Codec::setXAACDRCInfo(int32_t drcCut, int32_t drcBoost,
791
                                   int32_t drcRefLevel,
792
                                   int32_t drcHeavyCompression,
793
0
                                   int32_t drEffectType) {
794
0
  IA_ERRORCODE err_code = IA_NO_ERROR;
795
796
0
  int32_t ui_drc_enable = 1;
797
0
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
798
0
                              IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_ENABLE,
799
0
                              &ui_drc_enable);
800
801
0
  if (drcCut != -1) {
802
0
    err_code =
803
0
        ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
804
0
                         IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_CUT, &drcCut);
805
0
  }
806
807
0
  if (drcBoost != -1) {
808
0
    err_code =
809
0
        ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
810
0
                         IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_BOOST, &drcBoost);
811
0
  }
812
813
0
  if (drcRefLevel != -1) {
814
0
    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
815
0
                                IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_TARGET_LEVEL,
816
0
                                &drcRefLevel);
817
0
  }
818
819
0
  if (drcRefLevel != -1) {
820
0
    err_code =
821
0
        ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
822
0
                         IA_ENHAACPLUS_DEC_DRC_TARGET_LOUDNESS, &drcRefLevel);
823
0
  }
824
825
0
  if (drcHeavyCompression != -1) {
826
0
    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
827
0
                                IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_HEAVY_COMP,
828
0
                                &drcHeavyCompression);
829
0
  }
830
831
0
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
832
0
                              IA_ENHAACPLUS_DEC_DRC_EFFECT_TYPE, &drEffectType);
833
834
0
  int32_t i_effect_type, i_target_loudness, i_loud_norm;
835
  /*Set Effect Type*/
836
0
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
837
0
                              IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_EFFECT_TYPE,
838
0
                              &i_effect_type);
839
840
0
  err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
841
0
                            IA_DRC_DEC_CONFIG_DRC_EFFECT_TYPE, &i_effect_type);
842
843
  /*Set target loudness */
844
0
  err_code = ixheaacd_dec_api(
845
0
      mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
846
0
      IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_TARGET_LOUDNESS, &i_target_loudness);
847
848
0
  err_code =
849
0
      ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
850
0
                     IA_DRC_DEC_CONFIG_DRC_TARGET_LOUDNESS, &i_target_loudness);
851
852
  /*Set loud_norm_flag*/
853
0
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
854
0
                              IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_LOUD_NORM,
855
0
                              &i_loud_norm);
856
857
0
  err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
858
0
                            IA_DRC_DEC_CONFIG_DRC_LOUD_NORM, &i_loud_norm);
859
860
0
  return IA_NO_ERROR;
861
0
}
862
863
23.4k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
864
23.4k
  int status;
865
23.4k
  int num_proc_iterations = 0;
866
23.4k
  if (size < 1) return 0;
867
23.4k
  Codec* codec = new Codec();
868
23.4k
  bool isADTS = false;
869
23.4k
  if (size >= 2) {
870
23.4k
    if ((data[0] == 0xFF) && ((data[1] & 0xF0) == 0xF0)) {
871
21.0k
      isADTS = true;
872
21.0k
    }
873
23.4k
  }
874
23.4k
  status = codec->initDecoder(data, size, isADTS);
875
23.4k
  if (0 == status) {
876
23.4k
    int32_t bytesConsumed = 0;
877
23.4k
    status = codec->configXAACDecoder((uint8_t*)data, size, &bytesConsumed);
878
550k
    while ((int32_t)size > bytesConsumed) {
879
527k
      int32_t numOutBytes;
880
527k
      size -= bytesConsumed;
881
527k
      data += bytesConsumed;
882
527k
      status = codec->decodeXAACStream((uint8_t*)data, size, &bytesConsumed,
883
527k
                                       &numOutBytes);
884
527k
      num_proc_iterations++;
885
      /* Stop processing after 500 frames */
886
527k
      if (num_proc_iterations > 500)
887
52
        break;
888
889
      /* If decoder doesn't consume any bytes, advance by 4 bytes */
890
527k
      if (0 == bytesConsumed) bytesConsumed = 4;
891
527k
    }
892
23.4k
  }
893
23.4k
  status = codec->deInitXAACDecoder();
894
23.4k
  status = codec->deInitMPEGDDDrc();
895
23.4k
  delete codec;
896
23.4k
  return 0;
897
23.4k
}