From 8ff3209e1c1588b0b7d4ff0b688d86ee14e6cc85 Mon Sep 17 00:00:00 2001 From: "Gene Z. Ragan" Date: Sun, 25 Feb 2001 00:40:27 +0000 Subject: [PATCH] reviewed by: George Lebl 2001-02-24 Gene Z. Ragan reviewed by: George Lebl Fixed bug 3546, Nautilus fails if MP3 previews in rapid succession Fixed bug 5105, Preview sound file during MP3 playback -> "/dev/dsp: Device or resource busy" * libnautilus-extensions/nautilus-global-preferences.h: Add a preference that that tracks the result of an intial audio output capability check during nautilus_sound_initialize(). * libnautilus-extensions/nautilus-sound.c: (nautilus_sound_initialize): Check audio output capability and save the result of the check in a preference. (nautilus_sound_can_play_sound): Check saved preference instead of opening and closing esd as a way to check if sound output is available. The constant opening and closing creating a latency problem withing esd and was affecting the audio preview mechanism. --- ChangeLog | 24 +++++++++++++ .../nautilus-global-preferences.h | 3 ++ libnautilus-extensions/nautilus-sound.c | 35 +++++++++++++------ .../nautilus-global-preferences.h | 3 ++ libnautilus-private/nautilus-sound.c | 35 +++++++++++++------ src/file-manager/fm-icon-view.c | 6 ++-- 6 files changed, 82 insertions(+), 24 deletions(-) diff --git a/ChangeLog b/ChangeLog index 8816dcc98..adbe3979b 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,27 @@ +2001-02-24 Gene Z. Ragan + + reviewed by: George Lebl + + Fixed bug 3546, Nautilus fails if MP3 previews in rapid succession + + Fixed bug 5105, Preview sound file during MP3 playback + -> "/dev/dsp: Device or resource busy" + + * libnautilus-extensions/nautilus-global-preferences.h: + Add a preference that that tracks the result of an intial + audio output capability check during nautilus_sound_initialize(). + + * libnautilus-extensions/nautilus-sound.c: + (nautilus_sound_initialize): + Check audio output capability and save the result of the check in + a preference. + + (nautilus_sound_can_play_sound): + Check saved preference instead of opening and closing esd as a + way to check if sound output is available. The constant opening + and closing creating a latency problem withing esd and was + affecting the audio preview mechanism. + 2001-02-24 Gene Z. Ragan reviewed by: Seth Nickell diff --git a/libnautilus-extensions/nautilus-global-preferences.h b/libnautilus-extensions/nautilus-global-preferences.h index 96eb95d67..2782f24a6 100644 --- a/libnautilus-extensions/nautilus-global-preferences.h +++ b/libnautilus-extensions/nautilus-global-preferences.h @@ -35,8 +35,11 @@ BEGIN_GNOME_DECLS #define NAUTILUS_PREFERENCES_ICON_CAPTIONS "icon_view/captions" /* How wide the sidebar is (or how wide it will be when expanded) */ #define NAUTILUS_PREFERENCES_SIDEBAR_WIDTH "preferences/sidebar_width" + /* Keep track of the sound playing process */ #define NAUTILUS_PREFERENCES_CURRENT_SOUND_STATE "preferences/sound_state" +/* Does the system have audio output capability */ +#define NAUTILUS_PREFERENCES_HAS_AUDIO_OUT "preferences/audio_out" /* Window options */ #define NAUTILUS_PREFERENCES_WINDOW_ALWAYS_NEW "preferences/window_always_new" diff --git a/libnautilus-extensions/nautilus-sound.c b/libnautilus-extensions/nautilus-sound.c index 68979b0a6..f859dbd1d 100644 --- a/libnautilus-extensions/nautilus-sound.c +++ b/libnautilus-extensions/nautilus-sound.c @@ -42,6 +42,7 @@ kill_sound_if_necessary (void) /* fetch the sound state */ sound_process = nautilus_preferences_get_integer (NAUTILUS_PREFERENCES_CURRENT_SOUND_STATE); + /* if there was a sound playing, kill it */ if (sound_process > 0) { kill (-sound_process, SIGTERM); @@ -54,7 +55,22 @@ kill_sound_if_necessary (void) void nautilus_sound_initialize (void) { + int open_result; + nautilus_preferences_set_integer (NAUTILUS_PREFERENCES_CURRENT_SOUND_STATE, 0); + + /* Check and see if the system itself can play sound. We do this by attmepting + * to open esd. Save the result of this as a preference. This value only + * means that the system has audio out capabilities and should not be used as + * a way to check the current audio output state. + */ + open_result = esd_audio_open (); + if (open_result < 0) { + nautilus_preferences_set_integer (NAUTILUS_PREFERENCES_HAS_AUDIO_OUT, 0); + } else { + nautilus_preferences_set_integer (NAUTILUS_PREFERENCES_HAS_AUDIO_OUT, 1); + esd_audio_close (); + } } /* if there is a sound registered, kill it, and register the empty sound */ @@ -79,23 +95,22 @@ nautilus_sound_register_sound (pid_t sound_process) nautilus_preferences_set_integer (NAUTILUS_PREFERENCES_CURRENT_SOUND_STATE, sound_process); } +/* This function does two things. First it checks to see a sound is currently playing. If it is, + * it returns the process id of the external application playing the sound. If no sound is playing, + * it return the value set in nautilus_sound_initialize() when system audio output capabilites + * were queried. + */ gboolean nautilus_sound_can_play_sound (void) { - int open_result, sound_process; - + int sound_process; + /* first see if there's already one in progress; if so, return true */ sound_process = nautilus_preferences_get_integer (NAUTILUS_PREFERENCES_CURRENT_SOUND_STATE); if (sound_process > 0) { return TRUE; } - open_result = esd_audio_open (); - if (open_result < 0) { - return FALSE; - } - - esd_audio_close (); - return TRUE; + /* Now check and see if system has audio out capabilites */ + return nautilus_preferences_get_integer (NAUTILUS_PREFERENCES_HAS_AUDIO_OUT); } - diff --git a/libnautilus-private/nautilus-global-preferences.h b/libnautilus-private/nautilus-global-preferences.h index 96eb95d67..2782f24a6 100644 --- a/libnautilus-private/nautilus-global-preferences.h +++ b/libnautilus-private/nautilus-global-preferences.h @@ -35,8 +35,11 @@ BEGIN_GNOME_DECLS #define NAUTILUS_PREFERENCES_ICON_CAPTIONS "icon_view/captions" /* How wide the sidebar is (or how wide it will be when expanded) */ #define NAUTILUS_PREFERENCES_SIDEBAR_WIDTH "preferences/sidebar_width" + /* Keep track of the sound playing process */ #define NAUTILUS_PREFERENCES_CURRENT_SOUND_STATE "preferences/sound_state" +/* Does the system have audio output capability */ +#define NAUTILUS_PREFERENCES_HAS_AUDIO_OUT "preferences/audio_out" /* Window options */ #define NAUTILUS_PREFERENCES_WINDOW_ALWAYS_NEW "preferences/window_always_new" diff --git a/libnautilus-private/nautilus-sound.c b/libnautilus-private/nautilus-sound.c index 68979b0a6..f859dbd1d 100644 --- a/libnautilus-private/nautilus-sound.c +++ b/libnautilus-private/nautilus-sound.c @@ -42,6 +42,7 @@ kill_sound_if_necessary (void) /* fetch the sound state */ sound_process = nautilus_preferences_get_integer (NAUTILUS_PREFERENCES_CURRENT_SOUND_STATE); + /* if there was a sound playing, kill it */ if (sound_process > 0) { kill (-sound_process, SIGTERM); @@ -54,7 +55,22 @@ kill_sound_if_necessary (void) void nautilus_sound_initialize (void) { + int open_result; + nautilus_preferences_set_integer (NAUTILUS_PREFERENCES_CURRENT_SOUND_STATE, 0); + + /* Check and see if the system itself can play sound. We do this by attmepting + * to open esd. Save the result of this as a preference. This value only + * means that the system has audio out capabilities and should not be used as + * a way to check the current audio output state. + */ + open_result = esd_audio_open (); + if (open_result < 0) { + nautilus_preferences_set_integer (NAUTILUS_PREFERENCES_HAS_AUDIO_OUT, 0); + } else { + nautilus_preferences_set_integer (NAUTILUS_PREFERENCES_HAS_AUDIO_OUT, 1); + esd_audio_close (); + } } /* if there is a sound registered, kill it, and register the empty sound */ @@ -79,23 +95,22 @@ nautilus_sound_register_sound (pid_t sound_process) nautilus_preferences_set_integer (NAUTILUS_PREFERENCES_CURRENT_SOUND_STATE, sound_process); } +/* This function does two things. First it checks to see a sound is currently playing. If it is, + * it returns the process id of the external application playing the sound. If no sound is playing, + * it return the value set in nautilus_sound_initialize() when system audio output capabilites + * were queried. + */ gboolean nautilus_sound_can_play_sound (void) { - int open_result, sound_process; - + int sound_process; + /* first see if there's already one in progress; if so, return true */ sound_process = nautilus_preferences_get_integer (NAUTILUS_PREFERENCES_CURRENT_SOUND_STATE); if (sound_process > 0) { return TRUE; } - open_result = esd_audio_open (); - if (open_result < 0) { - return FALSE; - } - - esd_audio_close (); - return TRUE; + /* Now check and see if system has audio out capabilites */ + return nautilus_preferences_get_integer (NAUTILUS_PREFERENCES_HAS_AUDIO_OUT); } - diff --git a/src/file-manager/fm-icon-view.c b/src/file-manager/fm-icon-view.c index a36355439..82130c345 100644 --- a/src/file-manager/fm-icon-view.c +++ b/src/file-manager/fm-icon-view.c @@ -1327,7 +1327,6 @@ band_select_ended_callback (NautilusIconContainer *container, /* here's the timer task that actually plays the file using mpg123. */ /* FIXME bugzilla.eazel.com 1258: we should get the application from our mime-type stuff */ - static int play_file (gpointer callback_data) { @@ -1376,7 +1375,7 @@ play_file (gpointer callback_data) /* this routine is invoked from the preview signal handler to preview a sound file. We want to wait a suitable delay until we actually do it, so set up a timer task to actually start playing. If we move out before the task files, we remove it. */ - + static void preview_sound (NautilusFile *file, gboolean start_flag) { @@ -1391,7 +1390,6 @@ preview_sound (NautilusFile *file, gboolean start_flag) } } - static gboolean should_preview_sound (NautilusFile *file) { int preview_mode; @@ -1401,7 +1399,7 @@ should_preview_sound (NautilusFile *file) { if (preview_mode == NAUTILUS_SPEED_TRADEOFF_NEVER) { return FALSE; } - /* the followinf is disabled until we can preview remote sounds, which we currently can't do */ + /* the following is disabled until we can preview remote sounds, which we currently can't do */ /* if (preview_mode == NAUTILUS_SPEED_TRADEOFF_ALWAYS) { return TRUE;