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
|
@ -9,7 +9,6 @@
|
|||
#include "audio_core/sdl2_sink.h"
|
||||
#include "common/assert.h"
|
||||
#include "common/logging/log.h"
|
||||
#include "core/settings.h"
|
||||
|
||||
namespace AudioCore {
|
||||
|
||||
|
@ -23,7 +22,7 @@ struct SDL2Sink::Impl {
|
|||
static void Callback(void* impl_, u8* buffer, int buffer_size_in_bytes);
|
||||
};
|
||||
|
||||
SDL2Sink::SDL2Sink() : impl(std::make_unique<Impl>()) {
|
||||
SDL2Sink::SDL2Sink(std::string device_name) : impl(std::make_unique<Impl>()) {
|
||||
if (SDL_Init(SDL_INIT_AUDIO) < 0) {
|
||||
LOG_CRITICAL(Audio_Sink, "SDL_Init(SDL_INIT_AUDIO) failed with: {}", SDL_GetError());
|
||||
impl->audio_device_id = 0;
|
||||
|
@ -42,24 +41,16 @@ SDL2Sink::SDL2Sink() : impl(std::make_unique<Impl>()) {
|
|||
SDL_AudioSpec obtained_audiospec;
|
||||
SDL_zero(obtained_audiospec);
|
||||
|
||||
int device_count = SDL_GetNumAudioDevices(0);
|
||||
device_list.clear();
|
||||
for (int i = 0; i < device_count; ++i) {
|
||||
device_list.push_back(SDL_GetAudioDeviceName(i, 0));
|
||||
}
|
||||
|
||||
const char* device = nullptr;
|
||||
|
||||
if (device_count >= 1 && Settings::values.audio_device_id != "auto" &&
|
||||
!Settings::values.audio_device_id.empty()) {
|
||||
device = Settings::values.audio_device_id.c_str();
|
||||
if (device_name != "auto" && !device_name.empty()) {
|
||||
device = device_name.c_str();
|
||||
}
|
||||
|
||||
impl->audio_device_id = SDL_OpenAudioDevice(
|
||||
device, false, &desired_audiospec, &obtained_audiospec, SDL_AUDIO_ALLOW_FREQUENCY_CHANGE);
|
||||
if (impl->audio_device_id <= 0) {
|
||||
LOG_CRITICAL(Audio_Sink, "SDL_OpenAudioDevice failed with code {} for device \"{}\"",
|
||||
impl->audio_device_id, Settings::values.audio_device_id);
|
||||
impl->audio_device_id, device_name);
|
||||
return;
|
||||
}
|
||||
|
||||
|
@ -83,10 +74,6 @@ unsigned int SDL2Sink::GetNativeSampleRate() const {
|
|||
return impl->sample_rate;
|
||||
}
|
||||
|
||||
std::vector<std::string> SDL2Sink::GetDeviceList() const {
|
||||
return device_list;
|
||||
}
|
||||
|
||||
void SDL2Sink::EnqueueSamples(const s16* samples, size_t sample_count) {
|
||||
if (impl->audio_device_id <= 0)
|
||||
return;
|
||||
|
@ -140,4 +127,21 @@ void SDL2Sink::Impl::Callback(void* impl_, u8* buffer, int buffer_size_in_bytes)
|
|||
}
|
||||
}
|
||||
|
||||
std::vector<std::string> ListSDL2SinkDevices() {
|
||||
if (SDL_InitSubSystem(SDL_INIT_AUDIO) < 0) {
|
||||
LOG_CRITICAL(Audio_Sink, "SDL_InitSubSystem failed with: {}", SDL_GetError());
|
||||
return {};
|
||||
}
|
||||
|
||||
std::vector<std::string> device_list;
|
||||
const int device_count = SDL_GetNumAudioDevices(0);
|
||||
for (int i = 0; i < device_count; ++i) {
|
||||
device_list.push_back(SDL_GetAudioDeviceName(i, 0));
|
||||
}
|
||||
|
||||
SDL_QuitSubSystem(SDL_INIT_AUDIO);
|
||||
|
||||
return device_list;
|
||||
}
|
||||
|
||||
} // namespace AudioCore
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue