MythTV  master
audiooutputopensles.h
Go to the documentation of this file.
1 #ifndef AUDIOOUTPUTOPENSLES
2 #define AUDIOOUTPUTOPENSLES
3 
4 #include <QMutex>
5 // For native audio
6 #include <SLES/OpenSLES.h>
7 #include <SLES/OpenSLES_Android.h>
8 #include <jni.h>
9 
10 // MythTV headers
11 #include "audiooutputbase.h"
12 
13 using slCreateEngine_t = SLresult (*)(
14  SLObjectItf*, SLuint32, const SLEngineOption*, SLuint32,
15  const SLInterfaceID*, const SLboolean*);
16 
18 {
20  public:
21  explicit AudioOutputOpenSLES(const AudioSettings &settings);
22  virtual ~AudioOutputOpenSLES();
23 
24  // Volume control
25  int GetVolumeChannel(int channel) const override; // VolumeBase
26  void SetVolumeChannel(int channel, int volume) override; // VolumeBase
27 
28  protected:
29  bool OpenDevice(void) override; // AudioOutputBase
30  void CloseDevice(void) override; // AudioOutputBase
31  void WriteAudio(unsigned char *aubuf, int size) override; // AudioOutputBase
32  int GetBufferedOnSoundcard(void) const override; // AudioOutputBase
33  AudioOutputSettings* GetOutputSettings(bool digital) override; // AudioOutputBase
34 
35  private:
36  int GetNumberOfBuffersQueued() const;
37 
38  //static const uint kPacketCnt;
39 
40  bool CreateEngine();
41  static void SPlayedCallback(SLAndroidSimpleBufferQueueItf caller, void *pContext);
42  void PlayedCallback(SLAndroidSimpleBufferQueueItf caller);
43  bool StartPlayer();
44  bool Stop();
45  bool Open();
46  void Close();
47 
48  private:
49  /* OpenSL objects */
50  SLObjectItf m_engineObject {nullptr};
51  SLObjectItf m_outputMixObject {nullptr};
52  SLAndroidSimpleBufferQueueItf m_playerBufferQueue {nullptr};
53  SLObjectItf m_playerObject {nullptr};
54  SLVolumeItf m_volumeItf {nullptr};
55  SLEngineItf m_engineEngine {nullptr};
56  SLPlayItf m_playerPlay {nullptr};
57 
58  /* OpenSL symbols */
59  void *m_so_handle {nullptr};
60 
62  SLInterfaceID m_SL_IID_ENGINE {nullptr};
63  SLInterfaceID m_SL_IID_ANDROIDSIMPLEBUFFERQUEUE {nullptr};
64  SLInterfaceID m_SL_IID_VOLUME {nullptr};
65  SLInterfaceID m_SL_IID_PLAY {nullptr};
66 
67  /* audio buffered through opensles */
68  uint8_t *m_buf {nullptr};
69  int m_bufWriteBase {0}; // always fragment aligned
70  int m_bufWriteIndex {0}; // offset from base
71 
72  /* if we can measure latency already */
73  bool m_started {false};
75 
76  QMutex m_lock;
77 
78 };
79 
80 #endif // AUDIOOUTPUTOPENSLES
SLInterfaceID m_SL_IID_ENGINE
void PlayedCallback(SLAndroidSimpleBufferQueueItf caller)
bool OpenDevice(void) override
SLresult(*)(SLObjectItf *, SLuint32, const SLEngineOption *, SLuint32, const SLInterfaceID *, const SLboolean *) slCreateEngine_t
slCreateEngine_t m_slCreateEnginePtr
void CloseDevice(void) override
void WriteAudio(unsigned char *aubuf, int size) override
int GetBufferedOnSoundcard(void) const override
Return the size in bytes of frames currently in the audio buffer adjusted with the audio playback lat...
static void SPlayedCallback(SLAndroidSimpleBufferQueueItf caller, void *pContext)
friend class AudioOutputOpenSLESPrivate
SLInterfaceID m_SL_IID_PLAY
void SetVolumeChannel(int channel, int volume) override
SLInterfaceID m_SL_IID_VOLUME
SLAndroidSimpleBufferQueueItf m_playerBufferQueue
SLInterfaceID m_SL_IID_ANDROIDSIMPLEBUFFERQUEUE
int GetVolumeChannel(int channel) const override
AudioOutputOpenSLES(const AudioSettings &settings)
AudioOutputSettings * GetOutputSettings(bool digital) override
int GetNumberOfBuffersQueued() const