Coverage Report

Created: 2026-08-13 07:43

next uncovered line (L), next uncovered region (R), next uncovered branch (B)
/src/vlc/modules/packetizer/mpeg4audio.h
Line
Count
Source
1
/*****************************************************************************
2
 * mpeg4audio.h: ISO/IEC 14496-3 audio definitions
3
 *****************************************************************************
4
 * Copyright (C) 2001-2024 VLC authors, VideoLAN and VideoLabs
5
 *
6
 * This program is free software; you can redistribute it and/or modify it
7
 * under the terms of the GNU Lesser General Public License as published by
8
 * the Free Software Foundation; either version 2.1 of the License, or
9
 * (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14
 * GNU Lesser General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU Lesser General Public License
17
 * along with this program; if not, write to the Free Software Foundation,
18
 * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
19
 *****************************************************************************/
20
#include <vlc_bits.h>
21
22
enum MPEG4_audioObjectType /* ISO/IEC 14496-3:2009 1.5.1 */
23
{
24
    MPEG4_AOT_NULL            = 0,
25
    MPEG4_AOT_AAC_MAIN        = 1,
26
    MPEG4_AOT_AAC_LC          = 2,
27
    MPEG4_AOT_AAC_SSR         = 3,
28
    MPEG4_AOT_AAC_LTP         = 4,
29
    MPEG4_AOT_AAC_SBR         = 5,
30
    MPEG4_AOT_AAC_SC          = 6,
31
    MPEG4_AOT_TWINVQ          = 7,
32
    MPEG4_AOT_CELP            = 8,
33
    MPEG4_AOT_HVXC            = 9,
34
    MPEG4_AOT_RESERVED10      = 10,
35
    MPEG4_AOT_RESERVED11      = 11,
36
    MPEG4_AOT_TTSI            = 12,
37
    MPEG4_AOT_MAIN_SYNTHETIC  = 13,
38
    MPEG4_AOT_WAVETABLES      = 14,
39
    MPEG4_AOT_GENERAL_MIDI    = 15,
40
    MPEG4_AOT_ALGORITHMIC     = 16,
41
    MPEG4_AOT_ER_AAC_LC       = 17,
42
    MPEG4_AOT_RESERVED18      = 18,
43
    MPEG4_AOT_ER_AAC_LTP      = 19,
44
    MPEG4_AOT_ER_AAC_SC       = 20,
45
    MPEG4_AOT_ER_TWINVQ       = 21,
46
    MPEG4_AOT_ER_BSAC         = 22,
47
    MPEG4_AOT_ER_AAC_LD       = 23,
48
    MPEG4_AOT_ER_CELP         = 24,
49
    MPEG4_AOT_ER_HXVC         = 25,
50
    MPEG4_AOT_ER_HILN         = 26,
51
    MPEG4_AOT_ER_Parametric   = 27,
52
    MPEG4_AOT_SSC             = 28,
53
    MPEG4_AOT_AAC_PS          = 29,
54
    MPEG4_AOT_MPEG_SURROUND   = 30,
55
    MPEG4_AOT_ESCAPE          = 31,
56
    MPEG4_AOT_LAYER1          = 32,
57
    MPEG4_AOT_LAYER2          = 33,
58
    MPEG4_AOT_LAYER3          = 34,
59
    MPEG4_AOT_DST             = 35,
60
    MPEG4_AOT_ALS             = 36,
61
    MPEG4_AOT_SLS             = 37,
62
    MPEG4_AOT_SLS_NON_CORE    = 38,
63
    MPEG4_AOT_ER_AAC_ELD      = 39,
64
    MPEG4_AOT_SMR_SIMPLE      = 40,
65
    MPEG4_AOT_SMR_MAIN        = 41,
66
};
67
68
enum
69
{
70
    AAC_PROFILE_MAIN = MPEG4_AOT_AAC_MAIN - 1,
71
    AAC_PROFILE_LC,
72
    AAC_PROFILE_SSR,
73
    AAC_PROFILE_LTP,
74
    AAC_PROFILE_HE,
75
    AAC_PROFILE_LD   = MPEG4_AOT_ER_AAC_LD - 1,
76
    AAC_PROFILE_HEv2 = MPEG4_AOT_AAC_PS - 1,
77
    AAC_PROFILE_ELD  = MPEG4_AOT_ER_AAC_ELD - 1,
78
    /* Similar shift signaling as avcodec, as signaling should have been
79
       done in ADTS header. Values defaults to MPEG4 */
80
    AAC_PROFILE_MPEG2_LC = AAC_PROFILE_LC + 128,
81
    AAC_PROFILE_MPEG2_HE = AAC_PROFILE_HE + 128,
82
};
83
84
static const uint32_t MPEG4_asc_channelsbyindex[] =
85
{
86
    [0] = 0, /* Set later */
87
88
    [1] = AOUT_CHAN_CENTER, // Mono
89
90
    [2] = AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT, // Stereo
91
92
    [3] = AOUT_CHAN_CENTER | AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT, // 2.1ch 3.0
93
94
    [4] = AOUT_CHAN_CENTER | // 4ch 3.1
95
          AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT |
96
          AOUT_CHAN_REARCENTER,
97
98
    [5] = AOUT_CHAN_CENTER | // 5ch 3.2
99
          AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT |
100
          AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT,
101
102
    [6] = AOUT_CHAN_CENTER | // 5.1ch 3.2.1
103
          AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT |
104
          AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT |
105
          AOUT_CHAN_LFE,
106
107
    [7] = AOUT_CHAN_CENTER | // 7.1ch 5.2.1
108
          AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT |
109
          AOUT_CHAN_MIDDLELEFT | AOUT_CHAN_MIDDLERIGHT |
110
          AOUT_CHAN_REARLEFT | AOUT_CHAN_REARRIGHT |
111
          AOUT_CHAN_LFE,
112
113
    [8] = 0,
114
};
115
116
4.62k
#define MPEG4_ASC_MAX_INDEXEDPOS ARRAY_SIZE(MPEG4_asc_channelsbyindex)
117
118
typedef struct
119
{
120
    enum MPEG4_audioObjectType i_object_type;
121
    unsigned i_samplerate;
122
    uint8_t i_channel_configuration;
123
    int8_t i_sbr;          // 0: no sbr, 1: sbr, -1: unknown
124
    int8_t i_ps;           // 0: no ps,  1: ps,  -1: unknown
125
126
    struct
127
    {
128
        enum MPEG4_audioObjectType i_object_type;
129
        unsigned i_samplerate;
130
        uint8_t i_channel_configuration;
131
    } extension;
132
133
    /* GASpecific */
134
    unsigned i_frame_length;   // 1024 or 960
135
136
} MPEG4_asc_t;
137
138
static inline int MPEG4_read_GAProgramConfigElement(bs_t *s)
139
19.9k
{
140
    /* TODO compute channels count ? */
141
19.9k
    int i_tag = bs_read(s, 4);
142
19.9k
    if (i_tag != 0x05)
143
10.8k
        return -1;
144
9.11k
    bs_skip(s, 2 + 4); // object type + sampling index
145
9.11k
    int i_num_front = bs_read(s, 4);
146
9.11k
    int i_num_side = bs_read(s, 4);
147
9.11k
    int i_num_back = bs_read(s, 4);
148
9.11k
    int i_num_lfe = bs_read(s, 2);
149
9.11k
    int i_num_assoc_data = bs_read(s, 3);
150
9.11k
    int i_num_valid_cc = bs_read(s, 4);
151
152
9.11k
    if (bs_read1(s))
153
2.18k
        bs_skip(s, 4); // mono downmix
154
9.11k
    if (bs_read1(s))
155
2.45k
        bs_skip(s, 4); // stereo downmix
156
9.11k
    if (bs_read1(s))
157
1.58k
        bs_skip(s, 2+1); // matrix downmix + pseudo_surround
158
159
9.11k
    bs_skip(s, i_num_front * (1+4));
160
9.11k
    bs_skip(s, i_num_side * (1+4));
161
9.11k
    bs_skip(s, i_num_back * (1+4));
162
9.11k
    bs_skip(s, i_num_lfe * (4));
163
9.11k
    bs_skip(s, i_num_assoc_data * (4));
164
9.11k
    bs_skip(s, i_num_valid_cc * (5));
165
9.11k
    bs_align(s);
166
9.11k
    int i_comment = bs_read(s, 8);
167
9.11k
    bs_skip(s, i_comment * 8);
168
9.11k
    return 0;
169
19.9k
}
mpeg4audio.c:MPEG4_read_GAProgramConfigElement
Line
Count
Source
139
19.9k
{
140
    /* TODO compute channels count ? */
141
19.9k
    int i_tag = bs_read(s, 4);
142
19.9k
    if (i_tag != 0x05)
143
10.8k
        return -1;
144
9.11k
    bs_skip(s, 2 + 4); // object type + sampling index
145
9.11k
    int i_num_front = bs_read(s, 4);
146
9.11k
    int i_num_side = bs_read(s, 4);
147
9.11k
    int i_num_back = bs_read(s, 4);
148
9.11k
    int i_num_lfe = bs_read(s, 2);
149
9.11k
    int i_num_assoc_data = bs_read(s, 3);
150
9.11k
    int i_num_valid_cc = bs_read(s, 4);
151
152
9.11k
    if (bs_read1(s))
153
2.18k
        bs_skip(s, 4); // mono downmix
154
9.11k
    if (bs_read1(s))
155
2.45k
        bs_skip(s, 4); // stereo downmix
156
9.11k
    if (bs_read1(s))
157
1.58k
        bs_skip(s, 2+1); // matrix downmix + pseudo_surround
158
159
9.11k
    bs_skip(s, i_num_front * (1+4));
160
9.11k
    bs_skip(s, i_num_side * (1+4));
161
9.11k
    bs_skip(s, i_num_back * (1+4));
162
9.11k
    bs_skip(s, i_num_lfe * (4));
163
9.11k
    bs_skip(s, i_num_assoc_data * (4));
164
9.11k
    bs_skip(s, i_num_valid_cc * (5));
165
9.11k
    bs_align(s);
166
9.11k
    int i_comment = bs_read(s, 8);
167
9.11k
    bs_skip(s, i_comment * 8);
168
9.11k
    return 0;
169
19.9k
}
Unexecuted instantiation: faad.c:MPEG4_read_GAProgramConfigElement
170
171
static inline int MPEG4_read_GASpecificConfig(MPEG4_asc_t *p_cfg, bs_t *s)
172
125k
{
173
125k
    p_cfg->i_frame_length = bs_read1(s) ? 960 : 1024;
174
125k
    if(p_cfg->i_object_type == MPEG4_AOT_ER_AAC_LD) /* 14496-3 4.5.1.1 */
175
1.60k
        p_cfg->i_frame_length >>= 1;
176
124k
    else if(p_cfg->i_object_type == MPEG4_AOT_AAC_SSR)
177
9.30k
        p_cfg->i_frame_length = 256;
178
179
125k
    if (bs_read1(s))     // depend on core coder
180
26.1k
        bs_skip(s, 14);   // core coder delay
181
182
125k
    int i_extension_flag = bs_read1(s);
183
125k
    if (p_cfg->i_channel_configuration == 0)
184
19.9k
        MPEG4_read_GAProgramConfigElement(s);
185
125k
    if (p_cfg->i_object_type == MPEG4_AOT_AAC_SC ||
186
122k
        p_cfg->i_object_type == MPEG4_AOT_ER_AAC_SC)
187
8.11k
        bs_skip(s, 3);    // layer
188
189
125k
    if (i_extension_flag) {
190
86.0k
        if (p_cfg->i_object_type == MPEG4_AOT_ER_BSAC)
191
60.5k
            bs_skip(s, 5 + 11);   // numOfSubFrame + layer length
192
86.0k
        if (p_cfg->i_object_type == MPEG4_AOT_ER_AAC_LC ||
193
84.9k
            p_cfg->i_object_type == MPEG4_AOT_ER_AAC_LTP ||
194
83.2k
            p_cfg->i_object_type == MPEG4_AOT_ER_AAC_SC ||
195
79.1k
            p_cfg->i_object_type == MPEG4_AOT_ER_AAC_LD)
196
7.64k
            bs_skip(s, 1+1+1);    // ER data : section scale spectral */
197
86.0k
        if (bs_read1(s))     // extension 3
198
86.0k
            fprintf(stderr, "MPEG4GASpecificConfig: error 1\n");
199
86.0k
    }
200
125k
    return 0;
201
125k
}
mpeg4audio.c:MPEG4_read_GASpecificConfig
Line
Count
Source
172
125k
{
173
125k
    p_cfg->i_frame_length = bs_read1(s) ? 960 : 1024;
174
125k
    if(p_cfg->i_object_type == MPEG4_AOT_ER_AAC_LD) /* 14496-3 4.5.1.1 */
175
1.60k
        p_cfg->i_frame_length >>= 1;
176
124k
    else if(p_cfg->i_object_type == MPEG4_AOT_AAC_SSR)
177
9.30k
        p_cfg->i_frame_length = 256;
178
179
125k
    if (bs_read1(s))     // depend on core coder
180
26.1k
        bs_skip(s, 14);   // core coder delay
181
182
125k
    int i_extension_flag = bs_read1(s);
183
125k
    if (p_cfg->i_channel_configuration == 0)
184
19.9k
        MPEG4_read_GAProgramConfigElement(s);
185
125k
    if (p_cfg->i_object_type == MPEG4_AOT_AAC_SC ||
186
122k
        p_cfg->i_object_type == MPEG4_AOT_ER_AAC_SC)
187
8.11k
        bs_skip(s, 3);    // layer
188
189
125k
    if (i_extension_flag) {
190
86.0k
        if (p_cfg->i_object_type == MPEG4_AOT_ER_BSAC)
191
60.5k
            bs_skip(s, 5 + 11);   // numOfSubFrame + layer length
192
86.0k
        if (p_cfg->i_object_type == MPEG4_AOT_ER_AAC_LC ||
193
84.9k
            p_cfg->i_object_type == MPEG4_AOT_ER_AAC_LTP ||
194
83.2k
            p_cfg->i_object_type == MPEG4_AOT_ER_AAC_SC ||
195
79.1k
            p_cfg->i_object_type == MPEG4_AOT_ER_AAC_LD)
196
7.64k
            bs_skip(s, 1+1+1);    // ER data : section scale spectral */
197
86.0k
        if (bs_read1(s))     // extension 3
198
            fprintf(stderr, "MPEG4GASpecificConfig: error 1\n");
199
86.0k
    }
200
125k
    return 0;
201
125k
}
Unexecuted instantiation: faad.c:MPEG4_read_GASpecificConfig
202
203
static inline int MPEG4_read_ELDSpecificConfig(MPEG4_asc_t *p_cfg, bs_t *s)
204
43.9k
{
205
43.9k
    p_cfg->i_frame_length = bs_read1(s) ? 480 : 512;
206
207
    /* ELDSpecificConfig Table 4.180 */
208
209
43.9k
    bs_skip(s, 3);
210
43.9k
    if(bs_read1(s)) /* ldSbrPresentFlag */
211
25.0k
    {
212
25.0k
        bs_skip(s, 2);
213
        /* ld_sbr_header(channelConfiguration) Table 4.181 */
214
25.0k
        unsigned numSbrHeader;
215
25.0k
        switch(p_cfg->i_channel_configuration)
216
25.0k
        {
217
2.09k
        case 1: case 2:
218
2.09k
            numSbrHeader = 1;
219
2.09k
            break;
220
428
        case 3:
221
428
            numSbrHeader = 2;
222
428
            break;
223
6.08k
        case 4: case 5: case 6:
224
6.08k
            numSbrHeader = 3;
225
6.08k
            break;
226
788
        case 7:
227
788
            numSbrHeader = 4;
228
788
            break;
229
15.6k
        default:
230
15.6k
            numSbrHeader = 0;
231
15.6k
            break;
232
25.0k
        }
233
49.3k
        for( ; numSbrHeader; numSbrHeader-- )
234
24.3k
        {
235
            /* sbr_header() Table 4.63 */
236
24.3k
            bs_read(s, 14);
237
24.3k
            bool header_extra_1 = bs_read1(s);
238
24.3k
            bool header_extra_2 = bs_read1(s);
239
24.3k
            if(header_extra_1)
240
14.8k
                bs_read(s, 5);
241
24.3k
            if(header_extra_2)
242
11.6k
                bs_read(s, 6);
243
24.3k
        }
244
25.0k
    }
245
246
43.9k
    for(unsigned eldExtType = bs_read(s, 4);
247
181k
         eldExtType != 0x0 /* ELDEXT_TERM */;
248
137k
         eldExtType = bs_read(s, 4))
249
137k
    {
250
137k
        unsigned eldExtLen = bs_read(s, 4);
251
137k
        unsigned eldExtLenAdd = 0;
252
137k
        if(eldExtLen == 15)
253
10.0k
        {
254
10.0k
            eldExtLenAdd = bs_read(s, 8);
255
10.0k
            eldExtLen += eldExtLenAdd;
256
10.0k
        }
257
137k
        if(eldExtLenAdd == 255)
258
3.46k
            eldExtLen += bs_read(s, 16);
259
        /* reserved extensions */
260
194M
        for(; eldExtLen; eldExtLen--)
261
194M
            bs_skip(s, 8);
262
137k
    }
263
264
43.9k
    return 0;
265
43.9k
}
mpeg4audio.c:MPEG4_read_ELDSpecificConfig
Line
Count
Source
204
43.9k
{
205
43.9k
    p_cfg->i_frame_length = bs_read1(s) ? 480 : 512;
206
207
    /* ELDSpecificConfig Table 4.180 */
208
209
43.9k
    bs_skip(s, 3);
210
43.9k
    if(bs_read1(s)) /* ldSbrPresentFlag */
211
25.0k
    {
212
25.0k
        bs_skip(s, 2);
213
        /* ld_sbr_header(channelConfiguration) Table 4.181 */
214
25.0k
        unsigned numSbrHeader;
215
25.0k
        switch(p_cfg->i_channel_configuration)
216
25.0k
        {
217
2.09k
        case 1: case 2:
218
2.09k
            numSbrHeader = 1;
219
2.09k
            break;
220
428
        case 3:
221
428
            numSbrHeader = 2;
222
428
            break;
223
6.08k
        case 4: case 5: case 6:
224
6.08k
            numSbrHeader = 3;
225
6.08k
            break;
226
788
        case 7:
227
788
            numSbrHeader = 4;
228
788
            break;
229
15.6k
        default:
230
15.6k
            numSbrHeader = 0;
231
15.6k
            break;
232
25.0k
        }
233
49.3k
        for( ; numSbrHeader; numSbrHeader-- )
234
24.3k
        {
235
            /* sbr_header() Table 4.63 */
236
24.3k
            bs_read(s, 14);
237
24.3k
            bool header_extra_1 = bs_read1(s);
238
24.3k
            bool header_extra_2 = bs_read1(s);
239
24.3k
            if(header_extra_1)
240
14.8k
                bs_read(s, 5);
241
24.3k
            if(header_extra_2)
242
11.6k
                bs_read(s, 6);
243
24.3k
        }
244
25.0k
    }
245
246
43.9k
    for(unsigned eldExtType = bs_read(s, 4);
247
181k
         eldExtType != 0x0 /* ELDEXT_TERM */;
248
137k
         eldExtType = bs_read(s, 4))
249
137k
    {
250
137k
        unsigned eldExtLen = bs_read(s, 4);
251
137k
        unsigned eldExtLenAdd = 0;
252
137k
        if(eldExtLen == 15)
253
10.0k
        {
254
10.0k
            eldExtLenAdd = bs_read(s, 8);
255
10.0k
            eldExtLen += eldExtLenAdd;
256
10.0k
        }
257
137k
        if(eldExtLenAdd == 255)
258
3.46k
            eldExtLen += bs_read(s, 16);
259
        /* reserved extensions */
260
194M
        for(; eldExtLen; eldExtLen--)
261
194M
            bs_skip(s, 8);
262
137k
    }
263
264
43.9k
    return 0;
265
43.9k
}
Unexecuted instantiation: faad.c:MPEG4_read_ELDSpecificConfig
266
267
static inline enum MPEG4_audioObjectType MPEG4_read_AudioObjectType(bs_t *s)
268
303k
{
269
303k
    int i_type = bs_read(s, 5);
270
303k
    if (i_type == 31)
271
9.80k
        i_type = 32 + bs_read(s, 6);
272
303k
    return (enum MPEG4_audioObjectType) i_type;
273
303k
}
mpeg4audio.c:MPEG4_read_AudioObjectType
Line
Count
Source
268
303k
{
269
303k
    int i_type = bs_read(s, 5);
270
303k
    if (i_type == 31)
271
9.80k
        i_type = 32 + bs_read(s, 6);
272
303k
    return (enum MPEG4_audioObjectType) i_type;
273
303k
}
Unexecuted instantiation: faad.c:MPEG4_read_AudioObjectType
274
275
static const int pi_sample_rates[16] =
276
    {
277
        96000, 88200, 64000, 48000, 44100, 32000, 24000, 22050,
278
        16000, 12000, 11025, 8000,  7350,  0,     0,     0
279
};
280
281
static inline unsigned MPEG4_read_AudioSamplerate(bs_t *s)
282
302k
{
283
302k
    int i_index = bs_read(s, 4);
284
302k
    if (i_index != 0x0f)
285
283k
        return pi_sample_rates[i_index];
286
19.0k
    return bs_read(s, 24);
287
302k
}
mpeg4audio.c:MPEG4_read_AudioSamplerate
Line
Count
Source
282
302k
{
283
302k
    int i_index = bs_read(s, 4);
284
302k
    if (i_index != 0x0f)
285
283k
        return pi_sample_rates[i_index];
286
19.0k
    return bs_read(s, 24);
287
302k
}
Unexecuted instantiation: faad.c:MPEG4_read_AudioSamplerate
288
289
static inline int MPEG4_read_AudioSpecificConfig(bs_t *s, MPEG4_asc_t *p_cfg, bool b_withext)
290
285k
{
291
285k
    p_cfg->i_object_type = MPEG4_read_AudioObjectType(s);
292
285k
    p_cfg->i_samplerate = MPEG4_read_AudioSamplerate(s);
293
285k
    p_cfg->i_channel_configuration = bs_read(s, 4);
294
295
285k
    p_cfg->i_sbr = -1;
296
285k
    p_cfg->i_ps  = -1;
297
285k
    p_cfg->extension.i_object_type = MPEG4_AOT_NULL;
298
285k
    p_cfg->extension.i_samplerate = 0;
299
285k
    p_cfg->extension.i_channel_configuration = 0;
300
285k
    p_cfg->i_frame_length = 0;
301
302
285k
    if (p_cfg->i_object_type == MPEG4_AOT_AAC_SBR ||
303
272k
        p_cfg->i_object_type == MPEG4_AOT_AAC_PS) {
304
16.8k
        p_cfg->i_sbr = 1;
305
16.8k
        if (p_cfg->i_object_type == MPEG4_AOT_AAC_PS)
306
3.98k
            p_cfg->i_ps = 1;
307
16.8k
        p_cfg->extension.i_object_type = MPEG4_AOT_AAC_SBR;
308
16.8k
        p_cfg->extension.i_samplerate = MPEG4_read_AudioSamplerate(s);
309
310
16.8k
        p_cfg->i_object_type = MPEG4_read_AudioObjectType(s);
311
16.8k
        if(p_cfg->i_object_type == MPEG4_AOT_ER_BSAC)
312
155
            p_cfg->extension.i_channel_configuration = bs_read(s, 4);
313
16.8k
    }
314
315
285k
    switch(p_cfg->i_object_type)
316
285k
    {
317
5.09k
    case MPEG4_AOT_AAC_MAIN:
318
22.8k
    case MPEG4_AOT_AAC_LC:
319
32.1k
    case MPEG4_AOT_AAC_SSR:
320
40.4k
    case MPEG4_AOT_AAC_LTP:
321
43.7k
    case MPEG4_AOT_AAC_SC:
322
47.9k
    case MPEG4_AOT_TWINVQ:
323
50.2k
    case MPEG4_AOT_ER_AAC_LC:
324
52.9k
    case MPEG4_AOT_ER_AAC_LTP:
325
57.7k
    case MPEG4_AOT_ER_AAC_SC:
326
59.3k
    case MPEG4_AOT_ER_TWINVQ:
327
124k
    case MPEG4_AOT_ER_BSAC:
328
125k
    case MPEG4_AOT_ER_AAC_LD:
329
125k
        MPEG4_read_GASpecificConfig(p_cfg, s);
330
125k
        break;
331
5.94k
    case MPEG4_AOT_CELP:
332
        // CelpSpecificConfig();
333
15.0k
    case MPEG4_AOT_HVXC:
334
        // HvxcSpecificConfig();
335
16.1k
    case MPEG4_AOT_TTSI:
336
        // TTSSSpecificConfig();
337
18.9k
    case MPEG4_AOT_MAIN_SYNTHETIC:
338
20.7k
    case MPEG4_AOT_WAVETABLES:
339
25.1k
    case MPEG4_AOT_GENERAL_MIDI:
340
30.3k
    case MPEG4_AOT_ALGORITHMIC:
341
        // StructuredAudioSpecificConfig();
342
31.8k
    case MPEG4_AOT_ER_CELP:
343
        // ERCelpSpecificConfig();
344
36.1k
    case MPEG4_AOT_ER_HXVC:
345
        // ERHvxcSpecificConfig();
346
38.0k
    case MPEG4_AOT_ER_HILN:
347
40.3k
    case MPEG4_AOT_ER_Parametric:
348
        // ParametricSpecificConfig();
349
42.6k
    case MPEG4_AOT_SSC:
350
        // SSCSpecificConfig();
351
42.8k
    case MPEG4_AOT_LAYER1:
352
42.8k
    case MPEG4_AOT_LAYER2:
353
42.9k
    case MPEG4_AOT_LAYER3:
354
        // MPEG_1_2_SpecificConfig();
355
43.0k
    case MPEG4_AOT_DST:
356
        // DSTSpecificConfig();
357
43.0k
    case MPEG4_AOT_ALS:
358
        // ALSSpecificConfig();
359
43.1k
    case MPEG4_AOT_SLS:
360
43.2k
    case MPEG4_AOT_SLS_NON_CORE:
361
        // SLSSpecificConfig();
362
43.9k
    case MPEG4_AOT_ER_AAC_ELD:
363
43.9k
        MPEG4_read_ELDSpecificConfig(p_cfg, s);
364
43.9k
        break;
365
0
    case MPEG4_AOT_SMR_SIMPLE:
366
0
    case MPEG4_AOT_SMR_MAIN:
367
        // SymbolicMusicSpecificConfig();
368
115k
    default:
369
        // error
370
115k
        return VLC_EGENERIC;
371
285k
    }
372
373
169k
    switch(p_cfg->i_object_type)
374
169k
    {
375
2.33k
    case MPEG4_AOT_ER_AAC_LC:
376
4.97k
    case MPEG4_AOT_ER_AAC_LTP:
377
9.77k
    case MPEG4_AOT_ER_AAC_SC:
378
11.3k
    case MPEG4_AOT_ER_TWINVQ:
379
76.3k
    case MPEG4_AOT_ER_BSAC:
380
77.9k
    case MPEG4_AOT_ER_AAC_LD:
381
79.4k
    case MPEG4_AOT_ER_CELP:
382
83.7k
    case MPEG4_AOT_ER_HXVC:
383
85.6k
    case MPEG4_AOT_ER_HILN:
384
88.0k
    case MPEG4_AOT_ER_Parametric:
385
88.7k
    case MPEG4_AOT_ER_AAC_ELD:
386
88.7k
    {
387
88.7k
        int epConfig = bs_read(s, 2);
388
88.7k
        if (epConfig == 2 || epConfig == 3)
389
            //ErrorProtectionSpecificConfig();
390
9.49k
            if (epConfig == 3)
391
6.51k
                if (bs_read1(s)) {
392
                    // TODO : directMapping
393
5.36k
                }
394
88.7k
        break;
395
88.0k
    }
396
81.1k
    default:
397
81.1k
        break;
398
169k
    }
399
400
169k
    if (b_withext && p_cfg->extension.i_object_type != MPEG4_AOT_AAC_SBR &&
401
83.8k
        !bs_eof(s) && bs_read(s, 11) == 0x2b7)
402
1.12k
    {
403
1.12k
        p_cfg->extension.i_object_type = MPEG4_read_AudioObjectType(s);
404
1.12k
        if (p_cfg->extension.i_object_type == MPEG4_AOT_AAC_SBR)
405
405
        {
406
405
            p_cfg->i_sbr  = bs_read1(s);
407
405
            if (p_cfg->i_sbr == 1) {
408
199
                p_cfg->extension.i_samplerate = MPEG4_read_AudioSamplerate(s);
409
199
                if (bs_read(s, 11) == 0x548)
410
179
                    p_cfg->i_ps = bs_read1(s);
411
199
            }
412
405
        }
413
715
        else if (p_cfg->extension.i_object_type == MPEG4_AOT_ER_BSAC)
414
162
        {
415
162
            p_cfg->i_sbr  = bs_read1(s);
416
162
            if(p_cfg->i_sbr)
417
11
                p_cfg->extension.i_samplerate = MPEG4_read_AudioSamplerate(s);
418
162
            p_cfg->extension.i_channel_configuration = bs_read(s, 4);
419
162
        }
420
1.12k
    }
421
422
#if 0
423
    static const char *ppsz_otype[] = {
424
        "NULL",
425
        "AAC Main", "AAC LC", "AAC SSR", "AAC LTP", "SBR", "AAC Scalable",
426
        "TwinVQ",
427
        "CELP", "HVXC",
428
        "Reserved", "Reserved",
429
        "TTSI",
430
        "Main Synthetic", "Wavetables Synthesis", "General MIDI",
431
        "Algorithmic Synthesis and Audio FX",
432
        "ER AAC LC",
433
        "Reserved",
434
        "ER AAC LTP", "ER AAC Scalable", "ER TwinVQ", "ER BSAC", "ER AAC LD",
435
        "ER CELP", "ER HVXC", "ER HILN", "ER Parametric",
436
        "SSC",
437
        "PS", "MPEG Surround", "Escape",
438
        "Layer 1", "Layer 2", "Layer 3",
439
        "DST", "ALS", "SLS", "SLS non-core", "ELD",
440
        "SMR Simple", "SMR Main",
441
    };
442
443
    fprintf(stderr, "MPEG4ReadAudioSpecificInfo: t=%s(%d)f=%d c=%d sbr=%d\n",
444
            ppsz_otype[p_cfg->i_object_type], p_cfg->i_object_type,
445
            p_cfg->i_samplerate, p_cfg->i_channel, p_cfg->i_sbr);
446
#endif
447
169k
    return bs_error(s) ? VLC_EGENERIC : VLC_SUCCESS;
448
169k
}
mpeg4audio.c:MPEG4_read_AudioSpecificConfig
Line
Count
Source
290
285k
{
291
285k
    p_cfg->i_object_type = MPEG4_read_AudioObjectType(s);
292
285k
    p_cfg->i_samplerate = MPEG4_read_AudioSamplerate(s);
293
285k
    p_cfg->i_channel_configuration = bs_read(s, 4);
294
295
285k
    p_cfg->i_sbr = -1;
296
285k
    p_cfg->i_ps  = -1;
297
285k
    p_cfg->extension.i_object_type = MPEG4_AOT_NULL;
298
285k
    p_cfg->extension.i_samplerate = 0;
299
285k
    p_cfg->extension.i_channel_configuration = 0;
300
285k
    p_cfg->i_frame_length = 0;
301
302
285k
    if (p_cfg->i_object_type == MPEG4_AOT_AAC_SBR ||
303
272k
        p_cfg->i_object_type == MPEG4_AOT_AAC_PS) {
304
16.8k
        p_cfg->i_sbr = 1;
305
16.8k
        if (p_cfg->i_object_type == MPEG4_AOT_AAC_PS)
306
3.98k
            p_cfg->i_ps = 1;
307
16.8k
        p_cfg->extension.i_object_type = MPEG4_AOT_AAC_SBR;
308
16.8k
        p_cfg->extension.i_samplerate = MPEG4_read_AudioSamplerate(s);
309
310
16.8k
        p_cfg->i_object_type = MPEG4_read_AudioObjectType(s);
311
16.8k
        if(p_cfg->i_object_type == MPEG4_AOT_ER_BSAC)
312
155
            p_cfg->extension.i_channel_configuration = bs_read(s, 4);
313
16.8k
    }
314
315
285k
    switch(p_cfg->i_object_type)
316
285k
    {
317
5.09k
    case MPEG4_AOT_AAC_MAIN:
318
22.8k
    case MPEG4_AOT_AAC_LC:
319
32.1k
    case MPEG4_AOT_AAC_SSR:
320
40.4k
    case MPEG4_AOT_AAC_LTP:
321
43.7k
    case MPEG4_AOT_AAC_SC:
322
47.9k
    case MPEG4_AOT_TWINVQ:
323
50.2k
    case MPEG4_AOT_ER_AAC_LC:
324
52.9k
    case MPEG4_AOT_ER_AAC_LTP:
325
57.7k
    case MPEG4_AOT_ER_AAC_SC:
326
59.3k
    case MPEG4_AOT_ER_TWINVQ:
327
124k
    case MPEG4_AOT_ER_BSAC:
328
125k
    case MPEG4_AOT_ER_AAC_LD:
329
125k
        MPEG4_read_GASpecificConfig(p_cfg, s);
330
125k
        break;
331
5.94k
    case MPEG4_AOT_CELP:
332
        // CelpSpecificConfig();
333
15.0k
    case MPEG4_AOT_HVXC:
334
        // HvxcSpecificConfig();
335
16.1k
    case MPEG4_AOT_TTSI:
336
        // TTSSSpecificConfig();
337
18.9k
    case MPEG4_AOT_MAIN_SYNTHETIC:
338
20.7k
    case MPEG4_AOT_WAVETABLES:
339
25.1k
    case MPEG4_AOT_GENERAL_MIDI:
340
30.3k
    case MPEG4_AOT_ALGORITHMIC:
341
        // StructuredAudioSpecificConfig();
342
31.8k
    case MPEG4_AOT_ER_CELP:
343
        // ERCelpSpecificConfig();
344
36.1k
    case MPEG4_AOT_ER_HXVC:
345
        // ERHvxcSpecificConfig();
346
38.0k
    case MPEG4_AOT_ER_HILN:
347
40.3k
    case MPEG4_AOT_ER_Parametric:
348
        // ParametricSpecificConfig();
349
42.6k
    case MPEG4_AOT_SSC:
350
        // SSCSpecificConfig();
351
42.8k
    case MPEG4_AOT_LAYER1:
352
42.8k
    case MPEG4_AOT_LAYER2:
353
42.9k
    case MPEG4_AOT_LAYER3:
354
        // MPEG_1_2_SpecificConfig();
355
43.0k
    case MPEG4_AOT_DST:
356
        // DSTSpecificConfig();
357
43.0k
    case MPEG4_AOT_ALS:
358
        // ALSSpecificConfig();
359
43.1k
    case MPEG4_AOT_SLS:
360
43.2k
    case MPEG4_AOT_SLS_NON_CORE:
361
        // SLSSpecificConfig();
362
43.9k
    case MPEG4_AOT_ER_AAC_ELD:
363
43.9k
        MPEG4_read_ELDSpecificConfig(p_cfg, s);
364
43.9k
        break;
365
0
    case MPEG4_AOT_SMR_SIMPLE:
366
0
    case MPEG4_AOT_SMR_MAIN:
367
        // SymbolicMusicSpecificConfig();
368
115k
    default:
369
        // error
370
115k
        return VLC_EGENERIC;
371
285k
    }
372
373
169k
    switch(p_cfg->i_object_type)
374
169k
    {
375
2.33k
    case MPEG4_AOT_ER_AAC_LC:
376
4.97k
    case MPEG4_AOT_ER_AAC_LTP:
377
9.77k
    case MPEG4_AOT_ER_AAC_SC:
378
11.3k
    case MPEG4_AOT_ER_TWINVQ:
379
76.3k
    case MPEG4_AOT_ER_BSAC:
380
77.9k
    case MPEG4_AOT_ER_AAC_LD:
381
79.4k
    case MPEG4_AOT_ER_CELP:
382
83.7k
    case MPEG4_AOT_ER_HXVC:
383
85.6k
    case MPEG4_AOT_ER_HILN:
384
88.0k
    case MPEG4_AOT_ER_Parametric:
385
88.7k
    case MPEG4_AOT_ER_AAC_ELD:
386
88.7k
    {
387
88.7k
        int epConfig = bs_read(s, 2);
388
88.7k
        if (epConfig == 2 || epConfig == 3)
389
            //ErrorProtectionSpecificConfig();
390
9.49k
            if (epConfig == 3)
391
6.51k
                if (bs_read1(s)) {
392
                    // TODO : directMapping
393
5.36k
                }
394
88.7k
        break;
395
88.0k
    }
396
81.1k
    default:
397
81.1k
        break;
398
169k
    }
399
400
169k
    if (b_withext && p_cfg->extension.i_object_type != MPEG4_AOT_AAC_SBR &&
401
83.8k
        !bs_eof(s) && bs_read(s, 11) == 0x2b7)
402
1.12k
    {
403
1.12k
        p_cfg->extension.i_object_type = MPEG4_read_AudioObjectType(s);
404
1.12k
        if (p_cfg->extension.i_object_type == MPEG4_AOT_AAC_SBR)
405
405
        {
406
405
            p_cfg->i_sbr  = bs_read1(s);
407
405
            if (p_cfg->i_sbr == 1) {
408
199
                p_cfg->extension.i_samplerate = MPEG4_read_AudioSamplerate(s);
409
199
                if (bs_read(s, 11) == 0x548)
410
179
                    p_cfg->i_ps = bs_read1(s);
411
199
            }
412
405
        }
413
715
        else if (p_cfg->extension.i_object_type == MPEG4_AOT_ER_BSAC)
414
162
        {
415
162
            p_cfg->i_sbr  = bs_read1(s);
416
162
            if(p_cfg->i_sbr)
417
11
                p_cfg->extension.i_samplerate = MPEG4_read_AudioSamplerate(s);
418
162
            p_cfg->extension.i_channel_configuration = bs_read(s, 4);
419
162
        }
420
1.12k
    }
421
422
#if 0
423
    static const char *ppsz_otype[] = {
424
        "NULL",
425
        "AAC Main", "AAC LC", "AAC SSR", "AAC LTP", "SBR", "AAC Scalable",
426
        "TwinVQ",
427
        "CELP", "HVXC",
428
        "Reserved", "Reserved",
429
        "TTSI",
430
        "Main Synthetic", "Wavetables Synthesis", "General MIDI",
431
        "Algorithmic Synthesis and Audio FX",
432
        "ER AAC LC",
433
        "Reserved",
434
        "ER AAC LTP", "ER AAC Scalable", "ER TwinVQ", "ER BSAC", "ER AAC LD",
435
        "ER CELP", "ER HVXC", "ER HILN", "ER Parametric",
436
        "SSC",
437
        "PS", "MPEG Surround", "Escape",
438
        "Layer 1", "Layer 2", "Layer 3",
439
        "DST", "ALS", "SLS", "SLS non-core", "ELD",
440
        "SMR Simple", "SMR Main",
441
    };
442
443
    fprintf(stderr, "MPEG4ReadAudioSpecificInfo: t=%s(%d)f=%d c=%d sbr=%d\n",
444
            ppsz_otype[p_cfg->i_object_type], p_cfg->i_object_type,
445
            p_cfg->i_samplerate, p_cfg->i_channel, p_cfg->i_sbr);
446
#endif
447
169k
    return bs_error(s) ? VLC_EGENERIC : VLC_SUCCESS;
448
169k
}
Unexecuted instantiation: faad.c:MPEG4_read_AudioSpecificConfig
449
450
#define MPEG4_STREAM_MAX_EXTRADATA 64
451
typedef struct
452
{
453
    uint8_t i_program;
454
    uint8_t i_layer;
455
456
    unsigned i_frame_length;         // type 1
457
    uint8_t i_frame_length_type;
458
    uint8_t i_frame_length_index;   // type 3 4 5 6 7
459
460
    MPEG4_asc_t cfg;
461
462
    /* Raw configuration */
463
    size_t i_extra;
464
    uint8_t extra[MPEG4_STREAM_MAX_EXTRADATA];
465
466
} MPEG4_audio_stream_t;
467
468
#define MPEG4_STREAMMUX_MAX_LAYER   8
469
#define MPEG4_STREAMMUX_MAX_PROGRAM 16
470
typedef struct
471
{
472
    bool allStreamsSameTimeFraming;
473
    uint8_t numSubFrames;
474
    uint8_t numProgram;
475
476
    uint8_t p_numLayer[MPEG4_STREAMMUX_MAX_PROGRAM];
477
478
    uint8_t pi_stream[MPEG4_STREAMMUX_MAX_PROGRAM][MPEG4_STREAMMUX_MAX_LAYER];
479
480
    uint8_t i_streams;
481
    MPEG4_audio_stream_t stream[MPEG4_STREAMMUX_MAX_PROGRAM*MPEG4_STREAMMUX_MAX_LAYER];
482
483
    uint32_t otherDataLenBits;
484
} MPEG4_streammux_config_t;
485
486
static inline uint32_t MPEG4_LatmGetValue(bs_t *s)
487
33.1k
{
488
33.1k
    uint32_t v = 0;
489
73.6k
    for (int i = 1 + bs_read(s, 2); i > 0; i--)
490
40.4k
        v = (v << 8) + bs_read(s, 8);
491
33.1k
    return v;
492
33.1k
}
mpeg4audio.c:MPEG4_LatmGetValue
Line
Count
Source
487
33.1k
{
488
33.1k
    uint32_t v = 0;
489
73.6k
    for (int i = 1 + bs_read(s, 2); i > 0; i--)
490
40.4k
        v = (v << 8) + bs_read(s, 8);
491
33.1k
    return v;
492
33.1k
}
Unexecuted instantiation: faad.c:MPEG4_LatmGetValue
493
494
static inline size_t AudioSpecificConfigBitsToBytes(bs_t *s, uint32_t i_bits, uint8_t *p_data)
495
207k
{
496
207k
    size_t i_extra = __MIN((i_bits + 7) / 8, MPEG4_STREAM_MAX_EXTRADATA);
497
2.21M
    for (size_t i = 0; i < i_extra; i++) {
498
2.00M
        const uint32_t i_read = __MIN(8, i_bits - 8*i);
499
2.00M
        p_data[i] = bs_read(s, i_read) << (8-i_read);
500
2.00M
    }
501
207k
    return i_extra;
502
207k
}
mpeg4audio.c:AudioSpecificConfigBitsToBytes
Line
Count
Source
495
207k
{
496
207k
    size_t i_extra = __MIN((i_bits + 7) / 8, MPEG4_STREAM_MAX_EXTRADATA);
497
2.21M
    for (size_t i = 0; i < i_extra; i++) {
498
2.00M
        const uint32_t i_read = __MIN(8, i_bits - 8*i);
499
2.00M
        p_data[i] = bs_read(s, i_read) << (8-i_read);
500
2.00M
    }
501
207k
    return i_extra;
502
207k
}
Unexecuted instantiation: faad.c:AudioSpecificConfigBitsToBytes
503
504
static inline int MPEG4_parse_StreamMuxConfig(bs_t *s, MPEG4_streammux_config_t *m)
505
13.9k
{
506
13.9k
    bool audioMuxVersion;
507
508
13.9k
    audioMuxVersion = bs_read(s, 1);
509
13.9k
    if (audioMuxVersion) {
510
3.47k
        if (bs_read(s, 1) != 0) /* support only audioMuxVersionA=0 */
511
23
            return -1;
512
3.47k
    }
513
514
13.9k
    memset(m, 0, sizeof(*m));
515
516
13.9k
    if (audioMuxVersion)
517
3.44k
        MPEG4_LatmGetValue(s); /* taraBufferFullness */
518
519
13.9k
    if(bs_eof(s))
520
141
        return -1;
521
522
13.8k
    m->allStreamsSameTimeFraming = bs_read1(s);
523
13.8k
    m->numSubFrames = bs_read(s, 6);
524
13.8k
    m->numProgram = bs_read(s, 4);
525
526
95.0k
    for (uint8_t i_program = 0; i_program <= m->numProgram; i_program++) {
527
85.2k
        if(bs_eof(s))
528
3.96k
            return -1;
529
81.2k
        m->p_numLayer[i_program] = bs_read(s, 3);
530
531
435k
        for (uint8_t i_layer = 0; i_layer <= m->p_numLayer[i_program]; i_layer++) {
532
353k
            MPEG4_audio_stream_t *st = &m->stream[m->i_streams];
533
353k
            bool b_previous_cfg;
534
535
353k
            m->pi_stream[i_program][i_layer] = m->i_streams;
536
353k
            st->i_program = i_program;
537
353k
            st->i_layer = i_layer;
538
539
353k
            b_previous_cfg = false;
540
353k
            if (i_program != 0 || i_layer != 0)
541
340k
                b_previous_cfg = bs_read1(s);
542
543
353k
            if (b_previous_cfg) {
544
146k
                assert(m->i_streams > 0);
545
146k
                st->cfg = m->stream[m->i_streams-1].cfg;
546
207k
            } else {
547
207k
                uint32_t asc_size = 0;
548
207k
                if(audioMuxVersion)
549
29.5k
                    asc_size = MPEG4_LatmGetValue(s);
550
207k
                bs_t asc_bs = *s;
551
207k
                MPEG4_read_AudioSpecificConfig(&asc_bs, &st->cfg, audioMuxVersion);
552
207k
                if (!audioMuxVersion)
553
178k
                    asc_size = bs_pos(&asc_bs) - bs_pos(s);
554
207k
                asc_bs = *s;
555
207k
                st->i_extra = AudioSpecificConfigBitsToBytes(&asc_bs, asc_size, st->extra);
556
207k
                bs_skip(s, asc_size);
557
207k
            }
558
559
353k
            st->i_frame_length_type = bs_read(s, 3);
560
353k
            switch(st->i_frame_length_type)
561
353k
            {
562
118k
            case 0:
563
118k
            {
564
118k
                bs_skip(s, 8); /* latmBufferFullnes */
565
118k
                if (!m->allStreamsSameTimeFraming)
566
26.5k
                    if (st->cfg.i_object_type == MPEG4_AOT_AAC_SC ||
567
26.3k
                        st->cfg.i_object_type == MPEG4_AOT_CELP ||
568
25.9k
                        st->cfg.i_object_type == MPEG4_AOT_ER_AAC_SC ||
569
25.8k
                        st->cfg.i_object_type == MPEG4_AOT_ER_CELP)
570
968
                        bs_skip(s, 6); /* eFrameOffset */
571
118k
                break;
572
0
            }
573
33.2k
            case 1:
574
33.2k
                st->i_frame_length = bs_read(s, 9);
575
33.2k
                break;
576
79.6k
            case 3: case 4: case 5:
577
79.6k
                st->i_frame_length_index = bs_read(s, 6); // celp
578
79.6k
                break;
579
101k
            case 6: case 7:
580
101k
                st->i_frame_length_index = bs_read(s, 1); // hvxc
581
121k
            default:
582
121k
                break;
583
353k
            }
584
            /* Next stream */
585
353k
            m->i_streams++;
586
353k
        }
587
81.2k
    }
588
589
9.84k
    if(bs_error(s) || bs_eof(s))
590
151
        return -1;
591
592
    /* other data */
593
9.69k
    if (bs_read1(s)) { // otherDataPresent
594
1.84k
        if (audioMuxVersion)
595
128
            m->otherDataLenBits = MPEG4_LatmGetValue(s);
596
1.72k
        else {
597
1.72k
            bool otherDataLenEsc;
598
5.43k
            do {
599
5.43k
                otherDataLenEsc = bs_read1(s);
600
5.43k
                m->otherDataLenBits = (m->otherDataLenBits << 8) + bs_read(s, 8);
601
5.43k
            } while (otherDataLenEsc);
602
1.72k
        }
603
1.84k
    }
604
7.84k
    else
605
7.84k
        m->otherDataLenBits = 0;
606
607
    /* crc */
608
9.69k
    if (bs_read1(s))
609
3.46k
        bs_skip(s, 8);
610
611
9.69k
    return bs_error(s) ? -1 : 0;
612
9.84k
}
mpeg4audio.c:MPEG4_parse_StreamMuxConfig
Line
Count
Source
505
13.9k
{
506
13.9k
    bool audioMuxVersion;
507
508
13.9k
    audioMuxVersion = bs_read(s, 1);
509
13.9k
    if (audioMuxVersion) {
510
3.47k
        if (bs_read(s, 1) != 0) /* support only audioMuxVersionA=0 */
511
23
            return -1;
512
3.47k
    }
513
514
13.9k
    memset(m, 0, sizeof(*m));
515
516
13.9k
    if (audioMuxVersion)
517
3.44k
        MPEG4_LatmGetValue(s); /* taraBufferFullness */
518
519
13.9k
    if(bs_eof(s))
520
141
        return -1;
521
522
13.8k
    m->allStreamsSameTimeFraming = bs_read1(s);
523
13.8k
    m->numSubFrames = bs_read(s, 6);
524
13.8k
    m->numProgram = bs_read(s, 4);
525
526
95.0k
    for (uint8_t i_program = 0; i_program <= m->numProgram; i_program++) {
527
85.2k
        if(bs_eof(s))
528
3.96k
            return -1;
529
81.2k
        m->p_numLayer[i_program] = bs_read(s, 3);
530
531
435k
        for (uint8_t i_layer = 0; i_layer <= m->p_numLayer[i_program]; i_layer++) {
532
353k
            MPEG4_audio_stream_t *st = &m->stream[m->i_streams];
533
353k
            bool b_previous_cfg;
534
535
353k
            m->pi_stream[i_program][i_layer] = m->i_streams;
536
353k
            st->i_program = i_program;
537
353k
            st->i_layer = i_layer;
538
539
353k
            b_previous_cfg = false;
540
353k
            if (i_program != 0 || i_layer != 0)
541
340k
                b_previous_cfg = bs_read1(s);
542
543
353k
            if (b_previous_cfg) {
544
146k
                assert(m->i_streams > 0);
545
146k
                st->cfg = m->stream[m->i_streams-1].cfg;
546
207k
            } else {
547
207k
                uint32_t asc_size = 0;
548
207k
                if(audioMuxVersion)
549
29.5k
                    asc_size = MPEG4_LatmGetValue(s);
550
207k
                bs_t asc_bs = *s;
551
207k
                MPEG4_read_AudioSpecificConfig(&asc_bs, &st->cfg, audioMuxVersion);
552
207k
                if (!audioMuxVersion)
553
178k
                    asc_size = bs_pos(&asc_bs) - bs_pos(s);
554
207k
                asc_bs = *s;
555
207k
                st->i_extra = AudioSpecificConfigBitsToBytes(&asc_bs, asc_size, st->extra);
556
207k
                bs_skip(s, asc_size);
557
207k
            }
558
559
353k
            st->i_frame_length_type = bs_read(s, 3);
560
353k
            switch(st->i_frame_length_type)
561
353k
            {
562
118k
            case 0:
563
118k
            {
564
118k
                bs_skip(s, 8); /* latmBufferFullnes */
565
118k
                if (!m->allStreamsSameTimeFraming)
566
26.5k
                    if (st->cfg.i_object_type == MPEG4_AOT_AAC_SC ||
567
26.3k
                        st->cfg.i_object_type == MPEG4_AOT_CELP ||
568
25.9k
                        st->cfg.i_object_type == MPEG4_AOT_ER_AAC_SC ||
569
25.8k
                        st->cfg.i_object_type == MPEG4_AOT_ER_CELP)
570
968
                        bs_skip(s, 6); /* eFrameOffset */
571
118k
                break;
572
0
            }
573
33.2k
            case 1:
574
33.2k
                st->i_frame_length = bs_read(s, 9);
575
33.2k
                break;
576
79.6k
            case 3: case 4: case 5:
577
79.6k
                st->i_frame_length_index = bs_read(s, 6); // celp
578
79.6k
                break;
579
101k
            case 6: case 7:
580
101k
                st->i_frame_length_index = bs_read(s, 1); // hvxc
581
121k
            default:
582
121k
                break;
583
353k
            }
584
            /* Next stream */
585
353k
            m->i_streams++;
586
353k
        }
587
81.2k
    }
588
589
9.84k
    if(bs_error(s) || bs_eof(s))
590
151
        return -1;
591
592
    /* other data */
593
9.69k
    if (bs_read1(s)) { // otherDataPresent
594
1.84k
        if (audioMuxVersion)
595
128
            m->otherDataLenBits = MPEG4_LatmGetValue(s);
596
1.72k
        else {
597
1.72k
            bool otherDataLenEsc;
598
5.43k
            do {
599
5.43k
                otherDataLenEsc = bs_read1(s);
600
5.43k
                m->otherDataLenBits = (m->otherDataLenBits << 8) + bs_read(s, 8);
601
5.43k
            } while (otherDataLenEsc);
602
1.72k
        }
603
1.84k
    }
604
7.84k
    else
605
7.84k
        m->otherDataLenBits = 0;
606
607
    /* crc */
608
9.69k
    if (bs_read1(s))
609
3.46k
        bs_skip(s, 8);
610
611
9.69k
    return bs_error(s) ? -1 : 0;
612
9.84k
}
Unexecuted instantiation: faad.c:MPEG4_parse_StreamMuxConfig