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

laser13 at svn.annodex.net laser13 at svn.annodex.net
Wed Jun 27 02:39:18 PDT 2007


Author: laser13
Date: 2007-06-27 02:39:18 -0700 (Wed, 27 Jun 2007)
New Revision: 3093

Modified:
   liboggplay/trunk/plugin/audio/sydney_audio_waveapi.c
   liboggplay/trunk/plugin/plugin_gui_win32.c
Log:
Reasonably stable Win32 plugin. Some Javascript stuff still missing.

Modified: liboggplay/trunk/plugin/audio/sydney_audio_waveapi.c
===================================================================
--- liboggplay/trunk/plugin/audio/sydney_audio_waveapi.c	2007-06-27 09:36:45 UTC (rev 3092)
+++ liboggplay/trunk/plugin/audio/sydney_audio_waveapi.c	2007-06-27 09:39:18 UTC (rev 3093)
@@ -45,11 +45,11 @@
 // FIX ME: block size and block should be determined based on the OggPlay offset 
 // for audio track
 #define BLOCK_SIZE  2560
-#define BLOCK_COUNT 4
+#define BLOCK_COUNT 32
 #define DEFAULT_DEVICE_NAME "Default WAVE Device"
 #define DEFAULT_DEVICE WAVE_MAPPER
 
-#define VERBOSE_OUTPUT 1
+#define VERBOSE_OUTPUT 0
 
 // INFO: if you get weird compile errors make sure there is no extra chars pass '\' 
 #if defined(VERBOSE_OUTPUT)
@@ -239,7 +239,7 @@
   mm.wType = TIME_BYTES;		
 	status = waveOutGetPosition(s->hWaveOut, &mm, sizeof(MMTIME));
   HANDLE_WAVE_ERROR(status, "reading audio buffer position");  
-  *pos = (int64_t)mm.u.cb;  
+  *pos = (int64_t)mm.u.cb;    
 
 	return SA_SUCCESS;
 }
@@ -350,10 +350,10 @@
   wfx.nBlockAlign		= (wfx.wBitsPerSample * wfx.nChannels) >> 3;
   wfx.nAvgBytesPerSec	= wfx.nBlockAlign * wfx.nSamplesPerSec;
 
