Coverage Report

Created: 2026-02-07 06:17

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
14.9k
#define MAX_CHANNEL_COUNT 8
52
53
#define MAX_MEM_ALLOCS 100
54
55
29.8k
#define IA_MAX_OUTPUT_PCM_SIZE (3)
56
29.8k
#define IA_MAX_USAC_CH (2)
57
29.8k
#define IA_MAX_OUT_SAMPLES_PER_FRAME (4096)
58
59
#define IA_DRC_DEC_IN_OUT_BUF_SIZE \
60
29.8k
  (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
17.1k
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
17.1k
  mInputBufferSize = 0;
122
17.1k
  mInputBuffer = nullptr;
123
17.1k
  mOutputBuffer = nullptr;
124
  /* Process struct initing end */
125
126
  /* ******************************************************************/
127
  /* Initialize API structure and set config params to default        */
128
  /* ******************************************************************/
129
  /* API size */
130
17.1k
  uint32_t pui_api_size;
131
  /* Get the API size */
132
17.1k
  IA_ERRORCODE err_code =
133
17.1k
      ixheaacd_dec_api(nullptr, IA_API_CMD_GET_API_SIZE, 0, &pui_api_size);
134
135
  /* Allocate memory for API */
136
17.1k
  mXheaacCodecHandle = malloc(pui_api_size);
137
17.1k
  if (!mXheaacCodecHandle) {
138
0
    return IA_FATAL_ERROR;
139
0
  }
140
17.1k
  mMemoryVec.push_back(mXheaacCodecHandle);
141
142
  /* Set the config params to default values */
143
17.1k
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_INIT,
144
17.1k
                              IA_CMD_TYPE_INIT_API_PRE_CONFIG_PARAMS, nullptr);
145
146
  /* Get the API size */
147
17.1k
  err_code = ia_drc_dec_api(nullptr, IA_API_CMD_GET_API_SIZE, 0, &pui_api_size);
148
149
  /* Allocate memory for API */
150
17.1k
  mMpegDDrcHandle = malloc(pui_api_size);
151
17.1k
  if (!mMpegDDrcHandle) {
152
0
    return IA_FATAL_ERROR;
153
0
  }
154
17.1k
  mMemoryVec.push_back(mMpegDDrcHandle);
155
156
  /* Set the config params to default values */
157
17.1k
  err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT,
158
17.1k
                            IA_CMD_TYPE_INIT_API_PRE_CONFIG_PARAMS, nullptr);
159
160
  /* ******************************************************************/
161
  /* Set config parameters                                            */
162
  /* ******************************************************************/
163
17.1k
  uint32_t ui_mp4_flag = isADTS ? 0 : 1;
164
17.1k
  err_code =
165
17.1k
      ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
166
17.1k
                       IA_ENHAACPLUS_DEC_CONFIG_PARAM_ISMP4, &ui_mp4_flag);
167
168
  /* ******************************************************************/
169
  /* Initialize Memory info tables                                    */
170
  /* ******************************************************************/
171
17.1k
  uint32_t ui_proc_mem_tabs_size;
172
17.1k
  pVOID pv_alloc_ptr;
173
  /* Get memory info tables size */
174
17.1k
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_MEMTABS_SIZE,
175
17.1k
                              0, &ui_proc_mem_tabs_size);
176
177
17.1k
  pv_alloc_ptr = malloc(ui_proc_mem_tabs_size);
178
17.1k
  if (!pv_alloc_ptr) {
179
0
    return IA_FATAL_ERROR;
180
0
  }
181
17.1k
  mMemoryVec.push_back(pv_alloc_ptr);
182
183
  /* Set pointer for process memory tables    */
184
17.1k
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_MEMTABS_PTR, 0,
185
17.1k
                              pv_alloc_ptr);
186
187
  /* initialize the API, post config, fill memory tables  */
188
17.1k
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_INIT,
189
17.1k
                              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
