summaryrefslogtreecommitdiffstats
path: root/src/multimedia/audio
diff options
context:
space:
mode:
Diffstat (limited to 'src/multimedia/audio')
-rw-r--r--src/multimedia/audio/audio.pri7
-rw-r--r--src/multimedia/audio/qaudio.cpp54
-rw-r--r--src/multimedia/audio/qaudio.h38
-rw-r--r--src/multimedia/audio/qaudio_mac.cpp30
-rw-r--r--src/multimedia/audio/qaudio_mac_p.h30
-rw-r--r--src/multimedia/audio/qaudiodevicefactory.cpp131
-rw-r--r--src/multimedia/audio/qaudiodevicefactory_p.h47
-rw-r--r--src/multimedia/audio/qaudiodeviceid.cpp168
-rw-r--r--src/multimedia/audio/qaudiodeviceid.h94
-rw-r--r--src/multimedia/audio/qaudiodeviceid_p.h82
-rw-r--r--src/multimedia/audio/qaudiodeviceinfo.cpp202
-rw-r--r--src/multimedia/audio/qaudiodeviceinfo.h62
-rw-r--r--src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp237
-rw-r--r--src/multimedia/audio/qaudiodeviceinfo_alsa_p.h42
-rw-r--r--src/multimedia/audio/qaudiodeviceinfo_mac_p.cpp58
-rw-r--r--src/multimedia/audio/qaudiodeviceinfo_mac_p.h36
-rw-r--r--src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp113
-rw-r--r--src/multimedia/audio/qaudiodeviceinfo_win32_p.h42
-rw-r--r--src/multimedia/audio/qaudioengine.cpp38
-rw-r--r--src/multimedia/audio/qaudioengine.h38
-rw-r--r--src/multimedia/audio/qaudioengineplugin.cpp30
-rw-r--r--src/multimedia/audio/qaudioengineplugin.h34
-rw-r--r--src/multimedia/audio/qaudioformat.cpp72
-rw-r--r--src/multimedia/audio/qaudioformat.h34
-rw-r--r--src/multimedia/audio/qaudioinput.cpp111
-rw-r--r--src/multimedia/audio/qaudioinput.h45
-rw-r--r--src/multimedia/audio/qaudioinput_alsa_p.cpp134
-rw-r--r--src/multimedia/audio/qaudioinput_alsa_p.h40
-rw-r--r--src/multimedia/audio/qaudioinput_mac_p.cpp62
-rw-r--r--src/multimedia/audio/qaudioinput_mac_p.h38
-rw-r--r--src/multimedia/audio/qaudioinput_win32_p.cpp135
-rw-r--r--src/multimedia/audio/qaudioinput_win32_p.h40
-rw-r--r--src/multimedia/audio/qaudiooutput.cpp97
-rw-r--r--src/multimedia/audio/qaudiooutput.h42
-rw-r--r--src/multimedia/audio/qaudiooutput_alsa_p.cpp137
-rw-r--r--src/multimedia/audio/qaudiooutput_alsa_p.h40
-rw-r--r--src/multimedia/audio/qaudiooutput_mac_p.cpp59
-rw-r--r--src/multimedia/audio/qaudiooutput_mac_p.h38
-rw-r--r--src/multimedia/audio/qaudiooutput_win32_p.cpp129
-rw-r--r--src/multimedia/audio/qaudiooutput_win32_p.h44
40 files changed, 1504 insertions, 1406 deletions
diff --git a/src/multimedia/audio/audio.pri b/src/multimedia/audio/audio.pri
index c7fbbb077..c4459415a 100644
--- a/src/multimedia/audio/audio.pri
+++ b/src/multimedia/audio/audio.pri
@@ -5,9 +5,7 @@ HEADERS += $$PWD/qaudio.h \
$$PWD/qaudiodeviceinfo.h \
$$PWD/qaudioengineplugin.h \
$$PWD/qaudioengine.h \
- $$PWD/qaudiodevicefactory_p.h \
- $$PWD/qaudiodeviceid.h \
- $$PWD/qaudiodeviceid_p.h
+ $$PWD/qaudiodevicefactory_p.h
SOURCES += $$PWD/qaudio.cpp \
@@ -17,8 +15,7 @@ SOURCES += $$PWD/qaudio.cpp \
$$PWD/qaudioinput.cpp \
$$PWD/qaudioengineplugin.cpp \
$$PWD/qaudioengine.cpp \
- $$PWD/qaudiodevicefactory.cpp \
- $$PWD/qaudiodeviceid.cpp
+ $$PWD/qaudiodevicefactory.cpp
mac {
HEADERS += $$PWD/qaudioinput_mac_p.h \
diff --git a/src/multimedia/audio/qaudio.cpp b/src/multimedia/audio/qaudio.cpp
index da1674c5e..b687f3411 100644
--- a/src/multimedia/audio/qaudio.cpp
+++ b/src/multimedia/audio/qaudio.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -71,23 +71,23 @@ public:
/*!
\enum QAudio::Error
- \value NoError No errors have occurred
- \value OpenError An error opening the audio device
- \value IOError An error occurred during read/write of audio device
- \value UnderrunError Audio data is not being fed to the audio device at a fast enough rate
- \value FatalError A non-recoverable error has occurred, the audio device is not usable at this time.
+ \value NoError No errors have occurred
+ \value OpenError An error opening the audio device
+ \value IOError An error occurred during read/write of audio device
+ \value UnderrunError Audio data is not being fed to the audio device at a fast enough rate
+ \value FatalError A non-recoverable error has occurred, the audio device is not usable at this time.
*/
/*!
\enum QAudio::State
- \value ActiveState Audio data is being processed, this state is set after start() is called
- and while audio data is available to be processed.
- \value SuspendState The audio device is in a suspended state, this state will only be entered
- after suspend() is called.
- \value StopState The audio device is closed, not processing any audio data
- \value IdleState The QIODevice passed in has no data and audio system's buffer is empty, this state
- is set after start() is called and while no audio data is available to be processed.
+ \value ActiveState Audio data is being processed, this state is set after start() is called
+ and while audio data is available to be processed.
+ \value SuspendedState The audio device is in a suspended state, this state will only be entered
+ after suspend() is called.
+ \value StoppedState The audio device is closed, not processing any audio data
+ \value IdleState The QIODevice passed in has no data and audio system's buffer is empty, this state
+ is set after start() is called and while no audio data is available to be processed.
*/
/*!
diff --git a/src/multimedia/audio/qaudio.h b/src/multimedia/audio/qaudio.h
index bf5495c4b..531e1a796 100644
--- a/src/multimedia/audio/qaudio.h
+++ b/src/multimedia/audio/qaudio.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -56,7 +56,7 @@ QT_MODULE(Multimedia)
namespace QAudio
{
enum Error { NoError, OpenError, IOError, UnderrunError, FatalError };
- enum State { ActiveState, SuspendState, StopState, IdleState };
+ enum State { ActiveState, SuspendedState, StoppedState, IdleState };
enum Mode { AudioInput, AudioOutput };
}
@@ -64,8 +64,8 @@ QT_END_NAMESPACE
QT_END_HEADER
-Q_DECLARE_METATYPE(QAudio::Error);
-Q_DECLARE_METATYPE(QAudio::State);
-Q_DECLARE_METATYPE(QAudio::Mode);
+Q_DECLARE_METATYPE(QAudio::Error)
+Q_DECLARE_METATYPE(QAudio::State)
+Q_DECLARE_METATYPE(QAudio::Mode)
#endif // QAUDIO_H
diff --git a/src/multimedia/audio/qaudio_mac.cpp b/src/multimedia/audio/qaudio_mac.cpp
index 075d6b3e2..1cd92253c 100644
--- a/src/multimedia/audio/qaudio_mac.cpp
+++ b/src/multimedia/audio/qaudio_mac.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
diff --git a/src/multimedia/audio/qaudio_mac_p.h b/src/multimedia/audio/qaudio_mac_p.h
index 57179b27c..ac6517b7d 100644
--- a/src/multimedia/audio/qaudio_mac_p.h
+++ b/src/multimedia/audio/qaudio_mac_p.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
diff --git a/src/multimedia/audio/qaudiodevicefactory.cpp b/src/multimedia/audio/qaudiodevicefactory.cpp
index c9be3130b..89e439419 100644
--- a/src/multimedia/audio/qaudiodevicefactory.cpp
+++ b/src/multimedia/audio/qaudiodevicefactory.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -44,7 +44,6 @@
#include <QtMultimedia/qaudioengineplugin.h>
#include <private/qfactoryloader_p.h>
#include "qaudiodevicefactory_p.h"
-#include "qaudiodeviceid_p.h"
#if defined(Q_OS_WIN)
#include "qaudiodeviceinfo_win32_p.h"
@@ -95,10 +94,10 @@ public:
int bufferSize() const { return 0; }
void setNotifyInterval(int ) {}
int notifyInterval() const { return 0; }
- qint64 totalTime() const { return 0; }
- qint64 clock() const { return 0; }
+ qint64 processedUSecs() const { return 0; }
+ qint64 elapsedUSecs() const { return 0; }
QAudio::Error error() const { return QAudio::OpenError; }
- QAudio::State state() const { return QAudio::StopState; }
+ QAudio::State state() const { return QAudio::StoppedState; }
QAudioFormat format() const { return QAudioFormat(); }
};
@@ -116,27 +115,27 @@ public:
int bufferSize() const { return 0; }
void setNotifyInterval(int ) {}
int notifyInterval() const { return 0; }
- qint64 totalTime() const { return 0; }
- qint64 clock() const { return 0; }
+ qint64 processedUSecs() const { return 0; }
+ qint64 elapsedUSecs() const { return 0; }
QAudio::Error error() const { return QAudio::OpenError; }
- QAudio::State state() const { return QAudio::StopState; }
+ QAudio::State state() const { return QAudio::StoppedState; }
QAudioFormat format() const { return QAudioFormat(); }
};
-QList<QAudioDeviceId> QAudioDeviceFactory::deviceList(QAudio::Mode mode)
+QList<QAudioDeviceInfo> QAudioDeviceFactory::availableDevices(QAudio::Mode mode)
{
- QList<QAudioDeviceId> devices;
+ QList<QAudioDeviceInfo> devices;
#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA))
- foreach (const QByteArray &handle, QAudioDeviceInfoPrivate::deviceList(mode))
- devices += createDeviceId(QLatin1String("builtin"), mode, handle);
+ foreach (const QByteArray &handle, QAudioDeviceInfoInternal::availableDevices(mode))
+ devices << QAudioDeviceInfo(QLatin1String("builtin"), handle, mode);
#endif
QFactoryLoader* l = loader();
foreach (QString const& key, l->keys()) {
QAudioEngineFactoryInterface* plugin = qobject_cast<QAudioEngineFactoryInterface*>(l->instance(key));
if (plugin) {
- foreach (QByteArray const& handle, plugin->deviceList(mode))
- devices += createDeviceId(key, mode, handle);
+ foreach (QByteArray const& handle, plugin->availableDevices(mode))
+ devices << QAudioDeviceInfo(key, handle, mode);
}
delete plugin;
@@ -145,50 +144,51 @@ QList<QAudioDeviceId> QAudioDeviceFactory::deviceList(QAudio::Mode mode)
return devices;
}
-QAudioDeviceId QAudioDeviceFactory::defaultInputDevice()
+QAudioDeviceInfo QAudioDeviceFactory::defaultInputDevice()
{
QAudioEngineFactoryInterface* plugin = qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(QLatin1String("default")));
if (plugin) {
- QList<QByteArray> list = plugin->deviceList(QAudio::AudioInput);
+ QList<QByteArray> list = plugin->availableDevices(QAudio::AudioInput);
if (list.size() > 0)
- return createDeviceId(QLatin1String("default"), QAudio::AudioInput, list.at(0));
+ return QAudioDeviceInfo(QLatin1String("default"), list.at(0), QAudio::AudioInput);
}
#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA))
- return createDeviceId(QLatin1String("builtin"), QAudio::AudioInput, QAudioDeviceInfoPrivate::defaultInputDevice());
+ return QAudioDeviceInfo(QLatin1String("builtin"), QAudioDeviceInfoInternal::defaultInputDevice(), QAudio::AudioInput);
#endif
- return QAudioDeviceId();
+ return QAudioDeviceInfo();
}
-QAudioDeviceId QAudioDeviceFactory::defaultOutputDevice()
+QAudioDeviceInfo QAudioDeviceFactory::defaultOutputDevice()
{
QAudioEngineFactoryInterface* plugin = qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(QLatin1String("default")));
if (plugin) {
- QList<QByteArray> list = plugin->deviceList(QAudio::AudioOutput);
+ QList<QByteArray> list = plugin->availableDevices(QAudio::AudioOutput);
if (list.size() > 0)
- return createDeviceId(QLatin1String("default"), QAudio::AudioOutput, list.at(0));
+ return QAudioDeviceInfo(QLatin1String("default"), list.at(0), QAudio::AudioOutput);
}
#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA))
- return createDeviceId(QLatin1String("builtin"), QAudio::AudioOutput, QAudioDeviceInfoPrivate::defaultOutputDevice());
+ return QAudioDeviceInfo(QLatin1String("builtin"), QAudioDeviceInfoInternal::defaultOutputDevice(), QAudio::AudioOutput);
#endif
- return QAudioDeviceId();
+ return QAudioDeviceInfo();
}
-QAbstractAudioDeviceInfo* QAudioDeviceFactory::audioDeviceInfo(QAudioDeviceId const& id)
+QAbstractAudioDeviceInfo* QAudioDeviceFactory::audioDeviceInfo(const QString &realm, const QByteArray &handle, QAudio::Mode mode)
{
- if (id.isNull())
- return new QNullDeviceInfo();
+ QAbstractAudioDeviceInfo *rc = 0;
+
#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA))
- if (id.d->key == QLatin1String("builtin"))
- return new QAudioDeviceInfoPrivate(id.d->handle, QAudio::Mode(id.d->mode));
+ if (realm == QLatin1String("builtin"))
+ return new QAudioDeviceInfoInternal(handle, mode);
#endif
- QAudioEngineFactoryInterface* plugin = qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(id.d->key));
+ QAudioEngineFactoryInterface* plugin =
+ qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(realm));
if (plugin)
- return plugin->createDeviceInfo(id.d->handle, QAudio::Mode(id.d->mode));
+ rc = plugin->createDeviceInfo(handle, mode);
- return new QNullDeviceInfo();
+ return rc == 0 ? new QNullDeviceInfo() : rc;
}
QAbstractAudioInput* QAudioDeviceFactory::createDefaultInputDevice(QAudioFormat const &format)
@@ -201,50 +201,39 @@ QAbstractAudioOutput* QAudioDeviceFactory::createDefaultOutputDevice(QAudioForma
return createOutputDevice(defaultOutputDevice(), format);
}
-QAbstractAudioInput* QAudioDeviceFactory::createInputDevice(QAudioDeviceId const& id, QAudioFormat const &format)
+QAbstractAudioInput* QAudioDeviceFactory::createInputDevice(QAudioDeviceInfo const& deviceInfo, QAudioFormat const &format)
{
- if (id.isNull())
+ if (deviceInfo.isNull())
return new QNullInputDevice();
#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA))
- if (id.d->key == QLatin1String("builtin")) {
- if(!defaultInputDevice().isNull())
- return new QAudioInputPrivate(id.d->handle, format);
- else
- return new QNullInputDevice();
- }
+ if (deviceInfo.realm() == QLatin1String("builtin"))
+ return new QAudioInputPrivate(deviceInfo.handle(), format);
#endif
- QAudioEngineFactoryInterface* plugin = qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance((id.d->key)));
+ QAudioEngineFactoryInterface* plugin =
+ qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(deviceInfo.realm()));
if (plugin)
- return plugin->createInput(id.d->handle, format);
+ return plugin->createInput(deviceInfo.handle(), format);
return new QNullInputDevice();
}
-QAbstractAudioOutput* QAudioDeviceFactory::createOutputDevice(QAudioDeviceId const& id, QAudioFormat const &format)
+QAbstractAudioOutput* QAudioDeviceFactory::createOutputDevice(QAudioDeviceInfo const& deviceInfo, QAudioFormat const &format)
{
- if (id.isNull())
+ if (deviceInfo.isNull())
return new QNullOutputDevice();
#if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA))
- if (id.d->key == QLatin1String("builtin")) {
- if(!defaultOutputDevice().isNull())
- return new QAudioOutputPrivate(id.d->handle, format);
- else
- return new QNullOutputDevice();
- }
+ if (deviceInfo.realm() == QLatin1String("builtin"))
+ return new QAudioOutputPrivate(deviceInfo.handle(), format);
#endif
- QAudioEngineFactoryInterface* plugin = qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(id.d->key));
+ QAudioEngineFactoryInterface* plugin =
+ qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(deviceInfo.realm()));
if (plugin)
- return plugin->createOutput(id.d->handle, format);
+ return plugin->createOutput(deviceInfo.handle(), format);
return new QNullOutputDevice();
}
-QAudioDeviceId QAudioDeviceFactory::createDeviceId(QString const& key, int mode, QByteArray const& handle)
-{
- return QAudioDeviceId(new QAudioDeviceIdPrivate(key, mode, handle));
-}
-
QT_END_NAMESPACE
diff --git a/src/multimedia/audio/qaudiodevicefactory_p.h b/src/multimedia/audio/qaudiodevicefactory_p.h
index f2ce7cee5..246645540 100644
--- a/src/multimedia/audio/qaudiodevicefactory_p.h
+++ b/src/multimedia/audio/qaudiodevicefactory_p.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -57,7 +57,6 @@
#include <QtCore/qbytearray.h>
#include <QtCore/qlist.h>
-#include <QtMultimedia/qaudiodeviceid.h>
#include <QtMultimedia/qaudiodeviceinfo.h>
QT_BEGIN_HEADER
@@ -68,28 +67,26 @@ QT_MODULE(Multimedia)
class QAbstractAudioInput;
class QAbstractAudioOutput;
-
+class QAbstractAudioDeviceInfo;
class QAudioDeviceFactory
{
public:
- static QList<QAudioDeviceId> deviceList(QAudio::Mode mode);
+ static QList<QAudioDeviceInfo> availableDevices(QAudio::Mode mode);
- static QAudioDeviceId defaultInputDevice();
- static QAudioDeviceId defaultOutputDevice();
+ static QAudioDeviceInfo defaultInputDevice();
+ static QAudioDeviceInfo defaultOutputDevice();
- static QAbstractAudioDeviceInfo* audioDeviceInfo(QAudioDeviceId const &device);
+ static QAbstractAudioDeviceInfo* audioDeviceInfo(const QString &realm, const QByteArray &handle, QAudio::Mode mode);
static QAbstractAudioInput* createDefaultInputDevice(QAudioFormat const &format);
static QAbstractAudioOutput* createDefaultOutputDevice(QAudioFormat const &format);
- static QAbstractAudioInput* createInputDevice(QAudioDeviceId const &device, QAudioFormat const &format);
- static QAbstractAudioOutput* createOutputDevice(QAudioDeviceId const &device, QAudioFormat const &format);
+ static QAbstractAudioInput* createInputDevice(QAudioDeviceInfo const &device, QAudioFormat const &format);
+ static QAbstractAudioOutput* createOutputDevice(QAudioDeviceInfo const &device, QAudioFormat const &format);
static QAbstractAudioInput* createNullInput();
static QAbstractAudioOutput* createNullOutput();
-
- static QAudioDeviceId createDeviceId(QString const& key, int mode, QByteArray const& handle);
};
QT_END_NAMESPACE
diff --git a/src/multimedia/audio/qaudiodeviceid.cpp b/src/multimedia/audio/qaudiodeviceid.cpp
deleted file mode 100644
index 9972fc162..000000000
--- a/src/multimedia/audio/qaudiodeviceid.cpp
+++ /dev/null
@@ -1,168 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtMultimedia module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#include <QtCore/qstring.h>
-#include <QtCore/qbytearray.h>
-#include <QtCore/qdatastream.h>
-
-#include <QtMultimedia/qaudiodeviceid.h>
-#include "qaudiodeviceid_p.h"
-
-
-QT_BEGIN_NAMESPACE
-
-/*!
- \class QAudioDeviceId
- \brief The QAudioDeviceId class provides means for identifying a unique input or output device on a system.
-
- \inmodule QtMultimedia
- \ingroup multimedia
- \since 4.6
-
- \sa QAudioDeviceInfo, QAudioOutput, QAudioInput
-*/
-
-/*!
- Construct a new null QAudioDeviceId.
-*/
-
-QAudioDeviceId::QAudioDeviceId()
-{
-}
-
-/*!
- Copy the QAudDeviceId referenced by \a other.
-*/
-
-QAudioDeviceId::QAudioDeviceId(const QAudioDeviceId &other):
- d(other.d)
-{
-}
-
-/*!
- Destroy the QAudioDeviceId.
-*/
-
-QAudioDeviceId::~QAudioDeviceId()
-{
-}
-
-/*!
- Make a copy of the \a other QAudioDeviceId.
-*/
-
-QAudioDeviceId& QAudioDeviceId::operator=(const QAudioDeviceId &other)
-{
- d = other.d;
- return *this;
-}
-
-/*!
- Compare with the \a other QAudioDeviceId, return true if they are the same;
- otherwise false.
-*/
-
-bool QAudioDeviceId::operator==(const QAudioDeviceId &other) const
-{
- return (d.constData() == 0 && other.d.constData() == 0) ||
- (d.constData() != 0 && other.d.constData() != 0 &&
- d->key == other.d->key && d->mode == other.d->mode && d->handle == other.d->handle);
-}
-
-/*!
- Compare with the \a other QAudioDeviceId, return false if they are the same;
- otherwise true.
-*/
-
-bool QAudioDeviceId::operator!=(const QAudioDeviceId &other) const
-{
- return !(*this == other);
-}
-
-/*!
- Returns true if this is not a valid QAudioDeviceId; otherwise false.
-*/
-
-bool QAudioDeviceId::isNull() const
-{
- return d.constData() == 0;
-}
-
-/*!
- \internal
-*/
-
-QAudioDeviceId::QAudioDeviceId(QAudioDeviceIdPrivate* data):
- d(data)
-{
-}
-
-/*!
- \internal
-*/
-
-QAudioDeviceIdPrivate::QAudioDeviceIdPrivate(QString const& k, int m, QByteArray const& h):
- key(k), mode(m), handle(h)
-{
-}
-
-#ifndef QT_NO_DATASTREAM
-Q_MULTIMEDIA_EXPORT QDataStream &operator<<(QDataStream &s, const QAudioDeviceId &id)
-{
- s << id.d->key << id.d->mode << id.d->handle;
- return s;
-}
-
-Q_MULTIMEDIA_EXPORT QDataStream &operator>>(QDataStream &s, QAudioDeviceId &id)
-{
- QString key;
- int mode;
- QByteArray handle;
-
- s >> key >> mode >> handle;
- id = QAudioDeviceId(new QAudioDeviceIdPrivate(key, mode, handle));
-
- return s;
-}
-#endif
-
-
-QT_END_NAMESPACE
diff --git a/src/multimedia/audio/qaudiodeviceid.h b/src/multimedia/audio/qaudiodeviceid.h
deleted file mode 100644
index 984283fd4..000000000
--- a/src/multimedia/audio/qaudiodeviceid.h
+++ /dev/null
@@ -1,94 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtMultimedia module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-#ifndef QAUDIODEVICEID_H
-#define QAUDIODEVICEID_H
-
-#include <QtCore/qshareddata.h>
-#include <QtCore/qmetatype.h>
-
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Multimedia)
-
-
-class QAudioDeviceFactory;
-class QAudioDeviceIdPrivate;
-
-class Q_MULTIMEDIA_EXPORT QAudioDeviceId
-{
- friend class QAudioDeviceFactory;
- friend Q_MULTIMEDIA_EXPORT QDataStream &operator<<(QDataStream&, const QAudioDeviceId&);
- friend Q_MULTIMEDIA_EXPORT QDataStream &operator>>(QDataStream&, QAudioDeviceId&);
-
-public:
- QAudioDeviceId();
- QAudioDeviceId(const QAudioDeviceId &other);
- ~QAudioDeviceId();
-
- QAudioDeviceId& operator=(const QAudioDeviceId &other);
- bool operator==(const QAudioDeviceId &id) const;
- bool operator!=(const QAudioDeviceId &id) const;
-
- bool isNull() const;
-
-private:
- QAudioDeviceId(QAudioDeviceIdPrivate *data);
-
- QSharedDataPointer<QAudioDeviceIdPrivate> d;
-};
-
-#ifndef QT_NO_DATASTREAM
-Q_MULTIMEDIA_EXPORT QDataStream &operator<<(QDataStream&, const QAudioDeviceId&);
-Q_MULTIMEDIA_EXPORT QDataStream &operator>>(QDataStream&, QAudioDeviceId&);
-#endif
-
-QT_END_NAMESPACE
-
-QT_END_HEADER
-
-Q_DECLARE_METATYPE(QAudioDeviceId);
-
-
-#endif // QAUDIODEVICEID_H
diff --git a/src/multimedia/audio/qaudiodeviceid_p.h b/src/multimedia/audio/qaudiodeviceid_p.h
deleted file mode 100644
index 1ff29a22e..000000000
--- a/src/multimedia/audio/qaudiodeviceid_p.h
+++ /dev/null
@@ -1,82 +0,0 @@
-/****************************************************************************
-**
-** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
-** Contact: Nokia Corporation (qt-info@nokia.com)
-**
-** This file is part of the QtMultimedia module of the Qt Toolkit.
-**
-** $QT_BEGIN_LICENSE:LGPL$
-** No Commercial Usage
-** This file contains pre-release code and may not be distributed.
-** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
-**
-** GNU Lesser General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU Lesser
-** General Public License version 2.1 as published by the Free Software
-** Foundation and appearing in the file LICENSE.LGPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU Lesser General Public License version 2.1 requirements
-** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
-**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
-**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
-**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
-** $QT_END_LICENSE$
-**
-****************************************************************************/
-
-//
-// W A R N I N G
-// -------------
-//
-// This file is not part of the Qt API. It exists for the convenience
-// of other Qt classes. This header file may change from version to
-// version without notice, or even be removed.
-//
-// We mean it.
-//
-
-#ifndef QAUDIODEVICEIDPRIVATE_H
-#define QAUDIODEVICEIDPRIVATE_H
-
-#include <QtCore/qstring.h>
-#include <QtCore/qbytearray.h>
-#include <QtCore/qshareddata.h>
-
-QT_BEGIN_HEADER
-
-QT_BEGIN_NAMESPACE
-
-QT_MODULE(Multimedia)
-
-
-class QAudioDeviceIdPrivate : public QSharedData
-{
-public:
- QAudioDeviceIdPrivate(QString const& k, int m, QByteArray const& h);
-
- QString key;
- int mode;
- QByteArray handle;
-};
-
-
-QT_END_NAMESPACE
-
-QT_END_HEADER
-
-#endif // QAUDIODEVICEIDPRIVATE_H
diff --git a/src/multimedia/audio/qaudiodeviceinfo.cpp b/src/multimedia/audio/qaudiodeviceinfo.cpp
index 83d01bea6..5e3adcb43 100644
--- a/src/multimedia/audio/qaudiodeviceinfo.cpp
+++ b/src/multimedia/audio/qaudiodeviceinfo.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -46,12 +46,52 @@
QT_BEGIN_NAMESPACE
+class QAudioDeviceInfoPrivate : public QSharedData
+{
+public:
+ QAudioDeviceInfoPrivate():info(0) {}
+ QAudioDeviceInfoPrivate(const QString &r, const QByteArray &h, QAudio::Mode m):
+ realm(r), handle(h), mode(m)
+ {
+ info = QAudioDeviceFactory::audioDeviceInfo(realm, handle, mode);
+ }
+
+ QAudioDeviceInfoPrivate(const QAudioDeviceInfoPrivate &other):
+ QSharedData(other),
+ realm(other.realm), handle(other.handle), mode(other.mode)
+ {
+ info = QAudioDeviceFactory::audioDeviceInfo(realm, handle, mode);
+ }
+
+ QAudioDeviceInfoPrivate& operator=(const QAudioDeviceInfoPrivate &other)
+ {
+ delete info;
+
+ realm = other.realm;
+ handle = other.handle;
+ mode = other.mode;
+ info = QAudioDeviceFactory::audioDeviceInfo(realm, handle, mode);
+ return *this;
+ }
+
+ ~QAudioDeviceInfoPrivate()
+ {
+ delete info;
+ }
+
+ QString realm;
+ QByteArray handle;
+ QAudio::Mode mode;
+ QAbstractAudioDeviceInfo* info;
+};
+
+
/*!
\class QAudioDeviceInfo
\brief The QAudioDeviceInfo class provides an interface to query audio devices and their functionality.
-
\inmodule QtMultimedia
\ingroup multimedia
+
\since 4.6
QAudioDeviceInfo lets you query for audio devices--such as sound
@@ -71,43 +111,51 @@ QT_BEGIN_NAMESPACE
audio plugins installed and the audio device capabilities. If you need a specific format, you can check if
the device supports it with isFormatSupported(), or fetch a
supported format that is as close as possible to the format with
- nearestFormat().
+ nearestFormat(). For instance:
- A QAudioDeviceInfo is constructed with a QAudioDeviceId, which is
- an identifier for a physical device. It is used by Qt to construct
+ \snippet doc/src/snippets/audio/main.cpp 1
+ \dots 8
+ \snippet doc/src/snippets/audio/main.cpp 2
+
+ A QAudioDeviceInfo is used by Qt to construct
classes that communicate with the device--such as
- QAudioDeviceInfo, QAudioInput, and QAudioOutput. The static
+ QAudioInput, and QAudioOutput. The static
functions defaultInputDevice(), defaultOutputDevice(), and
- deviceList() let you get a hold of the ids for all available
- devices. You fetch ids based on whether you will use the device
- for input or output; this is specified by the QAudio::Mode enum.
- The QAudioDeviceId returned are only valid for the QAudio::Mode.
+ availableDevices() let you get a list of all available
+ devices. Devices are fetch according to the value of mode
+ this is specified by the QAudio::Mode enum.
+ The QAudioDeviceInfo returned are only valid for the QAudio::Mode.
For instance:
\code
- foreach(QAudioDeviceId audioId, QAudioDeviceInfo::deviceList(QAudio::AudioOutput)) {
- QAudioDeviceInfo info(audioId);
- qDebug() << "Device name: " << info.deviceName();
- }
+ foreach(const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::availableDevices(QAudio::AudioOutput))
+ qDebug() << "Device name: " << deviceInfo.deviceName();
\endcode
In this code sample, we loop through all devices that are able to output
sound, i.e., play an audio stream in a supported format. For each device we
find, we simply print the deviceName().
- \sa QAudioOutput, QAudioInput, QAudioDeviceId
+ \sa QAudioOutput, QAudioInput
*/
/*!
- Construct a new audio device info and attach it to \a parent.
- Using the audio device with the specified \a id.
+ Constructs an empty QAudioDeviceInfo object.
*/
-QAudioDeviceInfo::QAudioDeviceInfo(const QAudioDeviceId &id, QObject *parent):
- QObject(parent)
+QAudioDeviceInfo::QAudioDeviceInfo():
+ d(new QAudioDeviceInfoPrivate)
+{
+}
+
+/*!
+ Constructs a copy of \a other.
+*/
+
+QAudioDeviceInfo::QAudioDeviceInfo(const QAudioDeviceInfo& other):
+ d(other.d)
{
- d = QAudioDeviceFactory::audioDeviceInfo(id);
}
/*!
@@ -116,7 +164,25 @@ QAudioDeviceInfo::QAudioDeviceInfo(const QAudioDeviceId &id, QObject *parent):
QAudioDeviceInfo::~QAudioDeviceInfo()
{
- delete d;
+}
+
+/*!
+ Sets the QAudioDeviceInfo object to be equal to \a other.
+*/
+
+QAudioDeviceInfo& QAudioDeviceInfo::operator=(const QAudioDeviceInfo &other)
+{
+ d = other.d;
+ return *this;
+}
+
+/*!
+ Returns whether this QAudioDeviceInfo object holds a device definition.
+*/
+
+bool QAudioDeviceInfo::isNull() const
+{
+ return d->info == 0;
}
/*!
@@ -131,7 +197,7 @@ QAudioDeviceInfo::~QAudioDeviceInfo()
QString QAudioDeviceInfo::deviceName() const
{
- return d->deviceName();
+ return isNull() ? QString() : d->info->deviceName();
}
/*!
@@ -140,7 +206,7 @@ QString QAudioDeviceInfo::deviceName() const
bool QAudioDeviceInfo::isFormatSupported(const QAudioFormat &settings) const
{
- return d->isFormatSupported(settings);
+ return isNull() ? false : d->info->isFormatSupported(settings);
}
/*!
@@ -159,7 +225,7 @@ bool QAudioDeviceInfo::isFormatSupported(const QAudioFormat &settings) const
QAudioFormat QAudioDeviceInfo::preferredFormat() const
{
- return d->preferredFormat();
+ return isNull() ? QAudioFormat() : d->info->preferredFormat();
}
/*!
@@ -172,7 +238,7 @@ QAudioFormat QAudioDeviceInfo::preferredFormat() const
QAudioFormat QAudioDeviceInfo::nearestFormat(const QAudioFormat &settings) const
{
- return d->nearestFormat(settings);
+ return isNull() ? QAudioFormat() : d->info->nearestFormat(settings);
}
/*!
@@ -189,7 +255,7 @@ QAudioFormat QAudioDeviceInfo::nearestFormat(const QAudioFormat &settings) const
QStringList QAudioDeviceInfo::supportedCodecs() const
{
- return d->codecList();
+ return isNull() ? QStringList() : d->info->codecList();
}
/*!
@@ -198,7 +264,7 @@ QStringList QAudioDeviceInfo::supportedCodecs() const
QList<int> QAudioDeviceInfo::supportedFrequencies() const
{
- return d->frequencyList();
+ return isNull() ? QList<int>() : d->info->frequencyList();
}
/*!
@@ -207,7 +273,7 @@ QList<int> QAudioDeviceInfo::supportedFrequencies() const
QList<int> QAudioDeviceInfo::supportedChannels() const
{
- return d->channelsList();
+ return isNull() ? QList<int>() : d->info->channelsList();
}
/*!
@@ -216,7 +282,7 @@ QList<int> QAudioDeviceInfo::supportedChannels() const
QList<int> QAudioDeviceInfo::supportedSampleSizes() const
{
- return d->sampleSizeList();
+ return isNull() ? QList<int>() : d->info->sampleSizeList();
}
/*!
@@ -225,7 +291,7 @@ QList<int> QAudioDeviceInfo::supportedSampleSizes() const
QList<QAudioFormat::Endian> QAudioDeviceInfo::supportedByteOrders() const
{
- return d->byteOrderList();
+ return isNull() ? QList<QAudioFormat::Endian>() : d->info->byteOrderList();
}
/*!
@@ -234,7 +300,7 @@ QList<QAudioFormat::Endian> QAudioDeviceInfo::supportedByteOrders() const
QList<QAudioFormat::SampleType> QAudioDeviceInfo::supportedSampleTypes() const
{
- return d->sampleTypeList();
+ return isNull() ? QList<QAudioFormat::SampleType>() : d->info->sampleTypeList();
}
/*!
@@ -242,7 +308,7 @@ QList<QAudioFormat::SampleType> QAudioDeviceInfo::supportedSampleTypes() const
All platform and audio plugin implementations provide a default audio device to use.
*/
-QAudioDeviceId QAudioDeviceInfo::defaultInputDevice()
+QAudioDeviceInfo QAudioDeviceInfo::defaultInputDevice()
{
return QAudioDeviceFactory::defaultInputDevice();
}
@@ -252,7 +318,7 @@ QAudioDeviceId QAudioDeviceInfo::defaultInputDevice()
All platform and audio plugin implementations provide a default audio device to use.
*/
-QAudioDeviceId QAudioDeviceInfo::defaultOutputDevice()
+QAudioDeviceInfo QAudioDeviceInfo::defaultOutputDevice()
{
return QAudioDeviceFactory::defaultOutputDevice();
}
@@ -261,9 +327,47 @@ QAudioDeviceId QAudioDeviceInfo::defaultOutputDevice()
Returns a list of audio devices that support \a mode.
*/
-QList<QAudioDeviceId> QAudioDeviceInfo::deviceList(QAudio::Mode mode)
+QList<QAudioDeviceInfo> QAudioDeviceInfo::availableDevices(QAudio::Mode mode)
+{
+ return QAudioDeviceFactory::availableDevices(mode);
+}
+
+
+/*!
+ \internal
+*/
+
+QAudioDeviceInfo::QAudioDeviceInfo(const QString &realm, const QByteArray &handle, QAudio::Mode mode):
+ d(new QAudioDeviceInfoPrivate(realm, handle, mode))
+{
+}
+
+/*!
+ \internal
+*/
+
+QString QAudioDeviceInfo::realm() const
+{
+ return d->realm;
+}
+
+/*!
+ \internal
+*/
+
+QByteArray QAudioDeviceInfo::handle() const
+{
+ return d->handle;
+}
+
+
+/*!
+ \internal
+*/
+
+QAudio::Mode QAudioDeviceInfo::mode() const
{
- return QAudioDeviceFactory::deviceList(mode);
+ return d->mode;
}
QT_END_NAMESPACE
diff --git a/src/multimedia/audio/qaudiodeviceinfo.h b/src/multimedia/audio/qaudiodeviceinfo.h
index 4b38cf31e..5c7cb9858 100644
--- a/src/multimedia/audio/qaudiodeviceinfo.h
+++ b/src/multimedia/audio/qaudiodeviceinfo.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -52,7 +52,7 @@
#include <QtMultimedia/qaudio.h>
#include <QtMultimedia/qaudioformat.h>
-#include <QtMultimedia/qaudiodeviceid.h>
+
QT_BEGIN_HEADER
@@ -60,17 +60,22 @@ QT_BEGIN_NAMESPACE
QT_MODULE(Multimedia)
+class QAudioDeviceFactory;
-class QAbstractAudioDeviceInfo;
-
-class Q_MULTIMEDIA_EXPORT QAudioDeviceInfo : public QObject
+class QAudioDeviceInfoPrivate;
+class Q_MULTIMEDIA_EXPORT QAudioDeviceInfo
{
- Q_OBJECT
+ friend class QAudioDeviceFactory;
public:
- explicit QAudioDeviceInfo(const QAudioDeviceId &id, QObject *parent = 0);
+ QAudioDeviceInfo();
+ QAudioDeviceInfo(const QAudioDeviceInfo& other);
~QAudioDeviceInfo();
+ QAudioDeviceInfo& operator=(const QAudioDeviceInfo& other);
+
+ bool isNull() const;
+
QString deviceName() const;
bool isFormatSupported(const QAudioFormat &format) const;
@@ -84,19 +89,24 @@ public:
QList<QAudioFormat::Endian> supportedByteOrders() const;
QList<QAudioFormat::SampleType> supportedSampleTypes() const;
- static QAudioDeviceId defaultInputDevice();
- static QAudioDeviceId defaultOutputDevice();
+ static QAudioDeviceInfo defaultInputDevice();
+ static QAudioDeviceInfo defaultOutputDevice();
- static QList<QAudioDeviceId> deviceList(QAudio::Mode mode);
+ static QList<QAudioDeviceInfo> availableDevices(QAudio::Mode mode);
private:
- Q_DISABLE_COPY(QAudioDeviceInfo)
+ QAudioDeviceInfo(const QString &realm, const QByteArray &handle, QAudio::Mode mode);
+ QString realm() const;
+ QByteArray handle() const;
+ QAudio::Mode mode() const;
- QAbstractAudioDeviceInfo* d;
+ QSharedDataPointer<QAudioDeviceInfoPrivate> d;
};
QT_END_NAMESPACE
QT_END_HEADER
+Q_DECLARE_METATYPE(QAudioDeviceInfo)
+
#endif // QAUDIODEVICEINFO_H
diff --git a/src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp b/src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp
index f15577061..9645fa8e6 100644
--- a/src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp
+++ b/src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -52,7 +52,11 @@
#include "qaudiodeviceinfo_alsa_p.h"
-QAudioDeviceInfoPrivate::QAudioDeviceInfoPrivate(QByteArray dev, QAudio::Mode mode)
+#include <alsa/version.h>
+
+QT_BEGIN_NAMESPACE
+
+QAudioDeviceInfoInternal::QAudioDeviceInfoInternal(QByteArray dev, QAudio::Mode mode)
{
handle = 0;
@@ -60,17 +64,17 @@ QAudioDeviceInfoPrivate::QAudioDeviceInfoPrivate(QByteArray dev, QAudio::Mode mo
this->mode = mode;
}
-QAudioDeviceInfoPrivate::~QAudioDeviceInfoPrivate()
+QAudioDeviceInfoInternal::~QAudioDeviceInfoInternal()
{
close();
}
-bool QAudioDeviceInfoPrivate::isFormatSupported(const QAudioFormat& format) const
+bool QAudioDeviceInfoInternal::isFormatSupported(const QAudioFormat& format) const
{
return testSettings(format);
}
-QAudioFormat QAudioDeviceInfoPrivate::preferredFormat() const
+QAudioFormat QAudioDeviceInfoInternal::preferredFormat() const
{
QAudioFormat nearest;
if(mode == QAudio::AudioOutput) {
@@ -79,18 +83,23 @@ QAudioFormat QAudioDeviceInfoPrivate::preferredFormat() const
nearest.setByteOrder(QAudioFormat::LittleEndian);
nearest.setSampleType(QAudioFormat::SignedInt);
nearest.setSampleSize(16);
- nearest.setCodec(tr("audio/pcm"));
+ nearest.setCodec(QLatin1String("audio/pcm"));
} else {
nearest.setFrequency(8000);
nearest.setChannels(1);
- nearest.setSampleType(QAudioFormat::SignedInt);
+ nearest.setSampleType(QAudioFormat::UnSignedInt);
nearest.setSampleSize(8);
- nearest.setCodec(tr("audio/pcm"));
+ nearest.setCodec(QLatin1String("audio/pcm"));
+ if(!testSettings(nearest)) {
+ nearest.setChannels(2);
+ nearest.setSampleSize(16);
+ nearest.setSampleType(QAudioFormat::SignedInt);
+ }
}
return nearest;
}
-QAudioFormat QAudioDeviceInfoPrivate::nearestFormat(const QAudioFormat& format) const
+QAudioFormat QAudioDeviceInfoInternal::nearestFormat(const QAudioFormat& format) const
{
if(testSettings(format))
return format;
@@ -98,54 +107,75 @@ QAudioFormat QAudioDeviceInfoPrivate::nearestFormat(const QAudioFormat& format)
return preferredFormat();
}
-QString QAudioDeviceInfoPrivate::deviceName() const
+QString QAudioDeviceInfoInternal::deviceName() const
{
return device;
}
-QStringList QAudioDeviceInfoPrivate::codecList()
+QStringList QAudioDeviceInfoInternal::codecList()
{
updateLists();
return codecz;
}
-QList<int> QAudioDeviceInfoPrivate::frequencyList()
+QList<int> QAudioDeviceInfoInternal::frequencyList()
{
updateLists();
return freqz;
}
-QList<int> QAudioDeviceInfoPrivate::channelsList()
+QList<int> QAudioDeviceInfoInternal::channelsList()
{
updateLists();
return channelz;
}
-QList<int> QAudioDeviceInfoPrivate::sampleSizeList()
+QList<int> QAudioDeviceInfoInternal::sampleSizeList()
{
updateLists();
return sizez;
}
-QList<QAudioFormat::Endian> QAudioDeviceInfoPrivate::byteOrderList()
+QList<QAudioFormat::Endian> QAudioDeviceInfoInternal::byteOrderList()
{
updateLists();
return byteOrderz;
}
-QList<QAudioFormat::SampleType> QAudioDeviceInfoPrivate::sampleTypeList()
+QList<QAudioFormat::SampleType> QAudioDeviceInfoInternal::sampleTypeList()
{
updateLists();
return typez;
}
-bool QAudioDeviceInfoPrivate::open()
+bool QAudioDeviceInfoInternal::open()
{
int err = 0;
QString dev = device;
- if(!dev.contains(tr("default"))) {
- int idx = snd_card_get_index(dev.toLocal8Bit().constData());
- dev = QString(tr("hw:%1,0")).arg(idx);
+ QList<QByteArray> devices = availableDevices(mode);
+
+ if(dev.compare(QLatin1String("default")) == 0) {
+#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
+ dev = QLatin1String(devices.first().constData());
+#else
+ dev = QLatin1String("hw:0,0");
+#endif
+ } else {
+#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
+ dev = device;
+#else
+ int idx = 0;
+ char *name;
+
+ QString shortName = device.mid(device.indexOf(QLatin1String("="),0)+1);
+
+ while(snd_card_get_name(idx,&name) == 0) {
+ if(dev.contains(QLatin1String(name)))
+ break;
+ idx++;
+ }
+ dev = QString(QLatin1String("hw:%1,0")).arg(idx);
+#endif
}
if(mode == QAudio::AudioOutput) {
err=snd_pcm_open( &handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_PLAYBACK,0);
@@ -159,27 +189,46 @@ bool QAudioDeviceInfoPrivate::open()
return true;
}
-void QAudioDeviceInfoPrivate::close()
+void QAudioDeviceInfoInternal::close()
{
if(handle)
snd_pcm_close(handle);
handle = 0;
}
-bool QAudioDeviceInfoPrivate::testSettings(const QAudioFormat& format) const
+bool QAudioDeviceInfoInternal::testSettings(const QAudioFormat& format) const
{
// Set nearest to closest settings that do work.
// See if what is in settings will work (return value).
-
int err = 0;
snd_pcm_t* handle;
snd_pcm_hw_params_t *params;
QString dev = device;
- // open()
- if(!dev.contains(tr("default"))) {
- int idx = snd_card_get_index(dev.toLocal8Bit().constData());
- dev = QString(tr("hw:%1,0")).arg(idx);
+ QList<QByteArray> devices = QAudioDeviceInfoInternal::availableDevices(QAudio::AudioOutput);
+
+ if(dev.compare(QLatin1String("default")) == 0) {
+#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
+ dev = QLatin1String(devices.first().constData());
+#else
+ dev = QLatin1String("hw:0,0");
+#endif
+ } else {
+#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
+ dev = device;
+#else
+ int idx = 0;
+ char *name;
+
+ QString shortName = device.mid(device.indexOf(QLatin1String("="),0)+1);
+
+ while(snd_card_get_name(idx,&name) == 0) {
+ if(shortName.compare(QLatin1String(name)) == 0)
+ break;
+ idx++;
+ }
+ dev = QString(QLatin1String("hw:%1,0")).arg(idx);
+#endif
}
if(mode == QAudio::AudioOutput) {
err=snd_pcm_open( &handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_PLAYBACK,0);
@@ -203,8 +252,45 @@ bool QAudioDeviceInfoPrivate::testSettings(const QAudioFormat& format) const
snd_pcm_hw_params_alloca( &params );
snd_pcm_hw_params_any( handle, params );
+ // set the values!
+ snd_pcm_hw_params_set_channels(handle,params,format.channels());
+ snd_pcm_hw_params_set_rate(handle,params,format.frequency(),dir);
+ switch(format.sampleSize()) {
+ case 8:
+ if(format.sampleType() == QAudioFormat::SignedInt)
+ snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S8);
+ else if(format.sampleType() == QAudioFormat::UnSignedInt)
+ snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U8);
+ break;
+ case 16:
+ if(format.sampleType() == QAudioFormat::SignedInt) {
+ if(format.byteOrder() == QAudioFormat::LittleEndian)
+ snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S16_LE);
+ else if(format.byteOrder() == QAudioFormat::BigEndian)
+ snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S16_BE);
+ } else if(format.sampleType() == QAudioFormat::UnSignedInt) {
+ if(format.byteOrder() == QAudioFormat::LittleEndian)
+ snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U16_LE);
+ else if(format.byteOrder() == QAudioFormat::BigEndian)
+ snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U16_BE);
+ }
+ break;
+ case 32:
+ if(format.sampleType() == QAudioFormat::SignedInt) {
+ if(format.byteOrder() == QAudioFormat::LittleEndian)
+ snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S32_LE);
+ else if(format.byteOrder() == QAudioFormat::BigEndian)
+ snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_S32_BE);
+ } else if(format.sampleType() == QAudioFormat::UnSignedInt) {
+ if(format.byteOrder() == QAudioFormat::LittleEndian)
+ snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U32_LE);
+ else if(format.byteOrder() == QAudioFormat::BigEndian)
+ snd_pcm_hw_params_set_format(handle,params,SND_PCM_FORMAT_U32_BE);
+ }
+ }
+
// For now, just accept only audio/pcm codec
- if(!format.codec().startsWith(tr("audio/pcm"))) {
+ if(!format.codec().startsWith(QLatin1String("audio/pcm"))) {
err=-1;
} else
testCodec = true;
@@ -281,7 +367,7 @@ bool QAudioDeviceInfoPrivate::testSettings(const QAudioFormat& format) const
return false;
}
-void QAudioDeviceInfoPrivate::updateLists()
+void QAudioDeviceInfoInternal::updateLists()
{
// redo all lists based on current settings
freqz.clear();
@@ -311,45 +397,41 @@ void QAudioDeviceInfoPrivate::updateLists()
typez.append(QAudioFormat::SignedInt);
typez.append(QAudioFormat::UnSignedInt);
typez.append(QAudioFormat::Float);
- codecz.append(tr("audio/pcm"));
+ codecz.append(QLatin1String("audio/pcm"));
close();
}
-QList<QByteArray> QAudioDeviceInfoPrivate::deviceList(QAudio::Mode mode)
+QList<QByteArray> QAudioDeviceInfoInternal::availableDevices(QAudio::Mode mode)
{
- QAudio::Mode _m;
QList<QByteArray> devices;
QByteArray filter;
- QString dir;
+#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
// Create a list of all current audio devices that support mode
void **hints, **n;
char *name, *descr, *io;
if(snd_device_name_hint(-1, "pcm", &hints) < 0) {
- qWarning()<<"no alsa devices available";
+ qWarning() << "no alsa devices available";
return devices;
}
n = hints;
+ if(mode == QAudio::AudioInput) {
+ filter = "Input";
+ } else {
+ filter = "Output";
+ }
+
while (*n != NULL) {
- _m = QAudio::AudioOutput;
name = snd_device_name_get_hint(*n, "NAME");
descr = snd_device_name_get_hint(*n, "DESC");
io = snd_device_name_get_hint(*n, "IOID");
- dir = QString::fromUtf8(io);
- if((name != NULL) && (descr != NULL) && ((io == NULL) || (dir.length() ==filter.length()))) {
- if(dir.length() == 5)
- _m = QAudio::AudioInput;
- if(io == NULL)
- _m = mode;
-
- QString str = tr(name);
-
- if(str.contains(tr("default"))) {
- int pos = str.indexOf(tr("="),0);
- devices.append(str.mid(pos+1).toLocal8Bit().constData());
- }
+ if((name != NULL) && (descr != NULL) && ((io == NULL) || (io == filter))) {
+ QString deviceName = QLatin1String(name);
+ QString deviceDescription = QLatin1String(descr);
+ if(deviceDescription.contains(QLatin1String("Default Audio Device")))
+ devices.append(deviceName.toLocal8Bit().constData());
}
if(name != NULL)
free(name);
@@ -357,38 +439,43 @@ QList<QByteArray> QAudioDeviceInfoPrivate::deviceList(QAudio::Mode mode)
free(descr);
if(io != NULL)
free(io);
- n++;
+ ++n;
}
snd_device_name_free_hint(hints);
if(devices.size() > 0) {
devices.append("default");
- if(mode == QAudio::AudioInput) {
- filter.append("Input");
- } else {
- filter.append("Output");
- }
}
+#else
+ int idx = 0;
+ char* name;
+ while(snd_card_get_name(idx,&name) == 0) {
+ devices.append(name);
+ idx++;
+ }
+ if (idx > 0)
+ devices.append("default");
+#endif
return devices;
}
-QByteArray QAudioDeviceInfoPrivate::defaultInputDevice()
+QByteArray QAudioDeviceInfoInternal::defaultInputDevice()
{
- QList<QByteArray> devices = deviceList(QAudio::AudioInput);
+ QList<QByteArray> devices = availableDevices(QAudio::AudioInput);
if(devices.size() == 0)
return QByteArray();
- return QByteArray("default");
+ return devices.first();
}
-QByteArray QAudioDeviceInfoPrivate::defaultOutputDevice()
+QByteArray QAudioDeviceInfoInternal::defaultOutputDevice()
{
- QList<QByteArray> devices = deviceList(QAudio::AudioOutput);
+ QList<QByteArray> devices = availableDevices(QAudio::AudioOutput);
if(devices.size() == 0)
return QByteArray();
- return QByteArray("default");
+ return devices.first();
}
-
+QT_END_NAMESPACE
diff --git a/src/multimedia/audio/qaudiodeviceinfo_alsa_p.h b/src/multimedia/audio/qaudiodeviceinfo_alsa_p.h
index ca8179f65..5a807af27 100644
--- a/src/multimedia/audio/qaudiodeviceinfo_alsa_p.h
+++ b/src/multimedia/audio/qaudiodeviceinfo_alsa_p.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -65,16 +65,18 @@
#include <QtMultimedia/qaudiodeviceinfo.h>
#include <QtMultimedia/qaudioengine.h>
+QT_BEGIN_NAMESPACE
+
const unsigned int MAX_SAMPLE_RATES = 5;
const unsigned int SAMPLE_RATES[] =
{ 8000, 11025, 22050, 44100, 48000 };
-class QAudioDeviceInfoPrivate : public QAbstractAudioDeviceInfo
+class QAudioDeviceInfoInternal : public QAbstractAudioDeviceInfo
{
Q_OBJECT
public:
- QAudioDeviceInfoPrivate(QByteArray dev,QAudio::Mode mode);
- ~QAudioDeviceInfoPrivate();
+ QAudioDeviceInfoInternal(QByteArray dev,QAudio::Mode mode);
+ ~QAudioDeviceInfoInternal();
bool testSettings(const QAudioFormat& format) const;
void updateLists();
@@ -90,7 +92,7 @@ public:
QList<QAudioFormat::SampleType> sampleTypeList();
static QByteArray defaultInputDevice();
static QByteArray defaultOutputDevice();
- static QList<QByteArray> deviceList(QAudio::Mode);
+ static QList<QByteArray> availableDevices(QAudio::Mode);
private:
bool open();
@@ -109,5 +111,7 @@ private:
snd_pcm_hw_params_t *params;
};
+QT_END_NAMESPACE
+
#endif
diff --git a/src/multimedia/audio/qaudiodeviceinfo_mac_p.cpp b/src/multimedia/audio/qaudiodeviceinfo_mac_p.cpp
index 28bd46737..8905119d9 100644
--- a/src/multimedia/audio/qaudiodeviceinfo_mac_p.cpp
+++ b/src/multimedia/audio/qaudiodeviceinfo_mac_p.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -66,7 +66,7 @@
QT_BEGIN_NAMESPACE
-QAudioDeviceInfoPrivate::QAudioDeviceInfoPrivate(QByteArray const& handle, QAudio::Mode)
+QAudioDeviceInfoInternal::QAudioDeviceInfoInternal(QByteArray const& handle, QAudio::Mode)
{
QDataStream ds(handle);
quint32 did, tm;
@@ -76,12 +76,12 @@ QAudioDeviceInfoPrivate::QAudioDeviceInfoPrivate(QByteArray const& handle, QAudi
mode = QAudio::Mode(tm);
}
-bool QAudioDeviceInfoPrivate::isFormatSupported(const QAudioFormat& format) const
+bool QAudioDeviceInfoInternal::isFormatSupported(const QAudioFormat& format) const
{
return format.codec() == QString::fromLatin1("audio/pcm");
}
-QAudioFormat QAudioDeviceInfoPrivate::preferredFormat() const
+QAudioFormat QAudioDeviceInfoInternal::preferredFormat() const
{
QAudioFormat rc;
@@ -134,7 +134,7 @@ QAudioFormat QAudioDeviceInfoPrivate::preferredFormat() const
return rc;
}
-QAudioFormat QAudioDeviceInfoPrivate::nearestFormat(const QAudioFormat& format) const
+QAudioFormat QAudioDeviceInfoInternal::nearestFormat(const QAudioFormat& format) const
{
QAudioFormat rc(format);
QAudioFormat target = preferredFormat();
@@ -158,17 +158,17 @@ QAudioFormat QAudioDeviceInfoPrivate::nearestFormat(const QAudioFormat& format)
return rc;
}
-QString QAudioDeviceInfoPrivate::deviceName() const
+QString QAudioDeviceInfoInternal::deviceName() const
{
return name;
}
-QStringList QAudioDeviceInfoPrivate::codecList()
+QStringList QAudioDeviceInfoInternal::codecList()
{
return QStringList() << QString::fromLatin1("audio/pcm");
}
-QList<int> QAudioDeviceInfoPrivate::frequencyList()
+QList<int> QAudioDeviceInfoInternal::frequencyList()
{
QSet<int> rc;
@@ -208,7 +208,7 @@ QList<int> QAudioDeviceInfoPrivate::frequencyList()
return rc.toList();
}
-QList<int> QAudioDeviceInfoPrivate::channelsList()
+QList<int> QAudioDeviceInfoInternal::channelsList()
{
QList<int> rc;
@@ -248,17 +248,17 @@ QList<int> QAudioDeviceInfoPrivate::channelsList()
return rc;
}
-QList<int> QAudioDeviceInfoPrivate::sampleSizeList()
+QList<int> QAudioDeviceInfoInternal::sampleSizeList()
{
return QList<int>() << 8 << 16 << 24 << 32 << 64;
}
-QList<QAudioFormat::Endian> QAudioDeviceInfoPrivate::byteOrderList()
+QList<QAudioFormat::Endian> QAudioDeviceInfoInternal::byteOrderList()
{
return QList<QAudioFormat::Endian>() << QAudioFormat::LittleEndian << QAudioFormat::BigEndian;
}
-QList<QAudioFormat::SampleType> QAudioDeviceInfoPrivate::sampleTypeList()
+QList<QAudioFormat::SampleType> QAudioDeviceInfoInternal::sampleTypeList()
{
return QList<QAudioFormat::SampleType>() << QAudioFormat::SignedInt << QAudioFormat::UnSignedInt << QAudioFormat::Float;
}
@@ -296,7 +296,7 @@ static QByteArray get_device_info(AudioDeviceID audioDevice, QAudio::Mode mode)
return device;
}
-QByteArray QAudioDeviceInfoPrivate::defaultInputDevice()
+QByteArray QAudioDeviceInfoInternal::defaultInputDevice()
{
AudioDeviceID audioDevice;
UInt32 size = sizeof(audioDevice);
@@ -310,7 +310,7 @@ QByteArray QAudioDeviceInfoPrivate::defaultInputDevice()
return get_device_info(audioDevice, QAudio::AudioInput);
}
-QByteArray QAudioDeviceInfoPrivate::defaultOutputDevice()
+QByteArray QAudioDeviceInfoInternal::defaultOutputDevice()
{
AudioDeviceID audioDevice;
UInt32 size = sizeof(audioDevice);
@@ -324,7 +324,7 @@ QByteArray QAudioDeviceInfoPrivate::defaultOutputDevice()
return get_device_info(audioDevice, QAudio::AudioOutput);
}
-QList<QByteArray> QAudioDeviceInfoPrivate::deviceList(QAudio::Mode mode)
+QList<QByteArray> QAudioDeviceInfoInternal::availableDevices(QAudio::Mode mode)
{
QList<QByteArray> devices;
diff --git a/src/multimedia/audio/qaudiodeviceinfo_mac_p.h b/src/multimedia/audio/qaudiodeviceinfo_mac_p.h
index 16429e2c0..0fd3ef50c 100644
--- a/src/multimedia/audio/qaudiodeviceinfo_mac_p.h
+++ b/src/multimedia/audio/qaudiodeviceinfo_mac_p.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -62,14 +62,14 @@ QT_BEGIN_HEADER
QT_BEGIN_NAMESPACE
-class QAudioDeviceInfoPrivate : public QAbstractAudioDeviceInfo
+class QAudioDeviceInfoInternal : public QAbstractAudioDeviceInfo
{
public:
AudioDeviceID deviceId;
QString name;
QAudio::Mode mode;
- QAudioDeviceInfoPrivate(QByteArray const& handle, QAudio::Mode mode);
+ QAudioDeviceInfoInternal(QByteArray const& handle, QAudio::Mode mode);
bool isFormatSupported(const QAudioFormat& format) const;
QAudioFormat preferredFormat() const;
@@ -87,7 +87,7 @@ public:
static QByteArray defaultInputDevice();
static QByteArray defaultOutputDevice();
- static QList<QByteArray> deviceList(QAudio::Mode mode);
+ static QList<QByteArray> availableDevices(QAudio::Mode mode);
};
QT_END_NAMESPACE
diff --git a/src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp b/src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp
index 58e7f8b71..33af02290 100644
--- a/src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp
+++ b/src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -55,6 +55,8 @@
#include <mmsystem.h>
#include "qaudiodeviceinfo_win32_p.h"
+QT_BEGIN_NAMESPACE
+
// For mingw toolchain mmsystem.h only defines half the defines, so add if needed.
#ifndef WAVE_FORMAT_44M08
#define WAVE_FORMAT_44M08 0x00000100
@@ -72,23 +74,23 @@
#endif
-QAudioDeviceInfoPrivate::QAudioDeviceInfoPrivate(QByteArray dev, QAudio::Mode mode)
+QAudioDeviceInfoInternal::QAudioDeviceInfoInternal(QByteArray dev, QAudio::Mode mode)
{
device = QLatin1String(dev);
this->mode = mode;
}
-QAudioDeviceInfoPrivate::~QAudioDeviceInfoPrivate()
+QAudioDeviceInfoInternal::~QAudioDeviceInfoInternal()
{
close();
}
-bool QAudioDeviceInfoPrivate::isFormatSupported(const QAudioFormat& format) const
+bool QAudioDeviceInfoInternal::isFormatSupported(const QAudioFormat& format) const
{
return testSettings(format);
}
-QAudioFormat QAudioDeviceInfoPrivate::preferredFormat() const
+QAudioFormat QAudioDeviceInfoInternal::preferredFormat() const
{
QAudioFormat nearest;
if(mode == QAudio::AudioOutput) {
@@ -97,18 +99,19 @@ QAudioFormat QAudioDeviceInfoPrivate::preferredFormat() const
nearest.setByteOrder(QAudioFormat::LittleEndian);
nearest.setSampleType(QAudioFormat::SignedInt);
nearest.setSampleSize(16);
- nearest.setCodec(tr("audio/pcm"));
+ nearest.setCodec(QLatin1String("audio/pcm"));
} else {
nearest.setFrequency(11025);
nearest.setChannels(1);
+ nearest.setByteOrder(QAudioFormat::LittleEndian);
nearest.setSampleType(QAudioFormat::SignedInt);
nearest.setSampleSize(8);
- nearest.setCodec(tr("audio/pcm"));
+ nearest.setCodec(QLatin1String("audio/pcm"));
}
return nearest;
}
-QAudioFormat QAudioDeviceInfoPrivate::nearestFormat(const QAudioFormat& format) const
+QAudioFormat QAudioDeviceInfoInternal::nearestFormat(const QAudioFormat& format) const
{
if(testSettings(format))
return format;
@@ -116,90 +119,88 @@ QAudioFormat QAudioDeviceInfoPrivate::nearestFormat(const QAudioFormat& format)
return preferredFormat();
}
-QString QAudioDeviceInfoPrivate::deviceName() const
+QString QAudioDeviceInfoInternal::deviceName() const
{
return device;
}
-QStringList QAudioDeviceInfoPrivate::codecList()
+QStringList QAudioDeviceInfoInternal::codecList()
{
updateLists();
return codecz;
}
-QList<int> QAudioDeviceInfoPrivate::frequencyList()
+QList<int> QAudioDeviceInfoInternal::frequencyList()
{
updateLists();
return freqz;
}
-QList<int> QAudioDeviceInfoPrivate::channelsList()
+QList<int> QAudioDeviceInfoInternal::channelsList()
{
updateLists();
return channelz;
}
-QList<int> QAudioDeviceInfoPrivate::sampleSizeList()
+QList<int> QAudioDeviceInfoInternal::sampleSizeList()
{
updateLists();
return sizez;
}
-QList<QAudioFormat::Endian> QAudioDeviceInfoPrivate::byteOrderList()
+QList<QAudioFormat::Endian> QAudioDeviceInfoInternal::byteOrderList()
{
updateLists();
return byteOrderz;
}
-QList<QAudioFormat::SampleType> QAudioDeviceInfoPrivate::sampleTypeList()
+QList<QAudioFormat::SampleType> QAudioDeviceInfoInternal::sampleTypeList()
{
updateLists();
return typez;
}
-bool QAudioDeviceInfoPrivate::open()
+bool QAudioDeviceInfoInternal::open()
{
return true;
}
-void QAudioDeviceInfoPrivate::close()
+void QAudioDeviceInfoInternal::close()
{
}
-bool QAudioDeviceInfoPrivate::testSettings(const QAudioFormat& format) const
+bool QAudioDeviceInfoInternal::testSettings(const QAudioFormat& format) const
{
// Set nearest to closest settings that do work.
// See if what is in settings will work (return value).
- bool testChannel = false;
- bool testCodec = false;
- bool testFreq = false;
-
- int err = 0;
+ bool failed = false;
// For now, just accept only audio/pcm codec
- if(!format.codec().startsWith(tr("audio/pcm"))) {
- err=-1;
- } else
- testCodec = true;
+ if(!format.codec().startsWith(QLatin1String("audio/pcm")))
+ failed = true;
- if(err>=0 && format.channels() != -1) {
- testChannel = true;
- }
+ if(!failed && !(format.channels() == 1 || format.channels() == 2))
+ failed = true;
- if(err>=0 && format.frequency() != -1) {
- testFreq = true;
+ if(!failed) {
+ if(!(format.frequency() == 8000 || format.frequency() == 11025 || format.frequency() == 22050 ||
+ format.frequency() == 44100 || format.frequency() == 48000 || format.frequency() == 96000))
+ failed = true;
}
- if(err == 0) {
+ if(!failed && !(format.sampleSize() == 8 || format.sampleSize() == 16))
+ failed = true;
+
+ if(!failed) {
// settings work
return true;
}
return false;
}
-void QAudioDeviceInfoPrivate::updateLists()
+void QAudioDeviceInfoInternal::updateLists()
{
// redo all lists based on current settings
bool base = false;
@@ -207,7 +208,7 @@ void QAudioDeviceInfoPrivate::updateLists()
DWORD fmt = NULL;
QString tmp;
- if(device.compare(tr("default")) == 0)
+ if(device.compare(QLatin1String("default")) == 0)
base = true;
if(mode == QAudio::AudioOutput) {
@@ -329,18 +330,16 @@ void QAudioDeviceInfoPrivate::updateLists()
typez.append(QAudioFormat::SignedInt);
typez.append(QAudioFormat::UnSignedInt);
- codecz.append(tr("audio/pcm"));
+ codecz.append(QLatin1String("audio/pcm"));
}
}
-QList<QByteArray> QAudioDeviceInfoPrivate::deviceList(QAudio::Mode mode)
+QList<QByteArray> QAudioDeviceInfoInternal::availableDevices(QAudio::Mode mode)
{
Q_UNUSED(mode)
QList<QByteArray> devices;
- devices.append("default");
-
if(mode == QAudio::AudioOutput) {
WAVEOUTCAPS woc;
unsigned long iNumDevs,i;
@@ -363,16 +362,20 @@ QList<QByteArray> QAudioDeviceInfoPrivate::deviceList(QAudio::Mode mode)
}
}
+ if(devices.count() > 0)
+ devices.append("default");
+
return devices;
}
-QByteArray QAudioDeviceInfoPrivate::defaultOutputDevice()
+QByteArray QAudioDeviceInfoInternal::defaultOutputDevice()
{
return QByteArray("default");
}
-QByteArray QAudioDeviceInfoPrivate::defaultInputDevice()
+QByteArray QAudioDeviceInfoInternal::defaultInputDevice()
{
return QByteArray("default");
}
+QT_END_NAMESPACE
diff --git a/src/multimedia/audio/qaudiodeviceinfo_win32_p.h b/src/multimedia/audio/qaudiodeviceinfo_win32_p.h
index 9e0d1ea69..e191b6f1c 100644
--- a/src/multimedia/audio/qaudiodeviceinfo_win32_p.h
+++ b/src/multimedia/audio/qaudiodeviceinfo_win32_p.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -63,16 +63,18 @@
#include <QtMultimedia/qaudioengine.h>
+QT_BEGIN_NAMESPACE
+
const unsigned int MAX_SAMPLE_RATES = 5;
const unsigned int SAMPLE_RATES[] = { 8000, 11025, 22050, 44100, 48000 };
-class QAudioDeviceInfoPrivate : public QAbstractAudioDeviceInfo
+class QAudioDeviceInfoInternal : public QAbstractAudioDeviceInfo
{
Q_OBJECT
public:
- QAudioDeviceInfoPrivate(QByteArray dev,QAudio::Mode mode);
- ~QAudioDeviceInfoPrivate();
+ QAudioDeviceInfoInternal(QByteArray dev,QAudio::Mode mode);
+ ~QAudioDeviceInfoInternal();
bool open();
void close();
@@ -91,7 +93,7 @@ public:
QList<QAudioFormat::SampleType> sampleTypeList();
static QByteArray defaultInputDevice();
static QByteArray defaultOutputDevice();
- static QList<QByteArray> deviceList(QAudio::Mode);
+ static QList<QByteArray> availableDevices(QAudio::Mode);
private:
QAudio::Mode mode;
@@ -105,4 +107,6 @@ private:
QList<QAudioFormat::SampleType> typez;
};
+QT_END_NAMESPACE
+
#endif
diff --git a/src/multimedia/audio/qaudioengine.cpp b/src/multimedia/audio/qaudioengine.cpp
index 1ef26f5c9..88e3804bf 100644
--- a/src/multimedia/audio/qaudioengine.cpp
+++ b/src/multimedia/audio/qaudioengine.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -189,12 +189,12 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn virtual qint64 QAbstractAudioOutput::totalTime() const
+ \fn virtual qint64 QAbstractAudioOutput::processedUSecs() const
Returns the amount of audio data processed since start() was called in milliseconds.
*/
/*!
- \fn virtual qint64 QAbstractAudioOutput::clock() const
+ \fn virtual qint64 QAbstractAudioOutput::elapsedUSecs() const
Returns the milliseconds since start() was called, including time in Idle and suspend states.
*/
@@ -304,12 +304,12 @@ QT_BEGIN_NAMESPACE
*/
/*!
- \fn virtual qint64 QAbstractAudioInput::totalTime() const
+ \fn virtual qint64 QAbstractAudioInput::processedUSecs() const
Returns the amount of audio data processed since start() was called in milliseconds.
*/
/*!
- \fn virtual qint64 QAbstractAudioInput::clock() const
+ \fn virtual qint64 QAbstractAudioInput::elapsedUSecs() const
Returns the milliseconds since start() was called, including time in Idle and suspend states.
*/
diff --git a/src/multimedia/audio/qaudioengine.h b/src/multimedia/audio/qaudioengine.h
index c1683e43c..f9e80c157 100644
--- a/src/multimedia/audio/qaudioengine.h
+++ b/src/multimedia/audio/qaudioengine.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -86,8 +86,8 @@ public:
virtual int bufferSize() const = 0;
virtual void setNotifyInterval(int milliSeconds) = 0;
virtual int notifyInterval() const = 0;
- virtual qint64 totalTime() const = 0;
- virtual qint64 clock() const = 0;
+ virtual qint64 processedUSecs() const = 0;
+ virtual qint64 elapsedUSecs() const = 0;
virtual QAudio::Error error() const = 0;
virtual QAudio::State state() const = 0;
virtual QAudioFormat format() const = 0;
@@ -113,8 +113,8 @@ public:
virtual int bufferSize() const = 0;
virtual void setNotifyInterval(int milliSeconds) = 0;
virtual int notifyInterval() const = 0;
- virtual qint64 totalTime() const = 0;
- virtual qint64 clock() const = 0;
+ virtual qint64 processedUSecs() const = 0;
+ virtual qint64 elapsedUSecs() const = 0;
virtual QAudio::Error error() const = 0;
virtual QAudio::State state() const = 0;
virtual QAudioFormat format() const = 0;
diff --git a/src/multimedia/audio/qaudioengineplugin.cpp b/src/multimedia/audio/qaudioengineplugin.cpp
index 4b484cf72..773fb6d7f 100644
--- a/src/multimedia/audio/qaudioengineplugin.cpp
+++ b/src/multimedia/audio/qaudioengineplugin.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
diff --git a/src/multimedia/audio/qaudioengineplugin.h b/src/multimedia/audio/qaudioengineplugin.h
index b3d25f2ef..82dfa15a1 100644
--- a/src/multimedia/audio/qaudioengineplugin.h
+++ b/src/multimedia/audio/qaudioengineplugin.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -60,7 +60,7 @@ QT_MODULE(Multimedia)
struct Q_MULTIMEDIA_EXPORT QAudioEngineFactoryInterface : public QFactoryInterface
{
- virtual QList<QByteArray> deviceList(QAudio::Mode) const = 0;
+ virtual QList<QByteArray> availableDevices(QAudio::Mode) const = 0;
virtual QAbstractAudioInput* createInput(const QByteArray& device, const QAudioFormat& format = QAudioFormat()) = 0;
virtual QAbstractAudioOutput* createOutput(const QByteArray& device, const QAudioFormat& format = QAudioFormat()) = 0;
virtual QAbstractAudioDeviceInfo* createDeviceInfo(const QByteArray& device, QAudio::Mode mode) = 0;
@@ -80,7 +80,7 @@ public:
~QAudioEnginePlugin();
virtual QStringList keys() const = 0;
- virtual QList<QByteArray> deviceList(QAudio::Mode) const = 0;
+ virtual QList<QByteArray> availableDevices(QAudio::Mode) const = 0;
virtual QAbstractAudioInput* createInput(const QByteArray& device, const QAudioFormat& format = QAudioFormat()) = 0;
virtual QAbstractAudioOutput* createOutput(const QByteArray& device, const QAudioFormat& format = QAudioFormat()) = 0;
virtual QAbstractAudioDeviceInfo* createDeviceInfo(const QByteArray& device, QAudio::Mode mode) = 0;
diff --git a/src/multimedia/audio/qaudioformat.cpp b/src/multimedia/audio/qaudioformat.cpp
index 8f3ef39d2..b2bbe144e 100644
--- a/src/multimedia/audio/qaudioformat.cpp
+++ b/src/multimedia/audio/qaudioformat.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,25 +21,24 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
-
+#include <QDebug>
#include <QtMultimedia/qaudioformat.h>
@@ -57,10 +57,32 @@ public:
sampleType = QAudioFormat::Unknown;
}
+ QAudioFormatPrivate(const QAudioFormatPrivate &other):
+ QSharedData(other),
+ codec(other.codec),
+ byteOrder(other.byteOrder),
+ sampleType(other.sampleType),
+ frequency(other.frequency),
+ channels(other.channels),
+ sampleSize(other.sampleSize)
+ {
+ }
+
+ QAudioFormatPrivate& operator=(const QAudioFormatPrivate &other)
+ {
+ codec = other.codec;
+ byteOrder = other.byteOrder;
+ sampleType = other.sampleType;
+ frequency = other.frequency;
+ channels = other.channels;
+ sampleSize = other.sampleSize;
+
+ return *this;
+ }
+
QString codec;
QAudioFormat::Endian byteOrder;
QAudioFormat::SampleType sampleType;
-
int frequency;
int channels;
int sampleSize;
@@ -112,7 +134,8 @@ public:
through functions in QAudioDeviceInfo. This class also lets you
query available parameter values for a device, so that you can set
the parameters yourself. See the QAudioDeviceInfo class
- description for details.
+ description for details. You need to know the format of the audio
+ streams you wish to play. Qt does not set up formats for you.
*/
/*!
@@ -191,16 +214,13 @@ bool QAudioFormat::operator!=(const QAudioFormat& other) const
}
/*!
- Returns true if any of the parameters are invalid.
+ Returns true if all of the parameters are valid.
*/
-bool QAudioFormat::isNull() const
+bool QAudioFormat::isValid() const
{
- return d->frequency == -1 && d->channels == -1 &&
- d->sampleSize == -1 &&
- d->byteOrder == QAudioFormat::Endian(QSysInfo::ByteOrder) &&
- d->sampleType == QAudioFormat::Unknown &&
- d->codec.isNull();
+ return d->frequency != -1 && d->channels != -1 && d->sampleSize != -1 &&
+ d->sampleType != QAudioFormat::Unknown && !d->codec.isEmpty();
}
/*!
@@ -263,7 +283,7 @@ int QAudioFormat::sampleSize() const
\sa QAudioDeviceInfo::supportedCodecs()
*/
-void QAudioFormat::setCodec(QString codec)
+void QAudioFormat::setCodec(const QString &codec)
{
d->codec = codec;
}
diff --git a/src/multimedia/audio/qaudioformat.h b/src/multimedia/audio/qaudioformat.h
index cb86d2772..7e92c2f45 100644
--- a/src/multimedia/audio/qaudioformat.h
+++ b/src/multimedia/audio/qaudioformat.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -71,7 +71,7 @@ public:
bool operator==(const QAudioFormat &other) const;
bool operator!=(const QAudioFormat &other) const;
- bool isNull() const;
+ bool isValid() const;
void setFrequency(int frequency);
int frequency() const;
@@ -82,7 +82,7 @@ public:
void setSampleSize(int sampleSize);
int sampleSize() const;
- void setCodec(QString codec);
+ void setCodec(const QString &codec);
QString codec() const;
void setByteOrder(QAudioFormat::Endian byteOrder);
diff --git a/src/multimedia/audio/qaudioinput.cpp b/src/multimedia/audio/qaudioinput.cpp
index 3b997848f..8b368d59f 100644
--- a/src/multimedia/audio/qaudioinput.cpp
+++ b/src/multimedia/audio/qaudioinput.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -47,7 +47,6 @@
#include "qaudiodevicefactory_p.h"
-
QT_BEGIN_NAMESPACE
/*!
@@ -61,7 +60,7 @@ QT_BEGIN_NAMESPACE
You can construct an audio input with the system's
\l{QAudioDeviceInfo::defaultInputDevice()}{default audio input
device}. It is also possible to create QAudioInput with a
- specific QAudioDeviceId. When you create the audio input, you
+ specific QAudioDeviceInfo. When you create the audio input, you
should also send in the QAudioFormat to be used for the recording
(see the QAudioFormat class description for details).
@@ -69,7 +68,7 @@ QT_BEGIN_NAMESPACE
QAudioInput lets you record audio with an audio input device. The
default constructor of this class will use the systems default
- audio device, but you can also specify a QAudioDeviceId for a
+ audio device, but you can also specify a QAudioDeviceInfo for a
specific device. You also need to pass in the QAudioFormat in
which you wish to record.
@@ -121,14 +120,19 @@ QT_BEGIN_NAMESPACE
when the state changes (stateChanged()).
QAudioInput provides several ways of measuring the time that has
- passed since the start() of the recording. The \c totalTime()
+ passed since the start() of the recording. The \c processedUSecs()
function returns the length of the stream in microseconds written,
i.e., it leaves out the times the audio input was suspended or idle.
- The clock() function returns the time elapsed since start() was called regardless of
+ The elapsedUSecs() function returns the time elapsed since start() was called regardless of
which states the QAudioInput has been in.
If an error should occur, you can fetch its reason with error().
- The possible error reasons are described by the QAudio::Error enum.
+ The possible error reasons are described by the QAudio::Error
+ enum. The QAudioInput will enter the \l{QAudio::}{StoppedState} when
+ an error is encountered. Connect to the stateChanged() signal to
+ handle the error:
+
+ \snippet doc/src/snippets/audio/main.cpp 0
\sa QAudioOutput, QAudioDeviceInfo
*/
@@ -149,14 +153,14 @@ QAudioInput::QAudioInput(const QAudioFormat &format, QObject *parent):
/*!
Construct a new audio input and attach it to \a parent.
- The \a id of the audio input device is used with the input
+ The device referenced by \a audioDevice is used with the input
\a format parameters.
*/
-QAudioInput::QAudioInput(const QAudioDeviceId &id, const QAudioFormat &format, QObject *parent):
+QAudioInput::QAudioInput(const QAudioDeviceInfo &audioDevice, const QAudioFormat &format, QObject *parent):
QObject(parent)
{
- d = QAudioDeviceFactory::createInputDevice(id, format);
+ d = QAudioDeviceFactory::createInputDevice(audioDevice, format);
connect(d, SIGNAL(notify()), SIGNAL(notify()));
connect(d, SIGNAL(stateChanged(QAudio::State)), SIGNAL(stateChanged(QAudio::State)));
}
@@ -171,37 +175,44 @@ QAudioInput::~QAudioInput()
}
/*!
- Uses the \a device as the QIODevice to transfer data.
- If \a device is null then the class creates an internal QIODevice.
+ Uses the \a device as the QIODevice to transfer data.
+ Passing a QIODevice allows the data to be transfered without any extra code.
+ All that is required is to open the QIODevice.
+
+ \sa QIODevice
+*/
+
+void QAudioInput::start(QIODevice* device)
+{
+ /*
+ -If currently not StoppedState, stop
+ -If previous start was push mode, delete internal QIODevice.
+ -open audio input.
+ If ok, NoError and ActiveState, else OpenError and StoppedState.
+ -emit stateChanged()
+ */
+ d->start(device);
+}
+
+/*!
Returns a pointer to the QIODevice being used to handle the data
transfer. This QIODevice can be used to read() audio data
directly.
- Passing a QIODevice allows the data to be transfered without any extra code.
- All that is required is to open the QIODevice.
- /sa QIODevice
+ \sa QIODevice
*/
-QIODevice* QAudioInput::start(QIODevice* device)
+QIODevice* QAudioInput::start()
{
/*
- PULL MODE (valid QIODevice)
- -If currently not StopState, stop
- -If previous start was push mode, delete internal QIODevice.
- -open audio input.
- If ok, NoError and ActiveState, else OpenError and StopState.
- -emit stateChanged()
- -return device
-
- PUSH MODE (device = 0)
- -If currently not StopState, stop
+ -If currently not StoppedState, stop
-If no internal QIODevice, create one.
-open audio input.
- -If ok, NoError and IdleState, else OpenError and StopState
+ -If ok, NoError and IdleState, else OpenError and StoppedState
-emit stateChanged()
-return internal QIODevice
*/
- return d->start(device);
+ return d->start(0);
}
/*!
@@ -220,8 +231,8 @@ QAudioFormat QAudioInput::format() const
void QAudioInput::stop()
{
/*
- -If StopState, return
- -set to StopState
+ -If StoppedState, return
+ -set to StoppedState
-detach from audio device
-emit stateChanged()
*/
@@ -250,7 +261,7 @@ void QAudioInput::suspend()
/*
-If not ActiveState|IdleState, return
-stop processing audio, saving all buffered audio data
- -set NoError and SuspendState
+ -set NoError and SuspendedState
-emit stateChanged()
*/
d->suspend();
@@ -263,7 +274,7 @@ void QAudioInput::suspend()
void QAudioInput::resume()
{
/*
- -If SuspendState, return
+ -If SuspendedState, return
-resume audio
-(PULL MODE): set ActiveState, NoError
-(PUSH MODE): set IdleState, NoError
@@ -352,9 +363,9 @@ int QAudioInput::notifyInterval() const
was called in microseconds.
*/
-qint64 QAudioInput::totalTime() const
+qint64 QAudioInput::processedUSecs() const
{
- return d->totalTime();
+ return d->processedUSecs();
}
/*!
@@ -362,9 +373,9 @@ qint64 QAudioInput::totalTime() const
Suspend states.
*/
-qint64 QAudioInput::clock() const
+qint64 QAudioInput::elapsedUSecs() const
{
- return d->clock();
+ return d->elapsedUSecs();
}
/*!
diff --git a/src/multimedia/audio/qaudioinput.h b/src/multimedia/audio/qaudioinput.h
index 772f0fbe3..bf93a270b 100644
--- a/src/multimedia/audio/qaudioinput.h
+++ b/src/multimedia/audio/qaudioinput.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -48,7 +48,8 @@
#include <QtMultimedia/qaudio.h>
#include <QtMultimedia/qaudioformat.h>
-#include <QtMultimedia/qaudiodeviceid.h>
+#include <QtMultimedia/qaudiodeviceinfo.h>
+
QT_BEGIN_HEADER
@@ -65,12 +66,14 @@ class Q_MULTIMEDIA_EXPORT QAudioInput : public QObject
public:
explicit QAudioInput(const QAudioFormat &format = QAudioFormat(), QObject *parent = 0);
- explicit QAudioInput(const QAudioDeviceId &id, const QAudioFormat &format = QAudioFormat(), QObject *parent = 0);
+ explicit QAudioInput(const QAudioDeviceInfo &audioDeviceInfo, const QAudioFormat &format = QAudioFormat(), QObject *parent = 0);
~QAudioInput();
QAudioFormat format() const;
- QIODevice* start(QIODevice *device = 0);
+ void start(QIODevice *device);
+ QIODevice* start();
+
void stop();
void reset();
void suspend();
@@ -85,8 +88,8 @@ public:
void setNotifyInterval(int milliSeconds);
int notifyInterval() const;
- qint64 totalTime() const;
- qint64 clock() const;
+ qint64 processedUSecs() const;
+ qint64 elapsedUSecs() const;
QAudio::Error error() const;
QAudio::State state() const;
@@ -96,7 +99,7 @@ Q_SIGNALS:
void notify();
private:
- Q_DISABLE_COPY(QAudioInput);
+ Q_DISABLE_COPY(QAudioInput)
QAbstractAudioInput* d;
};
diff --git a/src/multimedia/audio/qaudioinput_alsa_p.cpp b/src/multimedia/audio/qaudioinput_alsa_p.cpp
index 595c9df8e..3dbe66ce5 100644
--- a/src/multimedia/audio/qaudioinput_alsa_p.cpp
+++ b/src/multimedia/audio/qaudioinput_alsa_p.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -52,9 +52,14 @@
#include <QtCore/qcoreapplication.h>
#include "qaudioinput_alsa_p.h"
+#include "qaudiodeviceinfo_alsa_p.h"
+
+QT_BEGIN_NAMESPACE
//#define DEBUG_AUDIO 1
+static const int minimumIntervalTime = 50;
+
QAudioInputPrivate::QAudioInputPrivate(const QByteArray &device, const QAudioFormat& audioFormat):
settings(audioFormat)
{
@@ -71,13 +76,12 @@ QAudioInputPrivate::QAudioInputPrivate(const QByteArray &device, const QAudioFor
intervalTime = 1000;
audioBuffer = 0;
errorState = QAudio::NoError;
- deviceState = QAudio::StopState;
+ deviceState = QAudio::StoppedState;
audioSource = 0;
pullMode = true;
resuming = false;
- QStringList list1 = QString(tr(device)).split(tr(":"));
- m_device = QByteArray(list1.at(0).toLocal8Bit().constData());
+ m_device = device;
timer = new QTimer(this);
connect(timer,SIGNAL(timeout()),SLOT(userFeed()));
@@ -202,7 +206,7 @@ int QAudioInputPrivate::setFormat()
QIODevice* QAudioInputPrivate::start(QIODevice* device)
{
- if(deviceState != QAudio::StopState)
+ if(deviceState != QAudio::StoppedState)
close();
if(!pullMode && audioSource) {
@@ -230,10 +234,10 @@ QIODevice* QAudioInputPrivate::start(QIODevice* device)
void QAudioInputPrivate::stop()
{
- if(deviceState == QAudio::StopState)
+ if(deviceState == QAudio::StoppedState)
return;
- deviceState = QAudio::StopState;
+ deviceState = QAudio::StoppedState;
close();
emit stateChanged(deviceState);
@@ -245,16 +249,39 @@ bool QAudioInputPrivate::open()
QTime now(QTime::currentTime());
qDebug()<<now.second()<<"s "<<now.msec()<<"ms :open()";
#endif
+ clockStamp.restart();
timeStamp.restart();
+ elapsedTimeOffset = 0;
int dir;
int err=-1;
int count=0;
unsigned int freakuency=settings.frequency();
- QString dev = QString(tr(m_device.constData()));
- if(!dev.contains(tr("default"))) {
- dev = QString(tr("default:CARD=%1")).arg(tr(m_device.constData()));
+ QString dev = QString(QLatin1String(m_device.constData()));
+ QList<QByteArray> devices = QAudioDeviceInfoInternal::availableDevices(QAudio::AudioInput);
+ if(dev.compare(QLatin1String("default")) == 0) {
+#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
+ dev = QLatin1String(devices.first());
+#else
+ dev = QLatin1String("hw:0,0");
+#endif
+ } else {
+#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
+ dev = QLatin1String(m_device);
+#else
+ int idx = 0;
+ char *name;
+
+ QString shortName = QLatin1String(m_device.mid(m_device.indexOf('=',0)+1).constData());
+
+ while(snd_card_get_name(idx,&name) == 0) {
+ if(qstrncmp(shortName.toLocal8Bit().constData(),name,shortName.length()) == 0)
+ break;
+ idx++;
+ }
+ dev = QString(QLatin1String("hw:%1,0")).arg(idx);
+#endif
}
// Step 1: try and open the device
@@ -265,7 +292,7 @@ bool QAudioInputPrivate::open()
}
if (( err < 0)||(handle == 0)) {
errorState = QAudio::OpenError;
- deviceState = QAudio::StopState;
+ deviceState = QAudio::StoppedState;
emit stateChanged(deviceState);
return false;
}
@@ -281,75 +308,75 @@ bool QAudioInputPrivate::open()
err = snd_pcm_hw_params_any( handle, hwparams );
if ( err < 0 ) {
fatal = true;
- errMessage = QString(tr("QAudioInput: snd_pcm_hw_params_any: err = %1")).arg(err);
+ errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_any: err = %1").arg(err);
}
if ( !fatal ) {
err = snd_pcm_hw_params_set_rate_resample( handle, hwparams, 1 );
if ( err < 0 ) {
fatal = true;
- errMessage = QString(tr("QAudioInput: snd_pcm_hw_params_set_rate_resample: err = %1")).arg(err);
+ errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_rate_resample: err = %1").arg(err);
}
}
if ( !fatal ) {
err = snd_pcm_hw_params_set_access( handle, hwparams, access );
if ( err < 0 ) {
fatal = true;
- errMessage = QString(tr("QAudioInput: snd_pcm_hw_params_set_access: err = %1")).arg(err);
+ errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_access: err = %1").arg(err);
}
}
if ( !fatal ) {
err = setFormat();
if ( err < 0 ) {
fatal = true;
- errMessage = QString(tr("QAudioInput: snd_pcm_hw_params_set_format: err = %1")).arg(err);
+ errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_format: err = %1").arg(err);
}
}
if ( !fatal ) {
err = snd_pcm_hw_params_set_channels( handle, hwparams, (unsigned int)settings.channels() );
if ( err < 0 ) {
fatal = true;
- errMessage = QString(tr("QAudioInput: snd_pcm_hw_params_set_channels: err = %1")).arg(err);
+ errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_channels: err = %1").arg(err);
}
}
if ( !fatal ) {
err = snd_pcm_hw_params_set_rate_near( handle, hwparams, &freakuency, 0 );
if ( err < 0 ) {
fatal = true;
- errMessage = QString(tr("QAudioInput: snd_pcm_hw_params_set_rate_near: err = %1")).arg(err);
+ errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_rate_near: err = %1").arg(err);
}
}
if ( !fatal ) {
err = snd_pcm_hw_params_set_buffer_time_near(handle, hwparams, &buffer_time, &dir);
if ( err < 0 ) {
fatal = true;
- errMessage = QString(tr("QAudioInput: snd_pcm_hw_params_set_buffer_time_near: err = %1")).arg(err);
+ errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_buffer_time_near: err = %1").arg(err);
}
}
if ( !fatal ) {
err = snd_pcm_hw_params_set_period_time_near(handle, hwparams, &period_time, &dir);
if ( err < 0 ) {
fatal = true;
- errMessage = QString(tr("QAudioInput: snd_pcm_hw_params_set_period_time_near: err = %1")).arg(err);
+ errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_period_time_near: err = %1").arg(err);
}
}
if ( !fatal ) {
err = snd_pcm_hw_params_set_periods_near(handle, hwparams, &chunks, &dir);
if ( err < 0 ) {
fatal = true;
- errMessage = QString(tr("QAudioInput: snd_pcm_hw_params_set_periods_near: err = %1")).arg(err);
+ errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params_set_periods_near: err = %1").arg(err);
}
}
if ( !fatal ) {
err = snd_pcm_hw_params(handle, hwparams);
if ( err < 0 ) {
fatal = true;
- errMessage = QString(tr("QAudioInput: snd_pcm_hw_params: err = %1")).arg(err);
+ errMessage = QString::fromLatin1("QAudioInput: snd_pcm_hw_params: err = %1").arg(err);
}
}
if( err < 0) {
qWarning()<<errMessage;
errorState = QAudio::OpenError;
- deviceState = QAudio::StopState;
+ deviceState = QAudio::StoppedState;
emit stateChanged(deviceState);
return false;
}
@@ -395,7 +422,7 @@ bool QAudioInputPrivate::open()
void QAudioInputPrivate::close()
{
- deviceState = QAudio::StopState;
+ deviceState = QAudio::StoppedState;
timer->stop();
if ( handle ) {
@@ -441,7 +468,7 @@ qint64 QAudioInputPrivate::read(char* data, qint64 len)
if (readFrames >= 0) {
err = snd_pcm_frames_to_bytes(handle, readFrames);
#ifdef DEBUG_AUDIO
- qDebug()<<QString(tr("PULL: read in bytes = %1 (frames=%2)")).arg(err).arg(readFrames).toLatin1().constData();
+ qDebug()<<QString::fromLatin1("PULL: read in bytes = %1 (frames=%2)").arg(err).arg(readFrames).toLatin1().constData();
#endif
break;
} else if((readFrames == -EAGAIN) || (readFrames == -EINTR)) {
@@ -472,7 +499,7 @@ qint64 QAudioInputPrivate::read(char* data, qint64 len)
if(l < 0) {
close();
errorState = QAudio::IOError;
- deviceState = QAudio::StopState;
+ deviceState = QAudio::StoppedState;
emit stateChanged(deviceState);
} else if(l == 0) {
errorState = QAudio::NoError;
@@ -490,7 +517,7 @@ qint64 QAudioInputPrivate::read(char* data, qint64 len)
void QAudioInputPrivate::resume()
{
- if(deviceState == QAudio::SuspendState) {
+ if(deviceState == QAudio::SuspendedState) {
int err = 0;
if(handle) {
@@ -529,7 +556,10 @@ int QAudioInputPrivate::periodSize() const
void QAudioInputPrivate::setNotifyInterval(int ms)
{
- intervalTime = ms;
+ if(ms >= minimumIntervalTime)
+ intervalTime = ms;
+ else
+ intervalTime = minimumIntervalTime;
}
int QAudioInputPrivate::notifyInterval() const
@@ -537,7 +567,7 @@ int QAudioInputPrivate::notifyInterval() const
return intervalTime;
}
-qint64 QAudioInputPrivate::totalTime() const
+qint64 QAudioInputPrivate::processedUSecs() const
{
return totalTimeValue;
}
@@ -546,14 +576,14 @@ void QAudioInputPrivate::suspend()
{
if(deviceState == QAudio::ActiveState||resuming) {
timer->stop();
- deviceState = QAudio::SuspendState;
+ deviceState = QAudio::SuspendedState;
emit stateChanged(deviceState);
}
}
void QAudioInputPrivate::userFeed()
{
- if(deviceState == QAudio::StopState || deviceState == QAudio::SuspendState)
+ if(deviceState == QAudio::StoppedState || deviceState == QAudio::SuspendedState)
return;
#ifdef DEBUG_AUDIO
QTime now(QTime::currentTime());
@@ -577,21 +607,23 @@ bool QAudioInputPrivate::deviceReady()
if(deviceState != QAudio::ActiveState)
return true;
- if(timeStamp.elapsed() > intervalTime && intervalTime > 50) {
+ if((timeStamp.elapsed() + elapsedTimeOffset) > intervalTime) {
emit notify();
+ elapsedTimeOffset = timeStamp.elapsed() + elapsedTimeOffset - intervalTime;
timeStamp.restart();
}
return true;
}
-qint64 QAudioInputPrivate::clock() const
+qint64 QAudioInputPrivate::elapsedUSecs() const
{
if(!handle)
return 0;
- if(deviceState != QAudio::ActiveState)
+ if (deviceState == QAudio::StoppedState)
return 0;
+#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
snd_pcm_status_t* status;
snd_pcm_status_alloca(&status);
@@ -607,9 +639,12 @@ qint64 QAudioInputPrivate::clock() const
l = -l;
l %= 1000000;
}
- return ((t1.tv_sec * 1000)+l/1000);
+ return ((t1.tv_sec * 1000000)+l);
} else
return 0;
+#else
+ return clockStamp.elapsed()*1000;
+#endif
}
void QAudioInputPrivate::reset()
@@ -648,7 +683,7 @@ qint64 InputPrivate::readData( char* data, qint64 len)
if (readFrames >= 0) {
err = snd_pcm_frames_to_bytes(audioDevice->handle, readFrames);
#ifdef DEBUG_AUDIO
- qDebug()<<QString(tr("PUSH: read in bytes = %1 (frames=%2)")).arg(err).arg(readFrames).toLatin1().constData();
+ qDebug()<<QString::fromLatin1("PUSH: read in bytes = %1 (frames=%2)").arg(err).arg(readFrames).toLatin1().constData();
#endif
break;
} else if((readFrames == -EAGAIN) || (readFrames == -EINTR)) {
@@ -686,3 +721,4 @@ void InputPrivate::trigger()
emit readyRead();
}
+QT_END_NAMESPACE
diff --git a/src/multimedia/audio/qaudioinput_alsa_p.h b/src/multimedia/audio/qaudioinput_alsa_p.h
index 3f7c85edb..67d5cf55e 100644
--- a/src/multimedia/audio/qaudioinput_alsa_p.h
+++ b/src/multimedia/audio/qaudioinput_alsa_p.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -67,6 +67,8 @@
#include <QtMultimedia/qaudiodeviceinfo.h>
#include <QtMultimedia/qaudioengine.h>
+QT_BEGIN_NAMESPACE
+
class InputPrivate;
class QAudioInputPrivate : public QAbstractAudioInput
@@ -89,8 +91,8 @@ public:
int bufferSize() const;
void setNotifyInterval(int milliSeconds);
int notifyInterval() const;
- qint64 totalTime() const;
- qint64 clock() const;
+ qint64 processedUSecs() const;
+ qint64 elapsedUSecs() const;
QAudio::Error error() const;
QAudio::State state() const;
QAudioFormat format() const;
@@ -115,6 +117,8 @@ private:
QTimer* timer;
QTime timeStamp;
+ QTime clockStamp;
+ qint64 elapsedTimeOffset;
int intervalTime;
char* audioBuffer;
int bytesAvailable;
@@ -148,4 +152,6 @@ private:
QAudioInputPrivate *audioDevice;
};
+QT_END_NAMESPACE
+
#endif
diff --git a/src/multimedia/audio/qaudioinput_mac_p.cpp b/src/multimedia/audio/qaudioinput_mac_p.cpp
index 5c58e032a..d63045fc7 100644
--- a/src/multimedia/audio/qaudioinput_mac_p.cpp
+++ b/src/multimedia/audio/qaudioinput_mac_p.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -376,6 +376,9 @@ public:
void flush(bool all = false)
{
+ if (m_device == 0)
+ return;
+
const int used = m_buffer->used();
const int readSize = all ? used : used - (used % m_maxPeriodSize);
@@ -523,7 +526,7 @@ QAudioInputPrivate::QAudioInputPrivate(const QByteArray& device, QAudioFormat co
internalBufferSize = default_buffer_size;
clockFrequency = AudioGetHostClockFrequency() / 1000;
errorCode = QAudio::NoError;
- stateCode = QAudio::StopState;
+ stateCode = QAudio::StoppedState;
intervalTimer = new QTimer(this);
intervalTimer->setInterval(1000);
@@ -705,7 +708,7 @@ QIODevice* QAudioInputPrivate::start(QIODevice* device)
QIODevice* op = device;
if (!open()) {
- stateCode = QAudio::StopState;
+ stateCode = QAudio::StoppedState;
errorCode = QAudio::OpenError;
return audioIO;
}
@@ -723,18 +726,22 @@ QIODevice* QAudioInputPrivate::start(QIODevice* device)
audioThreadStart();
+ stateCode = QAudio::ActiveState;
+ errorCode = QAudio::NoError;
+ emit stateChanged(stateCode);
+
return op;
}
void QAudioInputPrivate::stop()
{
QMutexLocker lock(&mutex);
- if (stateCode != QAudio::StopState) {
+ if (stateCode != QAudio::StoppedState) {
audioThreadStop();
audioBuffer->flush(true);
errorCode = QAudio::NoError;
- stateCode = QAudio::StopState;
+ stateCode = QAudio::StoppedState;
QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode));
}
}
@@ -742,11 +749,11 @@ void QAudioInputPrivate::stop()
void QAudioInputPrivate::reset()
{
QMutexLocker lock(&mutex);
- if (stateCode != QAudio::StopState) {
+ if (stateCode != QAudio::StoppedState) {
audioThreadStop();
errorCode = QAudio::NoError;
- stateCode = QAudio::StopState;
+ stateCode = QAudio::StoppedState;
QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode));
}
}
@@ -758,7 +765,7 @@ void QAudioInputPrivate::suspend()
audioThreadStop();
errorCode = QAudio::NoError;
- stateCode = QAudio::SuspendState;
+ stateCode = QAudio::SuspendedState;
QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode));
}
}
@@ -766,7 +773,7 @@ void QAudioInputPrivate::suspend()
void QAudioInputPrivate::resume()
{
QMutexLocker lock(&mutex);
- if (stateCode == QAudio::SuspendState) {
+ if (stateCode == QAudio::SuspendedState) {
audioThreadStart();
errorCode = QAudio::NoError;
@@ -805,13 +812,16 @@ int QAudioInputPrivate::notifyInterval() const
return intervalTimer->interval();
}
-qint64 QAudioInputPrivate::totalTime() const
+qint64 QAudioInputPrivate::processedUSecs() const
{
return totalFrames * 1000000 / audioFormat.frequency();
}
-qint64 QAudioInputPrivate::clock() const
+qint64 QAudioInputPrivate::elapsedUSecs() const
{
+ if (stateCode == QAudio::StoppedState)
+ return 0;
+
return (AudioGetCurrentHostTime() - startTime) / (clockFrequency / 1000);
}
@@ -865,7 +875,7 @@ void QAudioInputPrivate::audioDeviceError()
audioDeviceStop();
errorCode = QAudio::IOError;
- stateCode = QAudio::StopState;
+ stateCode = QAudio::StoppedState;
QMetaObject::invokeMethod(this, "deviceStopped", Qt::QueuedConnection);
}
}
diff --git a/src/multimedia/audio/qaudioinput_mac_p.h b/src/multimedia/audio/qaudioinput_mac_p.h
index d6e1d153a..2dbb808d2 100644
--- a/src/multimedia/audio/qaudioinput_mac_p.h
+++ b/src/multimedia/audio/qaudioinput_mac_p.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -129,8 +129,8 @@ public:
void setNotifyInterval(int milliSeconds);
int notifyInterval() const;
- qint64 totalTime() const;
- qint64 clock() const;
+ qint64 processedUSecs() const;
+ qint64 elapsedUSecs() const;
QAudio::Error error() const;
QAudio::State state() const;
@@ -145,10 +145,6 @@ public:
void startTimers();
void stopTimers();
-signals:
- void stateChanged(QAudio::State);
- void notify();
-
private slots:
void deviceStopped();
diff --git a/src/multimedia/audio/qaudioinput_win32_p.cpp b/src/multimedia/audio/qaudioinput_win32_p.cpp
index 6da80ee04..b7f9ffd82 100644
--- a/src/multimedia/audio/qaudioinput_win32_p.cpp
+++ b/src/multimedia/audio/qaudioinput_win32_p.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -53,10 +53,14 @@
#include "qaudioinput_win32_p.h"
+QT_BEGIN_NAMESPACE
+
//#define DEBUG_AUDIO 1
static CRITICAL_SECTION waveInCriticalSection;
+static const int minimumIntervalTime = 50;
+
QAudioInputPrivate::QAudioInputPrivate(const QByteArray &device, const QAudioFormat& audioFormat):
settings(audioFormat)
{
@@ -67,10 +71,11 @@ QAudioInputPrivate::QAudioInputPrivate(const QByteArray &device, const QAudioFor
totalTimeValue = 0;
intervalTime = 1000;
errorState = QAudio::NoError;
- deviceState = QAudio::StopState;
+ deviceState = QAudio::StoppedState;
audioSource = 0;
pullMode = true;
resuming = false;
+ finished = false;
connect(this,SIGNAL(processMore()),SLOT(deviceReady()));
@@ -79,7 +84,7 @@ QAudioInputPrivate::QAudioInputPrivate(const QByteArray &device, const QAudioFor
QAudioInputPrivate::~QAudioInputPrivate()
{
- close();
+ stop();
DeleteCriticalSection(&waveInCriticalSection);
}
@@ -102,10 +107,13 @@ void CALLBACK QAudioInputPrivate::waveInProc( HWAVEIN hWaveIn, UINT uMsg,
EnterCriticalSection(&waveInCriticalSection);
if(qAudio->waveFreeBlockCount > 0)
qAudio->waveFreeBlockCount--;
- LeaveCriticalSection(&waveInCriticalSection);
qAudio->feedback();
+ LeaveCriticalSection(&waveInCriticalSection);
break;
case WIM_CLOSE:
+ EnterCriticalSection(&waveInCriticalSection);
+ qAudio->finished = true;
+ LeaveCriticalSection(&waveInCriticalSection);
break;
default:
return;
@@ -165,7 +173,7 @@ QAudioFormat QAudioInputPrivate::format() const
QIODevice* QAudioInputPrivate::start(QIODevice* device)
{
- if(deviceState != QAudio::StopState)
+ if(deviceState != QAudio::StoppedState)
close();
if(!pullMode && audioSource) {
@@ -193,11 +201,9 @@ QIODevice* QAudioInputPrivate::start(QIODevice* device)
void QAudioInputPrivate::stop()
{
- if(deviceState == QAudio::StopState)
+ if(deviceState == QAudio::StoppedState)
return;
- deviceState = QAudio::StopState;
-
close();
emit stateChanged(deviceState);
}
@@ -216,7 +222,13 @@ bool QAudioInputPrivate::open()
} else {
period_size = buffer_size/5;
}
+#ifdef Q_OS_WINCE
+ // For wince reduce size to 40ms for buffer size and 20ms period
+ buffer_size = settings.frequency()*settings.channels()*(settings.sampleSize()/8)*0.04;
+ period_size = buffer_size/2;
+#endif
timeStamp.restart();
+ elapsedTimeOffset = 0;
wfx.nSamplesPerSec = settings.frequency();
wfx.wBitsPerSample = settings.sampleSize();
wfx.nChannels = settings.channels();
@@ -236,7 +248,7 @@ bool QAudioInputPrivate::open()
== MMSYSERR_NOERROR) {
QString tmp;
tmp = QString::fromUtf16((const unsigned short*)wic.szPname);
- if(tmp.compare(tr(m_device)) == 0) {
+ if(tmp.compare(QLatin1String(m_device)) == 0) {
devId = ii;
break;
}
@@ -248,13 +260,25 @@ bool QAudioInputPrivate::open()
(DWORD_PTR) this,
CALLBACK_FUNCTION) != MMSYSERR_NOERROR) {
errorState = QAudio::OpenError;
- deviceState = QAudio::StopState;
+ deviceState = QAudio::StoppedState;
emit stateChanged(deviceState);
qWarning("QAudioInput: failed to open audio device");
return false;
}
waveBlocks = allocateBlocks(period_size, buffer_size/period_size);
+
+ if(waveBlocks == 0) {
+ errorState = QAudio::OpenError;
+ deviceState = QAudio::StoppedState;
+ emit stateChanged(deviceState);
+ qWarning("QAudioInput: failed to allocate blocks. open failed");
+ return false;
+ }
+
+ EnterCriticalSection(&waveInCriticalSection);
waveFreeBlockCount = buffer_size/period_size;
+ LeaveCriticalSection(&waveInCriticalSection);
+
waveCurrentBlock = 0;
for(int i=0; i<buffer_size/period_size; i++) {
@@ -262,7 +286,7 @@ bool QAudioInputPrivate::open()
if(result != MMSYSERR_NOERROR) {
qWarning("QAudioInput: failed to setup block %d,err=%d",i,result);
errorState = QAudio::OpenError;
- deviceState = QAudio::StopState;
+ deviceState = QAudio::StoppedState;
emit stateChanged(deviceState);
return false;
}
@@ -271,11 +295,12 @@ bool QAudioInputPrivate::open()
if(result) {
qWarning("QAudioInput: failed to start audio input");
errorState = QAudio::OpenError;
- deviceState = QAudio::StopState;
+ deviceState = QAudio::StoppedState;
emit stateChanged(deviceState);
return false;
}
timeStampOpened.restart();
+ elapsedTimeOffset = 0;
totalTimeValue = 0;
errorState = QAudio::NoError;
deviceState = QAudio::ActiveState;
@@ -284,22 +309,33 @@ bool QAudioInputPrivate::open()
void QAudioInputPrivate::close()
{
- deviceState = QAudio::StopState;
- int delay = (buffer_size-bytesReady())*1000/(settings.frequency()
- *settings.channels()*(settings.sampleSize()/8));
+ if(deviceState == QAudio::StoppedState)
+ return;
+
waveInReset(hWaveIn);
- Sleep(delay+10);
+ waveInClose(hWaveIn);
+ deviceState = QAudio::StoppedState;
+ int count = 0;
+ while(!finished && count < 100) {
+ count++;
+ Sleep(10);
+ }
+
+ EnterCriticalSection(&waveInCriticalSection);
for(int i=0; i<waveFreeBlockCount; i++) {
if(waveBlocks[i].dwFlags & WHDR_PREPARED)
waveInUnprepareHeader(hWaveIn,&waveBlocks[i],sizeof(WAVEHDR));
}
+ LeaveCriticalSection(&waveInCriticalSection);
freeBlocks(waveBlocks);
- waveInClose(hWaveIn);
}
int QAudioInputPrivate::bytesReady() const
{
+ if(period_size == 0 || buffer_size == 0)
+ return 0;
+
int buf = ((buffer_size/period_size)-waveFreeBlockCount)*period_size;
if(buf < 0)
buf = 0;
@@ -367,14 +403,14 @@ qint64 QAudioInputPrivate::read(char* data, qint64 len)
if(result != MMSYSERR_NOERROR) {
qWarning("QAudioInput: failed to prepare block %d,err=%d",header,result);
errorState = QAudio::OpenError;
- deviceState = QAudio::StopState;
+ deviceState = QAudio::StoppedState;
emit stateChanged(deviceState);
}
result = waveInAddBuffer(hWaveIn, &waveBlocks[header], sizeof(WAVEHDR));
if(result != MMSYSERR_NOERROR) {
qWarning("QAudioInput: failed to setup block %d,err=%d",header,result);
errorState = QAudio::OpenError;
- deviceState = QAudio::StopState;
+ deviceState = QAudio::StoppedState;
emit stateChanged(deviceState);
}
header++;
@@ -382,6 +418,7 @@ qint64 QAudioInputPrivate::read(char* data, qint64 len)
header = 0;
p+=l;
+ EnterCriticalSection(&waveInCriticalSection);
if(!pullMode) {
if(l+period_size > len && waveFreeBlockCount == buffer_size/period_size)
done = true;
@@ -389,6 +426,8 @@ qint64 QAudioInputPrivate::read(char* data, qint64 len)
if(waveFreeBlockCount == buffer_size/period_size)
done = true;
}
+ LeaveCriticalSection(&waveInCriticalSection);
+
written+=l;
}
#ifdef DEBUG_AUDIO
@@ -399,19 +438,22 @@ qint64 QAudioInputPrivate::read(char* data, qint64 len)
void QAudioInputPrivate::resume()
{
- if(deviceState == QAudio::SuspendState) {
+ if(deviceState == QAudio::SuspendedState) {
deviceState = QAudio::ActiveState;
for(int i=0; i<buffer_size/period_size; i++) {
result = waveInAddBuffer(hWaveIn, &waveBlocks[i], sizeof(WAVEHDR));
if(result != MMSYSERR_NOERROR) {
qWarning("QAudioInput: failed to setup block %d,err=%d",i,result);
errorState = QAudio::OpenError;
- deviceState = QAudio::StopState;
+ deviceState = QAudio::StoppedState;
emit stateChanged(deviceState);
return;
}
}
+ EnterCriticalSection(&waveInCriticalSection);
waveFreeBlockCount = buffer_size/period_size;
+ LeaveCriticalSection(&waveInCriticalSection);
+
waveCurrentBlock = 0;
header = 0;
resuming = true;
@@ -438,7 +480,10 @@ int QAudioInputPrivate::periodSize() const
void QAudioInputPrivate::setNotifyInterval(int ms)
{
- intervalTime = ms;
+ if(ms >= minimumIntervalTime)
+ intervalTime = ms;
+ else
+ intervalTime = minimumIntervalTime;
}
int QAudioInputPrivate::notifyInterval() const
@@ -446,7 +491,7 @@ int QAudioInputPrivate::notifyInterval() const
return intervalTime;
}
-qint64 QAudioInputPrivate::totalTime() const
+qint64 QAudioInputPrivate::processedUSecs() const
{
return totalTimeValue;
}
@@ -455,7 +500,7 @@ void QAudioInputPrivate::suspend()
{
if(deviceState == QAudio::ActiveState) {
waveInReset(hWaveIn);
- deviceState = QAudio::SuspendState;
+ deviceState = QAudio::SuspendedState;
emit stateChanged(deviceState);
}
}
@@ -464,11 +509,11 @@ void QAudioInputPrivate::feedback()
{
#ifdef DEBUG_AUDIO
QTime now(QTime::currentTime());
- qDebug()<<now.second()<<"s "<<now.msec()<<"ms :feedback() INPUT";
+ qDebug()<<now.second()<<"s "<<now.msec()<<"ms :feedback() INPUT "<<this;
#endif
bytesAvailable = bytesReady();
- if(!(deviceState==QAudio::StopState||deviceState==QAudio::SuspendState))
+ if(!(deviceState==QAudio::StoppedState||deviceState==QAudio::SuspendedState))
emit processMore();
}
@@ -489,19 +534,20 @@ bool QAudioInputPrivate::deviceReady()
if(deviceState != QAudio::ActiveState)
return true;
- if(timeStamp.elapsed() > intervalTime && intervalTime > 50) {
+ if((timeStamp.elapsed() + elapsedTimeOffset) > intervalTime) {
emit notify();
+ elapsedTimeOffset = timeStamp.elapsed() + elapsedTimeOffset - intervalTime;
timeStamp.restart();
}
return true;
}
-qint64 QAudioInputPrivate::clock() const
+qint64 QAudioInputPrivate::elapsedUSecs() const
{
- if(deviceState != QAudio::ActiveState)
+ if (deviceState == QAudio::StoppedState)
return 0;
- return timeStampOpened.elapsed();
+ return timeStampOpened.elapsed()*1000;
}
void QAudioInputPrivate::reset()
@@ -539,3 +585,4 @@ void InputPrivate::trigger()
emit readyRead();
}
+QT_END_NAMESPACE
diff --git a/src/multimedia/audio/qaudioinput_win32_p.h b/src/multimedia/audio/qaudioinput_win32_p.h
index 7f7b823b3..a2bd6876f 100644
--- a/src/multimedia/audio/qaudioinput_win32_p.h
+++ b/src/multimedia/audio/qaudioinput_win32_p.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -68,6 +68,8 @@
#include <QtMultimedia/qaudioengine.h>
+QT_BEGIN_NAMESPACE
+
class QAudioInputPrivate : public QAbstractAudioInput
{
Q_OBJECT
@@ -89,8 +91,8 @@ public:
int bufferSize() const;
void setNotifyInterval(int milliSeconds);
int notifyInterval() const;
- qint64 totalTime() const;
- qint64 clock() const;
+ qint64 processedUSecs() const;
+ qint64 elapsedUSecs() const;
QAudio::Error error() const;
QAudio::State state() const;
@@ -107,6 +109,7 @@ private:
int bytesAvailable;
int intervalTime;
QTime timeStamp;
+ qint64 elapsedTimeOffset;
QTime timeStampOpened;
qint64 totalTimeValue;
bool pullMode;
@@ -115,6 +118,7 @@ private:
HWAVEIN hWaveIn;
MMRESULT result;
WAVEHDR* waveBlocks;
+ volatile bool finished;
volatile int waveFreeBlockCount;
int waveCurrentBlock;
@@ -149,4 +153,6 @@ private:
QAudioInputPrivate *audioDevice;
};
+QT_END_NAMESPACE
+
#endif
diff --git a/src/multimedia/audio/qaudiooutput.cpp b/src/multimedia/audio/qaudiooutput.cpp
index 9a9fe8262..f8f2fa1a3 100644
--- a/src/multimedia/audio/qaudiooutput.cpp
+++ b/src/multimedia/audio/qaudiooutput.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -61,7 +61,7 @@ QT_BEGIN_NAMESPACE
You can construct an audio output with the system's
\l{QAudioDeviceInfo::defaultOutputDevice()}{default audio output
device}. It is also possible to create QAudioOutput with a
- specific QAudioDeviceId. When you create the audio output, you
+ specific QAudioDeviceInfo. When you create the audio output, you
should also send in the QAudioFormat to be used for the playback
(see the QAudioFormat class description for details).
@@ -125,13 +125,16 @@ QT_BEGIN_NAMESPACE
not emitted. A typical use-case would be to update a
\l{QSlider}{slider} that allows seeking in the stream.
If you want the time since playback started regardless of which
- states the audio output has been in, clock() is the function for you.
+ states the audio output has been in, elapsedUSecs() is the function for you.
If an error occurs, you can fetch the \l{QAudio::Error}{error
type} with the error() function. Please see the QAudio::Error enum
- for a description of the possible errors that are reported.
+ for a description of the possible errors that are reported. When
+ an error is encountered, the state changes to QAudio::StoppedState.
+ You can check for errors by connecting to the stateChanged()
+ signal:
- If an error is encountered state changes to QAudio::StopState.
+ \snippet doc/src/snippets/audio/main.cpp 3
\sa QAudioInput, QAudioDeviceInfo
*/
@@ -152,14 +155,14 @@ QAudioOutput::QAudioOutput(const QAudioFormat &format, QObject *parent):
/*!
Construct a new audio output and attach it to \a parent.
- The \a id of the audio output device is used with the output
+ The device referenced by \a audioDevice is used with the output
\a format parameters.
*/
-QAudioOutput::QAudioOutput(const QAudioDeviceId &id, const QAudioFormat &format, QObject *parent):
+QAudioOutput::QAudioOutput(const QAudioDeviceInfo &audioDevice, const QAudioFormat &format, QObject *parent):
QObject(parent)
{
- d = QAudioDeviceFactory::createOutputDevice(id, format);
+ d = QAudioDeviceFactory::createOutputDevice(audioDevice, format);
connect(d, SIGNAL(notify()), SIGNAL(notify()));
connect(d, SIGNAL(stateChanged(QAudio::State)), SIGNAL(stateChanged(QAudio::State)));
}
@@ -185,36 +188,42 @@ QAudioFormat QAudioOutput::format() const
/*!
Uses the \a device as the QIODevice to transfer data.
- If \a device is null then the class creates an internal QIODevice.
- Returns a pointer to the QIODevice being used to handle the data
- transfer. This QIODevice can be used to write() audio data
- directly.
Passing a QIODevice allows the data to be transfered without any extra code.
All that is required is to open the QIODevice.
- /sa QIODevice
+ \sa QIODevice
*/
-QIODevice* QAudioOutput::start(QIODevice* device)
+void QAudioOutput::start(QIODevice* device)
{
/*
- PULL MODE (valid QIODevice)
- -If currently not StopState, stop.
+ -If currently not StoppedState, stop.
-If previous start was push mode, delete internal QIODevice.
-open audio output.
- -If ok, NoError and ActiveState, else OpenError and StopState
+ -If ok, NoError and ActiveState, else OpenError and StoppedState
-emit stateChanged()
- -return device
+ */
+ d->start(device);
+}
+
+/*!
+ Returns a pointer to the QIODevice being used to handle the data
+ transfer. This QIODevice can be used to write() audio data directly.
- PUSH MODE (device = 0)
- -If currently not StopState, stop.
+ \sa QIODevice
+*/
+
+QIODevice* QAudioOutput::start()
+{
+ /*
+ -If currently not StoppedState, stop.
-If no internal QIODevice, create one.
-open audio output.
- -If ok, NoError and IdleState, else OpenError and StopState
+ -If ok, NoError and IdleState, else OpenError and StoppedState
-emit stateChanged()
-return internal QIODevice
*/
- return d->start(device);
+ return d->start(0);
}
/*!
@@ -224,8 +233,8 @@ QIODevice* QAudioOutput::start(QIODevice* device)
void QAudioOutput::stop()
{
/*
- -If StopState, return
- -set to StopState
+ -If StoppedState, return
+ -set to StoppedState
-detach from audio device
-emit stateChanged()
*/
@@ -254,7 +263,7 @@ void QAudioOutput::suspend()
/*
-If not ActiveState|IdleState, return
-stop processing audio, saving all buffered audio data
- -set NoError and SuspendState
+ -set NoError and SuspendedState
-emit stateChanged()
*/
d->suspend();
@@ -267,7 +276,7 @@ void QAudioOutput::suspend()
void QAudioOutput::resume()
{
/*
- -If SuspendState, return
+ -If SuspendedState, return
-resume audio
-(PULL MODE): set ActiveState, NoError
-(PUSH MODE): set IdleState, NoError
@@ -355,9 +364,9 @@ int QAudioOutput::notifyInterval() const
was called in microseconds.
*/
-qint64 QAudioOutput::totalTime() const
+qint64 QAudioOutput::processedUSecs() const
{
- return d->totalTime();
+ return d->processedUSecs();
}
/*!
@@ -365,9 +374,9 @@ qint64 QAudioOutput::totalTime() const
Suspend states.
*/
-qint64 QAudioOutput::clock() const
+qint64 QAudioOutput::elapsedUSecs() const
{
- return d->clock();
+ return d->elapsedUSecs();
}
/*!
diff --git a/src/multimedia/audio/qaudiooutput.h b/src/multimedia/audio/qaudiooutput.h
index 3c6e9ba5e..38bab8eef 100644
--- a/src/multimedia/audio/qaudiooutput.h
+++ b/src/multimedia/audio/qaudiooutput.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -48,7 +48,7 @@
#include <QtMultimedia/qaudio.h>
#include <QtMultimedia/qaudioformat.h>
-#include <QtMultimedia/qaudiodeviceid.h>
+#include <QtMultimedia/qaudiodeviceinfo.h>
QT_BEGIN_HEADER
@@ -66,12 +66,14 @@ class Q_MULTIMEDIA_EXPORT QAudioOutput : public QObject
public:
explicit QAudioOutput(const QAudioFormat &format = QAudioFormat(), QObject *parent = 0);
- explicit QAudioOutput(const QAudioDeviceId &id, const QAudioFormat &format = QAudioFormat(), QObject *parent = 0);
+ explicit QAudioOutput(const QAudioDeviceInfo &audioDeviceInfo, const QAudioFormat &format = QAudioFormat(), QObject *parent = 0);
~QAudioOutput();
QAudioFormat format() const;
- QIODevice* start(QIODevice *device = 0);
+ void start(QIODevice *device);
+ QIODevice* start();
+
void stop();
void reset();
void suspend();
@@ -86,8 +88,8 @@ public:
void setNotifyInterval(int milliSeconds);
int notifyInterval() const;
- qint64 totalTime() const;
- qint64 clock() const;
+ qint64 processedUSecs() const;
+ qint64 elapsedUSecs() const;
QAudio::Error error() const;
QAudio::State state() const;
diff --git a/src/multimedia/audio/qaudiooutput_alsa_p.cpp b/src/multimedia/audio/qaudiooutput_alsa_p.cpp
index 5997d3197..020a1044d 100644
--- a/src/multimedia/audio/qaudiooutput_alsa_p.cpp
+++ b/src/multimedia/audio/qaudiooutput_alsa_p.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -52,9 +52,14 @@
#include <QtCore/qcoreapplication.h>
#include "qaudiooutput_alsa_p.h"
+#include "qaudiodeviceinfo_alsa_p.h"
+
+QT_BEGIN_NAMESPACE
//#define DEBUG_AUDIO 1
+static const int minimumIntervalTime = 50;
+
QAudioOutputPrivate::QAudioOutputPrivate(const QByteArray &device, const QAudioFormat& audioFormat):
settings(audioFormat)
{
@@ -73,13 +78,13 @@ QAudioOutputPrivate::QAudioOutputPrivate(const QByteArray &device, const QAudioF
intervalTime = 1000;
audioBuffer = 0;
errorState = QAudio::NoError;
- deviceState = QAudio::StopState;
+ deviceState = QAudio::StoppedState;
audioSource = 0;
pullMode = true;
resuming = false;
opened = false;
- QStringList list1 = QString(tr(device)).split(tr(":"));
+ QStringList list1 = QString(QLatin1String(device)).split(QLatin1String(":"));
m_device = QByteArray(list1.at(0).toLocal8Bit().constData());
timer = new QTimer(this);
@@ -211,8 +216,8 @@ int QAudioOutputPrivate::setFormat()
QIODevice* QAudioOutputPrivate::start(QIODevice* device)
{
- if(deviceState != QAudio::StopState)
- deviceState = QAudio::StopState;
+ if(deviceState != QAudio::StoppedState)
+ deviceState = QAudio::StoppedState;
errorState = QAudio::NoError;
@@ -252,9 +257,9 @@ QIODevice* QAudioOutputPrivate::start(QIODevice* device)
void QAudioOutputPrivate::stop()
{
- if(deviceState == QAudio::StopState)
+ if(deviceState == QAudio::StoppedState)
return;
- deviceState = QAudio::StopState;
+ deviceState = QAudio::StoppedState;
close();
emit stateChanged(deviceState);
}
@@ -269,16 +274,39 @@ bool QAudioOutputPrivate::open()
qDebug()<<now.second()<<"s "<<now.msec()<<"ms :open()";
#endif
timeStamp.restart();
+ elapsedTimeOffset = 0;
int dir;
int err=-1;
int count=0;
unsigned int freakuency=settings.frequency();
- QString dev = tr(m_device.constData());
- if(!dev.contains(tr("default"))) {
- dev = QString(tr("default:CARD=%1")).arg(tr(m_device.constData()));
+ QString dev = QLatin1String(m_device.constData());
+ QList<QByteArray> devices = QAudioDeviceInfoInternal::availableDevices(QAudio::AudioOutput);
+ if(dev.compare(QLatin1String("default")) == 0) {
+#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
+ dev = QLatin1String(devices.first().constData());
+#else
+ dev = QLatin1String("hw:0,0");
+#endif
+ } else {
+#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
+ dev = QLatin1String(m_device);
+#else
+ int idx = 0;
+ char *name;
+
+ QString shortName = QLatin1String(m_device.mid(m_device.indexOf('=',0)+1).constData());
+
+ while(snd_card_get_name(idx,&name) == 0) {
+ if(qstrncmp(shortName.toLocal8Bit().constData(),name,shortName.length()) == 0)
+ break;
+ idx++;
+ }
+ dev = QString(QLatin1String("hw:%1,0")).arg(idx);
+#endif
}
+
// Step 1: try and open the device
while((count < 5) && (err < 0)) {
err=snd_pcm_open(&handle,dev.toLocal8Bit().constData(),SND_PCM_STREAM_PLAYBACK,0);
@@ -287,7 +315,7 @@ bool QAudioOutputPrivate::open()
}
if (( err < 0)||(handle == 0)) {
errorState = QAudio::OpenError;
- deviceState = QAudio::StopState;
+ deviceState = QAudio::StoppedState;
return false;
}
snd_pcm_nonblock( handle, 0 );
@@ -302,75 +330,75 @@ bool QAudioOutputPrivate::open()
err = snd_pcm_hw_params_any( handle, hwparams );
if ( err < 0 ) {
fatal = true;
- errMessage = QString(tr("QAudioOutput: snd_pcm_hw_params_any: err = %1")).arg(err);
+ errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_any: err = %1").arg(err);
}
if ( !fatal ) {
err = snd_pcm_hw_params_set_rate_resample( handle, hwparams, 1 );
if ( err < 0 ) {
fatal = true;
- errMessage = QString(tr("QAudioOutput: snd_pcm_hw_params_set_rate_resample: err = %1")).arg(err);
+ errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_rate_resample: err = %1").arg(err);
}
}
if ( !fatal ) {
err = snd_pcm_hw_params_set_access( handle, hwparams, access );
if ( err < 0 ) {
fatal = true;
- errMessage = QString(tr("QAudioOutput: snd_pcm_hw_params_set_access: err = %1")).arg(err);
+ errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_access: err = %1").arg(err);
}
}
if ( !fatal ) {
err = setFormat();
if ( err < 0 ) {
fatal = true;
- errMessage = QString(tr("QAudioOutput: snd_pcm_hw_params_set_format: err = %1")).arg(err);
+ errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_format: err = %1").arg(err);
}
}
if ( !fatal ) {
err = snd_pcm_hw_params_set_channels( handle, hwparams, (unsigned int)settings.channels() );
if ( err < 0 ) {
fatal = true;
- errMessage = QString(tr("QAudioOutput: snd_pcm_hw_params_set_channels: err = %1")).arg(err);
+ errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_channels: err = %1").arg(err);
}
}
if ( !fatal ) {
err = snd_pcm_hw_params_set_rate_near( handle, hwparams, &freakuency, 0 );
if ( err < 0 ) {
fatal = true;
- errMessage = QString(tr("QAudioOutput: snd_pcm_hw_params_set_rate_near: err = %1")).arg(err);
+ errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_rate_near: err = %1").arg(err);
}
}
if ( !fatal ) {
err = snd_pcm_hw_params_set_buffer_time_near(handle, hwparams, &buffer_time, &dir);
if ( err < 0 ) {
fatal = true;
- errMessage = QString(tr("QAudioOutput: snd_pcm_hw_params_set_buffer_time_near: err = %1")).arg(err);
+ errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_buffer_time_near: err = %1").arg(err);
}
}
if ( !fatal ) {
err = snd_pcm_hw_params_set_period_time_near(handle, hwparams, &period_time, &dir);
if ( err < 0 ) {
fatal = true;
- errMessage = QString(tr("QAudioOutput: snd_pcm_hw_params_set_period_time_near: err = %1")).arg(err);
+ errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_period_time_near: err = %1").arg(err);
}
}
if ( !fatal ) {
err = snd_pcm_hw_params_set_periods_near(handle, hwparams, &chunks, &dir);
if ( err < 0 ) {
fatal = true;
- errMessage = QString(tr("QAudioOutput: snd_pcm_hw_params_set_periods_near: err = %1")).arg(err);
+ errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params_set_periods_near: err = %1").arg(err);
}
}
if ( !fatal ) {
err = snd_pcm_hw_params(handle, hwparams);
if ( err < 0 ) {
fatal = true;
- errMessage = QString(tr("QAudioOutput: snd_pcm_hw_params: err = %1")).arg(err);
+ errMessage = QString::fromLatin1("QAudioOutput: snd_pcm_hw_params: err = %1").arg(err);
}
}
if( err < 0) {
qWarning()<<errMessage;
errorState = QAudio::OpenError;
- deviceState = QAudio::StopState;
+ deviceState = QAudio::StoppedState;
return false;
}
snd_pcm_hw_params_get_buffer_size(hwparams,&buffer_frames);
@@ -402,6 +430,9 @@ bool QAudioOutputPrivate::open()
// Step 6: Start audio processing
timer->start(period_time/1000);
+ clockStamp.restart();
+ timeStamp.restart();
+ elapsedTimeOffset = 0;
errorState = QAudio::NoError;
totalTimeValue = 0;
opened = true;
@@ -411,7 +442,7 @@ bool QAudioOutputPrivate::open()
void QAudioOutputPrivate::close()
{
- deviceState = QAudio::StopState;
+ deviceState = QAudio::StoppedState;
timer->stop();
if ( handle ) {
@@ -474,7 +505,7 @@ qint64 QAudioOutputPrivate::write( const char *data, qint64 len )
if(err < 0) {
close();
errorState = QAudio::FatalError;
- deviceState = QAudio::StopState;
+ deviceState = QAudio::StoppedState;
emit stateChanged(deviceState);
}
return 0;
@@ -487,7 +518,7 @@ int QAudioOutputPrivate::periodSize() const
void QAudioOutputPrivate::setBufferSize(int value)
{
- if(deviceState == QAudio::StopState)
+ if(deviceState == QAudio::StoppedState)
buffer_size = value;
}
@@ -498,7 +529,10 @@ int QAudioOutputPrivate::bufferSize() const
void QAudioOutputPrivate::setNotifyInterval(int ms)
{
- intervalTime = ms;
+ if(ms >= minimumIntervalTime)
+ intervalTime = ms;
+ else
+ intervalTime = minimumIntervalTime;
}
int QAudioOutputPrivate::notifyInterval() const
@@ -506,14 +540,14 @@ int QAudioOutputPrivate::notifyInterval() const
return intervalTime;
}
-qint64 QAudioOutputPrivate::totalTime() const
+qint64 QAudioOutputPrivate::processedUSecs() const
{
return totalTimeValue;
}
void QAudioOutputPrivate::resume()
{
- if(deviceState == QAudio::SuspendState) {
+ if(deviceState == QAudio::SuspendedState) {
int err = 0;
if(handle) {
@@ -548,7 +582,7 @@ void QAudioOutputPrivate::suspend()
{
if(deviceState == QAudio::ActiveState || deviceState == QAudio::IdleState || resuming) {
timer->stop();
- deviceState = QAudio::SuspendState;
+ deviceState = QAudio::SuspendedState;
errorState = QAudio::NoError;
emit stateChanged(deviceState);
}
@@ -556,7 +590,7 @@ void QAudioOutputPrivate::suspend()
void QAudioOutputPrivate::userFeed()
{
- if(deviceState == QAudio::StopState || deviceState == QAudio::SuspendState)
+ if(deviceState == QAudio::StoppedState || deviceState == QAudio::SuspendedState)
return;
#ifdef DEBUG_AUDIO
QTime now(QTime::currentTime());
@@ -627,21 +661,23 @@ bool QAudioOutputPrivate::deviceReady()
if(deviceState != QAudio::ActiveState)
return true;
- if(timeStamp.elapsed() > intervalTime && intervalTime > 50) {
+ if((timeStamp.elapsed() + elapsedTimeOffset) > intervalTime) {
emit notify();
+ elapsedTimeOffset = timeStamp.elapsed() + elapsedTimeOffset - intervalTime;
timeStamp.restart();
}
return true;
}
-qint64 QAudioOutputPrivate::clock() const
+qint64 QAudioOutputPrivate::elapsedUSecs() const
{
if(!handle)
return 0;
- if(deviceState != QAudio::ActiveState)
+ if (deviceState == QAudio::StoppedState)
return 0;
+#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14)
snd_pcm_status_t* status;
snd_pcm_status_alloca(&status);
@@ -657,9 +693,12 @@ qint64 QAudioOutputPrivate::clock() const
l = -l;
l %= 1000000;
}
- return ((t1.tv_sec * 1000)+l/1000);
+ return ((t1.tv_sec * 1000000)+l);
} else
return 0;
+#else
+ return clockStamp.elapsed()*1000;
+#endif
return 0;
}
@@ -704,3 +743,5 @@ qint64 OutputPrivate::writeData(const char* data, qint64 len)
return written;
}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/audio/qaudiooutput_alsa_p.h b/src/multimedia/audio/qaudiooutput_alsa_p.h
index 295927be4..619ecefc6 100644
--- a/src/multimedia/audio/qaudiooutput_alsa_p.h
+++ b/src/multimedia/audio/qaudiooutput_alsa_p.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -66,6 +66,8 @@
#include <QtMultimedia/qaudiodeviceinfo.h>
#include <QtMultimedia/qaudioengine.h>
+QT_BEGIN_NAMESPACE
+
class OutputPrivate;
class QAudioOutputPrivate : public QAbstractAudioOutput
@@ -89,8 +91,8 @@ public:
int bufferSize() const;
void setNotifyInterval(int milliSeconds);
int notifyInterval() const;
- qint64 totalTime() const;
- qint64 clock() const;
+ qint64 processedUSecs() const;
+ qint64 elapsedUSecs() const;
QAudio::Error error() const;
QAudio::State state() const;
QAudioFormat format() const;
@@ -132,6 +134,8 @@ private:
QByteArray m_device;
int bytesAvailable;
QTime timeStamp;
+ QTime clockStamp;
+ qint64 elapsedTimeOffset;
char* audioBuffer;
snd_pcm_t* handle;
snd_async_handler_t* ahandler;
@@ -156,4 +160,6 @@ private:
QAudioOutputPrivate *audioDevice;
};
+QT_END_NAMESPACE
+
#endif
diff --git a/src/multimedia/audio/qaudiooutput_mac_p.cpp b/src/multimedia/audio/qaudiooutput_mac_p.cpp
index da1ea19e1..e0651bf4c 100644
--- a/src/multimedia/audio/qaudiooutput_mac_p.cpp
+++ b/src/multimedia/audio/qaudiooutput_mac_p.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -288,7 +288,7 @@ QAudioOutputPrivate::QAudioOutputPrivate(const QByteArray& device, const QAudioF
internalBufferSize = default_buffer_size;
clockFrequency = AudioGetHostClockFrequency() / 1000;
errorCode = QAudio::NoError;
- stateCode = QAudio::StopState;
+ stateCode = QAudio::StoppedState;
audioThreadState = Stopped;
intervalTimer = new QTimer(this);
@@ -436,7 +436,7 @@ QIODevice* QAudioOutputPrivate::start(QIODevice* device)
QIODevice* op = device;
if (!open()) {
- stateCode = QAudio::StopState;
+ stateCode = QAudio::StoppedState;
errorCode = QAudio::OpenError;
return audioIO;
}
@@ -460,16 +460,18 @@ QIODevice* QAudioOutputPrivate::start(QIODevice* device)
if (stateCode == QAudio::ActiveState)
audioThreadStart();
+ emit stateChanged(stateCode);
+
return op;
}
void QAudioOutputPrivate::stop()
{
QMutexLocker lock(&mutex);
- if (stateCode != QAudio::StopState) {
+ if (stateCode != QAudio::StoppedState) {
audioThreadDrain();
- stateCode = QAudio::StopState;
+ stateCode = QAudio::StoppedState;
errorCode = QAudio::NoError;
QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode));
}
@@ -478,10 +480,10 @@ void QAudioOutputPrivate::stop()
void QAudioOutputPrivate::reset()
{
QMutexLocker lock(&mutex);
- if (stateCode != QAudio::StopState) {
+ if (stateCode != QAudio::StoppedState) {
audioThreadStop();
- stateCode = QAudio::StopState;
+ stateCode = QAudio::StoppedState;
errorCode = QAudio::NoError;
QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode));
}
@@ -493,7 +495,7 @@ void QAudioOutputPrivate::suspend()
if (stateCode == QAudio::ActiveState || stateCode == QAudio::IdleState) {
audioThreadStop();
- stateCode = QAudio::SuspendState;
+ stateCode = QAudio::SuspendedState;
errorCode = QAudio::NoError;
QMetaObject::invokeMethod(this, "stateChanged", Qt::QueuedConnection, Q_ARG(QAudio::State, stateCode));
}
@@ -502,7 +504,7 @@ void QAudioOutputPrivate::suspend()
void QAudioOutputPrivate::resume()
{
QMutexLocker lock(&mutex);
- if (stateCode == QAudio::SuspendState) {
+ if (stateCode == QAudio::SuspendedState) {
audioThreadStart();
stateCode = QAudio::ActiveState;
@@ -523,7 +525,7 @@ int QAudioOutputPrivate::periodSize() const
void QAudioOutputPrivate::setBufferSize(int bs)
{
- if (stateCode == QAudio::StopState)
+ if (stateCode == QAudio::StoppedState)
internalBufferSize = bs;
}
@@ -542,13 +544,16 @@ int QAudioOutputPrivate::notifyInterval() const
return intervalTimer->interval();
}
-qint64 QAudioOutputPrivate::totalTime() const
+qint64 QAudioOutputPrivate::processedUSecs() const
{
return totalFrames * 1000000 / audioFormat.frequency();
}
-qint64 QAudioOutputPrivate::clock() const
+qint64 QAudioOutputPrivate::elapsedUSecs() const
{
+ if (stateCode == QAudio::StoppedState)
+ return 0;
+
return (AudioGetCurrentHostTime() - startTime) / (clockFrequency / 1000);
}
@@ -609,7 +614,7 @@ void QAudioOutputPrivate::audioDeviceError()
audioDeviceStop();
errorCode = QAudio::IOError;
- stateCode = QAudio::StopState;
+ stateCode = QAudio::StoppedState;
QMetaObject::invokeMethod(this, "deviceStopped", Qt::QueuedConnection);
}
}
diff --git a/src/multimedia/audio/qaudiooutput_mac_p.h b/src/multimedia/audio/qaudiooutput_mac_p.h
index 0616c41bf..76d06a9bf 100644
--- a/src/multimedia/audio/qaudiooutput_mac_p.h
+++ b/src/multimedia/audio/qaudiooutput_mac_p.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -128,8 +128,8 @@ public:
void setNotifyInterval(int milliSeconds);
int notifyInterval() const;
- qint64 totalTime() const;
- qint64 clock() const;
+ qint64 processedUSecs() const;
+ qint64 elapsedUSecs() const;
QAudio::Error error() const;
QAudio::State state() const;
@@ -145,10 +145,6 @@ public:
void startTimers();
void stopTimers();
-signals:
- void stateChanged(QAudio::State);
- void notify();
-
private slots:
void deviceStopped();
void inputReady();
diff --git a/src/multimedia/audio/qaudiooutput_win32_p.cpp b/src/multimedia/audio/qaudiooutput_win32_p.cpp
index bace4a642..2cfc472d6 100644
--- a/src/multimedia/audio/qaudiooutput_win32_p.cpp
+++ b/src/multimedia/audio/qaudiooutput_win32_p.cpp
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -54,8 +54,12 @@
//#define DEBUG_AUDIO 1
+QT_BEGIN_NAMESPACE
+
static CRITICAL_SECTION waveOutCriticalSection;
+static const int minimumIntervalTime = 50;
+
QAudioOutputPrivate::QAudioOutputPrivate(const QByteArray &device, const QAudioFormat& audioFormat):
settings(audioFormat)
{
@@ -67,14 +71,19 @@ QAudioOutputPrivate::QAudioOutputPrivate(const QByteArray &device, const QAudioF
intervalTime = 1000;
audioBuffer = 0;
errorState = QAudio::NoError;
- deviceState = QAudio::StopState;
+ deviceState = QAudio::StoppedState;
audioSource = 0;
pullMode = true;
+ finished = false;
InitializeCriticalSection(&waveOutCriticalSection);
}
QAudioOutputPrivate::~QAudioOutputPrivate()
{
+ EnterCriticalSection(&waveOutCriticalSection);
+ finished = true;
+ LeaveCriticalSection(&waveOutCriticalSection);
+
close();
DeleteCriticalSection(&waveOutCriticalSection);
}
@@ -99,11 +108,15 @@ void CALLBACK QAudioOutputPrivate::waveOutProc( HWAVEOUT hWaveOut, UINT uMsg,
return;
case WOM_DONE:
EnterCriticalSection(&waveOutCriticalSection);
+ if(qAudio->finished || qAudio->buffer_size == 0 || qAudio->period_size == 0) {
+ LeaveCriticalSection(&waveOutCriticalSection);
+ return;
+ }
qAudio->waveFreeBlockCount++;
if(qAudio->waveFreeBlockCount >= qAudio->buffer_size/qAudio->period_size)
qAudio->waveFreeBlockCount = qAudio->buffer_size/qAudio->period_size;
- LeaveCriticalSection(&waveOutCriticalSection);
qAudio->feedback();
+ LeaveCriticalSection(&waveOutCriticalSection);
break;
default:
return;
@@ -144,7 +157,7 @@ QAudioFormat QAudioOutputPrivate::format() const
QIODevice* QAudioOutputPrivate::start(QIODevice* device)
{
- if(deviceState != QAudio::StopState)
+ if(deviceState != QAudio::StoppedState)
close();
if(!pullMode && audioSource) {
@@ -174,9 +187,8 @@ QIODevice* QAudioOutputPrivate::start(QIODevice* device)
void QAudioOutputPrivate::stop()
{
- if(deviceState == QAudio::StopState)
+ if(deviceState == QAudio::StoppedState)
return;
- deviceState = QAudio::StopState;
close();
if(!pullMode && audioSource) {
delete audioSource;
@@ -199,13 +211,18 @@ bool QAudioOutputPrivate::open()
period_size = buffer_size/5;
}
waveBlocks = allocateBlocks(period_size, buffer_size/period_size);
+
+ EnterCriticalSection(&waveOutCriticalSection);
waveFreeBlockCount = buffer_size/period_size;
+ LeaveCriticalSection(&waveOutCriticalSection);
+
waveCurrentBlock = 0;
if(audioBuffer == 0)
audioBuffer = new char[buffer_size];
timeStamp.restart();
+ elapsedTimeOffset = 0;
wfx.nSamplesPerSec = settings.frequency();
wfx.wBitsPerSample = settings.sampleSize();
@@ -226,7 +243,7 @@ bool QAudioOutputPrivate::open()
== MMSYSERR_NOERROR) {
QString tmp;
tmp = QString::fromUtf16((const unsigned short*)woc.szPname);
- if(tmp.compare(tr(m_device)) == 0) {
+ if(tmp.compare(QLatin1String(m_device)) == 0) {
devId = ii;
break;
}
@@ -238,7 +255,7 @@ bool QAudioOutputPrivate::open()
(DWORD_PTR) this,
CALLBACK_FUNCTION) != MMSYSERR_NOERROR) {
errorState = QAudio::OpenError;
- deviceState = QAudio::StopState;
+ deviceState = QAudio::StoppedState;
emit stateChanged(deviceState);
qWarning("QAudioOutput: open error");
return false;
@@ -246,6 +263,7 @@ bool QAudioOutputPrivate::open()
totalTimeValue = 0;
timeStampOpened.restart();
+ elapsedTimeOffset = 0;
errorState = QAudio::NoError;
if(pullMode) {
@@ -259,10 +277,10 @@ bool QAudioOutputPrivate::open()
void QAudioOutputPrivate::close()
{
- if(deviceState == QAudio::StopState)
+ if(deviceState == QAudio::StoppedState)
return;
- deviceState = QAudio::StopState;
+ deviceState = QAudio::StoppedState;
int delay = (buffer_size-bytesFree())*1000/(settings.frequency()
*settings.channels()*(settings.sampleSize()/8));
waveOutReset(hWaveOut);
@@ -279,6 +297,7 @@ int QAudioOutputPrivate::bytesFree() const
{
int buf;
buf = waveFreeBlockCount*period_size;
+
return buf;
}
@@ -289,7 +308,7 @@ int QAudioOutputPrivate::periodSize() const
void QAudioOutputPrivate::setBufferSize(int value)
{
- if(deviceState == QAudio::StopState)
+ if(deviceState == QAudio::StoppedState)
buffer_size = value;
}
@@ -300,7 +319,10 @@ int QAudioOutputPrivate::bufferSize() const
void QAudioOutputPrivate::setNotifyInterval(int ms)
{
- intervalTime = ms;
+ if(ms >= minimumIntervalTime)
+ intervalTime = ms;
+ else
+ intervalTime = minimumIntervalTime;
}
int QAudioOutputPrivate::notifyInterval() const
@@ -308,7 +330,7 @@ int QAudioOutputPrivate::notifyInterval() const
return intervalTime;
}
-qint64 QAudioOutputPrivate::totalTime() const
+qint64 QAudioOutputPrivate::processedUSecs() const
{
return totalTimeValue;
}
@@ -324,8 +346,12 @@ qint64 QAudioOutputPrivate::write( const char *data, qint64 len )
int remain;
current = &waveBlocks[waveCurrentBlock];
while(l > 0) {
- if(waveFreeBlockCount==0)
+ EnterCriticalSection(&waveOutCriticalSection);
+ if(waveFreeBlockCount==0) {
+ LeaveCriticalSection(&waveOutCriticalSection);
break;
+ }
+ LeaveCriticalSection(&waveOutCriticalSection);
if(current->dwFlags & WHDR_PREPARED)
waveOutUnprepareHeader(hWaveOut, current, sizeof(WAVEHDR));
@@ -346,8 +372,10 @@ qint64 QAudioOutputPrivate::write( const char *data, qint64 len )
waveFreeBlockCount--;
LeaveCriticalSection(&waveOutCriticalSection);
#ifdef DEBUG_AUDIO
+ EnterCriticalSection(&waveOutCriticalSection);
qDebug("write out l=%d, waveFreeBlockCount=%d",
current->dwBufferLength,waveFreeBlockCount);
+ LeaveCriticalSection(&waveOutCriticalSection);
#endif
totalTimeValue += current->dwBufferLength
/(settings.channels()*(settings.sampleSize()/8))
@@ -362,7 +390,7 @@ qint64 QAudioOutputPrivate::write( const char *data, qint64 len )
void QAudioOutputPrivate::resume()
{
- if(deviceState == QAudio::SuspendState) {
+ if(deviceState == QAudio::SuspendedState) {
deviceState = QAudio::ActiveState;
errorState = QAudio::NoError;
waveOutRestart(hWaveOut);
@@ -375,7 +403,7 @@ void QAudioOutputPrivate::suspend()
{
if(deviceState == QAudio::ActiveState) {
waveOutPause(hWaveOut);
- deviceState = QAudio::SuspendState;
+ deviceState = QAudio::SuspendedState;
errorState = QAudio::NoError;
emit stateChanged(deviceState);
}
@@ -389,7 +417,7 @@ void QAudioOutputPrivate::feedback()
#endif
bytesAvailable = bytesFree();
- if(!(deviceState==QAudio::StopState||deviceState==QAudio::SuspendState)) {
+ if(!(deviceState==QAudio::StoppedState||deviceState==QAudio::SuspendedState)) {
if(bytesAvailable >= period_size)
QMetaObject::invokeMethod(this, "deviceReady", Qt::QueuedConnection);
}
@@ -398,7 +426,6 @@ void QAudioOutputPrivate::feedback()
bool QAudioOutputPrivate::deviceReady()
{
if(pullMode) {
- int i = 0;
int chunks = bytesAvailable/period_size;
#ifdef DEBUG_AUDIO
qDebug()<<"deviceReady() avail="<<bytesAvailable<<" bytes, period size="<<period_size<<" bytes";
@@ -408,6 +435,22 @@ bool QAudioOutputPrivate::deviceReady()
if(totalTimeValue == 0)
startup = true;
+ bool full=false;
+ EnterCriticalSection(&waveOutCriticalSection);
+ if(waveFreeBlockCount==0) full = true;
+ LeaveCriticalSection(&waveOutCriticalSection);
+ if (full){
+#ifdef DEBUG_AUDIO
+ qDebug() << "Skipping data as unable to write";
+#endif
+ if((timeStamp.elapsed() + elapsedTimeOffset) > intervalTime ) {
+ emit notify();
+ elapsedTimeOffset = timeStamp.elapsed() + elapsedTimeOffset - intervalTime;
+ timeStamp.restart();
+ }
+ return true;
+ }
+
if(startup)
waveOutPause(hWaveOut);
int input = period_size*chunks;
@@ -420,13 +463,18 @@ bool QAudioOutputPrivate::deviceReady()
waveOutRestart(hWaveOut);
} else if(l == 0) {
bytesAvailable = bytesFree();
- if(waveFreeBlockCount == buffer_size/period_size) {
+
+ int check = 0;
+ EnterCriticalSection(&waveOutCriticalSection);
+ check = waveFreeBlockCount;
+ LeaveCriticalSection(&waveOutCriticalSection);
+ if(check == buffer_size/period_size) {
errorState = QAudio::UnderrunError;
deviceState = QAudio::IdleState;
emit stateChanged(deviceState);
}
- } else if(i < 0) {
+ } else if(l < 0) {
bytesAvailable = bytesFree();
errorState = QAudio::IOError;
}
@@ -434,20 +482,21 @@ bool QAudioOutputPrivate::deviceReady()
if(deviceState != QAudio::ActiveState)
return true;
- if(timeStamp.elapsed() > intervalTime && intervalTime > 50) {
+ if((timeStamp.elapsed() + elapsedTimeOffset) > intervalTime) {
emit notify();
+ elapsedTimeOffset = timeStamp.elapsed() + elapsedTimeOffset - intervalTime;
timeStamp.restart();
}
return true;
}
-qint64 QAudioOutputPrivate::clock() const
-{
- if(deviceState != QAudio::ActiveState)
+qint64 QAudioOutputPrivate::elapsedUSecs() const
+{
+ if (deviceState == QAudio::StoppedState)
return 0;
- return timeStampOpened.elapsed();
+ return timeStampOpened.elapsed()*1000;
}
QAudio::Error QAudioOutputPrivate::error() const
@@ -502,3 +551,5 @@ qint64 OutputPrivate::writeData(const char* data, qint64 len)
}
return written;
}
+
+QT_END_NAMESPACE
diff --git a/src/multimedia/audio/qaudiooutput_win32_p.h b/src/multimedia/audio/qaudiooutput_win32_p.h
index c6c025f14..f90b8c2e3 100644
--- a/src/multimedia/audio/qaudiooutput_win32_p.h
+++ b/src/multimedia/audio/qaudiooutput_win32_p.h
@@ -1,6 +1,7 @@
/****************************************************************************
**
** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
+** All rights reserved.
** Contact: Nokia Corporation (qt-info@nokia.com)
**
** This file is part of the QtMultimedia module of the Qt Toolkit.
@@ -9,8 +10,8 @@
** No Commercial Usage
** This file contains pre-release code and may not be distributed.
** You may use this file in accordance with the terms and conditions
-** contained in the either Technology Preview License Agreement or the
-** Beta Release License Agreement.
+** contained in the Technology Preview License Agreement accompanying
+** this package.
**
** GNU Lesser General Public License Usage
** Alternatively, this file may be used under the terms of the GNU Lesser
@@ -20,21 +21,20 @@
** ensure the GNU Lesser General Public License version 2.1 requirements
** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
**
-** In addition, as a special exception, Nokia gives you certain
-** additional rights. These rights are described in the Nokia Qt LGPL
-** Exception version 1.0, included in the file LGPL_EXCEPTION.txt in this
-** package.
+** In addition, as a special exception, Nokia gives you certain additional
+** rights. These rights are described in the Nokia Qt LGPL Exception
+** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
+**
+** If you have questions regarding the use of this file, please contact
+** Nokia at qt-info@nokia.com.
+**
+**
+**
+**
+**
+**
**
-** GNU General Public License Usage
-** Alternatively, this file may be used under the terms of the GNU
-** General Public License version 3.0 as published by the Free Software
-** Foundation and appearing in the file LICENSE.GPL included in the
-** packaging of this file. Please review the following information to
-** ensure the GNU General Public License version 3.0 requirements will be
-** met: http://www.gnu.org/copyleft/gpl.html.
**
-** If you are unsure which license is appropriate for your use, please
-** contact the sales department at http://qt.nokia.com/contact.
** $QT_END_LICENSE$
**
****************************************************************************/
@@ -67,6 +67,8 @@
#include <QtMultimedia/qaudioengine.h>
+QT_BEGIN_NAMESPACE
+
class QAudioOutputPrivate : public QAbstractAudioOutput
{
Q_OBJECT
@@ -88,8 +90,8 @@ public:
int bufferSize() const;
void setNotifyInterval(int milliSeconds);
int notifyInterval() const;
- qint64 totalTime() const;
- qint64 clock() const;
+ qint64 processedUSecs() const;
+ qint64 elapsedUSecs() const;
QAudio::Error error() const;
QAudio::State state() const;
@@ -102,15 +104,12 @@ private slots:
void feedback();
bool deviceReady();
-signals:
- void stateChanged(QAudio::State);
- void notify();
-
private:
QByteArray m_device;
bool resuming;
int bytesAvailable;
QTime timeStamp;
+ qint64 elapsedTimeOffset;
QTime timeStampOpened;
qint32 buffer_size;
qint32 period_size;
@@ -130,6 +129,7 @@ private:
MMRESULT result;
WAVEHDR header;
WAVEHDR* waveBlocks;
+ volatile bool finished;
volatile int waveFreeBlockCount;
int waveCurrentBlock;
char* audioBuffer;
@@ -149,4 +149,6 @@ private:
QAudioOutputPrivate *audioDevice;
};
+QT_END_NAMESPACE
+
#endif