Merge pull request #6308 from jbroadus/issue-6302-gst-error-crash

Fix MoodbarPipeline crash on gstreamer error.
This commit is contained in:
John Maguire 2019-03-18 14:19:49 +00:00 committed by GitHub
commit 106bb73aec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 16 additions and 2 deletions

View File

@ -37,7 +37,8 @@ MoodbarPipeline::MoodbarPipeline(const QUrl& local_filename)
local_filename_(local_filename),
pipeline_(nullptr),
convert_element_(nullptr),
success_(false) {}
success_(false),
running_(false) {}
MoodbarPipeline::~MoodbarPipeline() { Cleanup(); }
@ -117,6 +118,7 @@ void MoodbarPipeline::Start() {
gst_object_unref(bus);
// Start playing
running_ = true;
gst_element_set_state(pipeline_, GST_STATE_PLAYING);
}
@ -135,6 +137,12 @@ void MoodbarPipeline::ReportError(GstMessage* msg) {
void MoodbarPipeline::NewPadCallback(GstElement*, GstPad* pad, gpointer data) {
MoodbarPipeline* self = reinterpret_cast<MoodbarPipeline*>(data);
if (!self->running_) {
qLog(Warning) << "Received gstreamer callback after pipeline has stopped.";
return;
}
GstPad* const audiopad =
gst_element_get_static_pad(self->convert_element_, "sink");
@ -152,7 +160,10 @@ void MoodbarPipeline::NewPadCallback(GstElement*, GstPad* pad, gpointer data) {
gst_structure_get_int(structure, "rate", &rate);
gst_caps_unref(caps);
self->builder_->Init(kBands, rate);
if (self->builder_ != nullptr)
self->builder_->Init(kBands, rate);
else
qLog(Error) << "Builder does not exist";
}
GstBusSyncReply MoodbarPipeline::BusCallbackSync(GstBus*, GstMessage* msg,
@ -177,6 +188,7 @@ GstBusSyncReply MoodbarPipeline::BusCallbackSync(GstBus*, GstMessage* msg,
void MoodbarPipeline::Stop(bool success) {
success_ = success;
running_ = false;
if (builder_ != nullptr) {
data_ = builder_->Finish(1000);
builder_.reset();
@ -189,6 +201,7 @@ void MoodbarPipeline::Cleanup() {
Q_ASSERT(QThread::currentThread() == thread());
Q_ASSERT(QThread::currentThread() != qApp->thread());
running_ = false;
if (pipeline_) {
GstBus* bus = gst_pipeline_get_bus(GST_PIPELINE(pipeline_));
gst_bus_set_sync_handler(bus, nullptr, nullptr, nullptr);

View File

@ -71,6 +71,7 @@ class MoodbarPipeline : public QObject {
std::unique_ptr<MoodbarBuilder> builder_;
bool success_;
bool running_;
QByteArray data_;
};