85.5k
  for (int i = 0; i < 4; i++) {
197
68.4k
    int ui_size = 0, ui_alignment = 0, ui_type = 0;
198
199
    /* Get memory size */
200
68.4k
    err_code = ixheaacd_dec_api(mXheaacCodecHandle,
201
68.4k
                                IA_API_CMD_GET_MEM_INFO_SIZE, i, &ui_size);
202
203
    /* Get memory alignment */
204
68.4k
    err_code =
205
68.4k
        ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_MEM_INFO_ALIGNMENT,
206
68.4k
                         i, &ui_alignment);
207
208
    /* Get memory type */
209
68.4k
    err_code = ixheaacd_dec_api(mXheaacCodecHandle,
210
68.4k
                                IA_API_CMD_GET_MEM_INFO_TYPE, i, &ui_type);
211
212
68.4k
    pv_alloc_ptr = NULL;
213
68.4k
    ui_alignment = (ui_alignment + sizeof(void *) - 1) / sizeof(void *);
214
68.4k
    ui_alignment = ui_alignment * sizeof(void *);
215
68.4k
    if (0 != posix_memalign(&pv_alloc_ptr, ui_alignment, ui_size)) {
216
0
      return IA_FATAL_ERROR;
217
0
    }
218
68.4k
    if (!pv_alloc_ptr) {
219
0
      return IA_FATAL_ERROR;
220
0
    }
221
68.4k
    mMemoryVec.push_back(pv_alloc_ptr);
222
223
    /* Set the buffer pointer */
224
68.4k
    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_MEM_PTR, i,
225
68.4k
                                pv_alloc_ptr);
226
227
68.4k
    if (ui_type == IA_MEMTYPE_INPUT) {
228
17.1k
      mInputBuffer = (pWORD8)pv_alloc_ptr;
229
17.1k
      mInputBufferSize = ui_size;
230
17.1k
    }
231
68.4k
    if (ui_type == IA_MEMTYPE_OUTPUT) mOutputBuffer = (pWORD8)pv_alloc_ptr;
232
68.4k
  }
233
  /* End first part */
234
235
17.1k
  return IA_NO_ERROR;
236
17.1k
}
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
17.1k
IA_ERRORCODE Codec::initXAACDrc(const uint8_t* data, size_t size) {
250
17.1k
  IA_ERRORCODE err_code = IA_NO_ERROR;
251
17.1k
  unsigned int ui_drc_val;
252
  //  DRC_PRES_MODE_WRAP_DESIRED_TARGET
253
17.1k
  size_t targetLevelOffset =
254
17.1k
      std::min((size_t)DRC_TARGET_LEVEL_OFFSET, size - 1);
255
17.1k
  int32_t targetRefLevel = data[targetLevelOffset];
256
257
17.1k
  ui_drc_val = (unsigned int)targetRefLevel;
258
17.1k
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
259
17.1k
                              IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_TARGET_LEVEL,
260
17.1k
                              &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
17.1k
  err_code =
266
17.1k
      ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
267
17.1k
                       IA_ENHAACPLUS_DEC_DRC_TARGET_LOUDNESS, &ui_drc_val);
268
269
17.1k
  size_t attenuationOffset = std::min((size_t)DRC_ATTENUATION_OFFSET, size - 1);
270
17.1k
  int32_t attenuationFactor = data[attenuationOffset];
271
272
17.1k
  ui_drc_val = (unsigned int)attenuationFactor;
273
17.1k
  err_code =
274
17.1k
      ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
275
17.1k
                       IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_CUT, &ui_drc_val);
276
277
  //  DRC_PRES_MODE_WRAP_DESIRED_BOOST_FACTOR
278
17.1k
  size_t boostOffset = std::min((size_t)DRC_BOOST_OFFSET, size - 1);
279
17.1k
  int32_t boostFactor = data[boostOffset];
280
281
17.1k
  ui_drc_val = (unsigned int)boostFactor;
282
17.1k
  err_code =
283
17.1k
      ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
284
17.1k
                       IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_BOOST, &ui_drc_val);
285
286
  //  DRC_PRES_MODE_WRAP_DESIRED_HEAVY
287
17.1k
  size_t compressOffset = std::min((size_t)DRC_COMPRESS_OFFSET, size - 1);
288
17.1k
  int32_t compressMode = data[compressOffset];
