Coverage Report

Created: 2025-08-29 06:15

/src/libxaac/encoder/ixheaace_bitbuffer.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 <stdlib.h>
22
23
#include "ixheaac_type_def.h"
24
#include "ixheaac_constants.h"
25
#include "ixheaace_aac_constants.h"
26
#include "ixheaace_bitbuffer.h"
27
28
static VOID ia_enhaacplus_enc_update_bitbuf_word_ptr(ixheaace_bit_buf_handle pstr_bit_buf,
29
0
                                                     UWORD8 **p_bitbuf_word, WORD32 cnt) {
30
0
  *p_bitbuf_word += cnt;
31
32
0
  if (*p_bitbuf_word > pstr_bit_buf->ptr_bit_buf_end) {
33
0
    *p_bitbuf_word -= (pstr_bit_buf->ptr_bit_buf_end - pstr_bit_buf->ptr_bit_buf_base + 1);
34
0
  }
35
36
0
  if (*p_bitbuf_word < pstr_bit_buf->ptr_bit_buf_base) {
37
0
    *p_bitbuf_word += (pstr_bit_buf->ptr_bit_buf_end - pstr_bit_buf->ptr_bit_buf_base + 1);
38
0
  }
39
0
}
40
41
ixheaace_bit_buf_handle ia_enhaacplus_enc_create_bitbuffer(ixheaace_bit_buf_handle pstr_bit_buf,
42
                                                           UWORD8 *ptr_bit_buf_base,
43
382k
                                                           UWORD32 bitbuf_size) {
44
382k
  pstr_bit_buf->ptr_bit_buf_base = ptr_bit_buf_base;
45
46
382k
  pstr_bit_buf->ptr_bit_buf_end = ptr_bit_buf_base + bitbuf_size - 1;
47
48
382k
  pstr_bit_buf->ptr_read_next = ptr_bit_buf_base;
49
382k
  pstr_bit_buf->ptr_write_next = ptr_bit_buf_base;
50
51
382k
  pstr_bit_buf->write_position = 7;
52
382k
  pstr_bit_buf->read_position = 7;
53
54
382k
  pstr_bit_buf->cnt_bits = 0;
55
56
382k
  pstr_bit_buf->size = bitbuf_size * 8;
57
58
382k
  return pstr_bit_buf;
59
382k
}
60
61
0
VOID ia_enhaacplus_enc_delete_bitbuffer(ixheaace_bit_buf_handle pstr_bit_buf) {
62
0
  pstr_bit_buf = NULL;
63
0
}
64
65
VOID ixheaace_reset_bitbuf(ixheaace_bit_buf_handle pstr_bit_buf, UWORD8 *ptr_bit_buf_base,
66
479k
                           UWORD32 bitbuf_size) {
67
479k
  pstr_bit_buf->ptr_bit_buf_base = ptr_bit_buf_base;
68
69
479k
  pstr_bit_buf->ptr_bit_buf_end = ptr_bit_buf_base + bitbuf_size - 1;
70
71
479k
  pstr_bit_buf->ptr_read_next = ptr_bit_buf_base;
72
479k
  pstr_bit_buf->ptr_write_next = ptr_bit_buf_base;
73
74
479k
  pstr_bit_buf->read_position = 7;
75
479k
  pstr_bit_buf->write_position = 7;
76
77
479k
  pstr_bit_buf->cnt_bits = 0;
78
479k
}
79
VOID ixheaace_copy_bitbuf_to_and_fro(ixheaace_bit_buf_handle h_bitbuf_src,
80
                                     ixheaace_bit_buf_handle h_bitbuf_dst)
