From 4f5bf1cc6f4bba7cef15fa4029c610146c48311a Mon Sep 17 00:00:00 2001 From: Jim Broadus Date: Tue, 12 Jan 2021 22:49:02 -0800 Subject: [PATCH] gstengine: Give pipelines unique names Currently, most pipelines are named "pipeline". Use a type string in combination with the stream id to give each pipeline a unique name. --- src/engines/gstenginepipeline.cpp | 6 +++--- src/engines/gstpipelinebase.cpp | 7 ++++--- src/engines/gstpipelinebase.h | 6 ++++-- src/transcoder/transcoder.cpp | 2 +- src/transcoder/transcoder.h | 5 ++++- 5 files changed, 16 insertions(+), 10 deletions(-) diff --git a/src/engines/gstenginepipeline.cpp b/src/engines/gstenginepipeline.cpp index 7808e4502..56cabd1d9 100644 --- a/src/engines/gstenginepipeline.cpp +++ b/src/engines/gstenginepipeline.cpp @@ -51,7 +51,7 @@ const int GstEnginePipeline::kEqBandFrequencies[] = { GstElementDeleter* GstEnginePipeline::sElementDeleter = nullptr; GstEnginePipeline::GstEnginePipeline(GstEngine* engine) - : GstPipelineBase(), + : GstPipelineBase("audio"), engine_(engine), valid_(false), sink_(GstEngine::kAutoSink), @@ -508,7 +508,7 @@ void GstEnginePipeline::MaybeLinkDecodeToAudio() { } bool GstEnginePipeline::InitFromString(const QString& pipeline) { - if (!Init("pipeline")) return false; + if (!Init()) return false; GstElement* new_bin = CreateDecodeBinFromString(pipeline.toLatin1().constData()); @@ -527,7 +527,7 @@ bool GstEnginePipeline::InitFromString(const QString& pipeline) { bool GstEnginePipeline::InitFromReq(const MediaPlaybackRequest& req, qint64 end_nanosec) { - if (!Init("pipeline")) return false; + if (!Init()) return false; current_ = req; QUrl url = current_.url_; diff --git a/src/engines/gstpipelinebase.cpp b/src/engines/gstpipelinebase.cpp index c28b415af..e6268c7e6 100644 --- a/src/engines/gstpipelinebase.cpp +++ b/src/engines/gstpipelinebase.cpp @@ -21,8 +21,8 @@ std::atomic GstPipelineBase::sId(1); -GstPipelineBase::GstPipelineBase() - : QObject(nullptr), pipeline_(nullptr), id_(sId++) {} +GstPipelineBase::GstPipelineBase(const QString& type) + : QObject(nullptr), pipeline_(nullptr), type_(type), id_(sId++) {} GstPipelineBase::~GstPipelineBase() { if (pipeline_) { @@ -31,7 +31,8 @@ GstPipelineBase::~GstPipelineBase() { } } -bool GstPipelineBase::Init(const QString& name) { +bool GstPipelineBase::Init() { + QString name = QString("%1-pipeline-%2").arg(type_).arg(id_); pipeline_ = gst_pipeline_new(name.toUtf8().constData()); return pipeline_ != nullptr; } diff --git a/src/engines/gstpipelinebase.h b/src/engines/gstpipelinebase.h index b5c738dd5..b6ef97cc5 100644 --- a/src/engines/gstpipelinebase.h +++ b/src/engines/gstpipelinebase.h @@ -24,10 +24,10 @@ class GstPipelineBase : public QObject { public: - GstPipelineBase(); + GstPipelineBase(const QString& type); virtual ~GstPipelineBase(); - virtual bool Init(const QString& name); + virtual bool Init(); // Globally unique across all pipelines. int id() const { return id_; } @@ -38,6 +38,8 @@ class GstPipelineBase : public QObject { GstElement* pipeline_; private: + const QString type_; + // Using == to compare two pipelines is a bad idea, because new ones often // get created in the same address as old ones. This ID will be unique for // each pipeline. diff --git a/src/transcoder/transcoder.cpp b/src/transcoder/transcoder.cpp index 4cc88064a..c9d8a1891 100644 --- a/src/transcoder/transcoder.cpp +++ b/src/transcoder/transcoder.cpp @@ -402,7 +402,7 @@ bool Transcoder::StartJob(const Job& job) { // Create the pipeline. // This should be a scoped_ptr, but scoped_ptr doesn't support custom // destructors. - if (!state->Init("pipeline")) return false; + if (!state->Init()) return false; // Create all the elements GstElement* src = CreateElement("filesrc", state->Pipeline()); diff --git a/src/transcoder/transcoder.h b/src/transcoder/transcoder.h index 7a5e5e0f9..eea458843 100644 --- a/src/transcoder/transcoder.h +++ b/src/transcoder/transcoder.h @@ -88,7 +88,10 @@ class Transcoder : public QObject { class JobState : public GstPipelineBase { public: JobState(const Job& job, Transcoder* parent) - : job_(job), parent_(parent), convert_element_(nullptr) {} + : GstPipelineBase("transcode"), + job_(job), + parent_(parent), + convert_element_(nullptr) {} void PostFinished(bool success); void ReportError(GstMessage* msg);