Skip to content

Commit

Permalink
Interval qdebug. Fix nextClipTime initializer. Seek on initial play i…
Browse files Browse the repository at this point in the history
…f needed.
  • Loading branch information
rectalogic committed Nov 22, 2023
1 parent 554b028 commit dcb9214
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 6 deletions.
2 changes: 1 addition & 1 deletion src/mediafx/clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ void Clip::initializeNextClipTime()
{
setNextClipTime(Interval(
clipStartMicros(),
MediaFX::singletonInstance()->session()->frameDuration()));
clipStartMicros() + MediaFX::singletonInstance()->session()->frameDuration()));
}

void Clip::stop()
Expand Down
9 changes: 9 additions & 0 deletions src/mediafx/interval.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@

#pragma once

#include <QDebug>
#include <QDebugStateSaver>
#include <QtTypes>
#include <utility>

Expand Down Expand Up @@ -57,3 +59,10 @@ struct Interval {
qint64 s = 0;
qint64 e = 0;
};

QDebug inline operator<<(QDebug dbg, const Interval& interval)
{
QDebugStateSaver saver(dbg);
dbg.nospace() << "(" << interval.start() << ", " << interval.end() << ")";
return dbg;
}
16 changes: 11 additions & 5 deletions src/mediafx/video_clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,6 @@ void VideoClip::onVideoFrameChanged(const QVideoFrame& frame)
if (videoSinks().isEmpty())
return;

// XXX need to attempt to seek - should we do that when clipStart set, or when url set? we don't know which is set first
// XXX seek doesn't work until we are playing, so need to do it here

auto frameTimeStart = nextClipTime().start();
if (frame.endTime() < frameTimeStart) {
return;
Expand Down Expand Up @@ -104,13 +101,22 @@ void VideoClip::setActive(bool bactive)
VisualClip::setActive(bactive);
if (isComponentComplete()) {
if (active()) {
mediaPlayer.play();
play();
} else {
mediaPlayer.pause();
}
}
}

void VideoClip::play()
{
bool initialPlay = mediaPlayer.playbackState() == QMediaPlayer::StoppedState;
mediaPlayer.play();
if (initialPlay && clipStart() > 0 && mediaPlayer.isSeekable()) {
mediaPlayer.setPosition(clipStart());
}
}

void VideoClip::stop()
{
VisualClip::stop();
Expand All @@ -128,5 +134,5 @@ void VideoClip::componentComplete()
}
VisualClip::componentComplete();
if (active())
mediaPlayer.play();
play();
}
1 change: 1 addition & 0 deletions src/mediafx/video_clip.h
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ private slots:
void onVideoFrameChanged(const QVideoFrame& frame);

private:
void play();
void rateControl();
static const int MaxFrameQueueSize = 20;
static const int MinFrameQueueSize = 5;
Expand Down

0 comments on commit dcb9214

Please sign in to comment.