From 2e501c4d45dddba3db2d8817a27380615c1ce8fd Mon Sep 17 00:00:00 2001 From: Justin McPherson Date: Mon, 8 Mar 2010 13:45:33 +1000 Subject: Refactor QSoundEffect. Reviewed-by: Dmytro Poplavskiy --- src/multimedia/effects/qsoundeffect.cpp | 76 +++------- src/multimedia/effects/qsoundeffect_p.h | 14 +- src/multimedia/effects/qsoundeffect_pulse_p.cpp | 183 ++++++++++------------- src/multimedia/effects/qsoundeffect_pulse_p.h | 39 +++-- src/multimedia/effects/qsoundeffect_qmedia_p.cpp | 99 +++++------- src/multimedia/effects/qsoundeffect_qmedia_p.h | 34 ++--- src/multimedia/effects/qsoundeffect_qsound_p.cpp | 153 ++++--------------- src/multimedia/effects/qsoundeffect_qsound_p.h | 55 ++----- src/multimedia/effects/wavedecoder_p.h | 4 +- 9 files changed, 217 insertions(+), 440 deletions(-) diff --git a/src/multimedia/effects/qsoundeffect.cpp b/src/multimedia/effects/qsoundeffect.cpp index 2694023..3ccca6e 100644 --- a/src/multimedia/effects/qsoundeffect.cpp +++ b/src/multimedia/effects/qsoundeffect.cpp @@ -39,9 +39,6 @@ ** ****************************************************************************/ -#include "qmediacontent.h" -#include "qmediaplayer.h" - #include "qsoundeffect_p.h" #if defined(QT_MULTIMEDIA_PULSEAUDIO) @@ -139,17 +136,12 @@ QT_BEGIN_NAMESPACE */ QSoundEffect::QSoundEffect(QObject *parent) : - QObject(parent), - m_loopCount(1), - m_vol(100), - m_muted(false), - m_runningCount(0) + QObject(parent) { d = new QSoundEffectPrivate(this); - connect(d, SIGNAL(volumeChanged(int)), SIGNAL(volumeChanged())); - connect(d, SIGNAL(mutedChanged(bool)), SIGNAL(mutedChanged())); - connect(d, SIGNAL(durationChanged(qint64)), SIGNAL(durationChanged())); - connect(d, SIGNAL(stateChanged(QMediaPlayer::State)), SLOT(repeat())); + connect(d, SIGNAL(volumeChanged()), SIGNAL(volumeChanged())); + connect(d, SIGNAL(mutedChanged()), SIGNAL(mutedChanged())); + connect(d, SIGNAL(durationChanged()), SIGNAL(durationChanged())); } QSoundEffect::~QSoundEffect() @@ -159,97 +151,69 @@ QSoundEffect::~QSoundEffect() QUrl QSoundEffect::source() const { - return d != 0 ? d->media().canonicalUrl() : QUrl(); + return d->source(); } void QSoundEffect::setSource(const QUrl &url) { - if (d != 0 && d->media().canonicalUrl() == url) + if (d->source() == url) return; - d->setVolume(m_vol); - d->setMuted(m_muted); - d->setMedia(url); - - if (url.isEmpty()) - return; + d->setSource(url); emit sourceChanged(); } int QSoundEffect::loopCount() const { - return m_loopCount; + return d->loopCount(); } void QSoundEffect::setLoopCount(int loopCount) { - if (m_loopCount == loopCount) + if (d->loopCount() == loopCount) return; - m_loopCount = loopCount; + d->setLoopCount(loopCount); emit loopCountChanged(); } int QSoundEffect::volume() const { - return d != 0 ? d->volume() : m_vol; + return d->volume(); } void QSoundEffect::setVolume(int volume) { - if (m_vol == volume) + if (d->volume() == volume) return; - m_vol = volume; - if (d != 0) - d->setVolume(volume); - else - emit volumeChanged(); + d->setVolume(volume); + emit volumeChanged(); } bool QSoundEffect::isMuted() const { - return d != 0 ? d->isMuted() : m_muted; + return d->isMuted(); } void QSoundEffect::setMuted(bool muted) { - if (m_muted == muted) + if (d->isMuted() == muted) return; - m_muted = muted; - if (d != 0) - d->setMuted(muted); - else - emit mutedChanged(); + d->setMuted(muted); + emit mutedChanged(); } int QSoundEffect::duration() const { - return d != 0 ? d->duration() : 0; + return d->duration(); } void QSoundEffect::play() { - m_runningCount = 0; - - if (d != 0) - d->play(); -} - -void QSoundEffect::stop() -{ - if (d != 0) - d->stop(); -} - -void QSoundEffect::repeat() -{ - if (d->state() == QMediaPlayer::StoppedState) { - if (++m_runningCount < m_loopCount) - d->play(); - } + d->play(); } QT_END_NAMESPACE diff --git a/src/multimedia/effects/qsoundeffect_p.h b/src/multimedia/effects/qsoundeffect_p.h index c5554bf..29cb16c 100644 --- a/src/multimedia/effects/qsoundeffect_p.h +++ b/src/multimedia/effects/qsoundeffect_p.h @@ -90,28 +90,18 @@ public: int duration() const; -signals: +Q_SIGNALS: void sourceChanged(); void loopCountChanged(); void volumeChanged(); void mutedChanged(); void durationChanged(); -public slots: +public Q_SLOTS: void play(); - void stop(); - -private slots: - void repeat(); private: Q_DISABLE_COPY(QSoundEffect) - - int m_loopCount; - int m_vol; - bool m_muted; - int m_runningCount; - QSoundEffectPrivate* d; }; diff --git a/src/multimedia/effects/qsoundeffect_pulse_p.cpp b/src/multimedia/effects/qsoundeffect_pulse_p.cpp index d99bf4b..aa5a14d 100644 --- a/src/multimedia/effects/qsoundeffect_pulse_p.cpp +++ b/src/multimedia/effects/qsoundeffect_pulse_p.cpp @@ -55,10 +55,6 @@ #include #include -#include "qmediacontent.h" -#include "qmediaplayer.h" -#include "qsoundeffect_p.h" - #include "wavedecoder_p.h" #include "qsoundeffect_pulse_p.h" @@ -240,11 +236,12 @@ QSoundEffectPrivate::QSoundEffectPrivate(QObject* parent): QObject(parent), m_muted(false), m_playQueued(false), - m_vol(100), + m_sampleLoaded(false), + m_volume(100), m_duration(0), m_dataUploaded(0), - m_state(QMediaPlayer::StoppedState), - m_status(QMediaPlayer::NoMedia), + m_loopCount(1), + m_runningCount(0), m_reply(0), m_stream(0), m_networkAccessManager(0) @@ -257,76 +254,53 @@ QSoundEffectPrivate::~QSoundEffectPrivate() unloadSample(); } -qint64 QSoundEffectPrivate::duration() const +QUrl QSoundEffectPrivate::source() const { - return m_duration; + return m_source; } -int QSoundEffectPrivate::volume() const +void QSoundEffectPrivate::setSource(const QUrl &url) { - return m_vol; -} + if (url.isEmpty()) { + m_source = QUrl(); + unloadSample(); + return; + } -bool QSoundEffectPrivate::isMuted() const -{ - return m_muted; -} + m_source = url; -QMediaContent QSoundEffectPrivate::media() const -{ - return m_media; + if (m_networkAccessManager == 0) + m_networkAccessManager = new QNetworkAccessManager(this); + + m_stream = m_networkAccessManager->get(QNetworkRequest(m_source)); + + unloadSample(); + loadSample(); } -QMediaPlayer::State QSoundEffectPrivate::state() const +int QSoundEffectPrivate::loopCount() const { - return m_state; + return m_loopCount; } -QMediaPlayer::MediaStatus QSoundEffectPrivate::mediaStatus() const +void QSoundEffectPrivate::setLoopCount(int loopCount) { - return m_status; + m_loopCount = loopCount; } -void QSoundEffectPrivate::play() +int QSoundEffectPrivate::volume() const { - if (m_status == QMediaPlayer::LoadingMedia) { - m_playQueued = true; - return; - } - - if (m_status != QMediaPlayer::BufferedMedia || - m_state == QMediaPlayer::PlayingState) - return; - - pa_volume_t m_vol = PA_VOLUME_NORM; - - daemon()->lock(); -#if defined(Q_WS_MAEMO_5) - m_vol = PA_VOLUME_NORM/100*((daemon()->volume()+m_vol)/2); -#endif - pa_operation_unref( - pa_context_play_sample(daemon()->context(), - m_name.constData(), - 0, - m_vol, - play_callback, - this) - ); - daemon()->unlock(); - - m_playbackTime.start(); - - emit stateChanged(m_state = QMediaPlayer::PlayingState); + return m_volume; } -void QSoundEffectPrivate::stop() +void QSoundEffectPrivate::setVolume(int volume) { - emit stateChanged(m_state = QMediaPlayer::StoppedState); + m_volume = volume; } -void QSoundEffectPrivate::setVolume(int volume) +bool QSoundEffectPrivate::isMuted() const { - m_vol = volume; + return m_muted; } void QSoundEffectPrivate::setMuted(bool muted) @@ -334,34 +308,28 @@ void QSoundEffectPrivate::setMuted(bool muted) m_muted = muted; } -void QSoundEffectPrivate::setMedia(const QMediaContent &media) +qint64 QSoundEffectPrivate::duration() const { - if (media.isNull()) { - m_media = QMediaContent(); - unloadSample(); + return m_duration; +} + +void QSoundEffectPrivate::play() +{ + if (!m_sampleLoaded) { + m_playQueued = true; return; } - if (m_media == media) - return; - m_media = media; - if (m_networkAccessManager == 0) - m_networkAccessManager = new QNetworkAccessManager(this); - - m_stream = m_networkAccessManager->get(QNetworkRequest(m_media.canonicalUrl())); - - unloadSample(); - loadSample(); + m_runningCount += m_loopCount; - emit mediaChanged(m_media); + playSample(); } void QSoundEffectPrivate::decoderReady() { if (m_waveDecoder->size() >= PA_SCACHE_ENTRY_SIZE_MAX) { - m_status = QMediaPlayer::InvalidMedia; - emit mediaStatusChanged(m_status); - qWarning("QtPulseAudio: attempting to load to large a sample"); + m_waveDecoder->deleteLater(); + qWarning("QSoundEffect(pulseaudio): Attempting to load to large a sample"); return; } @@ -380,52 +348,65 @@ void QSoundEffectPrivate::decoderReady() void QSoundEffectPrivate::decoderError() { - emit mediaStatusChanged(m_status = QMediaPlayer::InvalidMedia); + qWarning("QSoundEffect(pulseaudio): Error decoding source"); } void QSoundEffectPrivate::checkPlayTime() { int elapsed = m_playbackTime.elapsed(); - if (elapsed >= m_duration) { - m_state = QMediaPlayer::StoppedState; - emit stateChanged(m_state); - } - else + if (elapsed < m_duration) startTimer(m_duration - elapsed); } void QSoundEffectPrivate::loadSample() { + m_sampleLoaded = false; + m_dataUploaded = 0; m_waveDecoder = new WaveDecoder(m_stream); connect(m_waveDecoder, SIGNAL(formatKnown()), SLOT(decoderReady())); connect(m_waveDecoder, SIGNAL(invalidFormat()), SLOT(decoderError())); - - m_status = QMediaPlayer::LoadingMedia; - emit mediaStatusChanged(m_status); } void QSoundEffectPrivate::unloadSample() { - if (m_status != QMediaPlayer::BufferedMedia) + if (!m_sampleLoaded) return; - m_status = QMediaPlayer::NoMedia; - daemon()->lock(); pa_context_remove_sample(daemon()->context(), m_name.constData(), NULL, NULL); daemon()->unlock(); m_duration = 0; m_dataUploaded = 0; + m_sampleLoaded = false; +} + +void QSoundEffectPrivate::playSample() +{ + pa_volume_t volume = PA_VOLUME_NORM; + + daemon()->lock(); +#ifdef Q_WS_MAEMO_5 + volume = PA_VOLUME_NORM / 100 * ((daemon()->volume() + m_volume) / 2); +#endif + pa_operation_unref( + pa_context_play_sample(daemon()->context(), + m_name.constData(), + 0, + volume, + play_callback, + this) + ); + daemon()->unlock(); + + m_playbackTime.start(); } void QSoundEffectPrivate::timerEvent(QTimerEvent *event) { - if (m_state == QMediaPlayer::PlayingState) { - m_state = QMediaPlayer::StoppedState; - emit stateChanged(m_state); - } + if (m_runningCount > 0) + playSample(); killTimer(event->timerId()); } @@ -456,15 +437,12 @@ void QSoundEffectPrivate::stream_write_callback(pa_stream *s, size_t length, voi pa_stream_finish_upload(s); self->m_duration = self->m_waveDecoder->duration(); - emit self->durationChanged(self->m_duration); - - self->m_status = QMediaPlayer::BufferedMedia; - emit self->mediaStatusChanged(self->m_status); + emit self->durationChanged(); self->m_waveDecoder->deleteLater(); - if (!self->m_media.isNull()) - self->m_stream->deleteLater(); + self->m_stream->deleteLater(); + self->m_sampleLoaded = true; if (self->m_playQueued) { self->m_playQueued = false; QMetaObject::invokeMethod(self, "play"); @@ -474,8 +452,6 @@ void QSoundEffectPrivate::stream_write_callback(pa_stream *s, size_t length, voi void QSoundEffectPrivate::stream_state_callback(pa_stream *s, void *userdata) { - QSoundEffectPrivate *self = reinterpret_cast(userdata); - switch (pa_stream_get_state(s)) { case PA_STREAM_CREATING: case PA_STREAM_READY: @@ -484,8 +460,7 @@ void QSoundEffectPrivate::stream_state_callback(pa_stream *s, void *userdata) case PA_STREAM_FAILED: default: - self->m_status = QMediaPlayer::InvalidMedia; - emit self->mediaStatusChanged(self->m_status); + qWarning("QSoundEffect(pulseaudio): Error in pulse audio stream"); break; } } @@ -496,14 +471,10 @@ void QSoundEffectPrivate::play_callback(pa_context *c, int success, void *userda QSoundEffectPrivate *self = reinterpret_cast(userdata); - if (success == 1) + if (success == 1) { + self->m_runningCount--; QMetaObject::invokeMethod(self, "checkPlayTime", Qt::QueuedConnection); - else { - self->m_state = QMediaPlayer::StoppedState; - emit self->stateChanged(self->m_state); } } QT_END_NAMESPACE - - diff --git a/src/multimedia/effects/qsoundeffect_pulse_p.h b/src/multimedia/effects/qsoundeffect_pulse_p.h index 247f8a3..7353e4f 100644 --- a/src/multimedia/effects/qsoundeffect_pulse_p.h +++ b/src/multimedia/effects/qsoundeffect_pulse_p.h @@ -77,30 +77,25 @@ public: explicit QSoundEffectPrivate(QObject* parent); ~QSoundEffectPrivate(); - qint64 duration() const; + QUrl source() const; + void setSource(const QUrl &url); + int loopCount() const; + void setLoopCount(int loopCount); int volume() const; + void setVolume(int volume); bool isMuted() const; - QMediaContent media() const; - QMediaPlayer::State state() const; - QMediaPlayer::MediaStatus mediaStatus() const; + void setMuted(bool muted); + qint64 duration() const; public Q_SLOTS: void play(); - void stop(); - void setVolume(int volume); - void setMuted(bool muted); - void setMedia(const QMediaContent &media); Q_SIGNALS: - void mediaChanged(const QMediaContent &media); - void mediaStatusChanged(QMediaPlayer::MediaStatus status); - void stateChanged(QMediaPlayer::State newState); - void durationChanged(qint64 duration); - void volumeChanged(int volume); - void mutedChanged(bool muted); - void error(QMediaPlayer::Error error); - -private slots: + void durationChanged(); + void volumeChanged(); + void mutedChanged(); + +private Q_SLOTS: void decoderReady(); void decoderError(); void checkPlayTime(); @@ -108,6 +103,7 @@ private slots: private: void loadSample(); void unloadSample(); + void playSample(); void timerEvent(QTimerEvent *event); @@ -117,14 +113,15 @@ private: bool m_muted; bool m_playQueued; - int m_vol; + bool m_sampleLoaded; + int m_volume; int m_duration; int m_dataUploaded; + int m_loopCount; + int m_runningCount; + QUrl m_source; QTime m_playbackTime; - QMediaPlayer::State m_state; - QMediaPlayer::MediaStatus m_status; QByteArray m_name; - QMediaContent m_media; QNetworkReply *m_reply; WaveDecoder *m_waveDecoder; QIODevice *m_stream; diff --git a/src/multimedia/effects/qsoundeffect_qmedia_p.cpp b/src/multimedia/effects/qsoundeffect_qmedia_p.cpp index 48fb257..e670a36 100644 --- a/src/multimedia/effects/qsoundeffect_qmedia_p.cpp +++ b/src/multimedia/effects/qsoundeffect_qmedia_p.cpp @@ -50,117 +50,90 @@ // We mean it. // -#include +#include "qsoundeffect_qmedia_p.h" -#include "qmediacontent.h" -#include "qmediaplayer.h" +#include -#include "qsoundeffect_p.h" -#include "qsoundeffect_qmedia_p.h" +#include +#include QT_BEGIN_NAMESPACE QSoundEffectPrivate::QSoundEffectPrivate(QObject* parent): QObject(parent), - m_muted(false), - m_vol(100), + m_loopCount(1), + m_runningCount(0), m_player(0) { + m_player = new QMediaPlayer(this, QMediaPlayer::LowLatency); + connect(m_player, SIGNAL(volumeChanged(int)), SIGNAL(volumeChanged())); + connect(m_player, SIGNAL(mutedChanged(bool)), SIGNAL(mutedChanged())); + connect(m_player, SIGNAL(durationChanged(qint64)), SIGNAL(durationChanged())); + connect(m_player, SIGNAL(stateChanged(QMediaPlayer::State)), SLOT(stateChanged(QMediaPlayer::State))); } QSoundEffectPrivate::~QSoundEffectPrivate() { - if (m_player) delete m_player; } -qint64 QSoundEffectPrivate::duration() const +QUrl QSoundEffectPrivate::source() const { - if (m_player) return m_player->duration(); - - return 0; + return m_player->media().canonicalUrl(); } -int QSoundEffectPrivate::volume() const +void QSoundEffectPrivate::setSource(const QUrl &url) { - if (m_player) return m_player->volume(); - - return m_vol; + m_player->setMedia(url); } -bool QSoundEffectPrivate::isMuted() const +int QSoundEffectPrivate::loopCount() const { - if (m_player) return m_player->isMuted(); - - return m_muted; + return m_loopCount; } -QMediaContent QSoundEffectPrivate::media() const +void QSoundEffectPrivate::setLoopCount(int loopCount) { - if (m_player) return m_player->media(); - - return QMediaContent(); + m_loopCount = loopCount; } -QMediaPlayer::State QSoundEffectPrivate::state() const +int QSoundEffectPrivate::volume() const { - if (m_player) return m_player->state(); - - return QMediaPlayer::StoppedState; + return m_player->volume(); } -QMediaPlayer::MediaStatus QSoundEffectPrivate::mediaStatus() const +void QSoundEffectPrivate::setVolume(int volume) { - if (m_player) return m_player->mediaStatus(); - - return QMediaPlayer::UnknownMediaStatus; + m_player->setVolume(volume); } -void QSoundEffectPrivate::play() +bool QSoundEffectPrivate::isMuted() const { - if (m_player && !m_player->isMuted()) - m_player->play(); + return m_player->isMuted(); } -void QSoundEffectPrivate::stop() +void QSoundEffectPrivate::setMuted(bool muted) { - if (m_player) - m_player->stop(); + m_player->setMuted(muted); } -void QSoundEffectPrivate::setVolume(int volume) +int QSoundEffectPrivate::duration() const { - m_vol = volume; - - if (m_player) - m_player->setVolume(volume); + return m_player->duration(); } -void QSoundEffectPrivate::setMuted(bool muted) +void QSoundEffectPrivate::play() { - m_muted = muted; - - if (m_player) - m_player->setMuted(muted); + m_runningCount += m_loopCount; + m_player->play(); } -void QSoundEffectPrivate::setMedia(const QMediaContent &media) +void QSoundEffectPrivate::stateChanged(QMediaPlayer::State state) { - if (media.isNull()) - return; - - if (m_player == 0) { - m_player = new QMediaPlayer(this, QMediaPlayer::LowLatency); - m_player->setVolume(m_vol); - m_player->setMuted(m_muted); - - connect(m_player, SIGNAL(volumeChanged(int)), SIGNAL(volumeChanged(int))); - connect(m_player, SIGNAL(mutedChanged(bool)), SIGNAL(mutedChanged(bool))); - connect(m_player, SIGNAL(durationChanged(qint64)), SIGNAL(durationChanged(qint64))); - connect(m_player, SIGNAL(stateChanged(QMediaPlayer::State)), SIGNAL(stateChanged(QMediaPlayer::State))); + if (state == QMediaPlayer::StoppedState) { + if (--m_runningCount > 0) + m_player->play(); } - - m_player->setMedia(media.canonicalUrl()); } QT_END_NAMESPACE diff --git a/src/multimedia/effects/qsoundeffect_qmedia_p.h b/src/multimedia/effects/qsoundeffect_qmedia_p.h index 8267f79..73682ea 100644 --- a/src/multimedia/effects/qsoundeffect_qmedia_p.h +++ b/src/multimedia/effects/qsoundeffect_qmedia_p.h @@ -57,14 +57,12 @@ #include #include #include -#include "qsoundeffect_p.h" QT_BEGIN_HEADER QT_BEGIN_NAMESPACE -class WaveDecoder; class QSoundEffectPrivate : public QObject { @@ -73,32 +71,30 @@ public: explicit QSoundEffectPrivate(QObject* parent); ~QSoundEffectPrivate(); - qint64 duration() const; + QUrl source() const; + void setSource(const QUrl &url); + int loopCount() const; + void setLoopCount(int loopCount); int volume() const; + void setVolume(int volume); bool isMuted() const; - QMediaContent media() const; - QMediaPlayer::State state() const; - QMediaPlayer::MediaStatus mediaStatus() const; + void setMuted(bool muted); + int duration() const; public Q_SLOTS: void play(); - void stop(); - void setVolume(int volume); - void setMuted(bool muted); - void setMedia(const QMediaContent &media); Q_SIGNALS: - void mediaChanged(const QMediaContent &media); - void mediaStatusChanged(QMediaPlayer::MediaStatus status); - void stateChanged(QMediaPlayer::State newState); - void durationChanged(qint64 duration); - void volumeChanged(int volume); - void mutedChanged(bool muted); - void error(QMediaPlayer::Error error); + void durationChanged(); + void volumeChanged(); + void mutedChanged(); + +private Q_SLOTS: + void stateChanged(QMediaPlayer::State); private: - bool m_muted; - int m_vol; + int m_loopCount; + int m_runningCount; QMediaPlayer *m_player; }; diff --git a/src/multimedia/effects/qsoundeffect_qsound_p.cpp b/src/multimedia/effects/qsoundeffect_qsound_p.cpp index df160a9..e6e889e 100644 --- a/src/multimedia/effects/qsoundeffect_qsound_p.cpp +++ b/src/multimedia/effects/qsoundeffect_qsound_p.cpp @@ -50,102 +50,72 @@ // We mean it. // +#include "qsoundeffect_qsound_p.h" + #include -#include -#include #include -#include -#include -#include "qmediacontent.h" -#include "qmediaplayer.h" -#include "qsoundeffect_p.h" - -#include "wavedecoder_p.h" - -#include "qsoundeffect_qsound_p.h" QT_BEGIN_NAMESPACE QSoundEffectPrivate::QSoundEffectPrivate(QObject* parent): QObject(parent), - m_queued(false), m_muted(false), - m_state(QMediaPlayer::StoppedState), - m_status(QMediaPlayer::NoMedia), - m_file(0), + m_loopCount(1), + m_volume(100), m_sound(0) { - m_timer = new QTimer(this); - connect(m_timer,SIGNAL(timeout()),SLOT(checkPlayTime())); - m_media = QMediaContent(); } QSoundEffectPrivate::~QSoundEffectPrivate() { - if (m_sound) delete m_sound; - if (m_waveDecoder) delete m_waveDecoder; - m_file->close(); } -qint64 QSoundEffectPrivate::duration() const +QUrl QSoundEffectPrivate::source() const { - if (m_waveDecoder) - return m_waveDecoder->size(); - - return 0; + return m_source; } -int QSoundEffectPrivate::volume() const +void QSoundEffectPrivate::setSource(const QUrl &url) { - return 100; -} + if (url.isEmpty() || url.scheme() != QLatin1String("file")) { + m_source = QUrl(); + return; + } -bool QSoundEffectPrivate::isMuted() const -{ - return m_muted; -} + if (m_sound != 0) + delete m_sound; -QMediaContent QSoundEffectPrivate::media() const -{ - return m_media; + m_source = url; + m_sound = new QSound(m_source.toLocalFile(), this); + m_sound->setLoops(m_loopCount); } -QMediaPlayer::State QSoundEffectPrivate::state() const +int QSoundEffectPrivate::loopCount() const { - return m_state; + return m_loopCount; } -QMediaPlayer::MediaStatus QSoundEffectPrivate::mediaStatus() const +void QSoundEffectPrivate::setLoopCount(int lc) { - return m_status; + m_loopCount = lc; + if (m_sound) + m_sound->setLoops(lc); } -void QSoundEffectPrivate::play() +int QSoundEffectPrivate::volume() const { - if (m_sound && !m_muted) { - m_queued = false; - m_timer->start(20); - m_playbackTime.start(); - m_sound->play(); - emit stateChanged(m_state = QMediaPlayer::PlayingState); - } else if (m_status == QMediaPlayer::LoadingMedia) - m_queued = true; + return m_volume; } -void QSoundEffectPrivate::stop() +void QSoundEffectPrivate::setVolume(int v) { - m_timer->stop(); - - if (m_sound) { - m_sound->stop(); - emit stateChanged(m_state = QMediaPlayer::StoppedState); - } + m_volume = v; } -void QSoundEffectPrivate::setVolume(int volume) +bool QSoundEffectPrivate::isMuted() const { - Q_UNUSED(volume) + return m_muted; } void QSoundEffectPrivate::setMuted(bool muted) @@ -153,73 +123,14 @@ void QSoundEffectPrivate::setMuted(bool muted) m_muted = muted; } -void QSoundEffectPrivate::setMedia(const QMediaContent &media) -{ - m_queued = false; - - if (media.isNull() || media.canonicalUrl().scheme() != QLatin1String("file")) { - m_media = QMediaContent(); - return; - } - if (m_media == media) - return; - - m_media = media; - m_file = new QFile(m_media.canonicalUrl().toLocalFile()); - m_file->open(QIODevice::ReadOnly|QIODevice::Unbuffered); - - unloadSample(); - loadSample(); - - emit mediaChanged(m_media); -} - -void QSoundEffectPrivate::decoderReady() -{ - m_file->close(); - m_sound = new QSound(m_media.canonicalUrl().toLocalFile()); - emit mediaStatusChanged(m_status = QMediaPlayer::LoadedMedia); - - if (m_queued) - play(); -} - -void QSoundEffectPrivate::decoderError() -{ - m_file->close(); - emit mediaStatusChanged(m_status = QMediaPlayer::InvalidMedia); -} - -void QSoundEffectPrivate::checkPlayTime() +int QSoundEffectPrivate::duration() const { - if (m_sound->isFinished()) { - m_timer->stop(); - m_state = QMediaPlayer::StoppedState; - emit stateChanged(m_state); - } + return 1000; } -void QSoundEffectPrivate::loadSample() -{ - m_waveDecoder = new WaveDecoder(m_file); - connect(m_waveDecoder, SIGNAL(formatKnown()), SLOT(decoderReady())); - connect(m_waveDecoder, SIGNAL(invalidFormat()), SLOT(decoderError())); - - m_status = QMediaPlayer::LoadingMedia; - emit mediaStatusChanged(m_status); -} - -void QSoundEffectPrivate::unloadSample() +void QSoundEffectPrivate::play() { - if (m_sound == 0) - return; - - m_status = QMediaPlayer::NoMedia; - - if (m_sound) - delete m_sound; - - m_sound = 0; + m_sound->play(); } QT_END_NAMESPACE diff --git a/src/multimedia/effects/qsoundeffect_qsound_p.h b/src/multimedia/effects/qsoundeffect_qsound_p.h index 45c0888..377c8a7 100644 --- a/src/multimedia/effects/qsoundeffect_qsound_p.h +++ b/src/multimedia/effects/qsoundeffect_qsound_p.h @@ -55,20 +55,14 @@ #include -#include -#include - -#include "qsoundeffect_p.h" +#include QT_BEGIN_HEADER QT_BEGIN_NAMESPACE -class QTimer; class QSound; -class QFile; -class WaveDecoder; class QSoundEffectPrivate : public QObject { @@ -77,49 +71,30 @@ public: explicit QSoundEffectPrivate(QObject* parent); ~QSoundEffectPrivate(); - qint64 duration() const; + QUrl source() const; + void setSource(const QUrl &url); + int loopCount() const; + void setLoopCount(int loopCount); int volume() const; + void setVolume(int volume); bool isMuted() const; - QMediaContent media() const; - QMediaPlayer::State state() const; - QMediaPlayer::MediaStatus mediaStatus() const; + void setMuted(bool muted); + int duration() const; public Q_SLOTS: void play(); - void stop(); - void setVolume(int volume); - void setMuted(bool muted); - void setMedia(const QMediaContent &media); Q_SIGNALS: - void mediaChanged(const QMediaContent &media); - void mediaStatusChanged(QMediaPlayer::MediaStatus status); - void stateChanged(QMediaPlayer::State newState); - void durationChanged(qint64 duration); - void volumeChanged(int volume); - void mutedChanged(bool muted); - void error(QMediaPlayer::Error error); - -private slots: - void decoderReady(); - void decoderError(); - void checkPlayTime(); + void durationChanged(); + void volumeChanged(); + void mutedChanged(); private: - void loadSample(); - void unloadSample(); - - bool m_queued; - bool m_muted; - QTime m_playbackTime; - QMediaPlayer::State m_state; - QMediaPlayer::MediaStatus m_status; - QFile *m_file; - QByteArray m_name; - QMediaContent m_media; - WaveDecoder *m_waveDecoder; + bool m_muted; + int m_loopCount; + int m_volume; QSound *m_sound; - QTimer *m_timer; + QUrl m_source; }; QT_END_NAMESPACE diff --git a/src/multimedia/effects/wavedecoder_p.h b/src/multimedia/effects/wavedecoder_p.h index fa1f77e..c1892bb 100644 --- a/src/multimedia/effects/wavedecoder_p.h +++ b/src/multimedia/effects/wavedecoder_p.h @@ -77,11 +77,11 @@ public: bool isSequential() const; qint64 bytesAvailable() const; -signals: +Q_SIGNALS: void formatKnown(); void invalidFormat(); -private slots: +private Q_SLOTS: void handleData(); private: -- cgit v0.12 From 7a3a25e9a1b7d4925b12297c91b37a2aba03e277 Mon Sep 17 00:00:00 2001 From: Justin McPherson Date: Mon, 8 Mar 2010 15:02:54 +1000 Subject: Fix effects.pri. Reviewed-by: Dmytro Poplavskiy --- src/multimedia/effects/effects.pri | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/multimedia/effects/effects.pri b/src/multimedia/effects/effects.pri index ff762e8..be2b696 100644 --- a/src/multimedia/effects/effects.pri +++ b/src/multimedia/effects/effects.pri @@ -1,7 +1,7 @@ -unix { - unix:contains(QT_CONFIG, pulseaudio) { +unix:!mac { + contains(QT_CONFIG, pulseaudio) { DEFINES += QT_MULTIMEDIA_PULSEAUDIO HEADERS += $$PWD/qsoundeffect_pulse_p.h SOURCES += $$PWD/qsoundeffect_pulse_p.cpp -- cgit v0.12 From aa5df3c136a5c01d505d3005790907e1bccc4e26 Mon Sep 17 00:00:00 2001 From: Justin McPherson Date: Mon, 8 Mar 2010 15:03:40 +1000 Subject: Remove duration property from QSoundEffect. Reviewed-by: Dmytro Poplavskiy --- src/multimedia/effects/qsoundeffect.cpp | 17 ----------------- src/multimedia/effects/qsoundeffect_p.h | 4 ---- src/multimedia/effects/qsoundeffect_pulse_p.cpp | 6 ------ src/multimedia/effects/qsoundeffect_pulse_p.h | 2 -- src/multimedia/effects/qsoundeffect_qmedia_p.cpp | 6 ------ src/multimedia/effects/qsoundeffect_qmedia_p.h | 2 -- src/multimedia/effects/qsoundeffect_qsound_p.cpp | 5 ----- src/multimedia/effects/qsoundeffect_qsound_p.h | 2 -- 8 files changed, 44 deletions(-) diff --git a/src/multimedia/effects/qsoundeffect.cpp b/src/multimedia/effects/qsoundeffect.cpp index 3ccca6e..f64d9ee 100644 --- a/src/multimedia/effects/qsoundeffect.cpp +++ b/src/multimedia/effects/qsoundeffect.cpp @@ -100,12 +100,6 @@ QT_BEGIN_NAMESPACE */ /*! - \qmlproperty int SoundEffect::duration - - This property holds the duration in milliseconds of the current source audio. -*/ - -/*! \qmlsignal SoundEffect::sourceChanged() This handler is called when the source has changed. @@ -129,11 +123,6 @@ QT_BEGIN_NAMESPACE This handler is called when the mute state has changed. */ -/*! - \qmlsignal SoundEffect::durationChanged() - - This handler is called when the duration has changed. -*/ QSoundEffect::QSoundEffect(QObject *parent) : QObject(parent) @@ -141,7 +130,6 @@ QSoundEffect::QSoundEffect(QObject *parent) : d = new QSoundEffectPrivate(this); connect(d, SIGNAL(volumeChanged()), SIGNAL(volumeChanged())); connect(d, SIGNAL(mutedChanged()), SIGNAL(mutedChanged())); - connect(d, SIGNAL(durationChanged()), SIGNAL(durationChanged())); } QSoundEffect::~QSoundEffect() @@ -206,11 +194,6 @@ void QSoundEffect::setMuted(bool muted) emit mutedChanged(); } -int QSoundEffect::duration() const -{ - return d->duration(); -} - void QSoundEffect::play() { d->play(); diff --git a/src/multimedia/effects/qsoundeffect_p.h b/src/multimedia/effects/qsoundeffect_p.h index 29cb16c..ec6a2f7 100644 --- a/src/multimedia/effects/qsoundeffect_p.h +++ b/src/multimedia/effects/qsoundeffect_p.h @@ -70,7 +70,6 @@ class Q_MULTIMEDIA_EXPORT QSoundEffect : public QObject Q_PROPERTY(int loopCount READ loopCount WRITE setLoopCount NOTIFY loopCountChanged) Q_PROPERTY(int volume READ volume WRITE setVolume NOTIFY volumeChanged) Q_PROPERTY(bool muted READ isMuted WRITE setMuted NOTIFY mutedChanged) - Q_PROPERTY(int duration READ duration NOTIFY durationChanged) public: explicit QSoundEffect(QObject *parent = 0); @@ -88,14 +87,11 @@ public: bool isMuted() const; void setMuted(bool muted); - int duration() const; - Q_SIGNALS: void sourceChanged(); void loopCountChanged(); void volumeChanged(); void mutedChanged(); - void durationChanged(); public Q_SLOTS: void play(); diff --git a/src/multimedia/effects/qsoundeffect_pulse_p.cpp b/src/multimedia/effects/qsoundeffect_pulse_p.cpp index aa5a14d..c322722 100644 --- a/src/multimedia/effects/qsoundeffect_pulse_p.cpp +++ b/src/multimedia/effects/qsoundeffect_pulse_p.cpp @@ -308,11 +308,6 @@ void QSoundEffectPrivate::setMuted(bool muted) m_muted = muted; } -qint64 QSoundEffectPrivate::duration() const -{ - return m_duration; -} - void QSoundEffectPrivate::play() { if (!m_sampleLoaded) { @@ -437,7 +432,6 @@ void QSoundEffectPrivate::stream_write_callback(pa_stream *s, size_t length, voi pa_stream_finish_upload(s); self->m_duration = self->m_waveDecoder->duration(); - emit self->durationChanged(); self->m_waveDecoder->deleteLater(); self->m_stream->deleteLater(); diff --git a/src/multimedia/effects/qsoundeffect_pulse_p.h b/src/multimedia/effects/qsoundeffect_pulse_p.h index 7353e4f..3aed018 100644 --- a/src/multimedia/effects/qsoundeffect_pulse_p.h +++ b/src/multimedia/effects/qsoundeffect_pulse_p.h @@ -85,13 +85,11 @@ public: void setVolume(int volume); bool isMuted() const; void setMuted(bool muted); - qint64 duration() const; public Q_SLOTS: void play(); Q_SIGNALS: - void durationChanged(); void volumeChanged(); void mutedChanged(); diff --git a/src/multimedia/effects/qsoundeffect_qmedia_p.cpp b/src/multimedia/effects/qsoundeffect_qmedia_p.cpp index e670a36..43ba22f 100644 --- a/src/multimedia/effects/qsoundeffect_qmedia_p.cpp +++ b/src/multimedia/effects/qsoundeffect_qmedia_p.cpp @@ -69,7 +69,6 @@ QSoundEffectPrivate::QSoundEffectPrivate(QObject* parent): m_player = new QMediaPlayer(this, QMediaPlayer::LowLatency); connect(m_player, SIGNAL(volumeChanged(int)), SIGNAL(volumeChanged())); connect(m_player, SIGNAL(mutedChanged(bool)), SIGNAL(mutedChanged())); - connect(m_player, SIGNAL(durationChanged(qint64)), SIGNAL(durationChanged())); connect(m_player, SIGNAL(stateChanged(QMediaPlayer::State)), SLOT(stateChanged(QMediaPlayer::State))); } @@ -117,11 +116,6 @@ void QSoundEffectPrivate::setMuted(bool muted) m_player->setMuted(muted); } -int QSoundEffectPrivate::duration() const -{ - return m_player->duration(); -} - void QSoundEffectPrivate::play() { m_runningCount += m_loopCount; diff --git a/src/multimedia/effects/qsoundeffect_qmedia_p.h b/src/multimedia/effects/qsoundeffect_qmedia_p.h index 73682ea..6ad9d79 100644 --- a/src/multimedia/effects/qsoundeffect_qmedia_p.h +++ b/src/multimedia/effects/qsoundeffect_qmedia_p.h @@ -79,13 +79,11 @@ public: void setVolume(int volume); bool isMuted() const; void setMuted(bool muted); - int duration() const; public Q_SLOTS: void play(); Q_SIGNALS: - void durationChanged(); void volumeChanged(); void mutedChanged(); diff --git a/src/multimedia/effects/qsoundeffect_qsound_p.cpp b/src/multimedia/effects/qsoundeffect_qsound_p.cpp index e6e889e..ff30f67 100644 --- a/src/multimedia/effects/qsoundeffect_qsound_p.cpp +++ b/src/multimedia/effects/qsoundeffect_qsound_p.cpp @@ -123,11 +123,6 @@ void QSoundEffectPrivate::setMuted(bool muted) m_muted = muted; } -int QSoundEffectPrivate::duration() const -{ - return 1000; -} - void QSoundEffectPrivate::play() { m_sound->play(); diff --git a/src/multimedia/effects/qsoundeffect_qsound_p.h b/src/multimedia/effects/qsoundeffect_qsound_p.h index 377c8a7..6fb3cfa 100644 --- a/src/multimedia/effects/qsoundeffect_qsound_p.h +++ b/src/multimedia/effects/qsoundeffect_qsound_p.h @@ -79,13 +79,11 @@ public: void setVolume(int volume); bool isMuted() const; void setMuted(bool muted); - int duration() const; public Q_SLOTS: void play(); Q_SIGNALS: - void durationChanged(); void volumeChanged(); void mutedChanged(); -- cgit v0.12 From d2d519f72433d70c342ed4cf0827a10ab0cdfdad Mon Sep 17 00:00:00 2001 From: Tom Cooksey Date: Mon, 8 Mar 2010 10:24:49 +0100 Subject: Enable cleanup hooks when creating an EGL surface for a pixmap Reviewed-By: TrustMe --- src/gui/egl/qegl_x11.cpp | 12 +++++++----- src/opengl/qgl_x11egl.cpp | 1 - 2 files changed, 7 insertions(+), 6 deletions(-) diff --git a/src/gui/egl/qegl_x11.cpp b/src/gui/egl/qegl_x11.cpp index 8608523..53c4711 100644 --- a/src/gui/egl/qegl_x11.cpp +++ b/src/gui/egl/qegl_x11.cpp @@ -41,18 +41,19 @@ #include -#include +#include #include -#include -#include +#include +#include +#include #include #include #include #include -#include "qegl_p.h" -#include "qeglcontext_p.h" +#include "QtGui/private/qegl_p.h" +#include "QtGui/private/qeglcontext_p.h" QT_BEGIN_NAMESPACE @@ -408,6 +409,7 @@ EGLSurface QEgl::createSurface(QPaintDevice *device, EGLConfig config, const QEg (EGLNativePixmapType) x11PixmapData->handle(), surfaceAttribs.properties()); x11PixmapData->gl_surface = (Qt::HANDLE)surf; + QImagePixmapCleanupHooks::enableCleanupHooks(x11PixmapData); return surf; } diff --git a/src/opengl/qgl_x11egl.cpp b/src/opengl/qgl_x11egl.cpp index 5ffecc5..fdcc412 100644 --- a/src/opengl/qgl_x11egl.cpp +++ b/src/opengl/qgl_x11egl.cpp @@ -42,7 +42,6 @@ #include "qgl.h" #include #include -#include #include #include #include "qgl_egl_p.h" -- cgit v0.12 From 76615ac642ffbe2730321623c5f298bde6109b11 Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Mon, 8 Mar 2010 11:34:50 +0100 Subject: Fix failing autotest. This was probably a bug in the test data. --- tests/auto/declarative/qdeclarativeanimations/data/dontAutoStart.qml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/tests/auto/declarative/qdeclarativeanimations/data/dontAutoStart.qml b/tests/auto/declarative/qdeclarativeanimations/data/dontAutoStart.qml index 3f00e68..408ad87 100644 --- a/tests/auto/declarative/qdeclarativeanimations/data/dontAutoStart.qml +++ b/tests/auto/declarative/qdeclarativeanimations/data/dontAutoStart.qml @@ -10,7 +10,7 @@ Rectangle { width: 100; height: 100 color: Qt.rgba(1,0,0) Behavior on x { - NumberAnimation { objectName: "MyAnim"; target: redRect; property: "y"; to: 300; repeat: true} + NumberAnimation { id: myAnim; objectName: "MyAnim"; target: redRect; property: "y"; to: 300; repeat: true} } } -- cgit v0.12 From 6f17a21647fe50ea79dd902220c1887b893f25b3 Mon Sep 17 00:00:00 2001 From: aavit Date: Mon, 8 Mar 2010 11:57:03 +0100 Subject: Fix crash on Win with 16bit screendepth when copy/pasting images Task-number: QTBUG-4687 Reviewed-by: Trond --- src/gui/kernel/qmime_win.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/gui/kernel/qmime_win.cpp b/src/gui/kernel/qmime_win.cpp index e191d7b..331626c 100644 --- a/src/gui/kernel/qmime_win.cpp +++ b/src/gui/kernel/qmime_win.cpp @@ -948,6 +948,8 @@ bool QWindowsMimeImage::convertFromMime(const FORMATETC &formatetc, const QMimeD QDataStream s(&ba, QIODevice::WriteOnly); s.setByteOrder(QDataStream::LittleEndian);// Intel byte order #### if (cf == CF_DIB) { + if (img.format() > QImage::Format_ARGB32) + img = img.convertToFormat(QImage::Format_RGB32); if (qt_write_dib(s, img)) return setData(ba, pmedium); } else { -- cgit v0.12 From d6e302a1a9bb05f000709830d865441ca7ab8c45 Mon Sep 17 00:00:00 2001 From: Tom Cooksey Date: Mon, 8 Mar 2010 12:47:55 +0100 Subject: Fix build on Maemo X11 Reviewed-By: Tobias Hunger --- src/src.pro | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/src.pro b/src/src.pro index 8c21ef7..403ffe1 100644 --- a/src/src.pro +++ b/src/src.pro @@ -112,7 +112,7 @@ src_declarative.target = sub-declarative contains(QT_CONFIG, phonon):src_webkit.depends += src_phonon contains(QT_CONFIG, xmlpatterns): src_webkit.depends += src_xmlpatterns contains(QT_CONFIG, declarative):src_declarative.depends += src_webkit - src_imports.depends += webkit + src_imports.depends += src_webkit #exists($$QT_SOURCE_TREE/src/3rdparty/webkit/JavaScriptCore/JavaScriptCore.pro): src_webkit.depends += src_javascriptcore } contains(QT_CONFIG, qt3support): src_plugins.depends += src_qt3support -- cgit v0.12 From b4519f022e8b715991836894fe97b6338ef7ee2b Mon Sep 17 00:00:00 2001 From: Thierry Bastian Date: Mon, 8 Mar 2010 15:30:14 +0100 Subject: fix to mainwindow demo the mask was not always correctly updated on the "blueTitleBar". Reviewed-by: gabi --- demos/mainwindow/mainwindow.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/demos/mainwindow/mainwindow.cpp b/demos/mainwindow/mainwindow.cpp index 32066d7..3ddb74b 100644 --- a/demos/mainwindow/mainwindow.cpp +++ b/demos/mainwindow/mainwindow.cpp @@ -329,7 +329,7 @@ void MainWindow::setupDockWidgets(const QMap &customSizeHints) BlueTitleBar *titlebar = new BlueTitleBar(swatch); swatch->setTitleBarWidget(titlebar); connect(swatch, SIGNAL(topLevelChanged(bool)), titlebar, SLOT(updateMask())); - connect(swatch, SIGNAL(featuresChanged(QDockWidget::DockWidgetFeatures)), titlebar, SLOT(updateMask())); + connect(swatch, SIGNAL(featuresChanged(QDockWidget::DockWidgetFeatures)), titlebar, SLOT(updateMask()), Qt::QueuedConnection); #ifdef Q_WS_QWS QPalette pal = palette(); -- cgit v0.12