Debian Codegraph @

Source/Core/AudioCommon/WASAPIStream.h

raw symbols SCIP
1 // Copyright 2018 Dolphin Emulator Project
2 // SPDX-License-Identifier: GPL-2.0-or-later
3
4 #pragma once
5
6 #ifdef _WIN32
7
8 // clang-format off
9 #include <Windows.h>
10 #include <mmreg.h>
11 #include <objbase.h>
12 #include <wil/resource.h>
13 // clang-format on
14
15 #include <atomic>
16 #include <string>
17 #include <thread>
18 #include <vector>
19 #include <wrl/client.h>
20
21 #include "AudioCommon/SoundStream.h"
22
23 struct IAudioClient;
24 struct IAudioRenderClient;
25 struct IMMDevice;
26 struct IMMDeviceEnumerator;
27
28 #endif
29
30 class WASAPIStream final : public SoundStream
31 {
32 #ifdef _WIN32
33 public:
34 explicit WASAPIStream();
35 ~WASAPIStream() override;
36 bool Init() override;
37 bool SetRunning(bool running) override;
38
39 static bool IsValid();
40 static std::vector<std::string> GetAvailableDevices();
41 static Microsoft::WRL::ComPtr<IMMDevice> GetDeviceByName(std::string_view name);
42
43 private:
44 void SoundLoop();
45
46 u32 m_frames_in_buffer = 0;
47 std::atomic<bool> m_running = false;
48 std::thread m_thread;
49
50 // CoUninitialize must be called after all WASAPI COM objects have been destroyed,
51 // therefore this member must be located before them, as first class fields are destructed last
52 wil::unique_couninitialize_call m_coinitialize{false};
53
54 Microsoft::WRL::ComPtr<IMMDeviceEnumerator> m_enumerator;
55 Microsoft::WRL::ComPtr<IAudioClient> m_audio_client;
56 Microsoft::WRL::ComPtr<IAudioRenderClient> m_audio_renderer;
57 wil::unique_event_nothrow m_need_data_event;
58 WAVEFORMATEXTENSIBLE m_format;
59 #endif // _WIN32
60 };