Skip to content

Commit

Permalink
Add clipEnded and finishEncoding signals
Browse files Browse the repository at this point in the history
  • Loading branch information
rectalogic committed Nov 29, 2023
1 parent 68a640a commit 71989c3
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 11 deletions.
1 change: 1 addition & 0 deletions src/mediafx/clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ void Clip::stop()
initializeNextClipTime();
setActive(false);
m_stopped = true;
emit clipEnded();
}

void Clip::setActive(bool active)
Expand Down
1 change: 1 addition & 0 deletions src/mediafx/clip.h
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,7 @@ class Clip : public QObject, public QQmlParserStatus {
void clipStartChanged();
void clipEndChanged();
void activeChanged(bool);
void clipEnded();

protected slots:
virtual void onActiveChanged(bool active) {};
Expand Down
1 change: 0 additions & 1 deletion src/mediafx/encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@
#include <QDebug>
#include <QMessageLogContext>
#include <QString>
#include <QStringLiteral>
#include <errno.h>
#include <fcntl.h>
#include <stdlib.h>
Expand Down
3 changes: 2 additions & 1 deletion src/mediafx/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
#include <QCommandLineParser>
#include <QGuiApplication>
#include <QMessageLogContext>
#include <QString>
#include <QStringList>
#include <QStringLiteral>
#include <QUrl>
Expand Down Expand Up @@ -77,7 +78,7 @@ int main(int argc, char* argv[])
command = parser.value(qSL("command"));
if (command == "ffplay") {
// XXX need to handle audio eventually
command = qSL("ffplay -f rawvideo -video_size ${MEDIAFX_FRAMESIZE} -pixel_format rgb0 -framerate ${MEDIAFX_FRAMERATE} -i pipe:${MEDIAFX_VIDEOFD}");
command = qSL("ffplay -autoexit -f rawvideo -video_size ${MEDIAFX_FRAMESIZE} -pixel_format rgb0 -framerate ${MEDIAFX_FRAMERATE} -i pipe:${MEDIAFX_VIDEOFD}");
} else if (command == "ffmpeg") {
if (!parser.isSet(qSL("output"))) {
parser.showHelp(1);
Expand Down
9 changes: 9 additions & 0 deletions src/mediafx/mediafx.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,17 @@

#include "mediafx.h"
#include "clip.h"
#include "session.h"
#include <QObject>
struct Interval;

MediaFX::MediaFX(Session* session, QObject* parent)
: QObject(parent)
, m_session(session)
{
connect(this, &MediaFX::finishEncoding, m_session, [this]() { emit this->session()->exitApp(0); });
}

MediaFX* MediaFX::singletonInstance()
{
return MediaFXForeign::s_singletonInstance;
Expand Down
11 changes: 4 additions & 7 deletions src/mediafx/mediafx.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,16 +29,10 @@ struct Interval;

class MediaFX : public QObject {
Q_OBJECT
QML_ELEMENT
QML_SINGLETON

public:
using QObject::QObject;
MediaFX(Session* session, QObject* parent = nullptr)
: QObject(parent)
, m_session(session)
{
}
MediaFX(Session* session, QObject* parent = nullptr);

static MediaFX* singletonInstance();

Expand All @@ -49,6 +43,9 @@ class MediaFX : public QObject {

bool renderVideoFrame(const Interval& frameTimeRange);

signals:
void finishEncoding();

private:
Session* m_session;
QList<Clip*> activeClips;
Expand Down
5 changes: 5 additions & 0 deletions src/mediafx/video_clip.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -92,6 +92,11 @@ bool VideoClip::prepareNextVideoFrame()
return true;
}
}
// No buffered frames and state is ended
if (mediaPlayer.mediaStatus() == QMediaPlayer::EndOfMedia) {
stop();
return false;
}
rateControl();
return false;
}
Expand Down
2 changes: 0 additions & 2 deletions tests/tst_encoder.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,7 @@
*/

#include "encoder.h"
#include <QDebug>
#include <QObject>
#include <QString>
#include <QStringLiteral>
#include <QtTest>

Expand Down

0 comments on commit 71989c3

Please sign in to comment.