early-access version 2291
This commit is contained in:
134
externals/cubeb/test/test_duplex.cpp
vendored
134
externals/cubeb/test/test_duplex.cpp
vendored
@@ -179,3 +179,137 @@ TEST(cubeb, duplex_collection_change)
|
||||
ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb stream";
|
||||
cubeb_stream_destroy(stream);
|
||||
}
|
||||
|
||||
long data_cb_input(cubeb_stream * stream, void * user, const void * inputbuffer, void * outputbuffer, long nframes)
|
||||
{
|
||||
if (stream == NULL || inputbuffer == NULL || outputbuffer != NULL) {
|
||||
return CUBEB_ERROR;
|
||||
}
|
||||
|
||||
return nframes;
|
||||
}
|
||||
|
||||
void state_cb_input(cubeb_stream * stream, void * /*user*/, cubeb_state state)
|
||||
{
|
||||
if (stream == NULL)
|
||||
return;
|
||||
|
||||
switch (state) {
|
||||
case CUBEB_STATE_STARTED:
|
||||
fprintf(stderr, "stream started\n"); break;
|
||||
case CUBEB_STATE_STOPPED:
|
||||
fprintf(stderr, "stream stopped\n"); break;
|
||||
case CUBEB_STATE_DRAINED:
|
||||
fprintf(stderr, "stream drained\n"); break;
|
||||
case CUBEB_STATE_ERROR:
|
||||
fprintf(stderr, "stream runs into error state\n"); break;
|
||||
default:
|
||||
fprintf(stderr, "unknown stream state %d\n", state);
|
||||
}
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
std::vector<cubeb_devid> get_devices(cubeb * ctx, cubeb_device_type type) {
|
||||
std::vector<cubeb_devid> devices;
|
||||
|
||||
cubeb_device_collection collection;
|
||||
int r = cubeb_enumerate_devices(ctx, type, &collection);
|
||||
|
||||
if (r != CUBEB_OK) {
|
||||
fprintf(stderr, "Failed to enumerate devices\n");
|
||||
return devices;
|
||||
}
|
||||
|
||||
for (uint32_t i = 0; i < collection.count; i++) {
|
||||
if (collection.device[i].state == CUBEB_DEVICE_STATE_ENABLED) {
|
||||
devices.emplace_back(collection.device[i].devid);
|
||||
}
|
||||
}
|
||||
|
||||
cubeb_device_collection_destroy(ctx, &collection);
|
||||
|
||||
return devices;
|
||||
}
|
||||
|
||||
TEST(cubeb, one_duplex_one_input)
|
||||
{
|
||||
cubeb *ctx;
|
||||
cubeb_stream *duplex_stream;
|
||||
cubeb_stream_params input_params;
|
||||
cubeb_stream_params output_params;
|
||||
int r;
|
||||
user_state_duplex duplex_stream_state;
|
||||
uint32_t latency_frames = 0;
|
||||
|
||||
r = common_init(&ctx, "Cubeb duplex example");
|
||||
ASSERT_EQ(r, CUBEB_OK) << "Error initializing cubeb library";
|
||||
|
||||
std::unique_ptr<cubeb, decltype(&cubeb_destroy)>
|
||||
cleanup_cubeb_at_exit(ctx, cubeb_destroy);
|
||||
|
||||
/* This test needs at least two available input devices. */
|
||||
std::vector<cubeb_devid> input_devices = get_devices(ctx, CUBEB_DEVICE_TYPE_INPUT);
|
||||
if (input_devices.size() < 2) {
|
||||
return;
|
||||
}
|
||||
|
||||
/* This test needs at least one available output device. */
|
||||
std::vector<cubeb_devid> output_devices = get_devices(ctx, CUBEB_DEVICE_TYPE_OUTPUT);
|
||||
if (output_devices.size() < 1) {
|
||||
return;
|
||||
}
|
||||
|
||||
cubeb_devid duplex_input = input_devices.front();
|
||||
cubeb_devid duplex_output = nullptr; // default device
|
||||
cubeb_devid input_only = input_devices.back();
|
||||
|
||||
/* typical use-case: mono voice input, stereo output, low latency. */
|
||||
input_params.format = STREAM_FORMAT;
|
||||
input_params.rate = SAMPLE_FREQUENCY;
|
||||
input_params.channels = INPUT_CHANNELS;
|
||||
input_params.layout = CUBEB_LAYOUT_UNDEFINED;
|
||||
input_params.prefs = CUBEB_STREAM_PREF_VOICE;
|
||||
|
||||
output_params.format = STREAM_FORMAT;
|
||||
output_params.rate = SAMPLE_FREQUENCY;
|
||||
output_params.channels = OUTPUT_CHANNELS;
|
||||
output_params.layout = OUTPUT_LAYOUT;
|
||||
output_params.prefs = CUBEB_STREAM_PREF_NONE;
|
||||
|
||||
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, &duplex_stream, "Cubeb duplex",
|
||||
duplex_input, &input_params, duplex_output, &output_params,
|
||||
latency_frames, data_cb_duplex, state_cb_duplex, &duplex_stream_state);
|
||||
ASSERT_EQ(r, CUBEB_OK) << "Error initializing duplex cubeb stream";
|
||||
|
||||
std::unique_ptr<cubeb_stream, decltype(&cubeb_stream_destroy)>
|
||||
cleanup_stream_at_exit(duplex_stream, cubeb_stream_destroy);
|
||||
|
||||
r = cubeb_stream_start(duplex_stream);
|
||||
ASSERT_EQ(r, CUBEB_OK) << "Could not start duplex stream";
|
||||
delay(500);
|
||||
|
||||
cubeb_stream *input_stream;
|
||||
r = cubeb_stream_init(ctx, &input_stream, "Cubeb input",
|
||||
input_only, &input_params, NULL, NULL,
|
||||
latency_frames, data_cb_input, state_cb_input, nullptr);
|
||||
ASSERT_EQ(r, CUBEB_OK) << "Error initializing input-only cubeb stream";
|
||||
|
||||
std::unique_ptr<cubeb_stream, decltype(&cubeb_stream_destroy)>
|
||||
cleanup_input_stream_at_exit(input_stream, cubeb_stream_destroy);
|
||||
|
||||
r = cubeb_stream_start(input_stream);
|
||||
ASSERT_EQ(r, CUBEB_OK) << "Could not start input stream";
|
||||
delay(500);
|
||||
|
||||
r = cubeb_stream_stop(duplex_stream);
|
||||
ASSERT_EQ(r, CUBEB_OK) << "Could not stop duplex stream";
|
||||
|
||||
r = cubeb_stream_stop(input_stream);
|
||||
ASSERT_EQ(r, CUBEB_OK) << "Could not stop input stream";
|
||||
|
||||
ASSERT_FALSE(duplex_stream_state.invalid_audio_value.load());
|
||||
}
|
||||
|
61
externals/cubeb/test/test_sanity.cpp
vendored
61
externals/cubeb/test/test_sanity.cpp
vendored
@@ -612,7 +612,7 @@ TEST(cubeb, drain)
|
||||
r = cubeb_stream_start(stream);
|
||||
ASSERT_EQ(r, CUBEB_OK);
|
||||
|
||||
delay(500);
|
||||
delay(5000);
|
||||
|
||||
do_drain = 1;
|
||||
|
||||
@@ -642,65 +642,6 @@ TEST(cubeb, drain)
|
||||
do_drain = 0;
|
||||
}
|
||||
|
||||
TEST(cubeb, device_reset)
|
||||
{
|
||||
int r;
|
||||
cubeb * ctx;
|
||||
cubeb_stream * stream;
|
||||
cubeb_stream_params params;
|
||||
uint64_t position;
|
||||
|
||||
r = common_init(&ctx, "test_sanity");
|
||||
ASSERT_EQ(r, CUBEB_OK);
|
||||
ASSERT_NE(ctx, nullptr);
|
||||
|
||||
if (strcmp(cubeb_get_backend_id(ctx), "wasapi")) {
|
||||
// cubeb_stream_reset_default_device is only useful and implemented in the
|
||||
// WASAPI backend.
|
||||
return;
|
||||
}
|
||||
|
||||
params.format = STREAM_FORMAT;
|
||||
params.rate = STREAM_RATE;
|
||||
params.channels = STREAM_CHANNELS;
|
||||
params.layout = STREAM_LAYOUT;
|
||||
params.prefs = CUBEB_STREAM_PREF_NONE;
|
||||
|
||||
r = cubeb_stream_init(ctx, &stream, "test", NULL, NULL, NULL, ¶ms, 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);
|
||||
|
||||
uint32_t iterations = 5;
|
||||
uint64_t previous_position = 0;
|
||||
while (iterations--) {
|
||||
r = cubeb_stream_get_position(stream, &position);
|
||||
ASSERT_EQ(r, CUBEB_OK);
|
||||
ASSERT_GE(position, previous_position);
|
||||
previous_position = position;
|
||||
delay(100);
|
||||
}
|
||||
|
||||
r = cubeb_stream_reset_default_device(stream);
|
||||
ASSERT_EQ(r, CUBEB_OK);
|
||||
|
||||
iterations = 5;
|
||||
while (iterations--) {
|
||||
r = cubeb_stream_get_position(stream, &position);
|
||||
ASSERT_EQ(r, CUBEB_OK);
|
||||
ASSERT_GE(position, previous_position);
|
||||
previous_position = position;
|
||||
delay(100);
|
||||
}
|
||||
|
||||
cubeb_stream_stop(stream);
|
||||
cubeb_stream_destroy(stream);
|
||||
cubeb_destroy(ctx);
|
||||
}
|
||||
|
||||
TEST(cubeb, DISABLED_eos_during_prefill)
|
||||
{
|
||||
// This test needs to be implemented.
|
||||
|
2
externals/cubeb/test/test_tone.cpp
vendored
2
externals/cubeb/test/test_tone.cpp
vendored
@@ -114,7 +114,7 @@ TEST(cubeb, tone)
|
||||
cleanup_stream_at_exit(stream, cubeb_stream_destroy);
|
||||
|
||||
cubeb_stream_start(stream);
|
||||
delay(500);
|
||||
delay(5000);
|
||||
cubeb_stream_stop(stream);
|
||||
|
||||
ASSERT_TRUE(user_data->position.load());
|
||||
|
Reference in New Issue
Block a user