Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 147 lines (132 sloc) 4.173 kb
4bd8e17 aurelj loosen dependencies over mpegaudiodec
aurelj authored
1 /*
2 * MPEG Audio header decoder
406792e Diego Biurrun cosmetics: Remove pointless period after copyright statement non-sentenc...
DonDiego authored
3 * Copyright (c) 2001, 2002 Fabrice Bellard
4bd8e17 aurelj loosen dependencies over mpegaudiodec
aurelj authored
4 *
5 * This file is part of FFmpeg.
6 *
7 * FFmpeg is free software; you can redistribute it and/or
8 * modify it under the terms of the GNU Lesser General Public
9 * License as published by the Free Software Foundation; either
10 * version 2.1 of the License, or (at your option) any later version.
11 *
12 * FFmpeg is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15 * Lesser General Public License for more details.
16 *
17 * You should have received a copy of the GNU Lesser General Public
18 * License along with FFmpeg; if not, write to the Free Software
19 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
20 */
21
22 /**
ba87f08 Diego Biurrun Remove explicit filename from Doxygen @file commands.
DonDiego authored
23 * @file
4bd8e17 aurelj loosen dependencies over mpegaudiodec
aurelj authored
24 * MPEG Audio header decoder.
25 */
26
27 //#define DEBUG
28 #include "avcodec.h"
29 #include "mpegaudio.h"
30 #include "mpegaudiodata.h"
c6e1599 Include mpegaudiodecheader.h: It contains the prototype for
Carl Eugen Hoyos authored
31 #include "mpegaudiodecheader.h"
4bd8e17 aurelj loosen dependencies over mpegaudiodec
aurelj authored
32
33
82ab61f elenril lavc: use avpriv_ prefix for some mpegaudio symbols used in lavf.
elenril authored
34 int avpriv_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header)
4bd8e17 aurelj loosen dependencies over mpegaudiodec
aurelj authored
35 {
36 int sample_rate, frame_size, mpeg25, padding;
37 int sample_rate_index, bitrate_index;
38 if (header & (1<<20)) {
39 s->lsf = (header & (1<<19)) ? 0 : 1;
40 mpeg25 = 0;
41 } else {
42 s->lsf = 1;
43 mpeg25 = 1;
44 }
45
46 s->layer = 4 - ((header >> 17) & 3);
47 /* extract frequency */
48 sample_rate_index = (header >> 10) & 3;
82ab61f elenril lavc: use avpriv_ prefix for some mpegaudio symbols used in lavf.
elenril authored
49 sample_rate = avpriv_mpa_freq_tab[sample_rate_index] >> (s->lsf + mpeg25);
4bd8e17 aurelj loosen dependencies over mpegaudiodec
aurelj authored
50 sample_rate_index += 3 * (s->lsf + mpeg25);
51 s->sample_rate_index = sample_rate_index;
52 s->error_protection = ((header >> 16) & 1) ^ 1;
53 s->sample_rate = sample_rate;
54
55 bitrate_index = (header >> 12) & 0xf;
56 padding = (header >> 9) & 1;
57 //extension = (header >> 8) & 1;
58 s->mode = (header >> 6) & 3;
59 s->mode_ext = (header >> 4) & 3;
60 //copyright = (header >> 3) & 1;
61 //original = (header >> 2) & 1;
62 //emphasis = header & 3;
63
64 if (s->mode == MPA_MONO)
65 s->nb_channels = 1;
66 else
67 s->nb_channels = 2;
68
69 if (bitrate_index != 0) {
82ab61f elenril lavc: use avpriv_ prefix for some mpegaudio symbols used in lavf.
elenril authored
70 frame_size = avpriv_mpa_bitrate_tab[s->lsf][s->layer - 1][bitrate_index];
4bd8e17 aurelj loosen dependencies over mpegaudiodec
aurelj authored
71 s->bit_rate = frame_size * 1000;
72 switch(s->layer) {
73 case 1:
74 frame_size = (frame_size * 12000) / sample_rate;
75 frame_size = (frame_size + padding) * 4;
76 break;
77 case 2:
78 frame_size = (frame_size * 144000) / sample_rate;
79 frame_size += padding;
80 break;
81 default:
82 case 3:
83 frame_size = (frame_size * 144000) / (sample_rate << s->lsf);
84 frame_size += padding;
85 break;
86 }
87 s->frame_size = frame_size;
88 } else {
89 /* if no frame size computed, signal it */
90 return 1;
91 }
92
93 #if defined(DEBUG)
9ef5a9d Luca Barbato Replace dprintf with av_dlog
lu-zero authored
94 av_dlog(NULL, "layer%d, %d Hz, %d kbits/s, ",
4bd8e17 aurelj loosen dependencies over mpegaudiodec
aurelj authored
95 s->layer, s->sample_rate, s->bit_rate);
96 if (s->nb_channels == 2) {
97 if (s->layer == 3) {
98 if (s->mode_ext & MODE_EXT_MS_STEREO)
9ef5a9d Luca Barbato Replace dprintf with av_dlog
lu-zero authored
99 av_dlog(NULL, "ms-");
4bd8e17 aurelj loosen dependencies over mpegaudiodec
aurelj authored
100 if (s->mode_ext & MODE_EXT_I_STEREO)
9ef5a9d Luca Barbato Replace dprintf with av_dlog
lu-zero authored
101 av_dlog(NULL, "i-");
4bd8e17 aurelj loosen dependencies over mpegaudiodec
aurelj authored
102 }
9ef5a9d Luca Barbato Replace dprintf with av_dlog
lu-zero authored
103 av_dlog(NULL, "stereo");
4bd8e17 aurelj loosen dependencies over mpegaudiodec
aurelj authored
104 } else {
9ef5a9d Luca Barbato Replace dprintf with av_dlog
lu-zero authored
105 av_dlog(NULL, "mono");
4bd8e17 aurelj loosen dependencies over mpegaudiodec
aurelj authored
106 }
9ef5a9d Luca Barbato Replace dprintf with av_dlog
lu-zero authored
107 av_dlog(NULL, "\n");
4bd8e17 aurelj loosen dependencies over mpegaudiodec
aurelj authored
108 #endif
109 return 0;
110 }
0199e00 Mans Rullgard mpegaudio: move all header parsing to mpegaudiodecheader.[ch]
mansr authored
111
82ab61f elenril lavc: use avpriv_ prefix for some mpegaudio symbols used in lavf.
elenril authored
112 int avpriv_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bit_rate)
0199e00 Mans Rullgard mpegaudio: move all header parsing to mpegaudiodecheader.[ch]
mansr authored
113 {
114 MPADecodeHeader s1, *s = &s1;
115
116 if (ff_mpa_check_header(head) != 0)
117 return -1;
118
82ab61f elenril lavc: use avpriv_ prefix for some mpegaudio symbols used in lavf.
elenril authored
119 if (avpriv_mpegaudio_decode_header(s, head) != 0) {
0199e00 Mans Rullgard mpegaudio: move all header parsing to mpegaudiodecheader.[ch]
mansr authored
120 return -1;
121 }
122
123 switch(s->layer) {
124 case 1:
36ef536 elenril Replace all CODEC_ID_* with AV_CODEC_ID_*
elenril authored
125 avctx->codec_id = AV_CODEC_ID_MP1;
0199e00 Mans Rullgard mpegaudio: move all header parsing to mpegaudiodecheader.[ch]
mansr authored
126 *frame_size = 384;
127 break;
128 case 2:
36ef536 elenril Replace all CODEC_ID_* with AV_CODEC_ID_*
elenril authored
129 avctx->codec_id = AV_CODEC_ID_MP2;
0199e00 Mans Rullgard mpegaudio: move all header parsing to mpegaudiodecheader.[ch]
mansr authored
130 *frame_size = 1152;
131 break;
132 default:
133 case 3:
36ef536 elenril Replace all CODEC_ID_* with AV_CODEC_ID_*
elenril authored
134 avctx->codec_id = AV_CODEC_ID_MP3;
0199e00 Mans Rullgard mpegaudio: move all header parsing to mpegaudiodecheader.[ch]
mansr authored
135 if (s->lsf)
136 *frame_size = 576;
137 else
138 *frame_size = 1152;
139 break;
140 }
141
142 *sample_rate = s->sample_rate;
143 *channels = s->nb_channels;
144 *bit_rate = s->bit_rate;
145 return s->frame_size;
146 }
Something went wrong with that request. Please try again.