diff --git a/media/libcubeb/README_MOZILLA b/media/libcubeb/README_MOZILLA index 3c8330da59ae..1caf03479071 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 bb0437c060a85a4f1f11b962a53ca0af02801967. +The git commit ID used was e8df12d770c6299640540e91cec13dc81efc9bbe. diff --git a/media/libcubeb/tests/common.h b/media/libcubeb/tests/common.h deleted file mode 100644 index 47cc28cc7f45..000000000000 --- a/media/libcubeb/tests/common.h +++ /dev/null @@ -1,30 +0,0 @@ -/* - * Copyright © 2013 Sebastien Alaiwan - * - * This program is made available under an ISC-style license. See the - * accompanying file LICENSE for details. - */ - -#if defined( _WIN32) -#ifndef WIN32_LEAN_AND_MEAN -#define WIN32_LEAN_AND_MEAN -#endif -#include -#else -#include -#endif - -void delay(unsigned int ms) -{ -#if defined(_WIN32) - Sleep(ms); -#else - sleep(ms / 1000); - usleep(ms % 1000 * 1000); -#endif -} - -#if !defined(M_PI) -#define M_PI 3.14159265358979323846 -#endif - diff --git a/media/libcubeb/tests/test_audio.cpp b/media/libcubeb/tests/test_audio.cpp deleted file mode 100644 index 5dfa468d18dc..000000000000 --- a/media/libcubeb/tests/test_audio.cpp +++ /dev/null @@ -1,174 +0,0 @@ -/* - * Copyright © 2013 Sebastien Alaiwan - * - * This program is made available under an ISC-style license. See the - * accompanying file LICENSE for details. - */ - -/* libcubeb api/function exhaustive test. Plays a series of tones in different - * conditions. */ -#ifdef NDEBUG -#undef NDEBUG -#endif -#define _XOPEN_SOURCE 500 -#include -#include -#include -#include - -#include "cubeb/cubeb.h" -#include "common.h" - -#define MAX_NUM_CHANNELS 32 - -#if !defined(M_PI) -#define M_PI 3.14159265358979323846 -#endif - -#define NELEMS(x) ((int) (sizeof(x) / sizeof(x[0]))) -#define VOLUME 0.2 - -float get_frequency(int channel_index) -{ - return 220.0f * (channel_index+1); -} - -/* store the phase of the generated waveform */ -typedef struct { - int num_channels; - float phase[MAX_NUM_CHANNELS]; - float sample_rate; -} synth_state; - -synth_state* synth_create(int num_channels, float sample_rate) -{ - synth_state* synth = (synth_state *) malloc(sizeof(synth_state)); - for(int i=0;i < MAX_NUM_CHANNELS;++i) - synth->phase[i] = 0.0f; - synth->num_channels = num_channels; - synth->sample_rate = sample_rate; - return synth; -} - -void synth_destroy(synth_state* synth) -{ - free(synth); -} - -void synth_run_float(synth_state* synth, float* audiobuffer, long nframes) -{ - for(int c=0;c < synth->num_channels;++c) { - float freq = get_frequency(c); - float phase_inc = 2.0 * M_PI * freq / synth->sample_rate; - for(long n=0;n < nframes;++n) { - audiobuffer[n*synth->num_channels+c] = sin(synth->phase[c]) * VOLUME; - synth->phase[c] += phase_inc; - } - } -} - -long data_cb_float(cubeb_stream *stream, void *user, void *buffer, long nframes) -{ - synth_state *synth = (synth_state *)user; - synth_run_float(synth, (float*)buffer, nframes); - return nframes; -} - -void synth_run_16bit(synth_state* synth, short* audiobuffer, long nframes) -{ - for(int c=0;c < synth->num_channels;++c) { - float freq = get_frequency(c); - float phase_inc = 2.0 * M_PI * freq / synth->sample_rate; - for(long n=0;n < nframes;++n) { - audiobuffer[n*synth->num_channels+c] = sin(synth->phase[c]) * VOLUME * 32767.0f; - synth->phase[c] += phase_inc; - } - } -} - -long data_cb_short(cubeb_stream *stream, void *user, void *buffer, long nframes) -{ - synth_state *synth = (synth_state *)user; - synth_run_16bit(synth, (short*)buffer, nframes); - return nframes; -} - -void state_cb(cubeb_stream *stream, void *user, cubeb_state state) -{ -} - -int run_test(int num_channels, int sampling_rate, int is_float) -{ - int ret = CUBEB_OK; - - cubeb *ctx = NULL; - synth_state* synth = NULL; - cubeb_stream *stream = NULL; - - ret = cubeb_init(&ctx, "Cubeb audio test"); - if (ret != CUBEB_OK) { - fprintf(stderr, "Error initializing cubeb library\n"); - goto cleanup; - } - - fprintf(stderr, "Testing %d channel(s), %d Hz, %s (%s)\n", num_channels, sampling_rate, is_float ? "float" : "short", cubeb_get_backend_id(ctx)); - - cubeb_stream_params params; - params.format = is_float ? CUBEB_SAMPLE_FLOAT32NE : CUBEB_SAMPLE_S16NE; - params.rate = sampling_rate; - params.channels = num_channels; - - synth = synth_create(params.channels, params.rate); - if (synth == NULL) { - fprintf(stderr, "Out of memory\n"); - goto cleanup; - } - - ret = cubeb_stream_init(ctx, &stream, "test tone", params, - 250, is_float ? data_cb_float : data_cb_short, state_cb, synth); - if (ret != CUBEB_OK) { - fprintf(stderr, "Error initializing cubeb stream: %d\n", ret); - goto cleanup; - } - - cubeb_stream_start(stream); - delay(200); - cubeb_stream_stop(stream); - -cleanup: - cubeb_stream_destroy(stream); - cubeb_destroy(ctx); - synth_destroy(synth); - - return ret; -} - -int main(int argc, char *argv[]) -{ - int channel_values[] = { - 1, - 2, - 4, - 5, - 6, - }; - - int freq_values[] = { - 24000, - 44100, - 48000, - }; - - for(int j=0;j < NELEMS(channel_values);++j) { - for(int i=0;i < NELEMS(freq_values);++i) { - assert(channel_values[j] < MAX_NUM_CHANNELS); - fprintf(stderr, "--------------------------\n"); - run_test(channel_values[j], freq_values[i], 0); - run_test(channel_values[j], freq_values[i], 1); - } - } - - return CUBEB_OK; -} - - diff --git a/media/libcubeb/tests/test_latency.cpp b/media/libcubeb/tests/test_latency.cpp deleted file mode 100644 index eb145f646400..000000000000 --- a/media/libcubeb/tests/test_latency.cpp +++ /dev/null @@ -1,39 +0,0 @@ -#ifdef NDEBUG -#undef NDEBUG -#endif -#include -#include -#include - -int main(int argc, char * argv[]) -{ - cubeb * ctx = NULL; - int rv; - uint32_t max_channels; - uint32_t preferred_rate; - uint32_t latency_ms; - - rv = cubeb_init(&ctx, "Cubeb audio test"); - assert(rv == CUBEB_OK && "Cubeb init failed."); - - rv = cubeb_get_max_channel_count(ctx, &max_channels); - assert(rv == CUBEB_OK && "Could not query the max channe count."); - assert(max_channels > 0 && "Invalid max channel count."); - - rv = cubeb_get_preferred_sample_rate(ctx, &preferred_rate); - assert(rv == CUBEB_OK && "Could not query the preferred sample rate."); - assert(preferred_rate && "Invalid preferred sample rate."); - - cubeb_stream_params params = { - CUBEB_SAMPLE_FLOAT32NE, - preferred_rate, - max_channels - }; - rv = cubeb_get_min_latency(ctx, params, &latency_ms); - assert(rv == CUBEB_OK && "Could not query the minimal latency."); - assert(latency_ms && "Invalid minimal latency."); - - cubeb_destroy(ctx); - - return EXIT_SUCCESS; -} diff --git a/media/libcubeb/tests/test_sanity.cpp b/media/libcubeb/tests/test_sanity.cpp deleted file mode 100644 index ed83d37be0e6..000000000000 --- a/media/libcubeb/tests/test_sanity.cpp +++ /dev/null @@ -1,466 +0,0 @@ -/* - * Copyright © 2011 Mozilla Foundation - * - * This program is made available under an ISC-style license. See the - * accompanying file LICENSE for details. - */ -#ifdef NDEBUG -#undef NDEBUG -#endif -#define _XOPEN_SOURCE 500 -#include "cubeb/cubeb.h" -#include -#include -#include -#include -#include "common.h" - -#define STREAM_LATENCY 100 -#define STREAM_RATE 44100 -#define STREAM_CHANNELS 1 -#define STREAM_FORMAT CUBEB_SAMPLE_S16LE - -static int dummy; -static uint64_t total_frames_written; -static int delay_callback; - -static long -test_data_callback(cubeb_stream * stm, void * user_ptr, void * p, long nframes) -{ - assert(stm && user_ptr == &dummy && p && nframes > 0); - memset(p, 0, nframes * sizeof(short)); - total_frames_written += nframes; - if (delay_callback) { - delay(10); - } - return nframes; -} - -void -test_state_callback(cubeb_stream * stm, void * user_ptr, cubeb_state state) -{ -} - -static void -test_init_destroy_context(void) -{ - int r; - cubeb * ctx; - - r = cubeb_init(&ctx, "test_sanity"); - assert(r == 0 && ctx); - - cubeb_destroy(ctx); -} - -static void -test_init_destroy_multiple_contexts(void) -{ - int i; - int r; - cubeb * ctx[4]; - - for (i = 0; i < 4; ++i) { - r = cubeb_init(&ctx[i], NULL); - assert(r == 0 && ctx[i]); - } - - /* destroy in a different order */ - cubeb_destroy(ctx[2]); - cubeb_destroy(ctx[0]); - cubeb_destroy(ctx[3]); - cubeb_destroy(ctx[1]); -} - -static void -test_init_destroy_stream(void) -{ - int r; - cubeb * ctx; - cubeb_stream * stream; - cubeb_stream_params params; - - r = cubeb_init(&ctx, "test_sanity"); - assert(r == 0 && ctx); - - params.format = STREAM_FORMAT; - params.rate = STREAM_RATE; - params.channels = STREAM_CHANNELS; - - r = cubeb_stream_init(ctx, &stream, "test", params, STREAM_LATENCY, - test_data_callback, test_state_callback, &dummy); - assert(r == 0 && stream); - - cubeb_stream_destroy(stream); - cubeb_destroy(ctx); -} - -static void -test_init_destroy_multiple_streams(void) -{ - int i; - int r; - cubeb * ctx; - cubeb_stream * stream[16]; - cubeb_stream_params params; - - r = cubeb_init(&ctx, "test_sanity"); - assert(r == 0 && ctx); - - params.format = STREAM_FORMAT; - params.rate = STREAM_RATE; - params.channels = STREAM_CHANNELS; - - for (i = 0; i < 16; ++i) { - r = cubeb_stream_init(ctx, &stream[i], "test", params, STREAM_LATENCY, - test_data_callback, test_state_callback, &dummy); - assert(r == 0 && stream[i]); - } - - for (i = 0; i < 16; ++i) { - cubeb_stream_destroy(stream[i]); - } - - cubeb_destroy(ctx); -} - -static void -test_init_start_stop_destroy_multiple_streams(int early, int delay_ms) -{ - int i; - int r; - cubeb * ctx; - cubeb_stream * stream[16]; - cubeb_stream_params params; - - r = cubeb_init(&ctx, "test_sanity"); - assert(r == 0 && ctx); - - params.format = STREAM_FORMAT; - params.rate = STREAM_RATE; - params.channels = STREAM_CHANNELS; - - for (i = 0; i < 16; ++i) { - r = cubeb_stream_init(ctx, &stream[i], "test", params, STREAM_LATENCY, - test_data_callback, test_state_callback, &dummy); - assert(r == 0 && stream[i]); - if (early) { - r = cubeb_stream_start(stream[i]); - assert(r == 0); - } - } - - - if (!early) { - for (i = 0; i < 16; ++i) { - r = cubeb_stream_start(stream[i]); - assert(r == 0); - } - } - - if (delay_ms) { - delay(delay_ms); - } - - if (!early) { - for (i = 0; i < 16; ++i) { - r = cubeb_stream_stop(stream[i]); - assert(r == 0); - } - } - - for (i = 0; i < 16; ++i) { - if (early) { - r = cubeb_stream_stop(stream[i]); - assert(r == 0); - } - cubeb_stream_destroy(stream[i]); - } - - cubeb_destroy(ctx); -} - -static void -test_init_destroy_multiple_contexts_and_streams(void) -{ - int i, j; - int r; - cubeb * ctx[4]; - cubeb_stream * stream[16]; - cubeb_stream_params params; - - params.format = STREAM_FORMAT; - params.rate = STREAM_RATE; - params.channels = STREAM_CHANNELS; - - for (i = 0; i < 4; ++i) { - r = cubeb_init(&ctx[i], "test_sanity"); - assert(r == 0 && ctx[i]); - - for (j = 0; j < 4; ++j) { - r = cubeb_stream_init(ctx[i], &stream[i * 4 + j], "test", params, STREAM_LATENCY, - test_data_callback, test_state_callback, &dummy); - assert(r == 0 && stream[i * 4 + j]); - } - } - - for (i = 0; i < 4; ++i) { - for (j = 0; j < 4; ++j) { - cubeb_stream_destroy(stream[i * 4 + j]); - } - cubeb_destroy(ctx[i]); - } -} - -static void -test_basic_stream_operations(void) -{ - int r; - cubeb * ctx; - cubeb_stream * stream; - cubeb_stream_params params; - uint64_t position; - - r = cubeb_init(&ctx, "test_sanity"); - assert(r == 0 && ctx); - - params.format = STREAM_FORMAT; - params.rate = STREAM_RATE; - params.channels = STREAM_CHANNELS; - - r = cubeb_stream_init(ctx, &stream, "test", params, STREAM_LATENCY, - test_data_callback, test_state_callback, &dummy); - assert(r == 0 && stream); - - /* position and volume before stream has started */ - r = cubeb_stream_get_position(stream, &position); - assert(r == 0 && position == 0); - - r = cubeb_stream_start(stream); - assert(r == 0); - - /* position and volume after while stream running */ - r = cubeb_stream_get_position(stream, &position); - assert(r == 0); - - r = cubeb_stream_stop(stream); - assert(r == 0); - - /* position and volume after stream has stopped */ - r = cubeb_stream_get_position(stream, &position); - assert(r == 0); - - cubeb_stream_destroy(stream); - cubeb_destroy(ctx); -} - -static void -test_stream_position(void) -{ - int i; - int r; - cubeb * ctx; - cubeb_stream * stream; - cubeb_stream_params params; - uint64_t position, last_position; - - total_frames_written = 0; - - r = cubeb_init(&ctx, "test_sanity"); - assert(r == 0 && ctx); - - params.format = STREAM_FORMAT; - params.rate = STREAM_RATE; - params.channels = STREAM_CHANNELS; - - r = cubeb_stream_init(ctx, &stream, "test", params, STREAM_LATENCY, - test_data_callback, test_state_callback, &dummy); - assert(r == 0 && stream); - - /* stream position should not advance before starting playback */ - r = cubeb_stream_get_position(stream, &position); - assert(r == 0 && position == 0); - - delay(500); - - r = cubeb_stream_get_position(stream, &position); - assert(r == 0 && position == 0); - - /* stream position should advance during playback */ - r = cubeb_stream_start(stream); - assert(r == 0); - - /* XXX let start happen */ - delay(500); - - /* stream should have prefilled */ - assert(total_frames_written > 0); - - r = cubeb_stream_get_position(stream, &position); - assert(r == 0); - last_position = position; - - delay(500); - - r = cubeb_stream_get_position(stream, &position); - assert(r == 0); - assert(position >= last_position); - last_position = position; - - /* stream position should not exceed total frames written */ - for (i = 0; i < 5; ++i) { - r = cubeb_stream_get_position(stream, &position); - assert(r == 0); - assert(position >= last_position); - assert(position <= total_frames_written); - last_position = position; - delay(500); - } - - assert(last_position != 0); - - /* stream position should not advance after stopping playback */ - r = cubeb_stream_stop(stream); - assert(r == 0); - - /* XXX allow stream to settle */ - delay(500); - - r = cubeb_stream_get_position(stream, &position); - assert(r == 0); - last_position = position; - - delay(500); - - r = cubeb_stream_get_position(stream, &position); - assert(r == 0); - assert(position == last_position); - - cubeb_stream_destroy(stream); - cubeb_destroy(ctx); -} - -static int do_drain; -static int got_drain; - -static long -test_drain_data_callback(cubeb_stream * stm, void * user_ptr, void * p, long nframes) -{ - assert(stm && user_ptr == &dummy && p && nframes > 0); - if (do_drain == 1) { - do_drain = 2; - return 0; - } - /* once drain has started, callback must never be called again */ - assert(do_drain != 2); - memset(p, 0, nframes * sizeof(short)); - total_frames_written += nframes; - return nframes; -} - -void -test_drain_state_callback(cubeb_stream * stm, void * user_ptr, cubeb_state state) -{ - if (state == CUBEB_STATE_DRAINED) { - assert(!got_drain); - got_drain = 1; - } -} - -static void -test_drain(void) -{ - int r; - cubeb * ctx; - cubeb_stream * stream; - cubeb_stream_params params; - uint64_t position; - - total_frames_written = 0; - - r = cubeb_init(&ctx, "test_sanity"); - assert(r == 0 && ctx); - - params.format = STREAM_FORMAT; - params.rate = STREAM_RATE; - params.channels = STREAM_CHANNELS; - - r = cubeb_stream_init(ctx, &stream, "test", params, STREAM_LATENCY, - test_drain_data_callback, test_drain_state_callback, &dummy); - assert(r == 0 && stream); - - r = cubeb_stream_start(stream); - assert(r == 0); - - delay(500); - - do_drain = 1; - - for (;;) { - r = cubeb_stream_get_position(stream, &position); - assert(r == 0); - if (got_drain) { - break; - } else { - // Latency passed to cubeb_stream_init is not really honored on OSX and - // winmm, skip this test. - const char * backend_id = cubeb_get_backend_id(ctx); - if (strcmp(backend_id, "audiounit") != 0 && - strcmp(backend_id, "winmm") != 0) { - /* Position should roughly be equal to the number of written frames. We - * need to take the latency into account. */ - int latency = (STREAM_LATENCY * STREAM_RATE) / 1000; - assert(position + latency <= total_frames_written); - } - } - delay(500); - } - - r = cubeb_stream_get_position(stream, &position); - assert(r == 0); - assert(got_drain); - - // Disabled due to failures in the ALSA backend. - //assert(position == total_frames_written); - - cubeb_stream_destroy(stream); - cubeb_destroy(ctx); -} - -static void -progress(void) -{ - printf("."); - fflush(stdout); -} - -int -main(int argc, char * argv[]) -{ - test_init_destroy_context(); progress(); - test_init_destroy_multiple_contexts(); progress(); - test_init_destroy_stream(); progress(); - test_init_destroy_multiple_streams(); progress(); - test_init_destroy_multiple_contexts_and_streams(); progress(); - test_basic_stream_operations(); progress(); - test_stream_position(); progress(); - delay_callback = 0; - test_init_start_stop_destroy_multiple_streams(0, 0); progress(); - test_init_start_stop_destroy_multiple_streams(1, 0); progress(); - test_init_start_stop_destroy_multiple_streams(0, 150); progress(); - test_init_start_stop_destroy_multiple_streams(1, 150); progress(); - delay_callback = 1; - test_init_start_stop_destroy_multiple_streams(0, 0); progress(); - test_init_start_stop_destroy_multiple_streams(1, 0); progress(); - test_init_start_stop_destroy_multiple_streams(0, 150); progress(); - test_init_start_stop_destroy_multiple_streams(1, 150); progress(); - delay_callback = 0; - test_drain(); -/* - to implement: - test_eos_during_prefill(); - test_stream_destroy_pending_drain(); -*/ - printf("\n"); - return 0; -} diff --git a/media/libcubeb/tests/test_tone.cpp b/media/libcubeb/tests/test_tone.cpp deleted file mode 100644 index c3e6cc75face..000000000000 --- a/media/libcubeb/tests/test_tone.cpp +++ /dev/null @@ -1,117 +0,0 @@ -/* - * Copyright © 2011 Mozilla Foundation - * - * This program is made available under an ISC-style license. See the - * accompanying file LICENSE for details. - */ - -/* libcubeb api/function test. Plays a simple tone. */ -#ifdef NDEBUG -#undef NDEBUG -#endif -#define _XOPEN_SOURCE 500 -#include -#include -#include -#include - -#include "cubeb/cubeb.h" -#include "common.h" - -#define SAMPLE_FREQUENCY 48000 - -/* store the phase of the generated waveform */ -struct cb_user_data { - long position; -}; - -long data_cb(cubeb_stream *stream, void *user, void *buffer, long nframes) -{ - struct cb_user_data *u = (struct cb_user_data *)user; - short *b = (short *)buffer; - int i; - - if (stream == NULL || u == NULL) - return CUBEB_ERROR; - - /* generate our test tone on the fly */ - for (i = 0; i < nframes; i++) { - /* North American dial tone */ - b[i] = 16000*sin(2*M_PI*(i + u->position)*350/SAMPLE_FREQUENCY); - b[i] += 16000*sin(2*M_PI*(i + u->position)*440/SAMPLE_FREQUENCY); - /* European dial tone */ - /*b[i] = 30000*sin(2*M_PI*(i + u->position)*425/SAMPLE_FREQUENCY);*/ - } - /* remember our phase to avoid clicking on buffer transitions */ - /* we'll still click if position overflows */ - u->position += nframes; - - return nframes; -} - -void state_cb(cubeb_stream *stream, void *user, cubeb_state state) -{ - struct cb_user_data *u = (struct cb_user_data *)user; - - if (stream == NULL || u == NULL) - return; - - switch (state) { - case CUBEB_STATE_STARTED: - printf("stream started\n"); break; - case CUBEB_STATE_STOPPED: - printf("stream stopped\n"); break; - case CUBEB_STATE_DRAINED: - printf("stream drained\n"); break; - default: - printf("unknown stream state %d\n", state); - } - - return; -} - -int main(int argc, char *argv[]) -{ - cubeb *ctx; - cubeb_stream *stream; - cubeb_stream_params params; - struct cb_user_data *user_data; - int ret; - - ret = cubeb_init(&ctx, "Cubeb tone example"); - if (ret != CUBEB_OK) { - fprintf(stderr, "Error initializing cubeb library\n"); - return ret; - } - - params.format = CUBEB_SAMPLE_S16NE; - params.rate = SAMPLE_FREQUENCY; - params.channels = 1; - - user_data = (struct cb_user_data *) malloc(sizeof(*user_data)); - if (user_data == NULL) { - fprintf(stderr, "Error allocating user data\n"); - return CUBEB_ERROR; - } - user_data->position = 0; - - ret = cubeb_stream_init(ctx, &stream, "Cubeb tone (mono)", params, - 250, data_cb, state_cb, user_data); - if (ret != CUBEB_OK) { - fprintf(stderr, "Error initializing cubeb stream\n"); - return ret; - } - - cubeb_stream_start(stream); - delay(500); - cubeb_stream_stop(stream); - - cubeb_stream_destroy(stream); - cubeb_destroy(ctx); - - assert(user_data->position); - - free(user_data); - - return CUBEB_OK; -}