From 5f0bedded8735155fd78ac8e65a7620c74a078ba Mon Sep 17 00:00:00 2001 From: Andrew Wason Date: Tue, 17 Oct 2023 10:28:27 -0400 Subject: [PATCH] Don't expose stop() and invoke it automatically. --- mediafx/clip.cpp | 4 ++++ mediafx/clip.h | 4 ++-- mediafx/image_clip.h | 4 ++-- mediafx/media_clip.cpp | 13 +++++++------ mediafx/media_clip.h | 6 +++--- 5 files changed, 18 insertions(+), 13 deletions(-) diff --git a/mediafx/clip.cpp b/mediafx/clip.cpp index 8c0fac7..0d1062a 100644 --- a/mediafx/clip.cpp +++ b/mediafx/clip.cpp @@ -80,6 +80,9 @@ bool Clip::renderVideoFrame(const QMediaTimeRange::Interval& globalTime) setCurrentGlobalTime(globalTime); setNextClipTime(nextClipTime().translated(duration)); return true; + } else if (clipEnd() < nextClipTime().start()) { + stop(); + return false; } else { setActive(false); return false; @@ -88,5 +91,6 @@ bool Clip::renderVideoFrame(const QMediaTimeRange::Interval& globalTime) void Clip::stop() { + setVideoSinks(QList()); setNextClipTime(QMediaTimeRange::Interval(clipStart(), -1)); } \ No newline at end of file diff --git a/mediafx/clip.h b/mediafx/clip.h index 91542ef..e9cd3ff 100644 --- a/mediafx/clip.h +++ b/mediafx/clip.h @@ -50,8 +50,6 @@ class Clip : public QObject { bool renderVideoFrame(const QMediaTimeRange::Interval& globalTime); - Q_INVOKABLE virtual void stop(); - signals: void clipStartChanged(); void clipEndChanged(); @@ -68,6 +66,8 @@ class Clip : public QObject { void setCurrentVideoFrame(const QVideoFrame& videoFrame) { m_currentVideoFrame = videoFrame; }; + virtual void stop(); + private: QMediaTimeRange::Interval clipTimeRange() const { return m_clipSegment; }; void setNextClipTime(const QMediaTimeRange::Interval& time) { m_nextClipTime = time; }; diff --git a/mediafx/image_clip.h b/mediafx/image_clip.h index c4b1ca8..e8020c4 100644 --- a/mediafx/image_clip.h +++ b/mediafx/image_clip.h @@ -21,8 +21,6 @@ class ImageClip : public Clip { qint64 duration() const override; - void stop() override; - protected: void loadMedia(const QUrl&) override; @@ -30,6 +28,8 @@ class ImageClip : public Clip { void setActive(bool active) override; + void stop() override; + private: QImage image; QVideoFrame videoFrame; diff --git a/mediafx/media_clip.cpp b/mediafx/media_clip.cpp index 7fd9c83..2f1b033 100644 --- a/mediafx/media_clip.cpp +++ b/mediafx/media_clip.cpp @@ -51,7 +51,7 @@ qint64 MediaClip::duration() const void MediaClip::rateControl() { - auto size = frameQueue.size(); + auto size = bufferedFrames.size(); if (size > MaxFrameQueueSize && mediaPlayer.isPlaying()) mediaPlayer.pause(); else if (size < MinFrameQueueSize && !mediaPlayer.isPlaying()) @@ -69,7 +69,7 @@ void MediaClip::onVideoFrameChanged(const QVideoFrame& frame) if (frame.endTime() >= frameTime.end()) return; if (frame.startTime() >= frameTime.start()) { - frameQueue.enqueue(frame); + bufferedFrames.enqueue(frame); rateControl(); } } @@ -77,8 +77,8 @@ void MediaClip::onVideoFrameChanged(const QVideoFrame& frame) bool MediaClip::prepareNextVideoFrame() { QVideoFrame videoFrame; - while (!frameQueue.isEmpty()) { - videoFrame = frameQueue.dequeue(); + while (!bufferedFrames.isEmpty()) { + videoFrame = bufferedFrames.dequeue(); if (nextClipTime().contains(videoFrame.startTime())) { setCurrentVideoFrame(videoFrame); rateControl(); @@ -105,7 +105,8 @@ void MediaClip::setActive(bool active) void MediaClip::stop() { Clip::stop(); + mediaPlayer.stop(); mediaPlayer.setSource(QUrl()); - frameQueue.clear(); - frameQueue.squeeze(); + bufferedFrames.clear(); + bufferedFrames.squeeze(); } \ No newline at end of file diff --git a/mediafx/media_clip.h b/mediafx/media_clip.h index d38d9d5..7df3948 100644 --- a/mediafx/media_clip.h +++ b/mediafx/media_clip.h @@ -25,8 +25,6 @@ class MediaClip : public Clip { qint64 duration() const override; - void stop() override; - protected: void loadMedia(const QUrl&) override; @@ -34,6 +32,8 @@ class MediaClip : public Clip { void setActive(bool active) override; + void stop() override; + private slots: void onErrorOccurred(QMediaPlayer::Error error, const QString& errorString); void onVideoFrameChanged(const QVideoFrame& frame); @@ -45,5 +45,5 @@ private slots: static const int MinFrameQueueSize = 5; QMediaPlayer mediaPlayer; QVideoSink mediaPlayerSink; - QQueue frameQueue; + QQueue bufferedFrames; };