Bug 1366707 - Update cubeb from upstream to 96cdb17. r=kinetik

MozReview-Commit-ID: 3aiEtrl289U

--HG--
extra : rebase_source : 16ebdb2e20fc516047cc8f4974d6c9e6ec638fcb
This commit is contained in:
Alex Chronopoulos 2017-05-23 11:29:33 +03:00
Родитель ad000bc76c
Коммит 9281e65d26
20 изменённых файлов: 137 добавлений и 64 удалений

Просмотреть файл

@ -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 26a50b08889a16d3f1e7fe05845cc107c7553f70 (2017-05-05 19:29:05 +1200)
The git commit ID used was 96cdb173f86dfc86cbd21d097b24ec1e256d69fc (2017-05-22 11:55:15 +0300)

Просмотреть файл

@ -82,6 +82,7 @@ int has_available_input_device(cubeb * ctx)
if (devices->count == 0) {
fprintf(stderr, "no input device available, skipping test.\n");
cubeb_device_collection_destroy(ctx, devices);
return 0;
}
@ -93,10 +94,10 @@ int has_available_input_device(cubeb * ctx)
if (!input_device_available) {
fprintf(stderr, "there are input devices, but they are not "
"available, skipping\n");
return 0;
}
return 1;
cubeb_device_collection_destroy(ctx, devices);
return !!input_device_available;
}
void print_log(const char * msg, ...)

Просмотреть файл

@ -129,7 +129,7 @@ TEST(cubeb, enumerate_devices)
fprintf(stdout, "Found %u input devices\n", collection->count);
print_device_collection(collection, stdout);
cubeb_device_collection_destroy(collection);
cubeb_device_collection_destroy(ctx, collection);
fprintf(stdout, "Enumerating output devices for backend %s\n",
cubeb_get_backend_id(ctx));
@ -139,5 +139,5 @@ TEST(cubeb, enumerate_devices)
fprintf(stdout, "Found %u output devices\n", collection->count);
print_device_collection(collection, stdout);
cubeb_device_collection_destroy(collection);
cubeb_device_collection_destroy(ctx, collection);
}

Просмотреть файл

@ -577,6 +577,8 @@ TEST(cubeb, resampler_passthrough_output_only)
got = cubeb_resampler_fill(resampler, nullptr, nullptr, output_buffer, 256);
ASSERT_EQ(got, 256);
}
cubeb_resampler_destroy(resampler);
}
// gtest does not support using ASSERT_EQ and friend in a function that returns
@ -620,6 +622,8 @@ TEST(cubeb, resampler_passthrough_input_only)
got = cubeb_resampler_fill(resampler, input_buffer, &frames, nullptr, 0);
ASSERT_EQ(got, 256);
}
cubeb_resampler_destroy(resampler);
}
template<typename T>
@ -748,4 +752,6 @@ TEST(cubeb, resampler_passthrough_duplex_callback_reordering)
}
ASSERT_EQ(got, BUF_BASE_SIZE);
}
cubeb_resampler_destroy(resampler);
}

Просмотреть файл

