changeset 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 1ccc7a9c7fc2
children c64da1c724b9
files ChangeLog src/madplug/configure.c src/madplug/decoder.c src/madplug/plugin.c src/madplug/plugin.h
diffstat 5 files changed, 43 insertions(+), 15 deletions(-) [+]
line wrap: on
line diff
--- a/ChangeLog	Thu Apr 05 10:47:18 2007 -0700
+++ b/ChangeLog	Thu Apr 05 21:12:59 2007 -0700
@@ -1,3 +1,12 @@
+2007-04-05 17:47:18 +0000  Giacomo Lozito <james@develia.org>
+  revision [1958]
+  - statusicon: memorize player windows visibility status between sessions
+  trunk/src/statusicon/si.c     |   25 ++++++++++++-------------
+  trunk/src/statusicon/si_cfg.c |   17 +++++++++++++++++
+  trunk/src/statusicon/si_cfg.h |    3 +++
+  3 files changed, 32 insertions(+), 13 deletions(-)
+
+
 2007-04-04 18:49:12 +0000  Giacomo Lozito <james@develia.org>
   revision [1946]
   - statusicon: smarter show/hide on statusicon click (plugin will now correctly handle the situation where the player window is always hidden and the playlist window should be shown/hidden)
--- a/src/madplug/configure.c	Thu Apr 05 10:47:18 2007 -0700
+++ b/src/madplug/configure.c	Thu Apr 05 21:12:59 2007 -0700
@@ -27,7 +27,7 @@
 
 static GtkWidget *configure_win = NULL;
 static GtkWidget *vbox;
-static GtkWidget *fast_playback, *use_xing, *dither, *sjis, *show_avg;
+static GtkWidget *fast_playback, *use_xing, *dither, *sjis, *show_avg, *reopen;
 static GtkWidget *RG_enable, *RG_track_mode, *RG_default, *pregain,
     *hard_limit;
 static GtkWidget *title_id3_box, *title_tag_desc;
@@ -38,7 +38,7 @@
     ConfigDb *db;
     const gchar *text = NULL;
 #ifdef DEBUG
-    g_message("saving\n");
+    g_message("saving");
 #endif
 
     audmad_config.fast_play_time_calc =
@@ -51,6 +51,8 @@
         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(sjis));
     audmad_config.show_avg_vbr_bitrate =
         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(show_avg));
+    audmad_config.force_reopen_audio = 
+        gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(reopen));
 
     audmad_config.replaygain.enable =
         gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(RG_enable));
@@ -100,6 +102,8 @@
 
     bmp_cfg_db_set_bool(db, "MAD", "show_avg_vbr_bitrate",
                             audmad_config.show_avg_vbr_bitrate);
+    bmp_cfg_db_set_bool(db, "MAD", "force_reopen_audio",
+                            audmad_config.force_reopen_audio);
 
     bmp_cfg_db_close(db);
     gtk_widget_destroy(configure_win);
@@ -179,6 +183,11 @@
     gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(show_avg),
                                  audmad_config.show_avg_vbr_bitrate);
 
+    reopen = gtk_check_button_new_with_label(_("Force reopen audio when audio type changed"));
+    gtk_box_pack_start(GTK_BOX(vbox2), reopen, TRUE, TRUE, 0);
+    gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(reopen),
+                                 audmad_config.force_reopen_audio);
+
     gtk_notebook_append_page(GTK_NOTEBOOK(notebook), vbox2, gtk_label_new(_("General")));
 
     vbox2 = gtk_vbox_new(FALSE, 5);
--- 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);
--- a/src/madplug/plugin.c	Thu Apr 05 10:47:18 2007 -0700
+++ b/src/madplug/plugin.c	Thu Apr 05 21:12:59 2007 -0700
@@ -129,6 +129,7 @@
     audmad_config.replaygain.track_mode = FALSE;
     audmad_config.title_override = FALSE;
     audmad_config.show_avg_vbr_bitrate = TRUE;
+    audmad_config.force_reopen_audio = FALSE;
 
     db = bmp_cfg_db_open();
     if (db) {
@@ -154,6 +155,8 @@
                               &audmad_config.id3_format);
         bmp_cfg_db_get_bool(db, "MAD", "show_avg_vbr_bitrate",
                             &audmad_config.show_avg_vbr_bitrate);
+        bmp_cfg_db_get_bool(db, "MAD", "force_reopen_audio",
+                            &audmad_config.force_reopen_audio);
 
         bmp_cfg_db_close(db);
     }
--- a/src/madplug/plugin.h	Thu Apr 05 10:47:18 2007 -0700
+++ b/src/madplug/plugin.h	Thu Apr 05 21:12:59 2007 -0700
@@ -122,6 +122,7 @@
     gboolean title_override;
     gchar *id3_format;
     gboolean show_avg_vbr_bitrate;
+    gboolean force_reopen_audio;
 };
 
 // global variables