-  supported = waveOutOpen(NULL, WAVE_MAPPER, &wfx, (DWORD_PTR)0, (DWORD_PTR)0, 
+  supported = waveOutOpen(NULL, s->device, &wfx, (DWORD_PTR)0, (DWORD_PTR)0, 
 				WAVE_FORMAT_QUERY);
   if (supported == MMSYSERR_NOERROR) { // audio device opened sucessfully 
-    status = waveOutOpen((LPHWAVEOUT)&(s->hWaveOut), WAVE_MAPPER, &wfx, 
+    status = waveOutOpen((LPHWAVEOUT)&(s->hWaveOut), s->device, &wfx, 
 	  (DWORD_PTR)waveOutProc, (DWORD_PTR)s, CALLBACK_FUNCTION);
     HANDLE_WAVE_ERROR(status, "opening audio device for playback");
 		printf("Audio device sucessfully opened\n");
@@ -445,9 +445,7 @@
 	  current->dwBufferLength = BLOCK_SIZE;
 	  /* write to audio device */
     waveOutPrepareHeader(s->hWaveOut, current, sizeof(WAVEHDR));
-    printf("Before writing to audio dev\n");
 	  status = waveOutWrite(s->hWaveOut, current, sizeof(WAVEHDR));      
-    printf("After writing to audio dev\n");
     HANDLE_WAVE_ERROR(status, "writing audio to audio device");
       
     EnterCriticalSection(&(s->waveCriticalSection));

Modified: liboggplay/trunk/plugin/plugin_gui_win32.c
===================================================================
--- liboggplay/trunk/plugin/plugin_gui_win32.c	2007-06-27 09:36:45 UTC (rev 3092)
+++ liboggplay/trunk/plugin/plugin_gui_win32.c	2007-06-27 09:39:18 UTC (rev 3093)
@@ -47,7 +47,7 @@
 #include <oggplay/oggplay_tools.h>
 
 #define OGGPLAY_FRAME_SKIP_OFFSET -30
-#define OGGPLAY_MIN_OFFSET        2
+#define OGGPLAY_MIN_OFFSET        10
 
 typedef struct {
   // window related data
@@ -70,34 +70,11 @@
 #ifdef USE_AUDIO
   sa_stream_t     *   audio_handle;
   BOOL                audio_ok;  
-#endif  
   BOOL        	      audio_opened;  
+#endif    
   nsPluginInstance *  plugin_instance;
 } PluginWindowInfo;
 
-
-static BOOL 
-switch_oggplays(PluginWindowInfo *info) {
-
-  BOOL rv = FALSE;
-  void * old_ogg_handle;
-    
-  if (info->new_oggplay_handle != NULL) { 
-    SEM_WAIT(info->oggplay_replace_sem);
-    if (info->new_oggplay_handle != NULL) {
-      printf("Switch oggplay before!!!\n");      
-      old_ogg_handle = info->oggplay_handle;
-      info->oggplay_handle = (void *)info->new_oggplay_handle;
-      info->new_oggplay_handle = NULL;      
-      printf("Switch oggplay after!!!\n");
-      shut_oggplay(old_ogg_handle);      
-      rv = TRUE;
-    }
-    SEM_SIGNAL(info->oggplay_replace_sem); 
-  }  
-  return rv;
-}
-
 #ifdef USE_AUDIO
 static void
 open_audio(PluginWindowInfo *info) {
@@ -119,7 +96,9 @@
     info->audio_handle = NULL;    
     return;
   }
-  printf("Audio device opened\n");
+  printf("Audio device opened at rate [%d] Hz and with [%d] audio channels\n", 
+    get_audio_rate(info->oggplay_handle),
+    get_audio_channels(info->oggplay_handle));
   return;
 }
 
@@ -130,11 +109,37 @@
     info->audio_handle = NULL;
     info->audio_opened = FALSE;
     info->playback_target = 0;
-    printf("Closed audio device\n");
+    printf("Audio device closed\n");
   }
 }
 #endif
 
+
+static BOOL 
+switch_oggplays(PluginWindowInfo *info) {
+
+  BOOL rv = FALSE;
+  void * old_ogg_handle;
+    
+  if (info->new_oggplay_handle != NULL) {     
+    SEM_WAIT(info->oggplay_replace_sem);    
+    if (info->new_oggplay_handle != NULL) {      
+      old_ogg_handle = info->oggplay_handle;
+      info->oggplay_handle = (void *)info->new_oggplay_handle;
+      info->new_oggplay_handle = NULL;      
+#ifdef USE_AUDIO
+      if (info->audio_opened == TRUE) {        
+        close_audio(info);              
+      }      
+#endif
+      rv = TRUE;
+    }     
+    SEM_SIGNAL(info->oggplay_replace_sem);    
+    shut_oggplay(old_ogg_handle);        
+  }  
+  return rv;
+}
+
 /**
  * \brief display_thread - main loop do the tread responsible for display 
  * \param [in] _info - PluginWindowInfo stucture 
@@ -143,23 +148,23 @@
   HWND                hWnd;  
   RECT                r;    
   __int64             ref_time;
-  DWORD               offset;
+  __int64             offset;
 #ifdef USE_AUDIO      
   __int64             bytes;
-#endif
+#endif  
   PluginWindowInfo *  info = (PluginWindowInfo*)_info;    
   
   /* initialise variables */  
   info->playback_target = 0;
   ref_time = 0;
-  info->shutdown_gui = 0;
+  info->shutdown_gui = 0;  
   hWnd = (HWND)(info->window);
-
+  
   /* 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      
@@ -175,25 +180,23 @@
     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
     * in the GUI message processing callback.
     */    