289
17.1k
  ui_drc_val = (unsigned int)compressMode;
290
291
17.1k
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
292
17.1k
                              IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_HEAVY_COMP,
293
17.1k
                              &ui_drc_val);
294
295
  // AAC_UNIDRC_SET_EFFECT
296
17.1k
  size_t effectOffset = std::min((size_t)DRC_EFFECT_OFFSET, size - 1);
297
17.1k
  int32_t effectType = data[effectOffset];
298
17.1k
  ui_drc_val = (unsigned int)effectType;
299
17.1k
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
300
17.1k
                              IA_ENHAACPLUS_DEC_DRC_EFFECT_TYPE, &ui_drc_val);
301
302
17.1k
#ifdef LOUDNESS_LEVELING_SUPPORT
303
  // DRC_LOUDNESS_LEVELING_FLAG
304
17.1k
  size_t flagOffset = std::min((size_t)DRC_LOUDNESS_LEVELING_OFFSET, size - 1);
305
17.1k
  uint8_t loudnessFlag = data[flagOffset];
306
17.1k
  ui_drc_val = (unsigned int)loudnessFlag;
307
17.1k
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_SET_CONFIG_PARAM,
308
17.1k
                              IA_XHEAAC_DEC_CONFIG_PARAM_DRC_LOUDNESS_LEVELING, &ui_drc_val);
309
17.1k
#endif
310
311
17.1k
  return IA_NO_ERROR;
312
17.1k
}
313
314
17.1k
IA_ERRORCODE Codec::deInitXAACDecoder() {
315
  /* Error code */
316
17.1k
  IA_ERRORCODE err_code = IA_NO_ERROR;
317
318
17.1k
  if (mXheaacCodecHandle) {
319
    /* Tell that the input is over in this buffer */
320
17.1k
    err_code =
321
17.1k
        ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_INPUT_OVER, 0, nullptr);
322
17.1k
  }
323
324
  /* Irrespective of error returned in IA_API_CMD_INPUT_OVER, free allocated
325
   * memory */
326
134k
  for (void* buf : mMemoryVec) {
327
134k
    if (buf) free(buf);
328
134k
  }
329
17.1k
  mMemoryVec.clear();
330
17.1k
  mXheaacCodecHandle = nullptr;
331
332
17.1k
  return err_code;
333
17.1k
}
334
335
32.0k
IA_ERRORCODE Codec::deInitMPEGDDDrc() {
336
59.7k
  for (void* buf : mDrcMemoryVec) {
337
59.7k
    if (buf) free(buf);
338
59.7k
  }
339
32.0k
  mDrcMemoryVec.clear();
340
32.0k
  return IA_NO_ERROR;
341
32.0k
}
342
343
IA_ERRORCODE Codec::configXAACDecoder(uint8_t* inBuffer,
344
                                      uint32_t inBufferLength,
345
27.7k
                                      int32_t* bytesConsumed) {
346
27.7k
  if (mInputBufferSize < inBufferLength) {
347
1.73k
    inBufferLength = mInputBufferSize;
348
1.73k
  }
349
  /* Copy the buffer passed by Android plugin to codec input buffer */
350
27.7k
  memcpy(mInputBuffer, inBuffer, inBufferLength);
351
352
  /* Set number of bytes to be processed */
353
27.7k
  IA_ERRORCODE err_code = ixheaacd_dec_api(
354
27.7k
      mXheaacCodecHandle, IA_API_CMD_SET_INPUT_BYTES, 0, &inBufferLength);
355
356
27.7k
  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
27.7k
  } else {
365
    /* Initialize the process */
366
27.7k
    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_INIT,
367
27.7k
                                IA_CMD_TYPE_INIT_PROCESS, nullptr);
368
27.7k
  }
369
370
27.7k
  uint32_t ui_init_done;
371
  /* Checking for end of initialization */
372
27.7k
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_INIT,
373
27.7k
                              IA_CMD_TYPE_INIT_DONE_QUERY, &ui_init_done);
374
375
  /* How much buffer is used in input buffers */
