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

tahn at svn.annodex.net tahn at svn.annodex.net
Sat Jun 16 01:05:55 PDT 2007


Author: tahn
Date: 2007-06-16 01:05:55 -0700 (Sat, 16 Jun 2007)
New Revision: 2950

Modified:
   liboggplay/trunk/plugin/plugin_gui_mac.c
Log:
Use the video rate, audio rate and audio channels from the media source instead of hard-wired values.


Modified: liboggplay/trunk/plugin/plugin_gui_mac.c
===================================================================
--- liboggplay/trunk/plugin/plugin_gui_mac.c	2007-06-16 07:43:58 UTC (rev 2949)
+++ liboggplay/trunk/plugin/plugin_gui_mac.c	2007-06-16 08:05:55 UTC (rev 2950)
@@ -98,14 +98,7 @@
 #define USE_AGL_DOUBLE_BUFFER
 #endif
 
-#define VIDEO_RATE            25
-#define AUDIO_MODE            SA_MODE_WRONLY
-#define AUDIO_FORMAT          SA_PCM_FORMAT_S16_LE
-#define AUDIO_RATE            44100
-#define AUDIO_CHANNELS        2
-#define AUDIO_BYTES_PER_CH    sizeof(short)
 
-
 /*
  * -----------------------------------------------------------------------------
  * Display thread functions
@@ -321,8 +314,11 @@
 static void
 init_audio(PluginWindowInfo *info, ThreadData *td) {
 
-  if (sa_stream_create_pcm(&td->audio_handle, NULL, AUDIO_MODE,
-          AUDIO_FORMAT, AUDIO_RATE, AUDIO_CHANNELS) != SA_SUCCESS) {
+  if (sa_stream_create_pcm(&td->audio_handle, NULL,
+        SA_MODE_WRONLY, SA_PCM_FORMAT_S16_LE,
+        get_audio_rate(info->oggplay_handle),
+        get_audio_channels(info->oggplay_handle)) != SA_SUCCESS
+  ) {
     td->audio_handle = NULL;
     return;
   }
@@ -362,10 +358,10 @@
 
   /*
    * Create our AGL drawing context, initialise the GL state, and
-   * open the audio output device.
+   * clear the audio output device (it'll get opened later).
    */
   init_agl_and_gl(info, &td);
-  init_audio(info, &td);
+  td.audio_handle = NULL;
 
   while (!info->shutdown_gui) {
 
@@ -394,7 +390,6 @@
       info->oggplay_handle     = info->new_oggplay_handle;
       info->new_oggplay_handle = NULL;
       shutdown_audio(info, &td);
-      init_audio(info, &td);
       playback_target = 0;
       if (paused) {
         SEM_WAIT(info->playback_sem);
@@ -465,6 +460,11 @@
       if (paused) {
         paused = FALSE;
         sa_stream_resume(td.audio_handle);
+
+        /*
+         * The audio device restarts its byte counter when we resume, so
+         * we need to restart our time tracking as well.
+         */
         playback_target = 0;
       }
       SEM_SIGNAL(info->playback_sem);
@@ -474,10 +474,13 @@
     }
 
     /*
-     * If the media source doesn't contain any audio, we shouldn't keep
-     * the audio output unit open.
+     * Start up the audio output unit as soon as we have some data to play
+     * with. If the media source stops supplying audio, we shouldn't keep
+     * the audio unit open.
      */
-    if (!have_audio && td.audio_handle != NULL) {
+    if (have_audio && td.audio_handle == NULL) {
+      init_audio(info, &td);
+    } else if (!have_audio && td.audio_handle != NULL) {
       shutdown_audio(info, &td);
       playback_target = 0;
     }
@@ -493,7 +496,8 @@
         &&
         sa_stream_get_position(td.audio_handle, SA_POSITION_WRITE_SOFTWARE, &bytes) == SA_SUCCESS
       ) {
-        cur_time = bytes * 1000 / (AUDIO_RATE * AUDIO_BYTES_PER_CH * AUDIO_CHANNELS);
+        cur_time = bytes * 1000 / get_audio_rate(info->oggplay_handle) /
+                    (sizeof(short) * get_audio_channels(info->oggplay_handle));
       } else {
         /*
          * Something's gone wrong with the audio; revert to using the system
@@ -524,7 +528,7 @@
      * If offset ends up negative, we've already missed the deadline for
      * displaying the next frame, so we'll just drop it.
      */
-    playback_target += 1000 / VIDEO_RATE;
+    playback_target += get_callback_period(info->oggplay_handle) >> 16;
     offset = playback_target - cur_time;
     drop_video_frame = (offset < 0);
 #ifdef TIMING_TRACE



More information about the commits mailing list