]> git.sesse.net Git - ffmpeg/blobdiff - libavcodec/apedec.c
mlpdec: Validate non-restart bit from the substream header.
[ffmpeg] / libavcodec / apedec.c
index 83281c1035e3cfd4265b6d0046d86a207c8479d4..59be99694e4799f3bce45625e351455d2cddfd6f 100644 (file)
@@ -27,7 +27,7 @@
 #include "bytestream.h"
 
 /**
- * @file apedec.c
+ * @file libavcodec/apedec.c
  * Monkey's Audio lossless audio decoder
  */
 
@@ -171,7 +171,7 @@ static av_cold int ape_decode_init(AVCodecContext * avctx)
         av_log(avctx, AV_LOG_ERROR, "Incorrect extradata\n");
         return -1;
     }
-    if (avctx->bits_per_sample != 16) {
+    if (avctx->bits_per_coded_sample != 16) {
         av_log(avctx, AV_LOG_ERROR, "Only 16-bit samples are supported\n");
         return -1;
     }
@@ -199,6 +199,7 @@ static av_cold int ape_decode_init(AVCodecContext * avctx)
 
     dsputil_init(&s->dsp, avctx);
     avctx->sample_fmt = SAMPLE_FMT_S16;
+    avctx->channel_layout = (avctx->channels==2) ? CH_LAYOUT_STEREO : CH_LAYOUT_MONO;
     return 0;
 }
 
@@ -247,6 +248,7 @@ static inline void range_dec_normalize(APEContext * ctx)
 
 /**
  * Calculate culmulative frequency for next symbol. Does NO update!
+ * @param ctx decoder context
  * @param tot_f is the total frequency or (code_value)1<<shift
  * @return the culmulative frequency
  */
@@ -259,6 +261,7 @@ static inline int range_decode_culfreq(APEContext * ctx, int tot_f)
 
 /**
  * Decode value with given size in bits
+ * @param ctx decoder context
  * @param shift number of bits to decode
  */
 static inline int range_decode_culshift(APEContext * ctx, int shift)
@@ -271,6 +274,7 @@ static inline int range_decode_culshift(APEContext * ctx, int shift)
 
 /**
  * Update decoding state
+ * @param ctx decoder context
  * @param sy_f the interval length (frequency of the symbol)
  * @param lt_f the lower end (frequency sum of < symbols)
  */
@@ -329,8 +333,9 @@ static const uint16_t counts_diff_3980[21] = {
 
 /**
  * Decode symbol
+ * @param ctx decoder context
  * @param counts probability range start position
- * @param count_diffs probability range widths
+ * @param counts_diff probability range widths
  */
 static inline int range_get_symbol(APEContext * ctx,
                                    const uint16_t counts[],
@@ -358,11 +363,10 @@ static inline int range_get_symbol(APEContext * ctx,
 
 static inline void update_rice(APERice *rice, int x)
 {
+    int lim = rice->k ? (1 << (rice->k + 4)) : 0;
     rice->ksum += ((x + 1) / 2) - ((rice->ksum + 16) >> 5);
 
-    if (rice->k == 0)
-        rice->k = 1;
-    else if (rice->ksum < (1 << (rice->k + 4)))
+    if (rice->ksum < lim)
         rice->k--;
     else if (rice->ksum >= (1 << (rice->k + 5)))
         rice->k++;