Skip to content

Commit

Permalink
make currentRenderTime a property, instead of just a frameRendered si…
Browse files Browse the repository at this point in the history
…gnal
  • Loading branch information
rectalogic committed Jan 17, 2024
1 parent 36975d5 commit 5d3f506
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 6 deletions.
7 changes: 7 additions & 0 deletions src/MediaFX/media_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ using namespace std::chrono;
MediaManager::MediaManager(const microseconds& frameDuration, QQuickView* quickView, QObject* parent)
: QObject(parent)
, m_frameDuration(frameDuration)
, m_currentRenderTime(Interval(0us, frameDuration))
, m_quickView(quickView)
{
connect(this, &MediaManager::finishEncoding, [this]() { this->finishedEncoding = true; });
Expand All @@ -32,6 +33,12 @@ void MediaManager::unregisterClip(MediaClip* clip)
activeClips.removeOne(clip);
}

void MediaManager::nextRenderTime()
{
m_currentRenderTime = m_currentRenderTime.nextInterval(m_frameDuration);
emit currentRenderTimeChanged();
}

void MediaManager::render()
{
for (auto clip : activeClips) {
Expand Down
6 changes: 5 additions & 1 deletion src/MediaFX/media_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ using namespace std::chrono;
class MediaManager : public QObject {
Q_OBJECT
Q_PROPERTY(QQuickView* window READ window FINAL)
Q_PROPERTY(Interval currentRenderTime READ currentRenderTime NOTIFY currentRenderTimeChanged FINAL)

public:
using QObject::QObject;
Expand All @@ -33,6 +34,8 @@ class MediaManager : public QObject {

QQuickView* window() const { return m_quickView; };
const microseconds& frameDuration() { return m_frameDuration; };
const Interval& currentRenderTime() const { return m_currentRenderTime; };
void nextRenderTime();

void registerClip(MediaClip* clip);
void unregisterClip(MediaClip* clip);
Expand All @@ -43,10 +46,11 @@ class MediaManager : public QObject {

signals:
void finishEncoding();
void frameRendered();
void currentRenderTimeChanged();

private:
microseconds m_frameDuration;
Interval m_currentRenderTime;
QQuickView* m_quickView;
QList<MediaClip*> activeClips;
bool finishedEncoding = false;
Expand Down
4 changes: 2 additions & 2 deletions src/MediaFX/qml/sequence.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
// SPDX-License-Identifier: GPL-3.0-or-later

function onClipEnded() {
MediaManager.frameRendered.connect(nextClip);
MediaManager.currentRenderTimeChanged.connect(nextClip);
};

function onCurrentFrameTimechanged() {
Expand All @@ -14,7 +14,7 @@ function onCurrentFrameTimechanged() {
};

function nextClip() {
MediaManager.frameRendered.disconnect(nextClip);
MediaManager.currentRenderTimeChanged.disconnect(nextClip);
if (internal.currentClipIndex + 1 < root.mediaClips.length) {
var clip = root.mediaClips[internal.currentClipIndex];
clip.currentFrameTimeChanged.disconnect(onCurrentFrameTimechanged);
Expand Down
4 changes: 1 addition & 3 deletions src/MediaFX/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,12 @@ bool Session::event(QEvent* event)
void Session::render()
{
manager->render();

auto frameData = renderControl->renderVideoFrame();
manager->nextRenderTime();

if (encoder->write(encoder->videofd(), frameData.size(), frameData.constData()) == -1)
return;

emit manager->frameRendered();

if (manager->isFinishedEncoding()) {
emit quickView->engine()->exit(0);
return;
Expand Down

0 comments on commit 5d3f506

Please sign in to comment.