Browse code

ffplay: fix silence insertion on error or pause

Insertion of silence was a bit broken since
df34b700981de606ca4847e1ed0bfdf9ac3e9104 because the info whether or not the
source buffer supposed to be silence must be kept between callbacks. Failing to
do so causes rogue samples from the last buffer to be presented, I guess even a
crash can occur under some circumstances.

This patch uses a NULL audio_buf to keep the silence state across audio
callbacks.

Reviewed-by: Lukasz Marek <lukasz.m.luki2 at gmail.com>
Signed-off-by: Marton Balint <cus@passwd.hu>

Marton Balint authored on 2016/04/04 04:23:41
Showing 1 changed files
... ...
@@ -2531,7 +2531,7 @@ static int audio_decode_frame(VideoState *is)
2531 2531
 static void sdl_audio_callback(void *opaque, Uint8 *stream, int len)
2532 2532
 {
2533 2533
     VideoState *is = opaque;
2534
-    int audio_size, len1, silence = 0;
2534
+    int audio_size, len1;
2535 2535
 
2536 2536
     audio_callback_time = av_gettime_relative();
2537 2537
 
... ...
@@ -2540,7 +2540,7 @@ static void sdl_audio_callback(void *opaque, Uint8 *stream, int len)
2540 2540
            audio_size = audio_decode_frame(is);
2541 2541
            if (audio_size < 0) {
2542 2542
                 /* if error, just output silence */
2543
-               silence = 1;
2543
+               is->audio_buf = NULL;
2544 2544
                is->audio_buf_size = SDL_AUDIO_MIN_BUFFER_SIZE / is->audio_tgt.frame_size * is->audio_tgt.frame_size;
2545 2545
            } else {
2546 2546
                if (is->show_mode != SHOW_MODE_VIDEO)
... ...
@@ -2552,11 +2552,11 @@ static void sdl_audio_callback(void *opaque, Uint8 *stream, int len)
2552 2552
         len1 = is->audio_buf_size - is->audio_buf_index;
2553 2553
         if (len1 > len)
2554 2554
             len1 = len;
2555
-        if (!is->muted && !silence && is->audio_volume == SDL_MIX_MAXVOLUME)
2555
+        if (!is->muted && is->audio_buf && is->audio_volume == SDL_MIX_MAXVOLUME)
2556 2556
             memcpy(stream, (uint8_t *)is->audio_buf + is->audio_buf_index, len1);
2557 2557
         else {
2558 2558
             memset(stream, 0, len1);
2559
-            if (!is->muted && !silence)
2559
+            if (!is->muted && is->audio_buf)
2560 2560
                 SDL_MixAudio(stream, (uint8_t *)is->audio_buf + is->audio_buf_index, len1, is->audio_volume);
2561 2561
         }
2562 2562
         len -= len1;