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 <boost/scope_exit.hpp>
#include <QList>
#include <QString>
#include <core/logging.h>
@ -34,9 +33,9 @@
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);

View File

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

View File

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

View File

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

View File

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

View File

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

View File

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

View File

@ -24,7 +24,6 @@
#include <CoreAudio/AudioHardware.h>
#include <QList>
#include <QString>
#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" }) {}
QList<DeviceFinder::Device> MacOsDeviceFinder::ListDevices() {
DeviceFinder::DeviceList MacOsDeviceFinder::ListDevices() {
QList<Device> ret;
DeviceList ret;
AudioObjectPropertyAddress address = {
kAudioHardwarePropertyDevices,

View File

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

View File

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

View File

@ -29,7 +29,7 @@ class MMDeviceFinder : public DeviceFinder {
explicit MMDeviceFinder();
virtual bool Initialize() { return true; }
virtual QList<Device> ListDevices();
virtual DeviceList ListDevices();
};
#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) {
return QList<Device>();
return DeviceList();
}
retry:

View File

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

View File

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

View File

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