Bug 1374275 - Update cubeb from upstream to 18153b9. r=kinetik

MozReview-Commit-ID: 4PKadUfp0Bc

--HG--
extra : rebase_source : 430224ccb31ba49c6c980529af3ba8385005f8be
This commit is contained in:
Alex Chronopoulos 2017-06-20 12:09:28 +03:00
Родитель 0ce89916ce
Коммит 1569d73eef
10 изменённых файлов: 64 добавлений и 38 удалений

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

@ -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 3428c2b08d2668a026469f2e71a6f6aa95614aeb (2017-05-31 16:26:45 +1200)
The git commit ID used was 18153b9c799965b95cc411b2adbb93fefaed1cd2 (2017-06-19 19:40:57 +1200)

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

@ -18,6 +18,7 @@
#include <cstdarg>
#include "cubeb/cubeb.h"
#include "cubeb_mixer.h"
template<typename T, size_t N>
constexpr size_t

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

@ -17,13 +17,14 @@
#include <memory>
#include "cubeb/cubeb.h"
#include "common.h"
#include <atomic>
#define SAMPLE_FREQUENCY 48000
#define STREAM_FORMAT CUBEB_SAMPLE_FLOAT32LE
struct user_state_duplex
{
bool seen_audio;
std::atomic<int> seen_audio{ 0 };
};
long data_cb_duplex(cubeb_stream * stream, void * user, const void * inputbuffer, void * outputbuffer, long nframes)
@ -31,7 +32,7 @@ long data_cb_duplex(cubeb_stream * stream, void * user, const void * inputbuffer
user_state_duplex * u = reinterpret_cast<user_state_duplex*>(user);
float *ib = (float *)inputbuffer;
float *ob = (float *)outputbuffer;
bool seen_audio = true;
bool seen_audio = 1;
if (stream == NULL || inputbuffer == NULL || outputbuffer == NULL) {
return CUBEB_ERROR;
@ -42,7 +43,7 @@ long data_cb_duplex(cubeb_stream * stream, void * user, const void * inputbuffer
long output_index = 0;
for (long i = 0; i < nframes; i++) {
if (ib[i] <= -1.0 && ib[i] >= 1.0) {
seen_audio = false;
seen_audio = 0;
break;
}
ob[output_index] = ob[output_index + 1] = ib[i];
@ -80,7 +81,7 @@ TEST(cubeb, duplex)
cubeb_stream_params input_params;
cubeb_stream_params output_params;
int r;
user_state_duplex stream_state = { false };
user_state_duplex stream_state;
uint32_t latency_frames = 0;
r = common_init(&ctx, "Cubeb duplex example");
@ -120,5 +121,5 @@ TEST(cubeb, duplex)
delay(500);
cubeb_stream_stop(stream);
ASSERT_TRUE(stream_state.seen_audio);
ASSERT_TRUE(stream_state.seen_audio.load());
}

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

@ -88,6 +88,20 @@ audio_input audio_inputs[CUBEB_LAYOUT_MAX] = {
{ CUBEB_LAYOUT_3F4_LFE, { L, R, C, LFE, RLS, RRS, LS, RS } }
};
char const * channel_names[CHANNEL_UNMAPPED + 1] = {
"mono", // CHANNEL_MONO
"left", // CHANNEL_LEFT
"right", // CHANNEL_RIGHT
"center", // CHANNEL_CENTER
"left surround", // CHANNEL_LS
"right surround", // CHANNEL_RS
"rear left surround", // CHANNEL_RLS
"rear center", // CHANNEL_RCENTER
"rear right surround", // CHANNEL_RRS
"low frequency effects", // CHANNEL_LFE
"unmapped" // CHANNEL_UNMAPPED
};
// The test cases must be aligned with cubeb_downmix.
void
downmix_test(float const * data, cubeb_channel_layout in_layout, cubeb_channel_layout out_layout)
@ -146,6 +160,7 @@ downmix_test(float const * data, cubeb_channel_layout in_layout, cubeb_channel_l
std::unique_ptr<cubeb_mixer, decltype(&cubeb_mixer_destroy)>
mixer(cubeb_mixer_create(in_params.format, CUBEB_MIXER_DIRECTION_DOWNMIX), cubeb_mixer_destroy);
assert(!in.empty() && !out.empty() && out.size() <= in.size());
cubeb_mixer_mix(mixer.get(), inframes, in.data(), in.size(), out.data(), out.size(), &in_params, &out_params);
uint32_t in_layout_mask = 0;
@ -158,33 +173,45 @@ downmix_test(float const * data, cubeb_channel_layout in_layout, cubeb_channel_l
out_layout_mask |= 1 << CHANNEL_INDEX_TO_ORDER[out_layout][i];
}
for (unsigned int i = 0 ; i < inframes * out_params.channels ; ++i) {
for (unsigned int i = 0 ; i < out.size() ; ++i) {
assert(in_params.channels && out_params.channels); // to pass the scan-build warning: Division by zero.
#if defined(__APPLE__)
// The size of audio mix buffer(vector out above) on OS X is same as input,
// so we need to check whether the out[i] will be dropped or not.
unsigned int index = i % in_params.channels;
if (index >= out_params.channels) {
// The out[i] will be dropped, so we don't care the data inside.
fprintf(stderr, "\tOS X: %d will be dropped. Ignore it.\n", i);
continue;
}
#else
unsigned int index = i % out_params.channels;
#endif
// downmix_3f2
if ((in_layout == CUBEB_LAYOUT_3F2 || in_layout == CUBEB_LAYOUT_3F2_LFE) &&
out_layout >= CUBEB_LAYOUT_MONO && out_layout <= CUBEB_LAYOUT_2F2_LFE) {
auto & downmix_results = DOWNMIX_3F2_RESULTS[in_layout - CUBEB_LAYOUT_3F2][out_layout - CUBEB_LAYOUT_MONO];
fprintf(stderr, "[3f2] Expect: %lf, Get: %lf\n", downmix_results[index], out[i]);
fprintf(stderr, "\t[3f2] %d(%s) - Expect: %lf, Get: %lf\n", i, channel_names[ CHANNEL_INDEX_TO_ORDER[out_layout][index] ], downmix_results[index], out[i]);
ASSERT_EQ(downmix_results[index], out[i]);
continue;
}
#if defined(__APPLE__)
// We only support downmix for audio 5.1 on OS X currently.
fprintf(stderr, "\tOS X: We only support downmix for audio 5.1 currently.\n");
return;
#endif
// mix_remap
if (out_layout_mask & in_layout_mask) {
uint32_t mask = 1 << CHANNEL_INDEX_TO_ORDER[out_layout][index];
fprintf(stderr, "[map channels] Expect: %lf, Get: %lf\n", (mask & in_layout_mask) ? audio_inputs[out_layout].data[index] : 0, out[i]);
fprintf(stderr, "\t[remap] %d(%s) - Expect: %lf, Get: %lf\n", i, channel_names[ CHANNEL_INDEX_TO_ORDER[out_layout][index] ], (mask & in_layout_mask) ? audio_inputs[out_layout].data[index] : 0, out[i]);
ASSERT_EQ((mask & in_layout_mask) ? audio_inputs[out_layout].data[index] : 0, out[i]);
continue;
}
// downmix_fallback
fprintf(stderr, "[fallback] Expect: %lf, Get: %lf\n", audio_inputs[in_layout].data[index], out[i]);
fprintf(stderr, "\t[fallback] %d - Expect: %lf, Get: %lf\n", i, audio_inputs[in_layout].data[index], out[i]);
ASSERT_EQ(audio_inputs[in_layout].data[index], out[i]);
}
}

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

@ -16,13 +16,14 @@
#include <memory>
#include "cubeb/cubeb.h"
#include "common.h"
#include <atomic>
#define SAMPLE_FREQUENCY 48000
#define STREAM_FORMAT CUBEB_SAMPLE_FLOAT32LE
struct user_state_record
{
bool seen_audio;
std::atomic<int> seen_audio{ 0 };
};
long data_cb_record(cubeb_stream * stream, void * user, const void * inputbuffer, void * outputbuffer, long nframes)
@ -34,10 +35,10 @@ long data_cb_record(cubeb_stream * stream, void * user, const void * inputbuffer
return CUBEB_ERROR;
}
bool seen_audio = true;
bool seen_audio = 1;
for (long i = 0; i < nframes; i++) {
if (b[i] <= -1.0 && b[i] >= 1.0) {
seen_audio = false;
seen_audio = 0;
break;
}
}
@ -75,7 +76,7 @@ TEST(cubeb, record)
cubeb_stream *stream;
cubeb_stream_params params;
int r;
user_state_record stream_state = { false };
user_state_record stream_state;
r = common_init(&ctx, "Cubeb record example");
ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb library";
@ -109,6 +110,6 @@ TEST(cubeb, record)
// user callback does not arrive in Linux, silence the error
fprintf(stderr, "Check is disabled in Linux\n");
#else
ASSERT_TRUE(stream_state.seen_audio);
ASSERT_TRUE(stream_state.seen_audio.load());
#endif
}

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

@ -17,13 +17,14 @@
#include <limits.h>
#include "cubeb/cubeb.h"
#include "common.h"
#include <atomic>
#define SAMPLE_FREQUENCY 48000
#define STREAM_FORMAT CUBEB_SAMPLE_S16LE
/* store the phase of the generated waveform */
struct cb_user_data {
long position;
std::atomic<long> position;
};
long data_cb_tone(cubeb_stream *stream, void *user, const void* /*inputbuffer*/, void *outputbuffer, long nframes)
@ -111,5 +112,5 @@ TEST(cubeb, tone)
delay(500);
cubeb_stream_stop(stream);
ASSERT_TRUE(user_data->position);
ASSERT_TRUE(user_data->position.load());
}

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

@ -405,7 +405,7 @@ typedef void (* cubeb_device_changed_callback)(void * user_ptr);
/**
* User supplied callback called when the underlying device collection changed.
* @param context A pointer to the cubeb context.
* @param user_ptr The pointer passed to cubeb_stream_init. */
* @param user_ptr The pointer passed to cubeb_register_device_collection_changed. */
typedef void (* cubeb_device_collection_changed_callback)(cubeb * context,
void * user_ptr);

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

@ -79,7 +79,7 @@ struct cubeb {
// The queue is asynchronously deallocated once all references to it are released
dispatch_queue_t serial_queue = dispatch_queue_create(DISPATCH_QUEUE_LABEL, DISPATCH_QUEUE_SERIAL);
// Current used channel layout
cubeb_channel_layout layout;
std::atomic<cubeb_channel_layout> layout{ CUBEB_LAYOUT_UNDEFINED };
};
static std::unique_ptr<AudioChannelLayout, decltype(&free)>
@ -613,6 +613,7 @@ static int
audiounit_reinit_stream(cubeb_stream * stm)
{
auto_lock context_lock(stm->context->mutex);
assert(stm->input_unit || stm->output_unit);
if (!stm->shutdown) {
audiounit_stream_stop_internal(stm);
}
@ -626,7 +627,7 @@ audiounit_reinit_stream(cubeb_stream * stm)
auto_lock lock(stm->mutex);
float volume = 0.0;
int vol_rv = CUBEB_ERROR;
if (has_output(stm)) {
if (stm->output_unit) {
vol_rv = audiounit_stream_get_volume(stm, &volume);
}

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

@ -325,14 +325,14 @@ mix_remap(long inframes,
return false;
}
for (unsigned long i = 0, out_index = 0; i < inframes * in_channels; i += in_channels, out_index += out_channels) {
for (long i = 0, out_index = 0; i < 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(out_index + j < out_len);
assert((unsigned long)out_index + j < out_len);
if (in_layout_mask & channel_mask) {
assert(i + channel_index < in_len);
assert((unsigned long)i + channel_index < in_len);
assert(channel_index != -1);
out[out_index + j] = in[i + channel_index];
} else {
@ -359,9 +359,9 @@ downmix_fallback(long inframes,
return;
}
for (unsigned long i = 0, out_index = 0; i < inframes * in_channels; i += in_channels, out_index += out_channels) {
for (long i = 0, out_index = 0; i < inframes * in_channels; i += in_channels, out_index += out_channels) {
for (unsigned int j = 0; j < out_channels; ++j) {
assert(i + j < in_len && out_index + j < out_len);
assert((unsigned long)i + j < in_len && (unsigned long)out_index + j < out_len);
out[out_index + j] = in[i + j];
}
}
@ -416,7 +416,7 @@ mono_to_stereo(long insamples, T const * in, unsigned long in_len,
T * out, unsigned long out_len, unsigned int out_channels)
{
for (long i = 0, j = 0; i < insamples; ++i, j += out_channels) {
assert(i < in_len && j + 1 < out_len);
assert((unsigned long)i < in_len && (unsigned long)j + 1 < out_len);
out[j] = out[j + 1] = in[i];
}
}
@ -460,7 +460,7 @@ cubeb_upmix(long inframes,
/* Put silence in remaining channels. */
for (long i = 0, o = 0; i < inframes; ++i, o += out_channels) {
for (unsigned int j = 2; j < out_channels; ++j) {
assert(o + j < out_len);
assert((unsigned long)o + j < out_len);
out[o + j] = 0.0;
}
}

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

@ -483,27 +483,21 @@ get_rate(cubeb_stream * stm)
}
uint32_t
hns_to_ms(REFERENCE_TIME hns)
hns_to_frames(uint32_t rate, REFERENCE_TIME hns)
{
return static_cast<uint32_t>(hns / 10000);
return std::ceil(hns / 10000000.0 * rate);
}
uint32_t
hns_to_frames(cubeb_stream * stm, REFERENCE_TIME hns)
{
return hns_to_ms(hns * get_rate(stm)) / 1000;
}
uint32_t
hns_to_frames(uint32_t rate, REFERENCE_TIME hns)
{
return hns_to_ms(hns * rate) / 1000;
return hns_to_frames(get_rate(stm), hns);
}
REFERENCE_TIME
frames_to_hns(cubeb_stream * stm, uint32_t frames)
{
return frames * 1000 / get_rate(stm);
return std::ceil(frames * 10000000.0 / get_rate(stm));
}
/* This returns the size of a frame in the stream, before the eventual upmix