376
27.7k
  err_code = ixheaacd_dec_api(
377
27.7k
      mXheaacCodecHandle, IA_API_CMD_GET_CURIDX_INPUT_BUF, 0, bytesConsumed);
378
379
27.7k
  if (ui_init_done) {
380
14.9k
    err_code = getXAACStreamInfo();
381
382
14.9k
    mIsCodecInitialized = true;
383
384
14.9k
    err_code = configMPEGDDrc();
385
14.9k
  }
386
387
27.7k
  return IA_NO_ERROR;
388
27.7k
}
389
14.9k
IA_ERRORCODE Codec::initMPEGDDDrc() {
390
14.9k
  IA_ERRORCODE err_code = IA_NO_ERROR;
391
392
44.8k
  for (int i = 0; i < (WORD32)2; i++) {
393
29.8k
    WORD32 ui_size, ui_alignment, ui_type;
394
29.8k
    pVOID pv_alloc_ptr;
395
396
    /* Get memory size */
397
29.8k
    err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_GET_MEM_INFO_SIZE, i,
398
29.8k
                              &ui_size);
399
400
    /* Get memory alignment */
401
29.8k
    err_code = ia_drc_dec_api(
402
29.8k
        mMpegDDrcHandle, IA_API_CMD_GET_MEM_INFO_ALIGNMENT, i, &ui_alignment);
403
404
    /* Get memory type */
405
29.8k
    err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_GET_MEM_INFO_TYPE, i,
406
29.8k
                              &ui_type);
407
408
29.8k
    pv_alloc_ptr = malloc(ui_size);
409
29.8k
    if (pv_alloc_ptr == nullptr) {
410
0
      return IA_FATAL_ERROR;
411
0
    }
412
29.8k
    mDrcMemoryVec.push_back(pv_alloc_ptr);
413
414
    /* Set the buffer pointer */
415
29.8k
    err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_MEM_PTR, i,
416
29.8k
                              pv_alloc_ptr);
417
29.8k
  }
418
419
14.9k
  mDrcInBuf = (int8_t*)malloc(IA_DRC_DEC_IN_OUT_BUF_SIZE);
420
14.9k
  if (mDrcInBuf == nullptr) {
421
0
    return IA_FATAL_ERROR;
422
0
  }
423
14.9k
  mDrcMemoryVec.push_back(mDrcInBuf);
424
425
14.9k
  err_code =
426
14.9k
      ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_MEM_PTR, 2, mDrcInBuf);
427
428
14.9k
  mDrcOutBuf = (int8_t*)malloc(IA_DRC_DEC_IN_OUT_BUF_SIZE);
429
14.9k
  if (mDrcOutBuf == nullptr) {
430
0
    return IA_FATAL_ERROR;
431
0
  }
432
14.9k
  mDrcMemoryVec.push_back(mDrcOutBuf);
433
434
14.9k
  err_code =
435
14.9k
      ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_MEM_PTR, 3, mDrcOutBuf);
436
437
14.9k
  return IA_NO_ERROR;
438
14.9k
}
439
14.9k
int Codec::configMPEGDDrc() {
440
14.9k
  IA_ERRORCODE err_code = IA_NO_ERROR;
441
14.9k
  int i_effect_type;
442
14.9k
  int i_loud_norm;
443
14.9k
  int i_target_loudness;
444
14.9k
  unsigned int i_sbr_mode;
445
14.9k
  uint32_t ui_proc_mem_tabs_size = 0;
446
14.9k
  pVOID pv_alloc_ptr = NULL;
447
448
  /* Sampling Frequency */
449
14.9k
  err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
450
14.9k
                            IA_DRC_DEC_CONFIG_PARAM_SAMP_FREQ, &mSampFreq);
451
452
  /* Total Number of Channels */
453
14.9k
  err_code =
454
14.9k
      ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
455
14.9k
                     IA_DRC_DEC_CONFIG_PARAM_NUM_CHANNELS, &mNumChannels);
456
457
  /* PCM word size  */
458
14.9k
  err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
459
14.9k
                            IA_DRC_DEC_CONFIG_PARAM_PCM_WDSZ, &mPcmWdSz);
