Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1314514 - Update libcubeb to 8bab182c. r=padenot
Browse files Browse the repository at this point in the history
  • Loading branch information
kinetiknz committed Nov 11, 2016
1 parent 676eec0 commit 3e54f90
Show file tree
Hide file tree
Showing 26 changed files with 603 additions and 634 deletions.
2 changes: 1 addition & 1 deletion media/libcubeb/README_MOZILLA
Original file line number Diff line number Diff line change
Expand Up @@ -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 f8467510a8b36793b1b8b7e85461e2e189eb7015.
The git commit ID used was 8bab182cd70ff66dec5bbecb69a69422f5d57647.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
* This program is made available under an ISC-style license. See the
* accompanying file LICENSE for details.
*/
#if !defined(TEST_COMMON)
#define TEST_COMMON

#if defined( _WIN32)
#ifndef WIN32_LEAN_AND_MEAN
Expand Down Expand Up @@ -59,3 +61,4 @@ int has_available_input_device(cubeb * ctx)
return 1;
}

#endif /* TEST_COMMON */
32 changes: 16 additions & 16 deletions media/libcubeb/tests/moz.build → media/libcubeb/gtest/moz.build
Original file line number Diff line number Diff line change
Expand Up @@ -4,26 +4,24 @@
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.

DEFINES['CUBEB_GECKO_BUILD'] = True

GeckoCppUnitTests([
'test_duplex',
'test_record',
'test_tone',
'test_utils'
])
UNIFIED_SOURCES += [
# 'test_duplex.cpp', # DISABLED: See bug 1314514.
# 'test_record.cpp', # DISABLED: See bug 1314514.
'test_tone.cpp',
'test_utils.cpp'
]

if CONFIG['MOZ_PULSEAUDIO'] or CONFIG['OS_TARGET'] in ('Darwin', 'WINNT', 'Android'):
GeckoCppUnitTests([
'test_resampler',
])
UNIFIED_SOURCES += [
'test_resampler.cpp',
]

if CONFIG['OS_TARGET'] != 'Android':
GeckoCppUnitTests([
'test_audio',
'test_latency',
'test_sanity'
])
UNIFIED_SOURCES += [
'test_audio.cpp',
'test_latency.cpp',
'test_sanity.cpp'
]

LOCAL_INCLUDES += [
'../include',
Expand Down Expand Up @@ -78,3 +76,5 @@ else:

if CONFIG['GNU_CXX']:
CXXFLAGS += ['-Wno-error=shadow']

FINAL_LIBRARY = 'xul-gtest'
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,16 @@

/* libcubeb api/function exhaustive test. Plays a series of tones in different
* conditions. */
#ifdef NDEBUG
#undef NDEBUG
#endif
#include "gtest/gtest.h"
#if !defined(_XOPEN_SOURCE)
#define _XOPEN_SOURCE 600
#endif
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>
#include <string.h>

#include "cubeb/cubeb.h"
#include "common.h"
#ifdef CUBEB_GECKO_BUILD
#include "TestHarness.h"
#endif

#define MAX_NUM_CHANNELS 32

Expand Down Expand Up @@ -99,7 +94,7 @@ long data_cb_short(cubeb_stream * /*stream*/, void * user, const void * /*inputb
return nframes;
}

void state_cb(cubeb_stream * /*stream*/, void * /*user*/, cubeb_state /*state*/)
void state_cb_audio(cubeb_stream * /*stream*/, void * /*user*/, cubeb_state /*state*/)
{
}

Expand Down Expand Up @@ -161,7 +156,7 @@ int run_test(int num_channels, int sampling_rate, int is_float)
}

r = cubeb_stream_init(ctx, &stream, "test tone", NULL, NULL, NULL, &params,
4096, is_float ? data_cb_float : data_cb_short, state_cb, synth);
4096, is_float ? data_cb_float : data_cb_short, state_cb_audio, synth);
if (r != CUBEB_OK) {
fprintf(stderr, "Error initializing cubeb stream: %d\n", r);
goto cleanup;
Expand Down Expand Up @@ -214,7 +209,7 @@ int run_panning_volume_test(int is_float)

r = cubeb_stream_init(ctx, &stream, "test tone", NULL, NULL, NULL, &params,
4096, is_float ? data_cb_float : data_cb_short,
state_cb, synth);
state_cb_audio, synth);
if (r != CUBEB_OK) {
fprintf(stderr, "Error initializing cubeb stream: %d\n", r);
goto cleanup;
Expand Down Expand Up @@ -252,7 +247,17 @@ int run_panning_volume_test(int is_float)
return r;
}

