Coverage Report

Created: 2025-11-24 06:48

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libxaac/encoder/ixheaace_bitbuffer.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 <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
330k
                                                           UWORD32 bitbuf_size) {
44
330k
  pstr_bit_buf->ptr_bit_buf_base = ptr_bit_buf_base;
45
46
330k
  pstr_bit_buf->ptr_bit_buf_end = ptr_bit_buf_base + bitbuf_size - 1;
47
48
330k
  pstr_bit_buf->ptr_read_next = ptr_bit_buf_base;
49
330k
  pstr_bit_buf->ptr_write_next = ptr_bit_buf_base;
50
51
330k
  pstr_bit_buf->write_position = 7;
52
330k
  pstr_bit_buf->read_position = 7;
53
54
330k
  pstr_bit_buf->cnt_bits = 0;
55
56
330k
  pstr_bit_buf->size = bitbuf_size * 8;
57
58
330k
  return pstr_bit_buf;
59
330k
}
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
408k
                           UWORD32 bitbuf_size) {
67
408k
  pstr_bit_buf->ptr_bit_buf_base = ptr_bit_buf_base;
68
69
408k
  pstr_bit_buf->ptr_bit_buf_end = ptr_bit_buf_base + bitbuf_size - 1;
70
71
408k
  pstr_bit_buf->ptr_read_next = ptr_bit_buf_base;
72
408k
  pstr_bit_buf->ptr_write_next = ptr_bit_buf_base;
73
74
408k
  pstr_bit_buf->read_position = 7;
75
408k
  pstr_bit_buf->write_position = 7;
76
77
408k
  pstr_bit_buf->cnt_bits = 0;
78
408k
}
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
28.7k
{
83
28.7k
  WORD32 i;
84
28.7k
  WORD32 bytes_to_go_src =
85
28.7k
      (WORD32)(h_bitbuf_src->ptr_bit_buf_end - h_bitbuf_src->ptr_bit_buf_base);
86
87
28.7k
  UWORD8 *dst = &h_bitbuf_dst->ptr_bit_buf_base[0];
88
28.7k
  UWORD8 *src = &h_bitbuf_src->ptr_bit_buf_base[0];
89
28.7k
  WORD32 temp321, temp322;
90
28.7k
  UWORD8 temp1, temp2, temp3;
91
28.7k
  WORD32 count;
92
28.7k
  WORD32 remaining;
93
94
28.7k
  count = bytes_to_go_src >> 1;
95
28.7k
  remaining = bytes_to_go_src - (count << 1);
96
97
3.67M
  for (i = count - 1; i >= 0; i--) {
98
3.64M
    temp1 = *src;
99
3.64M
    temp2 = *dst;
100
3.64M
    temp3 = *(src + 1);
101
3.64M
    *dst++ = temp1;
102
3.64M
    temp1 = *dst;
103
3.64M
    *src++ = temp2;
104
3.64M
    *dst++ = temp3;
105
3.64M
    *src++ = temp1;
106
3.64M
  }
107
28.7k
  if (remaining)
108
57.4k
    for (i = remaining - 1; i >= 0; i--) {
109
28.7k
      temp1 = *src;
110
28.7k
      temp2 = *dst;
111
28.7k
      *dst++ = temp1;
112
28.7k
      *src++ = temp2;
113
28.7k
    }
114
115
28.7k
  src = h_bitbuf_src->ptr_read_next;
116
28.7k
  dst = h_bitbuf_dst->ptr_read_next;
117
118
28.7k
  h_bitbuf_dst->ptr_read_next = src;
119
28.7k
  h_bitbuf_src->ptr_read_next = dst;
120
121
28.7k
  src = h_bitbuf_src->ptr_write_next;
122
28.7k
  dst = h_bitbuf_dst->ptr_write_next;
123
124
28.7k
  h_bitbuf_dst->ptr_write_next = src;
125
28.7k
  h_bitbuf_src->ptr_write_next = dst;
126
127
28.7k
  temp321 = h_bitbuf_dst->read_position;
128
28.7k
  temp322 = h_bitbuf_src->read_position;
129
130
28.7k
  h_bitbuf_dst->read_position = temp322;
131
28.7k
  h_bitbuf_src->read_position = temp321;
132
133
28.7k
  temp321 = h_bitbuf_dst->write_position;
134
28.7k
  temp322 = h_bitbuf_src->write_position;
135
136
28.7k
  h_bitbuf_dst->write_position = temp322;
137
28.7k
  h_bitbuf_src->write_position = temp321;
138
139
28.7k
  temp321 = h_bitbuf_dst->cnt_bits;
140
28.7k
  temp322 = h_bitbuf_src->cnt_bits;
141
142
28.7k
  h_bitbuf_dst->cnt_bits = temp322;
143
28.7k
  h_bitbuf_src->cnt_bits = temp321;
144
28.7k
}
145
146
VOID ia_enhaacplus_enc_copy_bitbuf(ixheaace_bit_buf_handle h_bitbuf_src,
147
308
                                   ixheaace_bit_buf_handle h_bitbuf_dst) {
148
308
  WORD32 i;
149
308
  WORD32 bytes_to_go_src =
150
308
      (WORD32)(h_bitbuf_src->ptr_bit_buf_end - h_bitbuf_src->ptr_bit_buf_base);
151
152
78.8k
  for (i = 0; i < bytes_to_go_src; i++) {
153
78.5k
    h_bitbuf_dst->ptr_bit_buf_base[i] = h_bitbuf_src->ptr_bit_buf_base[i];
154
78.5k
  }
155
156
308
  h_bitbuf_dst->ptr_read_next = h_bitbuf_src->ptr_read_next;
157
308
  h_bitbuf_dst->ptr_write_next = h_bitbuf_src->ptr_write_next;
158
159
308
  h_bitbuf_dst->read_position = h_bitbuf_src->read_position;
160
308
  h_bitbuf_dst->write_position = h_bitbuf_src->write_position;
161
162
308
  h_bitbuf_dst->cnt_bits = h_bitbuf_src->cnt_bits;
163
308
}
164
165
4.79M
WORD32 ia_enhaacplus_enc_get_bits_available(ixheaace_bit_buf_handle pstr_bit_buf_handle) {
166
4.79M
  return pstr_bit_buf_handle->cnt_bits;
167
4.79M
}
168
UWORD32
169
1.32M
ixheaace_readbits(ixheaace_bit_buf_handle pstr_bit_buf, UWORD8 no_bits_to_read) {
170
1.32M
  UWORD32 return_value;
171
172
1.32M
  if (no_bits_to_read >= 25) {
173
0
    return 0;
174
0
  }
175
176
1.32M
  pstr_bit_buf->cnt_bits -= no_bits_to_read;
177
1.32M
  pstr_bit_buf->read_position -= no_bits_to_read;
178
179
1.32M
  return_value = (UWORD32)*pstr_bit_buf->ptr_read_next;
180
181
3.66M
  while (pstr_bit_buf->read_position < 0) {
182
2.34M
    pstr_bit_buf->read_position += 8;
183
2.34M
    pstr_bit_buf->ptr_read_next++;
184
185
2.34M
    if (pstr_bit_buf->ptr_read_next > pstr_bit_buf->ptr_bit_buf_end) {
186
146
      pstr_bit_buf->ptr_read_next = pstr_bit_buf->ptr_bit_buf_base;
187
146
    }
188
189
2.34M
    return_value <<= 8;
190
191
2.34M
    return_value |= (UWORD32)*pstr_bit_buf->ptr_read_next;
192
2.34M
  }
193
1.32M
  return_value = return_value << (31 - no_bits_to_read - pstr_bit_buf->read_position) >>
194
1.32M
                 (32 - no_bits_to_read);
195
196
1.32M
  return (return_value);
197
1.32M
}
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
}