-
Notifications
You must be signed in to change notification settings - Fork 226
/
WASAPIManager.h
97 lines (74 loc) · 2.66 KB
/
WASAPIManager.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
//--------------------------------------------------------------------------------------
// WASAPIManager.h
//
// Wraps the underlying WASAPIRenderer in a simple WinRT class that can receive
// the DeviceStateChanged events.
//
// Advanced Technology Group (ATG)
// Copyright (C) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#pragma once
#ifndef WASAPI_MANAGER_H_INCLUDED
#define WASAPI_MANAGER_H_INCLUDED
#include "pch.h"
#include "DeviceState.h"
#include "WASAPIRenderer.h"
#include "WASAPICapture.h"
#include "CBuffer.h"
#include "DeviceManager.h"
static const LPCWSTR g_FileName = L"Recording.wav";
struct ManagerStatus
{
bool bCapturing;
bool bPlaying;
bool bLoopback;
};
ref class WASAPIManager sealed
{
public:
WASAPIManager();
void StartDevice();
void RestartDevice();
void PlayPauseToggle();
void RecordToggle();
void LoopbackToggle();
void SetCaptureDevice(int index);
void UpdateStatus();
void OnRenderDeviceChange(Platform::Object^,
Windows::Media::Devices::DefaultAudioRenderDeviceChangedEventArgs^);
internal:
void GetStatus(ManagerStatus *inStatus);
//--------------------------------------------------------------------------------------
// Name: SetDeviceChangeCallback
// Desc: Sets the callback when capture devices change
//--------------------------------------------------------------------------------------
void SetDeviceChangeCallback(void (*inFunc)(int))
{
m_deviceManager.SetDeviceListReport(inFunc);
}
void GetCaptureDevices(std::vector<LPWSTR> &device)
{
m_deviceManager.GetCaptureDevices(device);
}
private:
~WASAPIManager();
void OnDeviceStateChange( Object^ sender, DeviceStateChangedEventArgs^ e );
void InitializeRenderDevice();
void InitializeCaptureDevice();
Windows::Foundation::EventRegistrationToken m_RenderDeviceStateChangeToken;
Windows::Foundation::EventRegistrationToken m_CaptureDeviceStateChangeToken;
DeviceStateChangedEvent^ m_RenderStateChangedEvent;
DeviceStateChangedEvent^ m_CaptureStateChangedEvent;
Microsoft::WRL::ComPtr<WASAPIRenderer> m_Renderer;
Microsoft::WRL::ComPtr<WASAPICapture> m_Capture;
Windows::Foundation::EventRegistrationToken m_renderEventToken;
DeviceManager m_deviceManager;
WAVEFORMATEX m_CaptureWfx;
WAVEFORMATEX m_RenderWfx;
bool m_bUseLoopback;
UINT m_CaptureIndex;
CBuffer* m_captureBuffer;
CRITICAL_SECTION m_CritSec;
ManagerStatus m_Status;
};
#endif