[xiph-commits] r3070 - in liboggplay/trunk/plugin: . audio

laser13 at svn.annodex.net laser13 at svn.annodex.net
Tue Jun 26 06:47:50 PDT 2007


Author: laser13
Date: 2007-06-26 06:47:49 -0700 (Tue, 26 Jun 2007)
New Revision: 3070

Modified:
   liboggplay/trunk/plugin/audio/sydney_audio_waveapi.c
   liboggplay/trunk/plugin/plugin_gui_win32.c
Log:
Small Win32 audio fixes.

Modified: liboggplay/trunk/plugin/audio/sydney_audio_waveapi.c
===================================================================
--- liboggplay/trunk/plugin/audio/sydney_audio_waveapi.c	2007-06-26 13:07:13 UTC (rev 3069)
+++ liboggplay/trunk/plugin/audio/sydney_audio_waveapi.c	2007-06-26 13:47:49 UTC (rev 3070)
@@ -232,7 +232,7 @@
 
   ERROR_IF_NO_INIT(s);
 
-  if (position != SA_POSITION_WRITE_HARDWARE) {
+  if (position != SA_POSITION_WRITE_SOFTWARE) {
     return SA_ERROR_NOT_SUPPORTED;
   }
   // request playback progress in bytes
@@ -421,25 +421,31 @@
   UINT status;
   WAVEHDR* current;	  
   int remain;
-
+  //printf("API write audio 1 bytes to write: %d\n", bytes);
   current = &(s->waveBlocks[s->waveCurrentBlock]);
-  
+  //printf("API write audio 2\n");
   while(bytes > 0) {
+    //printf("API write audio 3 bytes to write: %d\n", bytes);
     /* first make sure the header we're going to use is unprepared */
     if(current->dwFlags & WHDR_PREPARED) {      
         status = waveOutUnprepareHeader(s->hWaveOut, current, sizeof(WAVEHDR));         
         HANDLE_WAVE_ERROR(status, "preparing audio headers for writing");
+        //printf("API write audio 3.1\n");
     }
-		  
+		
     if(bytes < (int)(BLOCK_SIZE - current->dwUser)) {							  	    
+      //printf("API write audio 3.2\n");
 		  memcpy(current->lpData + current->dwUser, data, bytes);
+      //printf("API write audio 3.3\n");
       current->dwUser += bytes;
       break;
     }
 	
     /* remain is even as BLOCK_SIZE and dwUser are even too */
     remain = BLOCK_SIZE - current->dwUser;      
+    printf("API write audio 3.4 samples pointer <%p>, remains [%d]\n", data, remain);
   	memcpy(current->lpData + current->dwUser, data, remain);
+    printf("API write audio 3.5\n");
     bytes -= remain;
     data += bytes;
 	  current->dwBufferLength = BLOCK_SIZE;
@@ -454,8 +460,8 @@
     /*
      * wait for a block to become free
      */
-    while (!(s->waveFreeBlockCount)) {
-        //printf("All audio buffer blocks empty\n");        
+    if (!(s->waveFreeBlockCount)) {
+      printf("All audio buffer blocks empty\n");        
       WaitForSingleObject(s->callbackEvent, INFINITE);
         //Sleep(10);
     }		  
@@ -469,6 +475,7 @@
     current = &(s->waveBlocks[s->waveCurrentBlock]);
     current->dwUser = 0;
   }
+  printf("API write audio 4 bytes to write: %d\n", bytes);
   return SA_SUCCESS;
 }
 

Modified: liboggplay/trunk/plugin/plugin_gui_win32.c
===================================================================
--- liboggplay/trunk/plugin/plugin_gui_win32.c	2007-06-26 13:07:13 UTC (rev 3069)
+++ liboggplay/trunk/plugin/plugin_gui_win32.c	2007-06-26 13:47:49 UTC (rev 3070)
@@ -65,6 +65,7 @@
   semaphore           playback_sem;
   semaphore           synch_sem;  
   PluginPlaybackState   playback_state;
+  __int64             playback_target;  
   void            *   new_oggplay_handle;
 #ifdef USE_AUDIO
   sa_stream_t     *   audio_handle;
@@ -102,6 +103,7 @@
 open_audio(PluginWindowInfo *info) {
   
   info->audio_opened = TRUE;
+  info->playback_target = 0;
 
   if (sa_stream_create_pcm(&(info->audio_handle), NULL,
         SA_MODE_WRONLY, SA_PCM_FORMAT_S16_NE,
@@ -127,6 +129,7 @@
     sa_stream_destroy(info->audio_handle);
     info->audio_handle = NULL;
     info->audio_opened = FALSE;
+    info->playback_target = 0;
     printf("Closed audio device\n");
   }
 }
@@ -138,8 +141,7 @@
  */
 DWORD WINAPI display_thread(void *_info) {  
   HWND                hWnd;  
-  RECT                r;  
-  __int64             playback_target;  
+  RECT                r;    
   __int64             ref_time;
   DWORD               offset;
 #ifdef USE_AUDIO      
@@ -147,8 +149,8 @@
 #endif
   PluginWindowInfo *  info = (PluginWindowInfo*)_info;    
   
-  /* initialise variables */
-  playback_target = 0;
+  /* initialise variables */  
+  info->playback_target = 0;
   ref_time = 0;
   info->shutdown_gui = 0;
   hWnd = (HWND)(info->window);
@@ -156,7 +158,8 @@
   /* signal that thread has been started sucessfully */
   SEM_SIGNAL(info->start_stop_sem);  
 
-  while (!info->shutdown_gui) {        
+  while (!info->shutdown_gui) {            
+
     // check if we should pause display
     if (info->playback_state == PAUSED) {
 #ifdef USE_AUDIO      
@@ -167,12 +170,19 @@
       SEM_WAIT(info->playback_sem);
 #endif
     }        
-
+    
     // check if plugin hasn't been shut down
     if (info->shutdown_gui) {      
       break;
     }
-     
+    
+#ifdef USE_AUDIO      
+    if (info->audio_opened == FALSE)     
+#endif
+    {      
+      info->playback_target = oggplay_sys_time_in_ms() << 16;
+    }    
+
    /*
     * Do not send WM_PAINT messages while waiting for GUI to shutdown.
     * This is asynchronous call so all calls to plugin_oggplay functions are
@@ -193,16 +203,18 @@
       } else {
         ref_time = (bytes * 1000 / get_audio_rate(info->oggplay_handle) / 
                         (sizeof(short) * get_audio_channels(info->oggplay_handle)));
+        printf("Ref time %ld : \n", ref_time);
       }
     } else 
 #endif
     {
-      ref_time = oggplay_sys_time_in_ms();
+      ref_time = oggplay_sys_time_in_ms();      
     }
     
     // calculate how long we should wait with processing the next frame
-    playback_target += get_callback_period(info->oggplay_handle) >> 16;
-    offset = (DWORD)(playback_target - ref_time);    
+    info->playback_target += get_callback_period(info->oggplay_handle);
+    offset = (DWORD)((info->playback_target >> 16) - ref_time);    
+    //printf("Offset %ld : \n", offset);
     offset = (offset > 0) ? offset : OGGPLAY_MIN_OFFSET;
    
     /* try switching oggplays */
@@ -210,8 +222,8 @@
       offset = 10;
     }
     
-    // Now just wait...
-    Sleep(40);
+    // Now just wait...    
+    oggplay_millisleep(40);   
     
   }
   
@@ -222,6 +234,7 @@
       close_audio(info);
     }
 #endif
+    //oggplay_millisleep(10);
     ExitThread(0);  
   }
      
@@ -250,8 +263,9 @@
   info->oggplay_handle = oggplay_handle;
   info->frame_data = (PluginOggFrame*)malloc(sizeof(PluginOggFrame));
   info->frame_data->frame = NULL;
-  info->frame_data->samples = NULL;
-  info->frame_data->cmml_strings = NULL;
+  info->frame_data->samples = NULL;  
+  info->frame_data->cmml_strings = NULL;  
+  info->frame_data->size = 0;
   info->shutdown_gui = 1;
   info->window = hWnd;
   info->new_oggplay_handle = NULL;
@@ -259,8 +273,9 @@
   /* initialisation of callback related variables */
   info->plugin_instance = instance;
   /* audio and synchronisation related variables */
-  info->audio_opened = FALSE;  
-#ifdef USE_AUDIO
+  info->audio_opened = FALSE;    
+  info->playback_target = 0;  
+#ifdef USE_AUDIO  
   info->audio_handle = NULL;
   info->audio_ok = FALSE;
 #endif
@@ -319,9 +334,11 @@
   if (info->playback_state == PAUSED) {
     SEM_SIGNAL(info->playback_sem);    
   }
+
+  SEM_CLOSE(info->synch_sem);  
   // wait for all threads to finish
   while (info->shutdown_gui) {         
-    Sleep(10);
+    oggplay_millisleep(1);
   }  
   
   shut_oggplay(info->oggplay_handle);  
@@ -456,24 +473,29 @@
     /* if audio device is opened try writing data */
     if (info->audio_opened == TRUE) {
       info->audio_ok = TRUE;
+      //printf("Stream write BEFORE\n");
+      if (info->frame_data->samples != NULL) {
+        printf("Audio data size %d\n", info->frame_data->size);
+      }
       if (sa_stream_write(info->audio_handle, 
             info->frame_data->samples, 
             info->frame_data->size) != SA_SUCCESS) {
         info->audio_ok = FALSE;
+        //printf("Stream write AFTER with FAIL\n");
       }
+      //printf("Stream write AFTER\n");
     }
-  }
+  }  
 #endif
-
+  
   /* call CMML data callback using plugin's main thread call */
   if (has_cmml == TRUE) {    
     onCMMLData(info->plugin_instance, info->frame_data->cmml_strings, info->frame_data->cmml_size);      
-  }
-
+  }  
 cleanup:
-  SEM_SIGNAL(info->synch_sem);
+  SEM_SIGNAL(info->synch_sem);  
   // progress with decoding  
-  free_oggplay_frame(info->oggplay_handle, info->frame_data);  
+  free_oggplay_frame(info->oggplay_handle, info->frame_data);    
   return;
 }
 



More information about the commits mailing list