Coverage Report

Created: 2025-11-24 06:48

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/libxaac/decoder/ixheaacd_sbr_crc.c
Line
Count
Source
1
/******************************************************************************
2
 *                                                                            *
3
 * Copyright (C) 2018 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
#include "ixheaac_type_def.h"
21
22
#include "ixheaacd_bitbuffer.h"
23
#include "ixheaacd_sbr_crc.h"
24
#include "ixheaac_sbr_const.h"
25
26
static VOID ixheaacd_calc_chk_sum(WORD16* crc_state, WORD32 stream_data,
27
1.63M
                                  WORD32 num_bits) {
28
1.63M
  WORD32 i;
29
1.63M
  WORD32 data_bit_mask = (1 << (num_bits - 1));
30
1.63M
  WORD16 crc10 = SBR_CRC_POLY;
31
1.63M
  WORD16 crc_mask = (1 << 9);
32
1.63M
  WORD16 crc_state_local = *crc_state;
33
34
14.6M
  for (i = 0; i < num_bits; i++) {
35
12.9M
    WORD32 bit0, bit1;
36
12.9M
    bit0 = ((crc_state_local & crc_mask) ? 1 : 0);
37
12.9M
    bit1 = ((data_bit_mask & stream_data) ? 1 : 0);
38
12.9M
    bit0 ^= bit1;
39
12.9M
    crc_state_local = (WORD16)((WORD32)(crc_state_local & 0x0000FFFF) << 1);
40
12.9M
    if (bit0) {
41
6.45M
      crc_state_local ^= crc10;
42
6.45M
    }
43
12.9M
    data_bit_mask = (data_bit_mask >> 1);
44
12.9M
  }
45
1.63M
  *crc_state = crc_state_local;
46
1.63M
  return;
47
1.63M
}
48
49
static PLATFORM_INLINE WORD32 ixheaacd_sbr_crc(ia_bit_buf_struct* it_bit_buff,
50
13.6k
                                               WORD32 num_crc_bits) {
51
13.6k
  WORD32 i;
52
13.6k
  WORD32 num_full_bytes, rem_bits;
53
13.6k
  WORD32 byte_value;
54
13.6k
  WORD16 crc_state = 0;
55
56
13.6k
  num_full_bytes = (num_crc_bits >> 3);
57
13.6k
  rem_bits = (num_crc_bits & 0x7);
58
59
1.63M
  for (i = 0; i < num_full_bytes; i++) {
60
1.61M
    byte_value = ixheaacd_read_bits_buf(it_bit_buff, 8);
61
1.61M
    ixheaacd_calc_chk_sum(&crc_state, byte_value, 8);
62
1.61M
  }
63
64
13.6k
  byte_value = ixheaacd_read_bits_buf(it_bit_buff, rem_bits);
65
13.6k
  ixheaacd_calc_chk_sum(&crc_state, byte_value, rem_bits);
66
67
13.6k
  return (crc_state & 0x03FF);
68
13.6k
}
69
70
FLAG ixheaacd_sbr_crccheck(ia_bit_buf_struct* it_bit_buff,
71
13.6k
                           WORD32 crc_bits_len) {
72
13.6k
  struct ia_bit_buf_struct it_bit_buff_local = {0};
73
13.6k
  WORD32 num_crc_bits;
74
13.6k
  WORD32 calc_crc_sum;
75
13.6k
  WORD32 bits_available;
76
13.6k
  WORD32 crc_check_sum;
77
78
13.6k
  crc_check_sum = ixheaacd_read_bits_buf(it_bit_buff, SBR_CYC_REDCY_CHK_BITS);
79
80
13.6k
  it_bit_buff_local = *it_bit_buff;
81
82
13.6k
  bits_available = it_bit_buff->cnt_bits;
83
84
13.6k
  if (bits_available <= 0) {
85
0
    return 0;
86
0
  }
87
88
13.6k
  num_crc_bits =
89
13.6k
      (crc_bits_len > bits_available) ? bits_available : crc_bits_len;
90
91
13.6k
  calc_crc_sum = ixheaacd_sbr_crc(&it_bit_buff_local, num_crc_bits);
92
93
13.6k
  if (calc_crc_sum != crc_check_sum) {
94
13.6k
    return 0;
95
13.6k
  }
96
22
  return 1;
97
13.6k
}