Bug 466699 - libsydneyaudio fixes for avsync - rs=roc
authorChris Double <chris.double@double.co.nz>
Mon, 18 May 2009 13:33:21 +1200
changeset 28483 8cae9be96140390727d4e69d92b2cb76f2f21255
parent 28482 4f3bf2efcfeb1fd3fbe1620f40eaf7a2635b1361
child 28484 f210fcece4f3d5535a47c3c0d5a7b727a0c64d4c
push idunknown
push userunknown
push dateunknown
reviewersroc
bugs466699
milestone1.9.2a1pre
Bug 466699 - libsydneyaudio fixes for avsync - rs=roc
media/libsydneyaudio/README_MOZILLA
media/libsydneyaudio/pause-resume.patch
media/libsydneyaudio/src/sydney_audio_alsa.c
media/libsydneyaudio/src/sydney_audio_mac.c
media/libsydneyaudio/update.sh
--- a/media/libsydneyaudio/README_MOZILLA
+++ b/media/libsydneyaudio/README_MOZILLA
@@ -1,8 +1,11 @@
 The source from this directory was copied from the libsydneyaudio svn
 source using the update.sh script. The only changes made were those
 applied by update.sh and the addition/upate of Makefile.in files for
 the Mozilla build system.
 
 http://svn.annodex.net/libsydneyaudio/trunk
 
 The svn revision number used was r3895.
