annotate mpegaudiodecheader.c @ 12180:b24153464669 libavcodec

Attempt to fix x86-64 testsuite on fate.
author rbultje
date Fri, 16 Jul 2010 21:35:30 +0000
parents 7dd2a45249a9
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
5050
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
1 /*
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
2 * MPEG Audio header decoder
8629
04423b2f6e0b cosmetics: Remove pointless period after copyright statement non-sentences.
diego
parents: 5051
diff changeset
3 * Copyright (c) 2001, 2002 Fabrice Bellard
5050
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
4 *
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
5 * This file is part of FFmpeg.
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
6 *
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
7 * FFmpeg is free software; you can redistribute it and/or
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
8 * modify it under the terms of the GNU Lesser General Public
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
9 * License as published by the Free Software Foundation; either
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
10 * version 2.1 of the License, or (at your option) any later version.
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
11 *
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
12 * FFmpeg is distributed in the hope that it will be useful,
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
15 * Lesser General Public License for more details.
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
16 *
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
17 * You should have received a copy of the GNU Lesser General Public
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
18 * License along with FFmpeg; if not, write to the Free Software
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
20 */
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
21
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
22 /**
11644
7dd2a45249a9 Remove explicit filename from Doxygen @file commands.
diego
parents: 11315
diff changeset
23 * @file
5050
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
24 * MPEG Audio header decoder.
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
25 */
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
26
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
27 //#define DEBUG
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
28 #include "avcodec.h"
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
29 #include "mpegaudio.h"
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
30 #include "mpegaudiodata.h"
11315
5f7c1d0e4104 Include mpegaudiodecheader.h: It contains the prototype for
cehoyos
parents: 9740
diff changeset
31 #include "mpegaudiodecheader.h"
5050
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
32
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
33
8641
54e2916c25a5 Avoid allocating MPADecodeContext on stack.
andoma
parents: 8629
diff changeset
34 int ff_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header)
5050
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
35 {
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
36 int sample_rate, frame_size, mpeg25, padding;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
37 int sample_rate_index, bitrate_index;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
38 if (header & (1<<20)) {
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
39 s->lsf = (header & (1<<19)) ? 0 : 1;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
40 mpeg25 = 0;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
41 } else {
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
42 s->lsf = 1;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
43 mpeg25 = 1;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
44 }
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
45
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
46 s->layer = 4 - ((header >> 17) & 3);
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
47 /* extract frequency */
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
48 sample_rate_index = (header >> 10) & 3;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
49 sample_rate = ff_mpa_freq_tab[sample_rate_index] >> (s->lsf + mpeg25);
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
50 sample_rate_index += 3 * (s->lsf + mpeg25);
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
51 s->sample_rate_index = sample_rate_index;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
52 s->error_protection = ((header >> 16) & 1) ^ 1;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
53 s->sample_rate = sample_rate;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
54
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
55 bitrate_index = (header >> 12) & 0xf;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
56 padding = (header >> 9) & 1;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
57 //extension = (header >> 8) & 1;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
58 s->mode = (header >> 6) & 3;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
59 s->mode_ext = (header >> 4) & 3;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
60 //copyright = (header >> 3) & 1;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
61 //original = (header >> 2) & 1;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
62 //emphasis = header & 3;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
63
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
64 if (s->mode == MPA_MONO)
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
65 s->nb_channels = 1;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
66 else
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
67 s->nb_channels = 2;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
68
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
69 if (bitrate_index != 0) {
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
70 frame_size = ff_mpa_bitrate_tab[s->lsf][s->layer - 1][bitrate_index];
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
71 s->bit_rate = frame_size * 1000;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
72 switch(s->layer) {
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
73 case 1:
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
74 frame_size = (frame_size * 12000) / sample_rate;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
75 frame_size = (frame_size + padding) * 4;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
76 break;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
77 case 2:
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
78 frame_size = (frame_size * 144000) / sample_rate;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
79 frame_size += padding;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
80 break;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
81 default:
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
82 case 3:
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
83 frame_size = (frame_size * 144000) / (sample_rate << s->lsf);
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
84 frame_size += padding;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
85 break;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
86 }
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
87 s->frame_size = frame_size;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
88 } else {
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
89 /* if no frame size computed, signal it */
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
90 return 1;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
91 }
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
92
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
93 #if defined(DEBUG)
9740
30b00f4bdeb1 fix compilation with DEBUG defined
bcoudurier
parents: 8718
diff changeset
94 dprintf(NULL, "layer%d, %d Hz, %d kbits/s, ",
5050
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
95 s->layer, s->sample_rate, s->bit_rate);
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
96 if (s->nb_channels == 2) {
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
97 if (s->layer == 3) {
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
98 if (s->mode_ext & MODE_EXT_MS_STEREO)
9740
30b00f4bdeb1 fix compilation with DEBUG defined
bcoudurier
parents: 8718
diff changeset
99 dprintf(NULL, "ms-");
5050
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
100 if (s->mode_ext & MODE_EXT_I_STEREO)
9740
30b00f4bdeb1 fix compilation with DEBUG defined
bcoudurier
parents: 8718
diff changeset
101 dprintf(NULL, "i-");
5050
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
102 }
9740
30b00f4bdeb1 fix compilation with DEBUG defined
bcoudurier
parents: 8718
diff changeset
103 dprintf(NULL, "stereo");
5050
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
104 } else {
9740
30b00f4bdeb1 fix compilation with DEBUG defined
bcoudurier
parents: 8718
diff changeset
105 dprintf(NULL, "mono");
5050
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
106 }
9740
30b00f4bdeb1 fix compilation with DEBUG defined
bcoudurier
parents: 8718
diff changeset
107 dprintf(NULL, "\n");
5050
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
108 #endif
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
109 return 0;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents:
diff changeset
110 }