Coverage Report

Created: 2026-02-07 06:13

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libxaac/decoder/ixheaacd_aacpluscheck.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 <stdio.h>
21
#include <string.h>
22
#include "ixheaacd_sbr_common.h"
23
#include "ixheaac_type_def.h"
24
25
#include "ixheaac_constants.h"
26
#include "ixheaac_basic_ops32.h"
27
#include "ixheaac_basic_ops16.h"
28
#include "ixheaac_basic_ops40.h"
29
#include "ixheaac_basic_ops.h"
30
31
#include "ixheaac_basic_op.h"
32
#include "ixheaacd_intrinsics.h"
33
#include "ixheaacd_bitbuffer.h"
34
#include "ixheaacd_defines.h"
35
36
#include "ixheaacd_pns.h"
37
38
#include "ixheaacd_aac_rom.h"
39
#include "ixheaacd_pulsedata.h"
40
#include "ixheaacd_drc_data_struct.h"
41
42
#include "ixheaacd_lt_predict.h"
43
#include "ixheaacd_cnst.h"
44
#include "ixheaacd_ec_defines.h"
45
#include "ixheaacd_ec_struct_def.h"
46
47
#include "ixheaacd_channelinfo.h"
48
#include "ixheaacd_drc_dec.h"
49
50
#include "ixheaacd_sbrdecoder.h"
51
#include "ixheaacd_sbr_payload.h"
52
#include "ixheaacd_audioobjtypes.h"
53
#include "ixheaacd_error_codes.h"
54
55
#define SBR_EXTENSION_MPEG SBR_EXTENSION
56
57
#define SBR_EXTENSION_CRC_MPEG SBR_EXTENSION_CRC
58
59
FLAG ixheaacd_check_for_sbr_payload(ia_bit_buf_struct *it_bit_buff,
60
                                    ia_aac_dec_sbr_bitstream_struct *pstr_stream_sbr,
61
                                    WORD16 prev_element, ia_drc_dec_struct *pstr_drc_dec,
62
                                    WORD32 object_type, WORD32 adtsheader, WORD32 cnt_bits,
63
                                    WORD32 ld_sbr_crc_flag, ia_drc_dec_struct *drc_dummy,
64
                                    UWORD8 *mps_buffer, WORD32 *mps_header, WORD32 *mps_bytes,
65
88.3k
                                    WORD32 is_init, WORD32 *is_first, WORD32 ec_flag) {
66
88.3k
  FLAG ret = 0;
67
88.3k
  WORD32 count;
68
69
88.3k
  if (object_type == AOT_ER_AAC_ELD) {
70
53.4k
    count = it_bit_buff->cnt_bits >> 3;
71
53.4k
    if (adtsheader == 1) count = cnt_bits >> 3;
72
53.4k
  } else {
73
34.8k
    count = ixheaacd_read_bits_buf(it_bit_buff, 4);
74
75
34.8k
    if ((count - 15) == 0) {
76
6.03k
      WORD32 esc_count;
77
6.03k
      esc_count = ixheaacd_read_bits_buf(it_bit_buff, 8);
78
6.03k
      count = (esc_count + 14);
79
6.03k
    }
80
34.8k
  }
81
82
88.3k
  if (count > 0) {
83
81.7k
    WORD32 extension_type;
84
85
81.7k
    if (object_type == AOT_ER_AAC_ELD)
86
53.3k
      extension_type = ld_sbr_crc_flag ? SBR_EXTENSION_CRC : SBR_EXTENSION;
87
28.3k
    else
88
28.3k
      extension_type = ixheaacd_read_bits_buf(it_bit_buff, 4);
89
90
81.7k
    if (((count < MAXSBRBYTES)) &&
91
55.6k
        (((extension_type == SBR_EXTENSION)) || ((extension_type == SBR_EXTENSION_CRC))) &&
92
42.7k
        ((prev_element == SBR_ID_SCE) || (prev_element == SBR_ID_CPE) ||
93
7.24k
         sub_d(prev_element, SBR_ID_CCE) == 0)
94
95
81.7k
            ) {
96
42.1k
      WORD32 no_elements = pstr_stream_sbr->no_elements;
97
42.1k
      WORD32 byte_count;
98
42.1k
      ia_sbr_element_stream_struct *ptr_stream_sbr;
99
100
42.1k
      ret = 1;
101
102
42.1k
      ptr_stream_sbr = &pstr_stream_sbr->str_sbr_ele[no_elements];
103
104
42.1k
      if (ec_flag) {
105
0
        ptr_stream_sbr->size_payload = ptr_stream_sbr->size_payload_old;
106
0
        byte_count = ptr_stream_sbr->size_payload;
107
0
        ptr_stream_sbr->extension_type = ptr_stream_sbr->prev_extension_type;
108
0
        ptr_stream_sbr->sbr_ele_id = ptr_stream_sbr->prev_sbr_ele_id;
109
0
      }
110
111
42.1k
      if (ec_flag) {
112
0
        ptr_stream_sbr->size_payload_old = count;
113
0
        byte_count = ptr_stream_sbr->size_payload_old;
114
0
        ptr_stream_sbr->prev_extension_type = extension_type;
115
0
        ptr_stream_sbr->prev_sbr_ele_id = prev_element;
116
42.1k
      } else {
117
42.1k
        ptr_stream_sbr->size_payload = count;
118
42.1k
        byte_count = ptr_stream_sbr->size_payload;
119
42.1k
        ptr_stream_sbr->extension_type = extension_type;
120
42.1k
        ptr_stream_sbr->sbr_ele_id = prev_element;
121
42.1k
      }
122
42.1k
      pstr_stream_sbr->no_elements = no_elements + 1;
123
124
42.1k
      if (pstr_drc_dec) pstr_drc_dec->sbr_found = 1;
125
126
42.1k
      if (ec_flag) {
127
0
        memcpy(ptr_stream_sbr->ptr_sbr_data, ptr_stream_sbr->sbr_prev_data,
128
0
               sizeof(ptr_stream_sbr->sbr_prev_data));
129
0
      }
130
131
42.1k
      if (byte_count > 0 && sub_d(byte_count, MAXSBRBYTES) <= 0) {
132
42.1k
        WORD32 i;
133
42.1k
        WORD8 *ptr_sbr_data;
134
42.1k
        if (object_type != AOT_ER_AAC_ELD) {
135
15.2k
          if (ec_flag) {
136
0
            ptr_sbr_data = &ptr_stream_sbr->sbr_prev_data[1];
137
0
            ptr_stream_sbr->sbr_prev_data[0] = (WORD8)ixheaacd_read_bits_buf(it_bit_buff, 4);
138
15.2k
          } else {
139
15.2k
            ptr_sbr_data = &ptr_stream_sbr->ptr_sbr_data[1];
140
15.2k
            ptr_stream_sbr->ptr_sbr_data[0] = (WORD8)ixheaacd_read_bits_buf(it_bit_buff, 4);
141
15.2k
          }
142
26.8k
        } else {
143
26.8k
          if (ec_flag) {
144
0
            ptr_sbr_data = ptr_stream_sbr->sbr_prev_data;
145
26.8k
          } else {
146
26.8k
            ptr_sbr_data = ptr_stream_sbr->ptr_sbr_data;
147
26.8k
          }
148
26.8k
        }
149
9.14M
        for (i = byte_count - 2; i >= 0; i--) {
150
9.10M
          *ptr_sbr_data++ = (WORD8)ixheaacd_read_bits_buf(it_bit_buff, 8);
151
9.10M
          if (object_type == AOT_ER_AAC_ELD) {
152
8.97M
            if (adtsheader == 1) {
153
0
              cnt_bits = cnt_bits - 8;
154
0
            }
155
8.97M
          }
156
9.10M
        }
157
158
42.1k
        if (object_type == AOT_ER_AAC_ELD) {
159
26.8k
          *ptr_sbr_data++ = (WORD8)ixheaacd_read_bits_buf(it_bit_buff, 8);
160
26.8k
          if (adtsheader == 1) {
161
0
            cnt_bits = cnt_bits - 8;
162
0
            if (cnt_bits > 0) {
163
0
              WORD32 unaligned_bits = (8 - it_bit_buff->cnt_bits);
164
0
              *ptr_sbr_data = (WORD8)ixheaacd_read_bits_buf(it_bit_buff, cnt_bits);
165
0
              *ptr_sbr_data = *ptr_sbr_data << unaligned_bits;
166
0
              if (!ec_flag)
167
0
                ptr_stream_sbr->size_payload++;
168
0
              else
169
0
                ptr_stream_sbr->size_payload_old++;
170
0
            }
171
26.8k
          } else {
172
26.8k
            if (it_bit_buff->cnt_bits > 0) {
173
22.8k
              WORD32 unaligned_bits = (8 - it_bit_buff->cnt_bits);
174
22.8k
              *ptr_sbr_data = (WORD8)ixheaacd_read_bits_buf(it_bit_buff, it_bit_buff->cnt_bits);
175
22.8k
              *ptr_sbr_data = *ptr_sbr_data << unaligned_bits;
176
22.8k
              if (!ec_flag)
177
22.8k
                ptr_stream_sbr->size_payload++;
178
0
              else
179
0
                ptr_stream_sbr->size_payload_old++;
180
22.8k
            }
181
26.8k
          }
182
26.8k
        }
183
42.1k
      }
184
185
42.1k
    } else if (extension_type == EXT_DYNAMIC_RANGE) {
186
379
      pstr_drc_dec->drc_element_found = 1;
187
379
      count -= ixheaacd_dec_drc_read_element(pstr_drc_dec, drc_dummy, it_bit_buff);
188
39.2k
    } else if (extension_type == EXT_SAC_DATA) {
189
10.5k
      WORD32 anc_type, anc_start, i, len = 0;
190
10.5k
      anc_type = ixheaacd_read_bits_buf(it_bit_buff, 2);
191
10.5k
      *mps_header = anc_type;
192
193
10.5k
      anc_start = ixheaacd_read_bits_buf(it_bit_buff, 1);
194
10.5k
      if (anc_start == 1) {
195
8.23k
        *mps_bytes = 0;
196
8.23k
      }
197
10.5k
      ixheaacd_read_bits_buf(it_bit_buff, 1);
198
199
10.5k
      if (anc_type == 1 && is_init == 0 && *is_first == 1) {
200
574
        len = ixheaacd_read_bits_buf(it_bit_buff, 1);
201
574
        len = ixheaacd_read_bits_buf(it_bit_buff, 7) + 1;
202
574
        ixheaacd_read_bidirection(it_bit_buff, -8);
203
574
      }
204
205
377k
      for (i = 0; i < count - 1; i++) {
206
366k
        mps_buffer[i + *mps_bytes] = ixheaacd_read_bits_buf(it_bit_buff, 8);
207
366k
      }
208
209
10.5k
      *mps_bytes += (count - 1);
210
10.5k
      if (anc_type == 1 && is_init == 0 && *is_first == 1) {
211
574
        if (*mps_bytes < len) {
212
1
          if (ec_flag) {
213
0
            *mps_bytes = 0;
214
0
          }
215
1
          longjmp(*(it_bit_buff->xaac_jmp_buf),
216
1
            IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
217
1
        }
218
15.8k
        for (i = 0; i < count - 1; i++) {
219
15.2k
          mps_buffer[i] = mps_buffer[i + len];
220
15.2k
        }
221
573
        *mps_bytes = *mps_bytes - len;
222
573
      }
223
10.5k
      *is_first = 1;
224
28.6k
    } else {
225
28.6k
      ixheaacd_read_bits_buf(it_bit_buff, 4);
226
227
28.6k
      if (it_bit_buff->cnt_bits < ((count - 1) << 3)) {
228
6
        longjmp(*(it_bit_buff->xaac_jmp_buf),
229
6
                IA_XHEAAC_DEC_EXE_NONFATAL_INSUFFICIENT_INPUT_BYTES);
230
6
      }
231
28.6k
      it_bit_buff->ptr_read_next += count - 1;
232
28.6k
      it_bit_buff->cnt_bits -= ((count - 1) << 3);
233
28.6k
    }
234
81.7k
  }
235
88.3k
  return (ret);
236
88.3k
}