Bug 1427702 - Update cubeb from upstream to bda37c2. r=kamidphish
authorAlex Chronopoulos <achronop@gmail.com>
Wed, 03 Jan 2018 12:06:11 +0200
changeset 397615 ba12a841ef9370953df6e282983b2dcda502c22e
parent 397614 b1e9b56dbc7dca27144feb718dfda4f493935ea9
child 397616 9de67942469381c88c87f7422b6a7116b9f20a14
push id33181
push useraciure@mozilla.com
push dateWed, 03 Jan 2018 21:39:06 +0000
treeherdermozilla-central@b4142655f44e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskamidphish
bugs1427702
milestone59.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1427702 - Update cubeb from upstream to bda37c2. r=kamidphish MozReview-Commit-ID: H106jbl4sok
media/libcubeb/README_MOZILLA
media/libcubeb/src/cubeb_audiounit.cpp
--- 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 43e15fc92293fc842ecd8a109fbe039c4f3c0c13 (2017-12-28 09:32:11 +1000)
+The git commit ID used was bda37c26b0ed46c568e35b10728fc498262778f3 (2017-12-28 09:34:08 +1000)
--- a/media/libcubeb/src/cubeb_audiounit.cpp
+++ b/media/libcubeb/src/cubeb_audiounit.cpp
@@ -28,16 +28,17 @@
 #include "cubeb_osx_run_loop.h"
 #endif
 #include "cubeb_resampler.h"
 #include "cubeb_ring_array.h"
 #include <algorithm>
 #include <atomic>
 #include <vector>
 #include <sys/time.h>
+#include <string>
 
 #if MAC_OS_X_VERSION_MIN_REQUIRED < 101000
 typedef UInt32 AudioFormatFlags;
 #endif
 
 #define AU_OUT_BUS    0
 #define AU_IN_BUS     1
 
@@ -1676,16 +1677,64 @@ audiounit_activate_clock_drift_compensat
     }
   }
   return CUBEB_OK;
 }
 
 static int audiounit_destroy_aggregate_device(AudioObjectID plugin_id, AudioDeviceID * aggregate_device_id);
 static void audiounit_get_available_samplerate(AudioObjectID devid, AudioObjectPropertyScope scope,
                                    uint32_t * min, uint32_t * max, uint32_t * def);
