---
 libavcodec/alac.c |  296 +++++++++++++++++++++++++++--------------------------
 1 files changed, 149 insertions(+), 147 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 8e2b803..aefd1c7 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -380,180 +380,182 @@ static int alac_decode_frame(AVCodecContext *avctx, 
void *data,
     init_get_bits(&alac->gb, inbuffer, input_buffer_size * 8);
 
     while (channels > 0) {
-    enum RawDataBlockType element;
-    int paired;
+        enum RawDataBlockType element;
+        int paired;
 
-    element = get_bits(&alac->gb, 3);
-    if (element > TYPE_CPE && element != TYPE_LFE) {
-        av_log(avctx, AV_LOG_ERROR, "syntax element unsupported: %d", element);
-        return AVERROR_PATCHWELCOME;
-    }
+        element = get_bits(&alac->gb, 3);
+        if (element > TYPE_CPE && element != TYPE_LFE) {
+            av_log(avctx, AV_LOG_ERROR, "syntax element unsupported: %d", 
element);
+            return AVERROR_PATCHWELCOME;
+        }
 
-    paired = (element == TYPE_CPE);
-    if (paired && channels < 2) {
-        av_log(avctx, AV_LOG_ERROR, "stereo frame in mono audio track\n");
-        return AVERROR_INVALIDDATA;
-    }
+        paired = (element == TYPE_CPE);
+        if (paired && channels < 2) {
+            av_log(avctx, AV_LOG_ERROR, "stereo frame in mono audio track\n");
+            return AVERROR_INVALIDDATA;
+        }
 
-    /* 2^result = something to do with output waiting.
-     * perhaps matters if we read > 1 frame in a pass?
-     */
-    skip_bits(&alac->gb, 4);
+        /* 2^result = something to do with output waiting.
+         * perhaps matters if we read > 1 frame in a pass?
+         */
+        skip_bits(&alac->gb, 4);
 
-    skip_bits(&alac->gb, 12); /* unknown, skip 12 bits */
+        skip_bits(&alac->gb, 12); /* unknown, skip 12 bits */
 
-    /* the output sample size is stored soon */
-    hassize = get_bits1(&alac->gb);
+        /* the output sample size is stored soon */
+        hassize = get_bits1(&alac->gb);
 
-    alac->extra_bits = get_bits(&alac->gb, 2) << 3;
+        alac->extra_bits = get_bits(&alac->gb, 2) << 3;
 
-    /* whether the frame is compressed */
-    isnotcompressed = get_bits1(&alac->gb);
+        /* whether the frame is compressed */
+        isnotcompressed = get_bits1(&alac->gb);
 
-    if (outputsamples == 0) {
-    if (hassize) {
-        /* now read the number of samples as a 32bit integer */
-        outputsamples = get_bits_long(&alac->gb, 32);
-        if(outputsamples > alac->setinfo_max_samples_per_frame){
-            av_log(avctx, AV_LOG_ERROR, "outputsamples %d > %d\n", 
outputsamples, alac->setinfo_max_samples_per_frame);
-            return -1;
+        if (outputsamples == 0) {
+            if (hassize) {
+                /* now read the number of samples as a 32bit integer */
+                outputsamples = get_bits_long(&alac->gb, 32);
+                if (outputsamples > alac->setinfo_max_samples_per_frame) {
+                    av_log(avctx, AV_LOG_ERROR, "outputsamples %d > %d\n",
+                           outputsamples, alac->setinfo_max_samples_per_frame);
+                    return -1;
+                }
+            }
+            if (outputsamples == 0)
+                outputsamples = alac->setinfo_max_samples_per_frame;
+
+            /* get output buffer */
+            if (outputsamples > INT32_MAX) {
+                av_log(avctx, AV_LOG_ERROR, "unsupported block size: %u\n",
+                       outputsamples);
+                return AVERROR_INVALIDDATA;
+            }
+            alac->frame.nb_samples = outputsamples;
+            if ((ret = avctx->get_buffer(avctx, &alac->frame)) < 0) {
+                av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
+                return ret;
+            }
+        } else {
+            if (hassize && get_bits_long(&alac->gb, 32) != outputsamples) {
+                av_log(avctx, AV_LOG_ERROR, "sample count disparity between 
channels\n");
+                return AVERROR_INVALIDDATA;
+            }
         }
-    }
-    if (outputsamples == 0)
-        outputsamples = alac->setinfo_max_samples_per_frame;
 
-    /* get output buffer */
-    if (outputsamples > INT32_MAX) {
-        av_log(avctx, AV_LOG_ERROR, "unsupported block size: %u\n", 
outputsamples);
-        return AVERROR_INVALIDDATA;
-    }
-    alac->frame.nb_samples = outputsamples;
-    if ((ret = avctx->get_buffer(avctx, &alac->frame)) < 0) {
-        av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
-        return ret;
-    }
-    } else {
-        if (hassize && get_bits_long(&alac->gb, 32) != outputsamples) {
-            av_log(avctx, AV_LOG_ERROR, "sample count disparity between 
channels\n");
-            return AVERROR_INVALIDDATA;
+        readsamplesize = alac->setinfo_sample_size - alac->extra_bits + paired;
+        if (readsamplesize > MIN_CACHE_BITS) {
+            av_log(avctx, AV_LOG_ERROR, "readsamplesize too big (%d)\n", 
readsamplesize);
+            return -1;
         }
-    }
-
-    readsamplesize = alac->setinfo_sample_size - alac->extra_bits + paired;
-    if (readsamplesize > MIN_CACHE_BITS) {
-        av_log(avctx, AV_LOG_ERROR, "readsamplesize too big (%d)\n", 
readsamplesize);
-        return -1;
-    }
 
-    if (!isnotcompressed) {
-        /* so it is compressed */
-        int16_t predictor_coef_table[2][32];
-        int predictor_coef_num[2];
-        int prediction_type[2];
-        int prediction_quantitization[2];
-        int ricemodifier[2];
+        if (!isnotcompressed) {
+            /* so it is compressed */
+            int16_t predictor_coef_table[2][32];
+            int predictor_coef_num[2];
+            int prediction_type[2];
+            int prediction_quantitization[2];
+            int ricemodifier[2];
 
-        interlacing_shift = get_bits(&alac->gb, 8);
-        interlacing_leftweight = get_bits(&alac->gb, 8);
+            interlacing_shift = get_bits(&alac->gb, 8);
+            interlacing_leftweight = get_bits(&alac->gb, 8);
 
-        for (ch = 0; ch <= paired; ch++) {
-            prediction_type[ch] = get_bits(&alac->gb, 4);
-            prediction_quantitization[ch] = get_bits(&alac->gb, 4);
+            for (ch = 0; ch <= paired; ch++) {
+                prediction_type[ch] = get_bits(&alac->gb, 4);
+                prediction_quantitization[ch] = get_bits(&alac->gb, 4);
 
-            ricemodifier[ch] = get_bits(&alac->gb, 3);
-            predictor_coef_num[ch] = get_bits(&alac->gb, 5);
+                ricemodifier[ch] = get_bits(&alac->gb, 3);
+                predictor_coef_num[ch] = get_bits(&alac->gb, 5);
 
-            /* read the predictor table */
-            for (i = 0; i < predictor_coef_num[ch]; i++)
-                predictor_coef_table[ch][i] = (int16_t)get_bits(&alac->gb, 16);
-        }
+                /* read the predictor table */
+                for (i = 0; i < predictor_coef_num[ch]; i++)
+                    predictor_coef_table[ch][i] = (int16_t)get_bits(&alac->gb, 
16);
+            }
 
-        if (alac->extra_bits) {
-            for (i = 0; i < outputsamples; i++) {
-                for (ch = 0; ch <= paired; ch++)
-                    alac->extra_bits_buffer[ch][i] = get_bits(&alac->gb, 
alac->extra_bits);
+            if (alac->extra_bits) {
+                for (i = 0; i < outputsamples; i++) {
+                    for (ch = 0; ch <= paired; ch++)
+                        alac->extra_bits_buffer[ch][i] = get_bits(&alac->gb, 
alac->extra_bits);
+                }
             }
-        }
-        for (ch = 0; ch <= paired; ch++) {
-            bastardized_rice_decompress(alac,
-                                        alac->predicterror_buffer[ch],
-                                        outputsamples,
-                                        readsamplesize,
-                                        alac->setinfo_rice_initialhistory,
-                                        alac->setinfo_rice_kmodifier,
-                                        ricemodifier[ch] * 
alac->setinfo_rice_historymult / 4,
-                                        (1 << alac->setinfo_rice_kmodifier) - 
1);
-
-            /* adaptive FIR filter */
-            if (prediction_type[ch] == 15) {
-                /* Prediction type 15 runs the adaptive FIR twice.
-                 * The first pass uses the special-case coef_num = 31, while
-                 * the second pass uses the coefs from the bitstream.
-                 *
-                 * However, this prediction type is not currently used by the
-                 * reference encoder.
-                 */
+            for (ch = 0; ch <= paired; ch++) {
+                bastardized_rice_decompress(alac,
+                                            alac->predicterror_buffer[ch],
+                                            outputsamples,
+                                            readsamplesize,
+                                            alac->setinfo_rice_initialhistory,
+                                            alac->setinfo_rice_kmodifier,
+                                            ricemodifier[ch] * 
alac->setinfo_rice_historymult / 4,
+                                            (1 << 
alac->setinfo_rice_kmodifier) - 1);
+
+                /* adaptive FIR filter */
+                if (prediction_type[ch] == 15) {
+                    /* Prediction type 15 runs the adaptive FIR twice.
+                     * The first pass uses the special-case coef_num = 31, 
while
+                     * the second pass uses the coefs from the bitstream.
+                     *
+                     * However, this prediction type is not currently used by 
the
+                     * reference encoder.
+                     */
+                    
predictor_decompress_fir_adapt(alac->predicterror_buffer[ch],
+                                                   
alac->predicterror_buffer[ch],
+                                                   outputsamples, 
readsamplesize,
+                                                   NULL, 31, 0);
+                } else if (prediction_type[ch] > 0) {
+                    av_log(avctx, AV_LOG_WARNING, "unknown prediction type: 
%i\n",
+                           prediction_type[ch]);
+                }
                 predictor_decompress_fir_adapt(alac->predicterror_buffer[ch],
-                                               alac->predicterror_buffer[ch],
+                                               alac->outputsamples_buffer[ch],
                                                outputsamples, readsamplesize,
-                                               NULL, 31, 0);
-            } else if (prediction_type[ch] > 0) {
-                av_log(avctx, AV_LOG_WARNING, "unknown prediction type: %i\n",
-                       prediction_type[ch]);
+                                               predictor_coef_table[ch],
+                                               predictor_coef_num[ch],
+                                               prediction_quantitization[ch]);
             }
-            predictor_decompress_fir_adapt(alac->predicterror_buffer[ch],
-                                           alac->outputsamples_buffer[ch],
-                                           outputsamples, readsamplesize,
-                                           predictor_coef_table[ch],
-                                           predictor_coef_num[ch],
-                                           prediction_quantitization[ch]);
-        }
-    } else {
-        /* not compressed, easy case */
-        for (i = 0; i < outputsamples; i++) {
-            for (ch = 0; ch <= paired; ch++) {
-                alac->outputsamples_buffer[ch][i] = get_sbits_long(&alac->gb,
-                                                                   
alac->setinfo_sample_size);
+        } else {
+            /* not compressed, easy case */
+            for (i = 0; i < outputsamples; i++) {
+                for (ch = 0; ch <= paired; ch++) {
+                    alac->outputsamples_buffer[ch][i] = 
get_sbits_long(&alac->gb,
+                                                                       
alac->setinfo_sample_size);
+                }
             }
+            alac->extra_bits = 0;
+            interlacing_shift = 0;
+            interlacing_leftweight = 0;
         }
-        alac->extra_bits = 0;
-        interlacing_shift = 0;
-        interlacing_leftweight = 0;
-    }
 
-    if (paired && interlacing_leftweight) {
-        decorrelate_stereo(alac->outputsamples_buffer, outputsamples,
-                           interlacing_shift, interlacing_leftweight);
-    }
-    offsetL = alac_channel_layout_offsets[avctx->channels - 1][avctx->channels 
- channels];
-    if (paired)
-        offsetR = alac_channel_layout_offsets[avctx->channels - 
1][avctx->channels - channels + 1];
+        if (paired && interlacing_leftweight) {
+            decorrelate_stereo(alac->outputsamples_buffer, outputsamples,
+                               interlacing_shift, interlacing_leftweight);
+        }
+        offsetL = alac_channel_layout_offsets[avctx->channels - 
1][avctx->channels - channels];
+        if (paired)
+            offsetR = alac_channel_layout_offsets[avctx->channels - 
1][avctx->channels - channels + 1];
 
-    if (alac->extra_bits) {
-        append_extra_bits(alac->outputsamples_buffer, alac->extra_bits_buffer,
-                          alac->extra_bits, paired, outputsamples);
-    }
+        if (alac->extra_bits) {
+            append_extra_bits(alac->outputsamples_buffer, 
alac->extra_bits_buffer,
+                              alac->extra_bits, paired, outputsamples);
+        }
 
-    switch(alac->setinfo_sample_size) {
-    case 16: {
-        int16_t *outbuffer = (int16_t *)alac->frame.data[0];
-        for (i = 0; i < outputsamples; i++) {
-            outbuffer[i * avctx->channels + offsetL] = 
alac->outputsamples_buffer[0][i];
-            if (paired)
-                outbuffer[i * avctx->channels + offsetR] = 
alac->outputsamples_buffer[1][i];
-        }}
-        break;
-    case 24: {
-        int32_t *outbuffer = (int32_t *)alac->frame.data[0];
-        for (i = 0; i < outputsamples; i++) {
-            outbuffer[i * avctx->channels + offsetL] = 
alac->outputsamples_buffer[0][i] << 8;
-            if (paired)
-                outbuffer[i * avctx->channels + offsetR] = 
alac->outputsamples_buffer[1][i] << 8;
-        }}
-        break;
-    }
+        switch(alac->setinfo_sample_size) {
+        case 16: {
+            int16_t *outbuffer = (int16_t *)alac->frame.data[0];
+            for (i = 0; i < outputsamples; i++) {
+                outbuffer[i * avctx->channels + offsetL] = 
alac->outputsamples_buffer[0][i];
+                if (paired)
+                    outbuffer[i * avctx->channels + offsetR] = 
alac->outputsamples_buffer[1][i];
+            }}
+            break;
+        case 24: {
+            int32_t *outbuffer = (int32_t *)alac->frame.data[0];
+            for (i = 0; i < outputsamples; i++) {
+                outbuffer[i * avctx->channels + offsetL] = 
alac->outputsamples_buffer[0][i] << 8;
+                if (paired)
+                    outbuffer[i * avctx->channels + offsetR] = 
alac->outputsamples_buffer[1][i] << 8;
+            }}
+            break;
+        }
 
-    channels -= (paired) ? 2 : 1;
+        channels -= (paired) ? 2 : 1;
     }
 
     if (get_bits(&alac->gb, 3) != TYPE_END)
-- 
1.7.1

_______________________________________________
libav-devel mailing list
libav-devel@libav.org
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to