[xiph-commits] r3005 - liboggplay/trunk/plugin

tahn at svn.annodex.net tahn at svn.annodex.net
Tue Jun 19 18:22:16 PDT 2007


Author: tahn
Date: 2007-06-19 18:22:16 -0700 (Tue, 19 Jun 2007)
New Revision: 3005

Modified:
   liboggplay/trunk/plugin/plugin_gui_mac.c
Log:
Slight tweak to audio handling so that we don't keep trying to re-open the device if it's failed.


Modified: liboggplay/trunk/plugin/plugin_gui_mac.c
===================================================================
--- liboggplay/trunk/plugin/plugin_gui_mac.c	2007-06-19 13:43:08 UTC (rev 3004)
+++ liboggplay/trunk/plugin/plugin_gui_mac.c	2007-06-20 01:22:16 UTC (rev 3005)
@@ -311,7 +311,7 @@
 }
 
 
-static void
+static bool
 init_audio(PluginWindowInfo *info, ThreadData *td) {
 
   if (sa_stream_create_pcm(&td->audio_handle, NULL,
@@ -320,12 +320,14 @@
         get_audio_channels(info->oggplay_handle)) != SA_SUCCESS
   ) {
     td->audio_handle = NULL;
-    return;
+    return FALSE;
   }
   if (sa_stream_open(td->audio_handle) != SA_SUCCESS) {
     sa_stream_destroy(td->audio_handle);
     td->audio_handle = NULL;
+    return FALSE;
   }
+  return TRUE;
 }
 
 
@@ -350,6 +352,7 @@
   ThreadData          td;
   bool                paused = FALSE;
   bool                drop_video_frame = FALSE;
+  bool                audio_ok = TRUE;
   int64_t             playback_target = 0;
   int64_t             time_ref = 0;
   int64_t             cur_time;
@@ -451,7 +454,9 @@
       if (!paused) {
         paused = TRUE;
         drop_video_frame = FALSE;
-        sa_stream_pause(td.audio_handle);
+        if (td.audio_handle != NULL) {
+          sa_stream_pause(td.audio_handle);
+        }
       }
       SEM_SIGNAL(info->playback_sem);
     } else if (info->playback_state_change == SET_PLAY) {
@@ -459,7 +464,9 @@
       info->playback_state_change = NO_CHANGE;
       if (paused) {
         paused = FALSE;
-        sa_stream_resume(td.audio_handle);
+        if (td.audio_handle != NULL) {
+          sa_stream_resume(td.audio_handle);
+        }
 
         /*
          * The audio device restarts its byte counter when we resume, so
@@ -481,9 +488,12 @@
      * files have "patchy" audio tracks -- they provide large chunks of audio
      * every few video frames, with nothing in between.
      */
-    if (have_audio) {
+    if (have_audio && audio_ok) {
       if (td.audio_handle == NULL) {
-        init_audio(info, &td);
+        /*
+         * Don't keep trying to re-open the audio unit if it's borked.
+         */
+        audio_ok = init_audio(info, &td);
       }
       if (td.audio_handle != NULL) {
         if (sa_stream_write(td.audio_handle, td.frame_data.samples,
@@ -494,6 +504,7 @@
            */
           shutdown_audio(info, &td);
           playback_target = 0;
+          audio_ok = FALSE;
         }
       }
     }



More information about the commits mailing list