Skip to content

Commit

Permalink
let MediaClip handle videoSink management
Browse files Browse the repository at this point in the history
  • Loading branch information
rectalogic committed Apr 19, 2024
1 parent 67941b3 commit fe605ce
Show file tree
Hide file tree
Showing 5 changed files with 9 additions and 16 deletions.
5 changes: 4 additions & 1 deletion src/MediaFX/VideoRenderer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,10 @@ VideoOutput {
property MediaClip mediaClip

onMediaClipChanged: {
RenderSession.updateVideoSinks(internal.previousMediaClip, root.mediaClip, root.videoSink);
if (internal.previousMediaClip)
internal.previousMediaClip.removeVideoSink(root.videoSink);
if (root.mediaClip)
root.mediaClip.addVideoSink(root.videoSink);
internal.previousMediaClip = root.mediaClip;
}

Expand Down
4 changes: 2 additions & 2 deletions src/MediaFX/media_clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -168,15 +168,15 @@ void MediaClip::updateActive()

void MediaClip::addVideoSink(QVideoSink* videoSink)
{
if (!m_videoSinks.contains(videoSink)) {
if (videoSink && !m_videoSinks.contains(videoSink)) {
m_videoSinks.append(videoSink);
updateActive();
}
}

void MediaClip::removeVideoSink(const QVideoSink* videoSink)
{
if (m_videoSinks.removeOne(videoSink)) {
if (videoSink && m_videoSinks.removeOne(videoSink)) {
updateActive();
}
}
Expand Down
5 changes: 3 additions & 2 deletions src/MediaFX/media_clip.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
#include <QtQmlIntegration>
#include <QtTypes>
#include <chrono>
Q_MOC_INCLUDE(<QVideoSink>)
class AudioRenderer;
class QVideoSink;
class RenderSession;
Expand Down Expand Up @@ -71,8 +72,8 @@ class MediaClip : public QObject, public QQmlParserStatus {
bool hasAudio() const { return m_decoder.hasAudio(); }
bool hasVideo() const { return m_decoder.hasVideo(); }

void addVideoSink(QVideoSink* videoSink);
void removeVideoSink(const QVideoSink* videoSink);
Q_INVOKABLE void addVideoSink(QVideoSink* videoSink);
Q_INVOKABLE void removeVideoSink(const QVideoSink* videoSink);

void render();

Expand Down
9 changes: 0 additions & 9 deletions src/MediaFX/render_session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -80,15 +80,6 @@ void RenderSession::initialize(const RenderContext& renderContext)
m_outputAudioFormat.setSampleRate(m_renderContext->sampleRate());
}

// NOLINTNEXTLINE(bugprone-easily-swappable-parameters)
void RenderSession::updateVideoSinks(MediaClip* oldClip, MediaClip* newClip, QVideoSink* videoSink)
{
if (oldClip)
oldClip->removeVideoSink(videoSink);
if (newClip)
newClip->addVideoSink(videoSink);
}

/*!
\qmlmethod void RenderSession::pauseRendering
Expand Down
2 changes: 0 additions & 2 deletions src/MediaFX/render_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -46,8 +46,6 @@ class RenderSession : public QObject {
return IntervalGadget(start, end);
};

Q_INVOKABLE void updateVideoSinks(MediaClip* oldClip, MediaClip* newClip, QVideoSink* videoSink);

const AVRational& outputFrameRate() const { return renderContext().frameRate(); }
const QAudioFormat& outputAudioFormat() const { return m_outputAudioFormat; }
const IntervalGadget currentRenderTime() const { return IntervalGadget(m_currentRenderTime); }
Expand Down

0 comments on commit fe605ce

Please sign in to comment.