Go to the documentation of this file.
2 #if QT_VERSION < QT_VERSION_CHECK(6,0,0)
3 #include <QAndroidJniObject>
4 #include <QAndroidJniEnvironment>
6 #include <QJniEnvironment>
8 #define QAndroidJniEnvironment QJniEnvironment
9 #define QAndroidJniObject QJniObject
11 #include <android/log.h>
16 #define CHANNELS_MIN 1
17 #define CHANNELS_MAX 8
19 #define ANDROID_EXCEPTION_CHECK \
20 if (env->ExceptionCheck()) { \
21 env->ExceptionDescribe(); \
22 env->ExceptionClear(); \
27 #define ANDROID_EXCEPTION_CLEAR \
28 if (env->ExceptionCheck()) { \
29 env->ExceptionDescribe(); \
30 env->ExceptionClear(); \
33 #define LOC QString("AudioTrack: ")
37 #define AF_CHANNEL_OUT_MONO 4
38 #define AF_ENCODING_AC3 5
39 #define AF_ENCODING_E_AC3 6
40 #define AF_ENCODING_DTS 7
41 #define AF_ENCODING_DOLBY_TRUEHD 14
42 #define AF_ENCODING_PCM_8BIT 3
43 #define AF_ENCODING_PCM_16BIT 2
44 #define AF_ENCODING_PCM_FLOAT 4
47 #include <android/log.h>
92 case AV_CODEC_ID_EAC3:
95 case AV_CODEC_ID_TRUEHD:
100 LOG(VB_GENERAL, LOG_ERR,
LOC + __func__ + QString(
" No support for audio passthru encoding %1").arg(
m_codec));
121 LOG(VB_GENERAL, LOG_ERR,
LOC + __func__ + QString(
" No support for audio format %1").arg(
m_outputFormat));
131 "(IIII)V", encoding, sampleRate, minBufferSize, channels);
136 LOG(VB_GENERAL, LOG_ERR,
LOC + __func__ + QString(
" Java Exception when creating AudioTrack"));
143 m_audioTrack->callMethod<
void>(
"setBitsPer10Frames",
"(I)V",bitsPer10Frames);
162 bool exception=
false;
168 int supportedrate = 0;
173 bufsize = QAndroidJniObject::callStaticMethod<jint>
174 (
"android/media/AudioTrack",
"getMinBufferSize",
"(III)I",
177 if (bufsize > 0 && !exception)
181 supportedrate = rate;
186 bufsize = QAndroidJniObject::callStaticMethod<jint>
187 (
"android/media/AudioTrack",
"getMinBufferSize",
"(III)I",
190 if (bufsize > 0 && !exception)
195 bufsize = QAndroidJniObject::callStaticMethod<jint>
196 (
"android/media/AudioTrack",
"getMinBufferSize",
"(III)I",
199 if (bufsize > 0 && !exception)
213 bool exception=
false;
219 jboolean param =
true;
226 jbyteArray arr = env->NewByteArray(size);
227 env->SetByteArrayRegion(arr, 0, size,
reinterpret_cast<jbyte*
>(aubuf));
231 ret =
m_audioTrack->callMethod<jint>(
"write",
"([BI)I", arr, size);
234 env->DeleteLocalRef(arr);
235 if (ret != size || exception)
236 LOG(VB_GENERAL, LOG_ERR,
LOC + __func__
237 + QString(
" Audio Write failed, size %1 return %2 exception %3")
238 .arg(size).arg(ret).arg(exception));
240 LOG(VB_AUDIO | VB_TIMESTAMP, LOG_INFO,
LOC + __func__
241 + QString(
" WriteAudio size=%1 written=%2")
242 .arg(size).arg(ret));
256 bool exception=
false;
261 =
m_audioTrack->callMethod<jint>(
"getLatencyViaHeadPosition");
272 std::chrono::milliseconds timecode,
int in_frames)
275 (in_buffer, in_len, timecode,in_frames);
285 jboolean param = paused;
299 m_audioTrack->callMethod<
void>(
"setBitsPer10Frames",
"(I)V",bitsPer10Frames);
308 m_audioTrack->callMethod<
void>(
"setOutputThread",
"(Z)V",
true);
320 m_audioTrack->callMethod<
void>(
"setOutputThread",
"(Z)V",
false);
#define AF_CHANNEL_OUT_MONO
void Pause(bool paused) override
bool AddData(void *buffer, int len, std::chrono::milliseconds timecode, int frames) override
Add data to the audiobuffer and perform any required processing.
void setPassthrough(int val)
#define QAndroidJniEnvironment
void AddSupportedFormat(AudioFormat format)
#define AF_ENCODING_PCM_FLOAT
QAndroidJniObject * m_audioTrack
bool StartOutputThread(void) override
void KillAudio(void)
Kill the output thread and cleanup.
int GetBufferedOnSoundcard(void) const override
Return the size in bytes of frames currently in the audio buffer adjusted with the audio playback lat...
#define LOG(_MASK_, _LEVEL_, _QSTRING_)
#define AF_ENCODING_PCM_8BIT
void AddSupportedChannels(int channels)
void SetSourceBitrate(int rate) override
#define QAndroidJniObject
long m_soundcardBufferSize
bool m_init
If set to false, AudioOutput instance will not try to initially open the audio device.
#define AF_ENCODING_E_AC3
virtual void StopOutputThread(void)
void Reconfigure(const AudioSettings &settings) override
(Re)Configure AudioOutputBase
void WriteAudio(unsigned char *aubuf, int size) override
bool OpenDevice(void) override
#define ANDROID_EXCEPTION_CLEAR
void AddSupportedRate(int rate)
bool AddData(void *buffer, int len, std::chrono::milliseconds timecode, int frames) override
Add data to the audiobuffer for playback.
AudioFormat m_outputFormat
AudioOutputAudioTrack(const AudioSettings &settings)
int m_outputBytesPerFrame
void StopOutputThread(void) override
~AudioOutputAudioTrack() override
#define AF_ENCODING_DOLBY_TRUEHD
void InitSettings(const AudioSettings &settings)
void Pause(bool paused) override
virtual bool StartOutputThread(void)
#define AF_ENCODING_PCM_16BIT
AudioOutputSettings * GetOutputSettings(bool digital) override
#define ANDROID_EXCEPTION_CHECK
void CloseDevice(void) override
void SetSourceBitrate(int rate) override
Set the bitrate of the source material, reported in periodic OutputEvents.