1
0
mirror of https://github.com/FFmpeg/FFmpeg.git synced 2025-08-10 06:10:52 +02:00

libspeex: decode directly to the user-provided AVFrame

This commit is contained in:
Justin Ruggles
2012-12-23 19:19:25 -05:00
parent 19b2cb268f
commit bed957bb11

View File

@@ -29,7 +29,6 @@
#include "internal.h" #include "internal.h"
typedef struct { typedef struct {
AVFrame frame;
SpeexBits bits; SpeexBits bits;
SpeexStereoState stereo; SpeexStereoState stereo;
void *dec_state; void *dec_state;
@@ -102,9 +101,6 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx)
speex_decoder_ctl(s->dec_state, SPEEX_SET_HANDLER, &callback); speex_decoder_ctl(s->dec_state, SPEEX_SET_HANDLER, &callback);
} }
avcodec_get_frame_defaults(&s->frame);
avctx->coded_frame = &s->frame;
return 0; return 0;
} }
@@ -114,16 +110,17 @@ static int libspeex_decode_frame(AVCodecContext *avctx, void *data,
uint8_t *buf = avpkt->data; uint8_t *buf = avpkt->data;
int buf_size = avpkt->size; int buf_size = avpkt->size;
LibSpeexContext *s = avctx->priv_data; LibSpeexContext *s = avctx->priv_data;
AVFrame *frame = data;
int16_t *output; int16_t *output;
int ret, consumed = 0; int ret, consumed = 0;
/* get output buffer */ /* get output buffer */
s->frame.nb_samples = s->frame_size; frame->nb_samples = s->frame_size;
if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) { if ((ret = ff_get_buffer(avctx, frame)) < 0) {
av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n"); av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
return ret; return ret;
} }
output = (int16_t *)s->frame.data[0]; output = (int16_t *)frame->data[0];
/* if there is not enough data left for the smallest possible frame or the /* if there is not enough data left for the smallest possible frame or the
next 5 bits are a terminator code, reset the libspeex buffer using the next 5 bits are a terminator code, reset the libspeex buffer using the
@@ -150,8 +147,7 @@ static int libspeex_decode_frame(AVCodecContext *avctx, void *data,
if (avctx->channels == 2) if (avctx->channels == 2)
speex_decode_stereo_int(output, s->frame_size, &s->stereo); speex_decode_stereo_int(output, s->frame_size, &s->stereo);
*got_frame_ptr = 1; *got_frame_ptr = 1;
*(AVFrame *)data = s->frame;
return consumed; return consumed;
} }