Coverage Report

Created: 2026-06-30 07:56

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
122M
#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
48.7k
#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.98M
{
100
4.98M
    bs_t s;
101
4.98M
    bs_init( &s, p_buf, i_buf );
102
103
    /* cf. 5.3.2 */
104
4.98M
    bs->i_fscod = bs_read( &s, 2 );
105
4.98M
    if( bs->i_fscod == 3 )
106
90.8k
        return VLC_EGENERIC;
107
4.88M
    bs->i_frmsizcod = bs_read( &s, 6 );
108
4.88M
    if( bs->i_frmsizcod >= 38 )
109
1.11M
        return VLC_EGENERIC;
110
3.77M
    bs->i_bsid = bs_read( &s, 5 );
111
3.77M
    bs->i_bsmod = bs_read( &s, 3 );
112
3.77M
    bs->i_acmod = bs_read( &s, 3 );
113
3.77M
    if( ( bs->i_acmod & 0x1 ) && ( bs->i_acmod != 0x1 ) )
114
2.06M
    {
115
        /* if 3 front channels */
116
2.06M
        bs_skip( &s, 2 ); /* i_cmixlev */
117
2.06M
    }
118
3.77M
    if( bs->i_acmod & 0x4 )
119
1.98M
    {
120
        /* if a surround channel exists */
121
1.98M
        bs_skip( &s, 2 ); /* i_surmixlev */
122
1.98M
    }
123
    /* if in 2/0 mode */
124
3.77M
    bs->ac3.i_dsurmod = bs->i_acmod == 0x2 ? bs_read( &s, 2 ) : 0;
125
3.77M
    bs->i_lfeon = bs_read( &s, 1 );
126
127
3.77M
    return VLC_SUCCESS;
128
4.88M
}
es.c:vlc_a52_ParseAc3BitstreamInfo
Line
Count
Source
99
85.5k
{
100
85.5k
    bs_t s;
101
85.5k
    bs_init( &s, p_buf, i_buf );
102
103
    /* cf. 5.3.2 */
104
85.5k
    bs->i_fscod = bs_read( &s, 2 );
105
85.5k
    if( bs->i_fscod == 3 )
106
9.50k
        return VLC_EGENERIC;
107
76.0k
    bs->i_frmsizcod = bs_read( &s, 6 );
108
76.0k
    if( bs->i_frmsizcod >= 38 )
109
28.2k
        return VLC_EGENERIC;
110
47.8k
    bs->i_bsid = bs_read( &s, 5 );
111
47.8k
    bs->i_bsmod = bs_read( &s, 3 );
112
47.8k
    bs->i_acmod = bs_read( &s, 3 );
113
47.8k
    if( ( bs->i_acmod & 0x1 ) && ( bs->i_acmod != 0x1 ) )
114
14.9k
    {
115
        /* if 3 front channels */
116
14.9k
        bs_skip( &s, 2 ); /* i_cmixlev */
117
14.9k
    }
118
47.8k
    if( bs->i_acmod & 0x4 )
119
10.0k
    {
120
        /* if a surround channel exists */
121
10.0k
        bs_skip( &s, 2 ); /* i_surmixlev */
122
10.0k
    }
123
    /* if in 2/0 mode */
124
47.8k
    bs->ac3.i_dsurmod = bs->i_acmod == 0x2 ? bs_read( &s, 2 ) : 0;
125
47.8k
    bs->i_lfeon = bs_read( &s, 1 );
126
127
47.8k
    return VLC_SUCCESS;
128
76.0k
}
a52.c:vlc_a52_ParseAc3BitstreamInfo
Line
Count
Source
99
4.82M
{
100
4.82M
    bs_t s;
101
4.82M
    bs_init( &s, p_buf, i_buf );
102
103
    /* cf. 5.3.2 */
104
4.82M
    bs->i_fscod = bs_read( &s, 2 );
105
4.82M
    if( bs->i_fscod == 3 )
106
77.7k
        return VLC_EGENERIC;
107
4.74M
    bs->i_frmsizcod = bs_read( &s, 6 );
108
4.74M
    if( bs->i_frmsizcod >= 38 )
109
1.08M
        return VLC_EGENERIC;
110
3.66M
    bs->i_bsid = bs_read( &s, 5 );
111
3.66M
    bs->i_bsmod = bs_read( &s, 3 );
112
3.66M
    bs->i_acmod = bs_read( &s, 3 );
113
3.66M
    if( ( bs->i_acmod & 0x1 ) && ( bs->i_acmod != 0x1 ) )
114
2.03M
    {
115
        /* if 3 front channels */
116
2.03M
        bs_skip( &s, 2 ); /* i_cmixlev */
117
2.03M
    }
118
3.66M
    if( bs->i_acmod & 0x4 )
119
1.96M
    {
120
        /* if a surround channel exists */
121
1.96M
        bs_skip( &s, 2 ); /* i_surmixlev */
122
1.96M
    }
123
    /* if in 2/0 mode */
124
3.66M
    bs->ac3.i_dsurmod = bs->i_acmod == 0x2 ? bs_read( &s, 2 ) : 0;
125
3.66M
    bs->i_lfeon = bs_read( &s, 1 );
126
127
3.66M
    return VLC_SUCCESS;
128
4.74M
}
mlp.c:vlc_a52_ParseAc3BitstreamInfo
Line
Count
Source
99
73.1k
{
100
73.1k
    bs_t s;
101
73.1k
    bs_init( &s, p_buf, i_buf );
102
103
    /* cf. 5.3.2 */
104
73.1k
    bs->i_fscod = bs_read( &s, 2 );
105
73.1k
    if( bs->i_fscod == 3 )
106
3.51k
        return VLC_EGENERIC;
107
69.5k
    bs->i_frmsizcod = bs_read( &s, 6 );
108
69.5k
    if( bs->i_frmsizcod >= 38 )
109
5.05k
        return VLC_EGENERIC;
110
64.5k
    bs->i_bsid = bs_read( &s, 5 );
111
64.5k
    bs->i_bsmod = bs_read( &s, 3 );
112
64.5k
    bs->i_acmod = bs_read( &s, 3 );
113
64.5k
    if( ( bs->i_acmod & 0x1 ) && ( bs->i_acmod != 0x1 ) )
114
13.4k
    {
115
        /* if 3 front channels */
116
13.4k
        bs_skip( &s, 2 ); /* i_cmixlev */
117
13.4k
    }
118
64.5k
    if( bs->i_acmod & 0x4 )
119
7.60k
    {
120
        /* if a surround channel exists */
121
7.60k
        bs_skip( &s, 2 ); /* i_surmixlev */
122
7.60k
    }
123
    /* if in 2/0 mode */
124
64.5k
    bs->ac3.i_dsurmod = bs->i_acmod == 0x2 ? bs_read( &s, 2 ) : 0;
125
64.5k
    bs->i_lfeon = bs_read( &s, 1 );
126
127
64.5k
    return VLC_SUCCESS;
128
69.5k
}
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.98M
{
135
4.98M
    if( vlc_a52_ParseAc3BitstreamInfo( &p_header->bs,
136
4.98M
                                       &p_buf[4], /* start code + CRC */
137
4.98M
                                       VLC_A52_MIN_HEADER_SIZE - 4 ) != VLC_SUCCESS )
138
1.20M
        return VLC_EGENERIC;
139
140
    /* cf. Table 5.18 Frame Size Code Table */
141
3.77M
    static const uint16_t ppi_frmsizcod_fscod_sizes[][3] = {
142
        /* 32K, 44.1K, 48K */
143
3.77M
        { 96, 69, 64 },
144
3.77M
        { 96, 70, 64 },
145
3.77M
        { 120, 87, 80 },
146
3.77M
        { 120, 88, 80 },
147
3.77M
        { 144, 104, 96 },
148
3.77M
        { 144, 105, 96 },
149
3.77M
        { 168, 121, 112 },
150
3.77M
        { 168, 122, 112 },
151
3.77M
        { 192, 139, 128 },
152
3.77M
        { 192, 140, 128 },
153
3.77M
        { 240, 174, 160 },
154
3.77M
        { 240, 175, 160 },
155
3.77M
        { 288, 208, 192 },
156
3.77M
        { 288, 209, 192 },
157
3.77M
        { 336, 243, 224 },
158
3.77M
        { 336, 244, 224 },
159
3.77M
        { 384, 278, 256 },
160
3.77M
        { 384, 279, 256 },
161
3.77M
        { 480, 348, 320 },
162
3.77M
        { 480, 349, 320 },
163
3.77M
        { 576, 417, 384 },
164
3.77M
        { 576, 418, 384 },
165
3.77M
        { 672, 487, 448 },
166
3.77M
        { 672, 488, 448 },
167
3.77M
        { 768, 557, 512 },
168
3.77M
        { 768, 558, 512 },
169
3.77M
        { 960, 696, 640 },
170
3.77M
        { 960, 697, 640 },
171
3.77M
        { 1152, 835, 768 },
172
3.77M
        { 1152, 836, 768 },
173
3.77M
        { 1344, 975, 896 },
174
3.77M
        { 1344, 976, 896 },
175
3.77M
        { 1536, 1114, 1024 },
176
3.77M
        { 1536, 1115, 1024 },
177
3.77M
        { 1728, 1253, 1152 },
178
3.77M
        { 1728, 1254, 1152 },
179
3.77M
        { 1920, 1393, 1280 },
180
3.77M
        { 1920, 1394, 1280 }
181
3.77M
    };
182
3.77M
    static const uint16_t pi_frmsizcod_bitrates[] = {
183
3.77M
        32,  40,  48,  56,
184
3.77M
        64,  80,  96, 112,
185
3.77M
        128, 160, 192, 224,
186
3.77M
        256, 320, 384, 448,
187
3.77M
        512, 576, 640
188
3.77M
    };
189
190
3.77M
    const struct vlc_a52_bitstream_info *bs = &p_header->bs;
191
192
3.77M
    p_header->i_channels_conf = p_acmod[bs->i_acmod];
193
3.77M
    p_header->i_chan_mode = 0;
194
3.77M
    if( bs->ac3.i_dsurmod == 2 )
195
1.19M
        p_header->i_chan_mode |= AOUT_CHANMODE_DOLBYSTEREO;
196
3.77M
    if( bs->i_acmod == 0 )
197
359k
        p_header->i_chan_mode |= AOUT_CHANMODE_DUALMONO;
198
199
3.77M
    if( bs->i_lfeon )
200
3.33M
        p_header->i_channels_conf |= AOUT_CHAN_LFE;
201
202
3.77M
    p_header->i_channels = stdc_count_ones(p_header->i_channels_conf);
203
204
3.77M
    const unsigned i_rate_shift = VLC_CLIP(bs->i_bsid, 8, 11) - 8;
205
3.77M
    p_header->i_bitrate = (pi_frmsizcod_bitrates[bs->i_frmsizcod >> 1] * 1000)
206
3.77M
                        >> i_rate_shift;
207
3.77M
    p_header->i_rate = pi_fscod_samplerates[bs->i_fscod] >> i_rate_shift;
208
209
3.77M
    p_header->i_size = ppi_frmsizcod_fscod_sizes[bs->i_frmsizcod]
210
3.77M
                                                [2 - bs->i_fscod] * 2;
211
3.77M
    p_header->i_blocks_per_sync_frame = 6;
212
3.77M
    p_header->i_samples = p_header->i_blocks_per_sync_frame * 256;
213
214
3.77M
    p_header->b_eac3 = false;
215
3.77M
    return VLC_SUCCESS;
216
4.98M
}
es.c:vlc_a52_header_ParseAc3
Line
Count
Source
134
85.5k
{
135
85.5k
    if( vlc_a52_ParseAc3BitstreamInfo( &p_header->bs,
136
85.5k
                                       &p_buf[4], /* start code + CRC */
137
85.5k
                                       VLC_A52_MIN_HEADER_SIZE - 4 ) != VLC_SUCCESS )
138
37.7k
        return VLC_EGENERIC;
139
140
    /* cf. Table 5.18 Frame Size Code Table */
141
47.8k
    static const uint16_t ppi_frmsizcod_fscod_sizes[][3] = {
142
        /* 32K, 44.1K, 48K */
143
47.8k
        { 96, 69, 64 },
144
47.8k
        { 96, 70, 64 },
145
47.8k
        { 120, 87, 80 },
146
47.8k
        { 120, 88, 80 },
147
47.8k
        { 144, 104, 96 },
148
47.8k
        { 144, 105, 96 },
149
47.8k
        { 168, 121, 112 },
150
47.8k
        { 168, 122, 112 },
151
47.8k
        { 192, 139, 128 },
152
47.8k
        { 192, 140, 128 },
153
47.8k
        { 240, 174, 160 },
154
47.8k
        { 240, 175, 160 },
155
47.8k
        { 288, 208, 192 },
156
47.8k
        { 288, 209, 192 },
157
47.8k
        { 336, 243, 224 },
158
47.8k
        { 336, 244, 224 },
159
47.8k
        { 384, 278, 256 },
160
47.8k
        { 384, 279, 256 },
161
47.8k
        { 480, 348, 320 },
162
47.8k
        { 480, 349, 320 },
163
47.8k
        { 576, 417, 384 },
164
47.8k
        { 576, 418, 384 },
165
47.8k
        { 672, 487, 448 },
166
47.8k
        { 672, 488, 448 },
167
47.8k
        { 768, 557, 512 },
168
47.8k
        { 768, 558, 512 },
169
47.8k
        { 960, 696, 640 },
170
47.8k
        { 960, 697, 640 },
171
47.8k
        { 1152, 835, 768 },
172
47.8k
        { 1152, 836, 768 },
173
47.8k
        { 1344, 975, 896 },
174
47.8k
        { 1344, 976, 896 },
175
47.8k
        { 1536, 1114, 1024 },
176
47.8k
        { 1536, 1115, 1024 },
177
47.8k
        { 1728, 1253, 1152 },
178
47.8k
        { 1728, 1254, 1152 },
179
47.8k
        { 1920, 1393, 1280 },
180
47.8k
        { 1920, 1394, 1280 }
181
47.8k
    };
182
47.8k
    static const uint16_t pi_frmsizcod_bitrates[] = {
183
47.8k
        32,  40,  48,  56,
184
47.8k
        64,  80,  96, 112,
185
47.8k
        128, 160, 192, 224,
186
47.8k
        256, 320, 384, 448,
187
47.8k
        512, 576, 640
188
47.8k
    };
189
190
47.8k
    const struct vlc_a52_bitstream_info *bs = &p_header->bs;
191
192
47.8k
    p_header->i_channels_conf = p_acmod[bs->i_acmod];
193
47.8k
    p_header->i_chan_mode = 0;
194
47.8k
    if( bs->ac3.i_dsurmod == 2 )
195
4.33k
        p_header->i_chan_mode |= AOUT_CHANMODE_DOLBYSTEREO;
196
47.8k
    if( bs->i_acmod == 0 )
197
20.1k
        p_header->i_chan_mode |= AOUT_CHANMODE_DUALMONO;
198
199
47.8k
    if( bs->i_lfeon )
200
21.2k
        p_header->i_channels_conf |= AOUT_CHAN_LFE;
201
202
47.8k
    p_header->i_channels = stdc_count_ones(p_header->i_channels_conf);
203
204
47.8k
    const unsigned i_rate_shift = VLC_CLIP(bs->i_bsid, 8, 11) - 8;
205
47.8k
    p_header->i_bitrate = (pi_frmsizcod_bitrates[bs->i_frmsizcod >> 1] * 1000)
206
47.8k
                        >> i_rate_shift;
207
47.8k
    p_header->i_rate = pi_fscod_samplerates[bs->i_fscod] >> i_rate_shift;
208
209
47.8k
    p_header->i_size = ppi_frmsizcod_fscod_sizes[bs->i_frmsizcod]
210
47.8k
                                                [2 - bs->i_fscod] * 2;
211
47.8k
    p_header->i_blocks_per_sync_frame = 6;
212
47.8k
    p_header->i_samples = p_header->i_blocks_per_sync_frame * 256;
213
214
47.8k
    p_header->b_eac3 = false;
215
47.8k
    return VLC_SUCCESS;
216
85.5k
}
a52.c:vlc_a52_header_ParseAc3
Line
Count
Source
134
4.82M
{
135
4.82M
    if( vlc_a52_ParseAc3BitstreamInfo( &p_header->bs,
136
4.82M
                                       &p_buf[4], /* start code + CRC */
137
4.82M
                                       VLC_A52_MIN_HEADER_SIZE - 4 ) != VLC_SUCCESS )
138
1.15M
        return VLC_EGENERIC;
139
140
    /* cf. Table 5.18 Frame Size Code Table */
141
3.66M
    static const uint16_t ppi_frmsizcod_fscod_sizes[][3] = {
142
        /* 32K, 44.1K, 48K */
143
3.66M
        { 96, 69, 64 },
144
3.66M
        { 96, 70, 64 },
145
3.66M
        { 120, 87, 80 },
146
3.66M
        { 120, 88, 80 },
147
3.66M
        { 144, 104, 96 },
148
3.66M
        { 144, 105, 96 },
149
3.66M
        { 168, 121, 112 },
150
3.66M
        { 168, 122, 112 },
151
3.66M
        { 192, 139, 128 },
152
3.66M
        { 192, 140, 128 },
153
3.66M
        { 240, 174, 160 },
154
3.66M
        { 240, 175, 160 },
155
3.66M
        { 288, 208, 192 },
156
3.66M
        { 288, 209, 192 },
157
3.66M
        { 336, 243, 224 },
158
3.66M
        { 336, 244, 224 },
159
3.66M
        { 384, 278, 256 },
160
3.66M
        { 384, 279, 256 },
161
3.66M
        { 480, 348, 320 },
162
3.66M
        { 480, 349, 320 },
163
3.66M
        { 576, 417, 384 },
164
3.66M
        { 576, 418, 384 },
165
3.66M
        { 672, 487, 448 },
166
3.66M
        { 672, 488, 448 },
167
3.66M
        { 768, 557, 512 },
168
3.66M
        { 768, 558, 512 },
169
3.66M
        { 960, 696, 640 },
170
3.66M
        { 960, 697, 640 },
171
3.66M
        { 1152, 835, 768 },
172
3.66M
        { 1152, 836, 768 },
173
3.66M
        { 1344, 975, 896 },
174
3.66M
        { 1344, 976, 896 },
175
3.66M
        { 1536, 1114, 1024 },
176
3.66M
        { 1536, 1115, 1024 },
177
3.66M
        { 1728, 1253, 1152 },
178
3.66M
        { 1728, 1254, 1152 },
179
3.66M
        { 1920, 1393, 1280 },
180
3.66M
        { 1920, 1394, 1280 }
181
3.66M
    };
182
3.66M
    static const uint16_t pi_frmsizcod_bitrates[] = {
183
3.66M
        32,  40,  48,  56,
184
3.66M
        64,  80,  96, 112,
185
3.66M
        128, 160, 192, 224,
186
3.66M
        256, 320, 384, 448,
187
3.66M
        512, 576, 640
188
3.66M
    };
189
190
3.66M
    const struct vlc_a52_bitstream_info *bs = &p_header->bs;
191
192
3.66M
    p_header->i_channels_conf = p_acmod[bs->i_acmod];
193
3.66M
    p_header->i_chan_mode = 0;
194
3.66M
    if( bs->ac3.i_dsurmod == 2 )
195
1.19M
        p_header->i_chan_mode |= AOUT_CHANMODE_DOLBYSTEREO;
196
3.66M
    if( bs->i_acmod == 0 )
197
304k
        p_header->i_chan_mode |= AOUT_CHANMODE_DUALMONO;
198
199
3.66M
    if( bs->i_lfeon )
200
3.29M
        p_header->i_channels_conf |= AOUT_CHAN_LFE;
201
202
3.66M
    p_header->i_channels = stdc_count_ones(p_header->i_channels_conf);
203
204
3.66M
    const unsigned i_rate_shift = VLC_CLIP(bs->i_bsid, 8, 11) - 8;
205
3.66M
    p_header->i_bitrate = (pi_frmsizcod_bitrates[bs->i_frmsizcod >> 1] * 1000)
206
3.66M
                        >> i_rate_shift;
207
3.66M
    p_header->i_rate = pi_fscod_samplerates[bs->i_fscod] >> i_rate_shift;
208
209
3.66M
    p_header->i_size = ppi_frmsizcod_fscod_sizes[bs->i_frmsizcod]
210
3.66M
                                                [2 - bs->i_fscod] * 2;
211
3.66M
    p_header->i_blocks_per_sync_frame = 6;
212
3.66M
    p_header->i_samples = p_header->i_blocks_per_sync_frame * 256;
213
214
3.66M
    p_header->b_eac3 = false;
215
3.66M
    return VLC_SUCCESS;
216
4.82M
}
mlp.c:vlc_a52_header_ParseAc3
Line
Count
Source
134
73.1k
{
135
73.1k
    if( vlc_a52_ParseAc3BitstreamInfo( &p_header->bs,
136
73.1k
                                       &p_buf[4], /* start code + CRC */
137
73.1k
                                       VLC_A52_MIN_HEADER_SIZE - 4 ) != VLC_SUCCESS )
138
8.57k
        return VLC_EGENERIC;
139
140
    /* cf. Table 5.18 Frame Size Code Table */
141
64.5k
    static const uint16_t ppi_frmsizcod_fscod_sizes[][3] = {
142
        /* 32K, 44.1K, 48K */
143
64.5k
        { 96, 69, 64 },
144
64.5k
        { 96, 70, 64 },
145
64.5k
        { 120, 87, 80 },
146
64.5k
        { 120, 88, 80 },
147
64.5k
        { 144, 104, 96 },
148
64.5k
        { 144, 105, 96 },
149
64.5k
        { 168, 121, 112 },
150
64.5k
        { 168, 122, 112 },
151
64.5k
        { 192, 139, 128 },
152
64.5k
        { 192, 140, 128 },
153
64.5k
        { 240, 174, 160 },
154
64.5k
        { 240, 175, 160 },
155
64.5k
        { 288, 208, 192 },
156
64.5k
        { 288, 209, 192 },
157
64.5k
        { 336, 243, 224 },
158
64.5k
        { 336, 244, 224 },
159
64.5k
        { 384, 278, 256 },
160
64.5k
        { 384, 279, 256 },
161
64.5k
        { 480, 348, 320 },
162
64.5k
        { 480, 349, 320 },
163
64.5k
        { 576, 417, 384 },
164
64.5k
        { 576, 418, 384 },
165
64.5k
        { 672, 487, 448 },
166
64.5k
        { 672, 488, 448 },
167
64.5k
        { 768, 557, 512 },
168
64.5k
        { 768, 558, 512 },
169
64.5k
        { 960, 696, 640 },
170
64.5k
        { 960, 697, 640 },
171
64.5k
        { 1152, 835, 768 },
172
64.5k
        { 1152, 836, 768 },
173
64.5k
        { 1344, 975, 896 },
174
64.5k
        { 1344, 976, 896 },
175
64.5k
        { 1536, 1114, 1024 },
176
64.5k
        { 1536, 1115, 1024 },
177
64.5k
        { 1728, 1253, 1152 },
178
64.5k
        { 1728, 1254, 1152 },
179
64.5k
        { 1920, 1393, 1280 },
180
64.5k
        { 1920, 1394, 1280 }
181
64.5k
    };
182
64.5k
    static const uint16_t pi_frmsizcod_bitrates[] = {
183
64.5k
        32,  40,  48,  56,
184
64.5k
        64,  80,  96, 112,
185
64.5k
        128, 160, 192, 224,
186
64.5k
        256, 320, 384, 448,
187
64.5k
        512, 576, 640
188
64.5k
    };
189
190
64.5k
    const struct vlc_a52_bitstream_info *bs = &p_header->bs;
191
192
64.5k
    p_header->i_channels_conf = p_acmod[bs->i_acmod];
193
64.5k
    p_header->i_chan_mode = 0;
194
64.5k
    if( bs->ac3.i_dsurmod == 2 )
195
145
        p_header->i_chan_mode |= AOUT_CHANMODE_DOLBYSTEREO;
196
64.5k
    if( bs->i_acmod == 0 )
197
34.9k
        p_header->i_chan_mode |= AOUT_CHANMODE_DUALMONO;
198
199
64.5k
    if( bs->i_lfeon )
200
18.7k
        p_header->i_channels_conf |= AOUT_CHAN_LFE;
201
202
64.5k
    p_header->i_channels = stdc_count_ones(p_header->i_channels_conf);
203
204
64.5k
    const unsigned i_rate_shift = VLC_CLIP(bs->i_bsid, 8, 11) - 8;
205
64.5k
    p_header->i_bitrate = (pi_frmsizcod_bitrates[bs->i_frmsizcod >> 1] * 1000)
206
64.5k
                        >> i_rate_shift;
207
64.5k
    p_header->i_rate = pi_fscod_samplerates[bs->i_fscod] >> i_rate_shift;
208
209
64.5k
    p_header->i_size = ppi_frmsizcod_fscod_sizes[bs->i_frmsizcod]
210
64.5k
                                                [2 - bs->i_fscod] * 2;
211
64.5k
    p_header->i_blocks_per_sync_frame = 6;
212
64.5k
    p_header->i_samples = p_header->i_blocks_per_sync_frame * 256;
213
214
64.5k
    p_header->b_eac3 = false;
215
64.5k
    return VLC_SUCCESS;
216
73.1k
}
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
3.11M
{
224
3.11M
    bs_t s;
225
3.11M
    bs_init( &s, p_buf, i_buf );
226
3.11M
    bs->eac3.strmtyp = bs_read( &s, 2 );      /* Stream Type */
227
3.11M
    bs->eac3.i_substreamid = bs_read( &s, 3 );/* Substream Identification */
228
229
3.11M
    bs->eac3.i_frmsiz = bs_read( &s, 11 );
230
3.11M
    if( bs->eac3.i_frmsiz < 2 )
231
29.0k
        return VLC_EGENERIC;
232
233
3.08M
    bs->i_fscod = bs_read( &s, 2 );
234
3.08M
    if( bs->i_fscod == 0x03 )
235
603k
    {
236
603k
        bs->eac3.i_fscod2 = bs_read( &s, 2 );
237
603k
        if( bs->eac3.i_fscod2 == 0x03 )
238
195k
            return VLC_EGENERIC;
239
407k
        bs->eac3.i_numblkscod = 0x03;
240
407k
    }
241
2.48M
    else bs->eac3.i_numblkscod = bs_read( &s, 2 );
242
243
2.89M
    bs->i_acmod = bs_read( &s, 3 );
244
2.89M
    bs->i_lfeon = bs_read1( &s );
245
2.89M
    bs->i_bsid = bs_read( &s, 5 );
246
247
2.89M
    if( i_buf <= VLC_A52_MIN_HEADER_SIZE )
248
2.89M
    {
249
2.89M
        bs->i_bsmod = 0;
250
2.89M
        return VLC_SUCCESS;
251
2.89M
    }
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
2.89M
}
es.c:vlc_a52_ParseEac3BitstreamInfo
Line
Count
Source
223
345k
{
224
345k
    bs_t s;
225
345k
    bs_init( &s, p_buf, i_buf );
226
345k
    bs->eac3.strmtyp = bs_read( &s, 2 );      /* Stream Type */
227
345k
    bs->eac3.i_substreamid = bs_read( &s, 3 );/* Substream Identification */
228
229
345k
    bs->eac3.i_frmsiz = bs_read( &s, 11 );
230
345k
    if( bs->eac3.i_frmsiz < 2 )
231
2.99k
        return VLC_EGENERIC;
232
233
342k
    bs->i_fscod = bs_read( &s, 2 );
234
342k
    if( bs->i_fscod == 0x03 )
235
75.8k
    {
236
75.8k
        bs->eac3.i_fscod2 = bs_read( &s, 2 );
237
75.8k
        if( bs->eac3.i_fscod2 == 0x03 )
238
43.8k
            return VLC_EGENERIC;
239
32.0k
        bs->eac3.i_numblkscod = 0x03;
240
32.0k
    }
241
266k
    else bs->eac3.i_numblkscod = bs_read( &s, 2 );
242
243
298k
    bs->i_acmod = bs_read( &s, 3 );
244
298k
    bs->i_lfeon = bs_read1( &s );
245
298k
    bs->i_bsid = bs_read( &s, 5 );
246
247
298k
    if( i_buf <= VLC_A52_MIN_HEADER_SIZE )
248
298k
    {
249
298k
        bs->i_bsmod = 0;
250
298k
        return VLC_SUCCESS;
251
298k
    }
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
298k
}
a52.c:vlc_a52_ParseEac3BitstreamInfo
Line
Count
Source
223
2.26M
{
224
2.26M
    bs_t s;
225
2.26M
    bs_init( &s, p_buf, i_buf );
226
2.26M
    bs->eac3.strmtyp = bs_read( &s, 2 );      /* Stream Type */
227
2.26M
    bs->eac3.i_substreamid = bs_read( &s, 3 );/* Substream Identification */
228
229
2.26M
    bs->eac3.i_frmsiz = bs_read( &s, 11 );
230
2.26M
    if( bs->eac3.i_frmsiz < 2 )
231
24.0k
        return VLC_EGENERIC;
232
233
2.24M
    bs->i_fscod = bs_read( &s, 2 );
234
2.24M
    if( bs->i_fscod == 0x03 )
235
382k
    {
236
382k
        bs->eac3.i_fscod2 = bs_read( &s, 2 );
237
382k
        if( bs->eac3.i_fscod2 == 0x03 )
238
150k
            return VLC_EGENERIC;
239
232k
        bs->eac3.i_numblkscod = 0x03;
240
232k
    }
241
1.86M
    else bs->eac3.i_numblkscod = bs_read( &s, 2 );
242
243
2.09M
    bs->i_acmod = bs_read( &s, 3 );
244
2.09M
    bs->i_lfeon = bs_read1( &s );
245
2.09M
    bs->i_bsid = bs_read( &s, 5 );
246
247
2.09M
    if( i_buf <= VLC_A52_MIN_HEADER_SIZE )
248
2.09M
    {
249
2.09M
        bs->i_bsmod = 0;
250
2.09M
        return VLC_SUCCESS;
251
2.09M
    }
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
2.09M
}
mlp.c:vlc_a52_ParseEac3BitstreamInfo
Line
Count
Source
223
502k
{
224
502k
    bs_t s;
225
502k
    bs_init( &s, p_buf, i_buf );
226
502k
    bs->eac3.strmtyp = bs_read( &s, 2 );      /* Stream Type */
227
502k
    bs->eac3.i_substreamid = bs_read( &s, 3 );/* Substream Identification */
228
229
502k
    bs->eac3.i_frmsiz = bs_read( &s, 11 );
230
502k
    if( bs->eac3.i_frmsiz < 2 )
231
2.05k
        return VLC_EGENERIC;
232
233
500k
    bs->i_fscod = bs_read( &s, 2 );
234
500k
    if( bs->i_fscod == 0x03 )
235
145k
    {
236
145k
        bs->eac3.i_fscod2 = bs_read( &s, 2 );
237
145k
        if( bs->eac3.i_fscod2 == 0x03 )
238
1.65k
            return VLC_EGENERIC;
239
143k
        bs->eac3.i_numblkscod = 0x03;
240
143k
    }
241
354k
    else bs->eac3.i_numblkscod = bs_read( &s, 2 );
242
243
498k
    bs->i_acmod = bs_read( &s, 3 );
244
498k
    bs->i_lfeon = bs_read1( &s );
245
498k
    bs->i_bsid = bs_read( &s, 5 );
246
247
498k
    if( i_buf <= VLC_A52_MIN_HEADER_SIZE )
248
498k
    {
249
498k
        bs->i_bsmod = 0;
250
498k
        return VLC_SUCCESS;
251
498k
    }
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
498k
}
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
3.11M
{
336
3.11M
    if( vlc_a52_ParseEac3BitstreamInfo( &p_header->bs,
337
3.11M
                                        &p_buf[2], /* start code */
338
3.11M
                                        VLC_A52_MIN_HEADER_SIZE - 2 ) != VLC_SUCCESS )
339
224k
        return VLC_EGENERIC;
340
341
2.89M
    const struct vlc_a52_bitstream_info *bs = &p_header->bs;
342
343
2.89M
    p_header->i_size = 2 * (bs->eac3.i_frmsiz + 1 );
344
345
2.89M
    if( bs->i_fscod == 0x03 )
346
407k
    {
347
407k
        p_header->i_rate = pi_fscod_samplerates[bs->eac3.i_fscod2] / 2;
348
407k
        p_header->i_blocks_per_sync_frame = 6;
349
407k
    }
350
2.48M
    else
351
2.48M
    {
352
2.48M
        static const int pi_numblkscod [4] = { 1, 2, 3, 6 };
353
2.48M
        p_header->i_rate = pi_fscod_samplerates[bs->i_fscod];
354
2.48M
        p_header->i_blocks_per_sync_frame = pi_numblkscod[bs->eac3.i_numblkscod];
355
2.48M
    }
356
357
2.89M
    p_header->i_channels_conf = p_acmod[bs->i_acmod];
358
2.89M
    p_header->i_chan_mode = 0;
359
2.89M
    if( bs->i_acmod == 0 )
360
348k
        p_header->i_chan_mode |= AOUT_CHANMODE_DUALMONO;
361
2.89M
    if( bs->i_lfeon )
362
2.21M
        p_header->i_channels_conf |= AOUT_CHAN_LFE;
363
2.89M
    p_header->i_channels = stdc_count_ones( p_header->i_channels_conf );
364
2.89M
    p_header->i_bitrate = 8 * p_header->i_size * p_header->i_rate
365
2.89M
                        / (p_header->i_blocks_per_sync_frame * 256);
366
2.89M
    p_header->i_samples = p_header->i_blocks_per_sync_frame * 256;
367
368
2.89M
    p_header->b_eac3 = true;
369
2.89M
    return VLC_SUCCESS;
370
3.11M
}
es.c:vlc_a52_header_ParseEac3
Line
Count
Source
335
345k
{
336
345k
    if( vlc_a52_ParseEac3BitstreamInfo( &p_header->bs,
337
345k
                                        &p_buf[2], /* start code */
338
345k
                                        VLC_A52_MIN_HEADER_SIZE - 2 ) != VLC_SUCCESS )
339
46.8k
        return VLC_EGENERIC;
340
341
298k
    const struct vlc_a52_bitstream_info *bs = &p_header->bs;
342
343
298k
    p_header->i_size = 2 * (bs->eac3.i_frmsiz + 1 );
344
345
298k
    if( bs->i_fscod == 0x03 )
346
32.0k
    {
347
32.0k
        p_header->i_rate = pi_fscod_samplerates[bs->eac3.i_fscod2] / 2;
348
32.0k
        p_header->i_blocks_per_sync_frame = 6;
349
32.0k
    }
350
266k
    else
351
266k
    {
352
266k
        static const int pi_numblkscod [4] = { 1, 2, 3, 6 };
353
266k
        p_header->i_rate = pi_fscod_samplerates[bs->i_fscod];
354
266k
        p_header->i_blocks_per_sync_frame = pi_numblkscod[bs->eac3.i_numblkscod];
355
266k
    }
356
357
298k
    p_header->i_channels_conf = p_acmod[bs->i_acmod];
358
298k
    p_header->i_chan_mode = 0;
359
298k
    if( bs->i_acmod == 0 )
360
63.1k
        p_header->i_chan_mode |= AOUT_CHANMODE_DUALMONO;
361
298k
    if( bs->i_lfeon )
362
196k
        p_header->i_channels_conf |= AOUT_CHAN_LFE;
363
298k
    p_header->i_channels = stdc_count_ones( p_header->i_channels_conf );
364
298k
    p_header->i_bitrate = 8 * p_header->i_size * p_header->i_rate
365
298k
                        / (p_header->i_blocks_per_sync_frame * 256);
366
298k
    p_header->i_samples = p_header->i_blocks_per_sync_frame * 256;
367
368
298k
    p_header->b_eac3 = true;
369
298k
    return VLC_SUCCESS;
370
345k
}
a52.c:vlc_a52_header_ParseEac3
Line
Count
Source
335
2.26M
{
336
2.26M
    if( vlc_a52_ParseEac3BitstreamInfo( &p_header->bs,
337
2.26M
                                        &p_buf[2], /* start code */
338
2.26M
                                        VLC_A52_MIN_HEADER_SIZE - 2 ) != VLC_SUCCESS )
339
174k
        return VLC_EGENERIC;
340
341
2.09M
    const struct vlc_a52_bitstream_info *bs = &p_header->bs;
342
343
2.09M
    p_header->i_size = 2 * (bs->eac3.i_frmsiz + 1 );
344
345
2.09M
    if( bs->i_fscod == 0x03 )
346
232k
    {
347
232k
        p_header->i_rate = pi_fscod_samplerates[bs->eac3.i_fscod2] / 2;
348
232k
        p_header->i_blocks_per_sync_frame = 6;
349
232k
    }
350
1.86M
    else
351
1.86M
    {
352
1.86M
        static const int pi_numblkscod [4] = { 1, 2, 3, 6 };
353
1.86M
        p_header->i_rate = pi_fscod_samplerates[bs->i_fscod];
354
1.86M
        p_header->i_blocks_per_sync_frame = pi_numblkscod[bs->eac3.i_numblkscod];
355
1.86M
    }
356
357
2.09M
    p_header->i_channels_conf = p_acmod[bs->i_acmod];
358
2.09M
    p_header->i_chan_mode = 0;
359
2.09M
    if( bs->i_acmod == 0 )
360
279k
        p_header->i_chan_mode |= AOUT_CHANMODE_DUALMONO;
361
2.09M
    if( bs->i_lfeon )
362
1.60M
        p_header->i_channels_conf |= AOUT_CHAN_LFE;
363
2.09M
    p_header->i_channels = stdc_count_ones( p_header->i_channels_conf );
364
2.09M
    p_header->i_bitrate = 8 * p_header->i_size * p_header->i_rate
365
2.09M
                        / (p_header->i_blocks_per_sync_frame * 256);
366
2.09M
    p_header->i_samples = p_header->i_blocks_per_sync_frame * 256;
367
368
2.09M
    p_header->b_eac3 = true;
369
2.09M
    return VLC_SUCCESS;
370
2.26M
}
mlp.c:vlc_a52_header_ParseEac3
Line
Count
Source
335
502k
{
336
502k
    if( vlc_a52_ParseEac3BitstreamInfo( &p_header->bs,
337
502k
                                        &p_buf[2], /* start code */
338
502k
                                        VLC_A52_MIN_HEADER_SIZE - 2 ) != VLC_SUCCESS )
339
3.70k
        return VLC_EGENERIC;
340
341
498k
    const struct vlc_a52_bitstream_info *bs = &p_header->bs;
342
343
498k
    p_header->i_size = 2 * (bs->eac3.i_frmsiz + 1 );
344
345
498k
    if( bs->i_fscod == 0x03 )
346
143k
    {
347
143k
        p_header->i_rate = pi_fscod_samplerates[bs->eac3.i_fscod2] / 2;
348
143k
        p_header->i_blocks_per_sync_frame = 6;
349
143k
    }
350
354k
    else
351
354k
    {
352
354k
        static const int pi_numblkscod [4] = { 1, 2, 3, 6 };
353
354k
        p_header->i_rate = pi_fscod_samplerates[bs->i_fscod];
354
354k
        p_header->i_blocks_per_sync_frame = pi_numblkscod[bs->eac3.i_numblkscod];
355
354k
    }
356
357
498k
    p_header->i_channels_conf = p_acmod[bs->i_acmod];
358
498k
    p_header->i_chan_mode = 0;
359
498k
    if( bs->i_acmod == 0 )
360
5.46k
        p_header->i_chan_mode |= AOUT_CHANMODE_DUALMONO;
361
498k
    if( bs->i_lfeon )
362
409k
        p_header->i_channels_conf |= AOUT_CHAN_LFE;
363
498k
    p_header->i_channels = stdc_count_ones( p_header->i_channels_conf );
364
498k
    p_header->i_bitrate = 8 * p_header->i_size * p_header->i_rate
365
498k
                        / (p_header->i_blocks_per_sync_frame * 256);
366
498k
    p_header->i_samples = p_header->i_blocks_per_sync_frame * 256;
367
368
498k
    p_header->b_eac3 = true;
369
498k
    return VLC_SUCCESS;
370
502k
}
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
51.8M
{
381
51.8M
    static const uint32_t p_acmod[8] = {
382
51.8M
        AOUT_CHANS_2_0,
383
51.8M
        AOUT_CHAN_CENTER,
384
51.8M
        AOUT_CHANS_2_0,
385
51.8M
        AOUT_CHANS_3_0,
386
51.8M
        AOUT_CHANS_FRONT | AOUT_CHAN_REARCENTER, /* 2F1R */
387
51.8M
        AOUT_CHANS_FRONT | AOUT_CHANS_CENTER,    /* 3F1R */
388
51.8M
        AOUT_CHANS_4_0,
389
51.8M
        AOUT_CHANS_5_0,
390
51.8M
    };
391
51.8M
    static const unsigned pi_fscod_samplerates[] = {
392
51.8M
        48000, 44100, 32000
393
51.8M
    };
394
395
51.8M
    if( i_buffer < VLC_A52_MIN_HEADER_SIZE )
396
0
        return VLC_EGENERIC;
397
398
    /* Check synword */
399
51.8M
    if( p_buffer[0] != 0x0b || p_buffer[1] != 0x77 )
400
43.5M
        return VLC_EGENERIC;
401
402
    /* Check bsid */
403
8.29M
    const int bsid = p_buffer[5] >> 3;
404
405
    /* cf. Annex E 2.3.1.6 of AC3 spec */
406
8.29M
    if( bsid <= 10 )
407
4.98M
        return vlc_a52_header_ParseAc3( p_header, p_buffer,
408
4.98M
                                        p_acmod, pi_fscod_samplerates );
409
3.31M
    else if( bsid <= 16 )
410
3.11M
        return vlc_a52_header_ParseEac3( p_header, p_buffer,
411
3.11M
                                         p_acmod, pi_fscod_samplerates );
412
201k
    else
413
201k
        return VLC_EGENERIC;
414
8.29M
}
es.c:vlc_a52_header_Parse
Line
Count
Source
380
15.3M
{
381
15.3M
    static const uint32_t p_acmod[8] = {
382
15.3M
        AOUT_CHANS_2_0,
383
15.3M
        AOUT_CHAN_CENTER,
384
15.3M
        AOUT_CHANS_2_0,
385
15.3M
        AOUT_CHANS_3_0,
386
15.3M
        AOUT_CHANS_FRONT | AOUT_CHAN_REARCENTER, /* 2F1R */
387
15.3M
        AOUT_CHANS_FRONT | AOUT_CHANS_CENTER,    /* 3F1R */
388
15.3M
        AOUT_CHANS_4_0,
389
15.3M
        AOUT_CHANS_5_0,
390
15.3M
    };
391
15.3M
    static const unsigned pi_fscod_samplerates[] = {
392
15.3M
        48000, 44100, 32000
393
15.3M
    };
394
395
15.3M
    if( i_buffer < VLC_A52_MIN_HEADER_SIZE )
396
0
        return VLC_EGENERIC;
397
398
    /* Check synword */
399
15.3M
    if( p_buffer[0] != 0x0b || p_buffer[1] != 0x77 )
400
14.9M
        return VLC_EGENERIC;
401
402
    /* Check bsid */
403
452k
    const int bsid = p_buffer[5] >> 3;
404
405
    /* cf. Annex E 2.3.1.6 of AC3 spec */
406
452k
    if( bsid <= 10 )
407
85.5k
        return vlc_a52_header_ParseAc3( p_header, p_buffer,
408
85.5k
                                        p_acmod, pi_fscod_samplerates );
409
366k
    else if( bsid <= 16 )
410
345k
        return vlc_a52_header_ParseEac3( p_header, p_buffer,
411
345k
                                         p_acmod, pi_fscod_samplerates );
412
21.2k
    else
413
21.2k
        return VLC_EGENERIC;
414
452k
}
a52.c:vlc_a52_header_Parse
Line
Count
Source
380
10.9M
{
381
10.9M
    static const uint32_t p_acmod[8] = {
382
10.9M
        AOUT_CHANS_2_0,
383
10.9M
        AOUT_CHAN_CENTER,
384
10.9M
        AOUT_CHANS_2_0,
385
10.9M
        AOUT_CHANS_3_0,
386
10.9M
        AOUT_CHANS_FRONT | AOUT_CHAN_REARCENTER, /* 2F1R */
387
10.9M
        AOUT_CHANS_FRONT | AOUT_CHANS_CENTER,    /* 3F1R */
388
10.9M
        AOUT_CHANS_4_0,
389
10.9M
        AOUT_CHANS_5_0,
390
10.9M
    };
391
10.9M
    static const unsigned pi_fscod_samplerates[] = {
392
10.9M
        48000, 44100, 32000
393
10.9M
    };
394
395
10.9M
    if( i_buffer < VLC_A52_MIN_HEADER_SIZE )
396
0
        return VLC_EGENERIC;
397
398
    /* Check synword */
399
10.9M
    if( p_buffer[0] != 0x0b || p_buffer[1] != 0x77 )
400
3.70M
        return VLC_EGENERIC;
401
402
    /* Check bsid */
403
7.26M
    const int bsid = p_buffer[5] >> 3;
404
405
    /* cf. Annex E 2.3.1.6 of AC3 spec */
406
7.26M
    if( bsid <= 10 )
407
4.82M
        return vlc_a52_header_ParseAc3( p_header, p_buffer,
408
4.82M
                                        p_acmod, pi_fscod_samplerates );
409
2.44M
    else if( bsid <= 16 )
410
2.26M
        return vlc_a52_header_ParseEac3( p_header, p_buffer,
411
2.26M
                                         p_acmod, pi_fscod_samplerates );
412
175k
    else
413
175k
        return VLC_EGENERIC;
414
7.26M
}
mlp.c:vlc_a52_header_Parse
Line
Count
Source
380
25.5M
{
381
25.5M
    static const uint32_t p_acmod[8] = {
382
25.5M
        AOUT_CHANS_2_0,
383
25.5M
        AOUT_CHAN_CENTER,
384
25.5M
        AOUT_CHANS_2_0,
385
25.5M
        AOUT_CHANS_3_0,
386
25.5M
        AOUT_CHANS_FRONT | AOUT_CHAN_REARCENTER, /* 2F1R */
387
25.5M
        AOUT_CHANS_FRONT | AOUT_CHANS_CENTER,    /* 3F1R */
388
25.5M
        AOUT_CHANS_4_0,
389
25.5M
        AOUT_CHANS_5_0,
390
25.5M
    };
391
25.5M
    static const unsigned pi_fscod_samplerates[] = {
392
25.5M
        48000, 44100, 32000
393
25.5M
    };
394
395
25.5M
    if( i_buffer < VLC_A52_MIN_HEADER_SIZE )
396
0
        return VLC_EGENERIC;
397
398
    /* Check synword */
399
25.5M
    if( p_buffer[0] != 0x0b || p_buffer[1] != 0x77 )
400
24.9M
        return VLC_EGENERIC;
401
402
    /* Check bsid */
403
579k
    const int bsid = p_buffer[5] >> 3;
404
405
    /* cf. Annex E 2.3.1.6 of AC3 spec */
406
579k
    if( bsid <= 10 )
407
73.1k
        return vlc_a52_header_ParseAc3( p_header, p_buffer,
408
73.1k
                                        p_acmod, pi_fscod_samplerates );
409
506k
    else if( bsid <= 16 )
410
502k
        return vlc_a52_header_ParseEac3( p_header, p_buffer,
411
502k
                                         p_acmod, pi_fscod_samplerates );
412
4.52k
    else
413
4.52k
        return VLC_EGENERIC;
414
579k
}
415
416
#endif