From 04139e26bdcf8e6a181a9d9487954fdfc99bfe2c Mon Sep 17 00:00:00 2001 From: darkf Date: Fri, 25 May 2018 03:39:07 -0500 Subject: [PATCH] cubeb_sink: Skip devices without a name Previously this would crash. --- src/audio_core/cubeb_sink.cpp | 11 +++++++---- src/audio_core/cubeb_sink.h | 2 -- 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/audio_core/cubeb_sink.cpp b/src/audio_core/cubeb_sink.cpp index 75a82d3292..1e13e177d2 100644 --- a/src/audio_core/cubeb_sink.cpp +++ b/src/audio_core/cubeb_sink.cpp @@ -13,6 +13,7 @@ namespace AudioCore { struct CubebSink::Impl { unsigned int sample_rate = 0; + std::vector device_list; cubeb* ctx = nullptr; cubeb_stream* stream = nullptr; @@ -56,10 +57,12 @@ CubebSink::CubebSink() : impl(std::make_unique()) { for (size_t i = 0; i < collection.count; i++) { const cubeb_device_info& device = collection.device[i]; - device_list.emplace_back(device.friendly_name); + 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 && strcmp(target_device_name, device.friendly_name) == 0) { + output_device = device.devid; + } } } @@ -99,7 +102,7 @@ unsigned int CubebSink::GetNativeSampleRate() const { } std::vector CubebSink::GetDeviceList() const { - return device_list; + return impl->device_list; } void CubebSink::EnqueueSamples(const s16* samples, size_t sample_count) { diff --git a/src/audio_core/cubeb_sink.h b/src/audio_core/cubeb_sink.h index 192c76d9e3..1fb5218346 100644 --- a/src/audio_core/cubeb_sink.h +++ b/src/audio_core/cubeb_sink.h @@ -27,8 +27,6 @@ public: private: struct Impl; std::unique_ptr impl; - int device_id; - std::vector device_list; }; } // namespace AudioCore