blob: 2617ca4213ce5ecad308f24014da5ea2c608a5cc (
plain)
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
99
100
101
102
103
104
105
106
107
108
109
|
#pragma once
#include "DspChunk.h"
#include "DspFormat.h"
namespace SaneAudioRenderer
{
struct AudioDeviceBackend final
{
SharedString id;
SharedString adapterName;
SharedString endpointName;
UINT32 endpointFormFactor;
bool supportsSharedEventMode;
bool supportsExclusiveEventMode;
IAudioClientPtr audioClient;
IAudioRenderClientPtr audioRenderClient;
IAudioClockPtr audioClock;
SharedWaveFormat mixFormat;
SharedWaveFormat waveFormat;
DspFormat dspFormat;
uint32_t bufferDuration;
REFERENCE_TIME deviceLatency;
UINT32 deviceBufferSize;
bool exclusive;
bool bitstream;
bool eventMode;
bool realtime;
bool ignoredSystemChannelMixer;
};
class AudioDevice
{
public:
virtual ~AudioDevice() = default;
virtual void Push(DspChunk& chunk, CAMEvent* pFilledEvent) = 0;
virtual REFERENCE_TIME Finish(CAMEvent* pFilledEvent) = 0;
virtual int64_t GetPosition() = 0;
virtual int64_t GetEnd() = 0;
virtual int64_t GetSilence() = 0;
virtual void Start() = 0;
virtual void Stop() = 0;
virtual void Reset() = 0;
SharedString GetId() const { return m_backend->id; }
SharedString GetAdapterName() const { return m_backend->adapterName; }
SharedString GetEndpointName() const { return m_backend->endpointName; }
IAudioClockPtr GetClock() { return m_backend->audioClock; }
SharedWaveFormat GetMixFormat() const { return m_backend->mixFormat; }
SharedWaveFormat GetWaveFormat() const { return m_backend->waveFormat; }
DspFormat GetDspFormat() const { return m_backend->dspFormat; }
uint32_t GetBufferDuration() const { return m_backend->bufferDuration; }
REFERENCE_TIME GetStreamLatency() const { return m_backend->deviceLatency; }
bool IsExclusive() const { return m_backend->exclusive; }
bool IgnoredSystemChannelMixer() const { return m_backend->ignoredSystemChannelMixer; }
using RenewBackendFunction = std::function<bool(std::shared_ptr<AudioDeviceBackend>&)>;
virtual bool RenewInactive(const RenewBackendFunction& renewBackend, int64_t& position) = 0;
protected:
std::shared_ptr<AudioDeviceBackend> m_backend;
template <class T>
bool IsLastInstance(T& smartPointer)
{
bool ret = (smartPointer.GetInterfacePtr()->AddRef() == 2);
smartPointer.GetInterfacePtr()->Release();
return ret;
}
bool CheckLastInstances()
{
if (!m_backend.unique())
return false;
if (m_backend->audioClock && !IsLastInstance(m_backend->audioClock))
return false;
m_backend->audioClock = nullptr;
if (m_backend->audioRenderClient && !IsLastInstance(m_backend->audioRenderClient))
return false;
m_backend->audioRenderClient = nullptr;
if (m_backend->audioClient && !IsLastInstance(m_backend->audioClient))
return false;
return true;
}
};
}
|