annotate mpegaudio.h @ 6017:e1404acccac3 libavcodec

Actually return with an error condition if we're being asked to deal with too many reference frames. Also check max num ref frames against our internal ref buffer sizes. Part of fix for roundup issue 281
author heydowns
date Fri, 14 Dec 2007 05:48:27 +0000
parents 1d83e9c34641
children c4a4495715dd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3699
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 2979
diff changeset
1 /*
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 2979
diff changeset
2 * copyright (c) 2001 Fabrice Bellard
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 2979
diff changeset
3 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3699
diff changeset
4 * This file is part of FFmpeg.
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3699
diff changeset
5 *
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3699
diff changeset
6 * FFmpeg is free software; you can redistribute it and/or
3699
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 2979
diff changeset
7 * modify it under the terms of the GNU Lesser General Public
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 2979
diff changeset
8 * License as published by the Free Software Foundation; either
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3699
diff changeset
9 * version 2.1 of the License, or (at your option) any later version.
3699
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 2979
diff changeset
10 *
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3699
diff changeset
11 * FFmpeg is distributed in the hope that it will be useful,
3699
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 2979
diff changeset
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 2979
diff changeset
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 2979
diff changeset
14 * Lesser General Public License for more details.
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 2979
diff changeset
15 *
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 2979
diff changeset
16 * You should have received a copy of the GNU Lesser General Public
3947
c8c591fe26f8 Change license headers to say 'FFmpeg' instead of 'this program/this library'
diego
parents: 3699
diff changeset
17 * License along with FFmpeg; if not, write to the Free Software
3699
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 2979
diff changeset
18 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 2979
diff changeset
19 */
c537a97eec66 Add official LGPL license headers to the files that were missing them.
diego
parents: 2979
diff changeset
20
1106
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
21 /**
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
22 * @file mpegaudio.h
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
23 * mpeg audio declarations for both encoder and decoder.
1e39f273ecd6 per file doxy
michaelni
parents: 1064
diff changeset
24 */
84
608c7f964bca merged code and tables between encoder and decoder
glantau
parents: 64
diff changeset
25
5830
1d83e9c34641 Add FFMPEG_ prefix to all multiple inclusion guards.
diego
parents: 5161
diff changeset
26 #ifndef FFMPEG_MPEGAUDIO_H
1d83e9c34641 Add FFMPEG_ prefix to all multiple inclusion guards.
diego
parents: 5161
diff changeset
27 #define FFMPEG_MPEGAUDIO_H
5050
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
28
5052
d981eb275c8f remove dependency of mpeg audio encoder over mpeg audio decoder
aurel
parents: 5051
diff changeset
29 #include "avcodec.h"
5050
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
30 #include "bitstream.h"
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
31 #include "dsputil.h"
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
32
84
608c7f964bca merged code and tables between encoder and decoder
glantau
parents: 64
diff changeset
33 /* max frame size, in samples */
2967
ef2149182f1c COSMETICS: Remove all trailing whitespace.
diego
parents: 2913
diff changeset
34 #define MPA_FRAME_SIZE 1152
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
35
986e461dc072 Initial revision
glantau
parents:
diff changeset
36 /* max compressed frame size */
84
608c7f964bca merged code and tables between encoder and decoder
glantau
parents: 64
diff changeset
37 #define MPA_MAX_CODED_FRAME_SIZE 1792
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
38
986e461dc072 Initial revision
glantau
parents:
diff changeset
39 #define MPA_MAX_CHANNELS 2
986e461dc072 Initial revision
glantau
parents:
diff changeset
40
986e461dc072 Initial revision
glantau
parents:
diff changeset
41 #define SBLIMIT 32 /* number of subbands */
84
608c7f964bca merged code and tables between encoder and decoder
glantau
parents: 64
diff changeset
42
608c7f964bca merged code and tables between encoder and decoder
glantau
parents: 64
diff changeset
43 #define MPA_STEREO 0
608c7f964bca merged code and tables between encoder and decoder
glantau
parents: 64
diff changeset
44 #define MPA_JSTEREO 1
608c7f964bca merged code and tables between encoder and decoder
glantau
parents: 64
diff changeset
45 #define MPA_DUAL 2
608c7f964bca merged code and tables between encoder and decoder
glantau
parents: 64
diff changeset
46 #define MPA_MONO 3
608c7f964bca merged code and tables between encoder and decoder
glantau
parents: 64
diff changeset
47
2472
021dc26e760f dithering for the mpeg audio decoder
michael
parents: 1612
diff changeset
48 /* header + layer + bitrate + freq + lsf/mpeg25 */
021dc26e760f dithering for the mpeg audio decoder
michael
parents: 1612
diff changeset
49 #define SAME_HEADER_MASK \
021dc26e760f dithering for the mpeg audio decoder
michael
parents: 1612
diff changeset
50 (0xffe00000 | (3 << 17) | (0xf << 12) | (3 << 10) | (3 << 19))
021dc26e760f dithering for the mpeg audio decoder
michael
parents: 1612
diff changeset
51
5033
3c034e71667f move mp3_header_decompress bitstream filter in its own file
aurel
parents: 5031
diff changeset
52 #define MP3_MASK 0xFFFE0CCF
3c034e71667f move mp3_header_decompress bitstream filter in its own file
aurel
parents: 5031
diff changeset
53
2913
cc55bc1f8d92 QDM2 compatible decoder
rtognimp
parents: 2472
diff changeset
54 /* define USE_HIGHPRECISION to have a bit exact (but slower) mpeg
cc55bc1f8d92 QDM2 compatible decoder
rtognimp
parents: 2472
diff changeset
55 audio decoder */
cc55bc1f8d92 QDM2 compatible decoder
rtognimp
parents: 2472
diff changeset
56
cc55bc1f8d92 QDM2 compatible decoder
rtognimp
parents: 2472
diff changeset
57 #ifdef USE_HIGHPRECISION
cc55bc1f8d92 QDM2 compatible decoder
rtognimp
parents: 2472
diff changeset
58 #define FRAC_BITS 23 /* fractional bits for sb_samples and dct */
cc55bc1f8d92 QDM2 compatible decoder
rtognimp
parents: 2472
diff changeset
59 #define WFRAC_BITS 16 /* fractional bits for window */
cc55bc1f8d92 QDM2 compatible decoder
rtognimp
parents: 2472
diff changeset
60 #else
cc55bc1f8d92 QDM2 compatible decoder
rtognimp
parents: 2472
diff changeset
61 #define FRAC_BITS 15 /* fractional bits for sb_samples and dct */
cc55bc1f8d92 QDM2 compatible decoder
rtognimp
parents: 2472
diff changeset
62 #define WFRAC_BITS 14 /* fractional bits for window */
cc55bc1f8d92 QDM2 compatible decoder
rtognimp
parents: 2472
diff changeset
63 #endif
cc55bc1f8d92 QDM2 compatible decoder
rtognimp
parents: 2472
diff changeset
64
5161
94c3f01c243c move a couple of macros and structs to mpegaudio.h
mru
parents: 5052
diff changeset
65 #define FRAC_ONE (1 << FRAC_BITS)
94c3f01c243c move a couple of macros and structs to mpegaudio.h
mru
parents: 5052
diff changeset
66
94c3f01c243c move a couple of macros and structs to mpegaudio.h
mru
parents: 5052
diff changeset
67 #define FIX(a) ((int)((a) * FRAC_ONE))
94c3f01c243c move a couple of macros and structs to mpegaudio.h
mru
parents: 5052
diff changeset
68
2913
cc55bc1f8d92 QDM2 compatible decoder
rtognimp
parents: 2472
diff changeset
69 #if defined(USE_HIGHPRECISION) && defined(CONFIG_AUDIO_NONSHORT)
cc55bc1f8d92 QDM2 compatible decoder
rtognimp
parents: 2472
diff changeset
70 typedef int32_t OUT_INT;
cc55bc1f8d92 QDM2 compatible decoder
rtognimp
parents: 2472
diff changeset
71 #define OUT_MAX INT32_MAX
cc55bc1f8d92 QDM2 compatible decoder
rtognimp
parents: 2472
diff changeset
72 #define OUT_MIN INT32_MIN
cc55bc1f8d92 QDM2 compatible decoder
rtognimp
parents: 2472
diff changeset
73 #define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 31)
cc55bc1f8d92 QDM2 compatible decoder
rtognimp
parents: 2472
diff changeset
74 #else
cc55bc1f8d92 QDM2 compatible decoder
rtognimp
parents: 2472
diff changeset
75 typedef int16_t OUT_INT;
cc55bc1f8d92 QDM2 compatible decoder
rtognimp
parents: 2472
diff changeset
76 #define OUT_MAX INT16_MAX
cc55bc1f8d92 QDM2 compatible decoder
rtognimp
parents: 2472
diff changeset
77 #define OUT_MIN INT16_MIN
cc55bc1f8d92 QDM2 compatible decoder
rtognimp
parents: 2472
diff changeset
78 #define OUT_SHIFT (WFRAC_BITS + FRAC_BITS - 15)
cc55bc1f8d92 QDM2 compatible decoder
rtognimp
parents: 2472
diff changeset
79 #endif
cc55bc1f8d92 QDM2 compatible decoder
rtognimp
parents: 2472
diff changeset
80
cc55bc1f8d92 QDM2 compatible decoder
rtognimp
parents: 2472
diff changeset
81 #if FRAC_BITS <= 15
cc55bc1f8d92 QDM2 compatible decoder
rtognimp
parents: 2472
diff changeset
82 typedef int16_t MPA_INT;
cc55bc1f8d92 QDM2 compatible decoder
rtognimp
parents: 2472
diff changeset
83 #else
cc55bc1f8d92 QDM2 compatible decoder
rtognimp
parents: 2472
diff changeset
84 typedef int32_t MPA_INT;
cc55bc1f8d92 QDM2 compatible decoder
rtognimp
parents: 2472
diff changeset
85 #endif
cc55bc1f8d92 QDM2 compatible decoder
rtognimp
parents: 2472
diff changeset
86
5050
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
87 #define BACKSTEP_SIZE 512
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
88 #define EXTRABYTES 24
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
89
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
90 struct GranuleDef;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
91
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
92 typedef struct MPADecodeContext {
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
93 DECLARE_ALIGNED_8(uint8_t, last_buf[2*BACKSTEP_SIZE + EXTRABYTES]);
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
94 int last_buf_size;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
95 int frame_size;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
96 /* next header (used in free format parsing) */
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
97 uint32_t free_format_next_header;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
98 int error_protection;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
99 int layer;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
100 int sample_rate;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
101 int sample_rate_index; /* between 0 and 8 */
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
102 int bit_rate;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
103 GetBitContext gb;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
104 GetBitContext in_gb;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
105 int nb_channels;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
106 int mode;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
107 int mode_ext;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
108 int lsf;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
109 DECLARE_ALIGNED_16(MPA_INT, synth_buf[MPA_MAX_CHANNELS][512 * 2]);
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
110 int synth_buf_offset[MPA_MAX_CHANNELS];
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
111 DECLARE_ALIGNED_16(int32_t, sb_samples[MPA_MAX_CHANNELS][36][SBLIMIT]);
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
112 int32_t mdct_buf[MPA_MAX_CHANNELS][SBLIMIT * 18]; /* previous samples, for layer 3 MDCT */
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
113 #ifdef DEBUG
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
114 int frame_count;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
115 #endif
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
116 void (*compute_antialias)(struct MPADecodeContext *s, struct GranuleDef *g);
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
117 int adu_mode; ///< 0 for standard mp3, 1 for adu formatted mp3
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
118 int dither_state;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
119 int error_resilience;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
120 AVCodecContext* avctx;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
121 } MPADecodeContext;
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
122
5161
94c3f01c243c move a couple of macros and structs to mpegaudio.h
mru
parents: 5052
diff changeset
123 /* layer 3 huffman tables */
94c3f01c243c move a couple of macros and structs to mpegaudio.h
mru
parents: 5052
diff changeset
124 typedef struct HuffTable {
94c3f01c243c move a couple of macros and structs to mpegaudio.h
mru
parents: 5052
diff changeset
125 int xsize;
94c3f01c243c move a couple of macros and structs to mpegaudio.h
mru
parents: 5052
diff changeset
126 const uint8_t *bits;
94c3f01c243c move a couple of macros and structs to mpegaudio.h
mru
parents: 5052
diff changeset
127 const uint16_t *codes;
94c3f01c243c move a couple of macros and structs to mpegaudio.h
mru
parents: 5052
diff changeset
128 } HuffTable;
94c3f01c243c move a couple of macros and structs to mpegaudio.h
mru
parents: 5052
diff changeset
129
5052
d981eb275c8f remove dependency of mpeg audio encoder over mpeg audio decoder
aurel
parents: 5051
diff changeset
130 int ff_mpa_l2_select_table(int bitrate, int nb_channels, int freq, int lsf);
5051
b908c67063c8 add a ff_ prefix to some mpegaudio funcs
aurel
parents: 5050
diff changeset
131 int ff_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate);
2913
cc55bc1f8d92 QDM2 compatible decoder
rtognimp
parents: 2472
diff changeset
132 void ff_mpa_synth_init(MPA_INT *window);
cc55bc1f8d92 QDM2 compatible decoder
rtognimp
parents: 2472
diff changeset
133 void ff_mpa_synth_filter(MPA_INT *synth_buf_ptr, int *synth_buf_offset,
2979
bfabfdf9ce55 COSMETICS: tabs --> spaces, some prettyprinting
diego
parents: 2967
diff changeset
134 MPA_INT *window, int *dither_state,
2913
cc55bc1f8d92 QDM2 compatible decoder
rtognimp
parents: 2472
diff changeset
135 OUT_INT *samples, int incr,
cc55bc1f8d92 QDM2 compatible decoder
rtognimp
parents: 2472
diff changeset
136 int32_t sb_samples[SBLIMIT]);
0
986e461dc072 Initial revision
glantau
parents:
diff changeset
137
2472
021dc26e760f dithering for the mpeg audio decoder
michael
parents: 1612
diff changeset
138 /* fast header check for resync */
021dc26e760f dithering for the mpeg audio decoder
michael
parents: 1612
diff changeset
139 static inline int ff_mpa_check_header(uint32_t header){
021dc26e760f dithering for the mpeg audio decoder
michael
parents: 1612
diff changeset
140 /* header */
021dc26e760f dithering for the mpeg audio decoder
michael
parents: 1612
diff changeset
141 if ((header & 0xffe00000) != 0xffe00000)
021dc26e760f dithering for the mpeg audio decoder
michael
parents: 1612
diff changeset
142 return -1;
021dc26e760f dithering for the mpeg audio decoder
michael
parents: 1612
diff changeset
143 /* layer check */
021dc26e760f dithering for the mpeg audio decoder
michael
parents: 1612
diff changeset
144 if ((header & (3<<17)) == 0)
021dc26e760f dithering for the mpeg audio decoder
michael
parents: 1612
diff changeset
145 return -1;
021dc26e760f dithering for the mpeg audio decoder
michael
parents: 1612
diff changeset
146 /* bit rate */
021dc26e760f dithering for the mpeg audio decoder
michael
parents: 1612
diff changeset
147 if ((header & (0xf<<12)) == 0xf<<12)
021dc26e760f dithering for the mpeg audio decoder
michael
parents: 1612
diff changeset
148 return -1;
021dc26e760f dithering for the mpeg audio decoder
michael
parents: 1612
diff changeset
149 /* frequency */
021dc26e760f dithering for the mpeg audio decoder
michael
parents: 1612
diff changeset
150 if ((header & (3<<10)) == 3<<10)
021dc26e760f dithering for the mpeg audio decoder
michael
parents: 1612
diff changeset
151 return -1;
021dc26e760f dithering for the mpeg audio decoder
michael
parents: 1612
diff changeset
152 return 0;
021dc26e760f dithering for the mpeg audio decoder
michael
parents: 1612
diff changeset
153 }
5050
a5f6fbc9fa66 loosen dependencies over mpegaudiodec
aurel
parents: 5033
diff changeset
154
5830
1d83e9c34641 Add FFMPEG_ prefix to all multiple inclusion guards.
diego
parents: 5161
diff changeset
155 #endif /* FFMPEG_MPEGAUDIO_H */