+
+pause-resume.patch is applied to implement and fix issues
+with pausing and resuming audio streams.
new file mode 100644
--- /dev/null
+++ b/media/libsydneyaudio/pause-resume.patch
@@ -0,0 +1,69 @@
+diff --git a/media/libsydneyaudio/src/sydney_audio_alsa.c b/media/libsydneyaudio/src/sydney_audio_alsa.c
+index a57f640..5c2f113 100644
+--- a/media/libsydneyaudio/src/sydney_audio_alsa.c
++++ b/media/libsydneyaudio/src/sydney_audio_alsa.c
+@@ -307,9 +307,9 @@ sa_stream_pause(sa_stream_t *s) {
+   if (s == NULL || s->output_unit == NULL) {
+     return SA_ERROR_NO_INIT;
+   }
+-#if 0 /* TODO */
+-  AudioOutputUnitStop(s->output_unit);
+-#endif
++
++  if (snd_pcm_pause(s->output_unit, 1) != 0)
++    return SA_ERROR_NOT_SUPPORTED;
+ 
+   return SA_SUCCESS;
+ }
+@@ -322,12 +322,8 @@ sa_stream_resume(sa_stream_t *s) {
+     return SA_ERROR_NO_INIT;
+   }
+ 
+-  /*
+-   * The audio device resets its mSampleTime counter after pausing,
+-   * so we need to clear our tracking value to keep that in sync.
+-   */
+-  s->bytes_played = s->bytes_written = 0;
+-
++  if (snd_pcm_pause(s->output_unit, 0) != 0)
++    return SA_ERROR_NOT_SUPPORTED;
+   return SA_SUCCESS;
+ }
+ 
+diff --git a/media/libsydneyaudio/src/sydney_audio_mac.c b/media/libsydneyaudio/src/sydney_audio_mac.c
+index 8a7621c..d0fa148 100644
+--- a/media/libsydneyaudio/src/sydney_audio_mac.c
++++ b/media/libsydneyaudio/src/sydney_audio_mac.c
+@@ -70,6 +70,7 @@ struct sa_stream {
+   pthread_mutex_t   mutex;
+   bool              playing;
+   int64_t           bytes_played;
++  int64_t           total_bytes_played;
+ 
+   /* audio format info */
+   unsigned int      rate;
+@@ -153,6 +154,7 @@ sa_stream_create_pcm(
+   s->output_unit  = NULL;
+   s->playing      = FALSE;
+   s->bytes_played = 0;
++  s->total_bytes_played = 0;
+   s->rate         = rate;
+   s->n_channels   = n_channels;
+   s->bytes_per_ch = 2;
+@@ -536,7 +538,7 @@ sa_stream_get_position(sa_stream_t *s, sa_position_t position, int64_t *pos) {
+   }
+ 
+   pthread_mutex_lock(&s->mutex);
+-  *pos = s->bytes_played;
++  *pos = s->total_bytes_played + s->bytes_played;
+   pthread_mutex_unlock(&s->mutex);
+   return SA_SUCCESS;
+ }
+@@ -573,6 +575,7 @@ sa_stream_resume(sa_stream_t *s) {
+    * The audio device resets its mSampleTime counter after pausing,
+    * so we need to clear our tracking value to keep that in sync.
+    */
++  s->total_bytes_played += s->bytes_played;
+   s->bytes_played = 0;
+   pthread_mutex_unlock(&s->mutex);
+ 
--- a/media/libsydneyaudio/src/sydney_audio_alsa.c
+++ b/media/libsydneyaudio/src/sydney_audio_alsa.c
@@ -302,37 +302,33 @@ sa_stream_get_position(sa_stream_t *s, s
 
 
 int
 sa_stream_pause(sa_stream_t *s) {
 
   if (s == NULL || s->output_unit == NULL) {
     return SA_ERROR_NO_INIT;
   }
-#if 0 /* TODO */
-  AudioOutputUnitStop(s->output_unit);
-#endif
+
+  if (snd_pcm_pause(s->output_unit, 1) != 0)
+    return SA_ERROR_NOT_SUPPORTED;
 
   return SA_SUCCESS;
 }
 
 
 int
 sa_stream_resume(sa_stream_t *s) {
 
   if (s == NULL || s->output_unit == NULL) {
     return SA_ERROR_NO_INIT;
   }
 
-  /*
-   * The audio device resets its mSampleTime counter after pausing,
-   * so we need to clear our tracking value to keep that in sync.
-   */
-  s->bytes_played = s->bytes_written = 0;
-
+  if (snd_pcm_pause(s->output_unit, 0) != 0)
+    return SA_ERROR_NOT_SUPPORTED;
   return SA_SUCCESS;
 }
 
 
 int
 sa_stream_drain(sa_stream_t *s)
 {
   if (s == NULL || s->output_unit == NULL) {
--- a/media/libsydneyaudio/src/sydney_audio_mac.c
+++ b/media/libsydneyaudio/src/sydney_audio_mac.c
@@ -65,16 +65,17 @@ struct sa_buf {
   unsigned char     data[0];
 };
 
 struct sa_stream {
   AudioUnit         output_unit;
   pthread_mutex_t   mutex;
   bool              playing;
   int64_t           bytes_played;
+  int64_t           total_bytes_played;
 
   /* audio format info */
   unsigned int      rate;
   unsigned int      n_channels;
   unsigned int      bytes_per_ch;
 
   /* buffer list */
   sa_buf          * bl_head;
@@ -148,16 +149,17 @@ sa_stream_create_pcm(
     free(s->bl_head);
     free(s);
     return SA_ERROR_SYSTEM;
   }
 
   s->output_unit  = NULL;
   s->playing      = FALSE;
   s->bytes_played = 0;
+  s->total_bytes_played = 0;
   s->rate         = rate;
   s->n_channels   = n_channels;
   s->bytes_per_ch = 2;
   s->bl_tail      = s->bl_head;
   s->n_bufs       = 1;
 
   *_s = s;
   return SA_SUCCESS;
@@ -531,17 +533,17 @@ sa_stream_get_position(sa_stream_t *s, s
   if (s == NULL || s->output_unit == NULL) {
     return SA_ERROR_NO_INIT;
   }
   if (position != SA_POSITION_WRITE_SOFTWARE) {
     return SA_ERROR_NOT_SUPPORTED;
   }
 
   pthread_mutex_lock(&s->mutex);
-  *pos = s->bytes_played;
+  *pos = s->total_bytes_played + s->bytes_played;
   pthread_mutex_unlock(&s->mutex);
   return SA_SUCCESS;
 }
 
 
 int
 sa_stream_pause(sa_stream_t *s) {
 
@@ -568,16 +570,17 @@ sa_stream_resume(sa_stream_t *s) {
     return SA_ERROR_NO_INIT;
   }
 
   pthread_mutex_lock(&s->mutex);
   /*
    * The audio device resets its mSampleTime counter after pausing,
    * so we need to clear our tracking value to keep that in sync.
    */
+  s->total_bytes_played += s->bytes_played;
   s->bytes_played = 0;
   pthread_mutex_unlock(&s->mutex);
 
   /*
    * Don't hold the mutex when starting the audio device, because it is
    * possible to deadlock with this thread holding mutex then waiting on an
    * internal Core Audio lock, and with the callback thread holding the Core
    * Audio lock and waiting on the mutex.
--- a/media/libsydneyaudio/update.sh
+++ b/media/libsydneyaudio/update.sh
@@ -1,7 +1,8 @@
 # Usage: ./update.sh <oggplay_src_directory>
 #
 # Copies the needed files from a directory containing the original
 # liboggplay source that we need for the Mozilla HTML5 media support.
 cp $1/include/sydney_audio.h include/sydney_audio.h
 cp $1/src/*.c src/
 cp $1/AUTHORS ./AUTHORS
+patch -p4 <pause-resume.patch