Go to the documentation of this file. 1 #include <QAndroidJniObject>
2 #include <QAndroidJniEnvironment>
3 #include <android/log.h>
11 #define ANDROID_EXCEPTION_CHECK \
12 if (env->ExceptionCheck()) { \
13 env->ExceptionDescribe(); \
14 env->ExceptionClear(); \
19 #define ANDROID_EXCEPTION_CLEAR \
20 if (env->ExceptionCheck()) { \
21 env->ExceptionDescribe(); \
22 env->ExceptionClear(); \
25 #define LOC QString("AudioTrack: ")
29 #define AF_CHANNEL_OUT_MONO 4
30 #define AF_ENCODING_AC3 5
31 #define AF_ENCODING_E_AC3 6
32 #define AF_ENCODING_DTS 7
33 #define AF_ENCODING_DOLBY_TRUEHD 14
34 #define AF_ENCODING_PCM_8BIT 3
35 #define AF_ENCODING_PCM_16BIT 2
36 #define AF_ENCODING_PCM_FLOAT 4
39 #include <android/log.h>
57 QAndroidJniEnvironment env;
84 case AV_CODEC_ID_EAC3:
87 case AV_CODEC_ID_TRUEHD:
92 LOG(VB_GENERAL, LOG_ERR,
LOC + __func__ + QString(
" No support for audio passthru encoding %1").arg(
m_codec));
113 LOG(VB_GENERAL, LOG_ERR,
LOC + __func__ + QString(
" No support for audio format %1").arg(
m_outputFormat));
122 m_audioTrack =
new QAndroidJniObject(
"org/mythtv/audio/AudioOutputAudioTrack",
123 "(IIII)V", encoding, sampleRate, minBufferSize, channels);
128 LOG(VB_GENERAL, LOG_ERR,
LOC + __func__ + QString(
" Java Exception when creating AudioTrack"));
135 m_audioTrack->callMethod<
void>(
"setBitsPer10Frames",
"(I)V",bitsPer10Frames);
142 QAndroidJniEnvironment env;
154 bool exception=
false;
155 QAndroidJniEnvironment env;
160 int supportedrate = 0;
165 bufsize = QAndroidJniObject::callStaticMethod<jint>
166 (
"android/media/AudioTrack",
"getMinBufferSize",
"(III)I",
169 if (bufsize > 0 && !exception)
173 supportedrate = rate;
178 bufsize = QAndroidJniObject::callStaticMethod<jint>
179 (
"android/media/AudioTrack",
"getMinBufferSize",
"(III)I",
182 if (bufsize > 0 && !exception)
187 bufsize = QAndroidJniObject::callStaticMethod<jint>
188 (
"android/media/AudioTrack",
"getMinBufferSize",
"(III)I",
191 if (bufsize > 0 && !exception)
205 bool exception=
false;
206 QAndroidJniEnvironment env;
211 jboolean param =
true;
218 jbyteArray arr = env->NewByteArray(size);
219 env->SetByteArrayRegion(arr, 0, size,
reinterpret_cast<jbyte*
>(aubuf));
223 ret =
m_audioTrack->callMethod<jint>(
"write",
"([BI)I", arr, size);
226 env->DeleteLocalRef(arr);
227 if (ret != size || exception)
228 LOG(VB_GENERAL, LOG_ERR,
LOC + __func__
229 + QString(
" Audio Write failed, size %1 return %2 exception %3")
230 .arg(size).arg(ret).arg(exception));
232 LOG(VB_AUDIO | VB_TIMESTAMP, LOG_INFO,
LOC + __func__
233 + QString(
" WriteAudio size=%1 written=%2")
234 .arg(size).arg(ret));
240 QAndroidJniEnvironment env;
248 bool exception=
false;
253 =
m_audioTrack->callMethod<jint>(
"getLatencyViaHeadPosition");
264 std::chrono::milliseconds timecode,
int in_frames)
267 (in_buffer, in_len, timecode,in_frames);
277 jboolean param = paused;
291 m_audioTrack->callMethod<
void>(
"setBitsPer10Frames",
"(I)V",bitsPer10Frames);
297 QAndroidJniEnvironment env;
300 m_audioTrack->callMethod<
void>(
"setOutputThread",
"(Z)V",
true);
309 QAndroidJniEnvironment env;
312 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)
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
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.