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/recording | |
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/recording')
-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 |
3 files changed, 72 insertions, 3 deletions
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; |