-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathAudioCapture.h
98 lines (81 loc) · 2.38 KB
/
AudioCapture.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
98
#ifndef AUDIOCAPTURE_H
#define AUDIOCAPTURE_H
#include <QMap>
#include <windows.h>
#include <QObject>
#include <initguid.h>
#include <mmdeviceapi.h>
#include <QThread>
class IMMDeviceEnumerator;
class IMMDevice;
class IAudioCaptureClient;
class IAudioClient;
class CaptureAudioThread: public QObject
{
Q_OBJECT
public:
CaptureAudioThread();
~CaptureAudioThread();
Q_INVOKABLE void start(IAudioClient*);
void stop();
bool isRunning() const;
private:
QThread *thread;
bool bRunning;
private:
inline void inspect(HRESULT hr);
signals:
void notifyData(const QByteArray &);
void stoped();
void error(HRESULT);
};
struct CaptureDevice{
QString name;
_EDataFlow type;
LPWSTR id;
};
class AudioCapture : public QObject,public IMMNotificationClient
{
Q_OBJECT
public:
explicit AudioCapture(QObject *parent = nullptr);
~AudioCapture();
Q_INVOKABLE void startCapture();
Q_INVOKABLE void stopCapture();
bool isRunning() const;
void flushDevices();
QList<CaptureDevice> getDevices() const;
QString getCurrentDevice() const;
QString getDeviceName(LPCWSTR id);
void setCurrentDevice(const QString &value);
protected:
//以下函数用于监视设备变化
ULONG STDMETHODCALLTYPE AddRef(){return 0;};
ULONG STDMETHODCALLTYPE Release(){return 0;};
HRESULT STDMETHODCALLTYPE QueryInterface(
REFIID, VOID**){return 0;}
HRESULT STDMETHODCALLTYPE OnDefaultDeviceChanged(
EDataFlow flow, ERole role,
LPCWSTR pwstrDeviceId);
HRESULT STDMETHODCALLTYPE OnDeviceAdded(LPCWSTR pwstrDeviceId);
HRESULT STDMETHODCALLTYPE OnDeviceRemoved(LPCWSTR pwstrDeviceId);
HRESULT STDMETHODCALLTYPE OnDeviceStateChanged(LPCWSTR, DWORD){return 0;}
HRESULT STDMETHODCALLTYPE OnPropertyValueChanged( LPCWSTR, const PROPERTYKEY){return 0;}
BOOL AdjustFormatTo16Bits(WAVEFORMATEX *pwfx);
private:
IMMDevice *pDevice;
IMMDeviceEnumerator *pInputEnumerator;
IMMDeviceEnumerator *pOutputEnumerator;
IAudioClient *pAudioClient;
WAVEFORMATEX *pwfx;
QList<CaptureDevice> devices;
QString currentDevice;
CaptureAudioThread thread;
private:
CaptureDevice* getDevice(QString name);
inline void inspect(HRESULT hr);
signals:
void notifyData(const QByteArray &);
void formatChanged(WAVEFORMATEX fromat);
};
#endif // QCAPTURE_H