cubeb_sink: Skip devices without a name

Previously this would crash.
This commit is contained in:
darkf 2018-05-25 03:39:07 -05:00
parent ce6d9e2e28
commit 04139e26bd
2 changed files with 7 additions and 6 deletions

View file

@ -13,6 +13,7 @@ namespace AudioCore {
struct CubebSink::Impl { struct CubebSink::Impl {
unsigned int sample_rate = 0; unsigned int sample_rate = 0;
std::vector<std::string> device_list;
cubeb* ctx = nullptr; cubeb* ctx = nullptr;
cubeb_stream* stream = nullptr; cubeb_stream* stream = nullptr;
@ -56,12 +57,14 @@ CubebSink::CubebSink() : impl(std::make_unique<Impl>()) {
for (size_t i = 0; i < collection.count; i++) { for (size_t i = 0; i < collection.count; i++) {
const cubeb_device_info& device = collection.device[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) { if (target_device_name && strcmp(target_device_name, device.friendly_name) == 0) {
output_device = device.devid; output_device = device.devid;
} }
} }
}
cubeb_device_collection_destroy(impl->ctx, &collection); cubeb_device_collection_destroy(impl->ctx, &collection);
} }
@ -99,7 +102,7 @@ unsigned int CubebSink::GetNativeSampleRate() const {
} }
std::vector<std::string> CubebSink::GetDeviceList() const { std::vector<std::string> CubebSink::GetDeviceList() const {
return device_list; return impl->device_list;
} }
void CubebSink::EnqueueSamples(const s16* samples, size_t sample_count) { void CubebSink::EnqueueSamples(const s16* samples, size_t sample_count) {

View file

@ -27,8 +27,6 @@ public:
private: private:
struct Impl; struct Impl;
std::unique_ptr<Impl> impl; std::unique_ptr<Impl> impl;
int device_id;
std::vector<std::string> device_list;
}; };
} // namespace AudioCore } // namespace AudioCore