-    // force refresh    
-    GetClientRect(hWnd, &r);      
-    InvalidateRect(hWnd, &r, FALSE);     
-    UpdateWindow(hWnd);    
+    // force refresh 
+    GetClientRect(hWnd, &r);    
+    InvalidateRect(hWnd, &r, FALSE);         
+    UpdateWindow(hWnd);  
     SEM_WAIT(info->synch_sem);       
-
+#ifdef USE_AUDIO      
+    if (info->audio_opened == FALSE)     
+#endif
+    {      
+      info->playback_target = oggplay_sys_time_in_ms() << 16;
+    }      
 #ifdef USE_AUDIO
     if ((info->audio_opened == TRUE) && (info->audio_ok == TRUE)) {
       // calculate audio playback progress based on number of audio samples played    
@@ -202,8 +205,7 @@
         ref_time = oggplay_sys_time_in_ms();
       } 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);
+                        (sizeof(short) * get_audio_channels(info->oggplay_handle)));        
       }
     } else 
 #endif
@@ -211,30 +213,41 @@
       ref_time = oggplay_sys_time_in_ms();      
     }
     
-    // calculate how long we should wait with processing the next frame
+    /* calculate how long we should wait with processing the next frame */
     info->playback_target += get_callback_period(info->oggplay_handle);
-    offset = (DWORD)((info->playback_target >> 16) - ref_time);    
-    //printf("Offset %ld : \n", offset);
+    offset = (info->playback_target >> 16) - ref_time;    
+    /*printf("Playback target [%lld], reference time [%lld] and offset [%lld] : \n", 
+      (info->playback_target >> 16), ref_time, offset);*/
     offset = (offset > 0) ? offset : OGGPLAY_MIN_OFFSET;
    
     /* try switching oggplays */
     if (switch_oggplays(info) == TRUE) {
       offset = 10;
     }
-    
-    // Now just wait...    
-    oggplay_millisleep(40);   
-    
+    /* Now just wait... */
+    oggplay_millisleep(offset);   
   }
   
+  //clean up after receiving shut gui request
+
   if (info->shutdown_gui) {
     info->shutdown_gui = 0;
-#ifdef USE_AUDIO      
+#ifdef USE_AUDIO          
     if (info->audio_opened == TRUE) {
       close_audio(info);
     }
-#endif
-    //oggplay_millisleep(10);
+#endif        
+    
+    SubclassWindow((HWND)(info->window), (WNDPROC)(info->old_wnd_proc));    
+    
+    SEM_CLOSE(info->synch_sem);    
+    SEM_CLOSE(info->start_stop_sem);  
+    SEM_CLOSE(info->oggplay_replace_sem);  
+    SEM_CLOSE(info->playback_sem); 
+    shut_oggplay(info->oggplay_handle);  
+
+    free(info);
+
     ExitThread(0);  
   }
      
@@ -246,7 +259,7 @@
  * \param [in] parent - 
  * \param [in] width - window_width
  * \param [in] height - window_height
