From 0ae243650caa0853e4c01861f6a2a359c639ca84 Mon Sep 17 00:00:00 2001 From: Alex Chronopoulos Date: Thu, 26 Oct 2017 10:41:49 +0300 Subject: [PATCH] Bug 1411866 - Update cubeb from upstream to cf5ddc5. r=padenot,kinetik MozReview-Commit-ID: IPgIZ6oBVfg --- media/libcubeb/README_MOZILLA | 2 +- media/libcubeb/src/cubeb_audiounit.cpp | 26 ++++++++++++++++++-------- media/libcubeb/src/cubeb_utils.h | 2 +- 3 files changed, 20 insertions(+), 10 deletions(-) diff --git a/media/libcubeb/README_MOZILLA b/media/libcubeb/README_MOZILLA index f2de53433642..506d2dc5434b 100644 --- a/media/libcubeb/README_MOZILLA +++ b/media/libcubeb/README_MOZILLA @@ -5,4 +5,4 @@ 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 40cd4ad03b68a215e985979c96783824f19e288f (2017-10-03 13:38:45 +0200) +The git commit ID used was cf5ddc5316dd1ab3ee7f54b2dcbcc9980e556d13 (2017-10-26 09:48:04 +1300) diff --git a/media/libcubeb/src/cubeb_audiounit.cpp b/media/libcubeb/src/cubeb_audiounit.cpp index d06ed9247869..348528489a8e 100644 --- a/media/libcubeb/src/cubeb_audiounit.cpp +++ b/media/libcubeb/src/cubeb_audiounit.cpp @@ -651,13 +651,19 @@ audiounit_reinit_stream(cubeb_stream * stm, device_flags_value flags) * device. This is considered the most expected behavior for the user. */ if (flags & DEV_INPUT) { r = audiounit_set_device_info(stm, 0, INPUT); - assert(r == CUBEB_OK); + if (r != CUBEB_OK) { + LOG("(%p) Set input device info failed. This can happen when last media device is unplugged", stm); + return CUBEB_ERROR; + } } /* Always use the default output on reinit. This is not correct in every case * but it is sufficient for Firefox and prevent reinit from reporting failures. * It will change soon when reinit mechanism will be updated. */ r = audiounit_set_device_info(stm, 0, OUTPUT); - assert(r == CUBEB_OK); + if (r != CUBEB_OK) { + LOG("(%p) Set output device info failed. This can happen when last media device is unplugged", stm); + return CUBEB_ERROR; + } if (audiounit_setup_stream(stm) != CUBEB_OK) { LOG("(%p) Stream reinit failed.", stm); @@ -697,6 +703,8 @@ event_addr_to_string(AudioObjectPropertySelector selector) } } +static int audiounit_uninstall_system_changed_callback(cubeb_stream * stm); + static OSStatus audiounit_property_listener_callback(AudioObjectID id, UInt32 address_count, const AudioObjectPropertyAddress * addresses, @@ -775,6 +783,9 @@ audiounit_property_listener_callback(AudioObjectID id, UInt32 address_count, // Get/SetProperties method from inside notify callback dispatch_async(stm->context->serial_queue, ^() { if (audiounit_reinit_stream(stm, switch_side) != CUBEB_OK) { + if (audiounit_uninstall_system_changed_callback(stm) != CUBEB_OK) { + LOG("(%p) Could not uninstall the device changed callback", stm); + } stm->state_callback(stm, stm->user_ptr, CUBEB_STATE_STOPPED); LOG("(%p) Could not reopen the stream after switching.", stm); } @@ -921,7 +932,7 @@ audiounit_uninstall_system_changed_callback(cubeb_stream * stm) { OSStatus r; - if (stm->output_unit) { + if (has_output(stm)) { r = audiounit_remove_listener(stm, kAudioObjectSystemObject, kAudioHardwarePropertyDefaultOutputDevice, kAudioObjectPropertyScopeGlobal, &audiounit_property_listener_callback); if (r != noErr) { @@ -929,7 +940,7 @@ audiounit_uninstall_system_changed_callback(cubeb_stream * stm) } } - if (stm->input_unit) { + if (has_input(stm)) { r = audiounit_remove_listener(stm, kAudioObjectSystemObject, kAudioHardwarePropertyDefaultInputDevice, kAudioObjectPropertyScopeGlobal, &audiounit_property_listener_callback); if (r != noErr) { @@ -2498,7 +2509,9 @@ audiounit_stream_init(cubeb * context, cubeb_state_callback state_callback, void * user_ptr) { - std::unique_ptr stm(nullptr, audiounit_stream_destroy); + std::unique_ptr stm(new cubeb_stream(context), + audiounit_stream_destroy); + context->active_streams += 1; int r; assert(context); @@ -2509,8 +2522,6 @@ audiounit_stream_init(cubeb * context, return CUBEB_ERROR_INVALID_PARAMETER; } - stm.reset(new cubeb_stream(context)); - /* These could be different in the future if we have both * full-duplex stream and different devices for input vs output. */ stm->data_callback = data_callback; @@ -2539,7 +2550,6 @@ audiounit_stream_init(cubeb * context, // It's not critical to lock here, because no other thread has been started // yet, but it allows to assert that the lock has been taken in // `audiounit_setup_stream`. - context->active_streams += 1; auto_lock lock(stm->mutex); r = audiounit_setup_stream(stm.get()); } diff --git a/media/libcubeb/src/cubeb_utils.h b/media/libcubeb/src/cubeb_utils.h index 09665606247b..dc08fec9928d 100644 --- a/media/libcubeb/src/cubeb_utils.h +++ b/media/libcubeb/src/cubeb_utils.h @@ -17,7 +17,7 @@ #include #include #include -#if defined(WIN32) +#if defined(_WIN32) #include "cubeb_utils_win.h" #else #include "cubeb_utils_unix.h"