void run_channel_rate_test()
TEST(cubeb, run_panning_volume_test_short)
{
ASSERT_EQ(run_panning_volume_test(0), CUBEB_OK);
}

TEST(cubeb, run_panning_volume_test_float)
{
ASSERT_EQ(run_panning_volume_test(1), CUBEB_OK);
}

TEST(cubeb, run_channel_rate_test)
{
int channel_values[] = {
1,
Expand All @@ -271,24 +276,11 @@ void run_channel_rate_test()

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);
ASSERT_TRUE(channel_values[j] < MAX_NUM_CHANNELS);
fprintf(stderr, "--------------------------\n");
assert(run_test(channel_values[j], freq_values[i], 0) == CUBEB_OK);
assert(run_test(channel_values[j], freq_values[i], 1) == CUBEB_OK);
ASSERT_EQ(run_test(channel_values[j], freq_values[i], 0), CUBEB_OK);
ASSERT_EQ(run_test(channel_values[j], freq_values[i], 1), CUBEB_OK);
}
}
}


int main(int /*argc*/, char * /*argv*/[])
{
#ifdef CUBEB_GECKO_BUILD
ScopedXPCOM xpcom("test_audio");
#endif

assert(run_panning_volume_test(0) == CUBEB_OK);
assert(run_panning_volume_test(1) == CUBEB_OK);
run_channel_rate_test();

return CUBEB_OK;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,12 @@

/* libcubeb enumerate device test/example.
* Prints out a list of devices enumerated. */
#ifdef NDEBUG
#undef NDEBUG
#endif

#include "gtest/gtest.h"
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include "cubeb/cubeb.h"


static void
print_device_info(cubeb_device_info * info, FILE * f)
{
Expand Down Expand Up @@ -89,14 +84,14 @@ print_device_info(cubeb_device_info * info, FILE * f)
"\tCh: %u\n"
"\tFormat: %s (0x%x) (default: %s)\n"
"\tRate: %u - %u (default: %u)\n"
"\tLatency: lo %ums, hi %ums\n",
"\tLatency: lo %u frames, hi %u frames\n",
info->device_id, info->preferred ? " (PREFERRED)" : "",
info->friendly_name, info->group_id, info->vendor_name,
devtype, devstate, info->max_channels,
(devfmts[0] == ' ') ? &devfmts[1] : devfmts,
(devfmts[0] == '\0') ? devfmts : devfmts + 1,
(unsigned int)info->format, devdeffmt,
info->min_rate, info->max_rate, info->default_rate,
info->latency_lo_ms, info->latency_hi_ms);
info->latency_lo, info->latency_hi);
}

static void
Expand All @@ -108,23 +103,28 @@ print_device_collection(cubeb_device_collection * collection, FILE * f)
print_device_info(collection->device[i], f);
}

