2018-02-10 20:03:27 +00:00
|
|
|
// Copyright 2018 Dolphin Emulator Project
|
2021-07-05 01:22:19 +00:00
|
|
|
// SPDX-License-Identifier: GPL-2.0-or-later
|
2018-02-10 20:03:27 +00:00
|
|
|
|
|
|
|
#pragma once
|
|
|
|
|
|
|
|
#ifdef _WIN32
|
2019-08-16 21:53:47 +00:00
|
|
|
|
2018-02-10 20:03:27 +00:00
|
|
|
// clang-format off
|
|
|
|
#include <Windows.h>
|
|
|
|
#include <mmreg.h>
|
2019-08-16 21:53:47 +00:00
|
|
|
#include <objbase.h>
|
|
|
|
#include <wil/resource.h>
|
2018-02-10 20:03:27 +00:00
|
|
|
// clang-format on
|
|
|
|
|
|
|
|
#include <atomic>
|
|
|
|
#include <string>
|
|
|
|
#include <thread>
|
|
|
|
#include <vector>
|
2019-08-16 21:53:47 +00:00
|
|
|
#include <wrl/client.h>
|
2018-02-10 20:03:27 +00:00
|
|
|
|
|
|
|
#include "AudioCommon/SoundStream.h"
|
|
|
|
|
|
|
|
struct IAudioClient;
|
|
|
|
struct IAudioRenderClient;
|
|
|
|
struct IMMDevice;
|
|
|
|
struct IMMDeviceEnumerator;
|
|
|
|
|
2019-08-16 21:53:47 +00:00
|
|
|
#endif
|
|
|
|
|
2018-02-10 20:03:27 +00:00
|
|
|
class WASAPIStream final : public SoundStream
|
|
|
|
{
|
|
|
|
#ifdef _WIN32
|
|
|
|
public:
|
|
|
|
explicit WASAPIStream();
|
|
|
|
~WASAPIStream();
|
|
|
|
bool Init() override;
|
|
|
|
bool SetRunning(bool running) override;
|
|
|
|
|
2021-08-07 23:23:58 +00:00
|
|
|
static bool IsValid();
|
2018-02-10 20:03:27 +00:00
|
|
|
static std::vector<std::string> GetAvailableDevices();
|
2019-08-17 09:05:33 +00:00
|
|
|
static Microsoft::WRL::ComPtr<IMMDevice> GetDeviceByName(std::string_view name);
|
2018-02-10 20:03:27 +00:00
|
|
|
|
|
|
|
private:
|
2021-08-07 21:15:45 +00:00
|
|
|
void SoundLoop();
|
|
|
|
|
2018-02-10 20:03:27 +00:00
|
|
|
u32 m_frames_in_buffer = 0;
|
|
|
|
std::atomic<bool> m_running = false;
|
|
|
|
std::thread m_thread;
|
|
|
|
|
2019-08-16 21:53:47 +00:00
|
|
|
// CoUninitialize must be called after all WASAPI COM objects have been destroyed,
|
|
|
|
// therefore this member must be located before them, as first class fields are destructed last
|
|
|
|
wil::unique_couninitialize_call m_coinitialize{false};
|
|
|
|
|
|
|
|
Microsoft::WRL::ComPtr<IMMDeviceEnumerator> m_enumerator;
|
|
|
|
Microsoft::WRL::ComPtr<IAudioClient> m_audio_client;
|
|
|
|
Microsoft::WRL::ComPtr<IAudioRenderClient> m_audio_renderer;
|
|
|
|
wil::unique_event_nothrow m_need_data_event;
|
2018-02-10 20:03:27 +00:00
|
|
|
WAVEFORMATEXTENSIBLE m_format;
|
|
|
|
#endif // _WIN32
|
|
|
|
};
|