]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/8svx.c
Merge commit 'bfcd4b6a1691d20aebc6d2308424c2a88334a9f0'
[ffmpeg] / libavcodec / 8svx.c
index 8d6a6d692eb8082d9931b9a5383595503da985f0..0da48986f03f70f2d1383ce08509b161a57d5fec 100644 (file)
@@ -39,6 +39,7 @@
 
 #include "libavutil/avassert.h"
 #include "avcodec.h"
+#include "libavutil/common.h"
 
 /** decoder context */
 typedef struct EightSvxContext {
@@ -57,25 +58,6 @@ static const int8_t exponential[16] = { -128, -64, -32, -16, -8, -4, -2, -1, 0,
 
 #define MAX_FRAME_SIZE 2048
 
-/**
- * Interleave samples in buffer containing all left channel samples
- * at the beginning, and right channel samples at the end.
- * Each sample is assumed to be in signed 8-bit format.
- *
- * @param size the size in bytes of the dst and src buffer
- */
-static void interleave_stereo(uint8_t *dst, const uint8_t *src, int size)
-{
-    uint8_t *dst_end = dst + size;
-    size = size>>1;
-
-    while (dst < dst_end) {
-        *dst++ = *src;
-        *dst++ = *(src+size);
-        src++;
-    }
-}
-
 /**
  * Delta decode the compressed values in src, and put the resulting
  * decoded n samples in dst.
@@ -106,7 +88,8 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data,
                                  int *got_frame_ptr, AVPacket *avpkt)
 {
     EightSvxContext *esc = avctx->priv_data;
-    int n, out_data_size, ret;
+    int n, out_data_size;
+    int ch, ret;
     uint8_t *src, *dst;
 
     /* decode and interleave the first packet */
@@ -151,10 +134,7 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *data,
             deinterleaved_samples = avpkt->data;
         }
 
-        if (avctx->channels == 2)
-            interleave_stereo(esc->samples, deinterleaved_samples, esc->samples_size);
-        else
-            memcpy(esc->samples, deinterleaved_samples, esc->samples_size);
+        memcpy(esc->samples, deinterleaved_samples, esc->samples_size);
         av_freep(&p);
     }
 
@@ -169,11 +149,14 @@ static int eightsvx_decode_frame(AVCodecContext *avctx, void *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;
+    out_data_size = esc->frame.nb_samples;
+    for (ch = 0; ch<avctx->channels; ch++) {
+        dst = esc->frame.data[ch];
+        src = esc->samples + esc->samples_idx / avctx->channels + ch * esc->samples_size / avctx->channels;
+        for (n = out_data_size; n > 0; n--)
+            *dst++ = *src++ + 128;
+    }
+    out_data_size *= avctx->channels;
     esc->samples_idx += out_data_size;
 
     return esc->table ?
@@ -191,15 +174,15 @@ static av_cold int eightsvx_decode_init(AVCodecContext *avctx)
     }
 
     switch (avctx->codec->id) {
-    case CODEC_ID_8SVX_FIB: esc->table = fibonacci;    break;
-    case CODEC_ID_8SVX_EXP: esc->table = exponential;  break;
-    case CODEC_ID_PCM_S8_PLANAR:
-    case CODEC_ID_8SVX_RAW: esc->table = NULL;         break;
+    case AV_CODEC_ID_8SVX_FIB: esc->table = fibonacci;    break;
+    case AV_CODEC_ID_8SVX_EXP: esc->table = exponential;  break;
+    case AV_CODEC_ID_PCM_S8_PLANAR:
+    case AV_CODEC_ID_8SVX_RAW: esc->table = NULL;         break;
     default:
         av_log(avctx, AV_LOG_ERROR, "Invalid codec id %d.\n", avctx->codec->id);
         return AVERROR_INVALIDDATA;
     }
-    avctx->sample_fmt = AV_SAMPLE_FMT_U8;
+    avctx->sample_fmt = AV_SAMPLE_FMT_U8P;
 
     avcodec_get_frame_defaults(&esc->frame);
     avctx->coded_frame = &esc->frame;
@@ -222,38 +205,44 @@ static av_cold int eightsvx_decode_close(AVCodecContext *avctx)
 AVCodec ff_eightsvx_fib_decoder = {
   .name           = "8svx_fib",
   .type           = AVMEDIA_TYPE_AUDIO,
-  .id             = CODEC_ID_8SVX_FIB,
+  .id             = AV_CODEC_ID_8SVX_FIB,
   .priv_data_size = sizeof (EightSvxContext),
   .init           = eightsvx_decode_init,
   .decode         = eightsvx_decode_frame,
   .close          = eightsvx_decode_close,
   .capabilities   = CODEC_CAP_DR1,
   .long_name      = NULL_IF_CONFIG_SMALL("8SVX fibonacci"),
+  .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_U8P,
+                                                    AV_SAMPLE_FMT_NONE },
 };
 #endif
 #if CONFIG_EIGHTSVX_EXP_DECODER
 AVCodec ff_eightsvx_exp_decoder = {
   .name           = "8svx_exp",
   .type           = AVMEDIA_TYPE_AUDIO,
-  .id             = CODEC_ID_8SVX_EXP,
+  .id             = AV_CODEC_ID_8SVX_EXP,
   .priv_data_size = sizeof (EightSvxContext),
   .init           = eightsvx_decode_init,
   .decode         = eightsvx_decode_frame,
   .close          = eightsvx_decode_close,
   .capabilities   = CODEC_CAP_DR1,
   .long_name      = NULL_IF_CONFIG_SMALL("8SVX exponential"),
+  .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_U8P,
+                                                    AV_SAMPLE_FMT_NONE },
 };
 #endif
 #if CONFIG_PCM_S8_PLANAR_DECODER
 AVCodec ff_pcm_s8_planar_decoder = {
     .name           = "pcm_s8_planar",
     .type           = AVMEDIA_TYPE_AUDIO,
-    .id             = CODEC_ID_PCM_S8_PLANAR,
+    .id             = AV_CODEC_ID_PCM_S8_PLANAR,
     .priv_data_size = sizeof(EightSvxContext),
     .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"),
+    .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_U8P,
+                                                      AV_SAMPLE_FMT_NONE },
 };
 #endif