Bug 939593 - Resync libcubeb with upstream. r=kinetik, a=bajaj
authorPaul Adenot <paul@paul.cx>
Mon, 18 Nov 2013 11:47:24 +1300
changeset 166689 e1144ef584de750602f07e77a2f622de9159fa15
parent 166688 37df29dd2f8f1e6ab099f3fffb9b3d59fb4b6adb
child 166690 5f9dd1d87f5ca8b8a11ee982522a1798e93d5293
push id3066
push userakeybl@mozilla.com
push dateMon, 09 Dec 2013 19:58:46 +0000
treeherdermozilla-beta@a31a0dce83aa [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskinetik, bajaj
bugs939593
milestone27.0a2
Bug 939593 - Resync libcubeb with upstream. r=kinetik, a=bajaj
media/libcubeb/AUTHORS
media/libcubeb/README_MOZILLA
media/libcubeb/src/cubeb.c
media/libcubeb/src/cubeb_audiounit.c
--- a/media/libcubeb/AUTHORS
+++ b/media/libcubeb/AUTHORS
@@ -1,4 +1,6 @@
 Matthew Gregan <kinetik@flim.org>
 Alexandre Ratchov <alex@caoua.org>
 Michael Wu <mwu@mozilla.com>
 Paul Adenot <paul@paul.cx>
+David Richards <drichards@mozilla.com>
+Sebastien Alaiwan <sebastien.alaiwan@gmail.com>
--- a/media/libcubeb/README_MOZILLA
+++ b/media/libcubeb/README_MOZILLA
@@ -1,8 +1,8 @@
 The source from this directory was copied from the cubeb 
 git repository using the update.sh script.  The only changes
 made were those applied by update.sh and the addition of
 Makefile.in build files for the Mozilla build system.
 
 The cubeb git repository is: git://github.com/kinetiknz/cubeb.git
 
-The git commit ID used was 36659a5649fb31c180c39e70ea761e00354c0106.
+The git commit ID used was 93e51e70e978420c745ec22503fa8e121cbb7aa5.
--- a/media/libcubeb/src/cubeb.c
+++ b/media/libcubeb/src/cubeb.c
@@ -19,16 +19,19 @@ struct cubeb {
 
 struct cubeb_stream {
   struct cubeb * context;
 };
 
 #if defined(USE_PULSE)
 int pulse_init(cubeb ** context, char const * context_name);
 #endif
+#if defined(USE_JACK)
+int jack_init (cubeb ** context, char const * context_name);
+#endif
 #if defined(USE_ALSA)
 int alsa_init(cubeb ** context, char const * context_name);
 #endif
 #if defined(USE_AUDIOQUEUE)
 int audioqueue_init(cubeb ** context, char const * context_name);
 #endif
 #if defined(USE_AUDIOUNIT)
 int audiounit_init(cubeb ** context, char const * context_name);
@@ -82,16 +85,19 @@ validate_latency(int latency)
 
 int
 cubeb_init(cubeb ** context, char const * context_name)
 {
   int (* init[])(cubeb **, char const *) = {
 #if defined(USE_PULSE)
     pulse_init,
 #endif
+#if defined(USE_JACK)
+    jack_init,
+#endif
 #if defined(USE_ALSA)
     alsa_init,
 #endif
 #if defined(USE_AUDIOUNIT)
     audiounit_init,
 #endif
 #if defined(USE_AUDIOQUEUE)
     audioqueue_init,
--- a/media/libcubeb/src/cubeb_audiounit.c
+++ b/media/libcubeb/src/cubeb_audiounit.c
@@ -8,17 +8,16 @@
 #include <assert.h>
 #include <pthread.h>
 #include <stdlib.h>
 #include <AudioUnit/AudioUnit.h>
 #include <CoreAudio/AudioHardware.h>
 #include <CoreAudio/HostTime.h>
 #include "cubeb/cubeb.h"
 #include "cubeb-internal.h"
-#include "prtime.h"
 
 #define NBUFS 4
 
 static struct cubeb_ops const audiounit_ops;
 
 struct cubeb {
   struct cubeb_ops const * ops;
 };
@@ -44,17 +43,17 @@ audiotimestamp_to_latency(AudioTimeStamp
 {
   if (!(tstamp->mFlags & kAudioTimeStampHostTimeValid)) {
     return 0;
   }
 
   uint64_t pres = AudioConvertHostTimeToNanos(tstamp->mHostTime);
   uint64_t now = AudioConvertHostTimeToNanos(AudioGetCurrentHostTime());
 
-  return ((pres - now) * stream->sample_spec.mSampleRate) / PR_NSEC_PER_SEC;
+  return ((pres - now) * stream->sample_spec.mSampleRate) / 1000000000LL;
 }
 
 static OSStatus
 audiounit_output_callback(void * user_ptr, AudioUnitRenderActionFlags * flags,
                           AudioTimeStamp const * tstamp, UInt32 bus, UInt32 nframes,
                           AudioBufferList * bufs)
 {
   cubeb_stream * stm;
@@ -294,17 +293,17 @@ audiounit_stream_init(cubeb * context, c
   ComponentDescription desc;
   Component comp;
 #else
   AudioComponentDescription desc;
   AudioComponent comp;
 #endif
   cubeb_stream * stm;
   AURenderCallbackStruct input;
-  unsigned int buffer_size;
+  unsigned int buffer_size, default_buffer_size;
   OSStatus r;
   UInt32 size;
   AudioDeviceID output_device_id;
   AudioValueRange latency_range;
 
 
   assert(context);
   *stream = NULL;
@@ -403,25 +402,40 @@ audiounit_stream_init(cubeb * context, c
   }
 
   if (buffer_size < (unsigned int) latency_range.mMinimum) {
     buffer_size = (unsigned int) latency_range.mMinimum;
   } else if (buffer_size > (unsigned int) latency_range.mMaximum) {
     buffer_size = (unsigned int) latency_range.mMaximum;
   }
 
-  /* Set the maximum number of frame that the render callback will ask for,
-   * effectively setting the latency of the stream. This is process-wide. */
-  r = AudioUnitSetProperty(stm->unit, kAudioDevicePropertyBufferFrameSize,
-                           kAudioUnitScope_Output, 0, &buffer_size, sizeof(buffer_size));
+  /**
+   * Get the default buffer size. If our latency request is below the default,
+   * set it. Otherwise, use the default latency.
+   **/
+  size = sizeof(default_buffer_size);
+  r = AudioUnitGetProperty(stm->unit, kAudioDevicePropertyBufferFrameSize,
+                           kAudioUnitScope_Output, 0, &default_buffer_size, &size);
+
   if (r != 0) {
     audiounit_stream_destroy(stm);
     return CUBEB_ERROR;
   }
 
+  if (buffer_size < default_buffer_size) {
+    /* Set the maximum number of frame that the render callback will ask for,
+     * effectively setting the latency of the stream. This is process-wide. */
+    r = AudioUnitSetProperty(stm->unit, kAudioDevicePropertyBufferFrameSize,
+                             kAudioUnitScope_Output, 0, &buffer_size, sizeof(buffer_size));
+    if (r != 0) {
+      audiounit_stream_destroy(stm);
+      return CUBEB_ERROR;
+    }
+  }
+
   r = AudioUnitSetProperty(stm->unit, kAudioUnitProperty_StreamFormat, kAudioUnitScope_Input,
                            0, &ss, sizeof(ss));
   if (r != 0) {
     audiounit_stream_destroy(stm);
     return CUBEB_ERROR;
   }
 
   r = AudioUnitInitialize(stm->unit);