Coverage Report

Created: 2026-06-10 06:29

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
139k
                                                   ixheaace_tools_info *pstr_tools_info) {
50
139k
  WORD32 ms_bits = 0, sfb_off;
51
52
139k
  switch (pstr_tools_info->ms_digest) {
53
24.7k
    case MS_NONE:
54
115k
    case MS_ALL:
55
115k
      break;
56
57
23.3k
    case MS_SOME:
58
59
76.9k
      for (sfb_off = 0; sfb_off < sfb_cnt; sfb_off += sfb_per_group) {
60
53.6k
        ms_bits += max_sfb_per_grp;
61
53.6k
      }
62
23.3k
      break;
63
139k
  }
64
65
139k
  return ms_bits;
66
139k
}
67
68
static WORD32 ia_enhaacplus_enc_tns_count(ixheaace_temporal_noise_shaping_params *pstr_tns_info,
69
444k
                                          WORD32 block_type) {
70
444k
  WORD32 i, k;
71
444k
  WORD32 tns_present;
72
444k
  WORD32 num_windows;
73
444k
  WORD32 count;
74
444k
  WORD32 coef_bits;
75
76
444k
  count = 0;
77
444k
  num_windows = (block_type == 2 ? 8 : 1);
78
444k
  tns_present = 0;
79
80
1.49M
  for (i = 0; i < num_windows; i++) {
81
1.05M
    if (pstr_tns_info->tns_active[i] == 1) {
82
320k
      tns_present = 1;
83
320k
    }
84
1.05M
  }
85
86
444k
  if (tns_present == 1) {
87
743k
    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
320k
        count += (block_type == SHORT_WINDOW ? 8 : 12);
92
93
320k
        if (pstr_tns_info->order[i]) {
94
320k
          count += 2; /*coef_compression */
95
96
320k
          if (pstr_tns_info->coef_res[i] == 4) {
97
164k
            coef_bits = 3;
98
99
559k
            for (k = 0; k < pstr_tns_info->order[i]; k++) {
100
533k
              if (pstr_tns_info->coef[i * TEMPORAL_NOISE_SHAPING_MAX_ORDER_SHORT + k] > 3 ||
101
424k
                  pstr_tns_info->coef[i * TEMPORAL_NOISE_SHAPING_MAX_ORDER_SHORT + k] < -4) {
102
138k
                coef_bits = 4;
103
138k
                break;
104
138k
              }
105
533k
            }
106
164k
          } else {
107
155k
            coef_bits = 2;
108
109
429k
            for (k = 0; k < pstr_tns_info->order[i]; k++) {
110
328k
              if (pstr_tns_info->coef[i * TEMPORAL_NOISE_SHAPING_MAX_ORDER_SHORT + k] > 1 ||
111
277k
                  pstr_tns_info->coef[i * TEMPORAL_NOISE_SHAPING_MAX_ORDER_SHORT + k] < -2) {
112
54.9k
                coef_bits = 3;
113
54.9k
                break;
114
54.9k
              }
115
328k
            }
116
155k
          }
117
118
2.09M
          for (k = 0; k < pstr_tns_info->order[i]; k++) {
119
1.77M
            count += coef_bits;
120
1.77M
          }
121
320k
        }
122
320k
      }
123
532k
    }
124
210k
  }
125
126
444k
  return count;
127
444k
}
128
129
static WORD32 ia_enhaacplus_enc_count_tns_bits(
130
444k
    ixheaace_temporal_noise_shaping_params *pstr_tns_info, WORD32 block_type) {
131
444k
  return (ia_enhaacplus_enc_tns_count(pstr_tns_info, block_type));
132
444k
}
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
305k
    WORD32 stat_bits_flag, WORD32 flag_last_element) {
138
305k
  WORD32 static_bits = 0;
139
305k
  WORD32 ch;
140
141
305k
  switch (channels) {
142
166k
    case 1:
143
144
166k
      static_bits += SI_ID_BITS + SI_SCE_BITS + SI_ICS_BITS;
145
146
166k
      static_bits += ia_enhaacplus_enc_count_tns_bits(&(psy_out_ch[0]->tns_info),
147
166k
                                                      psy_out_ch[0]->window_sequence);
148
166k
      switch (psy_out_ch[0]->window_sequence) {
149
135k
        case LONG_WINDOW:
150
141k
        case START_WINDOW:
151
146k
        case STOP_WINDOW:
152
153
146k
          static_bits += SI_ICS_INFO_BITS_LONG;
154
146k
          break;
155
156
19.5k
        case SHORT_WINDOW:
157
158
19.5k
          static_bits += SI_ICS_INFO_BITS_SHORT;
159
19.5k
          break;
160
166k
      }
161
166k
      break;
162
163
166k
    case 2:
164
139k
      static_bits += SI_ID_BITS + SI_CPE_BITS + 2 * SI_ICS_BITS;
165
166
139k
      static_bits += SI_CPE_MS_MASK_BITS;
167
168
139k
      static_bits += ia_enhaacplus_enc_count_ms_mask_bits(
169
139k
          psy_out_ch[0]->sfb_count, psy_out_ch[0]->sfb_per_group, psy_out_ch[0]->max_sfb_per_grp,
170
139k
          &pstr_psy_out_element->tools_info);
171
172
139k
      switch (psy_out_ch[0]->window_sequence) {
173
90.2k
        case LONG_WINDOW:
174
98.3k
        case START_WINDOW:
175
105k
        case STOP_WINDOW:
176
177
105k
          static_bits += SI_ICS_INFO_BITS_LONG;
178
105k
          break;
179
180
33.7k
        case SHORT_WINDOW:
181
182
33.7k
          static_bits += SI_ICS_INFO_BITS_SHORT;
183
33.7k
          break;
184
139k
      }
185
186
417k
      for (ch = 0; ch < 2; ch++) {
187
278k
        static_bits += ia_enhaacplus_enc_count_tns_bits(&(psy_out_ch[ch]->tns_info),
188
278k
                                                        psy_out_ch[ch]->window_sequence);
189
278k
      }
190
191
139k
      break;
192
305k
  }
193
194
305k
  if (aot == AOT_AAC_LC || aot == AOT_SBR || aot == AOT_PS) {
195
203k
    if (!(adts_flag)) {
196
116k
      return static_bits + stat_bits_flag * 8;
197
116k
    }
198
199
86.8k
    if (adts_flag && (stat_bits_flag) && (flag_last_element)) {
200
12.1k
      return static_bits + 56;
201
74.7k
    } else {
202
74.7k
      return static_bits;
203
74.7k
    }
204
102k
  } else {
205
102k
    return static_bits;  // Default Case
206
102k
  }
207
305k
}