[vlc-devel] [PATCH] avcodec: avoid division by zero

Tristan Matthews le.businessman at gmail.com
Fri May 3 08:31:49 CEST 2013


Setting align to 0 to get default behaviour only works as of libavutil 51.27.2
See libav commit 0109a09dc3850eb5dbff84a7bb50eb252a5a8f22
Fixes #8508.
---
 modules/codec/avcodec/encoder.c | 14 ++++++++++++--
 1 file changed, 12 insertions(+), 2 deletions(-)

diff --git a/modules/codec/avcodec/encoder.c b/modules/codec/avcodec/encoder.c
index 5c06385..80bce30 100644
--- a/modules/codec/avcodec/encoder.c
+++ b/modules/codec/avcodec/encoder.c
@@ -1120,6 +1120,11 @@ static block_t *EncodeAudio( encoder_t *p_enc, block_t *p_aout_buf )
     {
         //How much we need to copy from new packet
         const int leftover = leftover_samples * p_enc->fmt_in.audio.i_channels * p_sys->i_sample_bytes;
+#if LIBAVUTIL_VERSION_CHECK( 51,27,2,0,0 )
+        const int align = 0;
+#else
+        const int align = 1;
+#endif
 
         AVPacket packet = {0};
         avcodec_get_frame_defaults( p_sys->frame );
@@ -1146,7 +1151,7 @@ static block_t *EncodeAudio( encoder_t *p_enc, block_t *p_aout_buf )
         if( avcodec_fill_audio_frame( p_sys->frame, p_enc->fmt_in.audio.i_channels,
                 p_sys->p_context->sample_fmt, p_sys->p_buffer,
                 leftover + buffer_delay,
-                0) < 0 )
+                align) < 0 )
             msg_Err( p_enc, "filling error on fillup" );
 
         buffer_delay = 0;
@@ -1210,6 +1215,11 @@ static block_t *EncodeAudio( encoder_t *p_enc, block_t *p_aout_buf )
            ( p_sys->b_variable && p_aout_buf->i_nb_samples ) )
     {
         AVPacket packet = {0};
+#if LIBAVUTIL_VERSION_CHECK( 51,27,2,0,0 )
+        const int align = 0;
+#else
+        const int align = 1;
+#endif
 
         if( unlikely( p_aout_buf->i_pts > VLC_TS_INVALID &&
                       p_aout_buf->i_pts != date_Get( &p_sys->buffer_date ) ) )
@@ -1234,7 +1244,7 @@ static block_t *EncodeAudio( encoder_t *p_enc, block_t *p_aout_buf )
                                     p_sys->p_context->sample_fmt,
                                     p_sys->b_planar ? p_sys->p_buffer : p_aout_buf->p_buffer,
                                     __MIN(p_sys->i_buffer_out, p_aout_buf->i_buffer),
-                                    0) < 0 )
+                                    align) < 0 )
                  msg_Err( p_enc, "filling error on encode" );
 
         p_aout_buf->p_buffer     += (p_sys->frame->nb_samples * p_enc->fmt_in.audio.i_channels * p_sys->i_sample_bytes);
-- 
1.8.1.2




More information about the vlc-devel mailing list