Coverage Report

Created: 2026-12-01 07:00

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libxaac/decoder/ixheaacd_mps_res_longblock.c
Line
Count
Source
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
#include "ixheaac_type_def.h"
21
#include "ixheaac_constants.h"
22
#include "ixheaacd_cnst.h"
23
#include "ixheaac_basic_ops32.h"
24
#include "ixheaac_basic_ops16.h"
25
#include "ixheaacd_bitbuffer.h"
26
#include "ixheaacd_mps_aac_struct.h"
27
#include "ixheaacd_mps_res_rom.h"
28
#include "ixheaacd_mps_res.h"
29
#include "ixheaacd_mps_res_huffman.h"
30
31
2.17k
#define LONG_BLOCK_SECT_LEN 5
32
769
#define SHORT_BLOCK_SECT_LEN 3
33
34
WORD16 ixheaacd_c_block_read_section_data(
35
    ia_bit_buf_struct *it_bit_buf,
36
2.17k
    ia_mps_dec_residual_channel_info_struct *p_aac_decoder_channel_info) {
37
2.17k
  WORD band;
38
2.17k
  WORD sect_cb;
39
2.17k
  WORD sect_len;
40
2.17k
  WORD sect_len_incr;
41
2.17k
  WORD sect_esc_val;
42
2.17k
  ia_mps_dec_residual_ics_info_struct *p_ics_info = &p_aac_decoder_channel_info->ics_info;
43
2.17k
  WORD sfb_transmitted = p_ics_info->max_sf_bands;
44
2.17k
  WORD win_group = p_ics_info->window_groups;
45
46
2.17k
  WORD8 *p_code_book = p_aac_decoder_channel_info->p_code_book;
47
2.17k
  WORD8 *p_code_book_temp = p_code_book;
48
2.17k
  WORD32 sect_bitlen = LONG_BLOCK_SECT_LEN;
49
50
2.17k
  if (p_aac_decoder_channel_info->ics_info.window_sequence == EIGHT_SHORT_SEQUENCE)
51
769
    sect_bitlen = SHORT_BLOCK_SECT_LEN;
52
53
2.17k
  sect_esc_val = (1 << sect_bitlen) - 1;
54
55
3.27k
  do {
56
3.27k
    band = 0;
57
58
8.97k
    while (band < sfb_transmitted) {
59
5.72k
      WORD32 temp_word;
60
5.72k
      sect_len = 0;
61
5.72k
      temp_word = ixheaacd_read_bits_buf(it_bit_buf, 4 + sect_bitlen);
62
5.72k
      sect_cb = temp_word >> sect_bitlen;
63
5.72k
      sect_len_incr = temp_word & sect_esc_val;
64
65
6.50k
      while (sect_len_incr == sect_esc_val) {
66
781
        sect_len = (sect_len + sect_esc_val);
67
781
        sect_len_incr = ixheaacd_read_bits_buf(it_bit_buf, sect_bitlen);
68
781
      }
69
70
5.72k
      sect_len = (sect_len + sect_len_incr);
71
72
5.72k
      band = (band + sect_len);
73
5.72k
      if (band > sfb_transmitted) {
74
27
        return (WORD16)((WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_EXCEEDS_SFB_TRANSMITTED);
75
27
      }
76
77
5.70k
      if (sect_cb == BOOKSCL) {
78
4
        return (WORD16)((WORD32)AAC_DEC_INVALID_CODE_BOOK);
79
4
      }
80
81
5.69k
      sect_len = sect_len - 1;
82
25.7k
      for (; sect_len >= 0; sect_len--) {
83
20.0k
        *p_code_book_temp++ = sect_cb;
84
20.0k
      }
85
5.69k
    }
86
3.24k
    p_code_book += MAX_SFB_SHORT;
87
3.24k
    p_code_book_temp = p_code_book;
88
3.24k
    win_group--;
89
3.24k
  } while (win_group != 0);
90
2.14k
  return AAC_DEC_OK;
91
2.17k
}
92
93
VOID ixheaacd_res_c_block_read_scf_data(
94
    ia_bit_buf_struct *it_bit_buf,
95
    ia_mps_dec_residual_channel_info_struct *p_aac_decoder_channel_info, WORD16 global_gain,
96
2.13k
    ia_mps_dec_residual_aac_tables_struct *aac_tables_ptr) {
97
2.13k
  WORD band;
98
2.13k
  WORD16 position = 0;
99
2.13k
  WORD group;
100
2.13k
  WORD16 factor = global_gain;
101
2.13k
  WORD8 *p_code_book, *p_codebook_tmp;
102
2.13k
  WORD16 *p_scale_factor, *p_scale_factor_tmp;
103
2.13k
  WORD16 norm_value;
104
2.13k
  ia_mps_dec_residual_ics_info_struct *p_ics_info;
105
2.13k
  WORD window_groups, sfb_transmitted;
106
2.13k
  UWORD16 *h;
107
108
2.13k
  const UWORD16 *hscf = &aac_tables_ptr->res_huffmann_tables_ptr->huffman_code_book_scl[1];
109
110
2.13k
  WORD start_bit_pos = it_bit_buf->bit_pos;
111
2.13k
  UWORD8 *start_read_pos = it_bit_buf->ptr_read_next;
112
2.13k
  UWORD8 *ptr_read_next = it_bit_buf->ptr_read_next;
113
2.13k
  WORD32 bit_pos = 7 - it_bit_buf->bit_pos;
114
115
2.13k
  WORD32 read_word;
116
2.13k
  WORD32 diffbytes;
117
118
2.13k
  diffbytes = (WORD32)(it_bit_buf->ptr_bit_buf_end - ptr_read_next);
119
2.13k
  diffbytes++;
120
2.13k
  if (diffbytes >= 4) {
121
2.04k
    read_word = ixheaacd_res_aac_showbits_32(ptr_read_next);
122
2.04k
    diffbytes = 4;
123
2.04k
    ptr_read_next = it_bit_buf->ptr_read_next + 4;
124
2.04k
  } else {
125
91
    WORD32 ii;
126
91
    read_word = 0;
127
249
    for (ii = 0; ii < diffbytes; ii++) {
128
158
      read_word = (read_word << 8) | (*ptr_read_next);
129
158
      ptr_read_next++;
130
158
    }
131
91
    read_word <<= ((4 - diffbytes) << 3);
132
91
  }
133
2.13k
  p_code_book = p_aac_decoder_channel_info->p_code_book;
134
135
2.13k
  p_ics_info = &p_aac_decoder_channel_info->ics_info;
136
2.13k
  sfb_transmitted = p_ics_info->max_sf_bands;
137
138
2.13k
  p_scale_factor = p_aac_decoder_channel_info->p_scale_factor;
139
2.13k
  window_groups = p_ics_info->window_groups;
140
2.13k
  band = sfb_transmitted - 1;
141
142
5.36k
  for (group = 0; group < window_groups; group++) {
143
3.22k
    p_codebook_tmp = &p_code_book[group * MAX_SFB_SHORT];
144
3.22k
    p_scale_factor_tmp = &p_scale_factor[group * MAX_SFB_SHORT];
145
23.0k
    for (band = sfb_transmitted - 1; band >= 0; band--) {
146
19.7k
      WORD32 cb_num = *p_codebook_tmp++;
147
148
19.7k
      if (cb_num == ZERO_HCB)
149
2.54k
        *p_scale_factor_tmp++ = 0;
150
17.2k
      else {
151
17.2k
        {
152
17.2k
          WORD32 flag = 1;
153
17.2k
          WORD pns_band;
154
17.2k
          ia_mps_dec_residual_pns_data_struct *p_pns_data = &p_aac_decoder_channel_info->pns_data;
155
17.2k
          if (cb_num == NOISE_HCB && (p_pns_data->pns_active != 1)) flag = 0;
156
157
17.2k
          if (flag) {
158
17.2k
            UWORD16 first_offset;
159
17.2k
            WORD16 sign_ret_val;
160
17.2k
            UWORD32 read_word1;
161
162
17.2k
            read_word1 = read_word << bit_pos;
163
17.2k
            h = (UWORD16 *)(hscf);
164
17.2k
            first_offset = 7;
165
17.2k
            h += (read_word1) >> (32 - first_offset);
166
17.2k
            sign_ret_val = *h;
167
168
19.7k
            while (sign_ret_val > 0) {
169
2.56k
              bit_pos += first_offset;
170
171
2.56k
              ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
172
2.56k
                                          it_bit_buf->ptr_bit_buf_end);
173
2.56k
              read_word1 = (read_word1) << (first_offset);
174
175
2.56k
              first_offset = (sign_ret_val >> 11);
176
2.56k
              first_offset = (sign_ret_val >> 11);
177
2.56k
              h += sign_ret_val & (0x07FF);
178
2.56k
              h += (read_word1) >> (32 - first_offset);
179
2.56k
              sign_ret_val = *h;
180
2.56k
            }
181
182
17.2k
            bit_pos += ((sign_ret_val & 0x7fff) >> 11);
183
184
17.2k
            ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
185
17.2k
                                        it_bit_buf->ptr_bit_buf_end);
186
17.2k
            norm_value = (sign_ret_val & (0x07FF)) - 60;
187
17.2k
          } else {
188
44
            WORD32 noise_start_value;
189
44
            UWORD32 temp;
190
44
            temp = (read_word << bit_pos);
191
44
            temp = ((UWORD32)temp >> (32 - 9));
192
44
            noise_start_value = temp;
193
44
            bit_pos += 9;
194
195
44
            ixheaacd_aac_read_2bytes(&ptr_read_next, &bit_pos, &read_word);
196
197
44
            norm_value = noise_start_value - 256;
198
44
            p_pns_data->pns_active = 1;
199
200
44
            p_pns_data->current_energy = global_gain - NOISE_OFFSET;
201
44
          }
202
203
17.2k
          if (cb_num > NOISE_HCB) {
204
2.34k
            position = position + norm_value;
205
2.34k
            *p_scale_factor_tmp++ = -position;
206
14.9k
          } else if (cb_num < NOISE_HCB) {
207
14.6k
            factor = factor + norm_value;
208
14.6k
            *p_scale_factor_tmp++ = factor;
209
14.6k
          } else {
210
260
            p_pns_data->current_energy =
211
260
                ixheaac_add16_sat(p_pns_data->current_energy, norm_value);
212
213
260
            pns_band = (group << 4) + sfb_transmitted - band - 1;
214
260
            p_aac_decoder_channel_info->p_scale_factor[pns_band] = p_pns_data->current_energy;
215
216
260
            p_pns_data->pns_used[pns_band] = 1;
217
260
            p_scale_factor_tmp++;
218
260
          }
219
17.2k
        }
220
17.2k
      }
221
19.7k
    }
222
3.22k
  }
223
224
2.13k
  it_bit_buf->ptr_read_next = ptr_read_next - diffbytes;
225
226
2.13k
  it_bit_buf->bit_pos = 7 - bit_pos;
227
2.13k
  {
228
2.13k
    WORD bits_cons;
229
2.13k
    bits_cons = (WORD)(((it_bit_buf->ptr_read_next - start_read_pos) << 3) +
230
2.13k
                       (start_bit_pos - it_bit_buf->bit_pos));
231
2.13k
    it_bit_buf->cnt_bits -= bits_cons;
232
2.13k
  }
233
2.13k
}