diff src/madplug/decoder.c @ 916:a8494c2a87eb trunk

[svn] revise reopen output code for #880. time count would be reset if output was closed. so I took two measures for it. - 1. time count will be recorded and restored on reopen. this seems to be right way, but it causes a short stoppage of playback. - 2. introduce a new plugin option "force_reopen_audio". if this is set to FALSE (default), decoder will not reopen output. this is a bit rude, but does not cause any interruption.
author yaz
date Thu, 05 Apr 2007 21:12:59 -0700
parents f0846bdd9de6
children f931c9d744a5
line wrap: on
line diff
--- a/src/madplug/decoder.c	Thu Apr 05 10:47:18 2007 -0700
+++ b/src/madplug/decoder.c	Thu Apr 05 21:12:59 2007 -0700
@@ -596,7 +596,7 @@
                 || info->channels !=
                 (guint) MAD_NCHANNELS(&frame.header)) {
 #ifdef DEBUG
-                g_message("re-opening audio due to change in audio type");
+                g_message("change in audio type detected");
                 g_message("old: frequency = %d, channels = %d", info->freq,
                           info->channels);
                 g_message("new: frequency = %d, channels = %d",
@@ -605,22 +605,28 @@
 #endif                          /* DEBUG */
                 info->freq = frame.header.samplerate;
                 info->channels = MAD_NCHANNELS(&frame.header);
-                info->playback->output->close_audio();
 
-                if(check_audio_param(info) == FALSE)
-                    return NULL;
-
-                if (!info->playback->output->open_audio(info->fmt, info->freq,
-                                                   info->channels)) {
-                    g_mutex_lock(pb_mutex);
-                    info->playback->error = TRUE;
-                    info->playback->eof = 1;
-                    g_mutex_unlock(pb_mutex);
-                    g_message("failed to re-open audio output: %s",
+                if(audmad_config.force_reopen_audio && check_audio_param(info)) {
+                    gint current_time = info->playback->output->output_time();
+#ifdef DEBUG
+                    g_message("re-opening audio due to change in audio type");
+#endif
+                    info->playback->output->close_audio();
+                    if (!info->playback->output->open_audio(info->fmt, info->freq,
+                                                            info->channels)) {
+                        g_mutex_lock(pb_mutex);
+                        info->playback->error = TRUE;
+                        info->playback->eof = 1;
+                        g_mutex_unlock(pb_mutex);
+                        g_message("failed to re-open audio output: %s",
                                   info->playback->output->description);
-                    return NULL;
+                        return NULL;
+                    }
+                    // restore time and advance 0.5sec
+                    info->seek = current_time + 500;
                 }
             }
+
             if (!info->playback->playing)
                 break;
             mad_synth_frame(&synth, &frame);