forked from microsoft/Xbox-ATG-Samples
-
Notifications
You must be signed in to change notification settings - Fork 0
/
WASAPICapture.h
69 lines (55 loc) · 2.35 KB
/
WASAPICapture.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
//--------------------------------------------------------------------------------------
// WASAPICapture.h
//
// Functions to assist in capturing audio in WASAPI
//
// Advanced Technology Group (ATG)
// Copyright (C) Microsoft Corporation. All rights reserved.
//--------------------------------------------------------------------------------------
#include <Windows.h>
#include <wrl\implements.h>
#include <mfapi.h>
#include <AudioClient.h>
#include <mmdeviceapi.h>
#include <mftransform.h>
#include "DeviceState.h"
#include "Common.h"
#include "CBuffer.h"
#include <mutex>
#pragma once
// Primary WASAPI Capture Class
class WASAPICapture :
public Microsoft::WRL::RuntimeClass< Microsoft::WRL::RuntimeClassFlags< Microsoft::WRL::ClassicCom >, Microsoft::WRL::FtmBase, IActivateAudioInterfaceCompletionHandler >
{
public:
WASAPICapture();
HRESULT InitializeAudioDeviceAsync(Platform::String^ deviceIdString);
HRESULT StartCaptureAsync(CBuffer* bufferToUse);
HRESULT StopCaptureAsync();
DeviceStateChangedEvent^ GetDeviceStateEvent() { return m_deviceStateChanged; };
WAVEFORMATEX* GetMixFormat() { return m_mixFormat; }
METHODASYNCCALLBACK( WASAPICapture, StartCapture, OnStartCapture );
METHODASYNCCALLBACK( WASAPICapture, StopCapture, OnStopCapture );
METHODASYNCCALLBACK( WASAPICapture, SampleReady, OnSampleReady );
// IActivateAudioInterfaceCompletionHandler
STDMETHOD(ActivateCompleted)( IActivateAudioInterfaceAsyncOperation *operation );
private:
~WASAPICapture();
HRESULT OnStartCapture( IMFAsyncResult* );
HRESULT OnStopCapture( IMFAsyncResult* );
HRESULT OnSampleReady( IMFAsyncResult* );
HRESULT OnAudioSampleRequested( bool isSilence = false );
private:
uint32_t m_bufferFrames;
HANDLE m_sampleReadyEvent;
MFWORKITEM_KEY m_sampleReadyKey;
std::mutex m_mutex;
DWORD m_queueID;
CBuffer* m_buffer;
WAVEFORMATEX* m_mixFormat;
Microsoft::WRL::ComPtr<IAudioClient> m_audioClient;
Microsoft::WRL::ComPtr<IAudioCaptureClient> m_audioCaptureClient;
Microsoft::WRL::ComPtr<IMFAsyncResult> m_sampleReadyAsyncResult;
Microsoft::WRL::ComPtr<IMFTransform> m_resampler;
DeviceStateChangedEvent^ m_deviceStateChanged;
};