Bug 1498519 - Update cubeb from upstream to 4559815. r=padenot
authorAlex Chronopoulos <achronop@gmail.com>
Fri, 12 Oct 2018 13:31:18 +0300
changeset 499319 fbf50f6e40718aa2c8e1e1116e858ac5a3d3e26e
parent 499318 e009fe76cb87961baf55cb10b68f86cb3a258367
child 499320 ede21c2f2f993c7bb00d37b1e52b62c9f0c4c671
child 499430 80983dcd1180daeaaf7da3201b48c63506b6f6c7
push id1864
push userffxbld-merge
push dateMon, 03 Dec 2018 15:51:40 +0000
treeherdermozilla-release@f040763d99ad [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerspadenot
bugs1498519, 4559815
milestone64.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 1498519 - Update cubeb from upstream to 4559815. r=padenot Differential Revision: https://phabricator.services.mozilla.com/D8527
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 b832dae6e48d3a95d1e6d977d0b7c53a873fd246 (2018-09-17 21:35:14 +1200)
+The git commit ID used was 455981555e37a0153e5dd4d4517f073262946519 (2018-10-11 18:48:08 +0300)
--- a/media/libcubeb/src/cubeb_audiounit.cpp
+++ b/media/libcubeb/src/cubeb_audiounit.cpp
@@ -582,17 +582,17 @@ audiounit_output_callback(void * user_pt
   cubeb_stream * stm = static_cast<cubeb_stream *>(user_ptr);
 
   ALOGV("(%p) output: buffers %u, size %u, channels %u, frames %u, total input frames %lu.",
         stm,
         (unsigned int) outBufferList->mNumberBuffers,
         (unsigned int) outBufferList->mBuffers[0].mDataByteSize,
         (unsigned int) outBufferList->mBuffers[0].mNumberChannels,
         (unsigned int) output_frames,
-        stm->input_linear_buffer->length() / stm->input_desc.mChannelsPerFrame);
+        has_input(stm) ? stm->input_linear_buffer->length() / stm->input_desc.mChannelsPerFrame : 0);
 
   long input_frames = 0;
   void * output_buffer = NULL, * input_buffer = NULL;
 
   if (stm->shutdown) {
     ALOG("(%p) output shutdown.", stm);
     audiounit_make_silent(&outBufferList->mBuffers[0]);
     return noErr;
@@ -3391,41 +3391,50 @@ audiounit_get_devices_of_type(cubeb_devi
 {
   UInt32 size = 0;
   OSStatus ret = AudioObjectGetPropertyDataSize(kAudioObjectSystemObject,
                                                 &DEVICES_PROPERTY_ADDRESS, 0,
                                                 NULL, &size);
   if (ret != noErr) {
     return vector<AudioObjectID>();
   }
-  /* Total number of input and output devices. */
-  uint32_t count = (uint32_t)(size / sizeof(AudioObjectID));
-
-  vector<AudioObjectID> devices(count);
+  vector<AudioObjectID> devices(size / sizeof(AudioObjectID));
   ret = AudioObjectGetPropertyData(kAudioObjectSystemObject,
                                    &DEVICES_PROPERTY_ADDRESS, 0, NULL, &size,
                                    devices.data());
   if (ret != noErr) {
     return vector<AudioObjectID>();
   }
+
+  // Remove the aggregate device from the list of devices (if any).
+  for (auto it = devices.begin(); it != devices.end();) {
+    CFStringRef name = get_device_name(*it);
+    if (CFStringFind(name, CFSTR("CubebAggregateDevice"), 0).location !=
+        kCFNotFound) {
+      it = devices.erase(it);
+    } else {
+      it++;
+    }
+  }
+
   /* Expected sorted but did not find anything in the docs. */
   sort(devices.begin(), devices.end(), [](AudioObjectID a, AudioObjectID b) {
       return a < b;
     });
 
   if (devtype == (CUBEB_DEVICE_TYPE_INPUT | CUBEB_DEVICE_TYPE_OUTPUT)) {
     return devices;
   }
 
   AudioObjectPropertyScope scope = (devtype == CUBEB_DEVICE_TYPE_INPUT) ?
                                          kAudioDevicePropertyScopeInput :
                                          kAudioDevicePropertyScopeOutput;
 
   vector<AudioObjectID> devices_in_scope;
-  for (uint32_t i = 0; i < count; ++i) {
+  for (uint32_t i = 0; i < devices.size(); ++i) {
     /* For device in the given scope channel must be > 0. */
     if (audiounit_get_channel_count(devices[i], scope) > 0) {
       devices_in_scope.push_back(devices[i]);
     }
   }
 
   return devices_in_scope;
 }
@@ -3441,57 +3450,27 @@ audiounit_collection_changed_callback(Au
   // This can be called from inside an AudioUnit function, dispatch to another queue.
   dispatch_async(context->serial_queue, ^() {
     auto_lock lock(context->mutex);
     if (context->collection_changed_callback == NULL) {
       /* Listener removed while waiting in mutex, abort. */
       return;
     }
 
-    /* Differentiate input from output changes. */
-    if (context->collection_changed_devtype == CUBEB_DEVICE_TYPE_INPUT ||
-        context->collection_changed_devtype == CUBEB_DEVICE_TYPE_OUTPUT) {
-      vector<AudioObjectID> devices = audiounit_get_devices_of_type(context->collection_changed_devtype);
-      /* When count is the same examine the devid for the case of coalescing. */
-      if (context->devtype_device_array == devices) {
-        /* Device changed for the other scope, ignore. */
-        return;
-      } else {
-        /* Also don't trigger the user callback if the new added device is private
-         * aggregate device: compute the set of new devices, and remove those
-         * with the name of our private aggregate devices. */
-        set<AudioObjectID> current_devices(devices.begin(), devices.end());
-        set<AudioObjectID> previous_devices(context->devtype_device_array.begin(),
-                                            context->devtype_device_array.end());
-        set<AudioObjectID> new_devices;
-        set_difference(current_devices.begin(), current_devices.end(),
-                       previous_devices.begin(), previous_devices.end(),
-                       inserter(new_devices, new_devices.begin()));
-
-        for (auto it = new_devices.begin(); it != new_devices.end();) {
-          CFStringRef name = get_device_name(*it);
-          if (CFStringFind(name, CFSTR("CubebAggregateDevice"), 0).location !=
-              kCFNotFound) {
-            it = new_devices.erase(it);
-          } else {
-            it++;
-          }
-        }
-
-        // If this set of new devices is empty, it means this was triggerd
-        // solely by creating an aggregate device, no need to trigger the user
-        // callback.
-        if (new_devices.empty()) {
-          return;
-        }
-      }
-      /* Device on desired scope changed. */
-      context->devtype_device_array = devices;
+    assert(context->collection_changed_devtype &
+           (CUBEB_DEVICE_TYPE_INPUT | CUBEB_DEVICE_TYPE_OUTPUT));
+
+    vector<AudioObjectID> devices = audiounit_get_devices_of_type(context->collection_changed_devtype);
+    /* The elements in the vector are sorted. */
+    if (context->devtype_device_array == devices) {
+      /* Device changed for the other scope, ignore. */
+      return;
     }
-
+    /* Device on desired scope has changed. */
+    context->devtype_device_array = devices;
     context->collection_changed_callback(context, context->collection_changed_user_ptr);
   });
   return noErr;
 }
 
 static OSStatus
 audiounit_add_device_listener(cubeb * context,
                               cubeb_device_type devtype,
@@ -3506,21 +3485,19 @@ audiounit_add_device_listener(cubeb * co
                                                 &DEVICES_PROPERTY_ADDRESS,
                                                 audiounit_collection_changed_callback,
                                                 context);
   if (ret == noErr) {
     /* Expected empty after unregister. */
     assert(context->devtype_device_array.empty());
     /* Listener works for input and output.
      * When requested one of them we need to differentiate. */
-    if (devtype == CUBEB_DEVICE_TYPE_INPUT ||
-        devtype == CUBEB_DEVICE_TYPE_OUTPUT) {
-      /* Used to differentiate input from output device changes. */
-      context->devtype_device_array = audiounit_get_devices_of_type(devtype);
-    }
+    assert(devtype &
+           (CUBEB_DEVICE_TYPE_INPUT | CUBEB_DEVICE_TYPE_OUTPUT));
+    context->devtype_device_array = audiounit_get_devices_of_type(devtype);
     context->collection_changed_devtype = devtype;
     context->collection_changed_callback = collection_changed_callback;
     context->collection_changed_user_ptr = user_ptr;
   }
   return ret;
 }
 
 static OSStatus