]> git.sesse.net Git - vlc/commitdiff
avcodec: avoid division by zero
authorTristan Matthews <le.businessman@gmail.com>
Fri, 3 May 2013 12:28:48 +0000 (08:28 -0400)
committerJean-Baptiste Kempf <jb@videolan.org>
Fri, 3 May 2013 12:50:11 +0000 (14:50 +0200)
Setting align to 0 to get default behaviour only works as of
libavutil 51.27.2 (libav) and 51.46.100 (ffmpeg)
See libav commit 0109a09dc3850eb5dbff84a7bb50eb252a5a8f22
Fixes #8508.

Signed-off-by: Jean-Baptiste Kempf <jb@videolan.org>
modules/codec/avcodec/encoder.c

index 5c0638513a3b48d4697145e4b39e4c7670c875ce..57d4ef496d68202eb010e7a55e7a2b4a7d4c10df 100644 (file)
@@ -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,46,100 )
+        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,46,100 )
+        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);