Commit cf92cec7 authored by Andreas Öman's avatar Andreas Öman

Avoid allocating MPADecodeContext on stack.

Instead move relevant fields into MPADecodeHeader and use it
where appropriate.

Originally committed as revision 16728 to svn://svn.ffmpeg.org/ffmpeg/trunk
parent 2d4eeaad
...@@ -90,23 +90,30 @@ typedef int32_t MPA_INT; ...@@ -90,23 +90,30 @@ typedef int32_t MPA_INT;
struct GranuleDef; struct GranuleDef;
#define MPA_DECODE_HEADER \
int frame_size; \
int error_protection; \
int layer; \
int sample_rate; \
int sample_rate_index; /* between 0 and 8 */ \
int bit_rate; \
int nb_channels; \
int mode; \
int mode_ext; \
int lsf;
typedef struct MPADecodeHeader {
MPA_DECODE_HEADER
} MPADecodeHeader;
typedef struct MPADecodeContext { typedef struct MPADecodeContext {
MPA_DECODE_HEADER
DECLARE_ALIGNED_8(uint8_t, last_buf[2*BACKSTEP_SIZE + EXTRABYTES]); DECLARE_ALIGNED_8(uint8_t, last_buf[2*BACKSTEP_SIZE + EXTRABYTES]);
int last_buf_size; int last_buf_size;
int frame_size;
/* next header (used in free format parsing) */ /* next header (used in free format parsing) */
uint32_t free_format_next_header; uint32_t free_format_next_header;
int error_protection;
int layer;
int sample_rate;
int sample_rate_index; /* between 0 and 8 */
int bit_rate;
GetBitContext gb; GetBitContext gb;
GetBitContext in_gb; GetBitContext in_gb;
int nb_channels;
int mode;
int mode_ext;
int lsf;
DECLARE_ALIGNED_16(MPA_INT, synth_buf[MPA_MAX_CHANNELS][512 * 2]); DECLARE_ALIGNED_16(MPA_INT, synth_buf[MPA_MAX_CHANNELS][512 * 2]);
int synth_buf_offset[MPA_MAX_CHANNELS]; int synth_buf_offset[MPA_MAX_CHANNELS];
DECLARE_ALIGNED_16(int32_t, sb_samples[MPA_MAX_CHANNELS][36][SBLIMIT]); DECLARE_ALIGNED_16(int32_t, sb_samples[MPA_MAX_CHANNELS][36][SBLIMIT]);
......
...@@ -46,8 +46,7 @@ typedef struct MpegAudioParseContext { ...@@ -46,8 +46,7 @@ typedef struct MpegAudioParseContext {
header, otherwise the coded frame size in bytes */ header, otherwise the coded frame size in bytes */
int ff_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bit_rate) int ff_mpa_decode_header(AVCodecContext *avctx, uint32_t head, int *sample_rate, int *channels, int *frame_size, int *bit_rate)
{ {
MPADecodeContext s1, *s = &s1; MPADecodeHeader s1, *s = &s1;
s1.avctx = avctx;
if (ff_mpa_check_header(head) != 0) if (ff_mpa_check_header(head) != 0)
return -1; return -1;
...@@ -145,7 +144,7 @@ static int mpegaudio_parse(AVCodecParserContext *s1, ...@@ -145,7 +144,7 @@ static int mpegaudio_parse(AVCodecParserContext *s1,
#if 0 #if 0
/* free format: prepare to compute frame size */ /* free format: prepare to compute frame size */
if (ff_mpegaudio_decode_header(s, header) == 1) { if (ff_mpegaudio_decode_header((MPADecodeHeader *)s, header) == 1) {
s->frame_size = -1; s->frame_size = -1;
} }
#endif #endif
...@@ -200,7 +199,7 @@ static int mpegaudio_parse(AVCodecParserContext *s1, ...@@ -200,7 +199,7 @@ static int mpegaudio_parse(AVCodecParserContext *s1,
s->free_format_frame_size -= padding; s->free_format_frame_size -= padding;
dprintf(avctx, "free frame size=%d padding=%d\n", dprintf(avctx, "free frame size=%d padding=%d\n",
s->free_format_frame_size, padding); s->free_format_frame_size, padding);
ff_mpegaudio_decode_header(s, header1); ff_mpegaudio_decode_header((MPADecodeHeader *)s, header1);
goto next_data; goto next_data;
} }
p++; p++;
......
...@@ -2277,7 +2277,7 @@ retry: ...@@ -2277,7 +2277,7 @@ retry:
goto retry; goto retry;
} }
if (ff_mpegaudio_decode_header(s, header) == 1) { if (ff_mpegaudio_decode_header((MPADecodeHeader *)s, header) == 1) {
/* free format: prepare to compute frame size */ /* free format: prepare to compute frame size */
s->frame_size = -1; s->frame_size = -1;
return -1; return -1;
...@@ -2342,7 +2342,7 @@ static int decode_frame_adu(AVCodecContext * avctx, ...@@ -2342,7 +2342,7 @@ static int decode_frame_adu(AVCodecContext * avctx,
return buf_size; return buf_size;
} }
ff_mpegaudio_decode_header(s, header); ff_mpegaudio_decode_header((MPADecodeHeader *)s, header);
/* update codec info */ /* update codec info */
avctx->sample_rate = s->sample_rate; avctx->sample_rate = s->sample_rate;
avctx->channels = s->nb_channels; avctx->channels = s->nb_channels;
...@@ -2491,7 +2491,7 @@ static int decode_frame_mp3on4(AVCodecContext * avctx, ...@@ -2491,7 +2491,7 @@ static int decode_frame_mp3on4(AVCodecContext * avctx,
if (ff_mpa_check_header(header) < 0) // Bad header, discard block if (ff_mpa_check_header(header) < 0) // Bad header, discard block
break; break;
ff_mpegaudio_decode_header(m, header); ff_mpegaudio_decode_header((MPADecodeHeader *)m, header);
out_size += mp_decode_frame(m, outptr, buf, fsize); out_size += mp_decode_frame(m, outptr, buf, fsize);
buf += fsize; buf += fsize;
len -= fsize; len -= fsize;
......
...@@ -30,7 +30,7 @@ ...@@ -30,7 +30,7 @@
#include "mpegaudiodata.h" #include "mpegaudiodata.h"
int ff_mpegaudio_decode_header(MPADecodeContext *s, uint32_t header) int ff_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header)
{ {
int sample_rate, frame_size, mpeg25, padding; int sample_rate, frame_size, mpeg25, padding;
int sample_rate_index, bitrate_index; int sample_rate_index, bitrate_index;
......
...@@ -34,6 +34,6 @@ ...@@ -34,6 +34,6 @@
/* header decoding. MUST check the header before because no /* header decoding. MUST check the header before because no
consistency check is done there. Return 1 if free format found and consistency check is done there. Return 1 if free format found and
that the frame size must be computed externally */ that the frame size must be computed externally */
int ff_mpegaudio_decode_header(MPADecodeContext *s, uint32_t header); int ff_mpegaudio_decode_header(MPADecodeHeader *s, uint32_t header);
#endif /* AVCODEC_MPEGAUDIODECHEADER_H */ #endif /* AVCODEC_MPEGAUDIODECHEADER_H */
...@@ -395,7 +395,7 @@ static int mp3_parse_vbr_tags(AVFormatContext *s, AVStream *st, int64_t base) ...@@ -395,7 +395,7 @@ static int mp3_parse_vbr_tags(AVFormatContext *s, AVStream *st, int64_t base)
uint32_t v, spf; uint32_t v, spf;
int frames = -1; /* Total number of frames in file */ int frames = -1; /* Total number of frames in file */
const int64_t xing_offtbl[2][2] = {{32, 17}, {17,9}}; const int64_t xing_offtbl[2][2] = {{32, 17}, {17,9}};
MPADecodeContext c; MPADecodeHeader c;
int vbrtag_size = 0; int vbrtag_size = 0;
v = get_be32(s->pb); v = get_be32(s->pb);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment