Coverage Report

Created: 2025-08-24 07:17

/src/libxaac/decoder/ixheaacd_huff_tools.c
Line
Count
Source (jump to first uncovered line)
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 <stdlib.h>
21
#include <stdio.h>
22
23
#include "ixheaac_type_def.h"
24
#include "ixheaacd_interface.h"
25
26
#include "ixheaacd_bitbuffer.h"
27
#include "ixheaacd_info.h"
28
#include "ixheaacd_bitbuffer.h"
29
30
VOID ixheaacd_hufftab(ia_huff_code_book_struct *ptr_huff_code_book,
31
                      const ia_huff_code_word_struct *ptr_huff_code_word,
32
                      const WORD16 *code_book_tbl, const WORD32 *index,
33
                      WORD32 dim, WORD32 lav, WORD32 lav_incr_esc,
34
8.47k
                      WORD32 sign_code_book, UWORD8 max_code_word_len) {
35
8.47k
  WORD32 i, num;
36
37
8.47k
  if (!sign_code_book) {
38
0
    ptr_huff_code_book->huff_mode = lav + 1;
39
0
    ptr_huff_code_book->off = 0;
40
8.47k
  } else {
41
8.47k
    ptr_huff_code_book->huff_mode = 2 * lav + 1;
42
8.47k
    ptr_huff_code_book->off = lav;
43
8.47k
  }
44
8.47k
  num = 1;
45
16.9k
  for (i = 0; i < dim; i++) num *= ptr_huff_code_book->huff_mode;
46
47
8.47k
  ptr_huff_code_book->num = num;
48
8.47k
  ptr_huff_code_book->dim = dim;
49
8.47k
  ptr_huff_code_book->lav = lav;
50
8.47k
  ptr_huff_code_book->lav_incr_esc = lav_incr_esc;
51
8.47k
  ptr_huff_code_book->sign_code_book = sign_code_book;
52
8.47k
  ptr_huff_code_book->pstr_huff_code_word = ptr_huff_code_word;
53
8.47k
  ptr_huff_code_book->code_book_tbl = code_book_tbl;
54
8.47k
  ptr_huff_code_book->idx_tbl = index;
55
8.47k
  ptr_huff_code_book->max_code_word_len = max_code_word_len;
56
8.47k
}
57
58
WORD32 ixheaacd_huff_codeword(
59
    const ia_huff_code_word_struct *ptr_huff_code_word, UWORD16 data_present,
60
    ia_bit_buf_struct *it_bit_buff)
61
62
177k
{
63
177k
  WORD32 i, j;
64
177k
  UWORD32 code_word = 0;
65
177k
  UWORD32 tmp = 0;
66
67
177k
  i = ptr_huff_code_word->len;
68
177k
  if (data_present == 0) {
69
177k
    code_word = ixheaacd_read_bits_buf(it_bit_buff, i);
70
177k
  }
71
72
177k
  if (data_present == 1) {
73
0
    code_word = ixheaacd_read_bits_buf(it_bit_buff, i);
74
0
  }
75
1.77M
  while (code_word != ptr_huff_code_word->code_word) {
76
1.60M
    ptr_huff_code_word++;
77
1.60M
    j = ptr_huff_code_word->len - i;
78
1.60M
    if (j < 0) {
79
0
      return ptr_huff_code_word->index;
80
0
    }
81
82
1.60M
    i += j;
83
1.60M
    code_word <<= j;
84
85
1.60M
    if (data_present == 0) {
86
1.60M
      tmp = ixheaacd_read_bits_buf(it_bit_buff, j);
87
1.60M
    }
88
89
1.60M
    if (data_present == 1) {
90
0
      tmp = ixheaacd_read_bits_buf(it_bit_buff, j);
91
0
    }
92
93
1.60M
    code_word |= tmp;
94
1.60M
  }
95
177k
  return (ptr_huff_code_word->index);
96
177k
}