summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSamuel Mira <samuel.mira@qt.io>2022-04-29 18:18:24 +0300
committerSamuel Mira <samuel.mira@qt.io>2022-04-30 14:41:17 +0300
commit8713f2e78dddbbb4f8e58cf791a3033dbb6e38ad (patch)
tree9566a2d7bfc83067d4302c8b1f55798f0db8be68
parent00d031795a16dab01a076fc8b5b086c3b11b7684 (diff)
Android: Fix qopenslengine audioFormat conversion
This patch fixes the conversion audio format into SLFormat on qopenslengine. Previously the conversion did not take into account the sample format. To take it into account the SLDataFormat_PCM had to be changed to SLAndroidDataFormat_PCM_EX. Fixes: QTBUG-102962 Change-Id: I3699ee0cc939c46ad9ce8eae35c555ea9e8fc59f Reviewed-by: Assam Boudjelthia <assam.boudjelthia@qt.io> Reviewed-by: Lars Knoll <lars.knoll@qt.io> (cherry picked from commit 742344a6652ace697d188e52687d4ac340028ddd)
-rw-r--r--src/multimedia/platform/android/audio/qandroidaudiosink.cpp2
-rw-r--r--src/multimedia/platform/android/audio/qandroidaudiosource.cpp2
-rw-r--r--src/multimedia/platform/android/audio/qopenslesengine.cpp31
-rw-r--r--src/multimedia/platform/android/audio/qopenslesengine_p.h2
4 files changed, 28 insertions, 9 deletions
diff --git a/src/multimedia/platform/android/audio/qandroidaudiosink.cpp b/src/multimedia/platform/android/audio/qandroidaudiosink.cpp
index 1a0b622a3..bd7005a5b 100644
--- a/src/multimedia/platform/android/audio/qandroidaudiosink.cpp
+++ b/src/multimedia/platform/android/audio/qandroidaudiosink.cpp
@@ -361,7 +361,7 @@ bool QAndroidAudioSink::preparePlayer()
}
SLDataLocator_BufferQueue bufferQueueLocator = { SL_DATALOCATOR_BUFFERQUEUE, BUFFER_COUNT };
- SLDataFormat_PCM pcmFormat = QOpenSLESEngine::audioFormatToSLFormatPCM(m_format);
+ SLAndroidDataFormat_PCM_EX pcmFormat = QOpenSLESEngine::audioFormatToSLFormatPCM(m_format);
SLDataSource audioSrc = { &bufferQueueLocator, &pcmFormat };
diff --git a/src/multimedia/platform/android/audio/qandroidaudiosource.cpp b/src/multimedia/platform/android/audio/qandroidaudiosource.cpp
index c7eaf57ad..2f8d52830 100644
--- a/src/multimedia/platform/android/audio/qandroidaudiosource.cpp
+++ b/src/multimedia/platform/android/audio/qandroidaudiosource.cpp
@@ -220,7 +220,7 @@ bool QAndroidAudioSource::startRecording()
SLDataLocator_BufferQueue loc_bq = { SL_DATALOCATOR_BUFFERQUEUE, NUM_BUFFERS };
#endif
- SLDataFormat_PCM format_pcm = QOpenSLESEngine::audioFormatToSLFormatPCM(m_format);
+ SLAndroidDataFormat_PCM_EX format_pcm = QOpenSLESEngine::audioFormatToSLFormatPCM(m_format);
SLDataSink audioSnk = { &loc_bq, &format_pcm };
// create audio recorder
diff --git a/src/multimedia/platform/android/audio/qopenslesengine.cpp b/src/multimedia/platform/android/audio/qopenslesengine.cpp
index 7d207a369..8f6caa5e4 100644
--- a/src/multimedia/platform/android/audio/qopenslesengine.cpp
+++ b/src/multimedia/platform/android/audio/qopenslesengine.cpp
@@ -51,6 +51,8 @@
#define CheckError(message) if (result != SL_RESULT_SUCCESS) { qWarning(message); return; }
+#define SL_ANDROID_PCM_REPRESENTATION_INVALID 0
+
Q_GLOBAL_STATIC(QOpenSLESEngine, openslesEngine);
QOpenSLESEngine::QOpenSLESEngine()
@@ -81,12 +83,12 @@ QOpenSLESEngine *QOpenSLESEngine::instance()
return openslesEngine();
}
-SLDataFormat_PCM QOpenSLESEngine::audioFormatToSLFormatPCM(const QAudioFormat &format)
+SLAndroidDataFormat_PCM_EX QOpenSLESEngine::audioFormatToSLFormatPCM(const QAudioFormat &format)
{
- SLDataFormat_PCM format_pcm;
- format_pcm.formatType = SL_DATAFORMAT_PCM;
+ SLAndroidDataFormat_PCM_EX format_pcm;
+ format_pcm.formatType = SL_ANDROID_DATAFORMAT_PCM_EX;
format_pcm.numChannels = format.channelCount();
- format_pcm.samplesPerSec = format.sampleRate() * 1000;
+ format_pcm.sampleRate = format.sampleRate() * 1000;
format_pcm.bitsPerSample = format.bytesPerSample() * 8;
format_pcm.containerSize = format.bytesPerSample() * 8;
format_pcm.channelMask = (format.channelCount() == 1 ?
@@ -95,8 +97,25 @@ SLDataFormat_PCM QOpenSLESEngine::audioFormatToSLFormatPCM(const QAudioFormat &f
format_pcm.endianness = (QSysInfo::ByteOrder == QSysInfo::LittleEndian ?
SL_BYTEORDER_LITTLEENDIAN :
SL_BYTEORDER_BIGENDIAN);
- return format_pcm;
+ switch (format.sampleFormat()) {
+ case QAudioFormat::SampleFormat::UInt8:
+ format_pcm.representation = SL_ANDROID_PCM_REPRESENTATION_UNSIGNED_INT;
+ break;
+ case QAudioFormat::SampleFormat::Int16:
+ case QAudioFormat::SampleFormat::Int32:
+ format_pcm.representation = SL_ANDROID_PCM_REPRESENTATION_SIGNED_INT;
+ break;
+ case QAudioFormat::SampleFormat::Float:
+ format_pcm.representation = SL_ANDROID_PCM_REPRESENTATION_FLOAT;
+ break;
+ case QAudioFormat::SampleFormat::NSampleFormats:
+ case QAudioFormat::SampleFormat::Unknown:
+ format_pcm.representation = SL_ANDROID_PCM_REPRESENTATION_INVALID;
+ break;
+ }
+
+ return format_pcm;
}
QList<QAudioDevice> QOpenSLESEngine::availableDevices(QAudioDevice::Mode mode)
@@ -302,9 +321,9 @@ void QOpenSLESEngine::checkSupportedInputFormats()
defaultFormat.sampleRate = SL_SAMPLINGRATE_44_1;
defaultFormat.bitsPerSample = SL_PCMSAMPLEFORMAT_FIXED_32;
defaultFormat.containerSize = SL_PCMSAMPLEFORMAT_FIXED_32;
- defaultFormat.representation = SL_ANDROID_PCM_REPRESENTATION_FLOAT;
defaultFormat.channelMask = SL_ANDROID_MAKE_INDEXED_CHANNEL_MASK(SL_SPEAKER_FRONT_CENTER);
defaultFormat.endianness = SL_BYTEORDER_LITTLEENDIAN;
+ defaultFormat.representation = SL_ANDROID_PCM_REPRESENTATION_SIGNED_INT;
const SLuint32 rates[13] = { SL_SAMPLINGRATE_8,
SL_SAMPLINGRATE_11_025,
diff --git a/src/multimedia/platform/android/audio/qopenslesengine_p.h b/src/multimedia/platform/android/audio/qopenslesengine_p.h
index 36e994fb2..3adf34594 100644
--- a/src/multimedia/platform/android/audio/qopenslesengine_p.h
+++ b/src/multimedia/platform/android/audio/qopenslesengine_p.h
@@ -72,7 +72,7 @@ public:
SLEngineItf slEngine() const { return m_engine; }
- static SLDataFormat_PCM audioFormatToSLFormatPCM(const QAudioFormat &format);
+ static SLAndroidDataFormat_PCM_EX audioFormatToSLFormatPCM(const QAudioFormat &format);
static QList<QAudioDevice> availableDevices(QAudioDevice::Mode mode);
QList<int> supportedChannelCounts(QAudioDevice::Mode mode) const;