- * Comments: Fuction notifies the display
+ * Comments: Fuction initialised the display thread
  * */
 void *
 initialise_gui(nsPluginInstance *instance, NPWindow *np_window, 
@@ -272,10 +285,10 @@
   info->playback_state = PLAYING;
   /* initialisation of callback related variables */
   info->plugin_instance = instance;
-  /* audio and synchronisation related variables */
-  info->audio_opened = FALSE;    
+  /* audio and synchronisation related variables */  
   info->playback_target = 0;  
 #ifdef USE_AUDIO  
+  info->audio_opened = FALSE;    
   info->audio_handle = NULL;
   info->audio_ok = FALSE;
 #endif
@@ -324,35 +337,15 @@
  * */
 void
 shut_gui(void *handle) {
-
-  PluginWindowInfo  * info = (PluginWindowInfo *)handle;
-    
-  // subclass it back
-  SubclassWindow((HWND)(info->window), (WNDPROC)(info->old_wnd_proc));    
-
+  
+  PluginWindowInfo  * info = (PluginWindowInfo *)handle;    
   info->shutdown_gui = 1;  
   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) {         
-    oggplay_millisleep(1);
-  }  
-  
-  shut_oggplay(info->oggplay_handle);  
+  return;
 
-  SEM_CLOSE(info->start_stop_sem);  
-  SEM_CLOSE(info->oggplay_replace_sem);  
-  SEM_CLOSE(info->playback_sem);  
-
-  if (info->frame_data != NULL) {
-    free(info->frame_data);  
-  }  
-  free(info);
-  
-  return;
 }
 
 /*
@@ -440,15 +433,15 @@
   BOOL          has_video = FALSE;
   BOOL          has_cmml = FALSE;
     
-  // filter early and random *broken* WM_PAINT messages  
+  // filter early and random *broken* WM_PAINT messages    
   if (info == NULL) {        
     SEM_SIGNAL(info->synch_sem);
     return;  
-  }  
-
-  get_oggplay_frame(info->oggplay_handle, info->frame_data);    
-  convert_oggplay_frame(info->oggplay_handle, info->frame_data, BGR);
-
+  }    
+  get_oggplay_frame(info->oggplay_handle, info->frame_data);      
+  // this has to be split 
+  convert_oggplay_frame(info->oggplay_handle, info->frame_data, BGR);  
+  
   has_video = ((info->frame_data->video_data != NULL) && (info->frame_data->frame != NULL)) ? TRUE : FALSE;
   has_audio = ((info->frame_data->samples != NULL) && (info->frame_data->size > 0)) ? TRUE : FALSE;
   has_cmml = ((info->frame_data->cmml_strings != NULL) && (info->frame_data->cmml_size > 0)) ? TRUE : FALSE;
@@ -461,8 +454,8 @@
     //return;
     goto cleanup;    
   }
-  /* display frame */
-  update_frame(info);  
+  /* display frame */  
+  update_frame(info);    
 
 #ifdef USE_AUDIO
   if (has_audio == TRUE) {    
@@ -472,18 +465,16 @@
     }
     /* 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);
+      info->audio_ok = TRUE;      
+      if (info->frame_data->samples != NULL) {        
       }
       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");
+        close_audio(info);
+        info->playback_target = 0;
+        info->audio_ok = FALSE;        
+      }      
     }
   }  
 #endif
@@ -491,11 +482,11 @@
   /* 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);  
   // progress with decoding  
-  free_oggplay_frame(info->oggplay_handle, info->frame_data);    
+  free_oggplay_frame(info->oggplay_handle, info->frame_data);     
   return;
 }
 
@@ -505,12 +496,12 @@
 // =================================
 LRESULT CALLBACK PluginWinProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam)
 {    
-  PluginWindowInfo * info = NULL;
+  PluginWindowInfo * info = NULL;  
   switch (msg) {
-    case WM_PAINT:      
+    case WM_PAINT: 
       info = (PluginWindowInfo*)GetWindowLongPtr(hWnd, GWL_USERDATA);      
-      process_frame_data(info);
-      break;
+      process_frame_data(info);      
+      break;    
     case WM_CLOSE :      
       break;
     case WM_DESTROY : 
@@ -530,15 +521,12 @@
 {
   
   PluginWindowInfo  * info = (PluginWindowInfo *)handle;
-  printf("update_gui_with_new_oggplay starts\n");
   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);
   }
   info->new_oggplay_handle = oggplay_handle;
-  printf("update_gui_with_new_oggplay new handle passed\n");
   SEM_SIGNAL(info->oggplay_replace_sem); 
   
 }
@@ -591,13 +579,25 @@
 
 long
 gui_get_window_width(void *handle) {
-//!todo
-  return 0;
+  
+  long width = 0;
+  PluginWindowInfo * info = (PluginWindowInfo *)handle;
+  
+  if (info != NULL) {
+    width = info->width;
+  }
+  return width;
 }
 
 long
 gui_get_window_height(void *handle) {
-//!todo
-  return 0;
+
+  long height = 0;
+  PluginWindowInfo * info = (PluginWindowInfo *)handle;
+  
+  if (info != NULL) {
+    height = info->height;
+  }
+  return height;
 }
 



More information about the commits mailing list