Skip to content

Commit

Permalink
simplify RenderContext
Browse files Browse the repository at this point in the history
  • Loading branch information
rectalogic committed Apr 23, 2024
1 parent e947944 commit 5122ca8
Show file tree
Hide file tree
Showing 6 changed files with 47 additions and 46 deletions.
1 change: 0 additions & 1 deletion src/MediaFX/encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#pragma once

#include "formats.h"
#include "render_context.h"
#include <QObject>
#include <QQmlParserStatus>
Expand Down
3 changes: 0 additions & 3 deletions src/MediaFX/formats.h
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,3 @@ inline constexpr auto VideoColorSpace_Qt = QVideoFrameFormat::ColorSpace_AdobeRg
inline constexpr auto VideoColorSpace_FFMPEG = AVCOL_SPC_RGB;
inline constexpr auto VideoColorRange_Qt = QVideoFrameFormat::ColorRange_Full;
inline constexpr auto VideoColorRange_FFMPEG = AVCOL_RANGE_JPEG;

inline constexpr int DefaultSampleRate = 44100;
inline constexpr Rational DefaultFrameRate = { 30, 1 };
7 changes: 5 additions & 2 deletions src/MediaFX/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,10 +104,13 @@ int encoder(QGuiApplication& app, QCommandLineParser& parser)
output = u"pipe:"_s;

QQmlApplicationEngine engine;
RenderContextData renderContextData(url, output, frameSize, frameRate, sampleRate);
RenderContext* renderContext = engine.singletonInstance<RenderContext*>("MediaFX", "RenderContext");
Q_ASSERT(renderContext);
renderContext->setData(renderContextData);
renderContext->setSourceUrl(url);
renderContext->setOutputFileName(output);
renderContext->setFrameSize(frameSize);
renderContext->setFrameRate(frameRate);
renderContext->setSampleRate(sampleRate);

auto fatalExit = [&engine]() {
emit engine.exit(1);
Expand Down
28 changes: 24 additions & 4 deletions src/MediaFX/render_context.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,16 +5,36 @@ extern "C" {
#include <libavutil/rational.h>
}

RenderContextData::RenderContextData(const QUrl& sourceUrl, const QString& outputFileName, const QSize& frameSize, const Rational& frameRate, int sampleRate)
: m_sourceUrl(sourceUrl)
RenderContext::RenderContext(const QUrl& sourceUrl, const QString& outputFileName, const QSize& frameSize, const Rational& frameRate, int sampleRate, QObject* parent)
: QObject(parent)
, m_sourceUrl(sourceUrl)
, m_outputFileName(outputFileName)
, m_frameSize(frameSize)
, m_frameRate(frameRate)
, m_sampleRate(sampleRate)
{
}

RenderContext::RenderContext(QObject* parent)
: QObject(parent)
void RenderContext::setSourceUrl(const QUrl& sourceUrl)
{
m_sourceUrl = sourceUrl;
}

void RenderContext::setOutputFileName(const QString& outputFileName)
{
m_outputFileName = outputFileName;
}

void RenderContext::setFrameSize(const QSize& frameSize)
{
m_frameSize = frameSize;
}

void RenderContext::setFrameRate(const Rational& frameRate)
{
m_frameRate = frameRate;
}

void RenderContext::setSampleRate(int sampleRate)
{
}
53 changes: 18 additions & 35 deletions src/MediaFX/render_context.h
Original file line number Diff line number Diff line change
Expand Up @@ -25,30 +25,8 @@ struct Rational : public AVRational {
}
};

class RenderContextData {
public:
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
explicit RenderContextData(const QUrl& sourceUrl = QUrl(), const QString& outputFileName = "", const QSize& frameSize = QSize(640, 360), const Rational& frameRate = { 30, 1 }, int sampleRate = 44100);

RenderContextData(RenderContextData&&) = default;
RenderContextData(const RenderContextData&) = default;
RenderContextData& operator=(RenderContextData&&) = default;
RenderContextData& operator=(const RenderContextData&) = default;
~RenderContextData() = default;

constexpr const QUrl& sourceUrl() const { return m_sourceUrl; }
constexpr const QString& outputFileName() const { return m_outputFileName; }
constexpr const QSize& frameSize() const noexcept { return m_frameSize; }
constexpr const Rational& frameRate() const noexcept { return m_frameRate; }
constexpr int sampleRate() const noexcept { return m_sampleRate; }

private:
QSize m_frameSize;
Rational m_frameRate;
int m_sampleRate;
QUrl m_sourceUrl;
QString m_outputFileName;
};
inline constexpr int DefaultSampleRate = 44100;
inline constexpr Rational DefaultFrameRate = { 30, 1 };

class RenderContext : public QObject {
Q_OBJECT
Expand All @@ -60,22 +38,27 @@ class RenderContext : public QObject {
QML_ELEMENT
QML_SINGLETON
public:
// NOLINTNEXTLINE(cppcoreguidelines-avoid-magic-numbers)
explicit RenderContext(QObject* parent = nullptr);
explicit RenderContext(const QUrl& sourceUrl = QUrl(), const QString& outputFileName = "", const QSize& frameSize = QSize(640, 360), const Rational& frameRate = DefaultFrameRate, int sampleRate = DefaultSampleRate, QObject* parent = nullptr);
RenderContext(RenderContext&&) = delete;
RenderContext& operator=(RenderContext&&) = delete;
~RenderContext() override = default;

constexpr const QUrl& sourceUrl() const { return m_data.sourceUrl(); }
constexpr const QString& outputFileName() const { return m_data.outputFileName(); }
constexpr int sampleRate() const noexcept { return m_data.sampleRate(); }
constexpr const QSize& frameSize() const noexcept { return m_data.frameSize(); }
constexpr const Rational& frameRate() const noexcept { return m_data.frameRate(); }

constexpr const RenderContextData& data() const noexcept { return m_data; }
void setData(const RenderContextData& data) { m_data = data; }
constexpr const QUrl& sourceUrl() const { return m_sourceUrl; }
void setSourceUrl(const QUrl& sourceUrl);
constexpr const QString& outputFileName() const { return m_outputFileName; }
void setOutputFileName(const QString& outputFileName);
constexpr const QSize& frameSize() const noexcept { return m_frameSize; }
void setFrameSize(const QSize& frameSize);
constexpr const Rational& frameRate() const noexcept { return m_frameRate; }
void setFrameRate(const Rational& frameRate);
constexpr int sampleRate() const noexcept { return m_sampleRate; }
void setSampleRate(int sampleRate);

private:
Q_DISABLE_COPY(RenderContext);
RenderContextData m_data;
QSize m_frameSize;
Rational m_frameRate;
int m_sampleRate;
QUrl m_sourceUrl;
QString m_outputFileName;
};
1 change: 0 additions & 1 deletion src/MediaFX/render_session.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@

#pragma once

#include "formats.h"
#include "interval.h"
#include "render_context.h"
#include <QAudioBuffer>
Expand Down

0 comments on commit 5122ca8

Please sign in to comment.