Coverage Report

Created: 2024-06-21 06:45

/src/libxaac/encoder/ixheaace_channel_map.c
Line
Count
Source (jump to first uncovered line)
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
5.18k
                                                   WORD32 element_instance_tag) {
52
5.18k
  IA_ERRORCODE error = IA_NO_ERROR;
53
54
5.18k
  pstr_element_info->el_type = el_type;
55
56
5.18k
  switch (pstr_element_info->el_type) {
57
2.39k
    case ID_SCE:
58
2.39k
    case ID_CCE:
59
2.39k
      pstr_element_info->n_channels_in_el = NUM_CHANS_MONO;
60
61
2.39k
      pstr_element_info->channel_index[0] = 0;
62
63
2.39k
      pstr_element_info->instance_tag = element_instance_tag;
64
2.39k
      break;
65
66
429
    case ID_LFE:
67
429
      pstr_element_info->n_channels_in_el = NUM_CHANS_MONO;
68
69
429
      pstr_element_info->channel_index[0] = 0;
70
71
429
      pstr_element_info->instance_tag = element_instance_tag;
72
429
      break;
73
74
2.36k
    case ID_CPE:
75
76
2.36k
      pstr_element_info->n_channels_in_el = NUM_CHANS_STEREO;
77
78
2.36k
      pstr_element_info->channel_index[0] = 0;
79
2.36k
      pstr_element_info->channel_index[1] = 1;
80
81
2.36k
      pstr_element_info->instance_tag = element_instance_tag;
82
2.36k
      break;
83
84
0
    default:
85
0
      return IA_EXHEAACE_INIT_FATAL_INVALID_ELEMENT_TYPE;
86
5.18k
  }
87
88
5.18k
  return error;
89
5.18k
}
90
91
IA_ERRORCODE ia_enhaacplus_enc_init_element_info(WORD32 num_channels,
92
                                                 ixheaace_element_info *pstr_element_info,
93
5.18k
                                                 WORD32 ele_type, WORD32 element_instance_tag) {
94
5.18k
  IA_ERRORCODE error = IA_NO_ERROR;
95
96
5.18k
  if (ele_type != ID_LFE) {
97
4.75k
    switch (num_channels) {
98
2.39k
      case NUM_CHANS_MONO:
99
2.39k
        if (ele_type == -1) {
100
306
          error = ia_enhaacplus_enc_init_element(pstr_element_info, ID_SCE, element_instance_tag);
101
2.08k
        } else {
102
2.08k
          error =
103
2.08k
              ia_enhaacplus_enc_init_element(pstr_element_info, ele_type, element_instance_tag);
104
2.08k
        }
105
2.39k
        break;
106
107
2.36k
      case NUM_CHANS_STEREO:
108
2.36k
        error = ia_enhaacplus_enc_init_element(pstr_element_info, ID_CPE, element_instance_tag);
109
2.36k
        break;
110
111
0
      default:
112
0
        return IA_EXHEAACE_INIT_FATAL_NUM_CHANNELS_NOT_SUPPORTED;
113
4.75k
    }
114
4.75k
  } else {
115
429
    error = ia_enhaacplus_enc_init_element(pstr_element_info, ID_LFE, element_instance_tag);
116
429
  }
117
118
5.18k
  return error;
119
5.18k
}
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
5.18k
                                                 WORD32 bit_res, FLAG flag_framelength_small) {
126
5.18k
  IA_ERRORCODE error = IA_NO_ERROR;
127
128
5.18k
  switch (pstr_element_info.n_channels_in_el) {
129
2.81k
    case NUM_CHANS_MONO:
130
2.81k
      element_bits->ch_bitrate = bitrate_tot;
131
132
2.81k
      element_bits->average_bits = (average_bits_tot - static_bits_tot);
133
2.81k
      switch (aot) {
134
532
        case AOT_AAC_LC:
135
1.27k
        case AOT_SBR:
136
1.69k
        case AOT_PS:
137
1.69k
          if (flag_framelength_small) {
138
607
            element_bits->max_bits = MAXIMUM_CHANNEL_BITS_960;
139
140
607
            element_bits->max_bit_res_bits = MAXIMUM_CHANNEL_BITS_960 - average_bits_tot;
141
1.08k
          } else {
142
1.08k
            element_bits->max_bits = MAXIMUM_CHANNEL_BITS_1024;
143
144
1.08k
            element_bits->max_bit_res_bits = MAXIMUM_CHANNEL_BITS_1024 - average_bits_tot;
145
1.08k
          }
146
1.69k
          break;
147
148
251
        case AOT_AAC_LD:
149
1.12k
        case AOT_AAC_ELD:
150
1.12k
          if (bit_res) {
151
832
            element_bits->max_bits = bit_res;
152
832
            element_bits->max_bit_res_bits = bit_res - average_bits_tot;
153
832
          } else {
154
295
            element_bits->max_bits = average_bits_tot;
155
295
            element_bits->max_bit_res_bits = 0;
156
295
          }
157
1.12k
          break;
158
2.81k
      }
159
160
2.81k
      element_bits->max_bit_res_bits -= (element_bits[0].max_bit_res_bits % 8);
161
2.81k
      element_bits->bit_res_level = element_bits[0].max_bit_res_bits;
162
2.81k
      element_bits->relative_bits = 1;
163
2.81k
      break;
164
165
2.36k
    case NUM_CHANS_STEREO:
166
2.36k
      element_bits->ch_bitrate = bitrate_tot >> 1;
167
168
2.36k
      element_bits->average_bits = (average_bits_tot - static_bits_tot);
169
2.36k
      switch (aot) {
170
548
        case AOT_AAC_LC:
171
1.43k
        case AOT_SBR:
172
1.43k
        case AOT_PS:
173
1.43k
          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
921
          } else {
179
921
            element_bits->max_bits = NUM_CHANS_STEREO * MAXIMUM_CHANNEL_BITS_1024;
180
181
921
            element_bits->max_bit_res_bits =
182
921
                NUM_CHANS_STEREO * MAXIMUM_CHANNEL_BITS_1024 - average_bits_tot;
183
921
          }
184
1.43k
          break;
185
186
242
        case AOT_AAC_LD:
187
928
        case AOT_AAC_ELD:
188
928
          if (bit_res) {
189
767
            element_bits->max_bits = bit_res;
190
767
            element_bits->max_bit_res_bits = bit_res - average_bits_tot;
191
767
          } else {
192
161
            element_bits->max_bits = average_bits_tot;
193
161
            element_bits->max_bit_res_bits = 0;
194
161
          }
195
928
          break;
196
2.36k
      }
197
198
2.36k
      element_bits->max_bit_res_bits -= (element_bits[0].max_bit_res_bits % 8);
199
200
2.36k
      element_bits->bit_res_level = element_bits[0].max_bit_res_bits;
201
2.36k
      element_bits->relative_bits = 1;
202
2.36k
      break;
203
204
0
    default:
205
0
      return IA_EXHEAACE_INIT_FATAL_INVALID_NUM_CHANNELS_IN_ELE;
206
5.18k
  }
207
  /* Bits carried over from previous frame */
208
5.18k
  element_bits->carry_bits = 0;
209
210
5.18k
  return error;
211
5.18k
}