diff options
author | Justin McPherson <justin.mcpherson@nokia.com> | 2010-01-15 05:35:55 (GMT) |
---|---|---|
committer | Justin McPherson <justin.mcpherson@nokia.com> | 2010-01-15 05:35:55 (GMT) |
commit | d2fa5b80d4f40ac67a7a74552390332551563466 (patch) | |
tree | 1ef112b385dbbdd49abefd9b574573f7d21b69bf /src/multimedia | |
parent | f0d24ba1eaa1079abef3a1da641b43437dc7df66 (diff) | |
parent | 6c5c2312ca5477a1ec33f43c1673ab65a0dce8bb (diff) | |
download | Qt-d2fa5b80d4f40ac67a7a74552390332551563466.zip Qt-d2fa5b80d4f40ac67a7a74552390332551563466.tar.gz Qt-d2fa5b80d4f40ac67a7a74552390332551563466.tar.bz2 |
Merge branch 'master' of ../../qt/master
Conflicts:
examples/multimedia/audioinput/audioinput.cpp
src/multimedia/audio/qaudiodeviceinfo.cpp
src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp
src/multimedia/audio/qaudioformat.cpp
src/multimedia/audio/qaudioinput_win32_p.cpp
src/multimedia/audio/qaudiooutput_win32_p.cpp
tests/auto/qaudioformat/tst_qaudioformat.cpp
Diffstat (limited to 'src/multimedia')
51 files changed, 531 insertions, 411 deletions
diff --git a/src/multimedia/audio/audio.pri b/src/multimedia/audio/audio.pri index c445941..625b871c 100644 --- a/src/multimedia/audio/audio.pri +++ b/src/multimedia/audio/audio.pri @@ -17,6 +17,8 @@ SOURCES += $$PWD/qaudio.cpp \ $$PWD/qaudioengine.cpp \ $$PWD/qaudiodevicefactory.cpp +contains(QT_CONFIG, audio-backend) { + mac { HEADERS += $$PWD/qaudioinput_mac_p.h \ $$PWD/qaudiooutput_mac_p.h \ @@ -51,3 +53,6 @@ mac { } } } +} else { + DEFINES += QT_NO_AUDIO_BACKEND +} diff --git a/src/multimedia/audio/qaudio.cpp b/src/multimedia/audio/qaudio.cpp index 04378d4..e0f24ce 100644 --- a/src/multimedia/audio/qaudio.cpp +++ b/src/multimedia/audio/qaudio.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -65,29 +65,31 @@ public: /*! \namespace QAudio \brief The QAudio namespace contains enums used by the audio classes. + \inmodule QtMultimedia + \ingroup multimedia \since 4.6 */ /*! \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 a66f0b1..9ca1dff 100644 --- a/src/multimedia/audio/qaudio.h +++ b/src/multimedia/audio/qaudio.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -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 }; } diff --git a/src/multimedia/audio/qaudio_mac.cpp b/src/multimedia/audio/qaudio_mac.cpp index d876745..61a00ce 100644 --- a/src/multimedia/audio/qaudio_mac.cpp +++ b/src/multimedia/audio/qaudio_mac.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** diff --git a/src/multimedia/audio/qaudio_mac_p.h b/src/multimedia/audio/qaudio_mac_p.h index ac6517b..4e7d688 100644 --- a/src/multimedia/audio/qaudio_mac_p.h +++ b/src/multimedia/audio/qaudio_mac_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** diff --git a/src/multimedia/audio/qaudiodevicefactory.cpp b/src/multimedia/audio/qaudiodevicefactory.cpp index 8804fb6..459b7f5 100644 --- a/src/multimedia/audio/qaudiodevicefactory.cpp +++ b/src/multimedia/audio/qaudiodevicefactory.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -45,6 +45,7 @@ #include <private/qfactoryloader_p.h> #include "qaudiodevicefactory_p.h" +#ifndef QT_NO_AUDIO_BACKEND #if defined(Q_OS_WIN) #include "qaudiodeviceinfo_win32_p.h" #include "qaudiooutput_win32_p.h" @@ -58,6 +59,7 @@ #include "qaudiooutput_alsa_p.h" #include "qaudioinput_alsa_p.h" #endif +#endif QT_BEGIN_NAMESPACE @@ -94,10 +96,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(); } }; @@ -115,26 +117,28 @@ 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<QAudioDeviceInfo> QAudioDeviceFactory::deviceList(QAudio::Mode mode) +QList<QAudioDeviceInfo> QAudioDeviceFactory::availableDevices(QAudio::Mode mode) { QList<QAudioDeviceInfo> devices; +#ifndef QT_NO_AUDIO_BACKEND #if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA)) - foreach (const QByteArray &handle, QAudioDeviceInfoInternal::deviceList(mode)) + foreach (const QByteArray &handle, QAudioDeviceInfoInternal::availableDevices(mode)) devices << QAudioDeviceInfo(QLatin1String("builtin"), handle, mode); #endif +#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)) + foreach (QByteArray const& handle, plugin->availableDevices(mode)) devices << QAudioDeviceInfo(key, handle, mode); } @@ -149,13 +153,15 @@ 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 QAudioDeviceInfo(QLatin1String("default"), list.at(0), QAudio::AudioInput); } +#ifndef QT_NO_AUDIO_BACKEND #if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA)) return QAudioDeviceInfo(QLatin1String("builtin"), QAudioDeviceInfoInternal::defaultInputDevice(), QAudio::AudioInput); #endif +#endif return QAudioDeviceInfo(); } @@ -164,13 +170,15 @@ 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 QAudioDeviceInfo(QLatin1String("default"), list.at(0), QAudio::AudioOutput); } +#ifndef QT_NO_AUDIO_BACKEND #if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA)) return QAudioDeviceInfo(QLatin1String("builtin"), QAudioDeviceInfoInternal::defaultOutputDevice(), QAudio::AudioOutput); #endif +#endif return QAudioDeviceInfo(); } @@ -178,10 +186,12 @@ QAbstractAudioDeviceInfo* QAudioDeviceFactory::audioDeviceInfo(const QString &re { QAbstractAudioDeviceInfo *rc = 0; +#ifndef QT_NO_AUDIO_BACKEND #if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA)) if (realm == QLatin1String("builtin")) return new QAudioDeviceInfoInternal(handle, mode); #endif +#endif QAudioEngineFactoryInterface* plugin = qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(realm)); @@ -205,10 +215,12 @@ QAbstractAudioInput* QAudioDeviceFactory::createInputDevice(QAudioDeviceInfo con { if (deviceInfo.isNull()) return new QNullInputDevice(); +#ifndef QT_NO_AUDIO_BACKEND #if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA)) if (deviceInfo.realm() == QLatin1String("builtin")) return new QAudioInputPrivate(deviceInfo.handle(), format); #endif +#endif QAudioEngineFactoryInterface* plugin = qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(deviceInfo.realm())); @@ -222,10 +234,12 @@ QAbstractAudioOutput* QAudioDeviceFactory::createOutputDevice(QAudioDeviceInfo c { if (deviceInfo.isNull()) return new QNullOutputDevice(); +#ifndef QT_NO_AUDIO_BACKEND #if (defined(Q_OS_WIN) || defined(Q_OS_MAC) || defined(HAS_ALSA)) if (deviceInfo.realm() == QLatin1String("builtin")) return new QAudioOutputPrivate(deviceInfo.handle(), format); #endif +#endif QAudioEngineFactoryInterface* plugin = qobject_cast<QAudioEngineFactoryInterface*>(loader()->instance(deviceInfo.realm())); diff --git a/src/multimedia/audio/qaudiodevicefactory_p.h b/src/multimedia/audio/qaudiodevicefactory_p.h index 008e4a8..8ee8b05 100644 --- a/src/multimedia/audio/qaudiodevicefactory_p.h +++ b/src/multimedia/audio/qaudiodevicefactory_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -72,7 +72,7 @@ class QAbstractAudioDeviceInfo; class QAudioDeviceFactory { public: - static QList<QAudioDeviceInfo> deviceList(QAudio::Mode mode); + static QList<QAudioDeviceInfo> availableDevices(QAudio::Mode mode); static QAudioDeviceInfo defaultInputDevice(); static QAudioDeviceInfo defaultOutputDevice(); diff --git a/src/multimedia/audio/qaudiodeviceinfo.cpp b/src/multimedia/audio/qaudiodeviceinfo.cpp index 45e177e..1bddb20 100644 --- a/src/multimedia/audio/qaudiodeviceinfo.cpp +++ b/src/multimedia/audio/qaudiodeviceinfo.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -121,7 +121,7 @@ public: classes that communicate with the device--such as QAudioInput, and QAudioOutput. The static functions defaultInputDevice(), defaultOutputDevice(), and - deviceList() let you get a list of all available + 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. @@ -129,7 +129,7 @@ public: For instance: \code - foreach(const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::deviceList(QAudio::AudioOutput)) + foreach(const QAudioDeviceInfo &deviceInfo, QAudioDeviceInfo::availableDevices(QAudio::AudioOutput)) qDebug() << "Device name: " << deviceInfo.deviceName(); \endcode @@ -353,9 +353,9 @@ QAudioDeviceInfo QAudioDeviceInfo::defaultOutputDevice() Returns a list of audio devices that support \a mode. */ -QList<QAudioDeviceInfo> QAudioDeviceInfo::deviceList(QAudio::Mode mode) +QList<QAudioDeviceInfo> QAudioDeviceInfo::availableDevices(QAudio::Mode mode) { - return QAudioDeviceFactory::deviceList(mode); + return QAudioDeviceFactory::availableDevices(mode); } diff --git a/src/multimedia/audio/qaudiodeviceinfo.h b/src/multimedia/audio/qaudiodeviceinfo.h index 134b688..1cc0731 100644 --- a/src/multimedia/audio/qaudiodeviceinfo.h +++ b/src/multimedia/audio/qaudiodeviceinfo.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -94,7 +94,7 @@ public: static QAudioDeviceInfo defaultInputDevice(); static QAudioDeviceInfo defaultOutputDevice(); - static QList<QAudioDeviceInfo> deviceList(QAudio::Mode mode); + static QList<QAudioDeviceInfo> availableDevices(QAudio::Mode mode); private: QAudioDeviceInfo(const QString &realm, const QByteArray &handle, QAudio::Mode mode); diff --git a/src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp b/src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp index 08c617b..a77a428 100644 --- a/src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp +++ b/src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -152,13 +152,23 @@ bool QAudioDeviceInfoInternal::open() { int err = 0; QString dev = device; - if(!dev.contains(QLatin1String("default"))) { + 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 = QString(QLatin1String("default:CARD=%1")).arg(dev); + 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; @@ -195,16 +205,25 @@ bool QAudioDeviceInfoInternal::testSettings(const QAudioFormat& format) const snd_pcm_hw_params_t *params; QString dev = device; - // open() - if(!dev.contains(QLatin1String("default"))) { + 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 = QString(QLatin1String("default:CARD=%1")).arg(dev); + 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))) + if(shortName.compare(QLatin1String(name)) == 0) break; idx++; } @@ -382,10 +401,12 @@ void QAudioDeviceInfoInternal::updateLists() close(); } -QList<QByteArray> QAudioDeviceInfoInternal::deviceList(QAudio::Mode mode) +QList<QByteArray> QAudioDeviceInfoInternal::availableDevices(QAudio::Mode mode) { + QList<QByteArray> allDevices; QList<QByteArray> devices; QByteArray filter; + #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; @@ -408,12 +429,11 @@ QList<QByteArray> QAudioDeviceInfoInternal::deviceList(QAudio::Mode mode) descr = snd_device_name_get_hint(*n, "DESC"); io = snd_device_name_get_hint(*n, "IOID"); if((name != NULL) && (descr != NULL) && ((io == NULL) || (io == filter))) { - QString str = QLatin1String(name); - - if(str.contains(QLatin1String("default"))) { - int pos = str.indexOf(QLatin1String("="),0); - devices.append(str.mid(pos+1).toLocal8Bit().constData()); - } + QString deviceName = QLatin1String(name); + QString deviceDescription = QLatin1String(descr); + allDevices.append(deviceName.toLocal8Bit().constData()); + if(deviceDescription.contains(QLatin1String("Default Audio Device"))) + devices.append(deviceName.toLocal8Bit().constData()); } if(name != NULL) free(name); @@ -439,25 +459,28 @@ QList<QByteArray> QAudioDeviceInfoInternal::deviceList(QAudio::Mode mode) if (idx > 0) devices.append("default"); #endif + if (devices.size() == 0 && allDevices.size() > 0) + return allDevices; + return devices; } 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 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 10078ca..6f9a459 100644 --- a/src/multimedia/audio/qaudiodeviceinfo_alsa_p.h +++ b/src/multimedia/audio/qaudiodeviceinfo_alsa_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -92,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(); diff --git a/src/multimedia/audio/qaudiodeviceinfo_mac_p.cpp b/src/multimedia/audio/qaudiodeviceinfo_mac_p.cpp index 258132a..9334069 100644 --- a/src/multimedia/audio/qaudiodeviceinfo_mac_p.cpp +++ b/src/multimedia/audio/qaudiodeviceinfo_mac_p.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -324,7 +324,7 @@ QByteArray QAudioDeviceInfoInternal::defaultOutputDevice() return get_device_info(audioDevice, QAudio::AudioOutput); } -QList<QByteArray> QAudioDeviceInfoInternal::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 60532a8..e234384 100644 --- a/src/multimedia/audio/qaudiodeviceinfo_mac_p.h +++ b/src/multimedia/audio/qaudiodeviceinfo_mac_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -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 f77efd0..e71e88d 100644 --- a/src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp +++ b/src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -333,7 +333,7 @@ void QAudioDeviceInfoInternal::updateLists() } } -QList<QByteArray> QAudioDeviceInfoInternal::deviceList(QAudio::Mode mode) +QList<QByteArray> QAudioDeviceInfoInternal::availableDevices(QAudio::Mode mode) { Q_UNUSED(mode) diff --git a/src/multimedia/audio/qaudiodeviceinfo_win32_p.h b/src/multimedia/audio/qaudiodeviceinfo_win32_p.h index 0d2ee29..cb6dd91 100644 --- a/src/multimedia/audio/qaudiodeviceinfo_win32_p.h +++ b/src/multimedia/audio/qaudiodeviceinfo_win32_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -93,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; diff --git a/src/multimedia/audio/qaudioengine.cpp b/src/multimedia/audio/qaudioengine.cpp index c6e9d97..7f1f5d3 100644 --- a/src/multimedia/audio/qaudioengine.cpp +++ b/src/multimedia/audio/qaudioengine.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -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 57a9ae6..df9d09d 100644 --- a/src/multimedia/audio/qaudioengine.h +++ b/src/multimedia/audio/qaudioengine.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -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 773fb6d..82324b5 100644 --- a/src/multimedia/audio/qaudioengineplugin.cpp +++ b/src/multimedia/audio/qaudioengineplugin.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** diff --git a/src/multimedia/audio/qaudioengineplugin.h b/src/multimedia/audio/qaudioengineplugin.h index fe30e0d..2322d2a 100644 --- a/src/multimedia/audio/qaudioengineplugin.h +++ b/src/multimedia/audio/qaudioengineplugin.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -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 e31d2ec..4544a73 100644 --- a/src/multimedia/audio/qaudioformat.cpp +++ b/src/multimedia/audio/qaudioformat.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -38,7 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ - +#include <QDebug> #include <QtMultimedia/qaudioformat.h> @@ -120,7 +120,7 @@ public: \row \o Sample size \o How much data is stored in each sample (typically 8 - or 16) + or 16 bits) \row \o Sample type \o Numerical representation of sample (typically signed integer, @@ -214,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(); } /*! @@ -315,7 +312,7 @@ int QAudioFormat::channels() const } /*! - Sets the sampleSize to \a sampleSize. + Sets the sample size to the \a sampleSize specified. */ void QAudioFormat::setSampleSize(int sampleSize) @@ -324,7 +321,7 @@ void QAudioFormat::setSampleSize(int sampleSize) } /*! - Returns the current sampleSize value. + Returns the current sample size value. */ int QAudioFormat::sampleSize() const diff --git a/src/multimedia/audio/qaudioformat.h b/src/multimedia/audio/qaudioformat.h index f64dd7e..b255907 100644 --- a/src/multimedia/audio/qaudioformat.h +++ b/src/multimedia/audio/qaudioformat.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -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; diff --git a/src/multimedia/audio/qaudioinput.cpp b/src/multimedia/audio/qaudioinput.cpp index 8f2d75b..da39c4a 100644 --- a/src/multimedia/audio/qaudioinput.cpp +++ b/src/multimedia/audio/qaudioinput.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -47,7 +47,6 @@ #include "qaudiodevicefactory_p.h" - QT_BEGIN_NAMESPACE /*! @@ -78,8 +77,12 @@ QT_BEGIN_NAMESPACE file, you can: \code + QFile outputFile; // class member. + QAudioInput* audio; // class member. + \endcode + + \code { - QFile outputFile; outputFile.setFileName("/tmp/test.raw"); outputFile.open( QIODevice::WriteOnly | QIODevice::Truncate ); @@ -92,9 +95,15 @@ QT_BEGIN_NAMESPACE format.setByteOrder(QAudioFormat::LittleEndian); format.setSampleType(QAudioFormat::UnSignedInt); - QAudioInput *audio = new QAudioInput(format, this); + if (QAudioDeviceInfo info(QAudioDeviceInfo::defaultInputDevice()); + if (!info.isFormatSupported(format)) { + qWarning()<<"default format not supported try to use nearest"; + format = info.nearestFormat(format); + } + + audio = new QAudioInput(format, this); QTimer::singleShot(3000, this, SLOT(stopRecording())); - audio->start(outputFile); + audio->start(&outputFile); // Records audio for 3000ms } \endcode @@ -110,6 +119,7 @@ QT_BEGIN_NAMESPACE { audio->stop(); outputFile->close(); + delete audio; } \endcode @@ -121,15 +131,15 @@ 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 QAudioInput will enter the \l{QAudio::}{StopState} when + enum. The QAudioInput will enter the \l{QAudio::}{StoppedState} when an error is encountered. Connect to the stateChanged() signal to handle the error: @@ -176,37 +186,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 */ -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); } /*! @@ -225,8 +242,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() */ @@ -255,7 +272,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(); @@ -268,7 +285,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 @@ -357,9 +374,9 @@ int QAudioInput::notifyInterval() const was called in microseconds. */ -qint64 QAudioInput::totalTime() const +qint64 QAudioInput::processedUSecs() const { - return d->totalTime(); + return d->processedUSecs(); } /*! @@ -367,9 +384,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 c8094f5..5be9b5a 100644 --- a/src/multimedia/audio/qaudioinput.h +++ b/src/multimedia/audio/qaudioinput.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -71,7 +71,9 @@ public: 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/qaudioinput_alsa_p.cpp b/src/multimedia/audio/qaudioinput_alsa_p.cpp index b6fff64..ea68c8d6 100644 --- a/src/multimedia/audio/qaudioinput_alsa_p.cpp +++ b/src/multimedia/audio/qaudioinput_alsa_p.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -52,6 +52,7 @@ #include <QtCore/qcoreapplication.h> #include "qaudioinput_alsa_p.h" +#include "qaudiodeviceinfo_alsa_p.h" QT_BEGIN_NAMESPACE @@ -75,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(QLatin1String(device)).split(QLatin1String(":")); - m_device = QByteArray(list1.at(0).toLocal8Bit().constData()); + m_device = device; timer = new QTimer(this); connect(timer,SIGNAL(timeout()),SLOT(userFeed())); @@ -206,7 +206,7 @@ int QAudioInputPrivate::setFormat() QIODevice* QAudioInputPrivate::start(QIODevice* device) { - if(deviceState != QAudio::StopState) + if(deviceState != QAudio::StoppedState) close(); if(!pullMode && audioSource) { @@ -234,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); @@ -259,22 +259,31 @@ bool QAudioInputPrivate::open() unsigned int freakuency=settings.sampleRate(); QString dev = QString(QLatin1String(m_device.constData())); - if(!dev.contains(QLatin1String("default"))) { -#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14) - dev = QString(QLatin1String("default:CARD=%1")).arg(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(m_device.contains(name)) + 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_CAPTURE,0); @@ -283,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; } @@ -367,7 +376,7 @@ bool QAudioInputPrivate::open() if( err < 0) { qWarning()<<errMessage; errorState = QAudio::OpenError; - deviceState = QAudio::StopState; + deviceState = QAudio::StoppedState; emit stateChanged(deviceState); return false; } @@ -413,7 +422,7 @@ bool QAudioInputPrivate::open() void QAudioInputPrivate::close() { - deviceState = QAudio::StopState; + deviceState = QAudio::StoppedState; timer->stop(); if ( handle ) { @@ -490,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; @@ -508,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) { @@ -525,7 +534,7 @@ void QAudioInputPrivate::resume() resuming = true; deviceState = QAudio::ActiveState; int chunks = buffer_size/period_size; - timer->start(buffer_time*chunks/2000); + timer->start(period_time*chunks/2000); emit stateChanged(deviceState); } } @@ -558,7 +567,7 @@ int QAudioInputPrivate::notifyInterval() const return intervalTime; } -qint64 QAudioInputPrivate::totalTime() const +qint64 QAudioInputPrivate::processedUSecs() const { return totalTimeValue; } @@ -567,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()); @@ -606,15 +615,15 @@ bool QAudioInputPrivate::deviceReady() return true; } -qint64 QAudioInputPrivate::clock() const +qint64 QAudioInputPrivate::elapsedUSecs() const { if(!handle) return 0; - if (deviceState == QAudio::StopState) + if (deviceState == QAudio::StoppedState) return 0; -#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14) +#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14) snd_pcm_status_t* status; snd_pcm_status_alloca(&status); diff --git a/src/multimedia/audio/qaudioinput_alsa_p.h b/src/multimedia/audio/qaudioinput_alsa_p.h index 2ed7453..92cef83 100644 --- a/src/multimedia/audio/qaudioinput_alsa_p.h +++ b/src/multimedia/audio/qaudioinput_alsa_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -91,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; diff --git a/src/multimedia/audio/qaudioinput_mac_p.cpp b/src/multimedia/audio/qaudioinput_mac_p.cpp index c88c558..f5be8ee 100644 --- a/src/multimedia/audio/qaudioinput_mac_p.cpp +++ b/src/multimedia/audio/qaudioinput_mac_p.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -526,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); @@ -708,7 +708,7 @@ QIODevice* QAudioInputPrivate::start(QIODevice* device) QIODevice* op = device; if (!open()) { - stateCode = QAudio::StopState; + stateCode = QAudio::StoppedState; errorCode = QAudio::OpenError; return audioIO; } @@ -736,12 +736,12 @@ QIODevice* QAudioInputPrivate::start(QIODevice* device) 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)); } } @@ -749,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)); } } @@ -765,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)); } } @@ -773,7 +773,7 @@ void QAudioInputPrivate::suspend() void QAudioInputPrivate::resume() { QMutexLocker lock(&mutex); - if (stateCode == QAudio::SuspendState) { + if (stateCode == QAudio::SuspendedState) { audioThreadStart(); errorCode = QAudio::NoError; @@ -812,14 +812,14 @@ int QAudioInputPrivate::notifyInterval() const return intervalTimer->interval(); } -qint64 QAudioInputPrivate::totalTime() const +qint64 QAudioInputPrivate::processedUSecs() const { return totalFrames * 1000000 / audioFormat.sampleRate(); } -qint64 QAudioInputPrivate::clock() const +qint64 QAudioInputPrivate::elapsedUSecs() const { - if (stateCode == QAudio::StopState) + if (stateCode == QAudio::StoppedState) return 0; return (AudioGetCurrentHostTime() - startTime) / (clockFrequency / 1000); @@ -875,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 a080648..e1b8e4a 100644 --- a/src/multimedia/audio/qaudioinput_mac_p.h +++ b/src/multimedia/audio/qaudioinput_mac_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -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; diff --git a/src/multimedia/audio/qaudioinput_win32_p.cpp b/src/multimedia/audio/qaudioinput_win32_p.cpp index ca0bc24..dfbe2ec 100644 --- a/src/multimedia/audio/qaudioinput_win32_p.cpp +++ b/src/multimedia/audio/qaudioinput_win32_p.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -71,7 +71,7 @@ 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; @@ -153,6 +153,14 @@ WAVEHDR* QAudioInputPrivate::allocateBlocks(int size, int count) void QAudioInputPrivate::freeBlocks(WAVEHDR* blockArray) { + WAVEHDR* blocks = blockArray; + + int count = buffer_size/period_size; + + for(int i = 0; i < count; i++) { + waveInUnprepareHeader(hWaveIn,&blocks[i], sizeof(WAVEHDR)); + blocks+=sizeof(WAVEHDR); + } HeapFree(GetProcessHeap(), 0, blockArray); } @@ -173,7 +181,7 @@ QAudioFormat QAudioInputPrivate::format() const QIODevice* QAudioInputPrivate::start(QIODevice* device) { - if(deviceState != QAudio::StopState) + if(deviceState != QAudio::StoppedState) close(); if(!pullMode && audioSource) { @@ -201,7 +209,7 @@ QIODevice* QAudioInputPrivate::start(QIODevice* device) void QAudioInputPrivate::stop() { - if(deviceState == QAudio::StopState) + if(deviceState == QAudio::StoppedState) return; close(); @@ -260,7 +268,7 @@ 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; @@ -269,7 +277,7 @@ bool QAudioInputPrivate::open() if(waveBlocks == 0) { errorState = QAudio::OpenError; - deviceState = QAudio::StopState; + deviceState = QAudio::StoppedState; emit stateChanged(deviceState); qWarning("QAudioInput: failed to allocate blocks. open failed"); return false; @@ -286,7 +294,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; } @@ -295,7 +303,7 @@ 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; } @@ -309,15 +317,15 @@ bool QAudioInputPrivate::open() void QAudioInputPrivate::close() { - if(deviceState == QAudio::StopState) + if(deviceState == QAudio::StoppedState) return; waveInReset(hWaveIn); waveInClose(hWaveIn); - deviceState = QAudio::StopState; + deviceState = QAudio::StoppedState; int count = 0; - while(!finished && count < 100) { + while(!finished && count < 500) { count++; Sleep(10); } @@ -333,6 +341,9 @@ void QAudioInputPrivate::close() 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; @@ -346,9 +357,10 @@ qint64 QAudioInputPrivate::read(char* data, qint64 len) char* p = data; qint64 l = 0; qint64 written = 0; + while(!done) { // Read in some audio data - if(waveBlocks[header].dwBytesRecorded > 0) { + if(waveBlocks[header].dwBytesRecorded > 0 && waveBlocks[header].dwFlags & WHDR_DONE) { if(pullMode) { l = audioSource->write(waveBlocks[header].lpData, waveBlocks[header].dwBytesRecorded); @@ -391,6 +403,9 @@ qint64 QAudioInputPrivate::read(char* data, qint64 len) //no data, not ready yet, next time return 0; } + + waveInUnprepareHeader(hWaveIn,&waveBlocks[header], sizeof(WAVEHDR)); + EnterCriticalSection(&waveInCriticalSection); waveFreeBlockCount++; LeaveCriticalSection(&waveInCriticalSection); @@ -398,17 +413,22 @@ qint64 QAudioInputPrivate::read(char* data, qint64 len) waveBlocks[header].dwFlags = 0L; result = waveInPrepareHeader(hWaveIn,&waveBlocks[header], sizeof(WAVEHDR)); if(result != MMSYSERR_NOERROR) { + result = waveInPrepareHeader(hWaveIn,&waveBlocks[header], sizeof(WAVEHDR)); qWarning("QAudioInput: failed to prepare block %d,err=%d",header,result); - errorState = QAudio::OpenError; - deviceState = QAudio::StopState; - emit stateChanged(deviceState); + errorState = QAudio::IOError; + EnterCriticalSection(&waveInCriticalSection); + waveFreeBlockCount--; + LeaveCriticalSection(&waveInCriticalSection); + return 0; } 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; - emit stateChanged(deviceState); + errorState = QAudio::IOError; + EnterCriticalSection(&waveInCriticalSection); + waveFreeBlockCount--; + LeaveCriticalSection(&waveInCriticalSection); + return 0; } header++; if(header >= buffer_size/period_size) @@ -435,14 +455,14 @@ 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; } @@ -488,7 +508,7 @@ int QAudioInputPrivate::notifyInterval() const return intervalTime; } -qint64 QAudioInputPrivate::totalTime() const +qint64 QAudioInputPrivate::processedUSecs() const { return totalTimeValue; } @@ -497,7 +517,7 @@ void QAudioInputPrivate::suspend() { if(deviceState == QAudio::ActiveState) { waveInReset(hWaveIn); - deviceState = QAudio::SuspendState; + deviceState = QAudio::SuspendedState; emit stateChanged(deviceState); } } @@ -510,7 +530,7 @@ void QAudioInputPrivate::feedback() #endif bytesAvailable = bytesReady(); - if(!(deviceState==QAudio::StopState||deviceState==QAudio::SuspendState)) + if(!(deviceState==QAudio::StoppedState||deviceState==QAudio::SuspendedState)) emit processMore(); } @@ -539,9 +559,9 @@ bool QAudioInputPrivate::deviceReady() return true; } -qint64 QAudioInputPrivate::clock() const +qint64 QAudioInputPrivate::elapsedUSecs() const { - if (deviceState == QAudio::StopState) + if (deviceState == QAudio::StoppedState) return 0; return timeStampOpened.elapsed()*1000; diff --git a/src/multimedia/audio/qaudioinput_win32_p.h b/src/multimedia/audio/qaudioinput_win32_p.h index 26c470d..d555eff 100644 --- a/src/multimedia/audio/qaudioinput_win32_p.h +++ b/src/multimedia/audio/qaudioinput_win32_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -91,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; diff --git a/src/multimedia/audio/qaudiooutput.cpp b/src/multimedia/audio/qaudiooutput.cpp index 24fbea9..b61aa4f 100644 --- a/src/multimedia/audio/qaudiooutput.cpp +++ b/src/multimedia/audio/qaudiooutput.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -73,7 +73,11 @@ QT_BEGIN_NAMESPACE simple as: \code - QFile inputFile; + QFile inputFile; // class member. + QAudioOutput* audio; // class member. + \endcode + + \code inputFile.setFileName("/tmp/test.raw"); inputFile.open(QIODevice::ReadOnly); @@ -86,9 +90,15 @@ QT_BEGIN_NAMESPACE format.setByteOrder(QAudioFormat::LittleEndian); format.setSampleType(QAudioFormat::UnSignedInt); - QAudioOutput *audio = new QAudioOutput(format, this); + QAudioDeviceInfo info(QAudioDeviceInfo::defaultOutputDevice()); + if (!info.isFormatSupported(format)) { + qWarning()<<"raw audio format not supported by backend, cannot play audio."; + return; + } + + audio = new QAudioOutput(format, this); connect(audio,SIGNAL(stateChanged(QAudio::State)),SLOT(finishedPlaying(QAudio::State))); - audio->start(inputFile); + audio->start(&inputFile); \endcode @@ -104,6 +114,7 @@ QT_BEGIN_NAMESPACE if(state == QAudio::IdleState) { audio->stop(); inputFile.close(); + delete audio; } } \endcode @@ -125,12 +136,12 @@ 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. When - an error is encountered, the state changes to QAudio::StopState. + an error is encountered, the state changes to QAudio::StoppedState. You can check for errors by connecting to the stateChanged() signal: @@ -188,36 +199,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 */ -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); +} - PUSH MODE (device = 0) - -If currently not StopState, stop. +/*! + Returns a pointer to the QIODevice being used to handle the data + transfer. This QIODevice can be used to write() audio data directly. + + \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); } /*! @@ -227,8 +244,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() */ @@ -257,7 +274,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(); @@ -270,7 +287,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 @@ -358,9 +375,9 @@ int QAudioOutput::notifyInterval() const was called in microseconds. */ -qint64 QAudioOutput::totalTime() const +qint64 QAudioOutput::processedUSecs() const { - return d->totalTime(); + return d->processedUSecs(); } /*! @@ -368,9 +385,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 bb3496e..0f45b1b 100644 --- a/src/multimedia/audio/qaudiooutput.h +++ b/src/multimedia/audio/qaudiooutput.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -71,7 +71,9 @@ public: 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 9cbbaf9..43b65ec 100644 --- a/src/multimedia/audio/qaudiooutput_alsa_p.cpp +++ b/src/multimedia/audio/qaudiooutput_alsa_p.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -52,6 +52,7 @@ #include <QtCore/qcoreapplication.h> #include "qaudiooutput_alsa_p.h" +#include "qaudiodeviceinfo_alsa_p.h" QT_BEGIN_NAMESPACE @@ -77,7 +78,7 @@ 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; @@ -215,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; @@ -256,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); } @@ -281,21 +282,31 @@ bool QAudioOutputPrivate::open() unsigned int freakuency=settings.sampleRate(); QString dev = QLatin1String(m_device.constData()); - if(!dev.contains(QLatin1String("default"))) { -#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14) - dev = QString(QLatin1String("default:CARD=%1")).arg(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(m_device.contains(name)) + 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); @@ -304,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 ); @@ -387,7 +398,7 @@ bool QAudioOutputPrivate::open() 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); @@ -431,7 +442,7 @@ bool QAudioOutputPrivate::open() void QAudioOutputPrivate::close() { - deviceState = QAudio::StopState; + deviceState = QAudio::StoppedState; timer->stop(); if ( handle ) { @@ -494,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; @@ -507,7 +518,7 @@ int QAudioOutputPrivate::periodSize() const void QAudioOutputPrivate::setBufferSize(int value) { - if(deviceState == QAudio::StopState) + if(deviceState == QAudio::StoppedState) buffer_size = value; } @@ -529,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) { @@ -571,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); } @@ -579,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()); @@ -658,15 +669,15 @@ bool QAudioOutputPrivate::deviceReady() return true; } -qint64 QAudioOutputPrivate::clock() const +qint64 QAudioOutputPrivate::elapsedUSecs() const { if(!handle) return 0; - if (deviceState == QAudio::StopState) + if (deviceState == QAudio::StoppedState) return 0; -#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14) +#if(SND_LIB_MAJOR == 1 && SND_LIB_MINOR == 0 && SND_LIB_SUBMINOR >= 14) snd_pcm_status_t* status; snd_pcm_status_alloca(&status); diff --git a/src/multimedia/audio/qaudiooutput_alsa_p.h b/src/multimedia/audio/qaudiooutput_alsa_p.h index 298e89e..802bc27 100644 --- a/src/multimedia/audio/qaudiooutput_alsa_p.h +++ b/src/multimedia/audio/qaudiooutput_alsa_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -91,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; diff --git a/src/multimedia/audio/qaudiooutput_mac_p.cpp b/src/multimedia/audio/qaudiooutput_mac_p.cpp index 5bb872f..4367ee7 100644 --- a/src/multimedia/audio/qaudiooutput_mac_p.cpp +++ b/src/multimedia/audio/qaudiooutput_mac_p.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -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; } @@ -468,10 +468,10 @@ QIODevice* QAudioOutputPrivate::start(QIODevice* device) 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)); } @@ -480,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)); } @@ -495,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)); } @@ -504,7 +504,7 @@ void QAudioOutputPrivate::suspend() void QAudioOutputPrivate::resume() { QMutexLocker lock(&mutex); - if (stateCode == QAudio::SuspendState) { + if (stateCode == QAudio::SuspendedState) { audioThreadStart(); stateCode = QAudio::ActiveState; @@ -525,7 +525,7 @@ int QAudioOutputPrivate::periodSize() const void QAudioOutputPrivate::setBufferSize(int bs) { - if (stateCode == QAudio::StopState) + if (stateCode == QAudio::StoppedState) internalBufferSize = bs; } @@ -544,14 +544,14 @@ int QAudioOutputPrivate::notifyInterval() const return intervalTimer->interval(); } -qint64 QAudioOutputPrivate::totalTime() const +qint64 QAudioOutputPrivate::processedUSecs() const { return totalFrames * 1000000 / audioFormat.sampleRate(); } -qint64 QAudioOutputPrivate::clock() const +qint64 QAudioOutputPrivate::elapsedUSecs() const { - if (stateCode == QAudio::StopState) + if (stateCode == QAudio::StoppedState) return 0; return (AudioGetCurrentHostTime() - startTime) / (clockFrequency / 1000); @@ -614,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 04b3239..1aacc67 100644 --- a/src/multimedia/audio/qaudiooutput_mac_p.h +++ b/src/multimedia/audio/qaudiooutput_mac_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -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; diff --git a/src/multimedia/audio/qaudiooutput_win32_p.cpp b/src/multimedia/audio/qaudiooutput_win32_p.cpp index 4a77386..b6e9762 100644 --- a/src/multimedia/audio/qaudiooutput_win32_p.cpp +++ b/src/multimedia/audio/qaudiooutput_win32_p.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -71,7 +71,7 @@ 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; @@ -147,6 +147,14 @@ WAVEHDR* QAudioOutputPrivate::allocateBlocks(int size, int count) void QAudioOutputPrivate::freeBlocks(WAVEHDR* blockArray) { + WAVEHDR* blocks = blockArray; + + int count = buffer_size/period_size; + + for(int i = 0; i < count; i++) { + waveOutUnprepareHeader(hWaveOut,&blocks[i], sizeof(WAVEHDR)); + blocks+=sizeof(WAVEHDR); + } HeapFree(GetProcessHeap(), 0, blockArray); } @@ -157,7 +165,7 @@ QAudioFormat QAudioOutputPrivate::format() const QIODevice* QAudioOutputPrivate::start(QIODevice* device) { - if(deviceState != QAudio::StopState) + if(deviceState != QAudio::StoppedState) close(); if(!pullMode && audioSource) { @@ -187,7 +195,7 @@ QIODevice* QAudioOutputPrivate::start(QIODevice* device) void QAudioOutputPrivate::stop() { - if(deviceState == QAudio::StopState) + if(deviceState == QAudio::StoppedState) return; close(); if(!pullMode && audioSource) { @@ -255,7 +263,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; @@ -277,10 +285,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.sampleRate() *settings.channelCount()*(settings.sampleSize()/8)); waveOutReset(hWaveOut); @@ -308,7 +316,7 @@ int QAudioOutputPrivate::periodSize() const void QAudioOutputPrivate::setBufferSize(int value) { - if(deviceState == QAudio::StopState) + if(deviceState == QAudio::StoppedState) buffer_size = value; } @@ -330,7 +338,7 @@ int QAudioOutputPrivate::notifyInterval() const return intervalTime; } -qint64 QAudioOutputPrivate::totalTime() const +qint64 QAudioOutputPrivate::processedUSecs() const { return totalTimeValue; } @@ -390,7 +398,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); @@ -403,7 +411,7 @@ void QAudioOutputPrivate::suspend() { if(deviceState == QAudio::ActiveState) { waveOutPause(hWaveOut); - deviceState = QAudio::SuspendState; + deviceState = QAudio::SuspendedState; errorState = QAudio::NoError; emit stateChanged(deviceState); } @@ -417,7 +425,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); } @@ -491,9 +499,9 @@ bool QAudioOutputPrivate::deviceReady() return true; } -qint64 QAudioOutputPrivate::clock() const +qint64 QAudioOutputPrivate::elapsedUSecs() const { - if (deviceState == QAudio::StopState) + if (deviceState == QAudio::StoppedState) return 0; return timeStampOpened.elapsed()*1000; diff --git a/src/multimedia/audio/qaudiooutput_win32_p.h b/src/multimedia/audio/qaudiooutput_win32_p.h index bcf8e1e..6e0899f 100644 --- a/src/multimedia/audio/qaudiooutput_win32_p.h +++ b/src/multimedia/audio/qaudiooutput_win32_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -90,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; diff --git a/src/multimedia/video/qabstractvideobuffer.cpp b/src/multimedia/video/qabstractvideobuffer.cpp index 16b5cff..22b36f2 100644 --- a/src/multimedia/video/qabstractvideobuffer.cpp +++ b/src/multimedia/video/qabstractvideobuffer.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** diff --git a/src/multimedia/video/qabstractvideobuffer.h b/src/multimedia/video/qabstractvideobuffer.h index a224024..4ffa46f 100644 --- a/src/multimedia/video/qabstractvideobuffer.h +++ b/src/multimedia/video/qabstractvideobuffer.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** diff --git a/src/multimedia/video/qabstractvideobuffer_p.h b/src/multimedia/video/qabstractvideobuffer_p.h index 4e73314..c72f303 100644 --- a/src/multimedia/video/qabstractvideobuffer_p.h +++ b/src/multimedia/video/qabstractvideobuffer_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** diff --git a/src/multimedia/video/qabstractvideosurface.cpp b/src/multimedia/video/qabstractvideosurface.cpp index a4f51a2..3f6bc08 100644 --- a/src/multimedia/video/qabstractvideosurface.cpp +++ b/src/multimedia/video/qabstractvideosurface.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -57,8 +57,8 @@ QT_BEGIN_NAMESPACE of each frame is compatible with a stream format supplied when starting a presentation. A list of pixel formats a surface can present is given by the supportedPixelFormats() function, - and the isFormatSupported() function will test if a complete video format is supported. In - some cases when a format is not supported; isFormatSupported() may suggest a similar format. + and the isFormatSupported() function will test if a video surface format is supported. If a + format is not supported the nearestFormat() function may be able to suggest a similar format. For example if a surface supports fixed set of resolutions it may suggest the smallest supported resolution that contains the proposed resolution. @@ -118,21 +118,37 @@ QAbstractVideoSurface::~QAbstractVideoSurface() */ /*! - Tests a video \a format to determine if a surface can accept it. If the format isn't supported - the surface may suggest a \a similar format that is supported. + Tests a video surface \a format to determine if a surface can accept it. Returns true if the format is supported by the surface, and false otherwise. */ -bool QAbstractVideoSurface::isFormatSupported( - const QVideoSurfaceFormat &format, QVideoSurfaceFormat *similar) const +bool QAbstractVideoSurface::isFormatSupported(const QVideoSurfaceFormat &format) const { - Q_UNUSED(similar); - return supportedPixelFormats(format.handleType()).contains(format.pixelFormat()); } /*! + Returns a supported video surface format that is similar to \a format. + + A similar surface format is one that has the same \l {QVideoSurfaceFormat::pixelFormat()}{pixel + format} and \l {QVideoSurfaceFormat::handleType()}{handle type} but differs in some of the other + properties. For example if there are restrictions on the \l {QVideoSurfaceFormat::frameSize()} + {frame sizes} a video surface can accept it may suggest a format with a larger frame size and + a \l {QVideoSurfaceFormat::viewport()}{viewport} the size of the original frame size. + + If the format is already supported it will be returned unchanged, or if there is no similar + supported format an invalid format will be returned. +*/ + +QVideoSurfaceFormat QAbstractVideoSurface::nearestFormat(const QVideoSurfaceFormat &format) const +{ + return isFormatSupported(format) + ? format + : QVideoSurfaceFormat(); +} + +/*! \fn QAbstractVideoSurface::supportedFormatsChanged() Signals that the set of formats supported by a video surface has changed. @@ -162,23 +178,23 @@ QVideoSurfaceFormat QAbstractVideoSurface::surfaceFormat() const Returns true if the surface was started, and false if an error occurred. - \sa isStarted(), stop() + \sa isActive(), stop() */ bool QAbstractVideoSurface::start(const QVideoSurfaceFormat &format) { Q_D(QAbstractVideoSurface); - bool wasStarted = d->started; + bool wasActive = d->active; - d->started = true; + d->active = true; d->format = format; d->error = NoError; emit surfaceFormatChanged(d->format); - if (!wasStarted) - emit startedChanged(true); + if (!wasActive) + emit activeChanged(true); return true; } @@ -186,18 +202,18 @@ bool QAbstractVideoSurface::start(const QVideoSurfaceFormat &format) /*! Stops a video surface presenting frames and releases any resources acquired in start(). - \sa isStarted(), start() + \sa isActive(), start() */ void QAbstractVideoSurface::stop() { Q_D(QAbstractVideoSurface); - if (d->started) { + if (d->active) { d->format = QVideoSurfaceFormat(); - d->started = false; + d->active = false; - emit startedChanged(false); + emit activeChanged(false); emit surfaceFormatChanged(d->format); } } @@ -208,17 +224,17 @@ void QAbstractVideoSurface::stop() Returns true if the surface has been started, and false otherwise. */ -bool QAbstractVideoSurface::isStarted() const +bool QAbstractVideoSurface::isActive() const { - return d_func()->started; + return d_func()->active; } /*! - \fn QAbstractVideoSurface::startedChanged(bool started) + \fn QAbstractVideoSurface::activeChanged(bool active) - Signals that the \a started state of a video surface has changed. + Signals that the \a active state of a video surface has changed. - \sa isStarted(), start(), stop() + \sa isActive(), start(), stop() */ /*! diff --git a/src/multimedia/video/qabstractvideosurface.h b/src/multimedia/video/qabstractvideosurface.h index 3823eeb..f2cae17 100644 --- a/src/multimedia/video/qabstractvideosurface.h +++ b/src/multimedia/video/qabstractvideosurface.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -75,22 +75,22 @@ public: virtual QList<QVideoFrame::PixelFormat> supportedPixelFormats( QAbstractVideoBuffer::HandleType handleType = QAbstractVideoBuffer::NoHandle) const = 0; - virtual bool isFormatSupported( - const QVideoSurfaceFormat &format, QVideoSurfaceFormat *similar = 0) const; + virtual bool isFormatSupported(const QVideoSurfaceFormat &format) const; + virtual QVideoSurfaceFormat nearestFormat(const QVideoSurfaceFormat &format) const; QVideoSurfaceFormat surfaceFormat() const; virtual bool start(const QVideoSurfaceFormat &format); virtual void stop(); - bool isStarted() const; + bool isActive() const; virtual bool present(const QVideoFrame &frame) = 0; Error error() const; Q_SIGNALS: - void startedChanged(bool started); + void activeChanged(bool active); void surfaceFormatChanged(const QVideoSurfaceFormat &format); void supportedFormatsChanged(); diff --git a/src/multimedia/video/qabstractvideosurface_p.h b/src/multimedia/video/qabstractvideosurface_p.h index 3142b78..42df112 100644 --- a/src/multimedia/video/qabstractvideosurface_p.h +++ b/src/multimedia/video/qabstractvideosurface_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -64,14 +64,13 @@ class QAbstractVideoSurfacePrivate : public QObjectPrivate public: QAbstractVideoSurfacePrivate() : error(QAbstractVideoSurface::NoError) - , started(false) + , active(false) { } mutable QAbstractVideoSurface::Error error; QVideoSurfaceFormat format; - bool started; - + bool active; }; QT_END_NAMESPACE diff --git a/src/multimedia/video/qimagevideobuffer.cpp b/src/multimedia/video/qimagevideobuffer.cpp index bfeb2a0..e3e1585 100644 --- a/src/multimedia/video/qimagevideobuffer.cpp +++ b/src/multimedia/video/qimagevideobuffer.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -85,7 +85,7 @@ uchar *QImageVideoBuffer::map(MapMode mode, int *numBytes, int *bytesPerLine) d->mapMode = mode; if (numBytes) - *numBytes = d->image.numBytes(); + *numBytes = d->image.byteCount(); if (bytesPerLine) *bytesPerLine = d->image.bytesPerLine(); diff --git a/src/multimedia/video/qimagevideobuffer_p.h b/src/multimedia/video/qimagevideobuffer_p.h index e19d224..82075d7 100644 --- a/src/multimedia/video/qimagevideobuffer_p.h +++ b/src/multimedia/video/qimagevideobuffer_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** diff --git a/src/multimedia/video/qmemoryvideobuffer.cpp b/src/multimedia/video/qmemoryvideobuffer.cpp index 18118b1..2e892b7 100644 --- a/src/multimedia/video/qmemoryvideobuffer.cpp +++ b/src/multimedia/video/qmemoryvideobuffer.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** diff --git a/src/multimedia/video/qmemoryvideobuffer_p.h b/src/multimedia/video/qmemoryvideobuffer_p.h index 8f1f9a7..c66cf93 100644 --- a/src/multimedia/video/qmemoryvideobuffer_p.h +++ b/src/multimedia/video/qmemoryvideobuffer_p.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** diff --git a/src/multimedia/video/qvideoframe.cpp b/src/multimedia/video/qvideoframe.cpp index c884da0..f10ce97 100644 --- a/src/multimedia/video/qvideoframe.cpp +++ b/src/multimedia/video/qvideoframe.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -59,7 +59,7 @@ public: : startTime(-1) , endTime(-1) , data(0) - , numBytes(0) + , mappedBytes(0) , bytesPerLine(0) , pixelFormat(QVideoFrame::Format_Invalid) , fieldType(QVideoFrame::ProgressiveFrame) @@ -72,7 +72,7 @@ public: , startTime(-1) , endTime(-1) , data(0) - , numBytes(0) + , mappedBytes(0) , bytesPerLine(0) , pixelFormat(format) , fieldType(QVideoFrame::ProgressiveFrame) @@ -89,7 +89,7 @@ public: qint64 startTime; qint64 endTime; uchar *data; - int numBytes; + int mappedBytes; int bytesPerLine; QVideoFrame::PixelFormat pixelFormat; QVideoFrame::FieldType fieldType; @@ -109,7 +109,7 @@ private: The contents of a video frame can be mapped to memory using the map() function. While mapped the video data can accessed using the bits() function which returns a pointer to a - buffer, the total size of which is given by the numBytes(), and the size of each line is given + buffer, the total size of which is given by the mappedBytes(), and the size of each line is given by bytesPerLine(). The return value of the handle() function may be used to access frame data using the internal buffer's native APIs. @@ -304,12 +304,12 @@ QVideoFrame::QVideoFrame(int bytes, const QSize &size, int bytesPerLine, PixelFo \note This will construct an invalid video frame if there is no frame type equivalent to the image format. - \sa equivalentPixelFormat() + \sa pixelFormatFromImageFormat() */ QVideoFrame::QVideoFrame(const QImage &image) : d(new QVideoFramePrivate( - image.size(), equivalentPixelFormat(image.format()))) + image.size(), pixelFormatFromImageFormat(image.format()))) { if (d->pixelFormat != Format_Invalid) d->buffer = new QImageVideoBuffer(image); @@ -510,9 +510,9 @@ bool QVideoFrame::map(QAbstractVideoBuffer::MapMode mode) { if (d->buffer != 0 && d->data == 0) { Q_ASSERT(d->bytesPerLine == 0); - Q_ASSERT(d->numBytes == 0); + Q_ASSERT(d->mappedBytes == 0); - d->data = d->buffer->map(mode, &d->numBytes, &d->bytesPerLine); + d->data = d->buffer->map(mode, &d->mappedBytes, &d->bytesPerLine); return d->data != 0; } @@ -532,7 +532,7 @@ bool QVideoFrame::map(QAbstractVideoBuffer::MapMode mode) void QVideoFrame::unmap() { if (d->data != 0) { - d->numBytes = 0; + d->mappedBytes = 0; d->bytesPerLine = 0; d->data = 0; @@ -548,7 +548,7 @@ void QVideoFrame::unmap() This value is only valid while the frame data is \l {map()}{mapped}. - \sa bits(), map(), numBytes() + \sa bits(), map(), mappedBytes() */ int QVideoFrame::bytesPerLine() const @@ -561,7 +561,7 @@ int QVideoFrame::bytesPerLine() const This value is only valid while the frame data is \l {map()}{mapped}. - \sa map(), numBytes(), bytesPerLine() + \sa map(), mappedBytes(), bytesPerLine() */ uchar *QVideoFrame::bits() @@ -574,7 +574,7 @@ uchar *QVideoFrame::bits() This value is only valid while the frame data is \l {map()}{mapped}. - \sa map(), numBytes(), bytesPerLine() + \sa map(), mappedBytes(), bytesPerLine() */ const uchar *QVideoFrame::bits() const @@ -583,16 +583,16 @@ const uchar *QVideoFrame::bits() const } /*! - Returns the number of bytes occupied by the frame data. + Returns the number of bytes occupied by the mapped frame data. This value is only valid while the frame data is \l {map()}{mapped}. \sa map() */ -int QVideoFrame::numBytes() const +int QVideoFrame::mappedBytes() const { - return d->numBytes; + return d->mappedBytes; } /*! @@ -649,7 +649,7 @@ void QVideoFrame::setEndTime(qint64 time) format QVideoFrame::InvalidType is returned instead. */ -QVideoFrame::PixelFormat QVideoFrame::equivalentPixelFormat(QImage::Format format) +QVideoFrame::PixelFormat QVideoFrame::pixelFormatFromImageFormat(QImage::Format format) { switch (format) { case QImage::Format_Invalid: @@ -689,7 +689,7 @@ QVideoFrame::PixelFormat QVideoFrame::equivalentPixelFormat(QImage::Format forma format QImage::Format_Invalid is returned instead. */ -QImage::Format QVideoFrame::equivalentImageFormat(PixelFormat format) +QImage::Format QVideoFrame::imageFormatFromPixelFormat(PixelFormat format) { switch (format) { case Format_Invalid: diff --git a/src/multimedia/video/qvideoframe.h b/src/multimedia/video/qvideoframe.h index e1b46a8..668a738 100644 --- a/src/multimedia/video/qvideoframe.h +++ b/src/multimedia/video/qvideoframe.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -141,7 +141,7 @@ public: uchar *bits(); const uchar *bits() const; - int numBytes() const; + int mappedBytes() const; QVariant handle() const; @@ -151,8 +151,8 @@ public: qint64 endTime() const; void setEndTime(qint64 time); - static PixelFormat equivalentPixelFormat(QImage::Format format); - static QImage::Format equivalentImageFormat(PixelFormat format); + static PixelFormat pixelFormatFromImageFormat(QImage::Format format); + static QImage::Format imageFormatFromPixelFormat(PixelFormat format); private: QExplicitlySharedDataPointer<QVideoFramePrivate> d; diff --git a/src/multimedia/video/qvideosurfaceformat.cpp b/src/multimedia/video/qvideosurfaceformat.cpp index e6ef8f3..6b16e6a 100644 --- a/src/multimedia/video/qvideosurfaceformat.cpp +++ b/src/multimedia/video/qvideosurfaceformat.cpp @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -57,7 +57,7 @@ public: , handleType(QAbstractVideoBuffer::NoHandle) , scanLineDirection(QVideoSurfaceFormat::TopToBottom) , pixelAspectRatio(1, 1) - , yuvColorSpace(QVideoSurfaceFormat::YCbCr_Undefined) + , ycbcrColorSpace(QVideoSurfaceFormat::YCbCr_Undefined) , frameRate(0.0) { } @@ -71,7 +71,7 @@ public: , scanLineDirection(QVideoSurfaceFormat::TopToBottom) , frameSize(size) , pixelAspectRatio(1, 1) - , yuvColorSpace(QVideoSurfaceFormat::YCbCr_Undefined) + , ycbcrColorSpace(QVideoSurfaceFormat::YCbCr_Undefined) , viewport(QPoint(0, 0), size) , frameRate(0.0) { @@ -84,7 +84,7 @@ public: , scanLineDirection(other.scanLineDirection) , frameSize(other.frameSize) , pixelAspectRatio(other.pixelAspectRatio) - , yuvColorSpace(other.yuvColorSpace) + , ycbcrColorSpace(other.ycbcrColorSpace) , viewport(other.viewport) , frameRate(other.frameRate) , propertyNames(other.propertyNames) @@ -101,7 +101,7 @@ public: && pixelAspectRatio == other.pixelAspectRatio && viewport == other.viewport && frameRatesEqual(frameRate, other.frameRate) - && yuvColorSpace == other.yuvColorSpace + && ycbcrColorSpace == other.ycbcrColorSpace && propertyNames.count() == other.propertyNames.count()) { for (int i = 0; i < propertyNames.count(); ++i) { int j = other.propertyNames.indexOf(propertyNames.at(i)); @@ -125,7 +125,7 @@ public: QVideoSurfaceFormat::Direction scanLineDirection; QSize frameSize; QSize pixelAspectRatio; - QVideoSurfaceFormat::YuvColorSpace yuvColorSpace; + QVideoSurfaceFormat::YCbCrColorSpace ycbcrColorSpace; QRect viewport; qreal frameRate; QList<QByteArray> propertyNames; @@ -168,19 +168,10 @@ public: \value BottomToTop Scan lines are arranged from the bottom of the frame to the top. */ -/*! - \enum QVideoSurfaceFormat::ViewportMode - - Enumerates the methods for updating the stream viewport when the frame size is changed. - - \value ResetViewport The viewport is reset to cover an entire frame. - \value KeepViewport The viewport is kept within the bounds the frame. -*/ - /*! - \enum QVideoSurfaceFormat::YuvColorSpace + \enum QVideoSurfaceFormat::YCbCrColorSpace - Enumerates the YUV color space of video frames. + Enumerates the Y'CbCr color space of video frames. \value YCbCr_Undefined No color space is specified. @@ -340,21 +331,13 @@ int QVideoSurfaceFormat::frameHeight() const /*! Sets the size of frames in a video stream to \a size. - The viewport \a mode indicates how the view port should be updated. + This will reset the viewport() to fill the entire frame. */ -void QVideoSurfaceFormat::setFrameSize(const QSize &size, ViewportMode mode) +void QVideoSurfaceFormat::setFrameSize(const QSize &size) { d->frameSize = size; - - switch (mode) { - case ResetViewport: - d->viewport = QRect(QPoint(0, 0), size); - break; - case KeepViewport: - d->viewport = QRect(QPoint(0, 0), size).intersected(d->viewport); - break; - } + d->viewport = QRect(QPoint(0, 0), size); } /*! @@ -362,12 +345,13 @@ void QVideoSurfaceFormat::setFrameSize(const QSize &size, ViewportMode mode) Sets the \a width and \a height of frames in a video stream. - The viewport \a mode indicates how the view port should be updated. + This will reset the viewport() to fill the entire frame. */ -void QVideoSurfaceFormat::setFrameSize(int width, int height, ViewportMode mode) +void QVideoSurfaceFormat::setFrameSize(int width, int height) { - setFrameSize(QSize(width, height), mode); + d->frameSize = QSize(width, height); + d->viewport = QRect(0, 0, width, height); } /*! @@ -458,22 +442,22 @@ void QVideoSurfaceFormat::setPixelAspectRatio(int horizontal, int vertical) } /*! - Returns a YUV color space of a video stream. + Returns the Y'CbCr color space of a video stream. */ -QVideoSurfaceFormat::YuvColorSpace QVideoSurfaceFormat::yuvColorSpace() const +QVideoSurfaceFormat::YCbCrColorSpace QVideoSurfaceFormat::yCbCrColorSpace() const { - return d->yuvColorSpace; + return d->ycbcrColorSpace; } /*! - Sets a YUV color \a space of a video stream. + Sets the Y'CbCr color \a space of a video stream. It is only used with raw YUV frame types. */ -void QVideoSurfaceFormat::setYuvColorSpace(QVideoSurfaceFormat::YuvColorSpace space) +void QVideoSurfaceFormat::setYCbCrColorSpace(QVideoSurfaceFormat::YCbCrColorSpace space) { - d->yuvColorSpace = space; + d->ycbcrColorSpace = space; } /*! @@ -508,7 +492,7 @@ QList<QByteArray> QVideoSurfaceFormat::propertyNames() const << "frameRate" << "pixelAspectRatio" << "sizeHint" - << "yuvColorSpace") + << "yCbCrColorSpace") + d->propertyNames; } @@ -540,8 +524,8 @@ QVariant QVideoSurfaceFormat::property(const char *name) const return qVariantFromValue(d->pixelAspectRatio); } else if (qstrcmp(name, "sizeHint") == 0) { return sizeHint(); - } else if (qstrcmp(name, "yuvColorSpace") == 0) { - return qVariantFromValue(d->yuvColorSpace); + } else if (qstrcmp(name, "yCbCrColorSpace") == 0) { + return qVariantFromValue(d->ycbcrColorSpace); } else { int id = 0; for (; id < d->propertyNames.count() && d->propertyNames.at(id) != name; ++id) {} @@ -585,9 +569,9 @@ void QVideoSurfaceFormat::setProperty(const char *name, const QVariant &value) d->pixelAspectRatio = qvariant_cast<QSize>(value); } else if (qstrcmp(name, "sizeHint") == 0) { // read only. - } else if (qstrcmp(name, "yuvColorSpace") == 0) { - if (qVariantCanConvert<YuvColorSpace>(value)) - d->yuvColorSpace = qvariant_cast<YuvColorSpace>(value); + } else if (qstrcmp(name, "yCbCrColorSpace") == 0) { + if (qVariantCanConvert<YCbCrColorSpace>(value)) + d->ycbcrColorSpace = qvariant_cast<YCbCrColorSpace>(value); } else { int id = 0; for (; id < d->propertyNames.count() && d->propertyNames.at(id) != name; ++id) {} diff --git a/src/multimedia/video/qvideosurfaceformat.h b/src/multimedia/video/qvideosurfaceformat.h index 1f4a5cb..9c73f5f 100644 --- a/src/multimedia/video/qvideosurfaceformat.h +++ b/src/multimedia/video/qvideosurfaceformat.h @@ -1,6 +1,6 @@ /**************************************************************************** ** -** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). ** All rights reserved. ** Contact: Nokia Corporation (qt-info@nokia.com) ** @@ -68,13 +68,7 @@ public: BottomToTop }; - enum ViewportMode - { - ResetViewport, - KeepViewport - }; - - enum YuvColorSpace + enum YCbCrColorSpace { YCbCr_Undefined, YCbCr_BT601, @@ -106,8 +100,8 @@ public: QAbstractVideoBuffer::HandleType handleType() const; QSize frameSize() const; - void setFrameSize(const QSize &size, ViewportMode mode = ResetViewport); - void setFrameSize(int width, int height, ViewportMode mode = ResetViewport); + void setFrameSize(const QSize &size); + void setFrameSize(int width, int height); int frameWidth() const; int frameHeight() const; @@ -125,8 +119,8 @@ public: void setPixelAspectRatio(const QSize &ratio); void setPixelAspectRatio(int width, int height); - YuvColorSpace yuvColorSpace() const; - void setYuvColorSpace(YuvColorSpace colorSpace); + YCbCrColorSpace yCbCrColorSpace() const; + void setYCbCrColorSpace(YCbCrColorSpace colorSpace); QSize sizeHint() const; @@ -145,7 +139,7 @@ Q_MULTIMEDIA_EXPORT QDebug operator<<(QDebug, const QVideoSurfaceFormat &); QT_END_NAMESPACE Q_DECLARE_METATYPE(QVideoSurfaceFormat::Direction) -Q_DECLARE_METATYPE(QVideoSurfaceFormat::YuvColorSpace) +Q_DECLARE_METATYPE(QVideoSurfaceFormat::YCbCrColorSpace) QT_END_HEADER |