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
AudioOutputOpenSLES::m_engineObject
SLObjectItf m_engineObject
Definition: audiooutputopensles.h:50
channel
QDomElement channel
Definition: mythplugins/mytharchive/mytharchivehelper/main.cpp:498
AudioOutputOpenSLES::m_SL_IID_ANDROIDSIMPLEBUFFERQUEUE
SLInterfaceID m_SL_IID_ANDROIDSIMPLEBUFFERQUEUE
Definition: audiooutputopensles.h:63
AudioOutputOpenSLES::GetOutputSettings
AudioOutputSettings * GetOutputSettings(bool digital) override
Definition: audiooutputopensles.cpp:338
AudioOutputOpenSLES::m_slCreateEnginePtr
slCreateEngine_t m_slCreateEnginePtr
Definition: audiooutputopensles.h:61
AudioOutputOpenSLES::GetNumberOfBuffersQueued
int GetNumberOfBuffersQueued() const
Definition: audiooutputopensles.cpp:407
AudioOutputOpenSLES::GetVolumeChannel
int GetVolumeChannel(int channel) const override
Definition: audiooutputopensles.cpp:480
AudioOutputOpenSLES::m_outputMixObject
SLObjectItf m_outputMixObject
Definition: audiooutputopensles.h:51
AudioOutputOpenSLES::m_bufWriteIndex
int m_bufWriteIndex
Definition: audiooutputopensles.h:70
AudioOutputOpenSLES::GetBufferedOnSoundcard
int GetBufferedOnSoundcard(void) const override
Return the size in bytes of frames currently in the audio buffer adjusted with the audio playback lat...
Definition: audiooutputopensles.cpp:470
slCreateEngine_t
SLresult(*)(SLObjectItf *, SLuint32, const SLEngineOption *, SLuint32, const SLInterfaceID *, const SLboolean *) slCreateEngine_t
Definition: audiooutputopensles.h:15
AudioOutputOpenSLES::OpenDevice
bool OpenDevice(void) override
Definition: audiooutputopensles.cpp:364
AudioOutputOpenSLES::m_SL_IID_PLAY
SLInterfaceID m_SL_IID_PLAY
Definition: audiooutputopensles.h:65
AudioOutputOpenSLES::SPlayedCallback
static void SPlayedCallback(SLAndroidSimpleBufferQueueItf caller, void *pContext)
Definition: audiooutputopensles.cpp:391
AudioSettings
Definition: audiosettings.h:29
AudioOutputOpenSLES::m_volumeItf
SLVolumeItf m_volumeItf
Definition: audiooutputopensles.h:54
AudioOutputOpenSLES::AudioOutputOpenSLES
AudioOutputOpenSLES(const AudioSettings &settings)
Definition: audiooutputopensles.cpp:322
AudioOutputBase
Definition: audiooutputbase.h:50
AudioOutputOpenSLES::PlayedCallback
void PlayedCallback(SLAndroidSimpleBufferQueueItf caller)
Definition: audiooutputopensles.cpp:396
AudioOutputOpenSLES::m_SL_IID_VOLUME
SLInterfaceID m_SL_IID_VOLUME
Definition: audiooutputopensles.h:64
AudioOutputOpenSLES::Stop
bool Stop()
Definition: audiooutputopensles.cpp:267
AudioOutputOpenSLES
Definition: audiooutputopensles.h:18
AudioOutputOpenSLES::m_started
bool m_started
Definition: audiooutputopensles.h:73
AudioOutputOpenSLES::CreateEngine
bool CreateEngine()
Definition: audiooutputopensles.cpp:84
AudioOutputOpenSLES::AudioOutputOpenSLESPrivate
friend class AudioOutputOpenSLESPrivate
Definition: audiooutputopensles.h:19
AudioOutputOpenSLES::~AudioOutputOpenSLES
virtual ~AudioOutputOpenSLES()
Definition: audiooutputopensles.cpp:331
AudioOutputOpenSLES::CloseDevice
void CloseDevice(void) override
Definition: audiooutputopensles.cpp:385
audiooutputbase.h
AudioOutputOpenSLES::m_lock
QMutex m_lock
Definition: audiooutputopensles.h:76
AudioOutputOpenSLES::m_bufWriteBase
int m_bufWriteBase
Definition: audiooutputopensles.h:69
AudioOutputSettings
Definition: audiooutputsettings.h:53
AudioOutputOpenSLES::m_SL_IID_ENGINE
SLInterfaceID m_SL_IID_ENGINE
Definition: audiooutputopensles.h:62
AudioOutputOpenSLES::Close
void Close()
Definition: audiooutputopensles.cpp:300
AudioOutputOpenSLES::StartPlayer
bool StartPlayer()
Definition: audiooutputopensles.cpp:147
AudioOutputOpenSLES::m_engineEngine
SLEngineItf m_engineEngine
Definition: audiooutputopensles.h:55
AudioOutputOpenSLES::m_playerPlay
SLPlayItf m_playerPlay
Definition: audiooutputopensles.h:56
AudioOutputOpenSLES::Open
bool Open()
Definition: audiooutputopensles.cpp:286
AudioOutputOpenSLES::m_playerObject
SLObjectItf m_playerObject
Definition: audiooutputopensles.h:53
AudioOutputOpenSLES::m_playerBufferQueue
SLAndroidSimpleBufferQueueItf m_playerBufferQueue
Definition: audiooutputopensles.h:52
AudioOutputOpenSLES::WriteAudio
void WriteAudio(unsigned char *aubuf, int size) override
Definition: audiooutputopensles.cpp:419
AudioOutputOpenSLES::m_nativeOutputSampleRate
int m_nativeOutputSampleRate
Definition: audiooutputopensles.h:74
AudioOutputOpenSLES::SetVolumeChannel
void SetVolumeChannel(int channel, int volume) override
Definition: audiooutputopensles.cpp:507
AudioOutputOpenSLES::m_buf
uint8_t * m_buf
Definition: audiooutputopensles.h:68
AudioOutputOpenSLES::m_so_handle
void * m_so_handle
Definition: audiooutputopensles.h:59