diff options
author | Bradley T. Hughes <bradley.hughes@nokia.com> | 2009-11-10 07:37:47 (GMT) |
---|---|---|
committer | Bradley T. Hughes <bradley.hughes@nokia.com> | 2009-11-10 07:37:47 (GMT) |
commit | 56a50deeb27032bd2125a6950a8044d77513a0fd (patch) | |
tree | a7539e3d9467df032ab4c5811da3ad9e5b4a784e /src | |
parent | 81f3b28f2f82b15f9d255ec38abdc5f749b8809c (diff) | |
parent | 6da8c83d8b5465cf9b767f288d3ebfa0727085c2 (diff) | |
download | Qt-56a50deeb27032bd2125a6950a8044d77513a0fd.zip Qt-56a50deeb27032bd2125a6950a8044d77513a0fd.tar.gz Qt-56a50deeb27032bd2125a6950a8044d77513a0fd.tar.bz2 |
Merge commit 'upstream/4.6' into 4.6
Diffstat (limited to 'src')
46 files changed, 1087 insertions, 228 deletions
diff --git a/src/multimedia/audio/qaudio.cpp b/src/multimedia/audio/qaudio.cpp index 04378d4..b687f34 100644 --- a/src/multimedia/audio/qaudio.cpp +++ b/src/multimedia/audio/qaudio.cpp @@ -71,23 +71,23 @@ public: /*! \enum QAudio::Error - \value NoError No errors have occurred - \value OpenError An error opening the audio device - \value IOError An error occurred during read/write of audio device - \value UnderrunError Audio data is not being fed to the audio device at a fast enough rate - \value FatalError A non-recoverable error has occurred, the audio device is not usable at this time. + \value NoError No errors have occurred + \value OpenError An error opening the audio device + \value IOError An error occurred during read/write of audio device + \value UnderrunError Audio data is not being fed to the audio device at a fast enough rate + \value FatalError A non-recoverable error has occurred, the audio device is not usable at this time. */ /*! \enum QAudio::State - \value ActiveState Audio data is being processed, this state is set after start() is called - and while audio data is available to be processed. - \value SuspendState The audio device is in a suspended state, this state will only be entered - after suspend() is called. - \value StopState The audio device is closed, not processing any audio data - \value IdleState The QIODevice passed in has no data and audio system's buffer is empty, this state - is set after start() is called and while no audio data is available to be processed. + \value ActiveState Audio data is being processed, this state is set after start() is called + and while audio data is available to be processed. + \value SuspendedState The audio device is in a suspended state, this state will only be entered + after suspend() is called. + \value StoppedState The audio device is closed, not processing any audio data + \value IdleState The QIODevice passed in has no data and audio system's buffer is empty, this state + is set after start() is called and while no audio data is available to be processed. */ /*! diff --git a/src/multimedia/audio/qaudio.h b/src/multimedia/audio/qaudio.h index a66f0b1..531e1a7 100644 --- a/src/multimedia/audio/qaudio.h +++ b/src/multimedia/audio/qaudio.h @@ -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/qaudiodevicefactory.cpp b/src/multimedia/audio/qaudiodevicefactory.cpp index 8804fb6..89e4394 100644 --- a/src/multimedia/audio/qaudiodevicefactory.cpp +++ b/src/multimedia/audio/qaudiodevicefactory.cpp @@ -94,10 +94,10 @@ public: int bufferSize() const { return 0; } void setNotifyInterval(int ) {} int notifyInterval() const { return 0; } - qint64 totalTime() const { return 0; } - qint64 clock() const { return 0; } + qint64 processedUSecs() const { return 0; } + qint64 elapsedUSecs() const { return 0; } QAudio::Error error() const { return QAudio::OpenError; } - QAudio::State state() const { return QAudio::StopState; } + QAudio::State state() const { return QAudio::StoppedState; } QAudioFormat format() const { return QAudioFormat(); } }; @@ -115,18 +115,18 @@ 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; #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 QFactoryLoader* l = loader(); @@ -134,7 +134,7 @@ QList<QAudioDeviceInfo> QAudioDeviceFactory::deviceList(QAudio::Mode mode) 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,7 +149,7 @@ 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); } @@ -164,7 +164,7 @@ 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); } diff --git a/src/multimedia/audio/qaudiodevicefactory_p.h b/src/multimedia/audio/qaudiodevicefactory_p.h index 008e4a8..2466455 100644 --- a/src/multimedia/audio/qaudiodevicefactory_p.h +++ b/src/multimedia/audio/qaudiodevicefactory_p.h @@ -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 dce2884..5e3adcb 100644 --- a/src/multimedia/audio/qaudiodeviceinfo.cpp +++ b/src/multimedia/audio/qaudiodeviceinfo.cpp @@ -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 @@ -327,9 +327,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 53b9904..5c7cb98 100644 --- a/src/multimedia/audio/qaudiodeviceinfo.h +++ b/src/multimedia/audio/qaudiodeviceinfo.h @@ -92,7 +92,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 e828238..5de6c70 100644 --- a/src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp +++ b/src/multimedia/audio/qaudiodeviceinfo_alsa_p.cpp @@ -382,7 +382,7 @@ void QAudioDeviceInfoInternal::updateLists() close(); } -QList<QByteArray> QAudioDeviceInfoInternal::deviceList(QAudio::Mode mode) +QList<QByteArray> QAudioDeviceInfoInternal::availableDevices(QAudio::Mode mode) { QList<QByteArray> devices; QByteArray filter; @@ -444,7 +444,7 @@ QList<QByteArray> QAudioDeviceInfoInternal::deviceList(QAudio::Mode mode) QByteArray QAudioDeviceInfoInternal::defaultInputDevice() { - QList<QByteArray> devices = deviceList(QAudio::AudioInput); + QList<QByteArray> devices = availableDevices(QAudio::AudioInput); if(devices.size() == 0) return QByteArray(); @@ -453,7 +453,7 @@ QByteArray QAudioDeviceInfoInternal::defaultInputDevice() QByteArray QAudioDeviceInfoInternal::defaultOutputDevice() { - QList<QByteArray> devices = deviceList(QAudio::AudioOutput); + QList<QByteArray> devices = availableDevices(QAudio::AudioOutput); if(devices.size() == 0) return QByteArray(); diff --git a/src/multimedia/audio/qaudiodeviceinfo_alsa_p.h b/src/multimedia/audio/qaudiodeviceinfo_alsa_p.h index 10078ca..5a807af 100644 --- a/src/multimedia/audio/qaudiodeviceinfo_alsa_p.h +++ b/src/multimedia/audio/qaudiodeviceinfo_alsa_p.h @@ -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 ec07748..8905119 100644 --- a/src/multimedia/audio/qaudiodeviceinfo_mac_p.cpp +++ b/src/multimedia/audio/qaudiodeviceinfo_mac_p.cpp @@ -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..0fd3ef5 100644 --- a/src/multimedia/audio/qaudiodeviceinfo_mac_p.h +++ b/src/multimedia/audio/qaudiodeviceinfo_mac_p.h @@ -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 69d5c94..33af022 100644 --- a/src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp +++ b/src/multimedia/audio/qaudiodeviceinfo_win32_p.cpp @@ -103,6 +103,7 @@ QAudioFormat QAudioDeviceInfoInternal::preferredFormat() const } else { nearest.setFrequency(11025); nearest.setChannels(1); + nearest.setByteOrder(QAudioFormat::LittleEndian); nearest.setSampleType(QAudioFormat::SignedInt); nearest.setSampleSize(8); nearest.setCodec(QLatin1String("audio/pcm")); @@ -333,7 +334,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..e191b6f 100644 --- a/src/multimedia/audio/qaudiodeviceinfo_win32_p.h +++ b/src/multimedia/audio/qaudiodeviceinfo_win32_p.h @@ -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..88e3804 100644 --- a/src/multimedia/audio/qaudioengine.cpp +++ b/src/multimedia/audio/qaudioengine.cpp @@ -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..f9e80c1 100644 --- a/src/multimedia/audio/qaudioengine.h +++ b/src/multimedia/audio/qaudioengine.h @@ -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.h b/src/multimedia/audio/qaudioengineplugin.h index fe30e0d..82dfa15 100644 --- a/src/multimedia/audio/qaudioengineplugin.h +++ b/src/multimedia/audio/qaudioengineplugin.h @@ -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 86fe85b..b2bbe14 100644 --- a/src/multimedia/audio/qaudioformat.cpp +++ b/src/multimedia/audio/qaudioformat.cpp @@ -38,7 +38,7 @@ ** $QT_END_LICENSE$ ** ****************************************************************************/ - +#include <QDebug> #include <QtMultimedia/qaudioformat.h> @@ -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(); } /*! diff --git a/src/multimedia/audio/qaudioformat.h b/src/multimedia/audio/qaudioformat.h index d5841ce..7e92c2f 100644 --- a/src/multimedia/audio/qaudioformat.h +++ b/src/multimedia/audio/qaudioformat.h @@ -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 7a3be23..e794eaf 100644 --- a/src/multimedia/audio/qaudioinput.cpp +++ b/src/multimedia/audio/qaudioinput.cpp @@ -121,15 +121,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 +176,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 +232,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 +262,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 +275,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 +364,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 +374,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..bf93a27 100644 --- a/src/multimedia/audio/qaudioinput.h +++ b/src/multimedia/audio/qaudioinput.h @@ -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 9eb8cfb..8a8f0db 100644 --- a/src/multimedia/audio/qaudioinput_alsa_p.cpp +++ b/src/multimedia/audio/qaudioinput_alsa_p.cpp @@ -75,7 +75,7 @@ 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; @@ -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); @@ -283,7 +283,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 +367,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 +413,7 @@ bool QAudioInputPrivate::open() void QAudioInputPrivate::close() { - deviceState = QAudio::StopState; + deviceState = QAudio::StoppedState; timer->stop(); if ( handle ) { @@ -490,7 +490,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 +508,7 @@ qint64 QAudioInputPrivate::read(char* data, qint64 len) void QAudioInputPrivate::resume() { - if(deviceState == QAudio::SuspendState) { + if(deviceState == QAudio::SuspendedState) { int err = 0; if(handle) { @@ -558,7 +558,7 @@ int QAudioInputPrivate::notifyInterval() const return intervalTime; } -qint64 QAudioInputPrivate::totalTime() const +qint64 QAudioInputPrivate::processedUSecs() const { return totalTimeValue; } @@ -567,14 +567,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,12 +606,12 @@ 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) diff --git a/src/multimedia/audio/qaudioinput_alsa_p.h b/src/multimedia/audio/qaudioinput_alsa_p.h index 2ed7453..67d5cf5 100644 --- a/src/multimedia/audio/qaudioinput_alsa_p.h +++ b/src/multimedia/audio/qaudioinput_alsa_p.h @@ -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 cb05920..d63045f 100644 --- a/src/multimedia/audio/qaudioinput_mac_p.cpp +++ b/src/multimedia/audio/qaudioinput_mac_p.cpp @@ -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.frequency(); } -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..2dbb808 100644 --- a/src/multimedia/audio/qaudioinput_mac_p.h +++ b/src/multimedia/audio/qaudioinput_mac_p.h @@ -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 a059e76..b7f9ffd 100644 --- a/src/multimedia/audio/qaudioinput_win32_p.cpp +++ b/src/multimedia/audio/qaudioinput_win32_p.cpp @@ -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; @@ -173,7 +173,7 @@ QAudioFormat QAudioInputPrivate::format() const QIODevice* QAudioInputPrivate::start(QIODevice* device) { - if(deviceState != QAudio::StopState) + if(deviceState != QAudio::StoppedState) close(); if(!pullMode && audioSource) { @@ -201,7 +201,7 @@ QIODevice* QAudioInputPrivate::start(QIODevice* device) void QAudioInputPrivate::stop() { - if(deviceState == QAudio::StopState) + if(deviceState == QAudio::StoppedState) return; close(); @@ -260,7 +260,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 +269,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 +286,7 @@ bool QAudioInputPrivate::open() if(result != MMSYSERR_NOERROR) { qWarning("QAudioInput: failed to setup block %d,err=%d",i,result); errorState = QAudio::OpenError; - deviceState = QAudio::StopState; + deviceState = QAudio::StoppedState; emit stateChanged(deviceState); return false; } @@ -295,7 +295,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,12 +309,12 @@ 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) { @@ -333,6 +333,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; @@ -400,14 +403,14 @@ qint64 QAudioInputPrivate::read(char* data, qint64 len) if(result != MMSYSERR_NOERROR) { qWarning("QAudioInput: failed to prepare block %d,err=%d",header,result); errorState = QAudio::OpenError; - deviceState = QAudio::StopState; + deviceState = QAudio::StoppedState; emit stateChanged(deviceState); } result = waveInAddBuffer(hWaveIn, &waveBlocks[header], sizeof(WAVEHDR)); if(result != MMSYSERR_NOERROR) { qWarning("QAudioInput: failed to setup block %d,err=%d",header,result); errorState = QAudio::OpenError; - deviceState = QAudio::StopState; + deviceState = QAudio::StoppedState; emit stateChanged(deviceState); } header++; @@ -435,14 +438,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 +491,7 @@ int QAudioInputPrivate::notifyInterval() const return intervalTime; } -qint64 QAudioInputPrivate::totalTime() const +qint64 QAudioInputPrivate::processedUSecs() const { return totalTimeValue; } @@ -497,7 +500,7 @@ void QAudioInputPrivate::suspend() { if(deviceState == QAudio::ActiveState) { waveInReset(hWaveIn); - deviceState = QAudio::SuspendState; + deviceState = QAudio::SuspendedState; emit stateChanged(deviceState); } } @@ -510,7 +513,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 +542,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..a2bd687 100644 --- a/src/multimedia/audio/qaudioinput_win32_p.h +++ b/src/multimedia/audio/qaudioinput_win32_p.h @@ -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 81b9496..f8f2fa1 100644 --- a/src/multimedia/audio/qaudiooutput.cpp +++ b/src/multimedia/audio/qaudiooutput.cpp @@ -125,12 +125,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 +188,42 @@ QAudioFormat QAudioOutput::format() const /*! Uses the \a device as the QIODevice to transfer data. - If \a device is null then the class creates an internal QIODevice. - Returns a pointer to the QIODevice being used to handle the data - transfer. This QIODevice can be used to write() audio data - directly. Passing a QIODevice allows the data to be transfered without any extra code. All that is required is to open the QIODevice. \sa QIODevice */ -QIODevice* QAudioOutput::start(QIODevice* device) +void QAudioOutput::start(QIODevice* device) { /* - PULL MODE (valid QIODevice) - -If currently not StopState, stop. + -If currently not StoppedState, stop. -If previous start was push mode, delete internal QIODevice. -open audio output. - -If ok, NoError and ActiveState, else OpenError and StopState + -If ok, NoError and ActiveState, else OpenError and StoppedState -emit stateChanged() - -return device + */ + d->start(device); +} + +/*! + Returns a pointer to the QIODevice being used to handle the data + transfer. This QIODevice can be used to write() audio data directly. - PUSH MODE (device = 0) - -If currently not StopState, stop. + \sa QIODevice +*/ + +QIODevice* QAudioOutput::start() +{ + /* + -If currently not StoppedState, stop. -If no internal QIODevice, create one. -open audio output. - -If ok, NoError and IdleState, else OpenError and StopState + -If ok, NoError and IdleState, else OpenError and StoppedState -emit stateChanged() -return internal QIODevice */ - return d->start(device); + return d->start(0); } /*! @@ -227,8 +233,8 @@ QIODevice* QAudioOutput::start(QIODevice* device) void QAudioOutput::stop() { /* - -If StopState, return - -set to StopState + -If StoppedState, return + -set to StoppedState -detach from audio device -emit stateChanged() */ @@ -257,7 +263,7 @@ void QAudioOutput::suspend() /* -If not ActiveState|IdleState, return -stop processing audio, saving all buffered audio data - -set NoError and SuspendState + -set NoError and SuspendedState -emit stateChanged() */ d->suspend(); @@ -270,7 +276,7 @@ void QAudioOutput::suspend() void QAudioOutput::resume() { /* - -If SuspendState, return + -If SuspendedState, return -resume audio -(PULL MODE): set ActiveState, NoError -(PUSH MODE): set IdleState, NoError @@ -358,9 +364,9 @@ int QAudioOutput::notifyInterval() const was called in microseconds. */ -qint64 QAudioOutput::totalTime() const +qint64 QAudioOutput::processedUSecs() const { - return d->totalTime(); + return d->processedUSecs(); } /*! @@ -368,9 +374,9 @@ qint64 QAudioOutput::totalTime() const Suspend states. */ -qint64 QAudioOutput::clock() const +qint64 QAudioOutput::elapsedUSecs() const { - return d->clock(); + return d->elapsedUSecs(); } /*! diff --git a/src/multimedia/audio/qaudiooutput.h b/src/multimedia/audio/qaudiooutput.h index bb3496e..38bab8e 100644 --- a/src/multimedia/audio/qaudiooutput.h +++ b/src/multimedia/audio/qaudiooutput.h @@ -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 689da89..e9784d2 100644 --- a/src/multimedia/audio/qaudiooutput_alsa_p.cpp +++ b/src/multimedia/audio/qaudiooutput_alsa_p.cpp @@ -77,7 +77,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 +215,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 +256,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); } @@ -304,7 +304,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 +387,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 +431,7 @@ bool QAudioOutputPrivate::open() void QAudioOutputPrivate::close() { - deviceState = QAudio::StopState; + deviceState = QAudio::StoppedState; timer->stop(); if ( handle ) { @@ -494,7 +494,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 +507,7 @@ int QAudioOutputPrivate::periodSize() const void QAudioOutputPrivate::setBufferSize(int value) { - if(deviceState == QAudio::StopState) + if(deviceState == QAudio::StoppedState) buffer_size = value; } @@ -529,14 +529,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 +571,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 +579,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,12 +658,12 @@ 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) diff --git a/src/multimedia/audio/qaudiooutput_alsa_p.h b/src/multimedia/audio/qaudiooutput_alsa_p.h index 298e89e..619ecef 100644 --- a/src/multimedia/audio/qaudiooutput_alsa_p.h +++ b/src/multimedia/audio/qaudiooutput_alsa_p.h @@ -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 f23db80..e0651bf 100644 --- a/src/multimedia/audio/qaudiooutput_mac_p.cpp +++ b/src/multimedia/audio/qaudiooutput_mac_p.cpp @@ -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.frequency(); } -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..76d06a9 100644 --- a/src/multimedia/audio/qaudiooutput_mac_p.h +++ b/src/multimedia/audio/qaudiooutput_mac_p.h @@ -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 1810ed2..2cfc472 100644 --- a/src/multimedia/audio/qaudiooutput_win32_p.cpp +++ b/src/multimedia/audio/qaudiooutput_win32_p.cpp @@ -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; @@ -157,7 +157,7 @@ QAudioFormat QAudioOutputPrivate::format() const QIODevice* QAudioOutputPrivate::start(QIODevice* device) { - if(deviceState != QAudio::StopState) + if(deviceState != QAudio::StoppedState) close(); if(!pullMode && audioSource) { @@ -187,7 +187,7 @@ QIODevice* QAudioOutputPrivate::start(QIODevice* device) void QAudioOutputPrivate::stop() { - if(deviceState == QAudio::StopState) + if(deviceState == QAudio::StoppedState) return; close(); if(!pullMode && audioSource) { @@ -255,7 +255,7 @@ bool QAudioOutputPrivate::open() (DWORD_PTR) this, CALLBACK_FUNCTION) != MMSYSERR_NOERROR) { errorState = QAudio::OpenError; - deviceState = QAudio::StopState; + deviceState = QAudio::StoppedState; emit stateChanged(deviceState); qWarning("QAudioOutput: open error"); return false; @@ -277,10 +277,10 @@ bool QAudioOutputPrivate::open() void QAudioOutputPrivate::close() { - if(deviceState == QAudio::StopState) + if(deviceState == QAudio::StoppedState) return; - deviceState = QAudio::StopState; + deviceState = QAudio::StoppedState; int delay = (buffer_size-bytesFree())*1000/(settings.frequency() *settings.channels()*(settings.sampleSize()/8)); waveOutReset(hWaveOut); @@ -308,7 +308,7 @@ int QAudioOutputPrivate::periodSize() const void QAudioOutputPrivate::setBufferSize(int value) { - if(deviceState == QAudio::StopState) + if(deviceState == QAudio::StoppedState) buffer_size = value; } @@ -330,7 +330,7 @@ int QAudioOutputPrivate::notifyInterval() const return intervalTime; } -qint64 QAudioOutputPrivate::totalTime() const +qint64 QAudioOutputPrivate::processedUSecs() const { return totalTimeValue; } @@ -390,7 +390,7 @@ qint64 QAudioOutputPrivate::write( const char *data, qint64 len ) void QAudioOutputPrivate::resume() { - if(deviceState == QAudio::SuspendState) { + if(deviceState == QAudio::SuspendedState) { deviceState = QAudio::ActiveState; errorState = QAudio::NoError; waveOutRestart(hWaveOut); @@ -403,7 +403,7 @@ void QAudioOutputPrivate::suspend() { if(deviceState == QAudio::ActiveState) { waveOutPause(hWaveOut); - deviceState = QAudio::SuspendState; + deviceState = QAudio::SuspendedState; errorState = QAudio::NoError; emit stateChanged(deviceState); } @@ -417,7 +417,7 @@ void QAudioOutputPrivate::feedback() #endif bytesAvailable = bytesFree(); - if(!(deviceState==QAudio::StopState||deviceState==QAudio::SuspendState)) { + if(!(deviceState==QAudio::StoppedState||deviceState==QAudio::SuspendedState)) { if(bytesAvailable >= period_size) QMetaObject::invokeMethod(this, "deviceReady", Qt::QueuedConnection); } @@ -491,9 +491,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..f90b8c2 100644 --- a/src/multimedia/audio/qaudiooutput_win32_p.h +++ b/src/multimedia/audio/qaudiooutput_win32_p.h @@ -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/script/api/qscriptengine.cpp b/src/script/api/qscriptengine.cpp index 2b60a46..216f325 100644 --- a/src/script/api/qscriptengine.cpp +++ b/src/script/api/qscriptengine.cpp @@ -1093,6 +1093,8 @@ void QScriptEnginePrivate::setContextFlags(JSC::ExecState *exec, uint flags) void QScriptEnginePrivate::mark(JSC::MarkStack& markStack) { + Q_Q(QScriptEngine); + markStack.append(originalGlobalObject()); markStack.append(globalObject()); if (originalGlobalObjectProxy) @@ -1130,6 +1132,22 @@ void QScriptEnginePrivate::mark(JSC::MarkStack& markStack) markStack.append((*it)->prototype); } } + + { + QScriptContext *context = q->currentContext(); + + while (context) { + JSC::ScopeChainNode *node = frameForContext(context)->scopeChain(); + JSC::ScopeChainIterator it(node); + for (it = node->begin(); it != node->end(); ++it) { + JSC::JSObject *object = *it; + if (object) + markStack.append(object); + } + + context = context->parentContext(); + } + } } bool QScriptEnginePrivate::isCollecting() const @@ -2281,7 +2299,8 @@ QScriptContext *QScriptEngine::pushContext() return the new top frame. (might be the same as exec if a new stackframe was not needed) or 0 if stack overflow */ JSC::CallFrame *QScriptEnginePrivate::pushContext(JSC::CallFrame *exec, JSC::JSValue _thisObject, - const JSC::ArgList& args, JSC::JSObject *callee, bool calledAsConstructor) + const JSC::ArgList& args, JSC::JSObject *callee, bool calledAsConstructor, + bool clearScopeChain) { JSC::JSValue thisObject = _thisObject; if (calledAsConstructor) { @@ -2315,7 +2334,14 @@ JSC::CallFrame *QScriptEnginePrivate::pushContext(JSC::CallFrame *exec, JSC::JSV for (it = args.begin(); it != args.end(); ++it) newCallFrame[++dst] = *it; newCallFrame += argc + JSC::RegisterFile::CallFrameHeaderSize; - newCallFrame->init(0, /*vPC=*/0, exec->scopeChain(), exec, flags | ShouldRestoreCallFrame, argc, callee); + + if (!clearScopeChain) { + newCallFrame->init(0, /*vPC=*/0, exec->scopeChain(), exec, flags | ShouldRestoreCallFrame, argc, callee); + } else { + JSC::JSObject *jscObject = originalGlobalObject(); + JSC::ScopeChainNode *scn = new JSC::ScopeChainNode(0, jscObject, &exec->globalData(), jscObject); + newCallFrame->init(0, /*vPC=*/0, scn, exec, flags | ShouldRestoreCallFrame, argc, callee); + } } else { setContextFlags(newCallFrame, flags); #if ENABLE(JIT) diff --git a/src/script/api/qscriptengine.h b/src/script/api/qscriptengine.h index 3f438da..7db61e1 100644 --- a/src/script/api/qscriptengine.h +++ b/src/script/api/qscriptengine.h @@ -56,6 +56,7 @@ #include <QtScript/qscriptvalue.h> #include <QtScript/qscriptcontext.h> #include <QtScript/qscriptstring.h> +#include <QtScript/qscriptprogram.h> QT_BEGIN_HEADER @@ -67,7 +68,6 @@ class QDateTime; class QScriptClass; class QScriptEngineAgent; class QScriptEnginePrivate; -class QScriptProgram; #ifndef QT_NO_QOBJECT diff --git a/src/script/api/qscriptengine_p.h b/src/script/api/qscriptengine_p.h index d12b0f4..e7cdcda 100644 --- a/src/script/api/qscriptengine_p.h +++ b/src/script/api/qscriptengine_p.h @@ -174,7 +174,7 @@ public: static JSC::Register *thisRegisterForFrame(JSC::ExecState *frame); JSC::CallFrame *pushContext(JSC::CallFrame *exec, JSC::JSValue thisObject, const JSC::ArgList& args, - JSC::JSObject *callee, bool calledAsConstructor = false); + JSC::JSObject *callee, bool calledAsConstructor = false, bool clearScopeChain = false); void popContext(); void mark(JSC::MarkStack& markStack); diff --git a/src/script/api/qscriptvalue.cpp b/src/script/api/qscriptvalue.cpp index 52a1e6d..d6cbb41 100644 --- a/src/script/api/qscriptvalue.cpp +++ b/src/script/api/qscriptvalue.cpp @@ -71,6 +71,7 @@ #include "bridge/qscriptclassobject_p.h" #include "bridge/qscriptvariant_p.h" #include "bridge/qscriptqobject_p.h" +#include "bridge/qscriptdeclarativeclass_p.h" /*! \since 4.3 @@ -1496,6 +1497,8 @@ QVariant QScriptValue::toVariant() const #endif else if (isArray()) return QScriptEnginePrivate::variantListFromArray(*this); + else if (QScriptDeclarativeClass *dc = QScriptDeclarativeClass::scriptClass(*this)) + return dc->toVariant(QScriptDeclarativeClass::object(*this)); // try to convert to primitive JSC::ExecState *exec = d->engine->currentFrame; JSC::JSValue savedException; @@ -1586,6 +1589,8 @@ QObject *QScriptValue::toQObject() const if (isQObject()) { QScriptObject *object = static_cast<QScriptObject*>(JSC::asObject(d->jscValue)); return static_cast<QScript::QObjectDelegate*>(object->delegate())->value(); + } else if (QScriptDeclarativeClass *dc = QScriptDeclarativeClass::scriptClass(*this)) { + return dc->toQObject(QScriptDeclarativeClass::object(*this)); } else if (isVariant()) { QVariant var = toVariant(); int type = var.userType(); diff --git a/src/script/bridge/bridge.pri b/src/script/bridge/bridge.pri index 666a07e..09e2dfb 100644 --- a/src/script/bridge/bridge.pri +++ b/src/script/bridge/bridge.pri @@ -5,7 +5,9 @@ SOURCES += \ $$PWD/qscriptvariant.cpp \ $$PWD/qscriptqobject.cpp \ $$PWD/qscriptglobalobject.cpp \ - $$PWD/qscriptactivationobject.cpp + $$PWD/qscriptactivationobject.cpp \ + $$PWD/qscriptdeclarativeobject.cpp \ + $$PWD/qscriptdeclarativeclass.cpp HEADERS += \ $$PWD/qscriptfunction_p.h \ @@ -14,4 +16,6 @@ HEADERS += \ $$PWD/qscriptvariant_p.h \ $$PWD/qscriptqobject_p.h \ $$PWD/qscriptglobalobject_p.h \ - $$PWD/qscriptactivationobject_p.h + $$PWD/qscriptactivationobject_p.h \ + $$PWD/qscriptdeclarativeobject_p.h \ + $$PWD/qscriptdeclarativeclass_p.h diff --git a/src/script/bridge/qscriptdeclarativeclass.cpp b/src/script/bridge/qscriptdeclarativeclass.cpp new file mode 100644 index 0000000..b5d9bf5 --- /dev/null +++ b/src/script/bridge/qscriptdeclarativeclass.cpp @@ -0,0 +1,356 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qscriptdeclarativeclass_p.h" +#include "qscriptdeclarativeobject_p.h" +#include "qscriptobject_p.h" +#include <QtScript/qscriptstring.h> +#include <QtScript/qscriptengine.h> +#include <QtScript/qscriptengineagent.h> +#include <private/qscriptengine_p.h> +#include <private/qscriptvalue_p.h> +#include <private/qscriptqobject_p.h> +#include <private/qscriptactivationobject_p.h> +#include <QtCore/qstringlist.h> + +QT_BEGIN_NAMESPACE + +QScriptDeclarativeClass::PersistentIdentifier::PersistentIdentifier() +{ + new (&d) JSC::Identifier(); +} + +QScriptDeclarativeClass::PersistentIdentifier::~PersistentIdentifier() +{ + ((JSC::Identifier &)d).JSC::Identifier::~Identifier(); +} + +QScriptDeclarativeClass::PersistentIdentifier::PersistentIdentifier(const PersistentIdentifier &other) +{ + identifier = other.identifier; + new (&d) JSC::Identifier((JSC::Identifier &)(other.d)); +} + +QScriptDeclarativeClass::PersistentIdentifier & +QScriptDeclarativeClass::PersistentIdentifier::operator=(const PersistentIdentifier &other) +{ + identifier = other.identifier; + ((JSC::Identifier &)d) = (JSC::Identifier &)(other.d); + return *this; +} + +QScriptDeclarativeClass::QScriptDeclarativeClass(QScriptEngine *engine) +: d_ptr(new QScriptDeclarativeClassPrivate) +{ + Q_ASSERT(sizeof(void*) == sizeof(JSC::Identifier)); + d_ptr->q_ptr = this; + d_ptr->engine = engine; +} + +QScriptValue QScriptDeclarativeClass::newObject(QScriptEngine *engine, + QScriptDeclarativeClass *scriptClass, + Object *object) +{ + Q_ASSERT(engine); + Q_ASSERT(scriptClass); + + QScriptEnginePrivate *p = static_cast<QScriptEnginePrivate *>(QObjectPrivate::get(engine)); + + JSC::ExecState* exec = p->currentFrame; + QScriptObject *result = new (exec) QScriptObject(p->scriptObjectStructure); + result->setDelegate(new QScript::DeclarativeObjectDelegate(scriptClass, object)); + return p->scriptValueFromJSCValue(result); +} + +QScriptDeclarativeClass *QScriptDeclarativeClass::scriptClass(const QScriptValue &v) +{ + QScriptValuePrivate *d = QScriptValuePrivate::get(v); + if (!d || !d->isJSC() || !d->jscValue.inherits(&QScriptObject::info)) + return 0; + QScriptObject *scriptObject = static_cast<QScriptObject*>(JSC::asObject(d->jscValue)); + QScriptObjectDelegate *delegate = scriptObject->delegate(); + if (!delegate || (delegate->type() != QScriptObjectDelegate::DeclarativeClassObject)) + return 0; + return static_cast<QScript::DeclarativeObjectDelegate*>(delegate)->scriptClass(); +} + +QScriptDeclarativeClass::Object *QScriptDeclarativeClass::object(const QScriptValue &v) +{ + QScriptValuePrivate *d = QScriptValuePrivate::get(v); + if (!d || !d->isJSC() || !d->jscValue.inherits(&QScriptObject::info)) + return 0; + QScriptObject *scriptObject = static_cast<QScriptObject*>(JSC::asObject(d->jscValue)); + QScriptObjectDelegate *delegate = scriptObject->delegate(); + if (!delegate || (delegate->type() != QScriptObjectDelegate::DeclarativeClassObject)) + return 0; + return static_cast<QScript::DeclarativeObjectDelegate*>(delegate)->object(); +} + +QScriptValue QScriptDeclarativeClass::function(const QScriptValue &v, const Identifier &name) +{ + QScriptValuePrivate *d = QScriptValuePrivate::get(v); + + if (!d->isObject()) + return QScriptValue(); + + JSC::ExecState *exec = d->engine->currentFrame; + JSC::JSObject *object = d->jscValue.getObject(); + JSC::PropertySlot slot(const_cast<JSC::JSObject*>(object)); + JSC::JSValue result; + + JSC::Identifier id(exec, (JSC::UString::Rep *)name); + + if (const_cast<JSC::JSObject*>(object)->getOwnPropertySlot(exec, id, slot)) { + result = slot.getValue(exec, id); + if (QScript::isFunction(result)) + return d->engine->scriptValueFromJSCValue(result); + } + + return QScriptValue(); +} + +QScriptValue QScriptDeclarativeClass::property(const QScriptValue &v, const Identifier &name) +{ + QScriptValuePrivate *d = QScriptValuePrivate::get(v); + + if (!d->isObject()) + return QScriptValue(); + + JSC::ExecState *exec = d->engine->currentFrame; + JSC::JSObject *object = d->jscValue.getObject(); + JSC::PropertySlot slot(const_cast<JSC::JSObject*>(object)); + JSC::JSValue result; + + JSC::Identifier id(exec, (JSC::UString::Rep *)name); + + if (const_cast<JSC::JSObject*>(object)->getOwnPropertySlot(exec, id, slot)) { + result = slot.getValue(exec, id); + return d->engine->scriptValueFromJSCValue(result); + } + + return QScriptValue(); +} + +/* +Returns the scope chain entry at \a index. If index is less than 0, returns +entries starting at the end. For example, scopeChainValue(context, -1) will return +the value last in the scope chain. +*/ +QScriptValue QScriptDeclarativeClass::scopeChainValue(QScriptContext *context, int index) +{ + context->activationObject(); //ensure the creation of the normal scope for native context + const JSC::CallFrame *frame = QScriptEnginePrivate::frameForContext(context); + QScriptEnginePrivate *engine = QScript::scriptEngineFromExec(frame); + + JSC::ScopeChainNode *node = frame->scopeChain(); + JSC::ScopeChainIterator it(node); + + if (index < 0) { + int count = 0; + for (it = node->begin(); it != node->end(); ++it) + ++count; + + index = qAbs(index); + if (index > count) + return QScriptValue(); + else + index = count - index; + } + + for (it = node->begin(); it != node->end(); ++it) { + + if (index == 0) { + + JSC::JSObject *object = *it; + if (!object) return QScriptValue(); + + if (object->inherits(&QScript::QScriptActivationObject::info) + && (static_cast<QScript::QScriptActivationObject*>(object)->delegate() != 0)) { + // Return the object that property access is being delegated to + object = static_cast<QScript::QScriptActivationObject*>(object)->delegate(); + } + return engine->scriptValueFromJSCValue(object); + + } else { + --index; + } + + } + + return QScriptValue(); +} + +/*! + Enters a new execution context and returns the associated + QScriptContext object. + + Once you are done with the context, you should call popContext() to + restore the old context. + + By default, the `this' object of the new context is the Global Object. + The context's \l{QScriptContext::callee()}{callee}() will be invalid. + + Unlike pushContext(), the default scope chain is reset to include + only the global object and the QScriptContext's activation object. + + \sa QScriptEngine::popContext() +*/ +QScriptContext * QScriptDeclarativeClass::pushCleanContext(QScriptEngine *engine) +{ + if (!engine) + return 0; + + QScriptEnginePrivate *d = QScriptEnginePrivate::get(engine); + + JSC::CallFrame* newFrame = d->pushContext(d->currentFrame, + d->currentFrame->globalData().dynamicGlobalObject, + JSC::ArgList(), /*callee = */0, false, true); + + if (engine->agent()) + engine->agent()->contextPush(); + + return d->contextForFrame(newFrame); +} + +QScriptDeclarativeClass::~QScriptDeclarativeClass() +{ +} + +QScriptEngine *QScriptDeclarativeClass::engine() const +{ + return d_ptr->engine; +} + +QScriptDeclarativeClass::PersistentIdentifier +QScriptDeclarativeClass::createPersistentIdentifier(const QString &str) +{ + QScriptEnginePrivate *p = + static_cast<QScriptEnginePrivate *>(QObjectPrivate::get(d_ptr->engine)); + JSC::ExecState* exec = p->currentFrame; + + PersistentIdentifier rv(true); + new (&rv.d) JSC::Identifier(exec, (UChar *)str.constData(), str.size()); + rv.identifier = (void *)((JSC::Identifier &)rv.d).ustring().rep(); + return rv; +} + +QScriptDeclarativeClass::PersistentIdentifier +QScriptDeclarativeClass::createPersistentIdentifier(const Identifier &id) +{ + QScriptEnginePrivate *p = + static_cast<QScriptEnginePrivate *>(QObjectPrivate::get(d_ptr->engine)); + JSC::ExecState* exec = p->currentFrame; + + PersistentIdentifier rv(true); + new (&rv.d) JSC::Identifier(exec, (JSC::UString::Rep *)id); + rv.identifier = (void *)((JSC::Identifier &)rv.d).ustring().rep(); + return rv; +} + +QString QScriptDeclarativeClass::toString(const Identifier &identifier) +{ + JSC::UString::Rep *r = (JSC::UString::Rep *)identifier; + return QString((QChar *)r->data(), r->size()); +} + +quint32 QScriptDeclarativeClass::toArrayIndex(const Identifier &identifier, bool *ok) +{ + JSC::UString::Rep *r = (JSC::UString::Rep *)identifier; + JSC::UString s(r); + return s.toArrayIndex(ok); +} + +QScriptClass::QueryFlags +QScriptDeclarativeClass::queryProperty(Object *object, const Identifier &name, + QScriptClass::QueryFlags flags) +{ + Q_UNUSED(object); + Q_UNUSED(name); + Q_UNUSED(flags); + return 0; +} + +QScriptValue QScriptDeclarativeClass::property(Object *object, const Identifier &name) +{ + Q_UNUSED(object); + Q_UNUSED(name); + return QScriptValue(); +} + +void QScriptDeclarativeClass::setProperty(Object *object, const Identifier &name, + const QScriptValue &value) +{ + Q_UNUSED(object); + Q_UNUSED(name); + Q_UNUSED(value); +} + +QScriptValue::PropertyFlags +QScriptDeclarativeClass::propertyFlags(Object *object, const Identifier &name) +{ + Q_UNUSED(object); + Q_UNUSED(name); + return 0; +} + +QStringList QScriptDeclarativeClass::propertyNames(Object *object) +{ + Q_UNUSED(object); + return QStringList(); +} + +QObject *QScriptDeclarativeClass::toQObject(Object *, bool *ok) +{ + if (ok) *ok = false; + return 0; +} + +QVariant QScriptDeclarativeClass::toVariant(Object *, bool *ok) +{ + if (ok) *ok = false; + return QVariant(); +} + +QScriptContext *QScriptDeclarativeClass::context() const +{ + return d_ptr->context; +} + diff --git a/src/script/bridge/qscriptdeclarativeclass_p.h b/src/script/bridge/qscriptdeclarativeclass_p.h new file mode 100644 index 0000000..d0e653d --- /dev/null +++ b/src/script/bridge/qscriptdeclarativeclass_p.h @@ -0,0 +1,129 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSCRIPTDECLARATIVECLASS_P_H +#define QSCRIPTDECLARATIVECLASS_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtCore/qobjectdefs.h> +#include <QtScript/qscriptvalue.h> +#include <QtScript/qscriptclass.h> + +QT_BEGIN_NAMESPACE + +class QScriptDeclarativeClassPrivate; +class PersistentIdentifierPrivate; +class QScriptContext; +class Q_SCRIPT_EXPORT QScriptDeclarativeClass +{ +public: + typedef void* Identifier; + + struct Object { virtual ~Object() {} }; + + static QScriptValue newObject(QScriptEngine *, QScriptDeclarativeClass *, Object *); + static QScriptDeclarativeClass *scriptClass(const QScriptValue &); + static Object *object(const QScriptValue &); + + static QScriptValue function(const QScriptValue &, const Identifier &); + static QScriptValue property(const QScriptValue &, const Identifier &); + + static QScriptValue scopeChainValue(QScriptContext *, int index); + static QScriptContext *pushCleanContext(QScriptEngine *); + + class Q_SCRIPT_EXPORT PersistentIdentifier + { + public: + Identifier identifier; + + PersistentIdentifier(); + ~PersistentIdentifier(); + PersistentIdentifier(const PersistentIdentifier &other); + PersistentIdentifier &operator=(const PersistentIdentifier &other); + + private: + friend class QScriptDeclarativeClass; + PersistentIdentifier(bool) : identifier(0), d(0) {} + void *d; + }; + + QScriptDeclarativeClass(QScriptEngine *engine); + virtual ~QScriptDeclarativeClass(); + + QScriptEngine *engine() const; + + PersistentIdentifier createPersistentIdentifier(const QString &); + PersistentIdentifier createPersistentIdentifier(const Identifier &); + + QString toString(const Identifier &); + quint32 toArrayIndex(const Identifier &, bool *ok); + + virtual QScriptClass::QueryFlags queryProperty(Object *, const Identifier &, + QScriptClass::QueryFlags flags); + + virtual QScriptValue property(Object *, const Identifier &); + virtual void setProperty(Object *, const Identifier &name, const QScriptValue &); + virtual QScriptValue::PropertyFlags propertyFlags(Object *, const Identifier &); + + virtual QStringList propertyNames(Object *); + + virtual QObject *toQObject(Object *, bool *ok = 0); + virtual QVariant toVariant(Object *, bool *ok = 0); + + QScriptContext *context() const; +protected: + friend class QScriptDeclarativeClassPrivate; + QScopedPointer<QScriptDeclarativeClassPrivate> d_ptr; +}; + +QT_END_NAMESPACE + +#endif diff --git a/src/script/bridge/qscriptdeclarativeobject.cpp b/src/script/bridge/qscriptdeclarativeobject.cpp new file mode 100644 index 0000000..1af632d --- /dev/null +++ b/src/script/bridge/qscriptdeclarativeobject.cpp @@ -0,0 +1,192 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "config.h" +#include "qscriptdeclarativeobject_p.h" + +#include "../api/qscriptengine.h" +#include "../api/qscriptengine_p.h" +#include "../api/qscriptcontext.h" +#include "../api/qscriptcontext_p.h" +#include "../api/qscriptclass.h" +#include "../api/qscriptclasspropertyiterator.h" + +#include "Error.h" +#include "PropertyNameArray.h" + +#include <QtCore/qstringlist.h> + +Q_DECLARE_METATYPE(QScriptContext*) +Q_DECLARE_METATYPE(QScriptValue) +Q_DECLARE_METATYPE(QScriptValueList) + +QT_BEGIN_NAMESPACE + +namespace QScript +{ + +DeclarativeObjectDelegate::DeclarativeObjectDelegate(QScriptDeclarativeClass *c, + QScriptDeclarativeClass::Object *o) +: m_class(c), m_object(o) +{ +} + +DeclarativeObjectDelegate::~DeclarativeObjectDelegate() +{ + delete m_object; +} + +QScriptObjectDelegate::Type DeclarativeObjectDelegate::type() const +{ + return DeclarativeClassObject; +} + +bool DeclarativeObjectDelegate::getOwnPropertySlot(QScriptObject* object, + JSC::ExecState *exec, + const JSC::Identifier &propertyName, + JSC::PropertySlot &slot) +{ + QScriptEnginePrivate *engine = scriptEngineFromExec(exec); + QScriptDeclarativeClass::Identifier identifier = (void *)propertyName.ustring().rep(); + + QScriptDeclarativeClassPrivate *p = QScriptDeclarativeClassPrivate::get(m_class); + p->context = reinterpret_cast<QScriptContext *>(exec); + QScriptClass::QueryFlags flags = + m_class->queryProperty(m_object, identifier, QScriptClass::HandlesReadAccess); + if (flags & QScriptClass::HandlesReadAccess) { + QScriptValue value = m_class->property(m_object, identifier); + p->context = 0; + slot.setValue(engine->scriptValueToJSCValue(value)); + return true; + } + p->context = 0; + + return QScriptObjectDelegate::getOwnPropertySlot(object, exec, propertyName, slot); +} + +void DeclarativeObjectDelegate::put(QScriptObject* object, JSC::ExecState *exec, + const JSC::Identifier &propertyName, + JSC::JSValue value, JSC::PutPropertySlot &slot) +{ + QScriptEnginePrivate *engine = scriptEngineFromExec(exec); + QScriptDeclarativeClass::Identifier identifier = (void *)propertyName.ustring().rep(); + + QScriptDeclarativeClassPrivate *p = QScriptDeclarativeClassPrivate::get(m_class); + p->context = reinterpret_cast<QScriptContext *>(exec); + QScriptClass::QueryFlags flags = + m_class->queryProperty(m_object, identifier, QScriptClass::HandlesWriteAccess); + if (flags & QScriptClass::HandlesWriteAccess) { + m_class->setProperty(m_object, identifier, engine->scriptValueFromJSCValue(value)); + p->context = 0; + return; + } + p->context = 0; + + QScriptObjectDelegate::put(object, exec, propertyName, value, slot); +} + +bool DeclarativeObjectDelegate::deleteProperty(QScriptObject* object, JSC::ExecState *exec, + const JSC::Identifier &propertyName, + bool checkDontDelete) +{ + return QScriptObjectDelegate::deleteProperty(object, exec, propertyName, checkDontDelete); +} + +bool DeclarativeObjectDelegate::getPropertyAttributes(const QScriptObject* object, + JSC::ExecState *exec, + const JSC::Identifier &propertyName, + unsigned &attribs) const +{ + QScriptDeclarativeClass::Identifier identifier = (void *)propertyName.ustring().rep(); + + QScriptClass::QueryFlags flags = + m_class->queryProperty(m_object, identifier, QScriptClass::HandlesReadAccess); + if (flags & QScriptClass::HandlesReadAccess) { + QScriptValue::PropertyFlags flags = m_class->propertyFlags(m_object, identifier); + attribs = 0; + if (flags & QScriptValue::ReadOnly) + attribs |= JSC::ReadOnly; + if (flags & QScriptValue::SkipInEnumeration) + attribs |= JSC::DontEnum; + if (flags & QScriptValue::Undeletable) + attribs |= JSC::DontDelete; + if (flags & QScriptValue::PropertyGetter) + attribs |= JSC::Getter; + if (flags & QScriptValue::PropertySetter) + attribs |= JSC::Setter; + attribs |= flags & QScriptValue::UserRange; + return true; + } + return QScriptObjectDelegate::getPropertyAttributes(object, exec, propertyName, attribs); +} + +void DeclarativeObjectDelegate::getOwnPropertyNames(QScriptObject* object, JSC::ExecState *exec, + JSC::PropertyNameArray &propertyNames, + bool includeNonEnumerable) +{ + QStringList properties = m_class->propertyNames(m_object); + for (int ii = 0; ii < properties.count(); ++ii) { + const QString &name = properties.at(ii); + propertyNames.add(JSC::Identifier(exec, name)); + } + + QScriptObjectDelegate::getOwnPropertyNames(object, exec, propertyNames, includeNonEnumerable); +} + +JSC::CallType DeclarativeObjectDelegate::getCallData(QScriptObject *object, JSC::CallData &callData) +{ + return QScriptObjectDelegate::getCallData(object, callData); +} + +JSC::ConstructType DeclarativeObjectDelegate::getConstructData(QScriptObject* object, JSC::ConstructData &constructData) +{ + return QScriptObjectDelegate::getConstructData(object, constructData); +} + +bool DeclarativeObjectDelegate::hasInstance(QScriptObject* object, JSC::ExecState *exec, + JSC::JSValue value, JSC::JSValue proto) +{ + return QScriptObjectDelegate::hasInstance(object, exec, value, proto); +} + +} // namespace QScript + +QT_END_NAMESPACE diff --git a/src/script/bridge/qscriptdeclarativeobject_p.h b/src/script/bridge/qscriptdeclarativeobject_p.h new file mode 100644 index 0000000..73e5527 --- /dev/null +++ b/src/script/bridge/qscriptdeclarativeobject_p.h @@ -0,0 +1,125 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the QtDeclarative module of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Nokia gives you certain additional +** rights. These rights are described in the Nokia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QSCRIPTDECLARATIVEOBJECT_P_H +#define QSCRIPTDECLARATIVEOBJECT_P_H + +// +// W A R N I N G +// ------------- +// +// This file is not part of the Qt API. It exists purely as an +// implementation detail. This header file may change from version to +// version without notice, or even be removed. +// +// We mean it. +// + +#include <QtCore/qobjectdefs.h> + +#include "config.h" +#include "qscriptobject_p.h" +#include "qscriptdeclarativeclass_p.h" + +QT_BEGIN_NAMESPACE + +class QScriptClass; + +class QScriptDeclarativeClassPrivate +{ +public: + QScriptDeclarativeClassPrivate() : engine(0), q_ptr(0), context(0) {} + + QScriptEngine *engine; + QScriptDeclarativeClass *q_ptr; + QScriptContext *context; + + static QScriptDeclarativeClassPrivate *get(QScriptDeclarativeClass *c) { + return c->d_ptr.data(); + } +}; + +namespace QScript +{ + +class DeclarativeObjectDelegate : public QScriptObjectDelegate +{ +public: + DeclarativeObjectDelegate(QScriptDeclarativeClass *c, QScriptDeclarativeClass::Object *o); + ~DeclarativeObjectDelegate(); + + virtual Type type() const; + + QScriptDeclarativeClass *scriptClass() const { return m_class; } + QScriptDeclarativeClass::Object *object() const { return m_object; } + + virtual bool getOwnPropertySlot(QScriptObject*, JSC::ExecState*, + const JSC::Identifier& propertyName, + JSC::PropertySlot&); + virtual void put(QScriptObject*, JSC::ExecState* exec, + const JSC::Identifier& propertyName, + JSC::JSValue, JSC::PutPropertySlot&); + virtual bool deleteProperty(QScriptObject*, JSC::ExecState*, + const JSC::Identifier& propertyName, + bool checkDontDelete = true); + virtual bool getPropertyAttributes(const QScriptObject*, JSC::ExecState*, + const JSC::Identifier&, + unsigned&) const; + virtual void getOwnPropertyNames(QScriptObject*, JSC::ExecState*, + JSC::PropertyNameArray&, + bool includeNonEnumerable = false); + + virtual JSC::CallType getCallData(QScriptObject*, JSC::CallData&); + virtual JSC::ConstructType getConstructData(QScriptObject*, JSC::ConstructData&); + + virtual bool hasInstance(QScriptObject*, JSC::ExecState*, + JSC::JSValue value, JSC::JSValue proto); + +private: + QScriptDeclarativeClass *m_class; + QScriptDeclarativeClass::Object *m_object; +}; + +} // namespace QScript + +QT_END_NAMESPACE + +#endif diff --git a/src/script/bridge/qscriptobject_p.h b/src/script/bridge/qscriptobject_p.h index 9dd9d88..0992eec 100644 --- a/src/script/bridge/qscriptobject_p.h +++ b/src/script/bridge/qscriptobject_p.h @@ -127,7 +127,8 @@ public: enum Type { QtObject, Variant, - ClassObject + ClassObject, + DeclarativeClassObject }; QScriptObjectDelegate(); diff --git a/src/sql/models/qsqlquerymodel.cpp b/src/sql/models/qsqlquerymodel.cpp index 1719239..319055e 100644 --- a/src/sql/models/qsqlquerymodel.cpp +++ b/src/sql/models/qsqlquerymodel.cpp @@ -314,6 +314,7 @@ void QSqlQueryModel::setQuery(const QSqlQuery &query) QSqlRecord newRec = query.record(); bool columnsChanged = (newRec != d->rec); bool hasQuerySize = query.driver()->hasFeature(QSqlDriver::QuerySize); + bool hasNewData = (newRec != QSqlRecord()) || !query.lastError().isValid(); if (d->colOffsets.size() != newRec.count() || columnsChanged) d->initColOffsets(newRec.count()); @@ -328,13 +329,13 @@ void QSqlQueryModel::setQuery(const QSqlQuery &query) d->error = QSqlError(); d->query = query; d->rec = newRec; - + if (mustClearModel) endRemoveRows(); - - d->atEnd = false; - if (columnsChanged) + d->atEnd = false; + + if (columnsChanged && hasNewData) reset(); if (!query.isActive() || query.isForwardOnly()) { diff --git a/src/src.pro b/src/src.pro index 7cab6c9..8dec49b 100644 --- a/src/src.pro +++ b/src/src.pro @@ -120,7 +120,7 @@ src_declarative.target = sub-declarative !symbian { # This creates a sub-src rule sub_src_target.CONFIG = recursive -sub_src_target.recurse = $$SRC_SUBDIRS +sub_src_target.recurse = $$TOOLS_SUBDIRS $$SRC_SUBDIRS sub_src_target.target = sub-src sub_src_target.recurse_target = QMAKE_EXTRA_TARGETS += sub_src_target diff --git a/src/tools/tools.pro b/src/tools/tools.pro index 7c8fb47..25527e3 100644 --- a/src/tools/tools.pro +++ b/src/tools/tools.pro @@ -20,10 +20,12 @@ src_tools_uic3.target = sub-uic3 src_tools_idc.subdir = $$QT_SOURCE_TREE/src/tools/idc src_tools_idc.target = sub-idc -# Set dependencies for each subdir -src_tools_moc.depends = src_tools_bootstrap -src_tools_rcc.depends = src_tools_bootstrap -src_tools_uic.depends = src_tools_bootstrap +!wince*:!symbian:!ordered { + # Set dependencies for each subdir + src_tools_moc.depends = src_tools_bootstrap + src_tools_rcc.depends = src_tools_bootstrap + src_tools_uic.depends = src_tools_bootstrap +} # Special handling, depending on type of project, if it used debug/release or only has one configuration EXTRA_DEBUG_TARGETS = |