]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/8svx.c
Merge remote-tracking branch 'qatar/master'
[ffmpeg] / libavcodec / 8svx.c
index efe554adc298b4aa131c2003354f111af4d26975..a91f001531f11b02ca403742e4cfa45f9c028dab 100644 (file)
@@ -41,6 +41,7 @@
 
 /** decoder context */
 typedef struct EightSvxContext {
+    AVFrame frame;
     const int8_t *table;
 
     /* buffer used to store the whole audio decoded/interleaved chunk,
@@ -99,11 +100,12 @@ static int delta_decode(int8_t *dst, const uint8_t *src, int src_size,
     return dst-dst0;
 }
 
-static int eightsvx_decode_frame(AVCodecContext *avctx, void *data, int *data_size,
-                                 AVPacket *avpkt)
+/** decode a frame */
+static int eightsvx_decode_frame(AVCodecContext *avctx, void *data,
+                                 int *got_frame_ptr, AVPacket *avpkt)
 {
     EightSvxContext *esc = avctx->priv_data;
-    int out_data_size, n;
+    int n, out_data_size, ret;
     uint8_t *src, *dst;
 
     /* decode and interleave the first packet */
@@ -145,19 +147,22 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data, int *data_si
             memcpy(esc->samples, deinterleaved_samples, esc->samples_size);
     }
 
-    /* return single packed with fixed size */
-    out_data_size = FFMIN(MAX_FRAME_SIZE, esc->samples_size - esc->samples_idx);
-    if (*data_size < out_data_size) {
-        av_log(avctx, AV_LOG_ERROR, "Provided buffer with size %d is too small.\n", *data_size);
-        return AVERROR(EINVAL);
+    /* get output buffer */
+    esc->frame.nb_samples = (FFMIN(MAX_FRAME_SIZE, esc->samples_size - esc->samples_idx) +avctx->channels-1)  / avctx->channels;
+    if ((ret = avctx->get_buffer(avctx, &esc->frame)) < 0) {
+        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+        return ret;
     }
 
-    *data_size = out_data_size;
-    dst = data;
+    *got_frame_ptr   = 1;
+    *(AVFrame *)data = esc->frame;
+
+    dst = esc->frame.data[0];
     src = esc->samples + esc->samples_idx;
+    out_data_size = esc->frame.nb_samples * avctx->channels;
     for (n = out_data_size; n > 0; n--)
         *dst++ = *src++ + 128;
-    esc->samples_idx += *data_size;
+    esc->samples_idx += out_data_size;
 
     return avctx->codec->id == CODEC_ID_8SVX_FIB || avctx->codec->id == CODEC_ID_8SVX_EXP ?
         (avctx->frame_number == 0)*2 + out_data_size / 2 :
@@ -184,6 +189,9 @@ static av_cold int eightsvx_decode_init(AVCodecContext *avctx)
     }
     avctx->sample_fmt = AV_SAMPLE_FMT_U8;
 
+    avcodec_get_frame_defaults(&esc->frame);
+    avctx->coded_frame = &esc->frame;
+
     return 0;
 }
 
@@ -206,6 +214,7 @@ AVCodec ff_eightsvx_fib_decoder = {
   .init           = eightsvx_decode_init,
   .decode         = eightsvx_decode_frame,
   .close          = eightsvx_decode_close,
+  .capabilities   = CODEC_CAP_DR1,
   .long_name      = NULL_IF_CONFIG_SMALL("8SVX fibonacci"),
 };
 
@@ -217,6 +226,7 @@ AVCodec ff_eightsvx_exp_decoder = {
   .init           = eightsvx_decode_init,
   .decode         = eightsvx_decode_frame,
   .close          = eightsvx_decode_close,
+  .capabilities   = CODEC_CAP_DR1,
   .long_name      = NULL_IF_CONFIG_SMALL("8SVX exponential"),
 };
 
@@ -228,5 +238,6 @@ AVCodec ff_pcm_s8_planar_decoder = {
     .init           = eightsvx_decode_init,
     .close          = eightsvx_decode_close,
     .decode         = eightsvx_decode_frame,
+    .capabilities   = CODEC_CAP_DR1,
     .long_name      = NULL_IF_CONFIG_SMALL("PCM signed 8-bit planar"),
 };