@ -330,9 +330,10 @@ typedef enum {
} cubeb_device_pref;
/** This structure holds the characteristics
* of an input or output audio device. It can be obtained using
* `cubeb_enumerate_devices`, and must be destroyed using
* `cubeb_device_info_destroy`. */
* of an input or output audio device. It is obtained using
* `cubeb_enumerate_devices`, which returns these structures via
* `cubeb_device_collection` and must be destroyed via
* `cubeb_device_collection_destroy`. */
typedef struct {
cubeb_devid devid; /**< Device identifier handle. */
char const * device_id; /**< Device identifier which might be presented in a UI. */
@ -355,10 +356,12 @@ typedef struct {
unsigned int latency_hi; /**< Higest possible latency in frames. */
} cubeb_device_info;
/** Device collection. */
/** Device collection.
* Returned by `cubeb_enumerate_devices` and destroyed by
* `cubeb_device_collection_destroy`. */
typedef struct {
uint32_t count; /**< Device count in collection. */
cubeb_device_info * device[1]; /**< Array of pointers to device info. */
cubeb_device_info * device[1]; /**< Array of pointers to device info. */
} cubeb_device_collection;
/** User supplied data callback.
@ -612,16 +615,12 @@ CUBEB_EXPORT int cubeb_enumerate_devices(cubeb * context,
cubeb_device_collection ** collection);
/** Destroy a cubeb_device_collection, and its `cubeb_device_info`.
@param context
@param collection collection to destroy
@retval CUBEB_OK
@retval CUBEB_ERROR_INVALID_PARAMETER if collection is an invalid pointer */
CUBEB_EXPORT int cubeb_device_collection_destroy(cubeb_device_collection * collection);
/** Destroy a cubeb_device_info structure.
@param info pointer to device info structure
@retval CUBEB_OK
@retval CUBEB_ERROR_INVALID_PARAMETER if info is an invalid pointer */
CUBEB_EXPORT int cubeb_device_info_destroy(cubeb_device_info * info);
CUBEB_EXPORT int cubeb_device_collection_destroy(cubeb * context,
cubeb_device_collection * collection);
/** Registers a callback which is called when the system detects
a new device or a device is removed.

Просмотреть файл

@ -52,6 +52,7 @@ struct cubeb_ops {
int (* get_preferred_channel_layout)(cubeb * context, cubeb_channel_layout * layout);
int (* enumerate_devices)(cubeb * context, cubeb_device_type type,
cubeb_device_collection ** collection);
int (* device_collection_destroy)(cubeb * context, cubeb_device_collection * collection);
void (* destroy)(cubeb * context);
int (* stream_init)(cubeb * context,
cubeb_stream ** stream,

Просмотреть файл

@ -571,33 +571,16 @@ int cubeb_enumerate_devices(cubeb * context,
return rv;
}
int cubeb_device_collection_destroy(cubeb_device_collection * collection)
int cubeb_device_collection_destroy(cubeb * context,
cubeb_device_collection * collection)
{
uint32_t i;
if (collection == NULL)
if (context == NULL || collection == NULL)
return CUBEB_ERROR_INVALID_PARAMETER;
for (i = 0; i < collection->count; i++)
cubeb_device_info_destroy(collection->device[i]);
if (!context->ops->device_collection_destroy)
return CUBEB_ERROR_NOT_SUPPORTED;
free(collection);
return CUBEB_OK;
}
int cubeb_device_info_destroy(cubeb_device_info * info)
{
if (info == NULL) {
return CUBEB_ERROR_INVALID_PARAMETER;
}
free((void *) info->device_id);
free((void *) info->friendly_name);
free((void *) info->group_id);
free((void *) info->vendor_name);
free(info);
return CUBEB_OK;
return context->ops->device_collection_destroy(context, collection);
}
int cubeb_register_device_collection_changed(cubeb * context,

Просмотреть файл

@ -17,6 +17,7 @@
#include <alsa/asoundlib.h>
#include "cubeb/cubeb.h"
#include "cubeb-internal.h"
#include "cubeb_utils.h"
#define CUBEB_STREAM_MAX 16
#define CUBEB_WATCHDOG_MS 10000
@ -1342,6 +1343,7 @@ static struct cubeb_ops const alsa_ops = {
.get_preferred_sample_rate = alsa_get_preferred_sample_rate,
.get_preferred_channel_layout = NULL,
.enumerate_devices = alsa_enumerate_devices,
.device_collection_destroy = cubeb_utils_default_device_collection_destroy,
.destroy = alsa_destroy,
.stream_init = alsa_stream_init,
.stream_destroy = alsa_stream_destroy,

Просмотреть файл

@ -423,6 +423,7 @@ static struct cubeb_ops const audiotrack_ops = {
.get_preferred_sample_rate = audiotrack_get_preferred_sample_rate,
.get_preferred_channel_layout = NULL,
.enumerate_devices = NULL,
.device_collection_destroy = NULL,
.destroy = audiotrack_destroy,
.stream_init = audiotrack_stream_init,
.stream_destroy = audiotrack_stream_destroy,

Просмотреть файл

@ -603,6 +603,7 @@ audiounit_get_input_device_id(AudioDeviceID * device_id)
static int audiounit_stream_get_volume(cubeb_stream * stm, float * volume);
static int audiounit_stream_set_volume(cubeb_stream * stm, float volume);
static int audiounit_uninstall_device_changed_callback(cubeb_stream * stm);
static int
audiounit_reinit_stream(cubeb_stream * stm)
@ -612,10 +613,18 @@ audiounit_reinit_stream(cubeb_stream * stm)
audiounit_stream_stop_internal(stm);
}
int r = audiounit_uninstall_device_changed_callback(stm);
if (r != CUBEB_OK) {
LOG("(%p) Could not uninstall the device changed callback", stm);
}
{
auto_lock lock(stm->mutex);
float volume = 0.0;
int vol_rv = audiounit_stream_get_volume(stm, &volume);
int vol_rv = CUBEB_ERROR;
if (has_output(stm)) {
vol_rv = audiounit_stream_get_volume(stm, &volume);
}
audiounit_close_stream(stm);
@ -677,11 +686,8 @@ audiounit_property_listener_callback(AudioObjectID /* id */, UInt32 address_coun
break;
case kAudioDevicePropertyDataSource: {
LOG("Event[%u] - mSelector == kAudioHardwarePropertyDataSource", (unsigned int) i);
if (has_output(stm)) {
stm->output_device = 0;
}
return noErr;
}
break;
default:
LOG("Event[%u] - mSelector == Unexpected Event id %d, return", (unsigned int) i, addresses[i].mSelector);
return noErr;
@ -2516,11 +2522,6 @@ audiounit_close_stream(cubeb_stream *stm)
{
stm->mutex.assert_current_thread_owns();
int r = audiounit_uninstall_device_changed_callback(stm);
if (r != CUBEB_OK) {
LOG("(%p) Could not uninstall the device changed callback", stm);
}
if (stm->input_unit) {
AudioUnitUninitialize(stm->input_unit);
AudioComponentInstanceDispose(stm->input_unit);
@ -2554,13 +2555,20 @@ audiounit_stream_destroy(cubeb_stream * stm)
LOG("(%p) Could not uninstall the device changed callback", stm);
}
r = audiounit_uninstall_device_changed_callback(stm);
if (r != CUBEB_OK) {
LOG("(%p) Could not uninstall the device changed callback", stm);
}
auto_lock context_lock(stm->context->mutex);
audiounit_stream_stop_internal(stm);
{
// Execute close in serial queue to avoid collision
// with reinit when un/plug devices
dispatch_sync(stm->context->serial_queue, ^() {
auto_lock lock(stm->mutex);
audiounit_close_stream(stm);
}
});
assert(stm->context->active_streams >= 1);
stm->context->active_streams -= 1;
@ -3297,6 +3305,7 @@ cubeb_ops const audiounit_ops = {
/*.get_preferred_sample_rate =*/ audiounit_get_preferred_sample_rate,
/*.get_preferred_channel_layout =*/ audiounit_get_preferred_channel_layout,
/*.enumerate_devices =*/ audiounit_enumerate_devices,
/*.device_collection_destroy =*/ cubeb_utils_default_device_collection_destroy,
/*.destroy =*/ audiounit_destroy,
/*.stream_init =*/ audiounit_stream_init,
/*.stream_destroy =*/ audiounit_stream_destroy,

Просмотреть файл

@ -19,6 +19,7 @@
#include "cubeb/cubeb.h"
#include "cubeb-internal.h"
#include "cubeb_resampler.h"
#include "cubeb_utils.h"
#include <jack/jack.h>
#include <jack/statistics.h>
@ -116,6 +117,7 @@ static struct cubeb_ops const cbjack_ops = {
.get_preferred_sample_rate = cbjack_get_preferred_sample_rate,
.get_preferred_channel_layout = NULL,
.enumerate_devices = cbjack_enumerate_devices,
.device_collection_destroy = cubeb_utils_default_device_collection_destroy,
.destroy = cbjack_destroy,
.stream_init = cbjack_stream_init,
.stream_destroy = cbjack_stream_destroy,

Просмотреть файл

@ -1740,6 +1740,7 @@ static struct cubeb_ops const opensl_ops = {
.get_preferred_sample_rate = opensl_get_preferred_sample_rate,
.get_preferred_channel_layout = NULL,
.enumerate_devices = NULL,
.device_collection_destroy = NULL,
.destroy = opensl_destroy,
.stream_init = opensl_stream_init,
.stream_destroy = opensl_stream_destroy,

Просмотреть файл

@ -13,6 +13,7 @@
#include "cubeb/cubeb.h"
#include "cubeb-internal.h"
#include "cubeb_mixer.h"
#include "cubeb_utils.h"
#include <stdio.h>
#ifdef DISABLE_LIBPULSE_DLOPEN
@ -1495,6 +1496,7 @@ static struct cubeb_ops const pulse_ops = {
.get_preferred_sample_rate = pulse_get_preferred_sample_rate,
.get_preferred_channel_layout = pulse_get_preferred_channel_layout,
.enumerate_devices = pulse_enumerate_devices,
.device_collection_destroy = cubeb_utils_default_device_collection_destroy,
.destroy = pulse_destroy,
.stream_init = pulse_stream_init,
.stream_destroy = pulse_stream_destroy,

Просмотреть файл

@ -370,6 +370,7 @@ static struct cubeb_ops const sndio_ops = {
.get_preferred_sample_rate = sndio_get_preferred_sample_rate,
.get_preferred_channel_layout = NULL,
.enumerate_devices = NULL,
.device_collection_destroy = NULL,
.destroy = sndio_destroy,
.stream_init = sndio_stream_init,
.stream_destroy = sndio_stream_destroy,

Просмотреть файл

@ -0,0 +1,40 @@
/*
* Copyright © 2016 Mozilla Foundation
*
* This program is made available under an ISC-style license. See the
* accompanying file LICENSE for details.
*/
#include "cubeb_utils.h"
#include "cubeb_assert.h"
#include <stdlib.h>
static void
device_info_destroy(cubeb_device_info * info)
{
XASSERT(info);
free((void *) info->device_id);
free((void *) info->friendly_name);
free((void *) info->group_id);
free((void *) info->vendor_name);
free(info);
}
int
cubeb_utils_default_device_collection_destroy(cubeb * context,
cubeb_device_collection * collection)
{
uint32_t i;
XASSERT(collection);
(void) context;
for (i = 0; i < collection->count; i++)
device_info_destroy(collection->device[i]);
free(collection);
return CUBEB_OK;
}

Просмотреть файл

@ -8,6 +8,10 @@
#if !defined(CUBEB_UTILS)
#define CUBEB_UTILS
#include "cubeb/cubeb.h"
#ifdef __cplusplus
#include <stdint.h>
#include <string.h>
#include <assert.h>
@ -330,5 +334,19 @@ private:
};
using auto_lock = std::lock_guard<owned_critical_section>;
#endif // __cplusplus
// C language helpers
#ifdef __cplusplus
extern "C" {
#endif
int cubeb_utils_default_device_collection_destroy(cubeb * context,
cubeb_device_collection * collection);
#ifdef __cplusplus
}
#endif
#endif /* CUBEB_UTILS */

Просмотреть файл

@ -421,14 +421,13 @@ double stream_to_mix_samplerate_ratio(cubeb_stream_params & stream, cubeb_stream
static DWORD
channel_layout_to_mask(cubeb_channel_layout layout)
{
XASSERT(layout > CUBEB_LAYOUT_UNDEFINED && layout < CUBEB_LAYOUT_MAX &&
"This mask conversion is not allowed.");
XASSERT(layout < CUBEB_LAYOUT_MAX && "invalid conversion.");
// This variable may be used for multiple times, so we should avoid to
// allocate it in stack, or it will be created and removed repeatedly.
// Use static to allocate this local variable in data space instead of stack.
static DWORD map[CUBEB_LAYOUT_MAX] = {
0, // CUBEB_LAYOUT_UNDEFINED (this won't be used.)
0, // CUBEB_LAYOUT_UNDEFINED
MASK_DUAL_MONO, // CUBEB_LAYOUT_DUAL_MONO
MASK_DUAL_MONO_LFE, // CUBEB_LAYOUT_DUAL_MONO_LFE
MASK_MONO, // CUBEB_LAYOUT_MONO
@ -1390,9 +1389,12 @@ waveformatex_update_derived_properties(WAVEFORMATEX * format)
/* Based on the mix format and the stream format, try to find a way to play
what the user requested. */
static void
handle_channel_layout(cubeb_stream * stm, com_heap_ptr<WAVEFORMATEX> & mix_format, const cubeb_stream_params * stream_params)
handle_channel_layout(cubeb_stream * stm, EDataFlow direction, com_heap_ptr<WAVEFORMATEX> & mix_format, const cubeb_stream_params * stream_params)
{
XASSERT(stream_params->layout != CUBEB_LAYOUT_UNDEFINED);
// The CUBEB_LAYOUT_UNDEFINED can be used for input but it's not allowed for output.
XASSERT(direction == eCapture || stream_params->layout != CUBEB_LAYOUT_UNDEFINED);
com_ptr<IAudioClient> & audio_client = (direction == eRender) ? stm->output_client : stm->input_client;
XASSERT(audio_client);
/* The docs say that GetMixFormat is always of type WAVEFORMATEXTENSIBLE [1],
so the reinterpret_cast below should be safe. In practice, this is not
true, and we just want to bail out and let the rest of the code find a good
@ -1415,9 +1417,9 @@ handle_channel_layout(cubeb_stream * stm, com_heap_ptr<WAVEFORMATEX> & mix_form
/* Check if wasapi will accept our channel layout request. */
WAVEFORMATEX * closest;
HRESULT hr = stm->output_client->IsFormatSupported(AUDCLNT_SHAREMODE_SHARED,
mix_format.get(),
&closest);
HRESULT hr = audio_client->IsFormatSupported(AUDCLNT_SHAREMODE_SHARED,
mix_format.get(),
&closest);
if (hr == S_FALSE) {
/* Channel layout not supported, but WASAPI gives us a suggestion. Use it,
and handle the eventual upmix/downmix ourselves. Ignore the subformat of
@ -1513,12 +1515,11 @@ int setup_wasapi_stream_one_side(cubeb_stream * stm,
mix_format->wBitsPerSample = stm->bytes_per_sample * 8;
format_pcm->SubFormat = stm->waveformatextensible_sub_format;
waveformatex_update_derived_properties(mix_format.get());
/* Set channel layout only when there're more than two channels. Otherwise,
* use the default setting retrieved from the stream format of the audio
* engine's internal processing by GetMixFormat. */
if (mix_format->nChannels > 2) {
handle_channel_layout(stm, mix_format, stream_params);
handle_channel_layout(stm, direction ,mix_format, stream_params);
}
mix_params->format = stream_params->format;
@ -1752,7 +1753,8 @@ wasapi_stream_init(cubeb * context, cubeb_stream ** stream,
stm->input_stream_params = *input_stream_params;
stm->input_device = utf8_to_wstr(reinterpret_cast<char const *>(input_device));
// Make sure the layout matches the channel count.
XASSERT(stm->input_stream_params.channels == CUBEB_CHANNEL_LAYOUT_MAPS[stm->input_stream_params.layout].channels);
XASSERT(stm->input_stream_params.layout == CUBEB_LAYOUT_UNDEFINED ||
stm->input_stream_params.channels == CUBEB_CHANNEL_LAYOUT_MAPS[stm->input_stream_params.layout].channels);
}
if (output_stream_params) {
stm->output_stream_params = *output_stream_params;
@ -2321,6 +2323,7 @@ cubeb_ops const wasapi_ops = {
/*.get_preferred_sample_rate =*/ wasapi_get_preferred_sample_rate,
/*.get_preferred_channel_layout =*/ wasapi_get_preferred_channel_layout,
/*.enumerate_devices =*/ wasapi_enumerate_devices,
/*.device_collection_destroy =*/ cubeb_utils_default_device_collection_destroy,
/*.destroy =*/ wasapi_destroy,
/*.stream_init =*/ wasapi_stream_init,
/*.stream_destroy =*/ wasapi_stream_destroy,

Просмотреть файл

@ -19,6 +19,7 @@
#include <math.h>
#include "cubeb/cubeb.h"
#include "cubeb-internal.h"
#include "cubeb_utils.h"
/* This is missing from the MinGW headers. Use a safe fallback. */
#if !defined(MEMORY_ALLOCATION_ALIGNMENT)
@ -1050,6 +1051,7 @@ static struct cubeb_ops const winmm_ops = {
/*.get_preferred_sample_rate =*/ winmm_get_preferred_sample_rate,
/*.get_preferred_channel_layout =*/ NULL,
/*.enumerate_devices =*/ winmm_enumerate_devices,
/*.device_collection_destroy =*/ cubeb_utils_default_device_collection_destroy,
/*.destroy =*/ winmm_destroy,
/*.stream_init =*/ winmm_stream_init,
/*.stream_destroy =*/ winmm_stream_destroy,

Просмотреть файл

@ -12,7 +12,8 @@ SOURCES += [
'cubeb.c',
'cubeb_log.cpp',
'cubeb_mixer.cpp',
'cubeb_panner.cpp'
'cubeb_panner.cpp',
'cubeb_utils.c'
]
if CONFIG['MOZ_ALSA']:

Просмотреть файл

@ -30,6 +30,7 @@ cp $1/src/cubeb_resampler_internal.h src
cp $1/src/cubeb_ring_array.h src
cp $1/src/cubeb_ringbuffer.h src
cp $1/src/cubeb_sndio.c src
cp $1/src/cubeb_utils.c src
cp $1/src/cubeb_utils.h src
cp $1/src/cubeb_utils_unix.h src
cp $1/src/cubeb_utils_win.h src