Coverage Report

Created: 2026-07-12 08:57

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vlc/modules/packetizer/a52.h
Line
Count
Source
1
/*****************************************************************************
2
 * a52.h
3
 *****************************************************************************
4
 * Copyright (C) 2001-2016 Laurent Aimar
5
 *
6
 * Authors: Stéphane Borel <stef@via.ecp.fr>
7
 *          Christophe Massiot <massiot@via.ecp.fr>
8
 *          Gildas Bazin <gbazin@videolan.org>
9
 *          Laurent Aimar <fenrir@via.ecp.fr>
10
 *          Thomas Guillem <thomas@gllm.fr>
11
 *
12
 * This program is free software; you can redistribute it and/or modify it
13
 * under the terms of the GNU Lesser General Public License as published by
14
 * the Free Software Foundation; either version 2.1 of the License, or
15
 * (at your option) any later version.
16
 *
17
 * This program is distributed in the hope that it will be useful,
18
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20
 * GNU Lesser General Public License for more details.
21
 *
22
 * You should have received a copy of the GNU Lesser General Public License
23
 * along with this program; if not, write to the Free Software Foundation,
24
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
25
 *****************************************************************************/
26
27
#ifndef VLC_A52_H_
28
#define VLC_A52_H_
29
30
#include <stdbit.h>
31
#include <vlc_bits.h>
32
33
/**
34
 * Minimum AC3 header size that vlc_a52_header_Parse needs.
35
 */
36
101M
#define VLC_A52_MIN_HEADER_SIZE  (8)
37
#define VLC_A52_EAC3_BSI_SIZE    ((532 + 7)/8)
38
#define VLC_A52_EAC3_HEADER_SIZE (VLC_A52_EAC3_BSI_SIZE + 2)
39
40
46.4k
#define VLC_A52_PROFILE_EAC3_DEPENDENT 1
41
42
/**
43
 * AC3 header information.
44
 */
45
struct vlc_a52_bitstream_info
46
{
47
    uint8_t i_fscod;
48
    uint8_t i_frmsizcod;
49
    uint8_t i_bsid;
50
    uint8_t i_bsmod;
51
    uint8_t i_acmod;
52
    uint8_t i_lfeon;
53
    union
54
    {
55
        struct {
56
            enum {
57
                EAC3_STRMTYP_INDEPENDENT    = 0,
58
                EAC3_STRMTYP_DEPENDENT      = 1,
59
                EAC3_STRMTYP_AC3_CONVERT    = 2,
60
                EAC3_STRMTYP_RESERVED,
61
            } strmtyp;
62
            uint16_t i_frmsiz;
63
            uint8_t i_fscod2;
64
            uint8_t i_numblkscod;
65
            uint8_t i_substreamid;
66
        } eac3;
67
        struct
68
        {
69
            uint8_t i_dsurmod;
70
        } ac3;
71
    };
72
};
73
74
typedef struct
75
{
76
    bool b_eac3;
77
78
    unsigned int i_channels;
79
    unsigned int i_channels_conf;
80
    unsigned int i_chan_mode;
81
    unsigned int i_rate;
82
    unsigned int i_bitrate;
83
84
    unsigned int i_size;
85
    unsigned int i_samples;
86
87
    struct vlc_a52_bitstream_info bs;
88
89
    uint8_t i_blocks_per_sync_frame;
90
} vlc_a52_header_t;
91
92
/**
93
 * It parse AC3 sync info.
94
 *
95
 * cf. AC3 spec
96
 */
97
static inline int vlc_a52_ParseAc3BitstreamInfo( struct vlc_a52_bitstream_info *bs,
98
                                                 const uint8_t *p_buf, size_t i_buf )
99
4.43M
{
100
4.43M
    bs_t s;
101
4.43M
    bs_init( &s, p_buf, i_buf );
102
103
    /* cf. 5.3.2 */
104
4.43M
    bs->i_fscod = bs_read( &s, 2 );
105
4.43M
    if( bs->i_fscod == 3 )
106
75.2k
        return VLC_EGENERIC;
107
4.36M
    bs->i_frmsizcod = bs_read( &s, 6 );
108
4.36M
    if( bs->i_frmsizcod >= 38 )
109
926k
        return VLC_EGENERIC;
110
3.43M
    bs->i_bsid = bs_read( &s, 5 );
111
3.43M
    bs->i_bsmod = bs_read( &s, 3 );
112
3.43M
    bs->i_acmod = bs_read( &s, 3 );
113
3.43M
    if( ( bs->i_acmod & 0x1 ) && ( bs->i_acmod != 0x1 ) )
114
1.83M
    {
115
        /* if 3 front channels */
116
1.83M
        bs_skip( &s, 2 ); /* i_cmixlev */
117
1.83M
    }
118
3.43M
    if( bs->i_acmod & 0x4 )
119
1.76M
    {
120
        /* if a surround channel exists */
121
1.76M
        bs_skip( &s, 2 ); /* i_surmixlev */
122
1.76M
    }
123
    /* if in 2/0 mode */
124
3.43M
    bs->ac3.i_dsurmod = bs->i_acmod == 0x2 ? bs_read( &s, 2 ) : 0;
125
3.43M
    bs->i_lfeon = bs_read( &s, 1 );
126
127
3.43M
    return VLC_SUCCESS;
128
4.36M
}
es.c:vlc_a52_ParseAc3BitstreamInfo
Line
Count
Source
99
72.3k
{
100
72.3k
    bs_t s;
101
72.3k
    bs_init( &s, p_buf, i_buf );
102
103
    /* cf. 5.3.2 */
104
72.3k
    bs->i_fscod = bs_read( &s, 2 );
105
72.3k
    if( bs->i_fscod == 3 )
106
5.42k
        return VLC_EGENERIC;
107
66.9k
    bs->i_frmsizcod = bs_read( &s, 6 );
108
66.9k
    if( bs->i_frmsizcod >= 38 )
109
26.5k
        return VLC_EGENERIC;
110
40.3k
    bs->i_bsid = bs_read( &s, 5 );
111
40.3k
    bs->i_bsmod = bs_read( &s, 3 );
112
40.3k
    bs->i_acmod = bs_read( &s, 3 );
113
40.3k
    if( ( bs->i_acmod & 0x1 ) && ( bs->i_acmod != 0x1 ) )
114
11.8k
    {
115
        /* if 3 front channels */
116
11.8k
        bs_skip( &s, 2 ); /* i_cmixlev */
117
11.8k
    }
118
40.3k
    if( bs->i_acmod & 0x4 )
119
7.97k
    {
120
        /* if a surround channel exists */
121
7.97k
        bs_skip( &s, 2 ); /* i_surmixlev */
122
7.97k
    }
123
    /* if in 2/0 mode */
124
40.3k
    bs->ac3.i_dsurmod = bs->i_acmod == 0x2 ? bs_read( &s, 2 ) : 0;
125
40.3k
    bs->i_lfeon = bs_read( &s, 1 );
126
127
40.3k
    return VLC_SUCCESS;
128
66.9k
}
a52.c:vlc_a52_ParseAc3BitstreamInfo
Line
Count
Source
99
4.30M
{
100
4.30M
    bs_t s;
101
4.30M
    bs_init( &s, p_buf, i_buf );
102
103
    /* cf. 5.3.2 */
104
4.30M
    bs->i_fscod = bs_read( &s, 2 );
105
4.30M
    if( bs->i_fscod == 3 )
106
66.5k
        return VLC_EGENERIC;
107
4.23M
    bs->i_frmsizcod = bs_read( &s, 6 );
108
4.23M
    if( bs->i_frmsizcod >= 38 )
109
896k
        return VLC_EGENERIC;
110
3.34M
    bs->i_bsid = bs_read( &s, 5 );
111
3.34M
    bs->i_bsmod = bs_read( &s, 3 );
112
3.34M
    bs->i_acmod = bs_read( &s, 3 );
113
3.34M
    if( ( bs->i_acmod & 0x1 ) && ( bs->i_acmod != 0x1 ) )
114
1.81M
    {
115
        /* if 3 front channels */
116
1.81M
        bs_skip( &s, 2 ); /* i_cmixlev */
117
1.81M
    }
118
3.34M
    if( bs->i_acmod & 0x4 )
119
1.75M
    {
120
        /* if a surround channel exists */
121
1.75M
        bs_skip( &s, 2 ); /* i_surmixlev */
122
1.75M
    }
123
    /* if in 2/0 mode */
124
3.34M
    bs->ac3.i_dsurmod = bs->i_acmod == 0x2 ? bs_read( &s, 2 ) : 0;
125
3.34M
    bs->i_lfeon = bs_read( &s, 1 );
126
127
3.34M
    return VLC_SUCCESS;
128
4.23M
}
mlp.c:vlc_a52_ParseAc3BitstreamInfo
Line
Count
Source
99
58.5k
{
100
58.5k
    bs_t s;
101
58.5k
    bs_init( &s, p_buf, i_buf );
102
103
    /* cf. 5.3.2 */
104
58.5k
    bs->i_fscod = bs_read( &s, 2 );
105
58.5k
    if( bs->i_fscod == 3 )
106
3.31k
        return VLC_EGENERIC;
107
55.2k
    bs->i_frmsizcod = bs_read( &s, 6 );
108
55.2k
    if( bs->i_frmsizcod >= 38 )
109
3.96k
        return VLC_EGENERIC;
110
51.2k
    bs->i_bsid = bs_read( &s, 5 );
111
51.2k
    bs->i_bsmod = bs_read( &s, 3 );
112
51.2k
    bs->i_acmod = bs_read( &s, 3 );
113
51.2k
    if( ( bs->i_acmod & 0x1 ) && ( bs->i_acmod != 0x1 ) )
114
6.84k
    {
115
        /* if 3 front channels */
116
6.84k
        bs_skip( &s, 2 ); /* i_cmixlev */
117
6.84k
    }
118
51.2k
    if( bs->i_acmod & 0x4 )
119
3.07k
    {
120
        /* if a surround channel exists */
121
3.07k
        bs_skip( &s, 2 ); /* i_surmixlev */
122
3.07k
    }
123
    /* if in 2/0 mode */
124
51.2k
    bs->ac3.i_dsurmod = bs->i_acmod == 0x2 ? bs_read( &s, 2 ) : 0;
125
51.2k
    bs->i_lfeon = bs_read( &s, 1 );
126
127
51.2k
    return VLC_SUCCESS;
128
55.2k
}
129
130
static inline int vlc_a52_header_ParseAc3( vlc_a52_header_t *p_header,
131
                                           const uint8_t *p_buf,
132
                                           const uint32_t *p_acmod,
133
                                           const unsigned *pi_fscod_samplerates )
