DeviceFinder: Add typedef DeviceList

This commit is contained in:
Jonas Kvinge
2023-06-01 18:43:43 +02:00
parent 8e14ef7c0c
commit a5a29f7ad3
15 changed files with 29 additions and 42 deletions

View File

@@ -24,7 +24,6 @@
#include <alsa/asoundlib.h> #include <alsa/asoundlib.h>
#include <boost/scope_exit.hpp> #include <boost/scope_exit.hpp>
#include <QList>
#include <QString> #include <QString>
#include <core/logging.h> #include <core/logging.h>
@@ -34,9 +33,9 @@
AlsaDeviceFinder::AlsaDeviceFinder() : DeviceFinder("alsa", { "alsa", "alsasink" }) {} AlsaDeviceFinder::AlsaDeviceFinder() : DeviceFinder("alsa", { "alsa", "alsasink" }) {}
QList<DeviceFinder::Device> AlsaDeviceFinder::ListDevices() { DeviceFinder::DeviceList AlsaDeviceFinder::ListDevices() {
QList<Device> ret; DeviceList ret;
snd_pcm_stream_name(SND_PCM_STREAM_PLAYBACK); snd_pcm_stream_name(SND_PCM_STREAM_PLAYBACK);

View File

@@ -22,8 +22,6 @@
#include "config.h" #include "config.h"
#include <QList>
#include "devicefinder.h" #include "devicefinder.h"
class AlsaDeviceFinder : public DeviceFinder { class AlsaDeviceFinder : public DeviceFinder {
@@ -31,7 +29,7 @@ class AlsaDeviceFinder : public DeviceFinder {
explicit AlsaDeviceFinder(); explicit AlsaDeviceFinder();
bool Initialize() override { return true; } bool Initialize() override { return true; }
QList<Device> ListDevices() override; DeviceList ListDevices() override;
private: private:
Q_DISABLE_COPY(AlsaDeviceFinder) Q_DISABLE_COPY(AlsaDeviceFinder)

View File

@@ -21,7 +21,6 @@
#include <alsa/asoundlib.h> #include <alsa/asoundlib.h>
#include <QList>
#include <QString> #include <QString>
#include <core/logging.h> #include <core/logging.h>
@@ -31,9 +30,9 @@
AlsaPCMDeviceFinder::AlsaPCMDeviceFinder() : DeviceFinder("alsa", { "alsa", "alsasink" }) {} AlsaPCMDeviceFinder::AlsaPCMDeviceFinder() : DeviceFinder("alsa", { "alsa", "alsasink" }) {}
QList<DeviceFinder::Device> AlsaPCMDeviceFinder::ListDevices() { DeviceFinder::DeviceList AlsaPCMDeviceFinder::ListDevices() {
QList<Device> ret; DeviceList ret;
void **hints = nullptr; void **hints = nullptr;
if (snd_device_name_hint(-1, "pcm", &hints) < 0) { if (snd_device_name_hint(-1, "pcm", &hints) < 0) {

View File

@@ -22,8 +22,6 @@
#include "config.h" #include "config.h"
#include <QList>
#include "devicefinder.h" #include "devicefinder.h"
class AlsaPCMDeviceFinder : public DeviceFinder { class AlsaPCMDeviceFinder : public DeviceFinder {
@@ -31,7 +29,7 @@ class AlsaPCMDeviceFinder : public DeviceFinder {
explicit AlsaPCMDeviceFinder(); explicit AlsaPCMDeviceFinder();
bool Initialize() override { return true; } bool Initialize() override { return true; }
QList<Device> ListDevices() override; DeviceList ListDevices() override;
private: private:
Q_DISABLE_COPY(AlsaPCMDeviceFinder) Q_DISABLE_COPY(AlsaPCMDeviceFinder)

View File

@@ -40,6 +40,7 @@ class DeviceFinder {
int card; int card;
int device; int device;
}; };
using DeviceList = QList<Device>;
virtual ~DeviceFinder() {} virtual ~DeviceFinder() {}
@@ -51,7 +52,7 @@ class DeviceFinder {
virtual bool Initialize() = 0; virtual bool Initialize() = 0;
// Returns a list of available devices. // Returns a list of available devices.
virtual QList<Device> ListDevices() = 0; virtual DeviceList ListDevices() = 0;
protected: protected:
explicit DeviceFinder(const QString &name, const QStringList &outputs); explicit DeviceFinder(const QString &name, const QStringList &outputs);

View File

@@ -27,7 +27,6 @@
#include <dsound.h> #include <dsound.h>
#include <QList>
#include <QVariant> #include <QVariant>
#include <QString> #include <QString>
#include <QUuid> #include <QUuid>
@@ -37,7 +36,7 @@
DirectSoundDeviceFinder::DirectSoundDeviceFinder() : DeviceFinder("directsound", { "directsound", "dsound", "directsoundsink", "directx", "directx2" }) {} DirectSoundDeviceFinder::DirectSoundDeviceFinder() : DeviceFinder("directsound", { "directsound", "dsound", "directsoundsink", "directx", "directx2" }) {}
QList<DeviceFinder::Device> DirectSoundDeviceFinder::ListDevices() { DeviceFinder::DeviceList DirectSoundDeviceFinder::ListDevices() {
State state; State state;
DirectSoundEnumerateA(&DirectSoundDeviceFinder::EnumerateCallback, &state); DirectSoundEnumerateA(&DirectSoundDeviceFinder::EnumerateCallback, &state);
return state.devices; return state.devices;

View File

@@ -33,11 +33,11 @@ class DirectSoundDeviceFinder : public DeviceFinder {
explicit DirectSoundDeviceFinder(); explicit DirectSoundDeviceFinder();
virtual bool Initialize() { return true; } virtual bool Initialize() { return true; }
virtual QList<Device> ListDevices(); virtual DeviceList ListDevices();
private: private:
struct State { struct State {
QList<Device> devices; DeviceList devices;
}; };
static BOOL CALLBACK EnumerateCallback(LPGUID guid, LPCSTR description, LPCSTR module, LPVOID state_voidptr); static BOOL CALLBACK EnumerateCallback(LPGUID guid, LPCSTR description, LPCSTR module, LPVOID state_voidptr);

View File

@@ -24,7 +24,6 @@
#include <CoreAudio/AudioHardware.h> #include <CoreAudio/AudioHardware.h>
#include <QList>
#include <QString> #include <QString>
#include "core/logging.h" #include "core/logging.h"
@@ -64,9 +63,9 @@ std::unique_ptr<T> GetProperty(const AudioDeviceID &device_id, const AudioObject
MacOsDeviceFinder::MacOsDeviceFinder() : DeviceFinder("osxaudio", { "osxaudio", "osx", "osxaudiosink" }) {} MacOsDeviceFinder::MacOsDeviceFinder() : DeviceFinder("osxaudio", { "osxaudio", "osx", "osxaudiosink" }) {}
QList<DeviceFinder::Device> MacOsDeviceFinder::ListDevices() { DeviceFinder::DeviceList MacOsDeviceFinder::ListDevices() {
QList<Device> ret; DeviceList ret;
AudioObjectPropertyAddress address = { AudioObjectPropertyAddress address = {
kAudioHardwarePropertyDevices, kAudioHardwarePropertyDevices,

View File

@@ -23,8 +23,6 @@
#include "config.h" #include "config.h"
#include <QList>
#include "devicefinder.h" #include "devicefinder.h"
class MacOsDeviceFinder : public DeviceFinder { class MacOsDeviceFinder : public DeviceFinder {
@@ -32,7 +30,7 @@ class MacOsDeviceFinder : public DeviceFinder {
explicit MacOsDeviceFinder(); explicit MacOsDeviceFinder();
virtual bool Initialize() { return true; } virtual bool Initialize() { return true; }
virtual QList<Device> ListDevices(); virtual DeviceList ListDevices();
}; };
#endif // MACOSDEVICEFINDER_H #endif // MACOSDEVICEFINDER_H

View File

@@ -29,7 +29,6 @@
#endif #endif
#include <mmdeviceapi.h> #include <mmdeviceapi.h>
#include <QList>
#include <QVariant> #include <QVariant>
#include <QString> #include <QString>
@@ -43,11 +42,11 @@
MMDeviceFinder::MMDeviceFinder() : DeviceFinder("mmdevice", { "wasapisink" }) {} MMDeviceFinder::MMDeviceFinder() : DeviceFinder("mmdevice", { "wasapisink" }) {}
QList<DeviceFinder::Device> MMDeviceFinder::ListDevices() { DeviceFinder::DeviceList MMDeviceFinder::ListDevices() {
HRESULT hr_coinit = CoInitializeEx(NULL, COINIT_MULTITHREADED); HRESULT hr_coinit = CoInitializeEx(NULL, COINIT_MULTITHREADED);
QList<Device> devices; DeviceList devices;
Device default_device; Device default_device;
default_device.description = "Default device"; default_device.description = "Default device";
default_device.iconname = GuessIconName(default_device.description); default_device.iconname = GuessIconName(default_device.description);

View File

@@ -29,7 +29,7 @@ class MMDeviceFinder : public DeviceFinder {
explicit MMDeviceFinder(); explicit MMDeviceFinder();
virtual bool Initialize() { return true; } virtual bool Initialize() { return true; }
virtual QList<Device> ListDevices(); virtual DeviceList ListDevices();
}; };
#endif // MMDEVICEFINDER_H #endif // MMDEVICEFINDER_H

View File

@@ -80,10 +80,10 @@ bool PulseDeviceFinder::Reconnect() {
} }
} }
QList<DeviceFinder::Device> PulseDeviceFinder::ListDevices() { DeviceFinder::DeviceList PulseDeviceFinder::ListDevices() {
if (!context_ || pa_context_get_state(context_) != PA_CONTEXT_READY) { if (!context_ || pa_context_get_state(context_) != PA_CONTEXT_READY) {
return QList<Device>(); return DeviceList();
} }
retry: retry:

View File

@@ -27,8 +27,6 @@
#include <pulse/introspect.h> #include <pulse/introspect.h>
#include <pulse/mainloop.h> #include <pulse/mainloop.h>
#include <QList>
#include "devicefinder.h" #include "devicefinder.h"
class PulseDeviceFinder : public DeviceFinder { class PulseDeviceFinder : public DeviceFinder {
@@ -37,14 +35,14 @@ class PulseDeviceFinder : public DeviceFinder {
~PulseDeviceFinder() override; ~PulseDeviceFinder() override;
bool Initialize() override; bool Initialize() override;
QList<Device> ListDevices() override; DeviceList ListDevices() override;
private: private:
struct ListDevicesState { struct ListDevicesState {
ListDevicesState() : finished(false) {} ListDevicesState() : finished(false) {}
bool finished; bool finished;
QList<Device> devices; DeviceList devices;
}; };
bool Reconnect(); bool Reconnect();

View File

@@ -23,7 +23,6 @@
#include <locale> #include <locale>
#include <codecvt> #include <codecvt>
#include <QList>
#include <QString> #include <QString>
#include <wrl.h> #include <wrl.h>
@@ -70,40 +69,40 @@ static std::string hstring_to_stdstring(HString *hstr) {
} // namespace } // namespace
QList<DeviceFinder::Device> UWPDeviceFinder::ListDevices() { DeviceFinder::DeviceList UWPDeviceFinder::ListDevices() {
ComPtr<IDeviceInformationStatics> device_info_statics; ComPtr<IDeviceInformationStatics> device_info_statics;
HRESULT hr = ABI::Windows::Foundation::GetActivationFactory(HStringReference(RuntimeClass_Windows_Devices_Enumeration_DeviceInformation).Get(), &device_info_statics); HRESULT hr = ABI::Windows::Foundation::GetActivationFactory(HStringReference(RuntimeClass_Windows_Devices_Enumeration_DeviceInformation).Get(), &device_info_statics);
if (FAILED(hr)) { if (FAILED(hr)) {
return QList<Device>(); return DeviceList();
} }
ComPtr<IAsyncOperation<DeviceInformationCollection*>> async_op; ComPtr<IAsyncOperation<DeviceInformationCollection*>> async_op;
hr = device_info_statics->FindAllAsyncDeviceClass(DeviceClass::DeviceClass_AudioRender, &async_op); hr = device_info_statics->FindAllAsyncDeviceClass(DeviceClass::DeviceClass_AudioRender, &async_op);
device_info_statics.Reset(); device_info_statics.Reset();
if (FAILED(hr)) { if (FAILED(hr)) {
return QList<Device>(); return DeviceList();
} }
hr = SyncWait<DeviceInformationCollection*>(async_op.Get()); hr = SyncWait<DeviceInformationCollection*>(async_op.Get());
if (FAILED(hr)) { if (FAILED(hr)) {
return QList<Device>(); return DeviceList();
} }
ComPtr<IVectorView<DeviceInformation*>> device_list; ComPtr<IVectorView<DeviceInformation*>> device_list;
hr = async_op->GetResults(&device_list); hr = async_op->GetResults(&device_list);
async_op.Reset(); async_op.Reset();
if (FAILED(hr)) { if (FAILED(hr)) {
return QList<Device>(); return DeviceList();
} }
unsigned int count = 0; unsigned int count = 0;
hr = device_list->get_Size(&count); hr = device_list->get_Size(&count);
if (FAILED(hr)) { if (FAILED(hr)) {
return QList<Device>(); return DeviceList();
} }
QList<Device> devices; DeviceList devices;
{ {
Device default_device; Device default_device;

View File

@@ -29,7 +29,7 @@ class UWPDeviceFinder : public DeviceFinder {
explicit UWPDeviceFinder(); explicit UWPDeviceFinder();
virtual bool Initialize() { return true; } virtual bool Initialize() { return true; }
virtual QList<Device> ListDevices(); virtual DeviceList ListDevices();
}; };
#endif // UWPDEVICEFINDER_H #endif // UWPDEVICEFINDER_H