[FFmpeg-devel] [PATCH] avcodec/alac: also use a temp buffer for 24bit samples

James Almer jamrial at gmail.com
Tue Oct 6 21:06:27 CEST 2015


Since AVFrame.extended_data is apparently not padded, simd functions
could in some cases overread, so make the decoder use a temp buffer
unconditionally.

Signed-off-by: James Almer <jamrial at gmail.com>
---
 libavcodec/alac.c | 18 +++++-------------
 1 file changed, 5 insertions(+), 13 deletions(-)

diff --git a/libavcodec/alac.c b/libavcodec/alac.c
index 146668e..394bd19 100644
--- a/libavcodec/alac.c
+++ b/libavcodec/alac.c
@@ -80,7 +80,6 @@ typedef struct ALACContext {
     int extra_bits;     /**< number of extra bits beyond 16-bit */
     int nb_samples;     /**< number of samples in the current frame */
 
-    int direct_output;
     int extra_bit_bug;
 
     ALACDSPContext dsp;
@@ -278,10 +277,6 @@ static int decode_element(AVCodecContext *avctx, AVFrame *frame, int ch_index,
         return AVERROR_INVALIDDATA;
     }
     alac->nb_samples = output_samples;
-    if (alac->direct_output) {
-        for (ch = 0; ch < channels; ch++)
-            alac->output_samples_buffer[ch] = (int32_t *)frame->extended_data[ch_index + ch];
-    }
 
     if (is_compressed) {
         int16_t lpc_coefs[2][32];
@@ -393,8 +388,9 @@ static int decode_element(AVCodecContext *avctx, AVFrame *frame, int ch_index,
         break;
     case 24: {
         for (ch = 0; ch < channels; ch++) {
+            int32_t *outbuffer = (int32_t *)frame->extended_data[ch_index + ch];
             for (i = 0; i < alac->nb_samples; i++)
-                alac->output_samples_buffer[ch][i] <<= 8;
+                *outbuffer++ = alac->output_samples_buffer[ch][i] << 8;
         }}
         break;
     }
@@ -468,8 +464,7 @@ static av_cold int alac_decode_close(AVCodecContext *avctx)
     int ch;
     for (ch = 0; ch < FFMIN(alac->channels, 2); ch++) {
         av_freep(&alac->predict_error_buffer[ch]);
-        if (!alac->direct_output)
-            av_freep(&alac->output_samples_buffer[ch]);
+        av_freep(&alac->output_samples_buffer[ch]);
         av_freep(&alac->extra_bits_buffer[ch]);
     }
 
@@ -491,11 +486,8 @@ static int allocate_buffers(ALACContext *alac)
         FF_ALLOC_OR_GOTO(alac->avctx, alac->predict_error_buffer[ch],
                          buf_size, buf_alloc_fail);
 
-        alac->direct_output = alac->sample_size > 16;
-        if (!alac->direct_output) {
-            FF_ALLOC_OR_GOTO(alac->avctx, alac->output_samples_buffer[ch],
-                             buf_size, buf_alloc_fail);
-        }
+        FF_ALLOC_OR_GOTO(alac->avctx, alac->output_samples_buffer[ch],
+                         buf_size, buf_alloc_fail);
 
         FF_ALLOC_OR_GOTO(alac->avctx, alac->extra_bits_buffer[ch],
                          buf_size, buf_alloc_fail);
-- 
2.5.2



More information about the ffmpeg-devel mailing list