]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/pcm-dvd.c
aarch64: vp9dsp: Fix vertical alignment in the init file
[ffmpeg] / libavcodec / pcm-dvd.c
index 9fd6d13365c7ea50ce5eff25b9b423283643748c..62aacf829a4b5fda3ff9e322fbadfc93fabbe9b5 100644 (file)
@@ -1,6 +1,6 @@
 /*
  * LPCM codecs for PCM formats found in Video DVD streams
- * Copyright (c) 2009-2013 Christian Schmidt
+ * Copyright (c) 2013 Christian Schmidt
  *
  * This file is part of Libav.
  *
@@ -32,7 +32,7 @@ typedef struct PCMDVDContext {
     uint32_t last_header;    // Cached header to see if parsing is needed
     int block_size;          // Size of a block of samples in bytes
     int samples_per_block;   // Number of samples per channel per block
-    int groups_per_block;    // Number of 20/24bit sample groups per block
+    int groups_per_block;    // Number of 20/24-bit sample groups per block
     uint8_t *extra_samples;  // Pointer to leftover samples from a frame
     int extra_sample_count;  // Number of leftover samples in the buffer
 } PCMDVDContext;
@@ -46,7 +46,6 @@ static av_cold int pcm_dvd_decode_init(AVCodecContext *avctx)
     /* reserve space for 8 channels, 3 bytes/sample, 4 samples/block */
     if (!(s->extra_samples = av_malloc(8 * 3 * 4)))
         return AVERROR(ENOMEM);
-    s->extra_sample_count = 0;
 
     return 0;
 }
@@ -55,8 +54,7 @@ static av_cold int pcm_dvd_decode_uninit(AVCodecContext *avctx)
 {
     PCMDVDContext *s = avctx->priv_data;
 
-    if (s->extra_samples)
-        av_free(s->extra_samples);
+    av_freep(&s->extra_samples);
 
     return 0;
 }
@@ -73,7 +71,7 @@ static int pcm_dvd_parse_header(AVCodecContext *avctx, const uint8_t *header)
         return 0;
 
     if (avctx->debug & FF_DEBUG_PICT_INFO)
-        av_dlog(avctx, "pcm_dvd_parse_header: header = %02x%02x%02x\n",
+        ff_dlog(avctx, "pcm_dvd_parse_header: header = %02x%02x%02x\n",
                 header[0], header[1], header[2]);
     /*
      * header[0] emphasis (1), muse(1), reserved(1), frame number(5)
@@ -81,6 +79,9 @@ static int pcm_dvd_parse_header(AVCodecContext *avctx, const uint8_t *header)
      * header[2] dynamic range control (0x80 = off)
      */
 
+    /* Discard potentially existing leftover samples from old channel layout */
+    s->extra_sample_count = 0;
+
     /* get the sample depth and derive the sample format from it */
     avctx->bits_per_coded_sample = 16 + (header[1] >> 6 & 3) * 4;
     if (avctx->bits_per_coded_sample == 28) {
@@ -101,7 +102,7 @@ static int pcm_dvd_parse_header(AVCodecContext *avctx, const uint8_t *header)
                       avctx->sample_rate *
                       avctx->bits_per_coded_sample;
 
-    /* 4 samples form a group in 20/24bit PCM on DVD Video.
+    /* 4 samples form a group in 20/24-bit PCM on DVD Video.
      * A block is formed by the number of groups that are
      * needed to complete a set of samples for each channel. */
     if (avctx->bits_per_coded_sample == 16) {
@@ -134,7 +135,7 @@ static int pcm_dvd_parse_header(AVCodecContext *avctx, const uint8_t *header)
     }
 
     if (avctx->debug & FF_DEBUG_PICT_INFO)
-        av_dlog(avctx,
+        ff_dlog(avctx,
                 "pcm_dvd_parse_header: %d channels, %d bits per sample, %d Hz, %d bit/s\n",
                 avctx->channels, avctx->bits_per_coded_sample,
                 avctx->sample_rate, avctx->bit_rate);
@@ -153,21 +154,21 @@ static void *pcm_dvd_decode_samples(AVCodecContext *avctx, const uint8_t *src,
     GetByteContext gb;
     int i;
     uint8_t t;
-    int samples;
 
     bytestream2_init(&gb, src, blocks * s->block_size);
     switch (avctx->bits_per_coded_sample) {
-    case 16:
+    case 16: {
 #if HAVE_BIGENDIAN
         bytestream2_get_buffer(&gb, dst16, blocks * s->block_size);
         dst16 += blocks * s->block_size / 2;
 #else
-        samples = blocks * avctx->channels;
+        int samples = blocks * avctx->channels;
         do {
             *dst16++ = bytestream2_get_be16u(&gb);
         } while (--samples);
 #endif
         return dst16;
+    }
     case 20:
         do {
             for (i = s->groups_per_block; i; i--) {
@@ -176,11 +177,11 @@ static void *pcm_dvd_decode_samples(AVCodecContext *avctx, const uint8_t *src,
                 dst32[2] = bytestream2_get_be16u(&gb) << 16;
                 dst32[3] = bytestream2_get_be16u(&gb) << 16;
                 t = bytestream2_get_byteu(&gb);
-                *dst32 += (t & 0xf0) << 8;
-                *dst32 += (t & 0x0f) << 12;
+                *dst32++ += (t & 0xf0) << 8;
+                *dst32++ += (t & 0x0f) << 12;
                 t = bytestream2_get_byteu(&gb);
-                *dst32 += (t & 0xf0) << 8;
-                *dst32 += (t & 0x0f) << 12;
+                *dst32++ += (t & 0xf0) << 8;
+                *dst32++ += (t & 0x0f) << 12;
             }
         } while (--blocks);
         return dst32;
@@ -280,7 +281,7 @@ AVCodec ff_pcm_dvd_decoder = {
     .init           = pcm_dvd_decode_init,
     .decode         = pcm_dvd_decode_frame,
     .close          = pcm_dvd_decode_uninit,
-    .capabilities   = CODEC_CAP_DR1,
+    .capabilities   = AV_CODEC_CAP_DR1,
     .sample_fmts    = (const enum AVSampleFormat[]) {
         AV_SAMPLE_FMT_S16, AV_SAMPLE_FMT_S32, AV_SAMPLE_FMT_NONE
     }