]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/vorbisdec.c
adxdec: clear eof flag and channel states when seeking
[ffmpeg] / libavcodec / vorbisdec.c
index e79feb90c6e1ecf75fa9cf3fa0e771c84bc9f3e1..70690ddb2cdef84b939f1e03922c1e785c4bc22e 100644 (file)
@@ -25,7 +25,7 @@
 #include <inttypes.h>
 #include <math.h>
 
-#define ALT_BITSTREAM_READER_LE
+#define BITSTREAM_READER_LE
 #include "avcodec.h"
 #include "get_bits.h"
 #include "dsputil.h"
@@ -121,6 +121,7 @@ typedef struct {
 
 typedef struct vorbis_context_s {
     AVCodecContext *avccontext;
+    AVFrame frame;
     GetBitContext gb;
     DSPContext dsp;
     FmtConvertContext fmt_conv;
@@ -936,12 +937,6 @@ static int vorbis_parse_id_hdr(vorbis_context *vc)
         av_log(vc->avccontext, AV_LOG_ERROR, " Vorbis id header packet corrupt (illegal blocksize). \n");
         return AVERROR_INVALIDDATA;
     }
-    // output format int16
-    if (vc->blocksize[1] / 2 * vc->audio_channels * 2 > AVCODEC_MAX_AUDIO_FRAME_SIZE) {
-        av_log(vc->avccontext, AV_LOG_ERROR, "Vorbis channel count makes "
-               "output packets too large.\n");
-        return AVERROR_PATCHWELCOME;
-    }
     vc->win[0] = ff_vorbis_vwin[bl0 - 6];
     vc->win[1] = ff_vorbis_vwin[bl1 - 6];
 
@@ -1039,6 +1034,9 @@ static av_cold int vorbis_decode_init(AVCodecContext *avccontext)
     avccontext->sample_rate = vc->audio_samplerate;
     avccontext->frame_size  = FFMIN(vc->blocksize[0], vc->blocksize[1]) >> 2;
 
+    avcodec_get_frame_defaults(&vc->frame);
+    avccontext->coded_frame = &vc->frame;
+
     return 0;
 }
 
@@ -1611,16 +1609,15 @@ static int vorbis_parse_audio_packet(vorbis_context *vc)
 
 // Return the decoded audio packet through the standard api
 
-static int vorbis_decode_frame(AVCodecContext *avccontext,
-                               void *data, int *data_size,
-                               AVPacket *avpkt)
+static int vorbis_decode_frame(AVCodecContext *avccontext, void *data,
+                               int *got_frame_ptr, AVPacket *avpkt)
 {
     const uint8_t *buf = avpkt->data;
     int buf_size       = avpkt->size;
     vorbis_context *vc = avccontext->priv_data;
     GetBitContext *gb = &(vc->gb);
     const float *channel_ptrs[255];
-    int i, len, out_size;
+    int i, len, ret;
 
     av_dlog(NULL, "packet length %d \n", buf_size);
 
@@ -1631,18 +1628,18 @@ static int vorbis_decode_frame(AVCodecContext *avccontext,
 
     if (!vc->first_frame) {
         vc->first_frame = 1;
-        *data_size = 0;
+        *got_frame_ptr = 0;
         return buf_size;
     }
 
     av_dlog(NULL, "parsed %d bytes %d bits, returned %d samples (*ch*bits) \n",
             get_bits_count(gb) / 8, get_bits_count(gb) % 8, len);
 
-    out_size = len * vc->audio_channels *
-               av_get_bytes_per_sample(avccontext->sample_fmt);
-    if (*data_size < out_size) {
-        av_log(avccontext, AV_LOG_ERROR, "output buffer is too small\n");
-        return AVERROR(EINVAL);
+    /* get output buffer */
+    vc->frame.nb_samples = len;
+    if ((ret = avccontext->get_buffer(avccontext, &vc->frame)) < 0) {
+        av_log(avccontext, AV_LOG_ERROR, "get_buffer() failed\n");
+        return ret;
     }
 
     if (vc->audio_channels > 8) {
@@ -1655,12 +1652,15 @@ static int vorbis_decode_frame(AVCodecContext *avccontext,
     }
 
     if (avccontext->sample_fmt == AV_SAMPLE_FMT_FLT)
-        vc->fmt_conv.float_interleave(data, channel_ptrs, len, vc->audio_channels);
+        vc->fmt_conv.float_interleave((float *)vc->frame.data[0], channel_ptrs,
+                                      len, vc->audio_channels);
     else
-        vc->fmt_conv.float_to_int16_interleave(data, channel_ptrs, len,
+        vc->fmt_conv.float_to_int16_interleave((int16_t *)vc->frame.data[0],
+                                               channel_ptrs, len,
                                                vc->audio_channels);
 
-    *data_size = out_size;
+    *got_frame_ptr   = 1;
+    *(AVFrame *)data = vc->frame;
 
     return buf_size;
 }
@@ -1684,6 +1684,7 @@ AVCodec ff_vorbis_decoder = {
     .init           = vorbis_decode_init,
     .close          = vorbis_decode_close,
     .decode         = vorbis_decode_frame,
+    .capabilities   = CODEC_CAP_DR1,
     .long_name = NULL_IF_CONFIG_SMALL("Vorbis"),
     .channel_layouts = ff_vorbis_channel_layouts,
     .sample_fmts = (const enum AVSampleFormat[]) {