Skip to content

Commit

Permalink
handle encoding errors and qml warnings
Browse files Browse the repository at this point in the history
  • Loading branch information
rectalogic committed Apr 22, 2024
1 parent fe605ce commit 5c9be5a
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 3 deletions.
4 changes: 4 additions & 0 deletions src/MediaFX/encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -145,6 +145,10 @@ void Encoder::componentComplete()

bool Encoder::encode(const QAudioBuffer& audioBuffer, const QByteArray& videoData)
{
if (!m_isValid) {
emit encodingError();
return false;
}
AVPacket* videoPacket = m_videoStream->packet();
videoPacket->flags |= AV_PKT_FLAG_KEY;
// NOLINTNEXTLINE(cppcoreguidelines-pro-type-const-cast, cppcoreguidelines-pro-type-reinterpret-cast)
Expand Down
1 change: 0 additions & 1 deletion src/MediaFX/encoder.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@ class Encoder : public QObject, public QQmlParserStatus {
Encoder& operator=(Encoder&&) = delete;
~Encoder() override;

bool isValid() const { return m_isValid; }
void initialize(const RenderContext& renderContext);
const QString& outputFileName() const { return m_outputFileName; }
void setOutputFileName(const QString& outputFileName);
Expand Down
3 changes: 2 additions & 1 deletion src/MediaFX/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,8 +110,9 @@ int encoder(QGuiApplication& app, QCommandLineParser& parser)
renderSession->initialize(renderContext);

if (parser.isSet(u"exitOnWarning"_s)) {
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed, renderSession, &RenderSession::fatalError, Qt::QueuedConnection);
QObject::connect(&engine, &QQmlApplicationEngine::warnings, renderSession, &RenderSession::fatalError, Qt::QueuedConnection);
}
QObject::connect(&engine, &QQmlApplicationEngine::objectCreationFailed, renderSession, &RenderSession::fatalError, Qt::QueuedConnection);
engine.load(QUrl(u"qrc:/qt/qml/MediaFX/app-encoder.qml"_s));

return app.exec();
Expand Down
5 changes: 4 additions & 1 deletion tests/tst_encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
#include <QFile>
#include <QIODevice>
#include <QObject>
#include <QSignalSpy>
#include <QSize>
#include <QString>
#include <QSysInfo>
Expand Down Expand Up @@ -50,9 +51,10 @@ private slots:

const RenderContext renderContext(QUrl(), encodedFile.fileName(), QSize(160, 120), AVRational { 5, 1 }, 44100);
Encoder encoder;
QSignalSpy spy(&encoder, SIGNAL(encodingError()));
QVERIFY(spy.isValid());
encoder.setOutputFileName(renderContext.outputFileName());
encoder.initialize(renderContext);
QVERIFY(encoder.isValid());

QAudioFormat audioFormat;
audioFormat.setSampleFormat(QAudioFormat::Float);
Expand Down Expand Up @@ -95,6 +97,7 @@ private slots:
QVERIFY(encoder.encode(audioBuffer, videoData));
}
QVERIFY(encoder.finish());
QVERIFY(spy.empty());

QVERIFY(encodedFile.open(QIODevice::ReadOnly));
QByteArray encodedData(encodedFile.readAll());
Expand Down

0 comments on commit 5c9be5a

Please sign in to comment.