in tools/cubeb-test.cpp [414:523]
bool choose_action(cubeb_client& cl, operation_data * op, int c) {
// Consume "enter" and "space"
while (c == 10 || c == 32) {
c = getchar();
}
if (c == EOF) {
c = 'q';
}
if (c == 'q') {
if (op->pm == PLAYBACK || op->pm == RECORD || op->pm == DUPLEX || op->pm == LATENCY_TESTING) {
bool res = cl.stop_stream();
if (!res) {
fprintf(stderr, "stop_stream failed\n");
}
res = cl.destroy_stream();
if (!res) {
fprintf(stderr, "destroy_stream failed\n");
}
} else if (op->pm == COLLECTION_CHANGE) {
bool res = cl.unregister_device_collection_changed(op->collection_device_type);
if (!res) {
fprintf(stderr, "unregister_device_collection_changed failed\n");
}
}
return false; // exit the loop
} else if (c == 'h') {
print_help();
} else if (c == '0') {
cl.activate_log(CUBEB_LOG_DISABLED);
fprintf(stderr, "Log level changed to DISABLED\n");
} else if (c == '1') {
cl.activate_log(CUBEB_LOG_DISABLED);
cl.activate_log(CUBEB_LOG_NORMAL);
fprintf(stderr, "Log level changed to NORMAL\n");
} else if (c == '2') {
cl.activate_log(CUBEB_LOG_DISABLED);
cl.activate_log(CUBEB_LOG_VERBOSE);
fprintf(stderr, "Log level changed to VERBOSE\n");
} else if (c == 'p') {
bool res = cl.start_stream();
if (res) {
fprintf(stderr, "start_stream succeed\n");
} else {
fprintf(stderr, "start_stream failed\n");
}
} else if (c == 's') {
bool res = cl.stop_stream();
if (res) {
fprintf(stderr, "stop_stream succeed\n");
} else {
fprintf(stderr, "stop_stream failed\n");
}
} else if (c == 'd') {
bool res = cl.destroy_stream();
if (res) {
fprintf(stderr, "destroy_stream succeed\n");
} else {
fprintf(stderr, "destroy_stream failed\n");
}
} else if (c == 'e') {
cl.force_drain();
} else if (c == 'c') {
uint32_t channel_count = cl.get_max_channel_count();
fprintf(stderr, "max channel count (default output device): %u\n", channel_count);
} else if (c == 'f') {
uint64_t pos = cl.get_stream_position();
uint32_t latency;
fprintf(stderr, "stream position %" PRIu64 ".", pos);
if(op->pm == PLAYBACK || op->pm == DUPLEX) {
latency = cl.get_stream_output_latency();
fprintf(stderr, " (output latency %" PRIu32 ")", latency);
}
if(op->pm == RECORD || op->pm == DUPLEX) {
latency = cl.get_stream_input_latency();
fprintf(stderr, " (input latency %" PRIu32 ")", latency);
}
fprintf(stderr, "\n");
} else if (c == 'i') {
op->collection_device_type = CUBEB_DEVICE_TYPE_INPUT;
fprintf(stderr, "collection device type changed to INPUT\n");
} else if (c == 'o') {
op->collection_device_type = CUBEB_DEVICE_TYPE_OUTPUT;
fprintf(stderr, "collection device type changed to OUTPUT\n");
} else if (c == 'a') {
op->collection_device_type = static_cast<cubeb_device_type>(CUBEB_DEVICE_TYPE_INPUT | CUBEB_DEVICE_TYPE_OUTPUT);
fprintf(stderr, "collection device type changed to INPUT | OUTPUT\n");
} else if (c == 'k') {
op->collection_device_type = CUBEB_DEVICE_TYPE_UNKNOWN;
fprintf(stderr, "collection device type changed to UNKNOWN\n");
} else if (c == 'r') {
bool res = cl.register_device_collection_changed(op->collection_device_type);
if (res) {
fprintf(stderr, "register_device_collection_changed succeed\n");
} else {
fprintf(stderr, "register_device_collection_changed failed\n");
}
} else if (c == 'u') {
bool res = cl.unregister_device_collection_changed(op->collection_device_type);
if (res) {
fprintf(stderr, "unregister_device_collection_changed succeed\n");
} else {
fprintf(stderr, "unregister_device_collection_changed failed\n");
}
} else {
fprintf(stderr, "Error: '%c' is not a valid entry\n", c);
}
return true; // Loop up
}