Coverage Report

Created: 2025-11-09 07:01

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
1.00k
#define LONG_BLOCK_SECT_LEN 5
32
298
#define SHORT_BLOCK_SECT_LEN 3
33
34
WORD16 ixheaacd_c_block_read_section_data(
35
    ia_bit_buf_struct *it_bit_buf,
36
1.00k
    ia_mps_dec_residual_channel_info_struct *p_aac_decoder_channel_info) {
37
1.00k
  WORD band;
38
1.00k
  WORD sect_cb;
39
1.00k
  WORD sect_len;
40
1.00k
  WORD sect_len_incr;
41
1.00k
  WORD sect_esc_val;
42
1.00k
  ia_mps_dec_residual_ics_info_struct *p_ics_info = &p_aac_decoder_channel_info->ics_info;
43
1.00k
  WORD sfb_transmitted = p_ics_info->max_sf_bands;
44
1.00k
  WORD win_group = p_ics_info->window_groups;
45
46
1.00k
  WORD8 *p_code_book = p_aac_decoder_channel_info->p_code_book;
47
1.00k
  WORD8 *p_code_book_temp = p_code_book;
48
1.00k
  WORD32 sect_bitlen = LONG_BLOCK_SECT_LEN;
49
50
1.00k
  if (p_aac_decoder_channel_info->ics_info.window_sequence == EIGHT_SHORT_SEQUENCE)
51
298
    sect_bitlen = SHORT_BLOCK_SECT_LEN;
52
53
1.00k
  sect_esc_val = (1 << sect_bitlen) - 1;
54
55
1.42k
  do {
56
1.42k
    band = 0;
57
58
3.93k
    while (band < sfb_transmitted) {
59
2.53k
      WORD32 temp_word;
60
2.53k
      sect_len = 0;
61
2.53k
      temp_word = ixheaacd_read_bits_buf(it_bit_buf, 4 + sect_bitlen);
62
2.53k
      sect_cb = temp_word >> sect_bitlen;
63
2.53k
      sect_len_incr = temp_word & sect_esc_val;
64
65
2.90k
      while (sect_len_incr == sect_esc_val) {
66
371
        sect_len = (sect_len + sect_esc_val);
67
371
        sect_len_incr = ixheaacd_read_bits_buf(it_bit_buf, sect_bitlen);
68
371
      }
69
70
2.53k
      sect_len = (sect_len + sect_len_incr);
71
72
2.53k
      band = (band + sect_len);
73
2.53k
      if (band > sfb_transmitted) {
74
22
        return (WORD16)((WORD32)IA_XHEAAC_DEC_EXE_NONFATAL_EXCEEDS_SFB_TRANSMITTED);
75
22
      }
76
77
2.51k
      if (sect_cb == BOOKSCL) {
78
2
        return (WORD16)((WORD32)AAC_DEC_INVALID_CODE_BOOK);
79
2
      }
80
81
2.50k
      sect_len = sect_len - 1;
82
12.1k
      for (; sect_len >= 0; sect_len--) {
83
9.59k
        *p_code_book_temp++ = sect_cb;
84
9.59k
      }
85
2.50k
    }
86
1.39k
    p_code_book += MAX_SFB_SHORT;
87
1.39k
    p_code_book_temp = p_code_book;
88
1.39k
    win_group--;
89
1.39k
  } while (win_group != 0);
90
981
  return AAC_DEC_OK;
91
1.00k
}
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
976
    ia_mps_dec_residual_aac_tables_struct *aac_tables_ptr) {
97
976
  WORD band;
98
976
  WORD16 position = 0;
99
976
  WORD group;
100
976
  WORD16 factor = global_gain;
101
976
  WORD8 *p_code_book, *p_codebook_tmp;
102
976
  WORD16 *p_scale_factor, *p_scale_factor_tmp;
103
976
  WORD16 norm_value;
104
976
  ia_mps_dec_residual_ics_info_struct *p_ics_info;
105
976
  WORD window_groups, sfb_transmitted;
106
976
  UWORD16 *h;
107
108
976
  const UWORD16 *hscf = &aac_tables_ptr->res_huffmann_tables_ptr->huffman_code_book_scl[1];
109
110
976
  WORD start_bit_pos = it_bit_buf->bit_pos;
111
976
  UWORD8 *start_read_pos = it_bit_buf->ptr_read_next;
112
976
  UWORD8 *ptr_read_next = it_bit_buf->ptr_read_next;
113
976
  WORD32 bit_pos = 7 - it_bit_buf->bit_pos;
114
115
976
  WORD32 read_word;
116
976
  WORD32 diffbytes;
117
118
976
  diffbytes = (WORD32)(it_bit_buf->ptr_bit_buf_end - ptr_read_next);
119
976
  diffbytes++;
120
976
  if (diffbytes >= 4) {
121
908
    read_word = ixheaacd_res_aac_showbits_32(ptr_read_next);
122
908
    diffbytes = 4;
123
908
    ptr_read_next = it_bit_buf->ptr_read_next + 4;
124
908
  } else {
125
68
    WORD32 ii;
126
68
    read_word = 0;
127
179
    for (ii = 0; ii < diffbytes; ii++) {
128
111
      read_word = (read_word << 8) | (*ptr_read_next);
129
111
      ptr_read_next++;
130
111
    }
131
68
    read_word <<= ((4 - diffbytes) << 3);
132
68
  }
133
976
  p_code_book = p_aac_decoder_channel_info->p_code_book;
134
135
976
  p_ics_info = &p_aac_decoder_channel_info->ics_info;
136
976
  sfb_transmitted = p_ics_info->max_sf_bands;
137
138
976
  p_scale_factor = p_aac_decoder_channel_info->p_scale_factor;
139
976
  window_groups = p_ics_info->window_groups;
140
976
  band = sfb_transmitted - 1;
141
142
2.35k
  for (group = 0; group < window_groups; group++) {
143
1.38k
    p_codebook_tmp = &p_code_book[group * MAX_SFB_SHORT];
144
1.38k
    p_scale_factor_tmp = &p_scale_factor[group * MAX_SFB_SHORT];
145
10.5k
    for (band = sfb_transmitted - 1; band >= 0; band--) {
146
9.19k
      WORD32 cb_num = *p_codebook_tmp++;
147
148
9.19k
      if (cb_num == ZERO_HCB)
149
1.35k
        *p_scale_factor_tmp++ = 0;
150
7.84k
      else {
151
7.84k
        {
152
7.84k
          WORD32 flag = 1;
153
7.84k
          WORD pns_band;
154
7.84k
          ia_mps_dec_residual_pns_data_struct *p_pns_data = &p_aac_decoder_channel_info->pns_data;
155
7.84k
          if (cb_num == NOISE_HCB && (p_pns_data->pns_active != 1)) flag = 0;
156
157
7.84k
          if (flag) {
158
7.80k
            UWORD16 first_offset;
159
7.80k
            WORD16 sign_ret_val;
160
7.80k
            UWORD32 read_word1;
161
162
7.80k
            read_word1 = read_word << bit_pos;
163
7.80k
            h = (UWORD16 *)(hscf);
164
7.80k
            first_offset = 7;
165
7.80k
            h += (read_word1) >> (32 - first_offset);
166
7.80k
            sign_ret_val = *h;
167
168
9.26k
            while (sign_ret_val > 0) {
169
1.45k
              bit_pos += first_offset;
170
171
1.45k
              ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
172
1.45k
                                          it_bit_buf->ptr_bit_buf_end);
173
1.45k
              read_word1 = (read_word1) << (first_offset);
174
175
1.45k
              first_offset = (sign_ret_val >> 11);
176
1.45k
              first_offset = (sign_ret_val >> 11);
177
1.45k
              h += sign_ret_val & (0x07FF);
178
1.45k
              h += (read_word1) >> (32 - first_offset);
179
1.45k
              sign_ret_val = *h;
180
1.45k
            }
181
182
7.80k
            bit_pos += ((sign_ret_val & 0x7fff) >> 11);
183
184
7.80k
            ixheaacd_aac_read_byte_corr(&ptr_read_next, &bit_pos, &read_word,
185
7.80k
                                        it_bit_buf->ptr_bit_buf_end);
186
7.80k
            norm_value = (sign_ret_val & (0x07FF)) - 60;
187
7.80k
          } else {
188
37
            WORD32 noise_start_value;
189
37
            UWORD32 temp;
190
37
            temp = (read_word << bit_pos);
191
37
            temp = ((UWORD32)temp >> (32 - 9));
192
37
            noise_start_value = temp;
193
37
            bit_pos += 9;
194
195
37
            ixheaacd_aac_read_2bytes(&ptr_read_next, &bit_pos, &read_word);
196
197
37
            norm_value = noise_start_value - 256;
198
37
            p_pns_data->pns_active = 1;
199
200
37
            p_pns_data->current_energy = global_gain - NOISE_OFFSET;
201
37
          }
202
203
7.84k
          if (cb_num > NOISE_HCB) {
204
1.13k
            position = position + norm_value;
205
1.13k
            *p_scale_factor_tmp++ = -position;
206
6.70k
          } else if (cb_num < NOISE_HCB) {
207
6.49k
            factor = factor + norm_value;
208
6.49k
            *p_scale_factor_tmp++ = factor;
209
6.49k
          } else {
210
214
            p_pns_data->current_energy =
211
214
                ixheaac_add16_sat(p_pns_data->current_energy, norm_value);
212
213
214
            pns_band = (group << 4) + sfb_transmitted - band - 1;
214
214
            p_aac_decoder_channel_info->p_scale_factor[pns_band] = p_pns_data->current_energy;
215
216
214
            p_pns_data->pns_used[pns_band] = 1;
217
214
            p_scale_factor_tmp++;
218
214
          }
219
7.84k
        }
220
7.84k
      }
221
9.19k
    }
222
1.38k
  }
223
224
976
  it_bit_buf->ptr_read_next = ptr_read_next - diffbytes;
225
226
976
  it_bit_buf->bit_pos = 7 - bit_pos;
227
976
  {
228
976
    WORD bits_cons;
229
976
    bits_cons = (WORD)(((it_bit_buf->ptr_read_next - start_read_pos) << 3) +
230
976
                       (start_bit_pos - it_bit_buf->bit_pos));
231
976
    it_bit_buf->cnt_bits -= bits_cons;
232
976
  }
233
976
}