460
461
  /*Set Effect Type*/
462
14.9k
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
463
14.9k
                              IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_EFFECT_TYPE,
464
14.9k
                              &i_effect_type);
465
466
14.9k
  err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
467
14.9k
                            IA_DRC_DEC_CONFIG_DRC_EFFECT_TYPE, &i_effect_type);
468
469
  /*Set target loudness */
470
14.9k
  err_code = ixheaacd_dec_api(
471
14.9k
      mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
472
14.9k
      IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_TARGET_LOUDNESS, &i_target_loudness);
473
474
14.9k
  err_code =
475
14.9k
      ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
476
14.9k
                     IA_DRC_DEC_CONFIG_DRC_TARGET_LOUDNESS, &i_target_loudness);
477
478
  /*Set loud_norm_flag*/
479
14.9k
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
480
14.9k
                              IA_ENHAACPLUS_DEC_CONFIG_PARAM_DRC_LOUD_NORM,
481
14.9k
                              &i_loud_norm);
482
483
14.9k
  err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
484
14.9k
                            IA_DRC_DEC_CONFIG_DRC_LOUD_NORM, &i_loud_norm);
485
486
14.9k
  err_code =
487
14.9k
      ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
488
14.9k
                       IA_ENHAACPLUS_DEC_CONFIG_PARAM_SBR_MODE, &i_sbr_mode);
489
490
  /* Get memory info tables size */
491
14.9k
  err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_GET_MEMTABS_SIZE, 0,
492
14.9k
                            &ui_proc_mem_tabs_size);
493
494
14.9k
  pv_alloc_ptr = malloc(ui_proc_mem_tabs_size);
495
14.9k
  if (pv_alloc_ptr == NULL) {
496
0
    return IA_FATAL_ERROR;
497
0
  }
498
14.9k
  memset(pv_alloc_ptr, 0, ui_proc_mem_tabs_size);
499
14.9k
  mMemoryVec.push_back(pv_alloc_ptr);
500
501
  /* Set pointer for process memory tables */
502
14.9k
  err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_MEMTABS_PTR, 0,
503
14.9k
                            pv_alloc_ptr);
504
505
14.9k
  err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT,
506
14.9k
                            IA_CMD_TYPE_INIT_API_POST_CONFIG_PARAMS, nullptr);
507
508
  /* Free any memory that is allocated for MPEG D Drc so far */
509
14.9k
  deInitMPEGDDDrc();
510
511
14.9k
  err_code = initMPEGDDDrc();
512
14.9k
  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
14.9k
  {
521
14.9k
    VOID* p_array[2][16];
522
14.9k
    WORD32 ii;
523
14.9k
    WORD32 buf_sizes[2][16];
524
14.9k
    WORD32 num_elements;
525
14.9k
    WORD32 num_config_ext;
526
14.9k
    WORD32 bit_str_fmt = 1;
527
528
14.9k
    WORD32 uo_num_chan;
529
530
14.9k
    memset(buf_sizes, 0, 32 * sizeof(WORD32));
531
532
14.9k
    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
533
14.9k
                                IA_ENHAACPLUS_DEC_CONFIG_EXT_ELE_BUF_SIZES,
534
14.9k
                                &buf_sizes[0][0]);
535
536
14.9k
    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
537
14.9k
                                IA_ENHAACPLUS_DEC_CONFIG_EXT_ELE_PTR, &p_array);
538
539
14.9k
    err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT,
540
14.9k
                              IA_CMD_TYPE_INIT_SET_BUFF_PTR, nullptr);
541
542
14.9k
    err_code =
543
14.9k
        ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
544
14.9k
                         IA_ENHAACPLUS_DEC_CONFIG_NUM_ELE, &num_elements);
545
546
14.9k
    err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
547
14.9k
                                IA_ENHAACPLUS_DEC_CONFIG_NUM_CONFIG_EXT,
548
14.9k
                                &num_config_ext);