134
4.43M
{
135
4.43M
    if( vlc_a52_ParseAc3BitstreamInfo( &p_header->bs,
136
4.43M
                                       &p_buf[4], /* start code + CRC */
137
4.43M
                                       VLC_A52_MIN_HEADER_SIZE - 4 ) != VLC_SUCCESS )
138
1.00M
        return VLC_EGENERIC;
139
140
    /* cf. Table 5.18 Frame Size Code Table */
141
3.43M
    static const uint16_t ppi_frmsizcod_fscod_sizes[][3] = {
142
        /* 32K, 44.1K, 48K */
143
3.43M
        { 96, 69, 64 },
144
3.43M
        { 96, 70, 64 },
145
3.43M
        { 120, 87, 80 },
146
3.43M
        { 120, 88, 80 },
147
3.43M
        { 144, 104, 96 },
148
3.43M
        { 144, 105, 96 },
149
3.43M
        { 168, 121, 112 },
150
3.43M
        { 168, 122, 112 },
151
3.43M
        { 192, 139, 128 },
152
3.43M
        { 192, 140, 128 },
153
3.43M
        { 240, 174, 160 },
154
3.43M
        { 240, 175, 160 },
155
3.43M
        { 288, 208, 192 },
156
3.43M
        { 288, 209, 192 },
157
3.43M
        { 336, 243, 224 },
158
3.43M
        { 336, 244, 224 },
159
3.43M
        { 384, 278, 256 },
160
3.43M
        { 384, 279, 256 },
161
3.43M
        { 480, 348, 320 },
162
3.43M
        { 480, 349, 320 },
163
3.43M
        { 576, 417, 384 },
164
3.43M
        { 576, 418, 384 },
165
3.43M
        { 672, 487, 448 },
166
3.43M
        { 672, 488, 448 },
167
3.43M
        { 768, 557, 512 },
168
3.43M
        { 768, 558, 512 },
169
3.43M
        { 960, 696, 640 },
170
3.43M
        { 960, 697, 640 },
171
3.43M
        { 1152, 835, 768 },
172
3.43M
        { 1152, 836, 768 },
173
3.43M
        { 1344, 975, 896 },
174
3.43M
        { 1344, 976, 896 },
175
3.43M
        { 1536, 1114, 1024 },
176
3.43M
        { 1536, 1115, 1024 },
177
3.43M
        { 1728, 1253, 1152 },
178
3.43M
        { 1728, 1254, 1152 },
179
3.43M
        { 1920, 1393, 1280 },
180
3.43M
        { 1920, 1394, 1280 }
181
3.43M
    };
182
3.43M
    static const uint16_t pi_frmsizcod_bitrates[] = {
183
3.43M
        32,  40,  48,  56,
184
3.43M
        64,  80,  96, 112,
185
3.43M
        128, 160, 192, 224,
186
3.43M
        256, 320, 384, 448,
187
3.43M
        512, 576, 640
188
3.43M
    };
189
190
3.43M
    const struct vlc_a52_bitstream_info *bs = &p_header->bs;
191
192
3.43M
    p_header->i_channels_conf = p_acmod[bs->i_acmod];
193
3.43M
    p_header->i_chan_mode = 0;
194
3.43M
    if( bs->ac3.i_dsurmod == 2 )
195
1.17M
        p_header->i_chan_mode |= AOUT_CHANMODE_DOLBYSTEREO;
196
3.43M
    if( bs->i_acmod == 0 )
197
317k
        p_header->i_chan_mode |= AOUT_CHANMODE_DUALMONO;
198
199
3.43M
    if( bs->i_lfeon )
200
3.05M
        p_header->i_channels_conf |= AOUT_CHAN_LFE;
201
202
3.43M
    p_header->i_channels = stdc_count_ones(p_header->i_channels_conf);
203
204
3.43M
    const unsigned i_rate_shift = VLC_CLIP(bs->i_bsid, 8, 11) - 8;
205
3.43M
    p_header->i_bitrate = (pi_frmsizcod_bitrates[bs->i_frmsizcod >> 1] * 1000)
206
3.43M
                        >> i_rate_shift;
207
3.43M
    p_header->i_rate = pi_fscod_samplerates[bs->i_fscod] >> i_rate_shift;
208
209
3.43M
    p_header->i_size = ppi_frmsizcod_fscod_sizes[bs->i_frmsizcod]
210
3.43M
                                                [2 - bs->i_fscod] * 2;
211
3.43M
    p_header->i_blocks_per_sync_frame = 6;
212
3.43M
    p_header->i_samples = p_header->i_blocks_per_sync_frame * 256;
213
214
3.43M
    p_header->b_eac3 = false;
215
3.43M
    return VLC_SUCCESS;
216
4.43M
}
es.c:vlc_a52_header_ParseAc3
Line
Count
Source
134
72.3k
{
135
72.3k
    if( vlc_a52_ParseAc3BitstreamInfo( &p_header->bs,
136
72.3k
                                       &p_buf[4], /* start code + CRC */
137
72.3k
                                       VLC_A52_MIN_HEADER_SIZE - 4 ) != VLC_SUCCESS )
138
31.9k
        return VLC_EGENERIC;
139
140
    /* cf. Table 5.18 Frame Size Code Table */
141
40.3k
    static const uint16_t ppi_frmsizcod_fscod_sizes[][3] = {
142
        /* 32K, 44.1K, 48K */
143
40.3k
        { 96, 69, 64 },
144
40.3k
        { 96, 70, 64 },
145
40.3k
        { 120, 87, 80 },
146
40.3k
        { 120, 88, 80 },
147
40.3k
        { 144, 104, 96 },
148
40.3k
        { 144, 105, 96 },
149
40.3k
        { 168, 121, 112 },
150
40.3k
        { 168, 122, 112 },
151
40.3k
        { 192, 139, 128 },
152
40.3k
        { 192, 140, 128 },
153
40.3k
        { 240, 174, 160 },
154
40.3k
        { 240, 175, 160 },
155
40.3k
        { 288, 208, 192 },
156
40.3k
        { 288, 209, 192 },
157
40.3k
        { 336, 243, 224 },
158
40.3k
        { 336, 244, 224 },
159
40.3k
        { 384, 278, 256 },
160
40.3k
        { 384, 279, 256 },
161
40.3k
        { 480, 348, 320 },
162
40.3k
        { 480, 349, 320 },
163
40.3k
        { 576, 417, 384 },
164
40.3k
        { 576, 418, 384 },
165
40.3k
        { 672, 487, 448 },
166
40.3k
        { 672, 488, 448 },
167
40.3k
        { 768, 557, 512 },
168
40.3k
        { 768, 558, 512 },
169
40.3k
        { 960, 696, 640 },
170
40.3k
        { 960, 697, 640 },
171
40.3k
        { 1152, 835, 768 },
172
40.3k
        { 1152, 836, 768 },
173
40.3k
        { 1344, 975, 896 },
174
40.3k
        { 1344, 976, 896 },
175
40.3k
        { 1536, 1114, 1024 },
176
40.3k
        { 1536, 1115, 1024 },
177
40.3k
        { 1728, 1253, 1152 },
178
40.3k
        { 1728, 1254, 1152 },
179
40.3k
        { 1920, 1393, 1280 },
180
40.3k
        { 1920, 1394, 1280 }
181
40.3k
    };
182
40.3k
    static const uint16_t pi_frmsizcod_bitrates[] = {
183
40.3k
        32,  40,  48,  56,
184
40.3k
        64,  80,  96, 112,
185
40.3k
        128, 160, 192, 224,
186
40.3k
        256, 320, 384, 448,
187
40.3k
        512, 576, 640
188
40.3k
    };
189
190
40.3k
    const struct vlc_a52_bitstream_info *bs = &p_header->bs;
191
192
40.3k
    p_header->i_channels_conf = p_acmod[bs->i_acmod];
193
40.3k
    p_header->i_chan_mode = 0;
194
40.3k
    if( bs->ac3.i_dsurmod == 2 )
195
3.88k
        p_header->i_chan_mode |= AOUT_CHANMODE_DOLBYSTEREO;
196
40.3k
    if( bs->i_acmod == 0 )
197
17.3k
        p_header->i_chan_mode |= AOUT_CHANMODE_DUALMONO;
198
199
40.3k
    if( bs->i_lfeon )
200
17.6k
        p_header->i_channels_conf |= AOUT_CHAN_LFE;
201
202
40.3k
    p_header->i_channels = stdc_count_ones(p_header->i_channels_conf);
203
204
40.3k
    const unsigned i_rate_shift = VLC_CLIP(bs->i_bsid, 8, 11) - 8;
205
40.3k
    p_header->i_bitrate = (pi_frmsizcod_bitrates[bs->i_frmsizcod >> 1] * 1000)
206
40.3k
                        >> i_rate_shift;
207
40.3k
    p_header->i_rate = pi_fscod_samplerates[bs->i_fscod] >> i_rate_shift;
208
209
40.3k
    p_header->i_size = ppi_frmsizcod_fscod_sizes[bs->i_frmsizcod]
210
40.3k
                                                [2 - bs->i_fscod] * 2;
211
40.3k
    p_header->i_blocks_per_sync_frame = 6;
212
40.3k
    p_header->i_samples = p_header->i_blocks_per_sync_frame * 256;
213
214
40.3k
    p_header->b_eac3 = false;
215
40.3k
    return VLC_SUCCESS;
216
72.3k
}
a52.c:vlc_a52_header_ParseAc3
Line
Count
Source
134
4.30M
{
135
4.30M
    if( vlc_a52_ParseAc3BitstreamInfo( &p_header->bs,
136
4.30M
                                       &p_buf[4], /* start code + CRC */
137
4.30M
                                       VLC_A52_MIN_HEADER_SIZE - 4 ) != VLC_SUCCESS )
138
962k
        return VLC_EGENERIC;
139
140
    /* cf. Table 5.18 Frame Size Code Table */
141
3.34M
    static const uint16_t ppi_frmsizcod_fscod_sizes[][3] = {
142
        /* 32K, 44.1K, 48K */
143
3.34M
        { 96, 69, 64 },
144
3.34M
        { 96, 70, 64 },
145
3.34M
        { 120, 87, 80 },
146
3.34M
        { 120, 88, 80 },
147
3.34M
        { 144, 104, 96 },
148
3.34M
        { 144, 105, 96 },
149
3.34M
        { 168, 121, 112 },
150
3.34M
        { 168, 122, 112 },
151
3.34M
        { 192, 139, 128 },
152
3.34M
        { 192, 140, 128 },
153
3.34M
        { 240, 174, 160 },
154
3.34M
        { 240, 175, 160 },
155
3.34M
        { 288, 208, 192 },
156
3.34M
        { 288, 209, 192 },
157
3.34M
        { 336, 243, 224 },
158
3.34M
        { 336, 244, 224 },
159
3.34M
        { 384, 278, 256 },
160
3.34M
        { 384, 279, 256 },
161
3.34M
        { 480, 348, 320 },
162
3.34M
        { 480, 349, 320 },
163
3.34M
        { 576, 417, 384 },
164
3.34M
        { 576, 418, 384 },
165
3.34M
        { 672, 487, 448 },
166
3.34M
        { 672, 488, 448 },
167
3.34M
        { 768, 557, 512 },
168
3.34M
        { 768, 558, 512 },
169
3.34M
        { 960, 696, 640 },
170
3.34M
        { 960, 697, 640 },
171
3.34M
        { 1152, 835, 768 },
172
3.34M
        { 1152, 836, 768 },
173
3.34M
        { 1344, 975, 896 },
174
3.34M
        { 1344, 976, 896 },
175
3.34M
        { 1536, 1114, 1024 },
176
3.34M
        { 1536, 1115, 1024 },
177
3.34M
        { 1728, 1253, 1152 },
178
3.34M
        { 1728, 1254, 1152 },
179
3.34M
        { 1920, 1393, 1280 },
180
3.34M
        { 1920, 1394, 1280 }
181
3.34M
    };
182
3.34M
    static const uint16_t pi_frmsizcod_bitrates[] = {
183
3.34M
        32,  40,  48,  56,
184
3.34M
        64,  80,  96, 112,
185
3.34M
        128, 160, 192, 224,
186
3.34M
        256, 320, 384, 448,
187
3.34M
        512, 576, 640
188
3.34M
    };
189
190
3.34M
    const struct vlc_a52_bitstream_info *bs = &p_header->bs;
191
192
3.34M
    p_header->i_channels_conf = p_acmod[bs->i_acmod];
193
3.34M
    p_header->i_chan_mode = 0;
194
3.34M
    if( bs->ac3.i_dsurmod == 2 )
195
1.17M
        p_header->i_chan_mode |= AOUT_CHANMODE_DOLBYSTEREO;
196
3.34M
    if( bs->i_acmod == 0 )
197
268k
        p_header->i_chan_mode |= AOUT_CHANMODE_DUALMONO;
198
199
3.34M
    if( bs->i_lfeon )
200
3.02M
        p_header->i_channels_conf |= AOUT_CHAN_LFE;
201
202
3.34M
    p_header->i_channels = stdc_count_ones(p_header->i_channels_conf);
203
204
3.34M
    const unsigned i_rate_shift = VLC_CLIP(bs->i_bsid, 8, 11) - 8;
205
3.34M
    p_header->i_bitrate = (pi_frmsizcod_bitrates[bs->i_frmsizcod >> 1] * 1000)
206
3.34M
                        >> i_rate_shift;
207
3.34M
    p_header->i_rate = pi_fscod_samplerates[bs->i_fscod] >> i_rate_shift;
208
209
3.34M
    p_header->i_size = ppi_frmsizcod_fscod_sizes[bs->i_frmsizcod]
210
3.34M
                                                [2 - bs->i_fscod] * 2;
211
3.34M
    p_header->i_blocks_per_sync_frame = 6;
212
3.34M
    p_header->i_samples = p_header->i_blocks_per_sync_frame * 256;
213
214
3.34M
    p_header->b_eac3 = false;
215
3.34M
    return VLC_SUCCESS;
216
4.30M
}
mlp.c:vlc_a52_header_ParseAc3
Line
Count
Source
134
58.5k
{
135
58.5k
    if( vlc_a52_ParseAc3BitstreamInfo( &p_header->bs,
136
58.5k
                                       &p_buf[4], /* start code + CRC */
137
58.5k
                                       VLC_A52_MIN_HEADER_SIZE - 4 ) != VLC_SUCCESS )
138
7.27k
        return VLC_EGENERIC;
139
140
    /* cf. Table 5.18 Frame Size Code Table */
141
51.2k
    static const uint16_t ppi_frmsizcod_fscod_sizes[][3] = {
142
        /* 32K, 44.1K, 48K */
143
51.2k
        { 96, 69, 64 },
144
51.2k
        { 96, 70, 64 },
145
51.2k
        { 120, 87, 80 },
146
51.2k
        { 120, 88, 80 },
147
51.2k
        { 144, 104, 96 },
148
51.2k
        { 144, 105, 96 },
149
51.2k
        { 168, 121, 112 },
150
51.2k
        { 168, 122, 112 },
151
51.2k
        { 192, 139, 128 },
152
51.2k
        { 192, 140, 128 },
153
51.2k
        { 240, 174, 160 },
154
51.2k
        { 240, 175, 160 },
155
51.2k
        { 288, 208, 192 },
156
51.2k
        { 288, 209, 192 },
157
51.2k
        { 336, 243, 224 },
158
51.2k
        { 336, 244, 224 },
159
51.2k
        { 384, 278, 256 },
160
51.2k
        { 384, 279, 256 },
161
51.2k
        { 480, 348, 320 },
162
51.2k
        { 480, 349, 320 },
163
51.2k
        { 576, 417, 384 },
164
51.2k
        { 576, 418, 384 },
165
51.2k
        { 672, 487, 448 },
166
51.2k
        { 672, 488, 448 },
167
51.2k
        { 768, 557, 512 },
168
51.2k
        { 768, 558, 512 },
169
51.2k
        { 960, 696, 640 },
170
51.2k
        { 960, 697, 640 },
171
51.2k
        { 1152, 835, 768 },
172
51.2k
        { 1152, 836, 768 },
173
51.2k
        { 1344, 975, 896 },
174
51.2k
        { 1344, 976, 896 },
175
51.2k
        { 1536, 1114, 1024 },
176
51.2k
        { 1536, 1115, 1024 },
177
51.2k
        { 1728, 1253, 1152 },
178
51.2k
        { 1728, 1254, 1152 },
179
51.2k
        { 1920, 1393, 1280 },
180
51.2k
        { 1920, 1394, 1280 }
181
51.2k
    };
182
51.2k
    static const uint16_t pi_frmsizcod_bitrates[] = {
183
51.2k
        32,  40,  48,  56,
184
51.2k
        64,  80,  96, 112,
185
51.2k
        128, 160, 192, 224,
186
51.2k
        256, 320, 384, 448,
187
51.2k
        512, 576, 640
188
51.2k
    };
189
190
51.2k
    const struct vlc_a52_bitstream_info *bs = &p_header->bs;
191
192
51.2k
    p_header->i_channels_conf = p_acmod[bs->i_acmod];
193
51.2k
    p_header->i_chan_mode = 0;
194
51.2k
    if( bs->ac3.i_dsurmod == 2 )
195
85
        p_header->i_chan_mode |= AOUT_CHANMODE_DOLBYSTEREO;
196
51.2k
    if( bs->i_acmod == 0 )
197
31.4k
        p_header->i_chan_mode |= AOUT_CHANMODE_DUALMONO;
198
199
51.2k
    if( bs->i_lfeon )
200
14.1k
        p_header->i_channels_conf |= AOUT_CHAN_LFE;
201
202
51.2k
    p_header->i_channels = stdc_count_ones(p_header->i_channels_conf);
203
204
51.2k
    const unsigned i_rate_shift = VLC_CLIP(bs->i_bsid, 8, 11) - 8;
205
51.2k
    p_header->i_bitrate = (pi_frmsizcod_bitrates[bs->i_frmsizcod >> 1] * 1000)
206
51.2k
                        >> i_rate_shift;
207
51.2k
    p_header->i_rate = pi_fscod_samplerates[bs->i_fscod] >> i_rate_shift;
208
209
51.2k
    p_header->i_size = ppi_frmsizcod_fscod_sizes[bs->i_frmsizcod]
210
51.2k
                                                [2 - bs->i_fscod] * 2;
211
51.2k
    p_header->i_blocks_per_sync_frame = 6;
212
51.2k
    p_header->i_samples = p_header->i_blocks_per_sync_frame * 256;
213
214
51.2k
    p_header->b_eac3 = false;
215
51.2k
    return VLC_SUCCESS;
216
58.5k
}
217
218
/**
219
 * It parse E-AC3 sync info
220
 */
