From 7712d5e6608d79104626f45f897cbc79c586156c Mon Sep 17 00:00:00 2001 From: Alex Chronopoulos Date: Mon, 17 Jul 2017 11:48:15 +0300 Subject: [PATCH] Bug 1381015 - Update cubeb from upstream to a329c6a. r=kinetik MozReview-Commit-ID: Gfutv4Tnvix --HG-- extra : rebase_source : 219433f6d6008814f8ce2839700a418cf0fda711 --- media/libcubeb/README_MOZILLA | 2 +- media/libcubeb/src/cubeb_audiounit.cpp | 21 ++++++---- media/libcubeb/src/cubeb_opensl.c | 55 ++++++++++++++++---------- 3 files changed, 49 insertions(+), 29 deletions(-) diff --git a/media/libcubeb/README_MOZILLA b/media/libcubeb/README_MOZILLA index 533dbc4e6519..f920788350c7 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 bb189841de715214d88e1fa0093dc390bbf95ff4 (2017-07-12 09:27:20 +0300) +The git commit ID used was a329c6a4184de3ccedb264cf2c3b0903fc506b94 (2017-07-14 15:35:51 +0300) diff --git a/media/libcubeb/src/cubeb_audiounit.cpp b/media/libcubeb/src/cubeb_audiounit.cpp index 4198574b7d54..ea5ca282ab61 100644 --- a/media/libcubeb/src/cubeb_audiounit.cpp +++ b/media/libcubeb/src/cubeb_audiounit.cpp @@ -1466,11 +1466,16 @@ audiounit_create_blank_aggregate_device(AudioObjectID * plugin_id, AudioDeviceID CFDictionaryAddValue(aggregate_device_dict, CFSTR(kAudioAggregateDeviceUIDKey), aggregate_device_UID); CFRelease(aggregate_device_UID); - int private_key = 1; - CFNumberRef aggregate_device_private_key = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &private_key); + int private_value = 1; + CFNumberRef aggregate_device_private_key = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &private_value); CFDictionaryAddValue(aggregate_device_dict, CFSTR(kAudioAggregateDeviceIsPrivateKey), aggregate_device_private_key); CFRelease(aggregate_device_private_key); + int stacked_value = 0; + CFNumberRef aggregate_device_stacked_key = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &stacked_value); + CFDictionaryAddValue(aggregate_device_dict, CFSTR(kAudioAggregateDeviceIsStackedKey), aggregate_device_stacked_key); + CFRelease(aggregate_device_stacked_key); + r = AudioObjectGetPropertyData(*plugin_id, &create_aggregate_device_address, sizeof(aggregate_device_dict), @@ -1506,20 +1511,22 @@ audiounit_set_aggregate_sub_device_list(AudioDeviceID aggregate_device_id, { LOG("Add devices input %u and output %u into aggregate device %u", input_device_id, output_device_id, aggregate_device_id); - const std::vector input_sub_devices = audiounit_get_sub_devices(input_device_id); const std::vector output_sub_devices = audiounit_get_sub_devices(output_device_id); + const std::vector input_sub_devices = audiounit_get_sub_devices(input_device_id); CFMutableArrayRef aggregate_sub_devices_array = CFArrayCreateMutable(NULL, 0, &kCFTypeArrayCallBacks); - for (UInt32 i = 0; i < input_sub_devices.size(); i++) { - CFStringRef ref = get_device_name(input_sub_devices[i]); + /* The order of the items in the array is significant and is used to determine the order of the streams + of the AudioAggregateDevice. */ + for (UInt32 i = 0; i < output_sub_devices.size(); i++) { + CFStringRef ref = get_device_name(output_sub_devices[i]); if (ref == NULL) { CFRelease(aggregate_sub_devices_array); return CUBEB_ERROR; } CFArrayAppendValue(aggregate_sub_devices_array, ref); } - for (UInt32 i = 0; i < output_sub_devices.size(); i++) { - CFStringRef ref = get_device_name(output_sub_devices[i]); + for (UInt32 i = 0; i < input_sub_devices.size(); i++) { + CFStringRef ref = get_device_name(input_sub_devices[i]); if (ref == NULL) { CFRelease(aggregate_sub_devices_array); return CUBEB_ERROR; diff --git a/media/libcubeb/src/cubeb_opensl.c b/media/libcubeb/src/cubeb_opensl.c index f4929cc4a4b9..677d7e40bfce 100644 --- a/media/libcubeb/src/cubeb_opensl.c +++ b/media/libcubeb/src/cubeb_opensl.c @@ -187,6 +187,29 @@ opensl_set_draining(cubeb_stream * stm, int value) stm->draining = value; } +static void +opensl_notify_drained(cubeb_stream * stm) +{ + assert(stm); + int r = pthread_mutex_lock(&stm->mutex); + assert(r == 0); + int draining = opensl_get_draining(stm); + r = pthread_mutex_unlock(&stm->mutex); + assert(r == 0); + if (draining) { + stm->state_callback(stm, stm->user_ptr, CUBEB_STATE_DRAINED); + if (stm->play) { + LOG("stop player in play_callback"); + r = opensl_stop_player(stm); + assert(r == CUBEB_OK); + } + if (stm->recorderItf) { + r = opensl_stop_recorder(stm); + assert(r == CUBEB_OK); + } + } +} + static uint32_t opensl_get_shutdown(cubeb_stream * stm) { @@ -217,24 +240,7 @@ play_callback(SLPlayItf caller, void * user_ptr, SLuint32 event) assert(stm); switch (event) { case SL_PLAYEVENT_HEADATMARKER: - { - int r = pthread_mutex_lock(&stm->mutex); - assert(r == 0); - draining = opensl_get_draining(stm); - r = pthread_mutex_unlock(&stm->mutex); - assert(r == 0); - if (draining) { - stm->state_callback(stm, stm->user_ptr, CUBEB_STATE_DRAINED); - if (stm->play) { - r = opensl_stop_player(stm); - assert(r == CUBEB_OK); - } - if (stm->recorderItf) { - r = opensl_stop_recorder(stm); - assert(r == CUBEB_OK); - } - } - } + opensl_notify_drained(stm); break; default: break; @@ -330,9 +336,16 @@ bufferqueue_callback(SLBufferQueueItf caller, void * user_ptr) opensl_set_draining(stm, 1); r = pthread_mutex_unlock(&stm->mutex); assert(r == 0); - // Use SL_PLAYEVENT_HEADATMARKER event from slPlayCallback of SLPlayItf - // to make sure all the data has been processed. - (*stm->play)->SetMarkerPosition(stm->play, (SLmillisecond)written_duration); + + if (written_duration == 0) { + // since we didn't write any sample, it's not possible to reach the marker + // time and trigger the callback. We should initiative notify drained. + opensl_notify_drained(stm); + } else { + // Use SL_PLAYEVENT_HEADATMARKER event from slPlayCallback of SLPlayItf + // to make sure all the data has been processed. + (*stm->play)->SetMarkerPosition(stm->play, (SLmillisecond)written_duration); + } return; } }