549
550
21.4k
    for (ii = 0; ii < num_config_ext; ii++) {
551
      /*copy loudness bitstream*/
552
6.51k
      if (buf_sizes[0][ii] > 0) {
553
831
        memcpy(mDrcInBuf, p_array[0][ii], buf_sizes[0][ii]);
554
555
        /*Set bitstream_split_format */
556
831
        err_code =
557
831
            ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
558
831
                           IA_DRC_DEC_CONFIG_PARAM_BITS_FORMAT, &bit_str_fmt);
559
560
        /* Set number of bytes to be processed */
561
831
        err_code =
562
831
            ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_INPUT_BYTES_IL_BS, 0,
563
831
                           &buf_sizes[0][ii]);
564
565
        /* Execute process */
566
831
        err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT,
567
831
                                  IA_CMD_TYPE_INIT_CPY_IL_BSF_BUFF, nullptr);
568
569
831
        mDRCFlag = 1;
570
831
      }
571
6.51k
    }
572
573
27.7k
    for (ii = 0; ii < num_elements; ii++) {
574
      /*copy config bitstream*/
575
12.7k
      if (buf_sizes[1][ii] > 0) {
576
1.24k
        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.24k
        err_code =
581
1.24k
            ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
582
1.24k
                           IA_DRC_DEC_CONFIG_PARAM_BITS_FORMAT, &bit_str_fmt);
583
584
1.24k
        err_code =
585
1.24k
            ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_INPUT_BYTES_IC_BS, 0,
586
1.24k
                           &buf_sizes[1][ii]);
587
588
        /* Execute process */
589
1.24k
        err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT,
590
1.24k
                                  IA_CMD_TYPE_INIT_CPY_IC_BSF_BUFF, nullptr);
591
592
1.24k
        mDRCFlag = 1;
593
1.24k
      }
594
12.7k
    }
595
596
14.9k
    if (mDRCFlag == 1) {
597
1.57k
      mMpegDDRCPresent = 1;
598
13.3k
    } else {
599
13.3k
      mMpegDDRCPresent = 0;
600
13.3k
    }
601
602
    /*Read interface buffer config file bitstream*/
603
14.9k
    if (mMpegDDRCPresent == 1) {
604
1.57k
      WORD32 interface_is_present = 1;
605
606
1.57k
      if (i_sbr_mode != 0) {
607
684
        if (i_sbr_mode == 1) {
608
630
          mOutputFrameLength = 2048;
609
630
        } else if (i_sbr_mode == 3) {
610
54
          mOutputFrameLength = 4096;
611
54
        } else {
612
0
          mOutputFrameLength = 1024;
613
0
        }
614
894
      } else {
615
894
        mOutputFrameLength = 4096;
616
894
      }
617
618
1.57k
      err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
619
1.57k
                                IA_DRC_DEC_CONFIG_PARAM_FRAME_SIZE,
620
1.57k
                                (WORD32*)&mOutputFrameLength);
621
622
1.57k
      err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
623
1.57k
                                IA_DRC_DEC_CONFIG_PARAM_INT_PRESENT,
624
1.57k
                                &interface_is_present);
625
626
      /* Execute process */
627
1.57k
      err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT,
628
1.57k
                                IA_CMD_TYPE_INIT_CPY_IN_BSF_BUFF, nullptr);
629
630
1.57k
      err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT,
631
1.57k
                                IA_CMD_TYPE_INIT_PROCESS, nullptr);
632
633
1.57k
      err_code =
634
1.57k
          ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_GET_CONFIG_PARAM,
635
1.57k
                         IA_DRC_DEC_CONFIG_PARAM_NUM_CHANNELS, &uo_num_chan);
636
1.57k
    }
637
14.9k
  }
638
639
14.9k
  return err_code;