221
static inline int vlc_a52_ParseEac3BitstreamInfo( struct vlc_a52_bitstream_info *bs,
222
                                                  const uint8_t *p_buf, size_t i_buf )
223
1.94M
{
224
1.94M
    bs_t s;
225
1.94M
    bs_init( &s, p_buf, i_buf );
226
1.94M
    bs->eac3.strmtyp = bs_read( &s, 2 );      /* Stream Type */
227
1.94M
    bs->eac3.i_substreamid = bs_read( &s, 3 );/* Substream Identification */
228
229
1.94M
    bs->eac3.i_frmsiz = bs_read( &s, 11 );
230
1.94M
    if( bs->eac3.i_frmsiz < 2 )
231
24.5k
        return VLC_EGENERIC;
232
233
1.91M
    bs->i_fscod = bs_read( &s, 2 );
234
1.91M
    if( bs->i_fscod == 0x03 )
235
402k
    {
236
402k
        bs->eac3.i_fscod2 = bs_read( &s, 2 );
237
402k
        if( bs->eac3.i_fscod2 == 0x03 )
238
165k
            return VLC_EGENERIC;
239
236k
        bs->eac3.i_numblkscod = 0x03;
240
236k
    }
241
1.51M
    else bs->eac3.i_numblkscod = bs_read( &s, 2 );
242
243
1.75M
    bs->i_acmod = bs_read( &s, 3 );
244
1.75M
    bs->i_lfeon = bs_read1( &s );
245
1.75M
    bs->i_bsid = bs_read( &s, 5 );
246
247
1.75M
    if( i_buf <= VLC_A52_MIN_HEADER_SIZE )
248
1.75M
    {
249
1.75M
        bs->i_bsmod = 0;
250
1.75M
        return VLC_SUCCESS;
251
1.75M
    }
252
253
0
    bs_skip( &s, 5 ); /* dialnorm */
254
0
    if(bs_read1( &s ))
255
0
        bs_skip( &s, 8 ); /* compr */
256
257
0
    if( bs->i_acmod == 0x00 )
258
0
    {
259
0
        bs_skip( &s, 5 );
260
0
        if(bs_read1( &s ))
261
0
            bs_skip( &s, 8 ); /* compr2 */
262
0
    }
263
264
0
    if( bs->eac3.strmtyp == 0x01 && bs_read1( &s ) )
265
0
        bs_skip( &s, 16 ); /* chanmap */
266
267
0
    if( bs_read1( &s ) ) /* mixmdate */
268
0
    {
269
0
        if( bs->i_acmod > 0x02 )
270
0
        {
271
0
            bs_skip( &s, 2 ); /* dmixmod */
272
0
            if( bs->i_acmod & 0x01 )
273
0
                bs_skip( &s, 6 ); /* ltrtcmixlev + lorocmixlev */
274
0
            if( bs->i_acmod & 0x04 )
275
0
                bs_skip( &s, 6 ); /* ltrtsurmixlev + lorosurmixlev */
276
0
        }
277
278
0
        if( bs->i_lfeon && bs_read1( &s ) )
279
0
            bs_skip( &s, 5 ); /* (lfemixlevcode) */
280
281
0
        if( bs->eac3.strmtyp == 0x00 )
282
0
        {
283
0
            if( bs_read1( &s ) )
284
0
                bs_skip( &s, 6 ); /* pgmscl */
285
0
            if( bs->i_acmod == 0x00 && bs_read1( &s ) )
286
0
                bs_skip( &s, 6 ); /* pgmscl2 */
287
0
            if(bs_read1( &s ))
288
0
                bs_skip( &s, 6 ); /* extpgmscl */
289
0
            const uint8_t i_mixdef = bs_read( &s, 2 );
290
0
            if( i_mixdef == 0x01 )
291
0
                bs_skip( &s, 5 ); /* premixcmpsel + drcsrc + premixcmpscl */
292
0
            else if( i_mixdef == 0x02 )
293
0
                bs_skip( &s, 12 ); /* mixdata */
294
0
            else if( i_mixdef == 0x03 )
295
0
            {
296
0
                const unsigned mixdeflen = bs_read( &s, 5 ) + 2;
297
0
                for(size_t i=0; i<mixdeflen; i++)
298
0
                    bs_skip( &s, 8 );
299
0
                bs_align( &s );
300
0
            }
301
0
            if( bs->i_acmod < 0x02 )
302
0
            {
303
0
                if( bs_read1( &s ) )
304
0
                    bs_skip( &s, 14 ); /* panmean + paninfo */
305
0
                if( bs->i_acmod == 0x00 && bs_read1( &s ) )
306
0
                    bs_skip( &s, 14 ); /* panmean2 + paninfo2 */
307
0
            }
308
0
            if( bs_read1( &s ) )
309
0
            {
310
0
                const uint8_t blkspersyncframe[] = { 0+1, 1, 2, 6 };
311
0
                const size_t nb = blkspersyncframe[bs->eac3.i_numblkscod];
312
0
                for(size_t i=0; i<nb; i++)
313
0
                {
314
0
                    if( bs->eac3.i_numblkscod == 0x00 )
315
0
                        bs_skip( &s, 5 ); /* blkmixcfginfo[N] */
316
0
                }
317
0
            }
318
0
        }
319
0
    }
320
321
0
    if( bs_read1( &s ) ) /* infomdate */
322
0
    {
323
0
        bs->i_bsmod = bs_read( &s, 3 );
324
        // ...
325
0
    }
326
0
    else bs->i_bsmod = 0;
327
328
0
    return VLC_SUCCESS;
329
1.75M
}
es.c:vlc_a52_ParseEac3BitstreamInfo
Line
Count
Source
223
298k
{
224
298k
    bs_t s;
225
298k
    bs_init( &s, p_buf, i_buf );
226
298k
    bs->eac3.strmtyp = bs_read( &s, 2 );      /* Stream Type */
227
298k
    bs->eac3.i_substreamid = bs_read( &s, 3 );/* Substream Identification */
228
229
298k
    bs->eac3.i_frmsiz = bs_read( &s, 11 );
230
298k
    if( bs->eac3.i_frmsiz < 2 )
231
2.35k
        return VLC_EGENERIC;
232
233
296k
    bs->i_fscod = bs_read( &s, 2 );
234
296k
    if( bs->i_fscod == 0x03 )
235
62.4k
    {
236
62.4k
        bs->eac3.i_fscod2 = bs_read( &s, 2 );
237
62.4k
        if( bs->eac3.i_fscod2 == 0x03 )
238
42.1k
            return VLC_EGENERIC;
239
20.3k
        bs->eac3.i_numblkscod = 0x03;
240
20.3k
    }
241
233k
    else bs->eac3.i_numblkscod = bs_read( &s, 2 );
242
243
254k
    bs->i_acmod = bs_read( &s, 3 );
244
254k
    bs->i_lfeon = bs_read1( &s );
245
254k
    bs->i_bsid = bs_read( &s, 5 );
246
247
254k
    if( i_buf <= VLC_A52_MIN_HEADER_SIZE )
248
254k
    {
249
254k
        bs->i_bsmod = 0;
250
254k
        return VLC_SUCCESS;
251
254k
    }
252
253
0
    bs_skip( &s, 5 ); /* dialnorm */
254
0
    if(bs_read1( &s ))
255
0
        bs_skip( &s, 8 ); /* compr */
256
257
0
    if( bs->i_acmod == 0x00 )
258
0
    {
259
0
        bs_skip( &s, 5 );
260
0
        if(bs_read1( &s ))
261
0
            bs_skip( &s, 8 ); /* compr2 */
262
0
    }
263
264
0
    if( bs->eac3.strmtyp == 0x01 && bs_read1( &s ) )
265
0
        bs_skip( &s, 16 ); /* chanmap */
266
267
0
    if( bs_read1( &s ) ) /* mixmdate */
268
0
    {
269
0
        if( bs->i_acmod > 0x02 )
270
0
        {
271
0
            bs_skip( &s, 2 ); /* dmixmod */
272
0
            if( bs->i_acmod & 0x01 )
273
0
                bs_skip( &s, 6 ); /* ltrtcmixlev + lorocmixlev */
274
0
            if( bs->i_acmod & 0x04 )
275
0
                bs_skip( &s, 6 ); /* ltrtsurmixlev + lorosurmixlev */
276
0
        }
277
278
0
        if( bs->i_lfeon && bs_read1( &s ) )
279
0
            bs_skip( &s, 5 ); /* (lfemixlevcode) */
280
281
0
        if( bs->eac3.strmtyp == 0x00 )
282
0
        {
283
0
            if( bs_read1( &s ) )
284
0
                bs_skip( &s, 6 ); /* pgmscl */
285
0
            if( bs->i_acmod == 0x00 && bs_read1( &s ) )
286
0
                bs_skip( &s, 6 ); /* pgmscl2 */
287
0
            if(bs_read1( &s ))
288
0
                bs_skip( &s, 6 ); /* extpgmscl */
289
0
            const uint8_t i_mixdef = bs_read( &s, 2 );
290
0
            if( i_mixdef == 0x01 )
291
0
                bs_skip( &s, 5 ); /* premixcmpsel + drcsrc + premixcmpscl */
292
0
            else if( i_mixdef == 0x02 )
293
0
                bs_skip( &s, 12 ); /* mixdata */
294
0
            else if( i_mixdef == 0x03 )
295
0
            {
296
0
                const unsigned mixdeflen = bs_read( &s, 5 ) + 2;
297
0
                for(size_t i=0; i<mixdeflen; i++)
298
0
                    bs_skip( &s, 8 );
299
0
                bs_align( &s );
300
0
            }
301
0
            if( bs->i_acmod < 0x02 )
302
0
            {
303
0
                if( bs_read1( &s ) )
304
0
                    bs_skip( &s, 14 ); /* panmean + paninfo */
305
0
                if( bs->i_acmod == 0x00 && bs_read1( &s ) )
306
0
                    bs_skip( &s, 14 ); /* panmean2 + paninfo2 */
307
0
            }
308
0
            if( bs_read1( &s ) )
309
0
            {
310
0
                const uint8_t blkspersyncframe[] = { 0+1, 1, 2, 6 };
311
0
                const size_t nb = blkspersyncframe[bs->eac3.i_numblkscod];
312
0
                for(size_t i=0; i<nb; i++)
313
0
                {
314
0
                    if( bs->eac3.i_numblkscod == 0x00 )
315
0
                        bs_skip( &s, 5 ); /* blkmixcfginfo[N] */
316
0
                }
317
0
            }
318
0
        }
319
0
    }
320
321
0
    if( bs_read1( &s ) ) /* infomdate */
322
0
    {
323
0
        bs->i_bsmod = bs_read( &s, 3 );
324
        // ...
325
0
    }
326
0
    else bs->i_bsmod = 0;
327
328
0
    return VLC_SUCCESS;
329
254k
}
a52.c:vlc_a52_ParseEac3BitstreamInfo
Line
Count
Source
223
1.58M
{
224
1.58M
    bs_t s;
225
1.58M
    bs_init( &s, p_buf, i_buf );
226
1.58M
    bs->eac3.strmtyp = bs_read( &s, 2 );      /* Stream Type */
227
1.58M
    bs->eac3.i_substreamid = bs_read( &s, 3 );/* Substream Identification */
228
229
1.58M
    bs->eac3.i_frmsiz = bs_read( &s, 11 );
230
1.58M
    if( bs->eac3.i_frmsiz < 2 )
231
20.7k
        return VLC_EGENERIC;
232
233
1.56M
    bs->i_fscod = bs_read( &s, 2 );
234
1.56M
    if( bs->i_fscod == 0x03 )
235
295k
    {
236
295k
        bs->eac3.i_fscod2 = bs_read( &s, 2 );
237
295k
        if( bs->eac3.i_fscod2 == 0x03 )
238
122k
            return VLC_EGENERIC;
239
172k
        bs->eac3.i_numblkscod = 0x03;
240
172k
    }
241
1.27M
    else bs->eac3.i_numblkscod = bs_read( &s, 2 );
242
243
1.44M
    bs->i_acmod = bs_read( &s, 3 );
244
1.44M
    bs->i_lfeon = bs_read1( &s );
245
1.44M
    bs->i_bsid = bs_read( &s, 5 );
246
247
1.44M
    if( i_buf <= VLC_A52_MIN_HEADER_SIZE )
248
1.44M
    {
249
1.44M
        bs->i_bsmod = 0;
250
1.44M
        return VLC_SUCCESS;
251
1.44M
    }
252
253
0
    bs_skip( &s, 5 ); /* dialnorm */
254
0
    if(bs_read1( &s ))
255
0
        bs_skip( &s, 8 ); /* compr */
256
257
0
    if( bs->i_acmod == 0x00 )
258
0
    {
259
0
        bs_skip( &s, 5 );
260
0
        if(bs_read1( &s ))
261
0
            bs_skip( &s, 8 ); /* compr2 */
262
0
    }
263
264
0
    if( bs->eac3.strmtyp == 0x01 && bs_read1( &s ) )
265
0
        bs_skip( &s, 16 ); /* chanmap */
266
267
0
    if( bs_read1( &s ) ) /* mixmdate */
268
0
    {
269
0
        if( bs->i_acmod > 0x02 )
270
0
        {
271
0
            bs_skip( &s, 2 ); /* dmixmod */
272
0
            if( bs->i_acmod & 0x01 )
273
0
                bs_skip( &s, 6 ); /* ltrtcmixlev + lorocmixlev */
274
0
            if( bs->i_acmod & 0x04 )
275
0
                bs_skip( &s, 6 ); /* ltrtsurmixlev + lorosurmixlev */
276
0
        }
277
278
0
        if( bs->i_lfeon && bs_read1( &s ) )
279
0
            bs_skip( &s, 5 ); /* (lfemixlevcode) */
280
281
0
        if( bs->eac3.strmtyp == 0x00 )
282
0
        {
283
0
            if( bs_read1( &s ) )
284
0
                bs_skip( &s, 6 ); /* pgmscl */
285
0
            if( bs->i_acmod == 0x00 && bs_read1( &s ) )
286
0
                bs_skip( &s, 6 ); /* pgmscl2 */
287
0
            if(bs_read1( &s ))
288
0
                bs_skip( &s, 6 ); /* extpgmscl */
289
0
            const uint8_t i_mixdef = bs_read( &s, 2 );
290
0
            if( i_mixdef == 0x01 )
291
0
                bs_skip( &s, 5 ); /* premixcmpsel + drcsrc + premixcmpscl */
292
0
            else if( i_mixdef == 0x02 )
293
0
                bs_skip( &s, 12 ); /* mixdata */
294
0
            else if( i_mixdef == 0x03 )
295
0
            {
296
0
                const unsigned mixdeflen = bs_read( &s, 5 ) + 2;
297
0
                for(size_t i=0; i<mixdeflen; i++)
298
0
                    bs_skip( &s, 8 );
299
0
                bs_align( &s );
300
0
            }
301
0
            if( bs->i_acmod < 0x02 )
302
0
            {
303
0
                if( bs_read1( &s ) )
304
0
                    bs_skip( &s, 14 ); /* panmean + paninfo */
305
0
                if( bs->i_acmod == 0x00 && bs_read1( &s ) )
306
0
                    bs_skip( &s, 14 ); /* panmean2 + paninfo2 */
307
0
            }
308
0
            if( bs_read1( &s ) )
309
0
            {
310
0
                const uint8_t blkspersyncframe[] = { 0+1, 1, 2, 6 };
311
0
                const size_t nb = blkspersyncframe[bs->eac3.i_numblkscod];
312
0
                for(size_t i=0; i<nb; i++)
313
0
                {
314
0
                    if( bs->eac3.i_numblkscod == 0x00 )
315
0
                        bs_skip( &s, 5 ); /* blkmixcfginfo[N] */
316
0
                }
317
0
            }
318
0
        }
319
0
    }
320
321
0
    if( bs_read1( &s ) ) /* infomdate */
322
0
    {
323
0
        bs->i_bsmod = bs_read( &s, 3 );
324
        // ...
325
0
    }
326
0
    else bs->i_bsmod = 0;
327
328
0
    return VLC_SUCCESS;
329
1.44M
}
mlp.c:vlc_a52_ParseEac3BitstreamInfo
Line
Count
Source
223
58.9k
{
224
58.9k
    bs_t s;
225
58.9k
    bs_init( &s, p_buf, i_buf );
226
58.9k
    bs->eac3.strmtyp = bs_read( &s, 2 );      /* Stream Type */
227
58.9k
    bs->eac3.i_substreamid = bs_read( &s, 3 );/* Substream Identification */
228
229
58.9k
    bs->eac3.i_frmsiz = bs_read( &s, 11 );
230
58.9k
    if( bs->eac3.i_frmsiz < 2 )
231
1.51k
        return VLC_EGENERIC;
232
233
57.4k
    bs->i_fscod = bs_read( &s, 2 );
234
57.4k
    if( bs->i_fscod == 0x03 )
235
44.2k
    {
236
44.2k
        bs->eac3.i_fscod2 = bs_read( &s, 2 );
237
44.2k
        if( bs->eac3.i_fscod2 == 0x03 )
238
985
            return VLC_EGENERIC;
239
43.2k
        bs->eac3.i_numblkscod = 0x03;
240
43.2k
    }
241
13.1k
    else bs->eac3.i_numblkscod = bs_read( &s, 2 );
242
243
56.4k
    bs->i_acmod = bs_read( &s, 3 );
244
56.4k
    bs->i_lfeon = bs_read1( &s );
245
56.4k
    bs->i_bsid = bs_read( &s, 5 );
246
247
56.4k
    if( i_buf <= VLC_A52_MIN_HEADER_SIZE )
248
56.4k
    {
249
56.4k
        bs->i_bsmod = 0;
250
56.4k
        return VLC_SUCCESS;
251
56.4k
    }
252
253
0
    bs_skip( &s, 5 ); /* dialnorm */
254
0
    if(bs_read1( &s ))
255
0
        bs_skip( &s, 8 ); /* compr */
256
257
0
    if( bs->i_acmod == 0x00 )
258
0
    {
259
0
        bs_skip( &s, 5 );
260
0
        if(bs_read1( &s ))
261
0
            bs_skip( &s, 8 ); /* compr2 */
262
0
    }
263
264
0
    if( bs->eac3.strmtyp == 0x01 && bs_read1( &s ) )
265
0
        bs_skip( &s, 16 ); /* chanmap */
266
267
0
    if( bs_read1( &s ) ) /* mixmdate */
268
0
    {
269
0
        if( bs->i_acmod > 0x02 )
270
0
        {
271
0
            bs_skip( &s, 2 ); /* dmixmod */
272
0
            if( bs->i_acmod & 0x01 )
273
0
                bs_skip( &s, 6 ); /* ltrtcmixlev + lorocmixlev */
274
0
            if( bs->i_acmod & 0x04 )
275
0
                bs_skip( &s, 6 ); /* ltrtsurmixlev + lorosurmixlev */
276
0
        }
277
278
0
        if( bs->i_lfeon && bs_read1( &s ) )
279
0
            bs_skip( &s, 5 ); /* (lfemixlevcode) */
280
281
0
        if( bs->eac3.strmtyp == 0x00 )
282
0
        {
283
0
            if( bs_read1( &s ) )
284
0
                bs_skip( &s, 6 ); /* pgmscl */
285
0
            if( bs->i_acmod == 0x00 && bs_read1( &s ) )
286
0
                bs_skip( &s, 6 ); /* pgmscl2 */
287
0
            if(bs_read1( &s ))
288
0
                bs_skip( &s, 6 ); /* extpgmscl */
289
0
            const uint8_t i_mixdef = bs_read( &s, 2 );
290
0
            if( i_mixdef == 0x01 )
291
0
                bs_skip( &s, 5 ); /* premixcmpsel + drcsrc + premixcmpscl */
292
0
            else if( i_mixdef == 0x02 )
293
0
                bs_skip( &s, 12 ); /* mixdata */
294
0
            else if( i_mixdef == 0x03 )
295
0
            {
296
0
                const unsigned mixdeflen = bs_read( &s, 5 ) + 2;
297
0
                for(size_t i=0; i<mixdeflen; i++)
298
0
                    bs_skip( &s, 8 );
299
0
                bs_align( &s );
300
0
            }
301
0
            if( bs->i_acmod < 0x02 )
302
0
            {
303
0
                if( bs_read1( &s ) )
304
0
                    bs_skip( &s, 14 ); /* panmean + paninfo */
305
0
                if( bs->i_acmod == 0x00 && bs_read1( &s ) )
306
0
                    bs_skip( &s, 14 ); /* panmean2 + paninfo2 */
307
0
            }
308
0
            if( bs_read1( &s ) )
309
0
            {
310
0
                const uint8_t blkspersyncframe[] = { 0+1, 1, 2, 6 };
311
0
                const size_t nb = blkspersyncframe[bs->eac3.i_numblkscod];
312
0
                for(size_t i=0; i<nb; i++)
313
0
                {
314
0
                    if( bs->eac3.i_numblkscod == 0x00 )
315
0
                        bs_skip( &s, 5 ); /* blkmixcfginfo[N] */
316
0
                }
317
0
            }
318
0
        }
319
0
    }
320
321
0
    if( bs_read1( &s ) ) /* infomdate */
322
0
    {
323
0
        bs->i_bsmod = bs_read( &s, 3 );
324
        // ...
325
0
    }
326
0
    else bs->i_bsmod = 0;
327
328
0
    return VLC_SUCCESS;
329
56.4k
}
330
331
static inline int vlc_a52_header_ParseEac3( vlc_a52_header_t *p_header,
332
                                            const uint8_t *p_buf,
333
                                            const uint32_t *p_acmod,
334
                                            const unsigned *pi_fscod_samplerates )
