Coverage Report

Created: 2026-02-26 06:35

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libxaac/encoder/ixheaace_channel_map.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
21
#include <stddef.h>
22
#include <string.h>
23
#include "ixheaac_type_def.h"
24
#include "ixheaac_constants.h"
25
#include "impd_drc_common_enc.h"
26
#include "impd_drc_uni_drc.h"
27
#include "impd_drc_tables.h"
28
#include "impd_drc_api.h"
29
#include "ixheaace_api.h"
30
#include "ixheaac_error_standards.h"
31
#include "ixheaace_error_codes.h"
32
#include "ixheaace_aac_constants.h"
33
#include "ixheaace_adjust_threshold_data.h"
34
#include "ixheaace_psy_const.h"
35
#include "ixheaace_tns.h"
36
#include "ixheaace_tns_params.h"
37
#include "ixheaace_rom.h"
38
#include "ixheaace_common_rom.h"
39
#include "ixheaace_bitbuffer.h"
40
41
#include "ixheaace_dynamic_bits.h"
42
#include "ixheaace_qc_data.h"
43
#include "ixheaace_channel_map.h"
44
#include "ixheaace_block_switch.h"
45
#include "ixheaace_psy_data.h"
46
#include "ixheaace_interface.h"
47
#include "ixheaace_write_bitstream.h"
48
49
static IA_ERRORCODE ia_enhaacplus_enc_init_element(ixheaace_element_info *pstr_element_info,
50
                                                   ixheaace_element_type el_type,
51
4.75k
                                                   WORD32 element_instance_tag) {
52
4.75k
  IA_ERRORCODE error = IA_NO_ERROR;
53
54
4.75k
  pstr_element_info->el_type = el_type;
55
56
4.75k
  switch (pstr_element_info->el_type) {
57
2.14k
    case ID_SCE:
58
2.14k
    case ID_CCE:
59
2.14k
      pstr_element_info->n_channels_in_el = NUM_CHANS_MONO;
60
61
2.14k
      pstr_element_info->channel_index[0] = 0;
62
63
2.14k
      pstr_element_info->instance_tag = element_instance_tag;
64
2.14k
      break;
65
66
435
    case ID_LFE:
67
435
      pstr_element_info->n_channels_in_el = NUM_CHANS_MONO;
68
69
435
      pstr_element_info->channel_index[0] = 0;
70
71
435
      pstr_element_info->instance_tag = element_instance_tag;
72
435
      break;
73
74
2.17k
    case ID_CPE:
75
76
2.17k
      pstr_element_info->n_channels_in_el = NUM_CHANS_STEREO;
77
78
2.17k
      pstr_element_info->channel_index[0] = 0;
79
2.17k
      pstr_element_info->channel_index[1] = 1;
80
81
2.17k
      pstr_element_info->instance_tag = element_instance_tag;
82
2.17k
      break;
83
84
0
    default:
85
0
      return IA_EXHEAACE_INIT_FATAL_INVALID_ELEMENT_TYPE;
86
4.75k
  }
87
88
4.75k
  return error;
89
4.75k
}
90
91
IA_ERRORCODE ia_enhaacplus_enc_init_element_info(WORD32 num_channels,
92
                                                 ixheaace_element_info *pstr_element_info,
93
4.75k
                                                 WORD32 ele_type, WORD32 element_instance_tag) {
94
4.75k
  IA_ERRORCODE error = IA_NO_ERROR;
95
96
4.75k
  if (ele_type != ID_LFE) {
97
4.32k
    switch (num_channels) {
98
2.14k
      case NUM_CHANS_MONO:
99
2.14k
        if (ele_type == -1) {
100
169
          error = ia_enhaacplus_enc_init_element(pstr_element_info, ID_SCE, element_instance_tag);
101
1.97k
        } else {
102
1.97k
          error =
103
1.97k
              ia_enhaacplus_enc_init_element(pstr_element_info, ele_type, element_instance_tag);
104
1.97k
        }
105
2.14k
        break;
106
107
2.17k
      case NUM_CHANS_STEREO:
108
2.17k
        error = ia_enhaacplus_enc_init_element(pstr_element_info, ID_CPE, element_instance_tag);
109
2.17k
        break;
110
111
0
      default:
112
0
        return IA_EXHEAACE_INIT_FATAL_NUM_CHANNELS_NOT_SUPPORTED;
113
4.32k
    }
114
4.32k
  } else {
115
435
    error = ia_enhaacplus_enc_init_element(pstr_element_info, ID_LFE, element_instance_tag);
116
435
  }
117
118
4.75k
  return error;
119
4.75k
}
120
121
IA_ERRORCODE ia_enhaacplus_enc_init_element_bits(ixheaace_element_bits *element_bits,
122
                                                 ixheaace_element_info pstr_element_info,
123
                                                 WORD32 bitrate_tot, WORD32 average_bits_tot,
124
                                                 WORD32 aot, WORD32 static_bits_tot,
125
4.75k
                                                 WORD32 bit_res, FLAG flag_framelength_small) {
126
4.75k
  IA_ERRORCODE error = IA_NO_ERROR;
127
128
4.75k
  switch (pstr_element_info.n_channels_in_el) {
129
2.58k
    case NUM_CHANS_MONO:
130
2.58k
      element_bits->ch_bitrate = bitrate_tot;
131
132
2.58k
      element_bits->average_bits = (average_bits_tot - static_bits_tot);
133
2.58k
      switch (aot) {
134
553
        case AOT_AAC_LC:
135
1.38k
        case AOT_SBR:
136
1.60k
        case AOT_PS:
137
1.60k
          if (flag_framelength_small) {
138
508
            element_bits->max_bits = MAXIMUM_CHANNEL_BITS_960;
139
140
508
            element_bits->max_bit_res_bits = MAXIMUM_CHANNEL_BITS_960 - average_bits_tot;
141
1.09k
          } else {
142
1.09k
            element_bits->max_bits = MAXIMUM_CHANNEL_BITS_1024;
143
144
1.09k
            element_bits->max_bit_res_bits = MAXIMUM_CHANNEL_BITS_1024 - average_bits_tot;
145
1.09k
          }
146
1.60k
          break;
147
148
286
        case AOT_AAC_LD:
149
978
        case AOT_AAC_ELD:
150
978
          if (bit_res) {
151
648
            element_bits->max_bits = bit_res;
152
648
            element_bits->max_bit_res_bits = bit_res - average_bits_tot;
153
648
          } else {
154
330
            element_bits->max_bits = average_bits_tot;
155
330
            element_bits->max_bit_res_bits = 0;
156
330
          }
157
978
          break;
158
2.58k
      }
159
160
2.58k
      element_bits->max_bit_res_bits -= (element_bits[0].max_bit_res_bits % 8);
161
2.58k
      element_bits->bit_res_level = element_bits[0].max_bit_res_bits;
162
2.58k
      element_bits->relative_bits = 1;
163
2.58k
      break;
164
165
2.17k
    case NUM_CHANS_STEREO:
166
2.17k
      element_bits->ch_bitrate = bitrate_tot >> 1;
167
168
2.17k
      element_bits->average_bits = (average_bits_tot - static_bits_tot);
169
2.17k
      switch (aot) {
170
553
        case AOT_AAC_LC:
171
1.39k
        case AOT_SBR:
172
1.39k
        case AOT_PS:
173
1.39k
          if (flag_framelength_small) {
174
516
            element_bits->max_bits = NUM_CHANS_STEREO * MAXIMUM_CHANNEL_BITS_960;
175
176
516
            element_bits->max_bit_res_bits =
177
516
                NUM_CHANS_STEREO * MAXIMUM_CHANNEL_BITS_960 - average_bits_tot;
178
879
          } else {
179
879
            element_bits->max_bits = NUM_CHANS_STEREO * MAXIMUM_CHANNEL_BITS_1024;
180
181
879
            element_bits->max_bit_res_bits =
182
879
                NUM_CHANS_STEREO * MAXIMUM_CHANNEL_BITS_1024 - average_bits_tot;
183
879
          }
184
1.39k
          break;
185
186
226
        case AOT_AAC_LD:
187
778
        case AOT_AAC_ELD:
188
778
          if (bit_res) {
189
549
            element_bits->max_bits = bit_res;
190
549
            element_bits->max_bit_res_bits = bit_res - average_bits_tot;
191
549
          } else {
192
229
            element_bits->max_bits = average_bits_tot;
193
229
            element_bits->max_bit_res_bits = 0;
194
229
          }
195
778
          break;
196
2.17k
      }
197
198
2.17k
      element_bits->max_bit_res_bits -= (element_bits[0].max_bit_res_bits % 8);
199
200
2.17k
      element_bits->bit_res_level = element_bits[0].max_bit_res_bits;
201
2.17k
      element_bits->relative_bits = 1;
202
2.17k
      break;
203
204
0
    default:
205
0
      return IA_EXHEAACE_INIT_FATAL_INVALID_NUM_CHANNELS_IN_ELE;
206
4.75k
  }
207
  /* Bits carried over from previous frame */
208
4.75k
  element_bits->carry_bits = 0;
209
210
4.75k
  return error;
211
4.75k
}