]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/libspeexdec.c
utvideodec: Convert to the new bitstream reader
[ffmpeg] / libavcodec / libspeexdec.c
index 0c93f05a1b181a3a0b24553949b96b91b7731d23..949a9344c1ce8057947512915a7e5986cbe4f501 100644 (file)
 #include <speex/speex_stereo.h>
 #include <speex/speex_callbacks.h>
 
-#include "libavutil/audioconvert.h"
+#include "libavutil/channel_layout.h"
 #include "libavutil/common.h"
 #include "avcodec.h"
+#include "internal.h"
 
-typedef struct {
-    AVFrame frame;
+typedef struct LibSpeexContext {
     SpeexBits bits;
     SpeexStereoState stereo;
     void *dec_state;
@@ -101,9 +101,6 @@ static av_cold int libspeex_decode_init(AVCodecContext *avctx)
         speex_decoder_ctl(s->dec_state, SPEEX_SET_HANDLER, &callback);
     }
 
-    avcodec_get_frame_defaults(&s->frame);
-    avctx->coded_frame = &s->frame;
-
     return 0;
 }
 
@@ -113,23 +110,24 @@ static int libspeex_decode_frame(AVCodecContext *avctx, void *data,
     uint8_t *buf = avpkt->data;
     int buf_size = avpkt->size;
     LibSpeexContext *s = avctx->priv_data;
+    AVFrame *frame     = data;
     int16_t *output;
     int ret, consumed = 0;
 
     /* get output buffer */
-    s->frame.nb_samples = s->frame_size;
-    if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) {
+    frame->nb_samples = s->frame_size;
+    if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
         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
        next 5 bits are a terminator code, reset the libspeex buffer using the
        current packet, otherwise ignore the current packet and keep decoding
        frames from the libspeex buffer. */
     if (speex_bits_remaining(&s->bits) < 5 ||
-        speex_bits_peek_unsigned(&s->bits, 5) == 0x1F) {
+        speex_bits_peek_unsigned(&s->bits, 5) == 0xF) {
         /* check for flush packet */
         if (!buf || !buf_size) {
             *got_frame_ptr = 0;
@@ -149,8 +147,7 @@ static int libspeex_decode_frame(AVCodecContext *avctx, void *data,
     if (avctx->channels == 2)
         speex_decode_stereo_int(output, s->frame_size, &s->stereo);
 
-    *got_frame_ptr   = 1;
-    *(AVFrame *)data = s->frame;
+    *got_frame_ptr = 1;
 
     return consumed;
 }
@@ -173,6 +170,7 @@ static av_cold void libspeex_decode_flush(AVCodecContext *avctx)
 
 AVCodec ff_libspeex_decoder = {
     .name           = "libspeex",
+    .long_name      = NULL_IF_CONFIG_SMALL("libspeex Speex"),
     .type           = AVMEDIA_TYPE_AUDIO,
     .id             = AV_CODEC_ID_SPEEX,
     .priv_data_size = sizeof(LibSpeexContext),
@@ -180,6 +178,5 @@ AVCodec ff_libspeex_decoder = {
     .close          = libspeex_decode_close,
     .decode         = libspeex_decode_frame,
     .flush          = libspeex_decode_flush,
-    .capabilities   = CODEC_CAP_SUBFRAMES | CODEC_CAP_DELAY | CODEC_CAP_DR1,
-    .long_name      = NULL_IF_CONFIG_SMALL("libspeex Speex"),
+    .capabilities   = AV_CODEC_CAP_SUBFRAMES | AV_CODEC_CAP_DELAY | AV_CODEC_CAP_DR1,
 };