81
82
29.6k
{
83
29.6k
  WORD32 i;
84
29.6k
  WORD32 bytes_to_go_src =
85
29.6k
      (WORD32)(h_bitbuf_src->ptr_bit_buf_end - h_bitbuf_src->ptr_bit_buf_base);
86
87
29.6k
  UWORD8 *dst = &h_bitbuf_dst->ptr_bit_buf_base[0];
88
29.6k
  UWORD8 *src = &h_bitbuf_src->ptr_bit_buf_base[0];
89
29.6k
  WORD32 temp321, temp322;
90
29.6k
  UWORD8 temp1, temp2, temp3;
91
29.6k
  WORD32 count;
92
29.6k
  WORD32 remaining;
93
94
29.6k
  count = bytes_to_go_src >> 1;
95
29.6k
  remaining = bytes_to_go_src - (count << 1);
96
97
3.78M
  for (i = count - 1; i >= 0; i--) {
98
3.75M
    temp1 = *src;
99
3.75M
    temp2 = *dst;
100
3.75M
    temp3 = *(src + 1);
101
3.75M
    *dst++ = temp1;
102
3.75M
    temp1 = *dst;
103
3.75M
    *src++ = temp2;
104
3.75M
    *dst++ = temp3;
105
3.75M
    *src++ = temp1;
106
3.75M
  }
107
29.6k
  if (remaining)
108
59.2k
    for (i = remaining - 1; i >= 0; i--) {
109
29.6k
      temp1 = *src;
110
29.6k
      temp2 = *dst;
111
29.6k
      *dst++ = temp1;
112
29.6k
      *src++ = temp2;
113
29.6k
    }
114
115
29.6k
  src = h_bitbuf_src->ptr_read_next;
116
29.6k
  dst = h_bitbuf_dst->ptr_read_next;
117
118
29.6k
  h_bitbuf_dst->ptr_read_next = src;
119
29.6k
  h_bitbuf_src->ptr_read_next = dst;
120
121
29.6k
  src = h_bitbuf_src->ptr_write_next;
122
29.6k
  dst = h_bitbuf_dst->ptr_write_next;
123
124
29.6k
  h_bitbuf_dst->ptr_write_next = src;
125
29.6k
  h_bitbuf_src->ptr_write_next = dst;
126
127
29.6k
  temp321 = h_bitbuf_dst->read_position;
128
29.6k
  temp322 = h_bitbuf_src->read_position;
129
130
29.6k
  h_bitbuf_dst->read_position = temp322;
131
29.6k
  h_bitbuf_src->read_position = temp321;
132
133
29.6k
  temp321 = h_bitbuf_dst->write_position;
134
29.6k
  temp322 = h_bitbuf_src->write_position;
135
136
29.6k
  h_bitbuf_dst->write_position = temp322;
137
29.6k
  h_bitbuf_src->write_position = temp321;
138
139
29.6k
  temp321 = h_bitbuf_dst->cnt_bits;
140
29.6k
  temp322 = h_bitbuf_src->cnt_bits;
141
142
29.6k
  h_bitbuf_dst->cnt_bits = temp322;
143
29.6k
  h_bitbuf_src->cnt_bits = temp321;
144
29.6k
}
145
146
VOID ia_enhaacplus_enc_copy_bitbuf(ixheaace_bit_buf_handle h_bitbuf_src,
147
352
                                   ixheaace_bit_buf_handle h_bitbuf_dst) {
148
352
  WORD32 i;
149
352
  WORD32 bytes_to_go_src =
150
352
      (WORD32)(h_bitbuf_src->ptr_bit_buf_end - h_bitbuf_src->ptr_bit_buf_base);
151
152
90.1k
  for (i = 0; i < bytes_to_go_src; i++) {
153
89.7k
    h_bitbuf_dst->ptr_bit_buf_base[i] = h_bitbuf_src->ptr_bit_buf_base[i];
154
89.7k
  }
155
156
352
  h_bitbuf_dst->ptr_read_next = h_bitbuf_src->ptr_read_next;
157
352
  h_bitbuf_dst->ptr_write_next = h_bitbuf_src->ptr_write_next;
158
159
352
  h_bitbuf_dst->read_position = h_bitbuf_src->read_position;
160
352
  h_bitbuf_dst->write_position = h_bitbuf_src->write_position;
161
162
352
  h_bitbuf_dst->cnt_bits = h_bitbuf_src->cnt_bits;
163
352
}
164
165
5.78M
WORD32 ia_enhaacplus_enc_get_bits_available(ixheaace_bit_buf_handle pstr_bit_buf_handle) {
166
5.78M
  return pstr_bit_buf_handle->cnt_bits;
167
5.78M
}
168
UWORD32
169
1.42M
ixheaace_readbits(ixheaace_bit_buf_handle pstr_bit_buf, UWORD8 no_bits_to_read) {
170
1.42M
  UWORD32 return_value;
171
172
1.42M
  if (no_bits_to_read >= 25) {
173
0
    return 0;
174
0
  }
175
176
1.42M
  pstr_bit_buf->cnt_bits -= no_bits_to_read;
177
1.42M
  pstr_bit_buf->read_position -= no_bits_to_read;
178
179
1.42M
  return_value = (UWORD32)*pstr_bit_buf->ptr_read_next;
180
181
3.97M
  while (pstr_bit_buf->read_position < 0) {
182
2.54M
    pstr_bit_buf->read_position += 8;
183
2.54M
    pstr_bit_buf->ptr_read_next++;
184
185
2.54M
    if (pstr_bit_buf->ptr_read_next > pstr_bit_buf->ptr_bit_buf_end) {
186
123
      pstr_bit_buf->ptr_read_next = pstr_bit_buf->ptr_bit_buf_base;
187
123
    }
188
189
2.54M
    return_value <<= 8;
190
191
2.54M
    return_value |= (UWORD32)*pstr_bit_buf->ptr_read_next;
192
2.54M
  }
193
1.42M
  return_value = return_value << (31 - no_bits_to_read - pstr_bit_buf->read_position) >>
194
1.42M
                 (32 - no_bits_to_read);
195
196
1.42M
  return (return_value);
197
1.42M
}
198
199
VOID ia_enhaacplus_enc_wind_bitbuffer_bidirectional(ixheaace_bit_buf_handle pstr_bit_buf,
200
0
                                                    WORD32 offset) {
201
0
  if (offset != 0) {
202
0
    WORD32 buff_offset;
203
0
    pstr_bit_buf->read_position -= offset;
204
0
    buff_offset = (pstr_bit_buf->read_position) >> 3;
205
0
    pstr_bit_buf->read_position -= buff_offset << 3;
206
207
0
    if (buff_offset) {
208
0
      ia_enhaacplus_enc_update_bitbuf_word_ptr(pstr_bit_buf, &pstr_bit_buf->ptr_read_next,
209
0
                                               -buff_offset);
210
0
    }
211
212
0
    pstr_bit_buf->cnt_bits -= offset;
213
0
  }
214
0
}