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

shans at svn.annodex.net shans at svn.annodex.net
Wed Jun 13 18:25:58 PDT 2007


Author: shans
Date: 2007-06-13 18:25:58 -0700 (Wed, 13 Jun 2007)
New Revision: 2919

Modified:
   liboggplay/trunk/plugin/plugin_gui_linux.c
Log:
Refactored maybe_switch_oggplays function, so that this can be called
even if no frame data has arrived
Removed debugging printfs
Reintroduced shutting of a newly created oggplay handle if another change
request arrives



Modified: liboggplay/trunk/plugin/plugin_gui_linux.c
===================================================================
--- liboggplay/trunk/plugin/plugin_gui_linux.c	2007-06-14 01:24:39 UTC (rev 2918)
+++ liboggplay/trunk/plugin/plugin_gui_linux.c	2007-06-14 01:25:58 UTC (rev 2919)
@@ -88,20 +88,42 @@
                   get_audio_channels(info->ogg_handle));
   
   if (err) {
-  	printf("Error creating audio device\n");
   	info->audio_opened = FALSE;
     return;
   } 
 
   err = sa_device_open(info->audio_handle);
   if (err) {
-  	printf("Error opening audio device\n");
   	info->audio_opened = FALSE;
     return;
   } 
   return;
 }
 
+int maybe_switch_oggplays(PluginWindowInfo *info) {
+
+  void * old_ogg_handle;
+  
+  if (info->new_oggplay_handle != NULL) {
+    
+    SEM_WAIT(info->oggplay_replace_sem);
+    old_ogg_handle = info->ogg_handle;
+    info->ogg_handle = (void *)info->new_oggplay_handle;
+    info->new_oggplay_handle = NULL;
+    SEM_SIGNAL(info->oggplay_replace_sem); 
+    shut_oggplay(old_ogg_handle);
+#ifdef USE_AUDIO  
+    if (info->audio_opened == TRUE)
+      sa_device_close(info->audio_handle);
+    info->audio_opened = FALSE;
+    info->tried_audio = FALSE;
+#endif
+    return TRUE;
+  }
+  
+  return FALSE;
+}
+
 #define OGGPLAY_FRAME_SKIP_OFFSET -30
 #define OGGPLAY_MIN_OFFSET        2
 
@@ -120,7 +142,7 @@
   frame_data.samples = NULL;
   frame_data.cmml_strings = NULL;
   frame_data.size = 0;
-  
+
   // check if we should pause display
   if (info->playback_state == PAUSED) {
     return TRUE;
@@ -137,6 +159,7 @@
     imlib_render_image_on_drawable_at_size(0, 0, info->width, info->height);
     imlib_free_image_and_decache();
   } else if (frame_data.samples == NULL) {
+    maybe_switch_oggplays(info);
     return TRUE;
   }
 
@@ -169,13 +192,11 @@
       sa_device_write(info->audio_handle, frame_data.size, frame_data.samples) > 0
     ) 
     {
-	    printf("Error writing audio samples\n");
   	  cur_time = oggplay_sys_time_in_ms();		
 	  } 
         /* get audio playback progress */ 
   	else if (sa_device_get_position(info->audio_handle, 
                             SA_PCM_WRITE_SOFTWARE_POS, &bytes) > 0) {
-  	  printf("Error reading the playback position\n");
 	    cur_time = oggplay_sys_time_in_ms();
   	} else {
     	cur_time = (bytes * 1000 / get_audio_rate(info->ogg_handle) / 
@@ -202,26 +223,12 @@
   } else if (offset < OGGPLAY_MIN_OFFSET) {
     offset = OGGPLAY_MIN_OFFSET;
   }
-  
-  if (info->new_oggplay_handle != NULL) {
-    void * old_ogg_handle;
-    
-    SEM_WAIT(info->oggplay_replace_sem);
-    old_ogg_handle = info->ogg_handle;
-    info->ogg_handle = (void *)info->new_oggplay_handle;
-    info->new_oggplay_handle = NULL;
-    SEM_SIGNAL(info->oggplay_replace_sem); 
-    shut_oggplay(old_ogg_handle);
-#ifdef USE_AUDIO  
-    if (info->audio_opened == TRUE)
-      sa_device_close(info->audio_handle);
-    info->audio_opened = FALSE;
-    info->tried_audio = FALSE;
-#endif
-    offset = get_callback_period(info->ogg_handle) >> 16;
+ 
+  if(maybe_switch_oggplays(info)) {
+    offset = 10;
   }
-  
-  info->timeout_id = g_timeout_add(offset, update_frame, (gpointer)info);
+
+  info->timeout_id = g_timeout_add((int)offset, update_frame, (gpointer)info);
   return FALSE;
 }
 
@@ -240,7 +247,6 @@
 gboolean
 display_signal (gpointer _info) {
   PluginWindowInfo  * info = (PluginWindowInfo *)_info;
-  printf("display thread: signaling startup\n");
   SEM_SIGNAL(info->start_stop_sem);
   return FALSE;
 }
@@ -250,8 +256,6 @@
 
   PluginWindowInfo  * info = (PluginWindowInfo *)_info;
 
-  printf("display thread: started\n");
-
   /*
    * construct a new toplevel window to draw into.  Make sure window is
    * realised so that it has an underlying XWindow attached to it.
@@ -275,18 +279,14 @@
   //SEM_SIGNAL(info->start_stop_sem);
   gtk_init_add (display_signal, info);
 
-  printf("display thread: entering gtk main\n");
-
   gtk_main();
 
-  printf("display thread: exited gtk main\n");
 #ifdef USE_AUDIO  
   if (info->audio_opened == TRUE)
     sa_device_close(info->audio_handle);
   info->audio_handle = NULL;
   info->audio_opened = FALSE;
 #endif
-  printf("display thread: signalling safe shutdown\n");
   info->shutdown_gui = 0;
 
   pthread_exit(NULL);
@@ -332,9 +332,7 @@
   /*
    * wait for the thread to start up
    */
-  printf("waiting for display thread startup\n");
   SEM_WAIT(info->start_stop_sem);
-  printf("waited for display thread startup\n");
 
   return info;
 
@@ -356,8 +354,7 @@
   SEM_WAIT(info->oggplay_replace_sem);
   if (info->new_oggplay_handle != NULL)
   {
-    printf("early shutting aborted oggplay at %p\n", info->new_oggplay_handle);
-    //shut_oggplay(info->new_oggplay_handle);
+    shut_oggplay(info->new_oggplay_handle);
   }
   info->new_oggplay_handle = oggplay_handle;
   SEM_SIGNAL(info->oggplay_replace_sem); 
@@ -401,7 +398,6 @@
   PluginWindowInfo  * info = (PluginWindowInfo *)handle;
   gboolean      result;
 
-  printf("signalling shutdown of gui\n");
   info->shutdown_gui = 1;
 
   g_signal_emit_by_name(info->window, "destroy-event", NULL, &result);
@@ -409,20 +405,13 @@
   while (info->shutdown_gui) {
     oggplay_millisleep(10);
   }
-  printf("recieved gui shutdown response\n");
 
   shut_oggplay(info->ogg_handle);
- 
-  printf("closed oggplay\n");
 
   SEM_CLOSE(info->start_stop_sem);
   SEM_CLOSE(info->oggplay_replace_sem);
 
-  printf("closed semaphores\n");
-
   free(info);
-  
-  printf("freed info\n");
 
 }
 



More information about the commits mailing list