+static int
+audiounit_create_device_from_hwdev(cubeb_device_info * ret, AudioObjectID devid, cubeb_device_type type);
+
+static void
+audiounit_workaround_for_airpod(cubeb_stream * stm)
+{
+  cubeb_device_info input_device_info;
+  audiounit_create_device_from_hwdev(&input_device_info, stm->input_device.id, CUBEB_DEVICE_TYPE_INPUT);
+
+  cubeb_device_info output_device_info;
+  audiounit_create_device_from_hwdev(&output_device_info, stm->output_device.id, CUBEB_DEVICE_TYPE_OUTPUT);
+
+  std::string input_name_str(input_device_info.friendly_name);
+  std::string output_name_str(output_device_info.friendly_name);
+
+  if( input_name_str.find("AirPods") != std::string::npos
+    && output_name_str.find("AirPods") != std::string::npos ) {
+    uint32_t input_min_rate = 0;
+    uint32_t input_max_rate = 0;
+    uint32_t input_nominal_rate = 0;
+    audiounit_get_available_samplerate(stm->input_device.id, kAudioObjectPropertyScopeGlobal,
+                                       &input_min_rate, &input_max_rate, &input_nominal_rate);
+    LOG("(%p) Input device %u, name: %s, min: %u, max: %u, nominal rate: %u", stm, stm->input_device.id
+    , input_device_info.friendly_name, input_min_rate, input_max_rate, input_nominal_rate);
+    uint32_t output_min_rate = 0;
+    uint32_t output_max_rate = 0;
+    uint32_t output_nominal_rate = 0;
+    audiounit_get_available_samplerate(stm->output_device.id, kAudioObjectPropertyScopeGlobal,
+                                       &output_min_rate, &output_max_rate, &output_nominal_rate);
+    LOG("(%p) Output device %u, name: %s, min: %u, max: %u, nominal rate: %u", stm, stm->output_device.id
+    , output_device_info.friendly_name, output_min_rate, output_max_rate, output_nominal_rate);
+
+    Float64 rate = input_nominal_rate;
+    AudioObjectPropertyAddress addr = {kAudioDevicePropertyNominalSampleRate,
+                                       kAudioObjectPropertyScopeGlobal,
+                                       kAudioObjectPropertyElementMaster};
+
+    OSStatus rv = AudioObjectSetPropertyData(stm->aggregate_device_id,
+                                             &addr,
+                                             0,
+                                             nullptr,
+                                             sizeof(Float64),
+                                             &rate);
+    if (rv != noErr) {
+      LOG("Non fatal error, AudioObjectSetPropertyData/kAudioDevicePropertyNominalSampleRate, rv=%d", rv);
+    }
+  }
+}
 
 /*
  * Aggregate Device is a virtual audio interface which utilizes inputs and outputs
  * of one or more physical audio interfaces. It is possible to use the clock of
  * one of the devices as a master clock for all the combined devices and enable
  * drift compensation for the devices that are not designated clock master.
  *
  * Creating a new aggregate device programmatically requires [0][1]:
@@ -1699,36 +1748,16 @@ static void audiounit_get_available_samp
  *
  * [0] https://lists.apple.com/archives/coreaudio-api/2006/Apr/msg00092.html
  * [1] https://lists.apple.com/archives/coreaudio-api/2005/Jul/msg00150.html
  * [2] CoreAudio.framework/Headers/AudioHardware.h
  * */
 static int
 audiounit_create_aggregate_device(cubeb_stream * stm)
 {
-  uint32_t input_min_rate = 0;
-  uint32_t input_max_rate = 0;
-  uint32_t input_nominal_rate = 0;
-  audiounit_get_available_samplerate(stm->input_device.id, kAudioObjectPropertyScopeGlobal,
-                                     &input_min_rate, &input_max_rate, &input_nominal_rate);
-  LOG("(%p) Input device %u min: %u, max: %u, nominal: %u rate", stm, stm->input_device.id
-      , input_min_rate, input_max_rate, input_nominal_rate);
-  uint32_t output_min_rate = 0;
-  uint32_t output_max_rate = 0;
-  uint32_t output_nominal_rate = 0;
-  audiounit_get_available_samplerate(stm->output_device.id, kAudioObjectPropertyScopeGlobal,
-                                     &output_min_rate, &output_max_rate, &output_nominal_rate);
-  LOG("(%p) Output device %u min: %u, max: %u, nominal: %u rate", stm, stm->output_device.id
-      , output_min_rate, output_max_rate, output_nominal_rate);
-
-  if ((output_nominal_rate < input_min_rate || output_nominal_rate > output_max_rate)
-      || (input_nominal_rate < output_min_rate || input_nominal_rate > output_max_rate)){
-    return CUBEB_ERROR;
-  }
-
   int r = audiounit_create_blank_aggregate_device(&stm->plugin_id, &stm->aggregate_device_id);
   if (r != CUBEB_OK) {
     LOG("(%p) Failed to create blank aggregate device", stm);
     audiounit_destroy_aggregate_device(stm->plugin_id, &stm->aggregate_device_id);
     return CUBEB_ERROR;
   }
 
   r = audiounit_set_aggregate_sub_device_list(stm->aggregate_device_id, stm->input_device.id, stm->output_device.id);
@@ -1747,36 +1776,17 @@ audiounit_create_aggregate_device(cubeb_
 
   r = audiounit_activate_clock_drift_compensation(stm->aggregate_device_id);
   if (r != CUBEB_OK) {
     LOG("(%p) Failed to activate clock drift compensation for aggregate device", stm);
     audiounit_destroy_aggregate_device(stm->plugin_id, &stm->aggregate_device_id);
     return  CUBEB_ERROR;
   }
 
-  /* Do not attempt to change the nominal rate if it's the same with the nominal rate of
-   * output device because it's the master device and rate will set to that anyway. */
-  uint32_t min_rate = std::min(input_nominal_rate, output_nominal_rate);
-  if (input_nominal_rate != output_nominal_rate && min_rate != output_nominal_rate) {
-    LOG("Update aggregate device rate to %u", min_rate);
-    Float64 rate = min_rate;
-    AudioObjectPropertyAddress addr = {kAudioDevicePropertyNominalSampleRate,
-                                       kAudioObjectPropertyScopeGlobal,
-                                       kAudioObjectPropertyElementMaster};
-
-    OSStatus rv = AudioObjectSetPropertyData(stm->aggregate_device_id,
-                                             &addr,
-                                             0,
-                                             nullptr,
-                                             sizeof(Float64),
-                                             &rate);
-    if (rv != noErr) {
-      LOG("Non fatal error, AudioObjectSetPropertyData/kAudioDevicePropertyNominalSampleRate, rv=%d", rv);
-    }
-  }
+  audiounit_workaround_for_airpod(stm);
 
   return CUBEB_OK;
 }
 
 static int
 audiounit_destroy_aggregate_device(AudioObjectID plugin_id, AudioDeviceID * aggregate_device_id)
 {
   assert(aggregate_device_id &&