Coverage Report

Created: 2025-07-18 06:38

/src/libxaac/encoder/ixheaace_static_bits.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 "ixheaac_type_def.h"
23
#include "ixheaace_aac_constants.h"
24
#include "impd_drc_common_enc.h"
25
#include "impd_drc_uni_drc.h"
26
#include "impd_drc_tables.h"
27
#include "impd_drc_api.h"
28
#include "ixheaace_api.h"
29
#include "ixheaace_adjust_threshold_data.h"
30
#include "ixheaace_psy_const.h"
31
#include "ixheaace_tns.h"
32
#include "ixheaace_tns_params.h"
33
#include "ixheaace_rom.h"
34
#include "ixheaace_common_rom.h"
35
#include "ixheaace_bitbuffer.h"
36
37
#include "ixheaace_dynamic_bits.h"
38
#include "ixheaace_qc_data.h"
39
40
#include "ixheaace_channel_map.h"
41
#include "ixheaace_block_switch.h"
42
43
#include "ixheaace_psy_data.h"
44
#include "ixheaace_interface.h"
45
#include "ixheaace_write_bitstream.h"
46
47
static WORD32 ia_enhaacplus_enc_count_ms_mask_bits(WORD32 sfb_cnt, WORD32 sfb_per_group,
48
                                                   WORD32 max_sfb_per_grp,
49
134k
                                                   ixheaace_tools_info *pstr_tools_info) {
50
134k
  WORD32 ms_bits = 0, sfb_off;
51
52
134k
  switch (pstr_tools_info->ms_digest) {
53
12.1k
    case MS_NONE:
54
123k
    case MS_ALL:
55
123k
      break;
56
57
10.9k
    case MS_SOME:
58
59
30.8k
      for (sfb_off = 0; sfb_off < sfb_cnt; sfb_off += sfb_per_group) {
60
19.9k
        ms_bits += max_sfb_per_grp;
61
19.9k
      }
62
10.9k
      break;
63
134k
  }
64
65
134k
  return ms_bits;
66
134k
}
67
68
static WORD32 ia_enhaacplus_enc_tns_count(ixheaace_temporal_noise_shaping_params *pstr_tns_info,
69
443k
                                          WORD32 block_type) {
70
443k
  WORD32 i, k;
71
443k
  WORD32 tns_present;
72
443k
  WORD32 num_windows;
73
443k
  WORD32 count;
74
443k
  WORD32 coef_bits;
75
76
443k
  count = 0;
77
443k
  num_windows = (block_type == 2 ? 8 : 1);
78
443k
  tns_present = 0;
79
80
1.42M
  for (i = 0; i < num_windows; i++) {
81
986k
    if (pstr_tns_info->tns_active[i] == 1) {
82
367k
      tns_present = 1;
83
367k
    }
84
986k
  }
85
86
443k
  if (tns_present == 1) {
87
806k
    for (i = 0; i < num_windows; i++) {
88
576k
      count += (block_type == SHORT_WINDOW ? 1 : 2);
89
90
576k
      if (pstr_tns_info->tns_active[i]) {
91
367k
        count += (block_type == SHORT_WINDOW ? 8 : 12);
92
93
367k
        if (pstr_tns_info->order[i]) {
94
367k
          count += 2; /*coef_compression */
95
96
367k
          if (pstr_tns_info->coef_res[i] == 4) {
97
181k
            coef_bits = 3;
98
99
633k
            for (k = 0; k < pstr_tns_info->order[i]; k++) {
100
612k
              if (pstr_tns_info->coef[i * TEMPORAL_NOISE_SHAPING_MAX_ORDER_SHORT + k] > 3 ||
101
612k
                  pstr_tns_info->coef[i * TEMPORAL_NOISE_SHAPING_MAX_ORDER_SHORT + k] < -4) {
102
160k
                coef_bits = 4;
103
160k
                break;
104
160k
              }
105
612k
            }
106
185k
          } else {
107
185k
            coef_bits = 2;
108
109
490k
            for (k = 0; k < pstr_tns_info->order[i]; k++) {
110
368k
              if (pstr_tns_info->coef[i * TEMPORAL_NOISE_SHAPING_MAX_ORDER_SHORT + k] > 1 ||
111
368k
                  pstr_tns_info->coef[i * TEMPORAL_NOISE_SHAPING_MAX_ORDER_SHORT + k] < -2) {
112
64.0k
                coef_bits = 3;
113
64.0k
                break;
114
64.0k
              }
115
368k
            }
116
185k
          }
117
118
2.39M
          for (k = 0; k < pstr_tns_info->order[i]; k++) {
119
2.02M
            count += coef_bits;
120
2.02M
          }
121
367k
        }
122
367k
      }
123
576k
    }
124
230k
  }
125
126
443k
  return count;
127
443k
}
128
129
static WORD32 ia_enhaacplus_enc_count_tns_bits(
130
443k
    ixheaace_temporal_noise_shaping_params *pstr_tns_info, WORD32 block_type) {
131
443k
  return (ia_enhaacplus_enc_tns_count(pstr_tns_info, block_type));
132
443k
}
133
134
WORD32 ia_enhaacplus_enc_count_static_bitdemand(
135
    ixheaace_psy_out_channel **psy_out_ch,
136
    ixheaace_psy_out_element *pstr_psy_out_element, WORD32 channels, WORD32 aot, WORD32 adts_flag,
137
308k
    WORD32 stat_bits_flag, WORD32 flag_last_element) {
138
308k
  WORD32 static_bits = 0;
139
308k
  WORD32 ch;
140
141
308k
  switch (channels) {
142
174k
    case 1:
143
144
174k
      static_bits += SI_ID_BITS + SI_SCE_BITS + SI_ICS_BITS;
145
146
174k
      static_bits += ia_enhaacplus_enc_count_tns_bits(&(psy_out_ch[0]->tns_info),
147
174k
                                                      psy_out_ch[0]->window_sequence);
148
174k
      switch (psy_out_ch[0]->window_sequence) {
149
148k
        case LONG_WINDOW:
150
154k
        case START_WINDOW:
151
159k
        case STOP_WINDOW:
152
153
159k
          static_bits += SI_ICS_INFO_BITS_LONG;
154
159k
          break;
155
156
14.8k
        case SHORT_WINDOW:
157
158
14.8k
          static_bits += SI_ICS_INFO_BITS_SHORT;
159
14.8k
          break;
160
174k
      }
161
174k
      break;
162
163
174k
    case 2:
164
134k
      static_bits += SI_ID_BITS + SI_CPE_BITS + 2 * SI_ICS_BITS;
165
166
134k
      static_bits += SI_CPE_MS_MASK_BITS;
167
168
134k
      static_bits += ia_enhaacplus_enc_count_ms_mask_bits(
169
134k
          psy_out_ch[0]->sfb_count, psy_out_ch[0]->sfb_per_group, psy_out_ch[0]->max_sfb_per_grp,
170
134k
          &pstr_psy_out_element->tools_info);
171
172
134k
      switch (psy_out_ch[0]->window_sequence) {
173
84.0k
        case LONG_WINDOW:
174
94.2k
        case START_WINDOW:
175
103k
        case STOP_WINDOW:
176
177
103k
          static_bits += SI_ICS_INFO_BITS_LONG;
178
103k
          break;
179
180
31.3k
        case SHORT_WINDOW:
181
182
31.3k
          static_bits += SI_ICS_INFO_BITS_SHORT;
183
31.3k
          break;
184
134k
      }
185
186
403k
      for (ch = 0; ch < 2; ch++) {
187
268k
        static_bits += ia_enhaacplus_enc_count_tns_bits(&(psy_out_ch[ch]->tns_info),
188
268k
                                                        psy_out_ch[ch]->window_sequence);
189
268k
      }
190
191
134k
      break;
192
308k
  }
193
194
308k
  if (aot == AOT_AAC_LC || aot == AOT_SBR || aot == AOT_PS) {
195
182k
    if (!(adts_flag)) {
196
89.9k
      return static_bits + stat_bits_flag * 8;
197
89.9k
    }
198
199
92.4k
    if (adts_flag && (stat_bits_flag) && (flag_last_element)) {
200
11.4k
      return static_bits + 56;
201
81.0k
    } else {
202
81.0k
      return static_bits;
203
81.0k
    }
204
126k
  } else {
205
126k
    return static_bits;  // Default Case
206
126k
  }
207
308k
}