Fix some failing QAudioInput integration tests on OSX.
This also meant implementing software volume support, and since this is the last backend to do so, make that interface pure virtual again. In some cases the test needed tweaks. Change-Id: Ie429863f187b43802cdd4f16d841929e0cb0e729 Reviewed-by: Kurt Korbatits <kurt.korbatits@nokia.com> Reviewed-by: Dmytro Poplavskiy <dmytro.poplavskiy@nokia.com>
This commit is contained in:
committed by
Qt by Nokia
parent
42cdb92543
commit
d67f9dba56
@@ -106,6 +106,8 @@ public:
|
||||
QAudio::State state() const { return QAudio::StoppedState; }
|
||||
void setFormat(const QAudioFormat&) {}
|
||||
QAudioFormat format() const { return QAudioFormat(); }
|
||||
void setVolume(qreal) {}
|
||||
qreal volume() const {return 1.0f;}
|
||||
};
|
||||
|
||||
class QNullOutputDevice : public QAbstractAudioOutput
|
||||
|
||||
@@ -59,6 +59,7 @@
|
||||
#include "qaudio_mac_p.h"
|
||||
#include "qaudioinput_mac_p.h"
|
||||
#include "qaudiodeviceinfo_mac_p.h"
|
||||
#include "qaudiohelpers_p.h"
|
||||
|
||||
QT_BEGIN_NAMESPACE
|
||||
|
||||
@@ -235,7 +236,8 @@ public:
|
||||
m_deviceError(false),
|
||||
m_audioConverter(0),
|
||||
m_inputFormat(inputFormat),
|
||||
m_outputFormat(outputFormat)
|
||||
m_outputFormat(outputFormat),
|
||||
m_volume(qreal(1.0f))
|
||||
{
|
||||
m_maxPeriodSize = maxPeriodSize;
|
||||
m_periodTime = m_maxPeriodSize / m_outputFormat.mBytesPerFrame * 1000 / m_outputFormat.mSampleRate;
|
||||
@@ -253,6 +255,8 @@ public:
|
||||
m_audioConverter = 0;
|
||||
}
|
||||
}
|
||||
|
||||
m_qFormat = toQAudioFormat(inputFormat); // we adjust volume before conversion
|
||||
}
|
||||
|
||||
~QAudioInputBuffer()
|
||||
@@ -260,6 +264,16 @@ public:
|
||||
delete m_buffer;
|
||||
}
|
||||
|
||||
qreal volume() const
|
||||
{
|
||||
return m_volume;
|
||||
}
|
||||
|
||||
void setVolume(qreal v)
|
||||
{
|
||||
m_volume = v;
|
||||
}
|
||||
|
||||
qint64 renderFromDevice(AudioUnit audioUnit,
|
||||
AudioUnitRenderActionFlags* ioActionFlags,
|
||||
const AudioTimeStamp* inTimeStamp,
|
||||
@@ -279,6 +293,15 @@ public:
|
||||
inNumberFrames,
|
||||
m_inputBufferList->audioBufferList());
|
||||
|
||||
// adjust volume, if necessary
|
||||
if (!qFuzzyCompare(m_volume, qreal(1.0f))) {
|
||||
QAudioHelperInternal::qMultiplySamples(m_volume,
|
||||
m_qFormat,
|
||||
m_inputBufferList->data(), /* input */
|
||||
m_inputBufferList->data(), /* output */
|
||||
m_inputBufferList->bufferSize());
|
||||
}
|
||||
|
||||
if (m_audioConverter != 0) {
|
||||
QAudioPacketFeeder feeder(m_inputBufferList);
|
||||
|
||||
@@ -452,6 +475,8 @@ private:
|
||||
AudioConverterRef m_audioConverter;
|
||||
AudioStreamBasicDescription m_inputFormat;
|
||||
AudioStreamBasicDescription m_outputFormat;
|
||||
QAudioFormat m_qFormat;
|
||||
qreal m_volume;
|
||||
|
||||
const static OSStatus as_empty = 'qtem';
|
||||
|
||||
@@ -535,6 +560,8 @@ QAudioInputPrivate::QAudioInputPrivate(const QByteArray& device)
|
||||
errorCode = QAudio::NoError;
|
||||
stateCode = QAudio::StoppedState;
|
||||
|
||||
m_volume = qreal(1.0f);
|
||||
|
||||
intervalTimer = new QTimer(this);
|
||||
intervalTimer->setInterval(1000);
|
||||
connect(intervalTimer, SIGNAL(timeout()), SIGNAL(notify()));
|
||||
@@ -709,6 +736,7 @@ bool QAudioInputPrivate::open()
|
||||
streamFormat,
|
||||
this);
|
||||
|
||||
audioBuffer->setVolume(m_volume);
|
||||
audioIO = new QtMultimediaInternal::MacInputDevice(audioBuffer, this);
|
||||
|
||||
// Init
|
||||
@@ -765,11 +793,11 @@ void QAudioInputPrivate::start(QIODevice* device)
|
||||
startTime = AudioGetCurrentHostTime();
|
||||
totalFrames = 0;
|
||||
|
||||
audioThreadStart();
|
||||
|
||||
stateCode = QAudio::ActiveState;
|
||||
stateCode = QAudio::IdleState;
|
||||
errorCode = QAudio::NoError;
|
||||
emit stateChanged(stateCode);
|
||||
|
||||
audioThreadStart();
|
||||
}
|
||||
|
||||
QIODevice* QAudioInputPrivate::start()
|
||||
@@ -793,12 +821,12 @@ QIODevice* QAudioInputPrivate::start()
|
||||
startTime = AudioGetCurrentHostTime();
|
||||
totalFrames = 0;
|
||||
|
||||
audioThreadStart();
|
||||
|
||||
stateCode = QAudio::ActiveState;
|
||||
stateCode = QAudio::IdleState;
|
||||
errorCode = QAudio::NoError;
|
||||
emit stateChanged(stateCode);
|
||||
|
||||
audioThreadStart();
|
||||
|
||||
return op;
|
||||
}
|
||||
|
||||
@@ -823,6 +851,7 @@ void QAudioInputPrivate::reset()
|
||||
|
||||
errorCode = QAudio::NoError;
|
||||
stateCode = QAudio::StoppedState;
|
||||
audioBuffer->reset();
|
||||
QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode));
|
||||
}
|
||||
}
|
||||
@@ -853,6 +882,8 @@ void QAudioInputPrivate::resume()
|
||||
|
||||
int QAudioInputPrivate::bytesReady() const
|
||||
{
|
||||
if (!audioBuffer)
|
||||
return 0;
|
||||
return audioBuffer->used();
|
||||
}
|
||||
|
||||
@@ -910,6 +941,19 @@ QAudio::State QAudioInputPrivate::state() const
|
||||
return stateCode;
|
||||
}
|
||||
|
||||
qreal QAudioInputPrivate::volume() const
|
||||
{
|
||||
return m_volume;
|
||||
}
|
||||
|
||||
void QAudioInputPrivate::setVolume(qreal volume)
|
||||
{
|
||||
m_volume = volume;
|
||||
if (audioBuffer)
|
||||
audioBuffer->setVolume(m_volume);
|
||||
}
|
||||
|
||||
|
||||
void QAudioInputPrivate::audioThreadStop()
|
||||
{
|
||||
stopTimers();
|
||||
@@ -931,15 +975,22 @@ void QAudioInputPrivate::audioDeviceStop()
|
||||
threadFinished.wakeOne();
|
||||
}
|
||||
|
||||
void QAudioInputPrivate::audioDeviceActive()
|
||||
{
|
||||
QMutexLocker lock(&mutex);
|
||||
if (stateCode == QAudio::IdleState) {
|
||||
stateCode = QAudio::ActiveState;
|
||||
QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode));
|
||||
}
|
||||
}
|
||||
|
||||
void QAudioInputPrivate::audioDeviceFull()
|
||||
{
|
||||
QMutexLocker lock(&mutex);
|
||||
if (stateCode == QAudio::ActiveState) {
|
||||
audioDeviceStop();
|
||||
|
||||
errorCode = QAudio::UnderrunError;
|
||||
stateCode = QAudio::IdleState;
|
||||
QMetaObject::invokeMethod(this, "deviceStopped", Qt::QueuedConnection);
|
||||
QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -998,9 +1049,10 @@ OSStatus QAudioInputPrivate::inputCallback(void* inRefCon,
|
||||
inBusNumber,
|
||||
inNumberFrames);
|
||||
|
||||
if (framesWritten > 0)
|
||||
if (framesWritten > 0) {
|
||||
d->totalFrames += framesWritten;
|
||||
else if (framesWritten == 0)
|
||||
d->audioDeviceActive();
|
||||
} else if (framesWritten == 0)
|
||||
d->audioDeviceFull();
|
||||
else if (framesWritten < 0)
|
||||
d->audioDeviceError();
|
||||
|
||||
@@ -109,6 +109,7 @@ public:
|
||||
AudioStreamBasicDescription streamFormat;
|
||||
AudioStreamBasicDescription deviceFormat;
|
||||
QAbstractAudioDeviceInfo *audioDeviceInfo;
|
||||
qreal m_volume;
|
||||
|
||||
QAudioInputPrivate(const QByteArray& device);
|
||||
~QAudioInputPrivate();
|
||||
@@ -142,10 +143,14 @@ public:
|
||||
QAudio::Error error() const;
|
||||
QAudio::State state() const;
|
||||
|
||||
qreal volume() const;
|
||||
void setVolume(qreal volume);
|
||||
|
||||
void audioThreadStart();
|
||||
void audioThreadStop();
|
||||
|
||||
void audioDeviceStop();
|
||||
void audioDeviceActive();
|
||||
void audioDeviceFull();
|
||||
void audioDeviceError();
|
||||
|
||||
|
||||
@@ -131,8 +131,8 @@ public:
|
||||
virtual QAudio::State state() const = 0;
|
||||
virtual void setFormat(const QAudioFormat& fmt) = 0;
|
||||
virtual QAudioFormat format() const = 0;
|
||||
virtual void setVolume(qreal) {}
|
||||
virtual qreal volume() const { return 1.0; }
|
||||
virtual void setVolume(qreal) = 0;
|
||||
virtual qreal volume() const = 0;
|
||||
|
||||
Q_SIGNALS:
|
||||
void errorChanged(QAudio::Error);
|
||||
|
||||
Reference in New Issue
Block a user