Skip to content

Commit

Permalink
make MediaManager not require Session. Hook up Qt.exit() in QML
Browse files Browse the repository at this point in the history
  • Loading branch information
rectalogic committed Jan 10, 2024
1 parent 9e08c59 commit f446de1
Show file tree
Hide file tree
Showing 9 changed files with 144 additions and 136 deletions.
10 changes: 5 additions & 5 deletions src/MediaFX/media_clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ void MediaClip::render()
if (m_videoTrack)
m_videoTrack->render(m_currentFrameTime);

m_currentFrameTime = m_currentFrameTime.nextInterval(MediaManager::singletonInstance()->session()->frameDuration());
m_currentFrameTime = m_currentFrameTime.nextInterval(MediaManager::singletonInstance()->frameDuration());

if (m_currentFrameTime.start() >= m_clipEnd) {
if (m_audioTrack)
Expand Down Expand Up @@ -125,7 +125,7 @@ void MediaClip::loadMedia()
{
if (!source().isValid()) {
qmlWarning(this) << "MediaClip requires source Url";
emit MediaManager::singletonInstance()->session()->exitApp(1);
emit MediaManager::singletonInstance()->window()->engine()->exit(1);
return;
}
ErrorInfo errorInfo;
Expand All @@ -134,14 +134,14 @@ void MediaClip::loadMedia()
FFMS_Indexer* indexer = FFMS_CreateIndexer(sourceFileUtf8.data(), &errorInfo);
if (!indexer) {
qmlWarning(this) << "MediaClip FFMS_CreateIndexer failed:" << errorInfo;
emit MediaManager::singletonInstance()->session()->exitApp(1);
emit MediaManager::singletonInstance()->window()->engine()->exit(1);
return;
}

FFMS_Index* index = FFMS_DoIndexing2(indexer, FFMS_IEH_ABORT, &errorInfo);
if (!index) {
qmlWarning(this) << "MediaClip FFMS_DoIndexing2 failed:" << errorInfo;
emit MediaManager::singletonInstance()->session()->exitApp(1);
emit MediaManager::singletonInstance()->window()->engine()->exit(1);
return;
}

Expand Down Expand Up @@ -169,5 +169,5 @@ void MediaClip::componentComplete()
if (clipEnd() < 0) {
setClipEnd(std::max(m_audioTrack ? m_audioTrack->duration() : 0, m_videoTrack ? m_videoTrack->duration() : 0));
}
m_currentFrameTime = Interval(milliseconds(clipStart()), milliseconds(clipStart()) + MediaManager::singletonInstance()->session()->frameDuration());
m_currentFrameTime = Interval(milliseconds(clipStart()), milliseconds(clipStart()) + MediaManager::singletonInstance()->frameDuration());
}
7 changes: 4 additions & 3 deletions src/MediaFX/media_manager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,14 @@

#include "media_manager.h"
#include "media_clip.h"
#include "session.h"
#include <QObject>
#include <QQuickView>
#include <chrono>
using namespace std::chrono;

MediaManager::MediaManager(Session* session, QQuickView* quickView, QObject* parent)
MediaManager::MediaManager(const microseconds& frameDuration, QQuickView* quickView, QObject* parent)
: QObject(parent)
, m_session(session)
, m_frameDuration(frameDuration)
, m_quickView(quickView)
{
connect(this, &MediaManager::finishEncoding, [this]() { this->finishedEncoding = true; });
Expand Down
9 changes: 5 additions & 4 deletions src/MediaFX/media_manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,16 +25,17 @@
#include <QtAssert>
#include <QtQml>
#include <QtQmlIntegration>
#include <chrono>
class MediaClip;
class Session;
using namespace std::chrono;

class MediaManager : public QObject {
Q_OBJECT
Q_PROPERTY(QQuickView* window READ window FINAL)

public:
using QObject::QObject;
MediaManager(Session* session, QQuickView* quickView, QObject* parent = nullptr);
MediaManager(const microseconds& frameDuration, QQuickView* quickView, QObject* parent = nullptr);

static MediaManager* singletonInstance();

Expand All @@ -43,8 +44,8 @@ class MediaManager : public QObject {
return Interval(start, end);
};

Session* session() const { return m_session; };
QQuickView* window() const { return m_quickView; };
const microseconds& frameDuration() { return m_frameDuration; };

void registerClip(MediaClip* clip);
void unregisterClip(MediaClip* clip);
Expand All @@ -58,7 +59,7 @@ class MediaManager : public QObject {
void frameRendered();

private:
Session* m_session;
microseconds m_frameDuration;
QQuickView* m_quickView;
QList<MediaClip*> activeClips;
bool finishedEncoding = false;
Expand Down
5 changes: 4 additions & 1 deletion src/MediaFX/qml/MultiEffectState.qml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ State {
target: root.effect
}
PropertyChanges {
anchors.fill: root.videoOutput
x: root.videoOutput.x
y: root.videoOutput.y
width: root.videoOutput.width
height: root.videoOutput.height
source: root.videoOutput
visible: true
target: root.effect
Expand Down
5 changes: 4 additions & 1 deletion src/MediaFX/qml/effects/LumaMixer.qml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,10 @@ MediaMixer {
name: "default"

PropertyChanges {
anchors.fill: root
x: root.x
y: root.y
width: root.width
height: root.height
layer.enabled: true
visible: false
target: root.luma
Expand Down
10 changes: 6 additions & 4 deletions src/MediaFX/session.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -51,19 +51,21 @@ Session::Session(Encoder* encoder, QObject* parent)
, quickView(nullptr)
{
FFMS_Init(0, 0);
connect(this, &Session::exitApp, qApp, &QCoreApplication::exit, Qt::QueuedConnection);

animationDriver->install();
renderControl.reset(new RenderControl());
quickView.reset(new QQuickView(QUrl(), renderControl.get()));
// Enables Qt.exit(0) in QML
connect(quickView->engine(), &QQmlEngine::exit, qApp, &QCoreApplication::exit, Qt::QueuedConnection);

#ifdef MEDIAFX_ENABLE_VULKAN
if (quickView->rendererInterface()->graphicsApi() == QSGRendererInterface::Vulkan) {
vulkanInstance.setExtensions(QQuickGraphicsConfiguration::preferredInstanceExtensions());
vulkanInstance.create();
}
#endif

manager = new MediaManager(this, quickView.get(), this);
manager = new MediaManager(m_frameDuration, quickView.get(), this);
MediaManagerForeign::s_singletonInstance = manager;

quickView->setResizeMode(QQuickView::ResizeMode::SizeRootObjectToView);
Expand Down Expand Up @@ -103,7 +105,7 @@ bool Session::initialize(const QUrl& url)
void Session::quickViewStatusChanged(QQuickView::Status status)
{
if (status == QQuickView::Error) {
emit exitApp(1);
emit quickView->engine()->exit(1);
} else if (status == QQuickView::Ready) {
quickView->rootObject()->setEnabled(false);
QCoreApplication::postEvent(this, new QEvent(renderEventType));
Expand Down Expand Up @@ -152,7 +154,7 @@ void Session::render()
emit manager->frameRendered();

if (manager->isFinishedEncoding()) {
emit exitApp(0);
emit quickView->engine()->exit(0);
return;
}

Expand Down
3 changes: 0 additions & 3 deletions src/MediaFX/session.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,9 +53,6 @@ class Session : public QObject {

bool event(QEvent* event) override;

signals:
void exitApp(int);

private slots:
void quickViewStatusChanged(QQuickView::Status status);
void engineWarnings(const QList<QQmlError>& warnings);
Expand Down
Loading

0 comments on commit f446de1

Please sign in to comment.