sink_details: Listing available devices should be separate from sink construction
This commit is contained in:
parent
ce5a5412ae
commit
d269beab0d
13 changed files with 84 additions and 70 deletions
|
@ -7,7 +7,6 @@
|
|||
#include "audio_core/audio_types.h"
|
||||
#include "audio_core/cubeb_sink.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "core/settings.h"
|
||||
|
||||
namespace AudioCore {
|
||||
|
||||
|
@ -25,13 +24,12 @@ struct CubebSink::Impl {
|
|||
static void StateCallback(cubeb_stream* stream, void* user_data, cubeb_state state);
|
||||
};
|
||||
|
||||
CubebSink::CubebSink() : impl(std::make_unique<Impl>()) {
|
||||
CubebSink::CubebSink(std::string target_device_name) : impl(std::make_unique<Impl>()) {
|
||||
if (cubeb_init(&impl->ctx, "Citra", nullptr) != CUBEB_OK) {
|
||||
LOG_CRITICAL(Audio_Sink, "cubeb_init failed");
|
||||
return;
|
||||
}
|
||||
|
||||
const char* target_device_name = nullptr;
|
||||
cubeb_devid output_device = nullptr;
|
||||
|
||||
cubeb_stream_params params;
|
||||
|
@ -46,27 +44,21 @@ CubebSink::CubebSink() : impl(std::make_unique<Impl>()) {
|
|||
if (cubeb_get_min_latency(impl->ctx, ¶ms, &minimum_latency) != CUBEB_OK)
|
||||
LOG_CRITICAL(Audio_Sink, "Error getting minimum latency");
|
||||
|
||||
cubeb_device_collection collection;
|
||||
if (cubeb_enumerate_devices(impl->ctx, CUBEB_DEVICE_TYPE_OUTPUT, &collection) != CUBEB_OK) {
|
||||
LOG_WARNING(Audio_Sink, "Audio output device enumeration not supported");
|
||||
} else {
|
||||
if (collection.count >= 1 && Settings::values.audio_device_id != "auto" &&
|
||||
!Settings::values.audio_device_id.empty()) {
|
||||
target_device_name = Settings::values.audio_device_id.c_str();
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < collection.count; i++) {
|
||||
const cubeb_device_info& device = collection.device[i];
|
||||
if (device.friendly_name) {
|
||||
impl->device_list.emplace_back(device.friendly_name);
|
||||
|
||||
if (target_device_name && strcmp(target_device_name, device.friendly_name) == 0) {
|
||||
output_device = device.devid;
|
||||
}
|
||||
if (target_device_name != "auto" && !target_device_name.empty()) {
|
||||
cubeb_device_collection collection;
|
||||
if (cubeb_enumerate_devices(impl->ctx, CUBEB_DEVICE_TYPE_OUTPUT, &collection) != CUBEB_OK) {
|
||||
LOG_WARNING(Audio_Sink, "Audio output device enumeration not supported");
|
||||
} else {
|
||||
const auto collection_end = collection.device + collection.count;
|
||||
const auto device = std::find_if(collection.device, collection_end,
|
||||
[&](const cubeb_device_info& device) {
|
||||
return target_device_name == device.friendly_name;
|
||||
});
|
||||
if (device != collection_end) {
|
||||
output_device = device->devid;
|
||||
}
|
||||
cubeb_device_collection_destroy(impl->ctx, &collection);
|
||||
}
|
||||
|
||||
cubeb_device_collection_destroy(impl->ctx, &collection);
|
||||
}
|
||||
|
||||
if (cubeb_stream_init(impl->ctx, &impl->stream, "Citra Audio Output", nullptr, nullptr,
|
||||
|
@ -101,10 +93,6 @@ unsigned int CubebSink::GetNativeSampleRate() const {
|
|||
return impl->sample_rate;
|
||||
}
|
||||
|
||||
std::vector<std::string> CubebSink::GetDeviceList() const {
|
||||
return impl->device_list;
|
||||
}
|
||||
|
||||
void CubebSink::EnqueueSamples(const s16* samples, size_t sample_count) {
|
||||
if (!impl->ctx)
|
||||
return;
|
||||
|
@ -144,4 +132,30 @@ long CubebSink::Impl::DataCallback(cubeb_stream* stream, void* user_data, const
|
|||
|
||||
void CubebSink::Impl::StateCallback(cubeb_stream* stream, void* user_data, cubeb_state state) {}
|
||||
|
||||
std::vector<std::string> ListCubebSinkDevices() {
|
||||
std::vector<std::string> device_list;
|
||||
cubeb* ctx;
|
||||
|
||||
if (cubeb_init(&ctx, "Citra Device Enumerator", nullptr) != CUBEB_OK) {
|
||||
LOG_CRITICAL(Audio_Sink, "cubeb_init failed");
|
||||
return {};
|
||||
}
|
||||
|
||||
cubeb_device_collection collection;
|
||||
if (cubeb_enumerate_devices(ctx, CUBEB_DEVICE_TYPE_OUTPUT, &collection) != CUBEB_OK) {
|
||||
LOG_WARNING(Audio_Sink, "Audio output device enumeration not supported");
|
||||
} else {
|
||||
for (size_t i = 0; i < collection.count; i++) {
|
||||
const cubeb_device_info& device = collection.device[i];
|
||||
if (device.friendly_name) {
|
||||
device_list.emplace_back(device.friendly_name);
|
||||
}
|
||||
}
|
||||
cubeb_device_collection_destroy(ctx, &collection);
|
||||
}
|
||||
|
||||
cubeb_destroy(ctx);
|
||||
return device_list;
|
||||
}
|
||||
|
||||
} // namespace AudioCore
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue