Skip to content

Commit

Permalink
Don't expose stop() and invoke it automatically.
Browse files Browse the repository at this point in the history
  • Loading branch information
rectalogic committed Oct 17, 2023
1 parent b485fd8 commit 5f0bedd
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 13 deletions.
4 changes: 4 additions & 0 deletions mediafx/clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -88,5 +91,6 @@ bool Clip::renderVideoFrame(const QMediaTimeRange::Interval& globalTime)

void Clip::stop()
{
setVideoSinks(QList<QVideoSink*>());
setNextClipTime(QMediaTimeRange::Interval(clipStart(), -1));
}
4 changes: 2 additions & 2 deletions mediafx/clip.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,8 +50,6 @@ class Clip : public QObject {

bool renderVideoFrame(const QMediaTimeRange::Interval& globalTime);

Q_INVOKABLE virtual void stop();

signals:
void clipStartChanged();
void clipEndChanged();
Expand All @@ -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; };
Expand Down
4 changes: 2 additions & 2 deletions mediafx/image_clip.h
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,15 @@ class ImageClip : public Clip {

qint64 duration() const override;

void stop() override;

protected:
void loadMedia(const QUrl&) override;

bool prepareNextVideoFrame() override;

void setActive(bool active) override;

void stop() override;

private:
QImage image;
QVideoFrame videoFrame;
Expand Down
13 changes: 7 additions & 6 deletions mediafx/media_clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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())
Expand All @@ -69,16 +69,16 @@ void MediaClip::onVideoFrameChanged(const QVideoFrame& frame)
if (frame.endTime() >= frameTime.end())
return;
if (frame.startTime() >= frameTime.start()) {
frameQueue.enqueue(frame);
bufferedFrames.enqueue(frame);
rateControl();
}
}

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();
Expand All @@ -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();
}
6 changes: 3 additions & 3 deletions mediafx/media_clip.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,15 +25,15 @@ class MediaClip : public Clip {

qint64 duration() const override;

void stop() override;

protected:
void loadMedia(const QUrl&) override;

bool prepareNextVideoFrame() override;

void setActive(bool active) override;

void stop() override;

private slots:
void onErrorOccurred(QMediaPlayer::Error error, const QString& errorString);
void onVideoFrameChanged(const QVideoFrame& frame);
Expand All @@ -45,5 +45,5 @@ private slots:
static const int MinFrameQueueSize = 5;
QMediaPlayer mediaPlayer;
QVideoSink mediaPlayerSink;
QQueue<QVideoFrame> frameQueue;
QQueue<QVideoFrame> bufferedFrames;
};

0 comments on commit 5f0bedd

Please sign in to comment.