Coverage Report

Created: 2025-10-10 06:12

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libxaac/encoder/ixheaace_static_bits.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 "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
142k
                                                   ixheaace_tools_info *pstr_tools_info) {
50
142k
  WORD32 ms_bits = 0, sfb_off;
51
52
142k
  switch (pstr_tools_info->ms_digest) {
53
11.9k
    case MS_NONE:
54
127k
    case MS_ALL:
55
127k
      break;
56
57
15.5k
    case MS_SOME:
58
59
43.6k
      for (sfb_off = 0; sfb_off < sfb_cnt; sfb_off += sfb_per_group) {
60
28.0k
        ms_bits += max_sfb_per_grp;
61
28.0k
      }
62
15.5k
      break;
63
142k
  }
64
65
142k
  return ms_bits;
66
142k
}
67
68
static WORD32 ia_enhaacplus_enc_tns_count(ixheaace_temporal_noise_shaping_params *pstr_tns_info,
69
458k
                                          WORD32 block_type) {
70
458k
  WORD32 i, k;
71
458k
  WORD32 tns_present;
72
458k
  WORD32 num_windows;
73
458k
  WORD32 count;
74
458k
  WORD32 coef_bits;
75
76
458k
  count = 0;
77
458k
  num_windows = (block_type == 2 ? 8 : 1);
78
458k
  tns_present = 0;
79
80
1.49M
  for (i = 0; i < num_windows; i++) {
81
1.03M
    if (pstr_tns_info->tns_active[i] == 1) {
82
347k
      tns_present = 1;
83
347k
    }
84
1.03M
  }
85
86
458k
  if (tns_present == 1) {
87
749k
    for (i = 0; i < num_windows; i++) {
88
532k
      count += (block_type == SHORT_WINDOW ? 1 : 2);
89
90
532k
      if (pstr_tns_info->tns_active[i]) {
91
347k
        count += (block_type == SHORT_WINDOW ? 8 : 12);
92
93
347k
        if (pstr_tns_info->order[i]) {
94
347k
          count += 2; /*coef_compression */
95
96
347k
          if (pstr_tns_info->coef_res[i] == 4) {
97
171k
            coef_bits = 3;
98
99
568k
            for (k = 0; k < pstr_tns_info->order[i]; k++) {
100
546k
              if (pstr_tns_info->coef[i * TEMPORAL_NOISE_SHAPING_MAX_ORDER_SHORT + k] > 3 ||
101
422k
                  pstr_tns_info->coef[i * TEMPORAL_NOISE_SHAPING_MAX_ORDER_SHORT + k] < -4) {
102
150k
                coef_bits = 4;
103
150k
                break;
104
150k
              }
105
546k
            }
106
175k
          } else {
107
175k
            coef_bits = 2;
108
109
484k
            for (k = 0; k < pstr_tns_info->order[i]; k++) {
110
361k
              if (pstr_tns_info->coef[i * TEMPORAL_NOISE_SHAPING_MAX_ORDER_SHORT + k] > 1 ||
111
312k
                  pstr_tns_info->coef[i * TEMPORAL_NOISE_SHAPING_MAX_ORDER_SHORT + k] < -2) {
112
52.6k
                coef_bits = 3;
113
52.6k
                break;
114
52.6k
              }
115
361k
            }
116
175k
          }
117
118
2.21M
          for (k = 0; k < pstr_tns_info->order[i]; k++) {
119
1.86M
            count += coef_bits;
120
1.86M
          }
121
347k
        }
122
347k
      }
123
532k
    }
124
216k
  }
125
126
458k
  return count;
127
458k
}
128
129
static WORD32 ia_enhaacplus_enc_count_tns_bits(
130
458k
    ixheaace_temporal_noise_shaping_params *pstr_tns_info, WORD32 block_type) {
131
458k
  return (ia_enhaacplus_enc_tns_count(pstr_tns_info, block_type));
132
458k
}
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
316k
    WORD32 stat_bits_flag, WORD32 flag_last_element) {
138
316k
  WORD32 static_bits = 0;
139
316k
  WORD32 ch;
140
141
316k
  switch (channels) {
142
173k
    case 1:
143
144
173k
      static_bits += SI_ID_BITS + SI_SCE_BITS + SI_ICS_BITS;
145
146
173k
      static_bits += ia_enhaacplus_enc_count_tns_bits(&(psy_out_ch[0]->tns_info),
147
173k
                                                      psy_out_ch[0]->window_sequence);
148
173k
      switch (psy_out_ch[0]->window_sequence) {
149
146k
        case LONG_WINDOW:
150
152k
        case START_WINDOW:
151
158k
        case STOP_WINDOW:
152
153
158k
          static_bits += SI_ICS_INFO_BITS_LONG;
154
158k
          break;
155
156
15.2k
        case SHORT_WINDOW:
157
158
15.2k
          static_bits += SI_ICS_INFO_BITS_SHORT;
159
15.2k
          break;
160
173k
      }
161
173k
      break;
162
163
173k
    case 2:
164
142k
      static_bits += SI_ID_BITS + SI_CPE_BITS + 2 * SI_ICS_BITS;
165
166
142k
      static_bits += SI_CPE_MS_MASK_BITS;
167
168
142k
      static_bits += ia_enhaacplus_enc_count_ms_mask_bits(
169
142k
          psy_out_ch[0]->sfb_count, psy_out_ch[0]->sfb_per_group, psy_out_ch[0]->max_sfb_per_grp,
170
142k
          &pstr_psy_out_element->tools_info);
171
172
142k
      switch (psy_out_ch[0]->window_sequence) {
173
89.3k
        case LONG_WINDOW:
174
99.7k
        case START_WINDOW:
175
108k
        case STOP_WINDOW:
176
177
108k
          static_bits += SI_ICS_INFO_BITS_LONG;
178
108k
          break;
179
180
33.8k
        case SHORT_WINDOW:
181
182
33.8k
          static_bits += SI_ICS_INFO_BITS_SHORT;
183
33.8k
          break;
184
142k
      }
185
186
428k
      for (ch = 0; ch < 2; ch++) {
187
285k
        static_bits += ia_enhaacplus_enc_count_tns_bits(&(psy_out_ch[ch]->tns_info),
188
285k
                                                        psy_out_ch[ch]->window_sequence);
189
285k
      }
190
191
142k
      break;
192
316k
  }
193
194
316k
  if (aot == AOT_AAC_LC || aot == AOT_SBR || aot == AOT_PS) {
195
196k
    if (!(adts_flag)) {
196
88.8k
      return static_bits + stat_bits_flag * 8;
197
88.8k
    }
198
199
107k
    if (adts_flag && (stat_bits_flag) && (flag_last_element)) {
200
11.2k
      return static_bits + 56;
201
96.0k
    } else {
202
96.0k
      return static_bits;
203
96.0k
    }
204
119k
  } else {
205
119k
    return static_bits;  // Default Case
206
119k
  }
207
316k
}