diff options
author | Doris Verria <doris.verria@qt.io> | 2021-02-10 16:54:25 +0100 |
---|---|---|
committer | Lars Knoll <lars.knoll@qt.io> | 2021-02-17 08:26:08 +0000 |
commit | 59b04ded0fe5fe5bbc3e2c29d7cd426a78600e59 (patch) | |
tree | e3d6200ab6d289f0676d6ad913abd0f493ad6451 /src/multimedia | |
parent | 03f3201a24514f43e781bf59026ca5039fd9ab21 (diff) |
Remove the notifyInterval functionality from QMediaSource
As a step towards removing QMediaSource from the
hierarchy, remove its notifyInterval functionality and implement it
in the child classes QMediaPlayer and QMediaRecorder instead.
Change-Id: I17aa778fc306881f9e08ab4decbc2d2f3928c686
Reviewed-by: Lars Knoll <lars.knoll@qt.io>
Diffstat (limited to 'src/multimedia')
-rw-r--r-- | src/multimedia/playback/qmediaplayer.cpp | 88 | ||||
-rw-r--r-- | src/multimedia/playback/qmediaplayer.h | 9 | ||||
-rw-r--r-- | src/multimedia/qmediasource.cpp | 103 | ||||
-rw-r--r-- | src/multimedia/qmediasource.h | 10 | ||||
-rw-r--r-- | src/multimedia/qmediasource_p.h | 7 | ||||
-rw-r--r-- | src/multimedia/recording/qmediarecorder.cpp | 66 | ||||
-rw-r--r-- | src/multimedia/recording/qmediarecorder.h | 7 | ||||
-rw-r--r-- | src/multimedia/recording/qmediarecorder_p.h | 2 |
8 files changed, 170 insertions, 122 deletions
diff --git a/src/multimedia/playback/qmediaplayer.cpp b/src/multimedia/playback/qmediaplayer.cpp index cf2823748..dc639c2c4 100644 --- a/src/multimedia/playback/qmediaplayer.cpp +++ b/src/multimedia/playback/qmediaplayer.cpp @@ -101,6 +101,7 @@ class QMediaPlayerPrivate : public QMediaSourcePrivate Q_DECLARE_NON_CONST_PUBLIC(QMediaPlayer) public: + QMediaPlayerPrivate() : notifyTimer(nullptr) {} QMediaPlatformPlayerInterface *playerInterface = nullptr; QMediaPlayerControl* control = nullptr; QString errorString; @@ -125,8 +126,31 @@ public: void _q_stateChanged(QMediaPlayer::State state); void _q_mediaStatusChanged(QMediaPlayer::MediaStatus status); void _q_error(int error, const QString &errorString); + void _q_notify(); + + QTimer* notifyTimer; + QSet<int> notifyProperties; }; +void QMediaPlayerPrivate::_q_notify() +{ + Q_Q(QMediaPlayer); + + const QMetaObject* m = q->metaObject(); + + // QTBUG-57045 + // we create a copy of notifyProperties container to ensure that if a property is removed + // from the original container as a result of invoking propertyChanged signal, the iterator + // won't become invalidated + QSet<int> properties = notifyProperties; + + for (int pi : qAsConst(properties)) { + QMetaProperty p = m->property(pi); + p.notifySignal().invoke( + q, QGenericArgument(p.metaType().name(), p.read(q).data())); + } +} + void QMediaPlayerPrivate::_q_stateChanged(QMediaPlayer::State ps) { Q_Q(QMediaPlayer); @@ -264,6 +288,10 @@ QMediaPlayer::QMediaPlayer(QObject *parent): { Q_D(QMediaPlayer); + d->notifyTimer = new QTimer(this); + d->notifyTimer->setInterval(1000); + connect(d->notifyTimer, SIGNAL(timeout()), SLOT(_q_notify())); + d->playerInterface = QMediaPlatformIntegration::instance()->createPlayerInterface(); if (!d->playerInterface) { qWarning() << "QPlatformMediaPlayerInterface not implemented!"; @@ -316,6 +344,66 @@ QMediaPlayer::~QMediaPlayer() delete d->playerInterface; } +int QMediaPlayer::notifyInterval() const +{ + return d_func()->notifyTimer->interval(); +} + +void QMediaPlayer::setNotifyInterval(int milliSeconds) +{ + Q_D(QMediaPlayer); + + if (d->notifyTimer->interval() != milliSeconds) { + d->notifyTimer->setInterval(milliSeconds); + + emit notifyIntervalChanged(milliSeconds); + } +} + +/*! + Watch the property \a name. The property's notify signal will be emitted + once every \c notifyInterval milliseconds. + + \sa notifyInterval +*/ + +void QMediaPlayer::addPropertyWatch(QByteArray const &name) +{ + Q_D(QMediaPlayer); + + const QMetaObject* m = metaObject(); + + int index = m->indexOfProperty(name.constData()); + + if (index != -1 && m->property(index).hasNotifySignal()) { + d->notifyProperties.insert(index); + + if (!d->notifyTimer->isActive()) + d->notifyTimer->start(); + } +} + +/*! + Remove property \a name from the list of properties whose changes are + regularly signaled. + + \sa notifyInterval +*/ + +void QMediaPlayer::removePropertyWatch(QByteArray const &name) +{ + Q_D(QMediaPlayer); + + int index = metaObject()->indexOfProperty(name.constData()); + + if (index != -1) { + d->notifyProperties.remove(index); + + if (d->notifyProperties.isEmpty()) + d->notifyTimer->stop(); + } +} + QUrl QMediaPlayer::media() const { Q_D(const QMediaPlayer); diff --git a/src/multimedia/playback/qmediaplayer.h b/src/multimedia/playback/qmediaplayer.h index 591383c30..791580253 100644 --- a/src/multimedia/playback/qmediaplayer.h +++ b/src/multimedia/playback/qmediaplayer.h @@ -55,6 +55,7 @@ class QMediaPlayerPrivate; class Q_MULTIMEDIA_EXPORT QMediaPlayer : public QMediaSource { Q_OBJECT + Q_PROPERTY(int notifyInterval READ notifyInterval WRITE setNotifyInterval NOTIFY notifyIntervalChanged) Q_PROPERTY(QUrl media READ media WRITE setMedia NOTIFY mediaChanged) Q_PROPERTY(qint64 duration READ duration NOTIFY durationChanged) Q_PROPERTY(qint64 position READ position WRITE setPosition NOTIFY positionChanged) @@ -112,6 +113,11 @@ public: // bool enableLowLatencyPlayback(bool tryEnable); // bool isLowLatencyPlaybackEnabled() const; + int notifyInterval() const; + void setNotifyInterval(int milliSeconds); + void addPropertyWatch(QByteArray const &name); + void removePropertyWatch(QByteArray const &name); + bool setAudioOutput(const QAudioDeviceInfo &device); QAudioDeviceInfo audioOutput() const; @@ -179,6 +185,8 @@ public Q_SLOTS: void setMedia(const QUrl &media, QIODevice *stream = nullptr); Q_SIGNALS: + void notifyIntervalChanged(int milliSeconds); + void mediaChanged(const QUrl &media); void stateChanged(QMediaPlayer::State newState); @@ -208,6 +216,7 @@ private: Q_PRIVATE_SLOT(d_func(), void _q_stateChanged(QMediaPlayer::State)) Q_PRIVATE_SLOT(d_func(), void _q_mediaStatusChanged(QMediaPlayer::MediaStatus)) Q_PRIVATE_SLOT(d_func(), void _q_error(int, const QString &)) + Q_PRIVATE_SLOT(d_func(), void _q_notify()) }; QT_END_NAMESPACE diff --git a/src/multimedia/qmediasource.cpp b/src/multimedia/qmediasource.cpp index f807e823e..5015f7e77 100644 --- a/src/multimedia/qmediasource.cpp +++ b/src/multimedia/qmediasource.cpp @@ -48,25 +48,6 @@ QT_BEGIN_NAMESPACE -void QMediaSourcePrivate::_q_notify() -{ - Q_Q(QMediaSource); - - const QMetaObject* m = q->metaObject(); - - // QTBUG-57045 - // we create a copy of notifyProperties container to ensure that if a property is removed - // from the original container as a result of invoking propertyChanged signal, the iterator - // won't become invalidated - QSet<int> properties = notifyProperties; - - for (int pi : qAsConst(properties)) { - QMetaProperty p = m->property(pi); - p.notifySignal().invoke( - q, QGenericArgument(p.metaType().name(), p.read(q).data())); - } -} - /*! \class QMediaSource @@ -133,22 +114,6 @@ QMediaService* QMediaSource::service() const return d_func()->service; } -int QMediaSource::notifyInterval() const -{ - return d_func()->notifyTimer->interval(); -} - -void QMediaSource::setNotifyInterval(int milliSeconds) -{ - Q_D(QMediaSource); - - if (d->notifyTimer->interval() != milliSeconds) { - d->notifyTimer->setInterval(milliSeconds); - - emit notifyIntervalChanged(milliSeconds); - } -} - /*! Bind \a object to this QMediaSource instance. @@ -211,10 +176,6 @@ QMediaSource::QMediaSource(QObject *parent, QMediaService *service) { Q_D(QMediaSource); - d->notifyTimer = new QTimer(this); - d->notifyTimer->setInterval(1000); - connect(d->notifyTimer, SIGNAL(timeout()), SLOT(_q_notify())); - d->service = service; } @@ -227,74 +188,10 @@ QMediaSource::QMediaSource(QMediaSourcePrivate &dd, QObject *parent, QMediaServi { Q_D(QMediaSource); - d->notifyTimer = new QTimer(this); - d->notifyTimer->setInterval(1000); - connect(d->notifyTimer, SIGNAL(timeout()), SLOT(_q_notify())); - d->service = service; } /*! - Watch the property \a name. The property's notify signal will be emitted - once every \c notifyInterval milliseconds. - - \sa notifyInterval -*/ - -void QMediaSource::addPropertyWatch(QByteArray const &name) -{ - Q_D(QMediaSource); - - const QMetaObject* m = metaObject(); - - int index = m->indexOfProperty(name.constData()); - - if (index != -1 && m->property(index).hasNotifySignal()) { - d->notifyProperties.insert(index); - - if (!d->notifyTimer->isActive()) - d->notifyTimer->start(); - } -} - -/*! - Remove property \a name from the list of properties whose changes are - regularly signaled. - - \sa notifyInterval -*/ - -void QMediaSource::removePropertyWatch(QByteArray const &name) -{ - Q_D(QMediaSource); - - int index = metaObject()->indexOfProperty(name.constData()); - - if (index != -1) { - d->notifyProperties.remove(index); - - if (d->notifyProperties.isEmpty()) - d->notifyTimer->stop(); - } -} - -/*! - \property QMediaSource::notifyInterval - - The interval at which notifiable properties will update. - - The interval is expressed in milliseconds, the default value is 1000. - - \sa addPropertyWatch(), removePropertyWatch() -*/ - -/*! - \fn void QMediaSource::notifyIntervalChanged(int milliseconds) - - Signal a change in the notify interval period to \a milliseconds. -*/ - -/*! Returns the value associated with a meta-data \a key. See the list of predefined \l {QMediaMetaData}{meta-data keys}. diff --git a/src/multimedia/qmediasource.h b/src/multimedia/qmediasource.h index 8f376eeaf..42db044f1 100644 --- a/src/multimedia/qmediasource.h +++ b/src/multimedia/qmediasource.h @@ -57,7 +57,6 @@ class QMediaSourcePrivate; class Q_MULTIMEDIA_EXPORT QMediaSource : public QObject { Q_OBJECT - Q_PROPERTY(int notifyInterval READ notifyInterval WRITE setNotifyInterval NOTIFY notifyIntervalChanged) public: ~QMediaSource(); @@ -69,29 +68,20 @@ public: virtual QMediaService* service() const; - int notifyInterval() const; - void setNotifyInterval(int milliSeconds); - bool bind(QMediaSink *); void unbind(QMediaSink *); virtual QMediaMetaData metaData() const; Q_SIGNALS: - void notifyIntervalChanged(int milliSeconds); - void metaDataChanged(); protected: QMediaSource(QObject *parent, QMediaService *service); QMediaSource(QMediaSourcePrivate &dd, QObject *parent, QMediaService *service); - void addPropertyWatch(QByteArray const &name); - void removePropertyWatch(QByteArray const &name); - private: Q_DECLARE_PRIVATE(QMediaSource) - Q_PRIVATE_SLOT(d_func(), void _q_notify()) }; diff --git a/src/multimedia/qmediasource_p.h b/src/multimedia/qmediasource_p.h index e6000e11e..756c86955 100644 --- a/src/multimedia/qmediasource_p.h +++ b/src/multimedia/qmediasource_p.h @@ -70,15 +70,10 @@ class QMediaSourcePrivate : public QObjectPrivate Q_DECLARE_PUBLIC(QMediaSource) public: - QMediaSourcePrivate() : service(nullptr), notifyTimer(nullptr) {} + QMediaSourcePrivate() : service(nullptr) {} virtual ~QMediaSourcePrivate() {} - void _q_notify(); - QMediaService *service; - - QTimer* notifyTimer; - QSet<int> notifyProperties; }; QT_END_NAMESPACE diff --git a/src/multimedia/recording/qmediarecorder.cpp b/src/multimedia/recording/qmediarecorder.cpp index 2fa14fd4e..50b77ab94 100644 --- a/src/multimedia/recording/qmediarecorder.cpp +++ b/src/multimedia/recording/qmediarecorder.cpp @@ -238,6 +238,66 @@ QMediaRecorder::~QMediaRecorder() delete d_ptr; } +int QMediaRecorder::notifyInterval() const +{ + return d_func()->notifyTimer->interval(); +} + +void QMediaRecorder::setNotifyInterval(int milliSeconds) +{ + Q_D(QMediaRecorder); + + if (d->notifyTimer->interval() != milliSeconds) { + d->notifyTimer->setInterval(milliSeconds); + + emit notifyIntervalChanged(milliSeconds); + } +} + +/*! + Watch the property \a name. The property's notify signal will be emitted + once every \c notifyInterval milliseconds. + + \sa notifyInterval +*/ + +void QMediaRecorder::addPropertyWatch(QByteArray const &name) +{ + Q_D(QMediaRecorder); + + const QMetaObject* m = metaObject(); + + int index = m->indexOfProperty(name.constData()); + + if (index != -1 && m->property(index).hasNotifySignal()) { + d->notifyProperties.insert(index); + + if (!d->notifyTimer->isActive()) + d->notifyTimer->start(); + } +} + +/*! + Remove property \a name from the list of properties whose changes are + regularly signaled. + + \sa notifyInterval +*/ + +void QMediaRecorder::removePropertyWatch(QByteArray const &name) +{ + Q_D(QMediaRecorder); + + int index = metaObject()->indexOfProperty(name.constData()); + + if (index != -1) { + d->notifyProperties.remove(index); + + if (d->notifyProperties.isEmpty()) + d->notifyTimer->stop(); + } +} + /*! Returns the QMediaSource instance that this QMediaRecorder is bound too, or 0 otherwise. @@ -281,7 +341,7 @@ bool QMediaRecorder::setMediaSource(QMediaSource *object) this, SLOT(_q_error(int,QString))); } - disconnect(d->mediaSource, SIGNAL(notifyIntervalChanged(int)), this, SLOT(_q_updateNotifyInterval(int))); + disconnect(this, SIGNAL(notifyIntervalChanged(int)), this, SLOT(_q_updateNotifyInterval(int))); QMediaService *service = d->mediaSource->service(); @@ -300,8 +360,8 @@ bool QMediaRecorder::setMediaSource(QMediaSource *object) if (d->mediaSource) { QMediaService *service = d->mediaSource->service(); - d->notifyTimer->setInterval(d->mediaSource->notifyInterval()); - connect(d->mediaSource, SIGNAL(notifyIntervalChanged(int)), SLOT(_q_updateNotifyInterval(int))); + d->notifyTimer->setInterval(notifyInterval()); + connect(this, SIGNAL(notifyIntervalChanged(int)), SLOT(_q_updateNotifyInterval(int))); if (service) { d->control = qobject_cast<QMediaRecorderControl*>(service->requestControl(QMediaRecorderControl_iid)); diff --git a/src/multimedia/recording/qmediarecorder.h b/src/multimedia/recording/qmediarecorder.h index 303dd3dea..844abf966 100644 --- a/src/multimedia/recording/qmediarecorder.h +++ b/src/multimedia/recording/qmediarecorder.h @@ -72,6 +72,7 @@ class Q_MULTIMEDIA_EXPORT QMediaRecorder : public QObject, public QMediaSink Q_ENUMS(State) Q_ENUMS(Status) Q_ENUMS(Error) + Q_PROPERTY(int notifyInterval READ notifyInterval WRITE setNotifyInterval NOTIFY notifyIntervalChanged) Q_PROPERTY(QMediaRecorder::State state READ state NOTIFY stateChanged) Q_PROPERTY(QMediaRecorder::Status status READ status NOTIFY statusChanged) Q_PROPERTY(qint64 duration READ duration NOTIFY durationChanged) @@ -118,6 +119,11 @@ public: explicit QMediaRecorder(QMediaSource *mediaSource, QObject *parent = nullptr); ~QMediaRecorder(); + int notifyInterval() const; + void setNotifyInterval(int milliSeconds); + void addPropertyWatch(QByteArray const &name); + void removePropertyWatch(QByteArray const &name); + QMediaSource *mediaSource() const override; QObject *asObject() override { return this; } @@ -159,6 +165,7 @@ public Q_SLOTS: bool setAudioInput(const QAudioDeviceInfo &device); Q_SIGNALS: + void notifyIntervalChanged(int milliSeconds); void stateChanged(QMediaRecorder::State state); void statusChanged(QMediaRecorder::Status status); void durationChanged(qint64 duration); diff --git a/src/multimedia/recording/qmediarecorder_p.h b/src/multimedia/recording/qmediarecorder_p.h index 94d5d80c9..44b3e74b3 100644 --- a/src/multimedia/recording/qmediarecorder_p.h +++ b/src/multimedia/recording/qmediarecorder_p.h @@ -81,6 +81,8 @@ public: QTimer* notifyTimer = nullptr; + QSet<int> notifyProperties; + QMediaRecorder::State state = QMediaRecorder::StoppedState; QMediaRecorder::Error error = QMediaRecorder::NoError; QString errorString; |