Coverage Report

Created: 2026-09-01 06:32

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libxaac/encoder/ixheaace_sbr_crc.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 <string.h>
22
23
#include "ixheaac_type_def.h"
24
#include "ixheaac_constants.h"
25
#include "ixheaace_aac_constants.h"
26
#include "ixheaac_basic_ops32.h"
27
#include "ixheaac_basic_ops16.h"
28
#include "ixheaac_basic_ops40.h"
29
30
#include "ixheaace_bitbuffer.h"
31
#include "ixheaace_sbr_def.h"
32
#include "ixheaace_sbr_cmondata.h"
33
#include "ixheaace_sbr_crc.h"
34
#include "ixheaace_common_utils.h"
35
36
static VOID ixheaace_crc_advance(UWORD16 crc_poly, UWORD16 crc_mask, UWORD16 *ptr_crc,
37
0
                                 UWORD32 b_value, WORD32 b_bits) {
38
0
  WORD32 i = b_bits - 1;
39
40
0
  while (i >= 0) {
41
0
    UWORD16 flag = (*ptr_crc) & crc_mask ? 1 : 0;
42
43
0
    flag ^= (b_value & (1 << i) ? 1 : 0);
44
45
0
    (*ptr_crc) <<= 1;
46
47
0
    if (flag) {
48
0
      (*ptr_crc) ^= crc_poly;
49
0
    }
50
0
    i--;
51
0
  }
52
0
}
53
54
VOID ixheaace_init_sbr_bitstream(ixheaace_pstr_common_data pstr_cmon_data,
55
                                 UWORD8 *ptr_memory_base, WORD32 memory_size, WORD32 crc_active,
56
424k
                                 ixheaace_sbr_codec_type sbr_codec) {
57
424k
  ixheaace_reset_bitbuf(&pstr_cmon_data->str_sbr_bit_buf, ptr_memory_base, memory_size);
58
59
424k
  pstr_cmon_data->str_tmp_write_bit_buf = pstr_cmon_data->str_sbr_bit_buf;
60
424k
  if (HEAAC_SBR == sbr_codec) {
61
138k
    ixheaace_write_bits(&pstr_cmon_data->str_sbr_bit_buf, 0, SI_FILL_EXTENTION_BITS);
62
63
138k
    if (crc_active) {
64
0
      ixheaace_write_bits(&pstr_cmon_data->str_sbr_bit_buf, 0, SI_CRC_BITS_SBR);
65
0
    }
66
138k
  }
67
424k
}
68
69
VOID ixheaace_assemble_sbr_bitstream(ixheaace_pstr_common_data pstr_cmon_data,
70
413k
                                     ixheaace_sbr_codec_type sbr_codec) {
71
413k
  UWORD16 crc_reg = CRCINIT_SBR;
72
413k
  WORD32 num_crc_bits, i;
73
413k
  WORD32 sbr_load = 0;
74
75
413k
  sbr_load = pstr_cmon_data->sbr_hdr_bits + pstr_cmon_data->sbr_data_bits;
76
77
413k
  if (HEAAC_SBR == sbr_codec) {
78
138k
    sbr_load += SI_FILL_EXTENTION_BITS;
79
138k
  }
80
81
413k
  if (pstr_cmon_data->sbr_crc_len) {
82
0
    sbr_load += SI_CRC_BITS_SBR;
83
0
  }
84
85
413k
  if (USAC_SBR != sbr_codec) {
86
211k
    pstr_cmon_data->sbr_fill_bits = (8 - (sbr_load) % 8) % 8;
87
88
211k
    ixheaace_write_bits(&pstr_cmon_data->str_sbr_bit_buf, 0,
89
211k
                        (UWORD8)pstr_cmon_data->sbr_fill_bits);
90
211k
  }
91
413k
  if (pstr_cmon_data->sbr_crc_len) {
92
0
    ixheaace_bit_buf tmp_crc_buf = pstr_cmon_data->str_sbr_bit_buf;
93
94
0
    ixheaace_readbits(&tmp_crc_buf, SI_FILL_EXTENTION_BITS);
95
96
0
    ixheaace_readbits(&tmp_crc_buf, SI_CRC_BITS_SBR);
97
98
0
    num_crc_bits = pstr_cmon_data->sbr_hdr_bits + pstr_cmon_data->sbr_data_bits +
99
0
                   pstr_cmon_data->sbr_fill_bits;
100
101
0
    i = 0;
102
0
    while (i < num_crc_bits) {
103
0
      UWORD32 bit;
104
105
0
      bit = ixheaace_readbits(&tmp_crc_buf, 1);
106
107
0
      ixheaace_crc_advance(CRC_POLYNOMIAL_SBR, CRC_MASK_SBR, &crc_reg, bit, 1);
108
109
0
      i++;
110
0
    }
111
112
0
    crc_reg &= (CRC_RANGE_SBR);
113
0
  }
114
115
413k
  if (pstr_cmon_data->sbr_crc_len) {
116
0
    ixheaace_write_bits(&pstr_cmon_data->str_tmp_write_bit_buf, SI_FIL_CRC_SBR,
117
0
                        SI_FILL_EXTENTION_BITS);
118
119
0
    ixheaace_write_bits(&pstr_cmon_data->str_tmp_write_bit_buf, crc_reg, SI_CRC_BITS_SBR);
120
413k
  } else {
121
413k
    if (HEAAC_SBR == sbr_codec) {
122
138k
      ixheaace_write_bits(&pstr_cmon_data->str_tmp_write_bit_buf, SI_FIL_SBR,
123
138k
                          SI_FILL_EXTENTION_BITS);
124
138k
    }
125
413k
  }
126
413k
}