Coverage Report

Created: 2025-08-03 06:57

/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
124k
                                                   ixheaace_tools_info *pstr_tools_info) {
50
124k
  WORD32 ms_bits = 0, sfb_off;
51
52
124k
  switch (pstr_tools_info->ms_digest) {
53
11.2k
    case MS_NONE:
54
114k
    case MS_ALL:
55
114k
      break;
56
57
10.4k
    case MS_SOME:
58
59
29.1k
      for (sfb_off = 0; sfb_off < sfb_cnt; sfb_off += sfb_per_group) {
60
18.7k
        ms_bits += max_sfb_per_grp;
61
18.7k
      }
62
10.4k
      break;
63
124k
  }
64
65
124k
  return ms_bits;
66
124k
}
67
68
static WORD32 ia_enhaacplus_enc_tns_count(ixheaace_temporal_noise_shaping_params *pstr_tns_info,
69
409k
                                          WORD32 block_type) {
70
409k
  WORD32 i, k;
71
409k
  WORD32 tns_present;
72
409k
  WORD32 num_windows;
73
409k
  WORD32 count;
74
409k
  WORD32 coef_bits;
75
76
409k
  count = 0;
77
409k
  num_windows = (block_type == 2 ? 8 : 1);
78
409k
  tns_present = 0;
79
80
1.31M
  for (i = 0; i < num_windows; i++) {
81
908k
    if (pstr_tns_info->tns_active[i] == 1) {
82
337k
      tns_present = 1;
83
337k
    }
84
908k
  }
85
86
409k
  if (tns_present == 1) {
87
716k
    for (i = 0; i < num_windows; i++) {
88
511k
      count += (block_type == SHORT_WINDOW ? 1 : 2);
89
90
511k
      if (pstr_tns_info->tns_active[i]) {
91
337k
        count += (block_type == SHORT_WINDOW ? 8 : 12);
92
93
337k
        if (pstr_tns_info->order[i]) {
94
337k
          count += 2; /*coef_compression */
95
96
337k
          if (pstr_tns_info->coef_res[i] == 4) {
97
161k
            coef_bits = 3;
98
99
537k
            for (k = 0; k < pstr_tns_info->order[i]; k++) {
100
518k
              if (pstr_tns_info->coef[i * TEMPORAL_NOISE_SHAPING_MAX_ORDER_SHORT + k] > 3 ||
101
518k
                  pstr_tns_info->coef[i * TEMPORAL_NOISE_SHAPING_MAX_ORDER_SHORT + k] < -4) {
102
143k
                coef_bits = 4;
103
143k
                break;
104
143k
              }
105
518k
            }
106
175k
          } else {
107
175k
            coef_bits = 2;
108
109
464k
            for (k = 0; k < pstr_tns_info->order[i]; k++) {
110
344k
              if (pstr_tns_info->coef[i * TEMPORAL_NOISE_SHAPING_MAX_ORDER_SHORT + k] > 1 ||
111
344k
                  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
344k
            }
116
175k
          }
117
118
2.12M
          for (k = 0; k < pstr_tns_info->order[i]; k++) {
119
1.79M
            count += coef_bits;
120
1.79M
          }
121
337k
        }
122
337k
      }
123
511k
    }
124
205k
  }
125
126
409k
  return count;
127
409k
}
128
129
static WORD32 ia_enhaacplus_enc_count_tns_bits(
130
409k
    ixheaace_temporal_noise_shaping_params *pstr_tns_info, WORD32 block_type) {
131
409k
  return (ia_enhaacplus_enc_tns_count(pstr_tns_info, block_type));
132
409k
}
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
285k
    WORD32 stat_bits_flag, WORD32 flag_last_element) {
138
285k
  WORD32 static_bits = 0;
139
285k
  WORD32 ch;
140
141
285k
  switch (channels) {
142
160k
    case 1:
143
144
160k
      static_bits += SI_ID_BITS + SI_SCE_BITS + SI_ICS_BITS;
145
146
160k
      static_bits += ia_enhaacplus_enc_count_tns_bits(&(psy_out_ch[0]->tns_info),
147
160k
                                                      psy_out_ch[0]->window_sequence);
148
160k
      switch (psy_out_ch[0]->window_sequence) {
149
137k
        case LONG_WINDOW:
150
142k
        case START_WINDOW:
151
147k
        case STOP_WINDOW:
152
153
147k
          static_bits += SI_ICS_INFO_BITS_LONG;
154
147k
          break;
155
156
13.0k
        case SHORT_WINDOW:
157
158
13.0k
          static_bits += SI_ICS_INFO_BITS_SHORT;
159
13.0k
          break;
160
160k
      }
161
160k
      break;
162
163
160k
    case 2:
164
124k
      static_bits += SI_ID_BITS + SI_CPE_BITS + 2 * SI_ICS_BITS;
165
166
124k
      static_bits += SI_CPE_MS_MASK_BITS;
167
168
124k
      static_bits += ia_enhaacplus_enc_count_ms_mask_bits(
169
124k
          psy_out_ch[0]->sfb_count, psy_out_ch[0]->sfb_per_group, psy_out_ch[0]->max_sfb_per_grp,
170
124k
          &pstr_psy_out_element->tools_info);
171
172
124k
      switch (psy_out_ch[0]->window_sequence) {
173
77.8k
        case LONG_WINDOW:
174
87.2k
        case START_WINDOW:
175
95.3k
        case STOP_WINDOW:
176
177
95.3k
          static_bits += SI_ICS_INFO_BITS_LONG;
178
95.3k
          break;
179
180
29.0k
        case SHORT_WINDOW:
181
182
29.0k
          static_bits += SI_ICS_INFO_BITS_SHORT;
183
29.0k
          break;
184
124k
      }
185
186
373k
      for (ch = 0; ch < 2; ch++) {
187
248k
        static_bits += ia_enhaacplus_enc_count_tns_bits(&(psy_out_ch[ch]->tns_info),
188
248k
                                                        psy_out_ch[ch]->window_sequence);
189
248k
      }
190
191
124k
      break;
192
285k
  }
193
194
285k
  if (aot == AOT_AAC_LC || aot == AOT_SBR || aot == AOT_PS) {
195
170k
    if (!(adts_flag)) {
196
87.5k
      return static_bits + stat_bits_flag * 8;
197
87.5k
    }
198
199
83.1k
    if (adts_flag && (stat_bits_flag) && (flag_last_element)) {
200
8.68k
      return static_bits + 56;
201
74.4k
    } else {
202
74.4k
      return static_bits;
203
74.4k
    }
204
114k
  } else {
205
114k
    return static_bits;  // Default Case
206
114k
  }
207
285k
}