640
14.9k
}
641
17.1k
IA_ERRORCODE Codec::initDecoder(const uint8_t* data, size_t size, bool isADTS) {
642
17.1k
  IA_ERRORCODE err_code = IA_NO_ERROR;
643
644
17.1k
  err_code = initXAACDecoder(isADTS);
645
17.1k
  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
17.1k
  err_code = initXAACDrc(data, size);
652
653
17.1k
  return IA_NO_ERROR;
654
17.1k
}
655
IA_ERRORCODE Codec::decodeXAACStream(uint8_t* inBuffer, uint32_t inBufferLength,
656
                                     int32_t* bytesConsumed,
657
393k
                                     int32_t* outBytes) {
658
393k
  if (mInputBufferSize < inBufferLength) {
659
177k
    inBufferLength = mInputBufferSize;
660
177k
  }
661
  /* If codec is not initialized, call configXAACDecoder decoder again */
662
393k
  if (!mIsCodecInitialized) {
663
10.6k
    configXAACDecoder(inBuffer, inBufferLength, bytesConsumed);
664
10.6k
  }
665
  /* Copy the buffer passed by Android plugin to codec input buffer */
666
393k
  memcpy(mInputBuffer, inBuffer, inBufferLength);
667
668
  /* Set number of bytes to be processed */
669
393k
  IA_ERRORCODE err_code = ixheaacd_dec_api(
670
393k
      mXheaacCodecHandle, IA_API_CMD_SET_INPUT_BYTES, 0, &inBufferLength);
671
672
  /* Execute process */
673
393k
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_EXECUTE,
674
393k
                              IA_CMD_TYPE_DO_EXECUTE, nullptr);
675
676
  /* Checking for end of processing */
677
393k
  uint32_t ui_exec_done;
678
393k
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_EXECUTE,
679
393k
                              IA_CMD_TYPE_DONE_QUERY, &ui_exec_done);
680
681
393k
  if (ui_exec_done != 1) {
682
393k
    VOID* p_array;        // ITTIAM:buffer to handle gain payload
683
393k
    WORD32 buf_size = 0;  // ITTIAM:gain payload length
684
393k
    WORD32 bit_str_fmt = 1;
685
393k
    WORD32 gain_stream_flag = 1;
686
687
393k
    err_code =
688
393k
        ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
689
393k
                         IA_ENHAACPLUS_DEC_CONFIG_GAIN_PAYLOAD_LEN, &buf_size);
690
691
393k
    err_code =
692
393k
        ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
693
393k
                         IA_ENHAACPLUS_DEC_CONFIG_GAIN_PAYLOAD_BUF, &p_array);
694
695
393k
    if (buf_size > 0) {
696
      /*Set bitstream_split_format */
697
1.51k
      err_code =
698
1.51k
          ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
699
1.51k
                         IA_DRC_DEC_CONFIG_PARAM_BITS_FORMAT, &bit_str_fmt);
700
701
1.51k
      memcpy(mDrcInBuf, p_array, buf_size);
702
      /* Set number of bytes to be processed */
703
1.51k
      err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_INPUT_BYTES_BS,
704
1.51k
                                0, &buf_size);
705
706
1.51k
      err_code =
707
1.51k
          ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_CONFIG_PARAM,
708
1.51k
                         IA_DRC_DEC_CONFIG_GAIN_STREAM_FLAG, &gain_stream_flag);
709
710
      /* Execute process */
711
1.51k
      err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_INIT,
712
1.51k
                                IA_CMD_TYPE_INIT_CPY_BSF_BUFF, nullptr);
713
714
1.51k
      mMpegDDRCPresent = 1;
715
1.51k
    }
716
393k
  }
717
718
  /* How much buffer is used in input buffers */
719
393k
  err_code = ixheaacd_dec_api(
720
393k
      mXheaacCodecHandle, IA_API_CMD_GET_CURIDX_INPUT_BUF, 0, bytesConsumed);
721
722
  /* Get the output bytes */
723
393k
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_OUTPUT_BYTES,
724
393k
                              0, outBytes);
725
726
393k
  if (mMpegDDRCPresent == 1) {
727
31.0k
    memcpy(mDrcInBuf, mOutputBuffer, *outBytes);
728
31.0k
    err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_SET_INPUT_BYTES, 0,
729
31.0k
                              outBytes);
730
731
31.0k
    err_code = ia_drc_dec_api(mMpegDDrcHandle, IA_API_CMD_EXECUTE,
732
31.0k
                              IA_CMD_TYPE_DO_EXECUTE, nullptr);
733
734
31.0k
    memcpy(mOutputBuffer, mDrcOutBuf, *outBytes);
