]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/8svx.c
proresenc: Realloc if buffer is too small
[ffmpeg] / libavcodec / 8svx.c
index 3c0c0911a5fc8bf7d16d518298654a0282a0aa8b..11fbf193ce7152bcaf090ed6468c66b566ab828c 100644 (file)
  */
 
 #include "avcodec.h"
+#include "internal.h"
+#include "libavutil/common.h"
 
 /** decoder context */
 typedef struct EightSvxContext {
-    AVFrame frame;
     uint8_t fib_acc[2];
     const int8_t *table;
 
@@ -57,30 +58,25 @@ static const int8_t exponential[16] = { -128, -64, -32, -16, -8, -4, -2, -1,
  * @param[in,out] state starting value. it is saved for use in the next call.
  */
 static void delta_decode(uint8_t *dst, const uint8_t *src, int src_size,
-                         uint8_t *state, const int8_t *table, int channels)
+                         uint8_t *state, const int8_t *table)
 {
     uint8_t val = *state;
 
     while (src_size--) {
         uint8_t d = *src++;
         val = av_clip_uint8(val + table[d & 0xF]);
-        *dst = val;
-        dst += channels;
+        *dst++ = val;
         val = av_clip_uint8(val + table[d >> 4]);
-        *dst = val;
-        dst += channels;
+        *dst++ = val;
     }
 
     *state = val;
 }
 
-static void raw_decode(uint8_t *dst, const int8_t *src, int src_size,
-                       int channels)
+static void raw_decode(uint8_t *dst, const int8_t *src, int src_size)
 {
-    while (src_size--) {
-        *dst = *src++ + 128;
-        dst += channels;
-    }
+    while (src_size--)
+        *dst++ = *src++ + 128;
 }
 
 /** decode a frame */
@@ -88,9 +84,9 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data,
                                  int *got_frame_ptr, AVPacket *avpkt)
 {
     EightSvxContext *esc = avctx->priv_data;
+    AVFrame *frame       = data;
     int buf_size;
-    uint8_t *out_data;
-    int ret;
+    int ch, ret;
     int is_compr = (avctx->codec_id != AV_CODEC_ID_PCM_S8_PLANAR);
 
     /* for the first packet, copy data to buffer */
@@ -140,31 +136,25 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data,
     }
 
     /* get output buffer */
-    esc->frame.nb_samples = buf_size * (is_compr + 1);
-    if ((ret = avctx->get_buffer(avctx, &esc->frame)) < 0) {
+    frame->nb_samples = buf_size * (is_compr + 1);
+    if ((ret = ff_get_buffer(avctx, frame, 0)) < 0) {
         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
         return ret;
     }
-    out_data = esc->frame.data[0];
-
-    if (is_compr) {
-    delta_decode(out_data, &esc->data[0][esc->data_idx], buf_size,
-                 &esc->fib_acc[0], esc->table, avctx->channels);
-    if (avctx->channels == 2) {
-        delta_decode(&out_data[1], &esc->data[1][esc->data_idx], buf_size,
-                    &esc->fib_acc[1], esc->table, avctx->channels);
-    }
-    } else {
-        int ch;
-        for (ch = 0; ch < avctx->channels; ch++) {
-            raw_decode((int8_t *)&out_data[ch], &esc->data[ch][esc->data_idx],
-                       buf_size, avctx->channels);
+
+    for (ch = 0; ch < avctx->channels; ch++) {
+        if (is_compr) {
+            delta_decode(frame->data[ch], &esc->data[ch][esc->data_idx],
+                         buf_size, &esc->fib_acc[ch], esc->table);
+        } else {
+            raw_decode(frame->data[ch], &esc->data[ch][esc->data_idx],
+                       buf_size);
         }
     }
+
     esc->data_idx += buf_size;
 
-    *got_frame_ptr   = 1;
-    *(AVFrame *)data = esc->frame;
+    *got_frame_ptr = 1;
 
     return avpkt->size;
 }
@@ -191,10 +181,7 @@ static av_cold int eightsvx_decode_init(AVCodecContext *avctx)
         default:
           return -1;
     }
-    avctx->sample_fmt = AV_SAMPLE_FMT_U8;
-
-    avcodec_get_frame_defaults(&esc->frame);
-    avctx->coded_frame = &esc->frame;
+    avctx->sample_fmt = AV_SAMPLE_FMT_U8P;
 
     return 0;
 }
@@ -211,6 +198,7 @@ static av_cold int eightsvx_decode_close(AVCodecContext *avctx)
 
 AVCodec ff_eightsvx_fib_decoder = {
   .name           = "8svx_fib",
+  .long_name      = NULL_IF_CONFIG_SMALL("8SVX fibonacci"),
   .type           = AVMEDIA_TYPE_AUDIO,
   .id             = AV_CODEC_ID_8SVX_FIB,
   .priv_data_size = sizeof (EightSvxContext),
@@ -218,11 +206,13 @@ AVCodec ff_eightsvx_fib_decoder = {
   .close          = eightsvx_decode_close,
   .decode         = eightsvx_decode_frame,
   .capabilities   = CODEC_CAP_DELAY | CODEC_CAP_DR1,
-  .long_name      = NULL_IF_CONFIG_SMALL("8SVX fibonacci"),
+  .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_U8P,
+                                                    AV_SAMPLE_FMT_NONE },
 };
 
 AVCodec ff_eightsvx_exp_decoder = {
   .name           = "8svx_exp",
+  .long_name      = NULL_IF_CONFIG_SMALL("8SVX exponential"),
   .type           = AVMEDIA_TYPE_AUDIO,
   .id             = AV_CODEC_ID_8SVX_EXP,
   .priv_data_size = sizeof (EightSvxContext),
@@ -230,11 +220,13 @@ AVCodec ff_eightsvx_exp_decoder = {
   .close          = eightsvx_decode_close,
   .decode         = eightsvx_decode_frame,
   .capabilities   = CODEC_CAP_DELAY | CODEC_CAP_DR1,
-  .long_name      = NULL_IF_CONFIG_SMALL("8SVX exponential"),
+  .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_U8P,
+                                                    AV_SAMPLE_FMT_NONE },
 };
 
 AVCodec ff_pcm_s8_planar_decoder = {
     .name           = "pcm_s8_planar",
+    .long_name      = NULL_IF_CONFIG_SMALL("PCM signed 8-bit planar"),
     .type           = AVMEDIA_TYPE_AUDIO,
     .id             = AV_CODEC_ID_PCM_S8_PLANAR,
     .priv_data_size = sizeof(EightSvxContext),
@@ -242,5 +234,6 @@ AVCodec ff_pcm_s8_planar_decoder = {
     .close          = eightsvx_decode_close,
     .decode         = eightsvx_decode_frame,
     .capabilities   = CODEC_CAP_DELAY | CODEC_CAP_DR1,
-    .long_name      = NULL_IF_CONFIG_SMALL("PCM signed 8-bit planar"),
+    .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_U8P,
+                                                      AV_SAMPLE_FMT_NONE },
 };