Coverage Report

Created: 2026-08-14 07:16

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
82.6M
#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
47.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
3.55M
{
100
3.55M
    bs_t s;
101
3.55M
    bs_init( &s, p_buf, i_buf );
102
103
    /* cf. 5.3.2 */
104
3.55M
    bs->i_fscod = bs_read( &s, 2 );
105
3.55M
    if( bs->i_fscod == 3 )
106
67.3k
        return VLC_EGENERIC;
107
3.49M
    bs->i_frmsizcod = bs_read( &s, 6 );
108
3.49M
    if( bs->i_frmsizcod >= 38 )
109
720k
        return VLC_EGENERIC;
110
2.77M
    bs->i_bsid = bs_read( &s, 5 );
111
2.77M
    bs->i_bsmod = bs_read( &s, 3 );
112
2.77M
    bs->i_acmod = bs_read( &s, 3 );
113
2.77M
    if( ( bs->i_acmod & 0x1 ) && ( bs->i_acmod != 0x1 ) )
114
1.41M
    {
115
        /* if 3 front channels */
116
1.41M
        bs_skip( &s, 2 ); /* i_cmixlev */
117
1.41M
    }
118
2.77M
    if( bs->i_acmod & 0x4 )
119
1.36M
    {
120
        /* if a surround channel exists */
121
1.36M
        bs_skip( &s, 2 ); /* i_surmixlev */
122
1.36M
    }
123
    /* if in 2/0 mode */
124
2.77M
    bs->ac3.i_dsurmod = bs->i_acmod == 0x2 ? bs_read( &s, 2 ) : 0;
125
2.77M
    bs->i_lfeon = bs_read( &s, 1 );
126
127
2.77M
    return VLC_SUCCESS;
128
3.49M
}
es.c:vlc_a52_ParseAc3BitstreamInfo
Line
Count
Source
99
47.5k
{
100
47.5k
    bs_t s;
101
47.5k
    bs_init( &s, p_buf, i_buf );
102
103
    /* cf. 5.3.2 */
104
47.5k
    bs->i_fscod = bs_read( &s, 2 );
105
47.5k
    if( bs->i_fscod == 3 )
106
3.00k
        return VLC_EGENERIC;
107
44.5k
    bs->i_frmsizcod = bs_read( &s, 6 );
108
44.5k
    if( bs->i_frmsizcod >= 38 )
109
17.4k
        return VLC_EGENERIC;
110
27.0k
    bs->i_bsid = bs_read( &s, 5 );
111
27.0k
    bs->i_bsmod = bs_read( &s, 3 );
112
27.0k
    bs->i_acmod = bs_read( &s, 3 );
113
27.0k
    if( ( bs->i_acmod & 0x1 ) && ( bs->i_acmod != 0x1 ) )
114
9.14k
    {
115
        /* if 3 front channels */
116
9.14k
        bs_skip( &s, 2 ); /* i_cmixlev */
117
9.14k
    }
118
27.0k
    if( bs->i_acmod & 0x4 )
119
6.58k
    {
120
        /* if a surround channel exists */
121
6.58k
        bs_skip( &s, 2 ); /* i_surmixlev */
122
6.58k
    }
123
    /* if in 2/0 mode */
124
27.0k
    bs->ac3.i_dsurmod = bs->i_acmod == 0x2 ? bs_read( &s, 2 ) : 0;
125
27.0k
    bs->i_lfeon = bs_read( &s, 1 );
126
127
27.0k
    return VLC_SUCCESS;
128
44.5k
}
a52.c:vlc_a52_ParseAc3BitstreamInfo
Line
Count
Source
99
3.46M
{
100
3.46M
    bs_t s;
101
3.46M
    bs_init( &s, p_buf, i_buf );
102
103
    /* cf. 5.3.2 */
104
3.46M
    bs->i_fscod = bs_read( &s, 2 );
105
3.46M
    if( bs->i_fscod == 3 )
106
62.6k
        return VLC_EGENERIC;
107
3.40M
    bs->i_frmsizcod = bs_read( &s, 6 );
108
3.40M
    if( bs->i_frmsizcod >= 38 )
109
700k
        return VLC_EGENERIC;
110
2.70M
    bs->i_bsid = bs_read( &s, 5 );
111
2.70M
    bs->i_bsmod = bs_read( &s, 3 );
112
2.70M
    bs->i_acmod = bs_read( &s, 3 );
113
2.70M
    if( ( bs->i_acmod & 0x1 ) && ( bs->i_acmod != 0x1 ) )
114
1.40M
    {
115
        /* if 3 front channels */
116
1.40M
        bs_skip( &s, 2 ); /* i_cmixlev */
117
1.40M
    }
118
2.70M
    if( bs->i_acmod & 0x4 )
119
1.35M
    {
120
        /* if a surround channel exists */
121
1.35M
        bs_skip( &s, 2 ); /* i_surmixlev */
122
1.35M
    }
123
    /* if in 2/0 mode */
124
2.70M
    bs->ac3.i_dsurmod = bs->i_acmod == 0x2 ? bs_read( &s, 2 ) : 0;
125
2.70M
    bs->i_lfeon = bs_read( &s, 1 );
126
127
2.70M
    return VLC_SUCCESS;
128
3.40M
}
mlp.c:vlc_a52_ParseAc3BitstreamInfo
Line
Count
Source
99
45.7k
{
100
45.7k
    bs_t s;
101
45.7k
    bs_init( &s, p_buf, i_buf );
102
103
    /* cf. 5.3.2 */
104
45.7k
    bs->i_fscod = bs_read( &s, 2 );
105
45.7k
    if( bs->i_fscod == 3 )
106
1.76k
        return VLC_EGENERIC;
107
43.9k
    bs->i_frmsizcod = bs_read( &s, 6 );
108
43.9k
    if( bs->i_frmsizcod >= 38 )
109
2.56k
        return VLC_EGENERIC;
110
41.4k
    bs->i_bsid = bs_read( &s, 5 );
111
41.4k
    bs->i_bsmod = bs_read( &s, 3 );
112
41.4k
    bs->i_acmod = bs_read( &s, 3 );
113
41.4k
    if( ( bs->i_acmod & 0x1 ) && ( bs->i_acmod != 0x1 ) )
114
4.42k
    {
115
        /* if 3 front channels */
116
4.42k
        bs_skip( &s, 2 ); /* i_cmixlev */
117
4.42k
    }
118
41.4k
    if( bs->i_acmod & 0x4 )
119
3.57k
    {
120
        /* if a surround channel exists */
121
3.57k
        bs_skip( &s, 2 ); /* i_surmixlev */
122
3.57k
    }
123
    /* if in 2/0 mode */
124
41.4k
    bs->ac3.i_dsurmod = bs->i_acmod == 0x2 ? bs_read( &s, 2 ) : 0;
125
41.4k
    bs->i_lfeon = bs_read( &s, 1 );
126
127
41.4k
    return VLC_SUCCESS;
128
43.9k
}
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
3.55M
{
135
3.55M
    if( vlc_a52_ParseAc3BitstreamInfo( &p_header->bs,
136
3.55M
                                       &p_buf[4], /* start code + CRC */
137
3.55M
                                       VLC_A52_MIN_HEADER_SIZE - 4 ) != VLC_SUCCESS )
138
787k
        return VLC_EGENERIC;
139
140
    /* cf. Table 5.18 Frame Size Code Table */
141
2.77M
    static const uint16_t ppi_frmsizcod_fscod_sizes[][3] = {
142
        /* 32K, 44.1K, 48K */
143
2.77M
        { 96, 69, 64 },
144
2.77M
        { 96, 70, 64 },
145
2.77M
        { 120, 87, 80 },
146
2.77M
        { 120, 88, 80 },
147
2.77M
        { 144, 104, 96 },
148
2.77M
        { 144, 105, 96 },
149
2.77M
        { 168, 121, 112 },
150
2.77M
        { 168, 122, 112 },
151
2.77M
        { 192, 139, 128 },
152
2.77M
        { 192, 140, 128 },
153
2.77M
        { 240, 174, 160 },
154
2.77M
        { 240, 175, 160 },
155
2.77M
        { 288, 208, 192 },
156
2.77M
        { 288, 209, 192 },
157
2.77M
        { 336, 243, 224 },
158
2.77M
        { 336, 244, 224 },
159
2.77M
        { 384, 278, 256 },
160
2.77M
        { 384, 279, 256 },
161
2.77M
        { 480, 348, 320 },
162
2.77M
        { 480, 349, 320 },
163
2.77M
        { 576, 417, 384 },
164
2.77M
        { 576, 418, 384 },
165
2.77M
        { 672, 487, 448 },
166
2.77M
        { 672, 488, 448 },
167
2.77M
        { 768, 557, 512 },
168
2.77M
        { 768, 558, 512 },
169
2.77M
        { 960, 696, 640 },
170
2.77M
        { 960, 697, 640 },
171
2.77M
        { 1152, 835, 768 },
172
2.77M
        { 1152, 836, 768 },
173
2.77M
        { 1344, 975, 896 },
174
2.77M
        { 1344, 976, 896 },
175
2.77M
        { 1536, 1114, 1024 },
176
2.77M
        { 1536, 1115, 1024 },
177
2.77M
        { 1728, 1253, 1152 },
178
2.77M
        { 1728, 1254, 1152 },
179
2.77M
        { 1920, 1393, 1280 },
180
2.77M
        { 1920, 1394, 1280 }
181
2.77M
    };
182
2.77M
    static const uint16_t pi_frmsizcod_bitrates[] = {
183
2.77M
        32,  40,  48,  56,
184
2.77M
        64,  80,  96, 112,
185
2.77M
        128, 160, 192, 224,
186
2.77M
        256, 320, 384, 448,
187
2.77M
        512, 576, 640
188
2.77M
    };
189
190
2.77M
    const struct vlc_a52_bitstream_info *bs = &p_header->bs;
191
192
2.77M
    p_header->i_channels_conf = p_acmod[bs->i_acmod];
193
2.77M
    p_header->i_chan_mode = 0;
194
2.77M
    if( bs->ac3.i_dsurmod == 2 )
195
960k
        p_header->i_chan_mode |= AOUT_CHANMODE_DOLBYSTEREO;
196
2.77M
    if( bs->i_acmod == 0 )
197
277k
        p_header->i_chan_mode |= AOUT_CHANMODE_DUALMONO;
198
199
2.77M
    if( bs->i_lfeon )
200
2.43M
        p_header->i_channels_conf |= AOUT_CHAN_LFE;
201
202
2.77M
    p_header->i_channels = stdc_count_ones(p_header->i_channels_conf);
203
204
2.77M
    const unsigned i_rate_shift = VLC_CLIP(bs->i_bsid, 8, 11) - 8;
205
2.77M
    p_header->i_bitrate = (pi_frmsizcod_bitrates[bs->i_frmsizcod >> 1] * 1000)
206
2.77M
                        >> i_rate_shift;
207
2.77M
    p_header->i_rate = pi_fscod_samplerates[bs->i_fscod] >> i_rate_shift;
208
209
2.77M
    p_header->i_size = ppi_frmsizcod_fscod_sizes[bs->i_frmsizcod]
210
2.77M
                                                [2 - bs->i_fscod] * 2;
211
2.77M
    p_header->i_blocks_per_sync_frame = 6;
212
2.77M
    p_header->i_samples = p_header->i_blocks_per_sync_frame * 256;
213
214
2.77M
    p_header->b_eac3 = false;
215
2.77M
    return VLC_SUCCESS;
216
3.55M
}
es.c:vlc_a52_header_ParseAc3
Line
Count
Source
134
47.5k
{
135
47.5k
    if( vlc_a52_ParseAc3BitstreamInfo( &p_header->bs,
136
47.5k
                                       &p_buf[4], /* start code + CRC */
137
47.5k
                                       VLC_A52_MIN_HEADER_SIZE - 4 ) != VLC_SUCCESS )
138
20.4k
        return VLC_EGENERIC;
139
140
    /* cf. Table 5.18 Frame Size Code Table */
141
27.0k
    static const uint16_t ppi_frmsizcod_fscod_sizes[][3] = {
142
        /* 32K, 44.1K, 48K */
143
27.0k
        { 96, 69, 64 },
144
27.0k
        { 96, 70, 64 },
145
27.0k
        { 120, 87, 80 },
146
27.0k
        { 120, 88, 80 },
147
27.0k
        { 144, 104, 96 },
148
27.0k
        { 144, 105, 96 },
149
27.0k
        { 168, 121, 112 },
150
27.0k
        { 168, 122, 112 },
151
27.0k
        { 192, 139, 128 },
152
27.0k
        { 192, 140, 128 },
153
27.0k
        { 240, 174, 160 },
154
27.0k
        { 240, 175, 160 },
155
27.0k
        { 288, 208, 192 },
156
27.0k
        { 288, 209, 192 },
157
27.0k
        { 336, 243, 224 },
158
27.0k
        { 336, 244, 224 },
159
27.0k
        { 384, 278, 256 },
160
27.0k
        { 384, 279, 256 },
161
27.0k
        { 480, 348, 320 },
162
27.0k
        { 480, 349, 320 },
163
27.0k
        { 576, 417, 384 },
164
27.0k
        { 576, 418, 384 },
165
27.0k
        { 672, 487, 448 },
166
27.0k
        { 672, 488, 448 },
167
27.0k
        { 768, 557, 512 },
168
27.0k
        { 768, 558, 512 },
169
27.0k
        { 960, 696, 640 },
170
27.0k
        { 960, 697, 640 },
171
27.0k
        { 1152, 835, 768 },
172
27.0k
        { 1152, 836, 768 },
173
27.0k
        { 1344, 975, 896 },
174
27.0k
        { 1344, 976, 896 },
175
27.0k
        { 1536, 1114, 1024 },
176
27.0k
        { 1536, 1115, 1024 },
177
27.0k
        { 1728, 1253, 1152 },
178
27.0k
        { 1728, 1254, 1152 },
179
27.0k
        { 1920, 1393, 1280 },
180
27.0k
        { 1920, 1394, 1280 }
181
27.0k
    };
182
27.0k
    static const uint16_t pi_frmsizcod_bitrates[] = {
183
27.0k
        32,  40,  48,  56,
184
27.0k
        64,  80,  96, 112,
185
27.0k
        128, 160, 192, 224,
186
27.0k
        256, 320, 384, 448,
187
27.0k
        512, 576, 640
188
27.0k
    };
189
190
27.0k
    const struct vlc_a52_bitstream_info *bs = &p_header->bs;
191
192
27.0k
    p_header->i_channels_conf = p_acmod[bs->i_acmod];
193
27.0k
    p_header->i_chan_mode = 0;
194
27.0k
    if( bs->ac3.i_dsurmod == 2 )
195
3.39k
        p_header->i_chan_mode |= AOUT_CHANMODE_DOLBYSTEREO;
196
27.0k
    if( bs->i_acmod == 0 )
197
8.54k
        p_header->i_chan_mode |= AOUT_CHANMODE_DUALMONO;
198
199
27.0k
    if( bs->i_lfeon )
200
14.3k
        p_header->i_channels_conf |= AOUT_CHAN_LFE;
201
202
27.0k
    p_header->i_channels = stdc_count_ones(p_header->i_channels_conf);
203
204
27.0k
    const unsigned i_rate_shift = VLC_CLIP(bs->i_bsid, 8, 11) - 8;
205
27.0k
    p_header->i_bitrate = (pi_frmsizcod_bitrates[bs->i_frmsizcod >> 1] * 1000)
206
27.0k
                        >> i_rate_shift;
207
27.0k
    p_header->i_rate = pi_fscod_samplerates[bs->i_fscod] >> i_rate_shift;
208
209
27.0k
    p_header->i_size = ppi_frmsizcod_fscod_sizes[bs->i_frmsizcod]
210
27.0k
                                                [2 - bs->i_fscod] * 2;
211
27.0k
    p_header->i_blocks_per_sync_frame = 6;
212
27.0k
    p_header->i_samples = p_header->i_blocks_per_sync_frame * 256;
213
214
27.0k
    p_header->b_eac3 = false;
215
27.0k
    return VLC_SUCCESS;
216
47.5k
}
a52.c:vlc_a52_header_ParseAc3
Line
Count
Source
134
3.46M
{
135
3.46M
    if( vlc_a52_ParseAc3BitstreamInfo( &p_header->bs,
136
3.46M
                                       &p_buf[4], /* start code + CRC */
137
3.46M
                                       VLC_A52_MIN_HEADER_SIZE - 4 ) != VLC_SUCCESS )
138
763k
        return VLC_EGENERIC;
139
140
    /* cf. Table 5.18 Frame Size Code Table */
141
2.70M
    static const uint16_t ppi_frmsizcod_fscod_sizes[][3] = {
142
        /* 32K, 44.1K, 48K */
143
2.70M
        { 96, 69, 64 },
144
2.70M
        { 96, 70, 64 },
145
2.70M
        { 120, 87, 80 },
146
2.70M
        { 120, 88, 80 },
147
2.70M
        { 144, 104, 96 },
148
2.70M
        { 144, 105, 96 },
149
2.70M
        { 168, 121, 112 },
150
2.70M
        { 168, 122, 112 },
151
2.70M
        { 192, 139, 128 },
152
2.70M
        { 192, 140, 128 },
153
2.70M
        { 240, 174, 160 },
154
2.70M
        { 240, 175, 160 },
155
2.70M
        { 288, 208, 192 },
156
2.70M
        { 288, 209, 192 },
157
2.70M
        { 336, 243, 224 },
158
2.70M
        { 336, 244, 224 },
159
2.70M
        { 384, 278, 256 },
160
2.70M
        { 384, 279, 256 },
161
2.70M
        { 480, 348, 320 },
162
2.70M
        { 480, 349, 320 },
163
2.70M
        { 576, 417, 384 },
164
2.70M
        { 576, 418, 384 },
165
2.70M
        { 672, 487, 448 },
166
2.70M
        { 672, 488, 448 },
167
2.70M
        { 768, 557, 512 },
168
2.70M
        { 768, 558, 512 },
169
2.70M
        { 960, 696, 640 },
170
2.70M
        { 960, 697, 640 },
171
2.70M
        { 1152, 835, 768 },
172
2.70M
        { 1152, 836, 768 },
173
2.70M
        { 1344, 975, 896 },
174
2.70M
        { 1344, 976, 896 },
175
2.70M
        { 1536, 1114, 1024 },
176
2.70M
        { 1536, 1115, 1024 },
177
2.70M
        { 1728, 1253, 1152 },
178
2.70M
        { 1728, 1254, 1152 },
179
2.70M
        { 1920, 1393, 1280 },
180
2.70M
        { 1920, 1394, 1280 }
181
2.70M
    };
182
2.70M
    static const uint16_t pi_frmsizcod_bitrates[] = {
183
2.70M
        32,  40,  48,  56,
184
2.70M
        64,  80,  96, 112,
185
2.70M
        128, 160, 192, 224,
186
2.70M
        256, 320, 384, 448,
187
2.70M
        512, 576, 640
188
2.70M
    };
189
190
2.70M
    const struct vlc_a52_bitstream_info *bs = &p_header->bs;
191
192
2.70M
    p_header->i_channels_conf = p_acmod[bs->i_acmod];
193
2.70M
    p_header->i_chan_mode = 0;
194
2.70M
    if( bs->ac3.i_dsurmod == 2 )
195
957k
        p_header->i_chan_mode |= AOUT_CHANMODE_DOLBYSTEREO;
196
2.70M
    if( bs->i_acmod == 0 )
197
246k
        p_header->i_chan_mode |= AOUT_CHANMODE_DUALMONO;
198
199
2.70M
    if( bs->i_lfeon )
200
2.40M
        p_header->i_channels_conf |= AOUT_CHAN_LFE;
201
202
2.70M
    p_header->i_channels = stdc_count_ones(p_header->i_channels_conf);
203
204
2.70M
    const unsigned i_rate_shift = VLC_CLIP(bs->i_bsid, 8, 11) - 8;
205
2.70M
    p_header->i_bitrate = (pi_frmsizcod_bitrates[bs->i_frmsizcod >> 1] * 1000)
206
2.70M
                        >> i_rate_shift;
207
2.70M
    p_header->i_rate = pi_fscod_samplerates[bs->i_fscod] >> i_rate_shift;
208
209
2.70M
    p_header->i_size = ppi_frmsizcod_fscod_sizes[bs->i_frmsizcod]
210
2.70M
                                                [2 - bs->i_fscod] * 2;
211
2.70M
    p_header->i_blocks_per_sync_frame = 6;
212
2.70M
    p_header->i_samples = p_header->i_blocks_per_sync_frame * 256;
213
214
2.70M
    p_header->b_eac3 = false;
215
2.70M
    return VLC_SUCCESS;
216
3.46M
}
mlp.c:vlc_a52_header_ParseAc3
Line
Count
Source
134
45.7k
{
135
45.7k
    if( vlc_a52_ParseAc3BitstreamInfo( &p_header->bs,
136
45.7k
                                       &p_buf[4], /* start code + CRC */
137
45.7k
                                       VLC_A52_MIN_HEADER_SIZE - 4 ) != VLC_SUCCESS )
138
4.32k
        return VLC_EGENERIC;
139
140
    /* cf. Table 5.18 Frame Size Code Table */
141
41.4k
    static const uint16_t ppi_frmsizcod_fscod_sizes[][3] = {
142
        /* 32K, 44.1K, 48K */
143
41.4k
        { 96, 69, 64 },
144
41.4k
        { 96, 70, 64 },
145
41.4k
        { 120, 87, 80 },
146
41.4k
        { 120, 88, 80 },
147
41.4k
        { 144, 104, 96 },
148
41.4k
        { 144, 105, 96 },
149
41.4k
        { 168, 121, 112 },
150
41.4k
        { 168, 122, 112 },
151
41.4k
        { 192, 139, 128 },
152
41.4k
        { 192, 140, 128 },
153
41.4k
        { 240, 174, 160 },
154
41.4k
        { 240, 175, 160 },
155
41.4k
        { 288, 208, 192 },
156
41.4k
        { 288, 209, 192 },
157
41.4k
        { 336, 243, 224 },
158
41.4k
        { 336, 244, 224 },
159
41.4k
        { 384, 278, 256 },
160
41.4k
        { 384, 279, 256 },
161
41.4k
        { 480, 348, 320 },
162
41.4k
        { 480, 349, 320 },
163
41.4k
        { 576, 417, 384 },
164
41.4k
        { 576, 418, 384 },
165
41.4k
        { 672, 487, 448 },
166
41.4k
        { 672, 488, 448 },
167
41.4k
        { 768, 557, 512 },
168
41.4k
        { 768, 558, 512 },
169
41.4k
        { 960, 696, 640 },
170
41.4k
        { 960, 697, 640 },
171
41.4k
        { 1152, 835, 768 },
172
41.4k
        { 1152, 836, 768 },
173
41.4k
        { 1344, 975, 896 },
174
41.4k
        { 1344, 976, 896 },
175
41.4k
        { 1536, 1114, 1024 },
176
41.4k
        { 1536, 1115, 1024 },
177
41.4k
        { 1728, 1253, 1152 },
178
41.4k
        { 1728, 1254, 1152 },
179
41.4k
        { 1920, 1393, 1280 },
180
41.4k
        { 1920, 1394, 1280 }
181
41.4k
    };
182
41.4k
    static const uint16_t pi_frmsizcod_bitrates[] = {
183
41.4k
        32,  40,  48,  56,
184
41.4k
        64,  80,  96, 112,
185
41.4k
        128, 160, 192, 224,
186
41.4k
        256, 320, 384, 448,
187
41.4k
        512, 576, 640
188
41.4k
    };
189
190
41.4k
    const struct vlc_a52_bitstream_info *bs = &p_header->bs;
191
192
41.4k
    p_header->i_channels_conf = p_acmod[bs->i_acmod];
193
41.4k
    p_header->i_chan_mode = 0;
194
41.4k
    if( bs->ac3.i_dsurmod == 2 )
195
127
        p_header->i_chan_mode |= AOUT_CHANMODE_DOLBYSTEREO;
196
41.4k
    if( bs->i_acmod == 0 )
197
22.5k
        p_header->i_chan_mode |= AOUT_CHANMODE_DUALMONO;
198
199
41.4k
    if( bs->i_lfeon )
200
12.9k
        p_header->i_channels_conf |= AOUT_CHAN_LFE;
201
202
41.4k
    p_header->i_channels = stdc_count_ones(p_header->i_channels_conf);
203
204
41.4k
    const unsigned i_rate_shift = VLC_CLIP(bs->i_bsid, 8, 11) - 8;
205
41.4k
    p_header->i_bitrate = (pi_frmsizcod_bitrates[bs->i_frmsizcod >> 1] * 1000)
206
41.4k
                        >> i_rate_shift;
207
41.4k
    p_header->i_rate = pi_fscod_samplerates[bs->i_fscod] >> i_rate_shift;
208
209
41.4k
    p_header->i_size = ppi_frmsizcod_fscod_sizes[bs->i_frmsizcod]
210
41.4k
                                                [2 - bs->i_fscod] * 2;
211
41.4k
    p_header->i_blocks_per_sync_frame = 6;
212
41.4k
    p_header->i_samples = p_header->i_blocks_per_sync_frame * 256;
213
214
41.4k
    p_header->b_eac3 = false;
215
41.4k
    return VLC_SUCCESS;
216
45.7k
}
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.68M
{
224
1.68M
    bs_t s;
225
1.68M
    bs_init( &s, p_buf, i_buf );
226
1.68M
    bs->eac3.strmtyp = bs_read( &s, 2 );      /* Stream Type */
227
1.68M
    bs->eac3.i_substreamid = bs_read( &s, 3 );/* Substream Identification */
228
229
1.68M
    bs->eac3.i_frmsiz = bs_read( &s, 11 );
230
1.68M
    if( bs->eac3.i_frmsiz < 2 )
231
24.9k
        return VLC_EGENERIC;
232
233
1.66M
    bs->i_fscod = bs_read( &s, 2 );
234
1.66M
    if( bs->i_fscod == 0x03 )
235
312k
    {
236
312k
        bs->eac3.i_fscod2 = bs_read( &s, 2 );
237
312k
        if( bs->eac3.i_fscod2 == 0x03 )
238
162k
            return VLC_EGENERIC;
239
150k
        bs->eac3.i_numblkscod = 0x03;
240
150k
    }
241
1.34M
    else bs->eac3.i_numblkscod = bs_read( &s, 2 );
242
243
1.49M
    bs->i_acmod = bs_read( &s, 3 );
244
1.49M
    bs->i_lfeon = bs_read1( &s );
245
1.49M
    bs->i_bsid = bs_read( &s, 5 );
246
247
1.49M
    if( i_buf <= VLC_A52_MIN_HEADER_SIZE )
248
1.49M
    {
249
1.49M
        bs->i_bsmod = 0;
250
1.49M
        return VLC_SUCCESS;
251
1.49M
    }
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.49M
}
es.c:vlc_a52_ParseEac3BitstreamInfo
Line
Count
Source
223
255k
{
224
255k
    bs_t s;
225
255k
    bs_init( &s, p_buf, i_buf );
226
255k
    bs->eac3.strmtyp = bs_read( &s, 2 );      /* Stream Type */
227
255k
    bs->eac3.i_substreamid = bs_read( &s, 3 );/* Substream Identification */
228
229
255k
    bs->eac3.i_frmsiz = bs_read( &s, 11 );
230
255k
    if( bs->eac3.i_frmsiz < 2 )
231
1.81k
        return VLC_EGENERIC;
232
233
253k
    bs->i_fscod = bs_read( &s, 2 );
234
253k
    if( bs->i_fscod == 0x03 )
235
52.1k
    {
236
52.1k
        bs->eac3.i_fscod2 = bs_read( &s, 2 );
237
52.1k
        if( bs->eac3.i_fscod2 == 0x03 )
238
40.5k
            return VLC_EGENERIC;
239
11.5k
        bs->eac3.i_numblkscod = 0x03;
240
11.5k
    }
241
201k
    else bs->eac3.i_numblkscod = bs_read( &s, 2 );
242
243
212k
    bs->i_acmod = bs_read( &s, 3 );
244
212k
    bs->i_lfeon = bs_read1( &s );
245
212k
    bs->i_bsid = bs_read( &s, 5 );
246
247
212k
    if( i_buf <= VLC_A52_MIN_HEADER_SIZE )
248
212k
    {
249
212k
        bs->i_bsmod = 0;
250
212k
        return VLC_SUCCESS;
251
212k
    }
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
212k
}
a52.c:vlc_a52_ParseEac3BitstreamInfo
Line
Count
Source
223
1.40M
{
224
1.40M
    bs_t s;
225
1.40M
    bs_init( &s, p_buf, i_buf );
226
1.40M
    bs->eac3.strmtyp = bs_read( &s, 2 );      /* Stream Type */
227
1.40M
    bs->eac3.i_substreamid = bs_read( &s, 3 );/* Substream Identification */
228
229
1.40M
    bs->eac3.i_frmsiz = bs_read( &s, 11 );
230
1.40M
    if( bs->eac3.i_frmsiz < 2 )
231
22.7k
        return VLC_EGENERIC;
232
233
1.37M
    bs->i_fscod = bs_read( &s, 2 );
234
1.37M
    if( bs->i_fscod == 0x03 )
235
244k
    {
236
244k
        bs->eac3.i_fscod2 = bs_read( &s, 2 );
237
244k
        if( bs->eac3.i_fscod2 == 0x03 )
238
120k
            return VLC_EGENERIC;
239
123k
        bs->eac3.i_numblkscod = 0x03;
240
123k
    }
241
1.13M
    else bs->eac3.i_numblkscod = bs_read( &s, 2 );
242
243
1.25M
    bs->i_acmod = bs_read( &s, 3 );
244
1.25M
    bs->i_lfeon = bs_read1( &s );
245
1.25M
    bs->i_bsid = bs_read( &s, 5 );
246
247
1.25M
    if( i_buf <= VLC_A52_MIN_HEADER_SIZE )
248
1.25M
    {
249
1.25M
        bs->i_bsmod = 0;
250
1.25M
        return VLC_SUCCESS;
251
1.25M
    }
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.25M
}
mlp.c:vlc_a52_ParseEac3BitstreamInfo
Line
Count
Source
223
31.1k
{
224
31.1k
    bs_t s;
225
31.1k
    bs_init( &s, p_buf, i_buf );
226
31.1k
    bs->eac3.strmtyp = bs_read( &s, 2 );      /* Stream Type */
227
31.1k
    bs->eac3.i_substreamid = bs_read( &s, 3 );/* Substream Identification */
228
229
31.1k
    bs->eac3.i_frmsiz = bs_read( &s, 11 );
230
31.1k
    if( bs->eac3.i_frmsiz < 2 )
231
418
        return VLC_EGENERIC;
232
233
30.7k
    bs->i_fscod = bs_read( &s, 2 );
234
30.7k
    if( bs->i_fscod == 0x03 )
235
15.8k
    {
236
15.8k
        bs->eac3.i_fscod2 = bs_read( &s, 2 );
237
15.8k
        if( bs->eac3.i_fscod2 == 0x03 )
238
1.01k
            return VLC_EGENERIC;
239
14.8k
        bs->eac3.i_numblkscod = 0x03;
240
14.8k
    }
241
14.8k
    else bs->eac3.i_numblkscod = bs_read( &s, 2 );
242
243
29.6k
    bs->i_acmod = bs_read( &s, 3 );
244
29.6k
    bs->i_lfeon = bs_read1( &s );
245
29.6k
    bs->i_bsid = bs_read( &s, 5 );
246
247
29.6k
    if( i_buf <= VLC_A52_MIN_HEADER_SIZE )
248
29.6k
    {
249
29.6k
        bs->i_bsmod = 0;
250
29.6k
        return VLC_SUCCESS;
251
29.6k
    }
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
29.6k
}
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.68M
{
336
1.68M
    if( vlc_a52_ParseEac3BitstreamInfo( &p_header->bs,
337
1.68M
                                        &p_buf[2], /* start code */
338
1.68M
                                        VLC_A52_MIN_HEADER_SIZE - 2 ) != VLC_SUCCESS )
339
187k
        return VLC_EGENERIC;
340
341
1.49M
    const struct vlc_a52_bitstream_info *bs = &p_header->bs;
342
343
1.49M
    p_header->i_size = 2 * (bs->eac3.i_frmsiz + 1 );
344
345
1.49M
    if( bs->i_fscod == 0x03 )
346
150k
    {
347
150k
        p_header->i_rate = pi_fscod_samplerates[bs->eac3.i_fscod2] / 2;
348
150k
        p_header->i_blocks_per_sync_frame = 6;
349
150k
    }
350
1.34M
    else
351
1.34M
    {
352
1.34M
        static const int pi_numblkscod [4] = { 1, 2, 3, 6 };
353
1.34M
        p_header->i_rate = pi_fscod_samplerates[bs->i_fscod];
354
1.34M
        p_header->i_blocks_per_sync_frame = pi_numblkscod[bs->eac3.i_numblkscod];
355
1.34M
    }
356
357
1.49M
    p_header->i_channels_conf = p_acmod[bs->i_acmod];
358
1.49M
    p_header->i_chan_mode = 0;
359
1.49M
    if( bs->i_acmod == 0 )
360
269k
        p_header->i_chan_mode |= AOUT_CHANMODE_DUALMONO;
361
1.49M
    if( bs->i_lfeon )
362
1.07M
        p_header->i_channels_conf |= AOUT_CHAN_LFE;
363
1.49M
    p_header->i_channels = stdc_count_ones( p_header->i_channels_conf );
364
1.49M
    p_header->i_bitrate = 8 * p_header->i_size * p_header->i_rate
365
1.49M
                        / (p_header->i_blocks_per_sync_frame * 256);
366
1.49M
    p_header->i_samples = p_header->i_blocks_per_sync_frame * 256;
367
368
1.49M
    p_header->b_eac3 = true;
369
1.49M
    return VLC_SUCCESS;
370
1.68M
}
es.c:vlc_a52_header_ParseEac3
Line
Count
Source
335
255k
{
336
255k
    if( vlc_a52_ParseEac3BitstreamInfo( &p_header->bs,
337
255k
                                        &p_buf[2], /* start code */
338
255k
                                        VLC_A52_MIN_HEADER_SIZE - 2 ) != VLC_SUCCESS )
339
42.3k
        return VLC_EGENERIC;
340
341
212k
    const struct vlc_a52_bitstream_info *bs = &p_header->bs;
342
343
212k
    p_header->i_size = 2 * (bs->eac3.i_frmsiz + 1 );
344
345
212k
    if( bs->i_fscod == 0x03 )
346
11.5k
    {
347
11.5k
        p_header->i_rate = pi_fscod_samplerates[bs->eac3.i_fscod2] / 2;
348
11.5k
        p_header->i_blocks_per_sync_frame = 6;
349
11.5k
    }
350
201k
    else
351
201k
    {
352
201k
        static const int pi_numblkscod [4] = { 1, 2, 3, 6 };
353
201k
        p_header->i_rate = pi_fscod_samplerates[bs->i_fscod];
354
201k
        p_header->i_blocks_per_sync_frame = pi_numblkscod[bs->eac3.i_numblkscod];
355
201k
    }
356
357
212k
    p_header->i_channels_conf = p_acmod[bs->i_acmod];
358
212k
    p_header->i_chan_mode = 0;
359
212k
    if( bs->i_acmod == 0 )
360
46.8k
        p_header->i_chan_mode |= AOUT_CHANMODE_DUALMONO;
361
212k
    if( bs->i_lfeon )
362
142k
        p_header->i_channels_conf |= AOUT_CHAN_LFE;
363
212k
    p_header->i_channels = stdc_count_ones( p_header->i_channels_conf );
364
212k
    p_header->i_bitrate = 8 * p_header->i_size * p_header->i_rate
365
212k
                        / (p_header->i_blocks_per_sync_frame * 256);
366
212k
    p_header->i_samples = p_header->i_blocks_per_sync_frame * 256;
367
368
212k
    p_header->b_eac3 = true;
369
212k
    return VLC_SUCCESS;
370
255k
}
a52.c:vlc_a52_header_ParseEac3
Line
Count
Source
335
1.40M
{
336
1.40M
    if( vlc_a52_ParseEac3BitstreamInfo( &p_header->bs,
337
1.40M
                                        &p_buf[2], /* start code */
338
1.40M
                                        VLC_A52_MIN_HEADER_SIZE - 2 ) != VLC_SUCCESS )
339
143k
        return VLC_EGENERIC;
340
341
1.25M
    const struct vlc_a52_bitstream_info *bs = &p_header->bs;
342
343
1.25M
    p_header->i_size = 2 * (bs->eac3.i_frmsiz + 1 );
344
345
1.25M
    if( bs->i_fscod == 0x03 )
346
123k
    {
347
123k
        p_header->i_rate = pi_fscod_samplerates[bs->eac3.i_fscod2] / 2;
348
123k
        p_header->i_blocks_per_sync_frame = 6;
349
123k
    }
350
1.13M
    else
351
1.13M
    {
352
1.13M
        static const int pi_numblkscod [4] = { 1, 2, 3, 6 };
353
1.13M
        p_header->i_rate = pi_fscod_samplerates[bs->i_fscod];
354
1.13M
        p_header->i_blocks_per_sync_frame = pi_numblkscod[bs->eac3.i_numblkscod];
355
1.13M
    }
356
357
1.25M
    p_header->i_channels_conf = p_acmod[bs->i_acmod];
358
1.25M
    p_header->i_chan_mode = 0;
359
1.25M
    if( bs->i_acmod == 0 )
360
218k
        p_header->i_chan_mode |= AOUT_CHANMODE_DUALMONO;
361
1.25M
    if( bs->i_lfeon )
362
909k
        p_header->i_channels_conf |= AOUT_CHAN_LFE;
363
1.25M
    p_header->i_channels = stdc_count_ones( p_header->i_channels_conf );
364
1.25M
    p_header->i_bitrate = 8 * p_header->i_size * p_header->i_rate
365
1.25M
                        / (p_header->i_blocks_per_sync_frame * 256);
366
1.25M
    p_header->i_samples = p_header->i_blocks_per_sync_frame * 256;
367
368
1.25M
    p_header->b_eac3 = true;
369
1.25M
    return VLC_SUCCESS;
370
1.40M
}
mlp.c:vlc_a52_header_ParseEac3
Line
Count
Source
335
31.1k
{
336
31.1k
    if( vlc_a52_ParseEac3BitstreamInfo( &p_header->bs,
337
31.1k
                                        &p_buf[2], /* start code */
338
31.1k
                                        VLC_A52_MIN_HEADER_SIZE - 2 ) != VLC_SUCCESS )
339
1.42k
        return VLC_EGENERIC;
340
341
29.6k
    const struct vlc_a52_bitstream_info *bs = &p_header->bs;
342
343
29.6k
    p_header->i_size = 2 * (bs->eac3.i_frmsiz + 1 );
344
345
29.6k
    if( bs->i_fscod == 0x03 )
346
14.8k
    {
347
14.8k
        p_header->i_rate = pi_fscod_samplerates[bs->eac3.i_fscod2] / 2;
348
14.8k
        p_header->i_blocks_per_sync_frame = 6;
349
14.8k
    }
350
14.8k
    else
351
14.8k
    {
352
14.8k
        static const int pi_numblkscod [4] = { 1, 2, 3, 6 };
353
14.8k
        p_header->i_rate = pi_fscod_samplerates[bs->i_fscod];
354
14.8k
        p_header->i_blocks_per_sync_frame = pi_numblkscod[bs->eac3.i_numblkscod];
355
14.8k
    }
356
357
29.6k
    p_header->i_channels_conf = p_acmod[bs->i_acmod];
358
29.6k
    p_header->i_chan_mode = 0;
359
29.6k
    if( bs->i_acmod == 0 )
360
3.70k
        p_header->i_chan_mode |= AOUT_CHANMODE_DUALMONO;
361
29.6k
    if( bs->i_lfeon )
362
27.3k
        p_header->i_channels_conf |= AOUT_CHAN_LFE;
363
29.6k
    p_header->i_channels = stdc_count_ones( p_header->i_channels_conf );
364
29.6k
    p_header->i_bitrate = 8 * p_header->i_size * p_header->i_rate
365
29.6k
                        / (p_header->i_blocks_per_sync_frame * 256);
366
29.6k
    p_header->i_samples = p_header->i_blocks_per_sync_frame * 256;
367
368
29.6k
    p_header->b_eac3 = true;
369
29.6k
    return VLC_SUCCESS;
370
31.1k
}
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
36.8M
{
381
36.8M
    static const uint32_t p_acmod[8] = {
382
36.8M
        AOUT_CHANS_2_0,
383
36.8M
        AOUT_CHAN_CENTER,
384
36.8M
        AOUT_CHANS_2_0,
385
36.8M
        AOUT_CHANS_3_0,
386
36.8M
        AOUT_CHANS_FRONT | AOUT_CHAN_REARCENTER, /* 2F1R */
387
36.8M
        AOUT_CHANS_FRONT | AOUT_CHANS_CENTER,    /* 3F1R */
388
36.8M
        AOUT_CHANS_4_0,
389
36.8M
        AOUT_CHANS_5_0,
390
36.8M
    };
391
36.8M
    static const unsigned pi_fscod_samplerates[] = {
392
36.8M
        48000, 44100, 32000
393
36.8M
    };
394
395
36.8M
    if( i_buffer < VLC_A52_MIN_HEADER_SIZE )
396
0
        return VLC_EGENERIC;
397
398
    /* Check synword */
399
36.8M
    if( p_buffer[0] != 0x0b || p_buffer[1] != 0x77 )
400
31.5M
        return VLC_EGENERIC;
401
402
    /* Check bsid */
403
5.37M
    const int bsid = p_buffer[5] >> 3;
404
405
    /* cf. Annex E 2.3.1.6 of AC3 spec */
406
5.37M
    if( bsid <= 10 )
407
3.55M
        return vlc_a52_header_ParseAc3( p_header, p_buffer,
408
3.55M
                                        p_acmod, pi_fscod_samplerates );
409
1.81M
    else if( bsid <= 16 )
410
1.68M
        return vlc_a52_header_ParseEac3( p_header, p_buffer,
411
1.68M
                                         p_acmod, pi_fscod_samplerates );
412
125k
    else
413
125k
        return VLC_EGENERIC;
414
5.37M
}
es.c:vlc_a52_header_Parse
Line
Count
Source
380
9.42M
{
381
9.42M
    static const uint32_t p_acmod[8] = {
382
9.42M
        AOUT_CHANS_2_0,
383
9.42M
        AOUT_CHAN_CENTER,
384
9.42M
        AOUT_CHANS_2_0,
385
9.42M
        AOUT_CHANS_3_0,
386
9.42M
        AOUT_CHANS_FRONT | AOUT_CHAN_REARCENTER, /* 2F1R */
387
9.42M
        AOUT_CHANS_FRONT | AOUT_CHANS_CENTER,    /* 3F1R */
388
9.42M
        AOUT_CHANS_4_0,
389
9.42M
        AOUT_CHANS_5_0,
390
9.42M
    };
391
9.42M
    static const unsigned pi_fscod_samplerates[] = {
392
9.42M
        48000, 44100, 32000
393
9.42M
    };
394
395
9.42M
    if( i_buffer < VLC_A52_MIN_HEADER_SIZE )
396
0
        return VLC_EGENERIC;
397
398
    /* Check synword */
399
9.42M
    if( p_buffer[0] != 0x0b || p_buffer[1] != 0x77 )
400
9.10M
        return VLC_EGENERIC;
401
402
    /* Check bsid */
403
315k
    const int bsid = p_buffer[5] >> 3;
404
405
    /* cf. Annex E 2.3.1.6 of AC3 spec */
406
315k
    if( bsid <= 10 )
407
47.5k
        return vlc_a52_header_ParseAc3( p_header, p_buffer,
408
47.5k
                                        p_acmod, pi_fscod_samplerates );
409
268k
    else if( bsid <= 16 )
410
255k
        return vlc_a52_header_ParseEac3( p_header, p_buffer,
411
255k
                                         p_acmod, pi_fscod_samplerates );
412
12.6k
    else
413
12.6k
        return VLC_EGENERIC;
414
315k
}
a52.c:vlc_a52_header_Parse
Line
Count
Source
380
7.61M
{
381
7.61M
    static const uint32_t p_acmod[8] = {
382
7.61M
        AOUT_CHANS_2_0,
383
7.61M
        AOUT_CHAN_CENTER,
384
7.61M
        AOUT_CHANS_2_0,
385
7.61M
        AOUT_CHANS_3_0,
386
7.61M
        AOUT_CHANS_FRONT | AOUT_CHAN_REARCENTER, /* 2F1R */
387
7.61M
        AOUT_CHANS_FRONT | AOUT_CHANS_CENTER,    /* 3F1R */
388
7.61M
        AOUT_CHANS_4_0,
389
7.61M
        AOUT_CHANS_5_0,
390
7.61M
    };
391
7.61M
    static const unsigned pi_fscod_samplerates[] = {
392
7.61M
        48000, 44100, 32000
393
7.61M
    };
394
395
7.61M
    if( i_buffer < VLC_A52_MIN_HEADER_SIZE )
396
0
        return VLC_EGENERIC;
397
398
    /* Check synword */
399
7.61M
    if( p_buffer[0] != 0x0b || p_buffer[1] != 0x77 )
400
2.64M
        return VLC_EGENERIC;
401
402
    /* Check bsid */
403
4.97M
    const int bsid = p_buffer[5] >> 3;
404
405
    /* cf. Annex E 2.3.1.6 of AC3 spec */
406
4.97M
    if( bsid <= 10 )
407
3.46M
        return vlc_a52_header_ParseAc3( p_header, p_buffer,
408
3.46M
                                        p_acmod, pi_fscod_samplerates );
409
1.51M
    else if( bsid <= 16 )
410
1.40M
        return vlc_a52_header_ParseEac3( p_header, p_buffer,
411
1.40M
                                         p_acmod, pi_fscod_samplerates );
412
110k
    else
413
110k
        return VLC_EGENERIC;
414
4.97M
}
mlp.c:vlc_a52_header_Parse
Line
Count
Source
380
19.8M
{
381
19.8M
    static const uint32_t p_acmod[8] = {
382
19.8M
        AOUT_CHANS_2_0,
383
19.8M
        AOUT_CHAN_CENTER,
384
19.8M
        AOUT_CHANS_2_0,
385
19.8M
        AOUT_CHANS_3_0,
386
19.8M
        AOUT_CHANS_FRONT | AOUT_CHAN_REARCENTER, /* 2F1R */
387
19.8M
        AOUT_CHANS_FRONT | AOUT_CHANS_CENTER,    /* 3F1R */
388
19.8M
        AOUT_CHANS_4_0,
389
19.8M
        AOUT_CHANS_5_0,
390
19.8M
    };
391
19.8M
    static const unsigned pi_fscod_samplerates[] = {
392
19.8M
        48000, 44100, 32000
393
19.8M
    };
394
395
19.8M
    if( i_buffer < VLC_A52_MIN_HEADER_SIZE )
396
0
        return VLC_EGENERIC;
397
398
    /* Check synword */
399
19.8M
    if( p_buffer[0] != 0x0b || p_buffer[1] != 0x77 )
400
19.7M
        return VLC_EGENERIC;
401
402
    /* Check bsid */
403
78.7k
    const int bsid = p_buffer[5] >> 3;
404
405
    /* cf. Annex E 2.3.1.6 of AC3 spec */
406
78.7k
    if( bsid <= 10 )
407
45.7k
        return vlc_a52_header_ParseAc3( p_header, p_buffer,
408
45.7k
                                        p_acmod, pi_fscod_samplerates );
409
32.9k
    else if( bsid <= 16 )
410
31.1k
        return vlc_a52_header_ParseEac3( p_header, p_buffer,
411
31.1k
                                         p_acmod, pi_fscod_samplerates );
412
1.86k
    else
413
1.86k
        return VLC_EGENERIC;
414
78.7k
}
415
416
#endif