735
31.0k
  }
736
393k
  return IA_NO_ERROR;
737
393k
}
738
739
14.9k
IA_ERRORCODE Codec::getXAACStreamInfo() {
740
14.9k
  IA_ERRORCODE err_code = IA_NO_ERROR;
741
742
  /* Sampling frequency */
743
14.9k
  err_code =
744
14.9k
      ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
745
14.9k
                       IA_ENHAACPLUS_DEC_CONFIG_PARAM_SAMP_FREQ, &mSampFreq);
746
747
  /* Total Number of Channels */
748
14.9k
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
749
14.9k
                              IA_ENHAACPLUS_DEC_CONFIG_PARAM_NUM_CHANNELS,
750
14.9k
                              &mNumChannels);
751
752
14.9k
  if (mNumChannels > MAX_CHANNEL_COUNT) {
753
0
    return IA_FATAL_ERROR;
754
0
  }
755
756
  /* PCM word size */
757
14.9k
  err_code =
758
14.9k
      ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
759
14.9k
                       IA_ENHAACPLUS_DEC_CONFIG_PARAM_PCM_WDSZ, &mPcmWdSz);
760
761
14.9k
  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
14.9k
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
767
14.9k
                              IA_ENHAACPLUS_DEC_CONFIG_PARAM_CHANNEL_MASK,
768
14.9k
                              &mChannelMask);
769
770
  /* Channel mode to tell MONO/STEREO/DUAL-MONO/NONE_OF_THESE */
771
14.9k
  uint32_t ui_channel_mode;
772
14.9k
  err_code = ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
773
14.9k
                              IA_ENHAACPLUS_DEC_CONFIG_PARAM_CHANNEL_MODE,
774
14.9k
                              &ui_channel_mode);
775
776
  /* Channel mode to tell SBR PRESENT/NOT_PRESENT */
777
14.9k
  uint32_t ui_sbr_mode;
778
14.9k
  err_code =
779
14.9k
      ixheaacd_dec_api(mXheaacCodecHandle, IA_API_CMD_GET_CONFIG_PARAM,
780
14.9k
                       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
14.9k
  mOutputFrameLength = 1024 * (1 + ui_sbr_mode);
786
787
14.9k
  return IA_NO_ERROR;
788
14.9k
}
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
17.1k
extern "C" int LLVMFuzzerTestOneInput(const uint8_t* data, size_t size) {
864
17.1k
  int status;
865
17.1k
  int num_proc_iterations = 0;
866
17.1k
  if (size < 1) return 0;
867
17.1k
  Codec* codec = new Codec();
868
17.1k
  bool isADTS = false;
869
17.1k
  if (size >= 2) {
870
17.0k
    if ((data[0] == 0xFF) && ((data[1] & 0xF0) == 0xF0)) {
871
15.3k
      isADTS = true;
872
15.3k
    }
873
17.0k
  }
874
17.1k
  status = codec->initDecoder(data, size, isADTS);
875
17.1k
  if (0 == status) {
876
17.1k
    int32_t bytesConsumed = 0;
877
17.1k
    status = codec->configXAACDecoder((uint8_t*)data, size, &bytesConsumed);
878
411k
    while ((int32_t)size > bytesConsumed) {
879
393k
      int32_t numOutBytes;
880
393k
      size -= bytesConsumed;
881
393k
      data += bytesConsumed;
882
393k
      status = codec->decodeXAACStream((uint8_t*)data, size, &bytesConsumed,
883
393k
                                       &numOutBytes);
884
393k
      num_proc_iterations++;
885
      /* Stop processing after 500 frames */
886
393k
      if (num_proc_iterations > 500)
887
34
        break;
888
889
      /* If decoder doesn't consume any bytes, advance by 4 bytes */
890
393k
      if (0 == bytesConsumed) bytesConsumed = 4;
891
393k
    }
892
17.1k
  }
893
17.1k
  status = codec->deInitXAACDecoder();
894
17.1k
  status = codec->deInitMPEGDDDrc();
895
17.1k
  delete codec;
896
17.1k
  return 0;
897
17.1k
}