]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/wavpack.c
aacenc: fix typo in sync extension constant in 8ae0fa2
[ffmpeg] / libavcodec / wavpack.c
index bcea7b528dbc9dcd46c25778b6626c842af59a0a..f78492c924c7f3c6a0ad605be7fdfa3f0d364006 100644 (file)
@@ -24,7 +24,7 @@
 #include "unary.h"
 
 /**
- * @file libavcodec/wavpack.c
+ * @file
  * WavPack lossless audio decoder
  */
 
@@ -469,7 +469,7 @@ static inline int wv_unpack_stereo(WavpackContext *s, GetBitContext *gb, void *d
     float   *dstfl = dst;
 
     if(s->samples_left == s->samples)
-    s->one = s->zero = s->zeroes = 0;
+        s->one = s->zero = s->zeroes = 0;
     do{
         L = wv_get_value(s, gb, 0, &last);
         if(last) break;
@@ -494,7 +494,7 @@ static inline int wv_unpack_stereo(WavpackContext *s, GetBitContext *gb, void *d
                     B = s->decorr[i].samplesB[pos];
                     j = (pos + t) & 7;
                 }
-                if(type != SAMPLE_FMT_S16){
+                if(type != AV_SAMPLE_FMT_S16){
                     L2 = L + ((s->decorr[i].weightA * (int64_t)A + 512) >> 10);
                     R2 = R + ((s->decorr[i].weightB * (int64_t)B + 512) >> 10);
                 }else{
@@ -506,13 +506,13 @@ static inline int wv_unpack_stereo(WavpackContext *s, GetBitContext *gb, void *d
                 s->decorr[i].samplesA[j] = L = L2;
                 s->decorr[i].samplesB[j] = R = R2;
             }else if(t == -1){
-                if(type != SAMPLE_FMT_S16)
+                if(type != AV_SAMPLE_FMT_S16)
                     L2 = L + ((s->decorr[i].weightA * (int64_t)s->decorr[i].samplesA[0] + 512) >> 10);
                 else
                     L2 = L + ((s->decorr[i].weightA * s->decorr[i].samplesA[0] + 512) >> 10);
                 UPDATE_WEIGHT_CLIP(s->decorr[i].weightA, s->decorr[i].delta, s->decorr[i].samplesA[0], L);
                 L = L2;
-                if(type != SAMPLE_FMT_S16)
+                if(type != AV_SAMPLE_FMT_S16)
                     R2 = R + ((s->decorr[i].weightB * (int64_t)L2 + 512) >> 10);
                 else
                     R2 = R + ((s->decorr[i].weightB * L2 + 512) >> 10);
@@ -520,7 +520,7 @@ static inline int wv_unpack_stereo(WavpackContext *s, GetBitContext *gb, void *d
                 R = R2;
                 s->decorr[i].samplesA[0] = R;
             }else{
-                if(type != SAMPLE_FMT_S16)
+                if(type != AV_SAMPLE_FMT_S16)
                     R2 = R + ((s->decorr[i].weightB * (int64_t)s->decorr[i].samplesB[0] + 512) >> 10);
                 else
                     R2 = R + ((s->decorr[i].weightB * s->decorr[i].samplesB[0] + 512) >> 10);
@@ -532,7 +532,7 @@ static inline int wv_unpack_stereo(WavpackContext *s, GetBitContext *gb, void *d
                     s->decorr[i].samplesA[0] = R;
                 }
 
-                if(type != SAMPLE_FMT_S16)
+                if(type != AV_SAMPLE_FMT_S16)
                     L2 = L + ((s->decorr[i].weightA * (int64_t)R2 + 512) >> 10);
                 else
                     L2 = L + ((s->decorr[i].weightA * R2 + 512) >> 10);
@@ -546,10 +546,10 @@ static inline int wv_unpack_stereo(WavpackContext *s, GetBitContext *gb, void *d
             L += (R -= (L >> 1));
         crc = (crc * 3 + L) * 3 + R;
 
-        if(type == SAMPLE_FMT_FLT){
+        if(type == AV_SAMPLE_FMT_FLT){
             *dstfl++ = wv_get_value_float(s, &crc_extra_bits, L);
             *dstfl++ = wv_get_value_float(s, &crc_extra_bits, R);
-        } else if(type == SAMPLE_FMT_S32){
+        } else if(type == AV_SAMPLE_FMT_S32){
             *dst32++ = wv_get_value_integer(s, &crc_extra_bits, L);
             *dst32++ = wv_get_value_integer(s, &crc_extra_bits, R);
         } else {
@@ -561,15 +561,15 @@ static inline int wv_unpack_stereo(WavpackContext *s, GetBitContext *gb, void *d
 
     s->samples_left -= count;
     if(!s->samples_left){
-    if(crc != s->CRC){
-        av_log(s->avctx, AV_LOG_ERROR, "CRC error\n");
-        return -1;
-    }
-    if(s->got_extra_bits && crc_extra_bits != s->crc_extra_bits){
-        av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n");
-        return -1;
-    }
-    wv_reset_saved_context(s);
+        if(crc != s->CRC){
+            av_log(s->avctx, AV_LOG_ERROR, "CRC error\n");
+            return -1;
+        }
+        if(s->got_extra_bits && crc_extra_bits != s->crc_extra_bits){
+            av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n");
+            return -1;
+        }
+        wv_reset_saved_context(s);
     }else{
         s->pos = pos;
         s->sc.crc = crc;
@@ -595,7 +595,7 @@ static inline int wv_unpack_mono(WavpackContext *s, GetBitContext *gb, void *dst
     float   *dstfl = dst;
 
     if(s->samples_left == s->samples)
-    s->one = s->zero = s->zeroes = 0;
+        s->one = s->zero = s->zeroes = 0;
     do{
         T = wv_get_value(s, gb, 0, &last);
         S = 0;
@@ -613,7 +613,7 @@ static inline int wv_unpack_mono(WavpackContext *s, GetBitContext *gb, void *dst
                 A = s->decorr[i].samplesA[pos];
                 j = (pos + t) & 7;
             }
-            if(type != SAMPLE_FMT_S16)
+            if(type != AV_SAMPLE_FMT_S16)
                 S = T + ((s->decorr[i].weightA * (int64_t)A + 512) >> 10);
             else
                 S = T + ((s->decorr[i].weightA * A + 512) >> 10);
@@ -623,26 +623,26 @@ static inline int wv_unpack_mono(WavpackContext *s, GetBitContext *gb, void *dst
         pos = (pos + 1) & 7;
         crc = crc * 3 + S;
 
-        if(type == SAMPLE_FMT_FLT)
+        if(type == AV_SAMPLE_FMT_FLT)
             *dstfl++ = wv_get_value_float(s, &crc_extra_bits, S);
-        else if(type == SAMPLE_FMT_S32)
+        else if(type == AV_SAMPLE_FMT_S32)
             *dst32++ = wv_get_value_integer(s, &crc_extra_bits, S);
         else
             *dst16++ = wv_get_value_integer(s, &crc_extra_bits, S);
         count++;
-    }while(!last && count < s->samples);
+    }while(!last && count < s->max_samples);
 
     s->samples_left -= count;
     if(!s->samples_left){
-    if(crc != s->CRC){
-        av_log(s->avctx, AV_LOG_ERROR, "CRC error\n");
-        return -1;
-    }
-    if(s->got_extra_bits && crc_extra_bits != s->crc_extra_bits){
-        av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n");
-        return -1;
-    }
-    wv_reset_saved_context(s);
+        if(crc != s->CRC){
+            av_log(s->avctx, AV_LOG_ERROR, "CRC error\n");
+            return -1;
+        }
+        if(s->got_extra_bits && crc_extra_bits != s->crc_extra_bits){
+            av_log(s->avctx, AV_LOG_ERROR, "Extra bits CRC error\n");
+            return -1;
+        }
+        wv_reset_saved_context(s);
     }else{
         s->pos = pos;
         s->sc.crc = crc;
@@ -660,11 +660,15 @@ static av_cold int wavpack_decode_init(AVCodecContext *avctx)
     WavpackContext *s = avctx->priv_data;
 
     s->avctx = avctx;
+    if (avctx->channels > 2) {
+        av_log(avctx, AV_LOG_ERROR, "Multichannel WavPack is not supported yet.\n");
+        return -1;
+    }
     s->stereo = (avctx->channels == 2);
     if(avctx->bits_per_coded_sample <= 16)
-        avctx->sample_fmt = SAMPLE_FMT_S16;
+        avctx->sample_fmt = AV_SAMPLE_FMT_S16;
     else
-        avctx->sample_fmt = SAMPLE_FMT_S32;
+        avctx->sample_fmt = AV_SAMPLE_FMT_S32;
     avctx->channel_layout = (avctx->channels==2) ? CH_LAYOUT_STEREO : CH_LAYOUT_MONO;
 
     wv_reset_saved_context(s);
@@ -693,11 +697,11 @@ static int wavpack_decode_frame(AVCodecContext *avctx,
     }
 
     if(!s->samples_left){
-    memset(s->decorr, 0, MAX_TERMS * sizeof(Decorr));
-    memset(s->ch, 0, sizeof(s->ch));
-    s->extra_bits = 0;
-    s->and = s->or = s->shift = 0;
-    s->got_extra_bits = 0;
+        memset(s->decorr, 0, MAX_TERMS * sizeof(Decorr));
+        memset(s->ch, 0, sizeof(s->ch));
+        s->extra_bits = 0;
+        s->and = s->or = s->shift = 0;
+        s->got_extra_bits = 0;
     }
 
     s->samples = AV_RL32(buf); buf += 4;
@@ -708,13 +712,13 @@ static int wavpack_decode_frame(AVCodecContext *avctx,
     s->frame_flags = AV_RL32(buf); buf += 4;
     if(s->frame_flags&0x80){
         bpp = sizeof(float);
-        avctx->sample_fmt = SAMPLE_FMT_FLT;
+        avctx->sample_fmt = AV_SAMPLE_FMT_FLT;
     } else if((s->frame_flags&0x03) <= 1){
         bpp = 2;
-        avctx->sample_fmt = SAMPLE_FMT_S16;
+        avctx->sample_fmt = AV_SAMPLE_FMT_S16;
     } else {
         bpp = 4;
-        avctx->sample_fmt = SAMPLE_FMT_S32;
+        avctx->sample_fmt = AV_SAMPLE_FMT_S32;
     }
     s->stereo_in = (s->frame_flags & WV_FALSE_STEREO) ? 0 : s->stereo;
     s->joint = s->frame_flags & WV_JOINT_STEREO;
@@ -921,43 +925,43 @@ static int wavpack_decode_frame(AVCodecContext *avctx,
         if(id & WP_IDF_ODD) buf++;
     }
     if(!s->samples_left){
-    if(!got_terms){
-        av_log(avctx, AV_LOG_ERROR, "No block with decorrelation terms\n");
-        return -1;
-    }
-    if(!got_weights){
-        av_log(avctx, AV_LOG_ERROR, "No block with decorrelation weights\n");
-        return -1;
-    }
-    if(!got_samples){
-        av_log(avctx, AV_LOG_ERROR, "No block with decorrelation samples\n");
-        return -1;
-    }
-    if(!got_entropy){
-        av_log(avctx, AV_LOG_ERROR, "No block with entropy info\n");
-        return -1;
-    }
-    if(s->hybrid && !got_hybrid){
-        av_log(avctx, AV_LOG_ERROR, "Hybrid config not found\n");
-        return -1;
-    }
-    if(!got_bs){
-        av_log(avctx, AV_LOG_ERROR, "Packed samples not found\n");
-        return -1;
-    }
-    if(!got_float && avctx->sample_fmt == SAMPLE_FMT_FLT){
-        av_log(avctx, AV_LOG_ERROR, "Float information not found\n");
-        return -1;
-    }
-    if(s->got_extra_bits && avctx->sample_fmt != SAMPLE_FMT_FLT){
-        const int size = get_bits_left(&s->gb_extra_bits);
-        const int wanted = s->samples * s->extra_bits << s->stereo_in;
-        if(size < wanted){
-            av_log(avctx, AV_LOG_ERROR, "Too small EXTRABITS\n");
-            s->got_extra_bits = 0;
+        if(!got_terms){
+            av_log(avctx, AV_LOG_ERROR, "No block with decorrelation terms\n");
+            return -1;
         }
-    }
-    s->samples_left = s->samples;
+        if(!got_weights){
+            av_log(avctx, AV_LOG_ERROR, "No block with decorrelation weights\n");
+            return -1;
+        }
+        if(!got_samples){
+            av_log(avctx, AV_LOG_ERROR, "No block with decorrelation samples\n");
+            return -1;
+        }
+        if(!got_entropy){
+            av_log(avctx, AV_LOG_ERROR, "No block with entropy info\n");
+            return -1;
+        }
+        if(s->hybrid && !got_hybrid){
+            av_log(avctx, AV_LOG_ERROR, "Hybrid config not found\n");
+            return -1;
+        }
+        if(!got_bs){
+            av_log(avctx, AV_LOG_ERROR, "Packed samples not found\n");
+            return -1;
+        }
+        if(!got_float && avctx->sample_fmt == AV_SAMPLE_FMT_FLT){
+            av_log(avctx, AV_LOG_ERROR, "Float information not found\n");
+            return -1;
+        }
+        if(s->got_extra_bits && avctx->sample_fmt != AV_SAMPLE_FMT_FLT){
+            const int size = get_bits_left(&s->gb_extra_bits);
+            const int wanted = s->samples * s->extra_bits << s->stereo_in;
+            if(size < wanted){
+                av_log(avctx, AV_LOG_ERROR, "Too small EXTRABITS\n");
+                s->got_extra_bits = 0;
+            }
+        }
+        s->samples_left = s->samples;
     }else{
         init_get_bits(&s->gb, avpkt->data + s->sc.offset, s->sc.size);
         skip_bits_long(&s->gb, s->sc.bits_used);
@@ -969,22 +973,22 @@ static int wavpack_decode_frame(AVCodecContext *avctx,
     }
 
     if(s->stereo_in){
-        if(avctx->sample_fmt == SAMPLE_FMT_S16)
-            samplecount = wv_unpack_stereo(s, &s->gb, samples, SAMPLE_FMT_S16);
-        else if(avctx->sample_fmt == SAMPLE_FMT_S32)
-            samplecount = wv_unpack_stereo(s, &s->gb, samples, SAMPLE_FMT_S32);
+        if(avctx->sample_fmt == AV_SAMPLE_FMT_S16)
+            samplecount = wv_unpack_stereo(s, &s->gb, samples, AV_SAMPLE_FMT_S16);
+        else if(avctx->sample_fmt == AV_SAMPLE_FMT_S32)
+            samplecount = wv_unpack_stereo(s, &s->gb, samples, AV_SAMPLE_FMT_S32);
         else
-            samplecount = wv_unpack_stereo(s, &s->gb, samples, SAMPLE_FMT_FLT);
+            samplecount = wv_unpack_stereo(s, &s->gb, samples, AV_SAMPLE_FMT_FLT);
 
     }else{
-        if(avctx->sample_fmt == SAMPLE_FMT_S16)
-            samplecount = wv_unpack_mono(s, &s->gb, samples, SAMPLE_FMT_S16);
-        else if(avctx->sample_fmt == SAMPLE_FMT_S32)
-            samplecount = wv_unpack_mono(s, &s->gb, samples, SAMPLE_FMT_S32);
+        if(avctx->sample_fmt == AV_SAMPLE_FMT_S16)
+            samplecount = wv_unpack_mono(s, &s->gb, samples, AV_SAMPLE_FMT_S16);
+        else if(avctx->sample_fmt == AV_SAMPLE_FMT_S32)
+            samplecount = wv_unpack_mono(s, &s->gb, samples, AV_SAMPLE_FMT_S32);
         else
-            samplecount = wv_unpack_mono(s, &s->gb, samples, SAMPLE_FMT_FLT);
+            samplecount = wv_unpack_mono(s, &s->gb, samples, AV_SAMPLE_FMT_FLT);
 
-        if(s->stereo && avctx->sample_fmt == SAMPLE_FMT_S16){
+        if(s->stereo && avctx->sample_fmt == AV_SAMPLE_FMT_S16){
             int16_t *dst = (int16_t*)samples + samplecount * 2;
             int16_t *src = (int16_t*)samples + samplecount;
             int cnt = samplecount;
@@ -993,7 +997,7 @@ static int wavpack_decode_frame(AVCodecContext *avctx,
                 *--dst = *src;
             }
             samplecount *= 2;
-        }else if(s->stereo && avctx->sample_fmt == SAMPLE_FMT_S32){
+        }else if(s->stereo && avctx->sample_fmt == AV_SAMPLE_FMT_S32){
             int32_t *dst = (int32_t*)samples + samplecount * 2;
             int32_t *src = (int32_t*)samples + samplecount;
             int cnt = samplecount;
@@ -1020,7 +1024,7 @@ static int wavpack_decode_frame(AVCodecContext *avctx,
 
 AVCodec wavpack_decoder = {
     "wavpack",
-    CODEC_TYPE_AUDIO,
+    AVMEDIA_TYPE_AUDIO,
     CODEC_ID_WAVPACK,
     sizeof(WavpackContext),
     wavpack_decode_init,