Bug 1380233 - Update cubeb from upstream to bb18984. r=kinetik

MozReview-Commit-ID: FU0a9BWcOoN

--HG--
extra : rebase_source : e40749d95d6928e12a1d5e88c082b3a167e18924
This commit is contained in:
Alex Chronopoulos 2017-07-13 13:04:52 +03:00
Родитель 2e698731b1
Коммит 90ea6c6cf8
18 изменённых файлов: 122 добавлений и 36 удалений

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

@ -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 18153b9c799965b95cc411b2adbb93fefaed1cd2 (2017-06-19 19:40:57 +1200)
The git commit ID used was bb189841de715214d88e1fa0093dc390bbf95ff4 (2017-07-12 09:27:20 +0300)

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

@ -106,7 +106,7 @@ TEST(cubeb, duplex)
output_params.channels = 2;
output_params.layout = CUBEB_LAYOUT_STEREO;
r = cubeb_get_min_latency(ctx, output_params, &latency_frames);
r = cubeb_get_min_latency(ctx, &output_params, &latency_frames);
ASSERT_EQ(r, CUBEB_OK) << "Could not get minimal latency";
r = cubeb_stream_init(ctx, &stream, "Cubeb duplex",

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

@ -39,7 +39,7 @@ TEST(cubeb, latency)
, CUBEB_STREAM_TYPE_MUSIC
#endif
};
r = cubeb_get_min_latency(ctx, params, &latency_frames);
r = cubeb_get_min_latency(ctx, &params, &latency_frames);
ASSERT_TRUE(r == CUBEB_OK || r == CUBEB_ERROR_NOT_SUPPORTED);
if (r == CUBEB_OK) {
ASSERT_GT(latency_frames, 0u);

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

@ -69,7 +69,7 @@ TEST(cubeb, overload_callback)
output_params.channels = 2;
output_params.layout = CUBEB_LAYOUT_STEREO;
r = cubeb_get_min_latency(ctx, output_params, &latency_frames);
r = cubeb_get_min_latency(ctx, &output_params, &latency_frames);
ASSERT_EQ(r, CUBEB_OK);
r = cubeb_stream_init(ctx, &stream, "Cubeb",

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

@ -128,7 +128,7 @@ TEST(cubeb, context_variables)
#if defined(__ANDROID__)
params.stream_type = CUBEB_STREAM_TYPE_MUSIC;
#endif
r = cubeb_get_min_latency(ctx, params, &value);
r = cubeb_get_min_latency(ctx, &params, &value);
ASSERT_TRUE(r == CUBEB_OK || r == CUBEB_ERROR_NOT_SUPPORTED);
if (r == CUBEB_OK) {
ASSERT_TRUE(value > 0);
@ -244,6 +244,42 @@ TEST(cubeb, configure_stream)
cubeb_destroy(ctx);
}
TEST(cubeb, configure_stream_undefined_layout)
{
int r;
cubeb * ctx;
cubeb_stream * stream;
cubeb_stream_params params;
r = common_init(&ctx, "test_sanity");
ASSERT_EQ(r, CUBEB_OK);
ASSERT_NE(ctx, nullptr);
params.format = STREAM_FORMAT;
params.rate = STREAM_RATE;
params.channels = 2; // panning
params.layout = CUBEB_LAYOUT_UNDEFINED;
#if defined(__ANDROID__)
params.stream_type = CUBEB_STREAM_TYPE_MUSIC;
#endif
r = cubeb_stream_init(ctx, &stream, "test", NULL, NULL, NULL, &params, STREAM_LATENCY,
test_data_callback, test_state_callback, &dummy);
ASSERT_EQ(r, CUBEB_OK);
ASSERT_NE(stream, nullptr);
r = cubeb_stream_start(stream);
ASSERT_EQ(r, CUBEB_OK);
delay(100);
r = cubeb_stream_stop(stream);
ASSERT_EQ(r, CUBEB_OK);
cubeb_stream_destroy(stream);
cubeb_destroy(ctx);
}
static void
test_init_start_stop_destroy_multiple_streams(int early, int delay_ms)
{

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

@ -33,11 +33,11 @@ extern "C" {
cubeb * app_ctx;
cubeb_init(&app_ctx, "Example Application");
int rv;
int rate;
int latency_frames;
uint32_t rate;
uint32_t latency_frames;
uint64_t ts;
rv = cubeb_get_min_latency(app_ctx, output_params, &latency_frames);
rv = cubeb_get_min_latency(app_ctx, &output_params, &latency_frames);
if (rv != CUBEB_OK) {
fprintf(stderr, "Could not get minimum latency");
return rv;
@ -239,8 +239,8 @@ typedef enum {
typedef struct {
cubeb_sample_format format; /**< Requested sample format. One of
#cubeb_sample_format. */
unsigned int rate; /**< Requested sample rate. Valid range is [1000, 192000]. */
unsigned int channels; /**< Requested channel count. Valid range is [1, 8]. */
uint32_t rate; /**< Requested sample rate. Valid range is [1000, 192000]. */
uint32_t channels; /**< Requested channel count. Valid range is [1, 8]. */
cubeb_channel_layout layout; /**< Requested channel layout. This must be consistent with the provided channels. */
#if defined(__ANDROID__)
cubeb_stream_type stream_type; /**< Used to map Android audio stream types */
@ -348,13 +348,13 @@ typedef struct {
cubeb_device_fmt format; /**< Sample format supported. */
cubeb_device_fmt default_format; /**< The default sample format for this device. */
unsigned int max_channels; /**< Channels. */
unsigned int default_rate; /**< Default/Preferred sample rate. */
unsigned int max_rate; /**< Maximum sample rate supported. */
unsigned int min_rate; /**< Minimum sample rate supported. */
uint32_t max_channels; /**< Channels. */
uint32_t default_rate; /**< Default/Preferred sample rate. */
uint32_t max_rate; /**< Maximum sample rate supported. */
uint32_t min_rate; /**< Minimum sample rate supported. */
unsigned int latency_lo; /**< Lowest possible latency in frames. */
unsigned int latency_hi; /**< Higest possible latency in frames. */
uint32_t latency_lo; /**< Lowest possible latency in frames. */
uint32_t latency_hi; /**< Higest possible latency in frames. */
} cubeb_device_info;
/** Device collection.
@ -455,7 +455,7 @@ CUBEB_EXPORT int cubeb_get_max_channel_count(cubeb * context, uint32_t * max_cha
@retval CUBEB_ERROR_INVALID_PARAMETER
@retval CUBEB_ERROR_NOT_SUPPORTED */
CUBEB_EXPORT int cubeb_get_min_latency(cubeb * context,
cubeb_stream_params params,
cubeb_stream_params * params,
uint32_t * latency_frames);
/** Get the preferred sample rate for this backend: this is hardware and
@ -512,7 +512,7 @@ CUBEB_EXPORT int cubeb_stream_init(cubeb * context,
cubeb_stream_params * input_stream_params,
cubeb_devid output_device,
cubeb_stream_params * output_stream_params,
unsigned int latency_frames,
uint32_t latency_frames,
cubeb_data_callback data_callback,
cubeb_state_callback state_callback,
void * user_ptr);
@ -534,6 +534,14 @@ CUBEB_EXPORT int cubeb_stream_start(cubeb_stream * stream);
@retval CUBEB_ERROR */
CUBEB_EXPORT int cubeb_stream_stop(cubeb_stream * stream);
/** Reset stream to the default device.
@param stream
@retval CUBEB_OK
@retval CUBEB_ERROR_INVALID_PARAMETER
@retval CUBEB_ERROR_NOT_SUPPORTED
@retval CUBEB_ERROR */
CUBEB_EXPORT int cubeb_stream_reset_default_device(cubeb_stream * stream);
/** Get the current stream playback position.
@param stream
@param position Playback position in frames.

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

@ -69,6 +69,7 @@ struct cubeb_ops {
void (* stream_destroy)(cubeb_stream * stream);
int (* stream_start)(cubeb_stream * stream);
int (* stream_stop)(cubeb_stream * stream);
int (* stream_reset_default_device)(cubeb_stream * stream);
int (* stream_get_position)(cubeb_stream * stream, uint64_t * position);
int (* stream_get_latency)(cubeb_stream * stream, uint32_t * latency);
int (* stream_set_volume)(cubeb_stream * stream, float volumes);

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

@ -248,9 +248,9 @@ cubeb_get_max_channel_count(cubeb * context, uint32_t * max_channels)
}
int
cubeb_get_min_latency(cubeb * context, cubeb_stream_params params, uint32_t * latency_ms)
cubeb_get_min_latency(cubeb * context, cubeb_stream_params * params, uint32_t * latency_ms)
{
if (!context || !latency_ms) {
if (!context || !params || !latency_ms) {
return CUBEB_ERROR_INVALID_PARAMETER;
}
@ -258,7 +258,7 @@ cubeb_get_min_latency(cubeb * context, cubeb_stream_params params, uint32_t * la
return CUBEB_ERROR_NOT_SUPPORTED;
}
return context->ops->get_min_latency(context, params, latency_ms);
return context->ops->get_min_latency(context, *params, latency_ms);
}
int
@ -371,6 +371,20 @@ cubeb_stream_stop(cubeb_stream * stream)
return stream->context->ops->stream_stop(stream);
}
int
cubeb_stream_reset_default_device(cubeb_stream * stream)
{
if (!stream) {
return CUBEB_ERROR_INVALID_PARAMETER;
}
if (!stream->context->ops->stream_reset_default_device) {
return CUBEB_ERROR_NOT_SUPPORTED;
}
return stream->context->ops->stream_reset_default_device(stream);
}
int
cubeb_stream_get_position(cubeb_stream * stream, uint64_t * position)
{

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

@ -1361,6 +1361,7 @@ static struct cubeb_ops const alsa_ops = {
.stream_destroy = alsa_stream_destroy,
.stream_start = alsa_stream_start,
.stream_stop = alsa_stream_stop,
.stream_reset_default_device = NULL,
.stream_get_position = alsa_stream_get_position,
.stream_get_latency = alsa_stream_get_latency,
.stream_set_volume = alsa_stream_set_volume,

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

@ -429,6 +429,7 @@ static struct cubeb_ops const audiotrack_ops = {
.stream_destroy = audiotrack_stream_destroy,
.stream_start = audiotrack_stream_start,
.stream_stop = audiotrack_stream_stop,
.stream_reset_default_device = NULL,
.stream_get_position = audiotrack_stream_get_position,
.stream_get_latency = audiotrack_stream_get_latency,
.stream_set_volume = audiotrack_stream_set_volume,

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

@ -525,8 +525,10 @@ audiounit_output_callback(void * user_ptr,
}
/* Mixing */
unsigned long output_buffer_length = outBufferList->mBuffers[0].mDataByteSize;
audiounit_mix_output_buffer(stm, output_frames, output_buffer, output_buffer_length);
if (stm->output_stream_params.layout != CUBEB_LAYOUT_UNDEFINED) {
unsigned long output_buffer_length = outBufferList->mBuffers[0].mDataByteSize;
audiounit_mix_output_buffer(stm, output_frames, output_buffer, output_buffer_length);
}
return noErr;
}
@ -2254,9 +2256,10 @@ audiounit_configure_output(cubeb_stream * stm)
return CUBEB_ERROR;
}
audiounit_layout_init(stm, OUTPUT);
audiounit_init_mixer(stm);
if (stm->output_stream_params.layout != CUBEB_LAYOUT_UNDEFINED) {
audiounit_layout_init(stm, OUTPUT);
audiounit_init_mixer(stm);
}
LOG("(%p) Output audiounit init successfully.", stm);
return CUBEB_OK;
}
@ -3337,6 +3340,7 @@ cubeb_ops const audiounit_ops = {
/*.stream_destroy =*/ audiounit_stream_destroy,
/*.stream_start =*/ audiounit_stream_start,
/*.stream_stop =*/ audiounit_stream_stop,
/*.stream_reset_default_device =*/ nullptr,
/*.stream_get_position =*/ audiounit_stream_get_position,
/*.stream_get_latency =*/ audiounit_stream_get_latency,
/*.stream_set_volume =*/ audiounit_stream_set_volume,

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

@ -123,6 +123,7 @@ static struct cubeb_ops const cbjack_ops = {
.stream_destroy = cbjack_stream_destroy,
.stream_start = cbjack_stream_start,
.stream_stop = cbjack_stream_stop,
.stream_reset_default_device = NULL,
.stream_get_position = cbjack_stream_get_position,
.stream_get_latency = cbjack_get_latency,
.stream_set_volume = cbjack_stream_set_volume,

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

@ -299,7 +299,7 @@ mix_remap(long inframes,
T * out, unsigned long out_len,
cubeb_channel_layout in_layout, cubeb_channel_layout out_layout)
{
assert(in_layout != out_layout);
assert(in_layout != out_layout && inframes >= 0);
// We might overwrite the data before we copied them to the mapped index
// (e.g. upmixing from stereo to 2F1 or mapping [L, R] to [R, L])
@ -325,15 +325,16 @@ mix_remap(long inframes,
return false;
}
for (long i = 0, out_index = 0; i < inframes * in_channels; i += in_channels, out_index += out_channels) {
for (unsigned long i = 0, out_index = 0; i < (unsigned long)inframes * in_channels; i += in_channels, out_index += out_channels) {
for (unsigned int j = 0; j < out_channels; ++j) {
cubeb_channel channel = CHANNEL_INDEX_TO_ORDER[out_layout][j];
uint32_t channel_mask = 1 << channel;
int channel_index = CHANNEL_ORDER_TO_INDEX[in_layout][channel];
assert((unsigned long)out_index + j < out_len);
assert(channel_index >= -1);
assert(out_index + j < out_len);
if (in_layout_mask & channel_mask) {
assert((unsigned long)i + channel_index < in_len);
assert(channel_index != -1);
assert(i + channel_index < in_len);
out[out_index + j] = in[i + channel_index];
} else {
assert(channel_index == -1);
@ -353,15 +354,15 @@ downmix_fallback(long inframes,
T * out, unsigned long out_len,
unsigned int in_channels, unsigned int out_channels)
{
assert(in_channels >= out_channels);
assert(in_channels >= out_channels && inframes >= 0);
if (in_channels == out_channels && in == out) {
return;
}
for (long i = 0, out_index = 0; i < inframes * in_channels; i += in_channels, out_index += out_channels) {
for (unsigned long i = 0, out_index = 0; i < (unsigned long)inframes * in_channels; i += in_channels, out_index += out_channels) {
for (unsigned int j = 0; j < out_channels; ++j) {
assert((unsigned long)i + j < in_len && (unsigned long)out_index + j < out_len);
assert(i + j < in_len && out_index + j < out_len);
out[out_index + j] = in[i + j];
}
}
@ -490,7 +491,8 @@ cubeb_should_downmix(cubeb_stream_params const * stream, cubeb_stream_params con
bool
cubeb_should_mix(cubeb_stream_params const * stream, cubeb_stream_params const * mixer)
{
return cubeb_should_upmix(stream, mixer) || cubeb_should_downmix(stream, mixer);
return stream->layout != CUBEB_LAYOUT_UNDEFINED &&
(cubeb_should_upmix(stream, mixer) || cubeb_should_downmix(stream, mixer));
}
struct cubeb_mixer {

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

@ -1746,6 +1746,7 @@ static struct cubeb_ops const opensl_ops = {
.stream_destroy = opensl_stream_destroy,
.stream_start = opensl_stream_start,
.stream_stop = opensl_stream_stop,
.stream_reset_default_device = NULL,
.stream_get_position = opensl_stream_get_position,
.stream_get_latency = opensl_stream_get_latency,
.stream_set_volume = opensl_stream_set_volume,

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

@ -751,8 +751,9 @@ create_pa_stream(cubeb_stream * stm,
{
assert(stm && stream_params);
assert(&stm->input_stream == pa_stm || (&stm->output_stream == pa_stm &&
(stream_params->layout == CUBEB_LAYOUT_UNDEFINED ||
stream_params->layout != CUBEB_LAYOUT_UNDEFINED &&
CUBEB_CHANNEL_LAYOUT_MAPS[stream_params->layout].channels == stream_params->channels));
CUBEB_CHANNEL_LAYOUT_MAPS[stream_params->layout].channels == stream_params->channels)));
*pa_stm = NULL;
pa_sample_spec ss;
ss.format = to_pulse_format(stream_params->format);
@ -1498,6 +1499,7 @@ static struct cubeb_ops const pulse_ops = {
.stream_destroy = pulse_stream_destroy,
.stream_start = pulse_stream_start,
.stream_stop = pulse_stream_stop,
.stream_reset_default_device = NULL,
.stream_get_position = pulse_stream_get_position,
.stream_get_latency = pulse_stream_get_latency,
.stream_set_volume = pulse_stream_set_volume,

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

@ -376,6 +376,7 @@ static struct cubeb_ops const sndio_ops = {
.stream_destroy = sndio_stream_destroy,
.stream_start = sndio_stream_start,
.stream_stop = sndio_stream_stop,
.stream_reset_default_device = NULL,
.stream_get_position = sndio_stream_get_position,
.stream_get_latency = sndio_stream_get_latency,
.stream_set_volume = sndio_stream_set_volume,

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

@ -1763,7 +1763,8 @@ wasapi_stream_init(cubeb * context, cubeb_stream ** stream,
stm->output_stream_params = *output_stream_params;
stm->output_device = utf8_to_wstr(reinterpret_cast<char const *>(output_device));
// Make sure the layout matches the channel count.
XASSERT(stm->output_stream_params.channels == CUBEB_CHANNEL_LAYOUT_MAPS[stm->output_stream_params.layout].channels);
XASSERT(stm->output_stream_params.layout == CUBEB_LAYOUT_UNDEFINED ||
stm->output_stream_params.channels == CUBEB_CHANNEL_LAYOUT_MAPS[stm->output_stream_params.layout].channels);
}
switch (output_stream_params ? output_stream_params->format : input_stream_params->format) {
@ -2007,6 +2008,17 @@ int wasapi_stream_stop(cubeb_stream * stm)
return CUBEB_OK;
}
int wasapi_stream_reset_default_device(cubeb_stream * stm)
{
XASSERT(stm && stm->reconfigure_event);
BOOL ok = SetEvent(stm->reconfigure_event);
if (!ok) {
LOG("SetEvent on reconfigure_event failed: %lx", GetLastError());
return CUBEB_ERROR;
}
return CUBEB_OK;
}
int wasapi_stream_get_position(cubeb_stream * stm, uint64_t * position)
{
XASSERT(stm && position);
@ -2331,6 +2343,7 @@ cubeb_ops const wasapi_ops = {
/*.stream_destroy =*/ wasapi_stream_destroy,
/*.stream_start =*/ wasapi_stream_start,
/*.stream_stop =*/ wasapi_stream_stop,
/*.stream_reset_default_device =*/ wasapi_stream_reset_default_device,
/*.stream_get_position =*/ wasapi_stream_get_position,
/*.stream_get_latency =*/ wasapi_stream_get_latency,
/*.stream_set_volume =*/ wasapi_stream_set_volume,

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

@ -1031,6 +1031,7 @@ static struct cubeb_ops const winmm_ops = {
/*.stream_destroy =*/ winmm_stream_destroy,
/*.stream_start =*/ winmm_stream_start,
/*.stream_stop =*/ winmm_stream_stop,
/*.stream_reset_default_device =*/ NULL,
/*.stream_get_position =*/ winmm_stream_get_position,
/*.stream_get_latency = */ winmm_stream_get_latency,
/*.stream_set_volume =*/ winmm_stream_set_volume,