static int
run_enumerate_devices(void)
TEST(cubeb, enumerate_devices)
{
int r = CUBEB_OK;
int r;
cubeb * ctx = NULL;
cubeb_device_collection * collection = NULL;

r = cubeb_init(&ctx, "Cubeb audio test");
if (r != CUBEB_OK) {
fprintf(stderr, "Error initializing cubeb library\n");
return r;
ASSERT_EQ(r, CUBEB_OK);
}

fprintf(stdout, "Enumerating input devices for backend %s\n",
cubeb_get_backend_id(ctx));

r = cubeb_enumerate_devices(ctx, CUBEB_DEVICE_TYPE_INPUT, &collection);
if (r == CUBEB_ERROR_NOT_SUPPORTED) {
fprintf(stderr, "Device enumeration not supported"
" for this backend, skipping this test.\n");
r = CUBEB_OK;
goto cleanup;
}
if (r != CUBEB_OK) {
fprintf(stderr, "Error enumerating devices %d\n", r);
goto cleanup;
Expand All @@ -149,14 +149,6 @@ run_enumerate_devices(void)

cleanup:
cubeb_destroy(ctx);
return r;
ASSERT_EQ(r, CUBEB_OK);
}

int main(int argc, char *argv[])
{
int ret;

ret = run_enumerate_devices();

return ret;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,20 +7,15 @@

/* libcubeb api/function test. Loops input back to output and check audio
* is flowing. */
#ifdef NDEBUG
#undef NDEBUG
#endif
#include "gtest/gtest.h"
#if !defined(_XOPEN_SOURCE)
#define _XOPEN_SOURCE 600
#endif
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <assert.h>

#include "cubeb/cubeb.h"
#include "common.h"
#ifdef CUBEB_GECKO_BUILD
#include "TestHarness.h"
#endif

#define SAMPLE_FREQUENCY 48000
#if (defined(_WIN32) || defined(__WIN32__))
Expand All @@ -31,16 +26,14 @@
#define SILENT_SAMPLE 0
#endif

struct user_state
struct user_state_duplex
{
bool seen_noise;
};



long data_cb(cubeb_stream * stream, void * user, const void * inputbuffer, void * outputbuffer, long nframes)
long data_cb_duplex(cubeb_stream * stream, void * user, const void * inputbuffer, void * outputbuffer, long nframes)
{
user_state * u = reinterpret_cast<user_state*>(user);
user_state_duplex * u = reinterpret_cast<user_state_duplex*>(user);
#if (defined(_WIN32) || defined(__WIN32__))
float *ib = (float *)inputbuffer;
float *ob = (float *)outputbuffer;
Expand Down Expand Up @@ -70,7 +63,7 @@ long data_cb(cubeb_stream * stream, void * user, const void * inputbuffer, void
return nframes;
}

void state_cb(cubeb_stream * stream, void * /*user*/, cubeb_state state)
void state_cb_duplex(cubeb_stream * stream, void * /*user*/, cubeb_state state)
{
if (stream == NULL)
return;
Expand All @@ -89,30 +82,26 @@ void state_cb(cubeb_stream * stream, void * /*user*/, cubeb_state state)
return;
}

int main(int /*argc*/, char * /*argv*/[])
TEST(cubeb, duplex)
{
#ifdef CUBEB_GECKO_BUILD
ScopedXPCOM xpcom("test_duplex");
#endif

cubeb *ctx;
cubeb_stream *stream;
cubeb_stream_params input_params;
cubeb_stream_params output_params;
int r;
user_state stream_state = { false };
user_state_duplex stream_state = { false };
uint32_t latency_frames = 0;

r = cubeb_init(&ctx, "Cubeb duplex example");
if (r != CUBEB_OK) {
fprintf(stderr, "Error initializing cubeb library\n");
return r;
ASSERT_EQ(r, CUBEB_OK);
}

/* This test needs an available input device, skip it if this host does not
* have one. */
if (!has_available_input_device(ctx)) {
return 0;
return;
}

/* typical user-case: mono input, stereo output, low latency. */
Expand All @@ -127,15 +116,15 @@ int main(int /*argc*/, char * /*argv*/[])

if (r != CUBEB_OK) {
fprintf(stderr, "Could not get minimal latency\n");
return r;
ASSERT_EQ(r, CUBEB_OK);
}

r = cubeb_stream_init(ctx, &stream, "Cubeb duplex",
NULL, &input_params, NULL, &output_params,
latency_frames, data_cb, state_cb, &stream_state);
latency_frames, data_cb_duplex, state_cb_duplex, &stream_state);
if (r != CUBEB_OK) {
fprintf(stderr, "Error initializing cubeb stream\n");
return r;
ASSERT_EQ(r, CUBEB_OK);
}

cubeb_stream_start(stream);
Expand All @@ -145,7 +134,5 @@ int main(int /*argc*/, char * /*argv*/[])
cubeb_stream_destroy(stream);
cubeb_destroy(ctx);

assert(stream_state.seen_noise);

return CUBEB_OK;
ASSERT_TRUE(stream_state.seen_noise);
}
Loading

0 comments on commit 3e54f90

Please sign in to comment.