xref: /aosp_15_r20/external/libxaac/encoder/ixheaace_dynamic_bits.h (revision 15dc779a375ca8b5125643b829a8aa4b70d7f451)
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 #pragma once
22 #define MAXIMUM_SECTIONS MAXIMUM_GROUPED_SCALE_FACTOR_BAND
23 #define SECT_ESC_VAL_LONG 31
24 #define SECT_ESC_VAL_SHORT 7
25 #define CODE_BCK_BITS 4
26 #define SECT_BITS_LONG 5
27 #define SECT_BITS_SHORT 3
28 
29 typedef enum {
30   SI_ID_BITS = (3),
31   SI_FILL_COUNT_BITS = (4),
32   SI_FILL_ESC_COUNT_BITS = (8),
33   SI_FILL_EXTENTION_BITS = (4),
34   SI_FILL_NIBBLE_BITS = (4),
35   SI_SCE_BITS = (4),
36   SI_CPE_BITS = (5),
37   SI_CPE_MS_MASK_BITS = (2),
38   SI_ICS_INFO_BITS_LONG = (1 + 2 + 1 + 6 + 1),
39   SI_ICS_INFO_BITS_SHORT = (1 + 2 + 1 + 4 + 7),
40   SI_ICS_BITS = (8 + 1 + 1 + 1),
41 } SI_BITS;
42 typedef struct {
43   WORD8 code_book;
44   WORD8 sfb_start;
45   WORD8 sfb_cnt;
46   WORD16 section_bits;
47 } ixheaace_section_info;
48 
49 typedef struct {
50   WORD32 block_type;
51   WORD32 total_groups_cnt;
52   WORD32 sfb_cnt;
53   WORD32 max_sfb_per_grp;
54   WORD32 sfb_per_group;
55   WORD32 num_of_sections;
56   ixheaace_section_info section[MAXIMUM_SECTIONS];
57   WORD32 side_info_bits; /* sectioning bits       */
58   WORD32 huffman_bits;   /* huffman    coded bits */
59   WORD32 scale_fac_bits; /* scalefac   coded bits */
60   WORD32 first_scf;      /* first scf to be coded */
61 } ixheaace_section_data;
62 
63 VOID ia_enhaacplus_enc_bitcount_init(WORD32 *side_info_tab_long, WORD32 *side_info_tab_short);
64 
65 IA_ERRORCODE ia_enhaacplus_enc_dyn_bitcount(
66     const WORD16 *ptr_quant_spec, const UWORD16 *ptr_max_val_in_sfb, const WORD16 *ptr_scale_fac,
67     const WORD32 block_type, const WORD32 sfb_cnt, const WORD32 max_sfb_per_grp,
68     const WORD32 sfb_per_grp, const WORD32 *ptr_sfb_offset,
69     ixheaace_section_data *pstr_section_data, WORD32 *ptr_side_info_tab_long,
70     WORD32 *ptr_side_info_tab_short, ixheaace_huffman_tables *ptr_huffman_tbl,
71     WORD32 *ptr_scratch_buf, WORD32 aot, WORD32 *bit_cnt);
72