Coverage Report

Created: 2026-05-08 06:29

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libxaac/encoder/ixheaace_bitbuffer_hp.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 "ixheaac_type_def.h"
22
#include "ixheaac_constants.h"
23
#include "ixheaace_aac_constants.h"
24
#include <stdlib.h>
25
#include "ixheaac_basic_ops32.h"
26
#include "ixheaac_basic_ops16.h"
27
#include "ixheaac_basic_ops40.h"
28
#include "ixheaac_basic_ops.h"
29
30
#include "ixheaace_bitbuffer.h"
31
#include "ixheaace_common_utils.h"
32
33
UWORD8
34
ixheaace_write_bits(ixheaace_bit_buf_handle pstr_bit_buf, UWORD32 write_value,
35
201M
                    UWORD8 num_bits_to_write) {
36
201M
  WORD8 bits_to_write;
37
201M
  WORD32 write_position;
38
201M
  UWORD8 *ptr_write_next;
39
201M
  UWORD8 *ptr_bit_buf_end;
40
201M
  UWORD8 *ptr_bit_buf_base;
41
42
201M
  UWORD8 bits_written = num_bits_to_write;
43
44
201M
  if (pstr_bit_buf == NULL) {
45
4.05M
    return num_bits_to_write;
46
4.05M
  }
47
48
197M
  pstr_bit_buf->cnt_bits += num_bits_to_write;
49
50
197M
  write_position = pstr_bit_buf->write_position;
51
197M
  ptr_write_next = pstr_bit_buf->ptr_write_next;
52
197M
  ptr_bit_buf_end = pstr_bit_buf->ptr_bit_buf_end;
53
197M
  ptr_bit_buf_base = pstr_bit_buf->ptr_bit_buf_base;
54
55
483M
  while (num_bits_to_write) {
56
286M
    UWORD8 tmp, msk;
57
286M
    bits_to_write = (WORD8)MIN(write_position + 1, num_bits_to_write);
58
59
286M
    tmp = (UWORD8)(write_value << (32 - num_bits_to_write) >>
60
286M
                   (32 - bits_to_write) << (write_position + 1 - bits_to_write));
61
62
286M
    msk = ~(((1 << bits_to_write) - 1) << (write_position + 1 - bits_to_write));
63
64
286M
    *ptr_write_next &= msk;
65
286M
    *ptr_write_next |= tmp;
66
67
286M
    write_position -= bits_to_write;
68
69
286M
    num_bits_to_write -= bits_to_write;
70
71
286M
    if (write_position < 0) {
72
116M
      write_position += 8;
73
116M
      ptr_write_next++;
74
75
116M
      if (ptr_write_next > ptr_bit_buf_end) {
76
23.3k
        ptr_write_next = ptr_bit_buf_base;
77
23.3k
      }
78
116M
    }
79
286M
  }
80
81
197M
  pstr_bit_buf->write_position = write_position;
82
197M
  pstr_bit_buf->ptr_write_next = ptr_write_next;
83
84
197M
  return bits_written;
85
201M
}
86
87
19.4k
UWORD32 ixheaace_byte_align_buffer(ixheaace_bit_buf_handle pstr_it_bit_buff) {
88
19.4k
  WORD alignment;
89
19.4k
  alignment = (WORD)((pstr_it_bit_buff->cnt_bits) & 0x07);
90
91
19.4k
  if (alignment) {
92
13.9k
    ixheaace_write_bits(pstr_it_bit_buff, 0, (UWORD8)(8 - alignment));
93
13.9k
    return (8 - alignment);
94
13.9k
  }
95
5.49k
  return 0;
96
19.4k
}