335
1.94M
{
336
1.94M
    if( vlc_a52_ParseEac3BitstreamInfo( &p_header->bs,
337
1.94M
                                        &p_buf[2], /* start code */
338
1.94M
                                        VLC_A52_MIN_HEADER_SIZE - 2 ) != VLC_SUCCESS )
339
190k
        return VLC_EGENERIC;
340
341
1.75M
    const struct vlc_a52_bitstream_info *bs = &p_header->bs;
342
343
1.75M
    p_header->i_size = 2 * (bs->eac3.i_frmsiz + 1 );
344
345
1.75M
    if( bs->i_fscod == 0x03 )
346
236k
    {
347
236k
        p_header->i_rate = pi_fscod_samplerates[bs->eac3.i_fscod2] / 2;
348
236k
        p_header->i_blocks_per_sync_frame = 6;
349
236k
    }
350
1.51M
    else
351
1.51M
    {
352
1.51M
        static const int pi_numblkscod [4] = { 1, 2, 3, 6 };
353
1.51M
        p_header->i_rate = pi_fscod_samplerates[bs->i_fscod];
354
1.51M
        p_header->i_blocks_per_sync_frame = pi_numblkscod[bs->eac3.i_numblkscod];
355
1.51M
    }
356
357
1.75M
    p_header->i_channels_conf = p_acmod[bs->i_acmod];
358
1.75M
    p_header->i_chan_mode = 0;
359
1.75M
    if( bs->i_acmod == 0 )
360
291k
        p_header->i_chan_mode |= AOUT_CHANMODE_DUALMONO;
361
1.75M
    if( bs->i_lfeon )
362
1.28M
        p_header->i_channels_conf |= AOUT_CHAN_LFE;
363
1.75M
    p_header->i_channels = stdc_count_ones( p_header->i_channels_conf );
364
1.75M
    p_header->i_bitrate = 8 * p_header->i_size * p_header->i_rate
365
1.75M
                        / (p_header->i_blocks_per_sync_frame * 256);
366
1.75M
    p_header->i_samples = p_header->i_blocks_per_sync_frame * 256;
367
368
1.75M
    p_header->b_eac3 = true;
369
1.75M
    return VLC_SUCCESS;
370
1.94M
}
es.c:vlc_a52_header_ParseEac3
Line
Count
Source
335
298k
{
336
298k
    if( vlc_a52_ParseEac3BitstreamInfo( &p_header->bs,
337
298k
                                        &p_buf[2], /* start code */
338
298k
                                        VLC_A52_MIN_HEADER_SIZE - 2 ) != VLC_SUCCESS )
339
44.5k
        return VLC_EGENERIC;
340
341
254k
    const struct vlc_a52_bitstream_info *bs = &p_header->bs;
342
343
254k
    p_header->i_size = 2 * (bs->eac3.i_frmsiz + 1 );
344
345
254k
    if( bs->i_fscod == 0x03 )
346
20.3k
    {
347
20.3k
        p_header->i_rate = pi_fscod_samplerates[bs->eac3.i_fscod2] / 2;
348
20.3k
        p_header->i_blocks_per_sync_frame = 6;
349
20.3k
    }
350
233k
    else
351
233k
    {
352
233k
        static const int pi_numblkscod [4] = { 1, 2, 3, 6 };
353
233k
        p_header->i_rate = pi_fscod_samplerates[bs->i_fscod];
354
233k
        p_header->i_blocks_per_sync_frame = pi_numblkscod[bs->eac3.i_numblkscod];
355
233k
    }
356
357
254k
    p_header->i_channels_conf = p_acmod[bs->i_acmod];
358
254k
    p_header->i_chan_mode = 0;
359
254k
    if( bs->i_acmod == 0 )
360
53.4k
        p_header->i_chan_mode |= AOUT_CHANMODE_DUALMONO;
361
254k
    if( bs->i_lfeon )
362
173k
        p_header->i_channels_conf |= AOUT_CHAN_LFE;
363
254k
    p_header->i_channels = stdc_count_ones( p_header->i_channels_conf );
364
254k
    p_header->i_bitrate = 8 * p_header->i_size * p_header->i_rate
365
254k
                        / (p_header->i_blocks_per_sync_frame * 256);
366
254k
    p_header->i_samples = p_header->i_blocks_per_sync_frame * 256;
367
368
254k
    p_header->b_eac3 = true;
369
254k
    return VLC_SUCCESS;
370
298k
}
a52.c:vlc_a52_header_ParseEac3
Line
Count
Source
335
1.58M
{
336
1.58M
    if( vlc_a52_ParseEac3BitstreamInfo( &p_header->bs,
337
1.58M
                                        &p_buf[2], /* start code */
338
1.58M
                                        VLC_A52_MIN_HEADER_SIZE - 2 ) != VLC_SUCCESS )
339
143k
        return VLC_EGENERIC;
340
341
1.44M
    const struct vlc_a52_bitstream_info *bs = &p_header->bs;
342
343
1.44M
    p_header->i_size = 2 * (bs->eac3.i_frmsiz + 1 );
344
345
1.44M
    if( bs->i_fscod == 0x03 )
346
172k
    {
347
172k
        p_header->i_rate = pi_fscod_samplerates[bs->eac3.i_fscod2] / 2;
348
172k
        p_header->i_blocks_per_sync_frame = 6;
349
172k
    }
350
1.27M
    else
351
1.27M
    {
352
1.27M
        static const int pi_numblkscod [4] = { 1, 2, 3, 6 };
353
1.27M
        p_header->i_rate = pi_fscod_samplerates[bs->i_fscod];
354
1.27M
        p_header->i_blocks_per_sync_frame = pi_numblkscod[bs->eac3.i_numblkscod];
355
1.27M
    }
356
357
1.44M
    p_header->i_channels_conf = p_acmod[bs->i_acmod];
358
1.44M
    p_header->i_chan_mode = 0;
359
1.44M
    if( bs->i_acmod == 0 )
360
235k
        p_header->i_chan_mode |= AOUT_CHANMODE_DUALMONO;
361
1.44M
    if( bs->i_lfeon )
362
1.05M
        p_header->i_channels_conf |= AOUT_CHAN_LFE;
363
1.44M
    p_header->i_channels = stdc_count_ones( p_header->i_channels_conf );
364
1.44M
    p_header->i_bitrate = 8 * p_header->i_size * p_header->i_rate
365
1.44M
                        / (p_header->i_blocks_per_sync_frame * 256);
366
1.44M
    p_header->i_samples = p_header->i_blocks_per_sync_frame * 256;
367
368
1.44M
    p_header->b_eac3 = true;
369
1.44M
    return VLC_SUCCESS;
370
1.58M
}
mlp.c:vlc_a52_header_ParseEac3
Line
Count
Source
335
58.9k
{
336
58.9k
    if( vlc_a52_ParseEac3BitstreamInfo( &p_header->bs,
337
58.9k
                                        &p_buf[2], /* start code */
338
58.9k
                                        VLC_A52_MIN_HEADER_SIZE - 2 ) != VLC_SUCCESS )
339
2.49k
        return VLC_EGENERIC;
340
341
56.4k
    const struct vlc_a52_bitstream_info *bs = &p_header->bs;
342
343
56.4k
    p_header->i_size = 2 * (bs->eac3.i_frmsiz + 1 );
344
345
56.4k
    if( bs->i_fscod == 0x03 )
346
43.2k
    {
347
43.2k
        p_header->i_rate = pi_fscod_samplerates[bs->eac3.i_fscod2] / 2;
348
43.2k
        p_header->i_blocks_per_sync_frame = 6;
349
43.2k
    }
350
13.1k
    else
351
13.1k
    {
352
13.1k
        static const int pi_numblkscod [4] = { 1, 2, 3, 6 };
353
13.1k
        p_header->i_rate = pi_fscod_samplerates[bs->i_fscod];
354
13.1k
        p_header->i_blocks_per_sync_frame = pi_numblkscod[bs->eac3.i_numblkscod];
355
13.1k
    }
356
357
56.4k
    p_header->i_channels_conf = p_acmod[bs->i_acmod];
358
56.4k
    p_header->i_chan_mode = 0;
359
56.4k
    if( bs->i_acmod == 0 )
360
2.99k
        p_header->i_chan_mode |= AOUT_CHANMODE_DUALMONO;
361
56.4k
    if( bs->i_lfeon )
362
53.6k
        p_header->i_channels_conf |= AOUT_CHAN_LFE;
363
56.4k
    p_header->i_channels = stdc_count_ones( p_header->i_channels_conf );
364
56.4k
    p_header->i_bitrate = 8 * p_header->i_size * p_header->i_rate
365
56.4k
                        / (p_header->i_blocks_per_sync_frame * 256);
366
56.4k
    p_header->i_samples = p_header->i_blocks_per_sync_frame * 256;
367
368
56.4k
    p_header->b_eac3 = true;
369
56.4k
    return VLC_SUCCESS;
370
58.9k
}
371
372
/**
373
 * It will parse the header AC3 frame and fill vlc_a52_header_t* if
374
 * it is valid or return VLC_EGENERIC.
375
 *
376
 * XXX It will only recognize big endian bitstream ie starting with 0x0b, 0x77
377
 */
