Skip to content

Commit

Permalink
MoodbarPipeline: Cleanup on finish
Browse files Browse the repository at this point in the history
  • Loading branch information
jonaski committed Jan 7, 2025
1 parent af525e4 commit c7830f6
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
19 changes: 18 additions & 1 deletion src/moodbar/moodbarpipeline.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,7 @@ QByteArray MoodbarPipeline::ToGstUrl(const QUrl &url) {

void MoodbarPipeline::Start() {

Q_ASSERT(QThread::currentThread() == thread());
Q_ASSERT(QThread::currentThread() != qApp->thread());

Utilities::SetThreadIOPriority(Utilities::IoPriority::IOPRIO_CLASS_IDLE);
Expand Down Expand Up @@ -208,6 +209,8 @@ GstBusSyncReply MoodbarPipeline::BusCallbackSync(GstBus *bus, GstMessage *messag

MoodbarPipeline *instance = reinterpret_cast<MoodbarPipeline*>(self);

if (!instance->running_) return GST_BUS_PASS;

switch (GST_MESSAGE_TYPE(message)) {
case GST_MESSAGE_EOS:
instance->Stop(true);
Expand All @@ -228,20 +231,34 @@ GstBusSyncReply MoodbarPipeline::BusCallbackSync(GstBus *bus, GstMessage *messag

void MoodbarPipeline::Stop(const bool success) {

success_ = success;
running_ = false;

QMetaObject::invokeMethod(this, "Finish", Qt::QueuedConnection, Q_ARG(bool, success));

}

void MoodbarPipeline::Finish(const bool success) {

Q_ASSERT(QThread::currentThread() == thread());
Q_ASSERT(QThread::currentThread() != qApp->thread());

success_ = success;

if (builder_) {
data_ = builder_->Finish(1000);
builder_.reset();
}

Cleanup();

Q_EMIT Finished(success);

}

void MoodbarPipeline::Cleanup() {

running_ = false;

if (pipeline_) {
GstBus *bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline_));
if (bus) {
Expand Down
4 changes: 2 additions & 2 deletions src/moodbar/moodbarpipeline.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,7 @@ class MoodbarPipeline : public QObject {
bool success() const { return success_; }
const QByteArray &data() const { return data_; }

public Q_SLOTS:
void Start();
Q_INVOKABLE void Start();

Q_SIGNALS:
void Finished(const bool success);
Expand All @@ -59,6 +58,7 @@ class MoodbarPipeline : public QObject {
QByteArray ToGstUrl(const QUrl &url);
void ReportError(GstMessage *msg);
void Stop(const bool success);
Q_INVOKABLE void Finish(const bool success);
void Cleanup();

static void NewPadCallback(GstElement *element, GstPad *pad, gpointer self);
Expand Down

0 comments on commit c7830f6

Please sign in to comment.