-
Notifications
You must be signed in to change notification settings - Fork 341
/
audiooutputopensles.h
80 lines (63 loc) · 2.87 KB
/
audiooutputopensles.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
#ifndef AUDIOOUTPUTOPENSLES
#define AUDIOOUTPUTOPENSLES
#include <QMutex>
// For native audio
#include <SLES/OpenSLES.h>
#include <SLES/OpenSLES_Android.h>
#include <jni.h>
// MythTV headers
#include "audiooutputbase.h"
using slCreateEngine_t = SLresult (*)(
SLObjectItf*, SLuint32, const SLEngineOption*, SLuint32,
const SLInterfaceID*, const SLboolean*);
class AudioOutputOpenSLES : public AudioOutputBase
{
friend class AudioOutputOpenSLESPrivate;
public:
explicit AudioOutputOpenSLES(const AudioSettings &settings);
virtual ~AudioOutputOpenSLES();
// Volume control
int GetVolumeChannel(int channel) const override; // VolumeBase
void SetVolumeChannel(int channel, int volume) override; // VolumeBase
protected:
bool OpenDevice(void) override; // AudioOutputBase
void CloseDevice(void) override; // AudioOutputBase
void WriteAudio(unsigned char *aubuf, int size) override; // AudioOutputBase
int GetBufferedOnSoundcard(void) const override; // AudioOutputBase
AudioOutputSettings* GetOutputSettings(bool digital) override; // AudioOutputBase
private:
int GetNumberOfBuffersQueued() const;
//static const uint kPacketCnt;
bool CreateEngine();
static void SPlayedCallback(SLAndroidSimpleBufferQueueItf caller, void *pContext);
void PlayedCallback(SLAndroidSimpleBufferQueueItf caller);
bool StartPlayer();
bool Stop();
bool Open();
void Close();
private:
/* OpenSL objects */
SLObjectItf m_engineObject {nullptr};
SLObjectItf m_outputMixObject {nullptr};
SLAndroidSimpleBufferQueueItf m_playerBufferQueue {nullptr};
SLObjectItf m_playerObject {nullptr};
SLVolumeItf m_volumeItf {nullptr};
SLEngineItf m_engineEngine {nullptr};
SLPlayItf m_playerPlay {nullptr};
/* OpenSL symbols */
void *m_so_handle {nullptr};
slCreateEngine_t m_slCreateEnginePtr {nullptr};
SLInterfaceID m_SL_IID_ENGINE {nullptr};
SLInterfaceID m_SL_IID_ANDROIDSIMPLEBUFFERQUEUE {nullptr};
SLInterfaceID m_SL_IID_VOLUME {nullptr};
SLInterfaceID m_SL_IID_PLAY {nullptr};
/* audio buffered through opensles */
uint8_t *m_buf {nullptr};
int m_bufWriteBase {0}; // always fragment aligned
int m_bufWriteIndex {0}; // offset from base
/* if we can measure latency already */
bool m_started {false};
int m_nativeOutputSampleRate;
QMutex m_lock;
};
#endif // AUDIOOUTPUTOPENSLES