378
static inline int vlc_a52_header_Parse( vlc_a52_header_t *p_header,
379
                                        const uint8_t *p_buffer, int i_buffer )
380
43.7M
{
381
43.7M
    static const uint32_t p_acmod[8] = {
382
43.7M
        AOUT_CHANS_2_0,
383
43.7M
        AOUT_CHAN_CENTER,
384
43.7M
        AOUT_CHANS_2_0,
385
43.7M
        AOUT_CHANS_3_0,
386
43.7M
        AOUT_CHANS_FRONT | AOUT_CHAN_REARCENTER, /* 2F1R */
387
43.7M
        AOUT_CHANS_FRONT | AOUT_CHANS_CENTER,    /* 3F1R */
388
43.7M
        AOUT_CHANS_4_0,
389
43.7M
        AOUT_CHANS_5_0,
390
43.7M
    };
391
43.7M
    static const unsigned pi_fscod_samplerates[] = {
392
43.7M
        48000, 44100, 32000
393
43.7M
    };
394
395
43.7M
    if( i_buffer < VLC_A52_MIN_HEADER_SIZE )
396
0
        return VLC_EGENERIC;
397
398
    /* Check synword */
399
43.7M
    if( p_buffer[0] != 0x0b || p_buffer[1] != 0x77 )
400
37.2M
        return VLC_EGENERIC;
401
402
    /* Check bsid */
403
6.53M
    const int bsid = p_buffer[5] >> 3;
404
405
    /* cf. Annex E 2.3.1.6 of AC3 spec */
406
6.53M
    if( bsid <= 10 )
407
4.43M
        return vlc_a52_header_ParseAc3( p_header, p_buffer,
408
4.43M
                                        p_acmod, pi_fscod_samplerates );
409
2.09M
    else if( bsid <= 16 )
410
1.94M
        return vlc_a52_header_ParseEac3( p_header, p_buffer,
411
1.94M
                                         p_acmod, pi_fscod_samplerates );
412
153k
    else
413
153k
        return VLC_EGENERIC;
414
6.53M
}
es.c:vlc_a52_header_Parse
Line
Count
Source
380
12.4M
{
381
12.4M
    static const uint32_t p_acmod[8] = {
382
12.4M
        AOUT_CHANS_2_0,
383
12.4M
        AOUT_CHAN_CENTER,
384
12.4M
        AOUT_CHANS_2_0,
385
12.4M
        AOUT_CHANS_3_0,
386
12.4M
        AOUT_CHANS_FRONT | AOUT_CHAN_REARCENTER, /* 2F1R */
387
12.4M
        AOUT_CHANS_FRONT | AOUT_CHANS_CENTER,    /* 3F1R */
388
12.4M
        AOUT_CHANS_4_0,
389
12.4M
        AOUT_CHANS_5_0,
390
12.4M
    };
391
12.4M
    static const unsigned pi_fscod_samplerates[] = {
392
12.4M
        48000, 44100, 32000
393
12.4M
    };
394
395
12.4M
    if( i_buffer < VLC_A52_MIN_HEADER_SIZE )
396
0
        return VLC_EGENERIC;
397
398
    /* Check synword */
399
12.4M
    if( p_buffer[0] != 0x0b || p_buffer[1] != 0x77 )
400
12.0M
        return VLC_EGENERIC;
401
402
    /* Check bsid */
403
386k
    const int bsid = p_buffer[5] >> 3;
404
405
    /* cf. Annex E 2.3.1.6 of AC3 spec */
406
386k
    if( bsid <= 10 )
407
72.3k
        return vlc_a52_header_ParseAc3( p_header, p_buffer,
408
72.3k
                                        p_acmod, pi_fscod_samplerates );
409
314k
    else if( bsid <= 16 )
410
298k
        return vlc_a52_header_ParseEac3( p_header, p_buffer,
411
298k
                                         p_acmod, pi_fscod_samplerates );
412
15.7k
    else
413
15.7k
        return VLC_EGENERIC;
414
386k
}
a52.c:vlc_a52_header_Parse
Line
Count
Source
380
9.30M
{
381
9.30M
    static const uint32_t p_acmod[8] = {
382
9.30M
        AOUT_CHANS_2_0,
383
9.30M
        AOUT_CHAN_CENTER,
384
9.30M
        AOUT_CHANS_2_0,
385
9.30M
        AOUT_CHANS_3_0,
386
9.30M
        AOUT_CHANS_FRONT | AOUT_CHAN_REARCENTER, /* 2F1R */
387
9.30M
        AOUT_CHANS_FRONT | AOUT_CHANS_CENTER,    /* 3F1R */
388
9.30M
        AOUT_CHANS_4_0,
389
9.30M
        AOUT_CHANS_5_0,
390
9.30M
    };
391
9.30M
    static const unsigned pi_fscod_samplerates[] = {
392
9.30M
        48000, 44100, 32000
393
9.30M
    };
394
395
9.30M
    if( i_buffer < VLC_A52_MIN_HEADER_SIZE )
396
0
        return VLC_EGENERIC;
397
398
    /* Check synword */
399
9.30M
    if( p_buffer[0] != 0x0b || p_buffer[1] != 0x77 )
400
3.27M
        return VLC_EGENERIC;
401
402
    /* Check bsid */
403
6.02M
    const int bsid = p_buffer[5] >> 3;
404
405
    /* cf. Annex E 2.3.1.6 of AC3 spec */
406
6.02M
    if( bsid <= 10 )
407
4.30M
        return vlc_a52_header_ParseAc3( p_header, p_buffer,
408
4.30M
                                        p_acmod, pi_fscod_samplerates );
409
1.72M
    else if( bsid <= 16 )
410
1.58M
        return vlc_a52_header_ParseEac3( p_header, p_buffer,
411
1.58M
                                         p_acmod, pi_fscod_samplerates );
412
135k
    else
413
135k
        return VLC_EGENERIC;
414
6.02M
}
mlp.c:vlc_a52_header_Parse
Line
Count
Source
380
22.0M
{
381
22.0M
    static const uint32_t p_acmod[8] = {
382
22.0M
        AOUT_CHANS_2_0,
383
22.0M
        AOUT_CHAN_CENTER,
384
22.0M
        AOUT_CHANS_2_0,
385
22.0M
        AOUT_CHANS_3_0,
386
22.0M
        AOUT_CHANS_FRONT | AOUT_CHAN_REARCENTER, /* 2F1R */
387
22.0M
        AOUT_CHANS_FRONT | AOUT_CHANS_CENTER,    /* 3F1R */
388
22.0M
        AOUT_CHANS_4_0,
389
22.0M
        AOUT_CHANS_5_0,
390
22.0M
    };
391
22.0M
    static const unsigned pi_fscod_samplerates[] = {
392
22.0M
        48000, 44100, 32000
393
22.0M
    };
394
395
22.0M
    if( i_buffer < VLC_A52_MIN_HEADER_SIZE )
396
0
        return VLC_EGENERIC;
397
398
    /* Check synword */
399
22.0M
    if( p_buffer[0] != 0x0b || p_buffer[1] != 0x77 )
400
21.9M
        return VLC_EGENERIC;
401
402
    /* Check bsid */
403
120k
    const int bsid = p_buffer[5] >> 3;
404
405
    /* cf. Annex E 2.3.1.6 of AC3 spec */
406
120k
    if( bsid <= 10 )
407
58.5k
        return vlc_a52_header_ParseAc3( p_header, p_buffer,
408
58.5k
                                        p_acmod, pi_fscod_samplerates );
409
61.7k
    else if( bsid <= 16 )
410
58.9k
        return vlc_a52_header_ParseEac3( p_header, p_buffer,
411
58.9k
                                         p_acmod, pi_fscod_samplerates );
412
2.84k
    else
413
2.84k
        return VLC_EGENERIC;
414
120k
}
415
416
#endif