]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/apedec.c
lavc: add a wrapper for AVCodecContext.get_buffer().
[ffmpeg] / libavcodec / apedec.c
index b07f3a090be1b9a8d1b6a3c54cfc822fdb8220ed..61eecfe27328b637ddd2d11e222ba7b9ccab747d 100644 (file)
  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  */
 
+#include "libavutil/avassert.h"
+#include "libavutil/channel_layout.h"
+#include "libavutil/opt.h"
 #include "avcodec.h"
 #include "dsputil.h"
 #include "bytestream.h"
-#include "libavutil/audioconvert.h"
-#include "libavutil/avassert.h"
-#include "libavutil/opt.h"
+#include "internal.h"
 
 /**
  * @file
@@ -196,13 +197,13 @@ static av_cold int ape_decode_init(AVCodecContext *avctx)
     s->bps = avctx->bits_per_coded_sample;
     switch (s->bps) {
     case 8:
-        avctx->sample_fmt = AV_SAMPLE_FMT_U8;
+        avctx->sample_fmt = AV_SAMPLE_FMT_U8P;
         break;
     case 16:
-        avctx->sample_fmt = AV_SAMPLE_FMT_S16;
+        avctx->sample_fmt = AV_SAMPLE_FMT_S16P;
         break;
     case 24:
-        avctx->sample_fmt = AV_SAMPLE_FMT_S32;
+        avctx->sample_fmt = AV_SAMPLE_FMT_S32P;
         break;
     default:
         av_log_ask_for_sample(avctx, "Unsupported bits per coded sample %d\n",
@@ -830,7 +831,7 @@ static int ape_decode_frame(AVCodecContext *avctx, void *data,
     uint8_t *sample8;
     int16_t *sample16;
     int32_t *sample24;
-    int i, ret;
+    int i, ch, ret;
     int blockstodecode;
     int bytes_used = 0;
 
@@ -909,7 +910,7 @@ static int ape_decode_frame(AVCodecContext *avctx, void *data,
 
     /* get output buffer */
     s->frame.nb_samples = blockstodecode;
-    if ((ret = avctx->get_buffer(avctx, &s->frame)) < 0) {
+    if ((ret = ff_get_buffer(avctx, &s->frame)) < 0) {
         av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
         return ret;
     }
@@ -930,27 +931,24 @@ static int ape_decode_frame(AVCodecContext *avctx, void *data,
 
     switch (s->bps) {
     case 8:
-        sample8 = (uint8_t *)s->frame.data[0];
-        for (i = 0; i < blockstodecode; i++) {
-            *sample8++ = (s->decoded[0][i] + 0x80) & 0xff;
-            if (s->channels == 2)
-                *sample8++ = (s->decoded[1][i] + 0x80) & 0xff;
+        for (ch = 0; ch < s->channels; ch++) {
+            sample8 = (uint8_t *)s->frame.data[ch];
+            for (i = 0; i < blockstodecode; i++)
+                *sample8++ = (s->decoded[ch][i] + 0x80) & 0xff;
         }
         break;
     case 16:
-        sample16 = (int16_t *)s->frame.data[0];
-        for (i = 0; i < blockstodecode; i++) {
-            *sample16++ = s->decoded[0][i];
-            if (s->channels == 2)
-                *sample16++ = s->decoded[1][i];
+        for (ch = 0; ch < s->channels; ch++) {
+            sample16 = (int16_t *)s->frame.data[ch];
+            for (i = 0; i < blockstodecode; i++)
+                *sample16++ = s->decoded[ch][i];
         }
         break;
     case 24:
-        sample24 = (int32_t *)s->frame.data[0];
-        for (i = 0; i < blockstodecode; i++) {
-            *sample24++ = s->decoded[0][i] << 8;
-            if (s->channels == 2)
-                *sample24++ = s->decoded[1][i] << 8;
+        for (ch = 0; ch < s->channels; ch++) {
+            sample24 = (int32_t *)s->frame.data[ch];
+            for (i = 0; i < blockstodecode; i++)
+                *sample24++ = s->decoded[ch][i] << 8;
         }
         break;
     }
@@ -972,8 +970,8 @@ static void ape_flush(AVCodecContext *avctx)
 #define OFFSET(x) offsetof(APEContext, x)
 #define PAR (AV_OPT_FLAG_DECODING_PARAM | AV_OPT_FLAG_AUDIO_PARAM)
 static const AVOption options[] = {
-    { "max_samples", "maximum number of samples decoded per call",             OFFSET(blocks_per_loop), AV_OPT_TYPE_INT,   { 4608 },    1,       INT_MAX, PAR, "max_samples" },
-    { "all",         "no maximum. decode all samples for each packet at once", 0,                       AV_OPT_TYPE_CONST, { INT_MAX }, INT_MIN, INT_MAX, PAR, "max_samples" },
+    { "max_samples", "maximum number of samples decoded per call",             OFFSET(blocks_per_loop), AV_OPT_TYPE_INT,   { .i64 = 4608 },    1,       INT_MAX, PAR, "max_samples" },
+    { "all",         "no maximum. decode all samples for each packet at once", 0,                       AV_OPT_TYPE_CONST, { .i64 = INT_MAX }, INT_MIN, INT_MAX, PAR, "max_samples" },
     { NULL},
 };
 
@@ -987,7 +985,7 @@ static const AVClass ape_decoder_class = {
 AVCodec ff_ape_decoder = {
     .name           = "ape",
     .type           = AVMEDIA_TYPE_AUDIO,
-    .id             = CODEC_ID_APE,
+    .id             = AV_CODEC_ID_APE,
     .priv_data_size = sizeof(APEContext),
     .init           = ape_decode_init,
     .close          = ape_decode_close,
@@ -995,5 +993,9 @@ AVCodec ff_ape_decoder = {
     .capabilities   = CODEC_CAP_SUBFRAMES | CODEC_CAP_DELAY | CODEC_CAP_DR1,
     .flush          = ape_flush,
     .long_name      = NULL_IF_CONFIG_SMALL("Monkey's Audio"),
+    .sample_fmts    = (const enum AVSampleFormat[]) { AV_SAMPLE_FMT_U8P,
+                                                      AV_SAMPLE_FMT_S16P,
+                                                      AV_SAMPLE_FMT_S32P,
+                                                      AV_SAMPLE_FMT_NONE },
     .priv_class     = &ape_decoder_class,
 };