1 /*****************************************************************************
2  * a52.h
3  *****************************************************************************
4  * Copyright (C) 2012-2017 L-SMASH project
5  *
6  * Authors: Yusuke Nakamura <muken.the.vfrmaniac@gmail.com>
7  *
8  * Permission to use, copy, modify, and/or distribute this software for any
9  * purpose with or without fee is hereby granted, provided that the above
10  * copyright notice and this permission notice appear in all copies.
11  *
12  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
13  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
14  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
15  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
16  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
17  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
18  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
19  *****************************************************************************/
20 
21 /* This file is available under an ISC license. */
22 
23 #define AC3_MIN_SYNCFRAME_LENGTH  128
24 #define AC3_MAX_SYNCFRAME_LENGTH  3840
25 #define EAC3_MAX_SYNCFRAME_LENGTH 4096
26 
27 typedef struct
28 {
29     lsmash_ac3_specific_parameters_t dac3_param;
30     lsmash_bits_t *bits;
31 } ac3_info_t;
32 
33 typedef struct
34 {
35     lsmash_eac3_specific_parameters_t dec3_param;
36     lsmash_eac3_substream_info_t independent_info[8];
37     lsmash_eac3_substream_info_t dependent_info;
38     uint8_t  dec3_param_initialized;
39     uint8_t  strmtyp;
40     uint8_t  substreamid;
41     uint8_t  current_independent_substream_id;
42     uint8_t  fscod2;
43     uint8_t  numblkscod;
44     uint8_t  number_of_audio_blocks;
45     uint8_t  number_of_independent_substreams;
46     uint32_t syncframe_count;
47     uint32_t frame_size;
48     lsmash_bits_t *bits;
49 } eac3_info_t;
50 
51 extern const uint32_t ac3_sample_rate_table  [4];
52 extern const uint32_t ac3_channel_count_table[8];
53 extern const uint8_t eac3_audio_block_table  [4];
54 
ac3_get_channel_count(lsmash_ac3_specific_parameters_t * dac3_param)55 static inline uint32_t ac3_get_channel_count
56 (
57     lsmash_ac3_specific_parameters_t *dac3_param
58 )
59 {
60     return ac3_channel_count_table[ dac3_param->acmod ] + dac3_param->lfeon;
61 }
62 
63 uint32_t ac3_get_sample_rate
64 (
65     lsmash_ac3_specific_parameters_t *dac3_param
66 );
67 
68 int ac3_parse_syncframe_header
69 (
70     ac3_info_t *info
71 );
72 
73 int eac3_parse_syncframe
74 (
75     eac3_info_t *info
76 );
77 
78 void eac3_update_specific_param
79 (
80     eac3_info_t *info
81 );
82 
83 void eac3_update_sample_rate
84 (
85     uint32_t                          *frequency,
86     lsmash_eac3_specific_parameters_t *dec3_param,
87     uint8_t                           *fscod2
88 );
89 
90 void eac3_update_channel_count
91 (
92     uint32_t                          *channels,
93     lsmash_eac3_specific_parameters_t *dec3_param
94 );
95