From 2f2b3f1cdc72a1afadbc151f12285669ca83fe39 Mon Sep 17 00:00:00 2001 From: Max Kellermann Date: Fri, 5 Mar 2021 19:01:45 +0100 Subject: [PATCH] output/wasapi: SearchDevice() returns IMMDevice --- .../plugins/wasapi/WasapiOutputPlugin.cxx | 21 ++++++++++--------- 1 file changed, 11 insertions(+), 10 deletions(-) diff --git a/src/output/plugins/wasapi/WasapiOutputPlugin.cxx b/src/output/plugins/wasapi/WasapiOutputPlugin.cxx index 741846444..78c7c461f 100644 --- a/src/output/plugins/wasapi/WasapiOutputPlugin.cxx +++ b/src/output/plugins/wasapi/WasapiOutputPlugin.cxx @@ -261,7 +261,7 @@ private: void FindSharedFormatSupported(AudioFormat &audio_format); void EnumerateDevices(); ComPtr GetDevice(unsigned int index); - unsigned int SearchDevice(std::string_view name); + ComPtr SearchDevice(std::string_view name); }; WasapiOutput &wasapi_output_downcast(AudioOutput &output) noexcept { @@ -616,13 +616,12 @@ void WasapiOutput::OpenDevice() { unsigned int id = kErrorId; if (!device_config.empty()) { if (!SafeSilenceTry([this, &id]() { id = std::stoul(device_config); })) { - id = SearchDevice(device_config); - if (id == kErrorId) + device = SearchDevice(device_config); + if (!device) throw FormatRuntimeError("Device '%s' not found", device_config.c_str()); - } - - device = GetDevice(id); + } else + device = GetDevice(id); } else { device = GetDefaultAudioEndpoint(*enumerator); } @@ -836,9 +835,11 @@ WasapiOutput::GetDevice(unsigned int index) } /// run inside COMWorkerThread -unsigned int WasapiOutput::SearchDevice(std::string_view name) { +ComPtr +WasapiOutput::SearchDevice(std::string_view name) +{ if (!SafeTry([this]() { EnumerateDevices(); })) { - return kErrorId; + return nullptr; } auto iter = std::find_if(device_desc.cbegin(), device_desc.cend(), @@ -846,11 +847,11 @@ unsigned int WasapiOutput::SearchDevice(std::string_view name) { if (iter == device_desc.cend()) { FormatError(wasapi_output_domain, "Device %.*s not founded.", int(name.size()), name.data()); - return kErrorId; + return nullptr; } FormatInfo(wasapi_output_domain, "Select device \"%u\" \"%s\"", iter->first, iter->second.c_str()); - return iter->first; + return GetDevice(iter->first); } static bool wasapi_output_test_default_device() { return true; }