Coverage Report

Created: 2026-02-26 06:28

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libxaac/decoder/ixheaacd_longblock.c
Line
Count
Source
1
/******************************************************************************
2
 *                                                                            *
3
 * Copyright (C) 2018 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
#include "ixheaacd_sbr_common.h"
21
#include "ixheaac_type_def.h"
22
#include "ixheaac_constants.h"
23
#include "ixheaac_basic_ops32.h"
24
#include "ixheaac_basic_ops16.h"
25
#include "ixheaac_basic_ops40.h"
26
#include "ixheaac_basic_ops.h"
27
28
#include "ixheaacd_defines.h"
29
#include "ixheaacd_aac_rom.h"
30
#include "ixheaacd_aac_imdct.h"
31
#include "ixheaacd_bitbuffer.h"
32
#include "ixheaac_basic_op.h"
33
#include "ixheaacd_intrinsics.h"
34
35
#include "ixheaacd_pulsedata.h"
36
37
#include "ixheaacd_pns.h"
38
#include "ixheaacd_common_rom.h"
39
#include "ixheaacd_drc_data_struct.h"
40
41
#include "ixheaacd_lt_predict.h"
42
#include "ixheaacd_cnst.h"
43
#include "ixheaacd_ec_defines.h"
44
#include "ixheaacd_ec_struct_def.h"
45
#include "ixheaacd_channelinfo.h"
46
#include "ixheaacd_drc_dec.h"
47
48
#include "ixheaacd_block.h"
49
#include "ixheaacd_channel.h"
50
51
#include "ixheaacd_pulsedata.h"
52
#include "ixheaacd_pns.h"
53
#include "ixheaacd_sbrdecoder.h"
54
#include "ixheaacd_error_codes.h"
55
#include "ixheaacd_audioobjtypes.h"
56
#include "ixheaacd_latmdemux.h"
57
#include "ixheaacd_aacdec.h"
58
59
148k
#define LONG_BLOCK_SECT_LEN 5
60
25.2k
#define SHORT_BLOCK_SECT_LEN 3
61
62
IA_ERRORCODE ixheaacd_read_section_data(
63
    ia_bit_buf_struct *it_bit_buff,
64
    ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info,
65
    WORD32 aac_spect_data_resil_flag, WORD32 aac_sect_data_resil_flag,
66
148k
    ia_aac_dec_tables_struct *ptr_aac_tables) {
67
148k
  WORD sfb;
68
148k
  WORD sect_cb;
69
148k
  WORD sect_len;
70
148k
  WORD sect_len_incr;
71
148k
  WORD sect_esc_val;
72
148k
  ia_ics_info_struct *ptr_ics_info = &ptr_aac_dec_channel_info->str_ics_info;
73
148k
  WORD max_sfb = ptr_ics_info->max_sfb;
74
148k
  WORD num_win_group;
75
76
148k
  WORD8 *ptr_code_book = ptr_aac_dec_channel_info->ptr_code_book;
77
148k
  WORD8 *ptr_code_book_temp = ptr_code_book;
78
148k
  WORD32 sect_bitlen = LONG_BLOCK_SECT_LEN;
79
148k
  int num_lines_sec_idx = 0, top;
80
148k
  short *ptr_num_sect_lines =
81
148k
      ptr_aac_dec_channel_info->num_line_in_sec4_hcr_arr;
82
148k
  UWORD8 *ptr_hcr_code_book = ptr_aac_dec_channel_info->cb4_hcr_arr;
83
148k
  const short *band_offsets = (WORD16 *)ixheaacd_getscalefactorbandoffsets(
84
148k
      &(ptr_aac_dec_channel_info->str_ics_info), ptr_aac_tables);
85
148k
  ptr_aac_dec_channel_info->number_sect = 0;
86
87
148k
  if (ptr_aac_dec_channel_info->str_ics_info.window_sequence ==
88
148k
      EIGHT_SHORT_SEQUENCE) {
89
25.2k
    sect_bitlen = SHORT_BLOCK_SECT_LEN;
90
25.2k
  }
91
92
148k
  sect_esc_val = (1 << sect_bitlen) - 1;
93
94
372k
  for (num_win_group = 0; num_win_group < ptr_ics_info->num_window_groups;
95
224k
       num_win_group++) {
96
224k
    sfb = 0;
97
98
777k
    while (sfb < max_sfb) {
99
554k
      sect_len = 0;
100
554k
      if (aac_sect_data_resil_flag) {
101
280k
        sect_cb = ixheaacd_read_bits_buf(it_bit_buff, 5);
102
280k
      } else {
103
273k
        sect_cb = ixheaacd_read_bits_buf(it_bit_buff, 4);
104
273k
      }
105
106
554k
      if ((aac_sect_data_resil_flag == 0) ||
107
388k
          ((sect_cb < 11) || ((sect_cb > 11) && (sect_cb < 16)))) {
108
388k
        sect_len_incr = ixheaacd_read_bits_buf(it_bit_buff, sect_bitlen);
109
395k
        while (sect_len_incr == sect_esc_val) {
110
6.68k
          sect_len = (sect_len + sect_esc_val);
111
6.68k
          sect_len_incr = ixheaacd_read_bits_buf(it_bit_buff, sect_bitlen);
112
6.68k
        }
113
388k
      } else
114
165k
        sect_len_incr = 1;
115
116
554k
      sect_len = (sect_len + sect_len_incr);
117
118
554k
      if (aac_spect_data_resil_flag) {
119
211k
        top = (sfb + sect_len);
120
211k
        if ((num_lines_sec_idx >= MAX_SFB_HCR) ||
121
211k
            (top >= MAX_SCALE_FACTOR_BANDS_LONG)) {
122
17
          return -1;
123
17
        }
124
211k
        ptr_num_sect_lines[num_lines_sec_idx] =
125
211k
            band_offsets[top] - band_offsets[sfb];
126
211k
        num_lines_sec_idx++;
127
211k
        if (sect_cb == (ESC_HCB + 1)) {
128
119
          return IA_XHEAAC_DEC_EXE_NONFATAL_INVALID_CODE_BOOK;
129
211k
        } else {
130
211k
          *ptr_hcr_code_book++ = sect_cb;
131
211k
        }
132
211k
        ptr_aac_dec_channel_info->number_sect++;
133
211k
      }
134
135
553k
      sfb = (sfb + sect_len);
136
553k
      if (sfb > max_sfb) {
137
642
        return (WORD16)(
138
642
            (WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_EXCEEDS_SFB_TRANSMITTED);
139
642
      }
140
553k
      if (sect_cb == (ESC_HCB + 1)) {
141
90
        return (WORD16)(
142
90
            (WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_INVALID_CODE_BOOK);
143
90
      }
144
145
2.51M
      while (sect_len--) {
146
1.95M
        *ptr_code_book_temp++ = sect_cb;
147
1.95M
      }
148
553k
    }
149
223k
    ptr_code_book += MAX_SCALE_FACTOR_BANDS_SHORT;
150
223k
    ptr_code_book_temp = ptr_code_book;
151
223k
  }
152
153
147k
  return AAC_DEC_OK;
154
148k
}
155
156
VOID ixheaacd_read_scale_factor_data(
157
    ia_bit_buf_struct *it_bit_buff,
158
    ia_aac_dec_channel_info_struct *ptr_aac_dec_channel_info,
159
112k
    ia_aac_dec_tables_struct *ptr_aac_tables, WORD32 object_type) {
160
112k
  WORD sfb;
161
112k
  WORD16 position = 0;
162
112k
  WORD num_win_group;
163
112k
  WORD16 factor = ptr_aac_dec_channel_info->global_gain;
164
112k
  WORD8 *ptr_code_book, *ptr_code_book_short;
165
112k
  WORD16 *ptr_scale_fact, *ptr_scale_fact_short;
166
112k
  WORD16 norm_value;
167
112k
  WORD16 index, length;
168
112k
  const UWORD16 *hcod_sf =
169
112k
      ptr_aac_tables->pstr_huffmann_tables->huffman_code_book_scl;
170
112k
  const UWORD32 *table_idx =
171
112k
      ptr_aac_tables->pstr_huffmann_tables->huffman_code_book_scl_index;
172
173
112k
  WORD start_bit_pos = it_bit_buff->bit_pos;
174
112k
  UWORD8 *start_read_pos = it_bit_buff->ptr_read_next;
175
112k
  UWORD8 *ptr_read_next = it_bit_buff->ptr_read_next;
176
112k
  WORD32 bit_pos = 7 - it_bit_buff->bit_pos;
177
112k
  WORD32 read_word;
178
112k
  WORD32 increment;
179
112k
  read_word = ixheaacd_aac_showbits_32(ptr_read_next, it_bit_buff->cnt_bits,
180
112k
                                       &increment);
181
112k
  ptr_read_next += increment;
182
183
112k
  ptr_code_book = ptr_aac_dec_channel_info->ptr_code_book;
184
185
112k
  ptr_scale_fact = ptr_aac_dec_channel_info->ptr_scale_factor;
186
187
112k
  for (num_win_group = 0;
188
292k
       num_win_group < ptr_aac_dec_channel_info->str_ics_info.num_window_groups;
189
180k
       num_win_group++) {
190
180k
    ptr_code_book_short =
191
180k
        &ptr_code_book[num_win_group * MAX_SCALE_FACTOR_BANDS_SHORT];
192
180k
    ptr_scale_fact_short =
193
180k
        &ptr_scale_fact[num_win_group * MAX_SCALE_FACTOR_BANDS_SHORT];
194
1.61M
    for (sfb = ptr_aac_dec_channel_info->str_ics_info.max_sfb - 1; sfb >= 0;
195
1.43M
         sfb--) {
196
1.43M
      WORD32 sfb_cb = *ptr_code_book_short++;
197
1.43M
      if (sfb_cb == ZERO_HCB)
198
388k
        *ptr_scale_fact_short++ = 0;
199
1.04M
      else {
200
1.04M
        {
201
1.04M
          WORD32 pns_present = 0;
202
1.04M
          WORD pns_band;
203
204
1.04M
          ia_pns_info_struct *ptr_pns_info =
205
1.04M
              &ptr_aac_dec_channel_info->str_pns_info;
206
207
1.04M
          if (sfb_cb == NOISE_HCB && (ptr_pns_info->pns_active != 1)) {
208
8.50k
            pns_present = 1;
209
8.50k
          }
210
211
1.04M
          if (!pns_present) {
212
1.03M
            UWORD32 read_word1;
213
214
1.03M
            read_word1 = read_word << bit_pos;
215
216
1.03M
            ixheaacd_huffman_decode(read_word1, &index, &length, hcod_sf,
217
1.03M
                                    table_idx);
218
219
1.03M
            bit_pos += length;
220
1.03M
            ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
221
1.03M
                                        it_bit_buff->ptr_bit_buf_end);
222
223
1.03M
            ixheaacd_aac_read_byte_corr1(&ptr_read_next, &bit_pos, &read_word,
224
1.03M
                                         it_bit_buff->ptr_bit_buf_end);
225
226
1.03M
            norm_value = index - 60;
227
1.03M
          }
228
229
8.50k
          else {
230
8.50k
            WORD32 noise_start_value;
231
8.50k
            UWORD32 temp;
232
233
8.50k
            temp = (read_word << bit_pos);
234
8.50k
            temp = ((UWORD32)temp >> (32 - 9));
235
8.50k
            noise_start_value = temp;
236
8.50k
            bit_pos += 9;
237
238
8.50k
            ixheaacd_aac_read_byte_corr1(&ptr_read_next, &bit_pos, &read_word,
239
8.50k
                                         it_bit_buff->ptr_bit_buf_end);
240
241
8.50k
            norm_value = noise_start_value - 256;
242
8.50k
            ptr_pns_info->pns_active = 1;
243
244
8.50k
            ptr_pns_info->noise_energy =
245
8.50k
                ptr_aac_dec_channel_info->global_gain - NOISE_OFFSET;
246
8.50k
          }
247
248
1.04M
          if ((object_type != AOT_ER_AAC_ELD) &&
249
981k
              (object_type != AOT_ER_AAC_LD) && (object_type != AOT_ER_AAC_LC)) {
250
78.2k
            if (sfb_cb > NOISE_HCB) {
251
8.03k
              position = position + norm_value;
252
8.03k
              *ptr_scale_fact_short++ = -position;
253
70.1k
            } else if (sfb_cb < NOISE_HCB) {
254
43.4k
              factor = factor + norm_value;
255
43.4k
              *ptr_scale_fact_short++ = factor;
256
43.4k
            } else {
257
26.7k
              ptr_pns_info->noise_energy =
258
26.7k
                  ixheaac_add16_sat(ptr_pns_info->noise_energy, norm_value);
259
260
26.7k
              pns_band = (num_win_group << 4) +
261
26.7k
                         ptr_aac_dec_channel_info->str_ics_info.max_sfb - sfb -
262
26.7k
                         1;
263
26.7k
              ptr_aac_dec_channel_info->ptr_scale_factor[pns_band] =
264
26.7k
                  ptr_pns_info->noise_energy;
265
266
26.7k
              ptr_pns_info->pns_used[pns_band] = 1;
267
26.7k
              ptr_scale_fact_short++;
268
26.7k
            }
269
969k
          } else {
270
969k
            if ((sfb_cb == INTENSITY_HCB) || (sfb_cb == INTENSITY_HCB2)) {
271
112k
              position = position + norm_value;
272
112k
              *ptr_scale_fact_short++ = -position;
273
857k
            } else if (sfb_cb == NOISE_HCB) {
274
27.3k
              ptr_pns_info->noise_energy =
275
27.3k
                  ixheaac_add16_sat(ptr_pns_info->noise_energy, norm_value);
276
277
27.3k
              pns_band = (num_win_group << 4) +
278
27.3k
                         ptr_aac_dec_channel_info->str_ics_info.max_sfb - sfb -
279
27.3k
                         1;
280
27.3k
              ptr_aac_dec_channel_info->ptr_scale_factor[pns_band] =
281
27.3k
                  ptr_pns_info->noise_energy;
282
283
27.3k
              ptr_pns_info->pns_used[pns_band] = 1;
284
27.3k
              ptr_scale_fact_short++;
285
286
829k
            } else {
287
829k
              factor = factor + norm_value;
288
829k
              *ptr_scale_fact_short++ = factor;
289
829k
            }
290
969k
          }
291
1.04M
        }
292
1.04M
      }
293
1.43M
    }
294
180k
  }
295
296
112k
  it_bit_buff->ptr_read_next = ptr_read_next - increment;
297
298
112k
  it_bit_buff->bit_pos = 7 - bit_pos;
299
112k
  {
300
112k
    WORD bits_consumed;
301
112k
    bits_consumed =
302
112k
        (WORD)(((it_bit_buff->ptr_read_next - start_read_pos) << 3) +
303
112k
               (start_bit_pos - it_bit_buff->bit_pos));
304
112k
    it_bit_buff->cnt_bits -= bits_consumed;
305
112k
  }
306
112k
}