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.
This commit is contained in:
Jim Broadus 2021-01-12 22:49:02 -08:00 committed by John Maguire
parent 5ffdb7d98c
commit 4f5bf1cc6f
5 changed files with 16 additions and 10 deletions

View File

@ -51,7 +51,7 @@ const int GstEnginePipeline::kEqBandFrequencies[] = {
GstElementDeleter* GstEnginePipeline::sElementDeleter = nullptr; GstElementDeleter* GstEnginePipeline::sElementDeleter = nullptr;
GstEnginePipeline::GstEnginePipeline(GstEngine* engine) GstEnginePipeline::GstEnginePipeline(GstEngine* engine)
: GstPipelineBase(), : GstPipelineBase("audio"),
engine_(engine), engine_(engine),
valid_(false), valid_(false),
sink_(GstEngine::kAutoSink), sink_(GstEngine::kAutoSink),
@ -508,7 +508,7 @@ void GstEnginePipeline::MaybeLinkDecodeToAudio() {
} }
bool GstEnginePipeline::InitFromString(const QString& pipeline) { bool GstEnginePipeline::InitFromString(const QString& pipeline) {
if (!Init("pipeline")) return false; if (!Init()) return false;
GstElement* new_bin = GstElement* new_bin =
CreateDecodeBinFromString(pipeline.toLatin1().constData()); CreateDecodeBinFromString(pipeline.toLatin1().constData());
@ -527,7 +527,7 @@ bool GstEnginePipeline::InitFromString(const QString& pipeline) {
bool GstEnginePipeline::InitFromReq(const MediaPlaybackRequest& req, bool GstEnginePipeline::InitFromReq(const MediaPlaybackRequest& req,
qint64 end_nanosec) { qint64 end_nanosec) {
if (!Init("pipeline")) return false; if (!Init()) return false;
current_ = req; current_ = req;
QUrl url = current_.url_; QUrl url = current_.url_;

View File

@ -21,8 +21,8 @@
std::atomic<int> GstPipelineBase::sId(1); std::atomic<int> GstPipelineBase::sId(1);
GstPipelineBase::GstPipelineBase() GstPipelineBase::GstPipelineBase(const QString& type)
: QObject(nullptr), pipeline_(nullptr), id_(sId++) {} : QObject(nullptr), pipeline_(nullptr), type_(type), id_(sId++) {}
GstPipelineBase::~GstPipelineBase() { GstPipelineBase::~GstPipelineBase() {
if (pipeline_) { 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()); pipeline_ = gst_pipeline_new(name.toUtf8().constData());
return pipeline_ != nullptr; return pipeline_ != nullptr;
} }

View File

@ -24,10 +24,10 @@
class GstPipelineBase : public QObject { class GstPipelineBase : public QObject {
public: public:
GstPipelineBase(); GstPipelineBase(const QString& type);
virtual ~GstPipelineBase(); virtual ~GstPipelineBase();
virtual bool Init(const QString& name); virtual bool Init();
// Globally unique across all pipelines. // Globally unique across all pipelines.
int id() const { return id_; } int id() const { return id_; }
@ -38,6 +38,8 @@ class GstPipelineBase : public QObject {
GstElement* pipeline_; GstElement* pipeline_;
private: private:
const QString type_;
// Using == to compare two pipelines is a bad idea, because new ones often // 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 // get created in the same address as old ones. This ID will be unique for
// each pipeline. // each pipeline.

View File

@ -402,7 +402,7 @@ bool Transcoder::StartJob(const Job& job) {
// Create the pipeline. // Create the pipeline.
// This should be a scoped_ptr, but scoped_ptr doesn't support custom // This should be a scoped_ptr, but scoped_ptr doesn't support custom
// destructors. // destructors.
if (!state->Init("pipeline")) return false; if (!state->Init()) return false;
// Create all the elements // Create all the elements
GstElement* src = CreateElement("filesrc", state->Pipeline()); GstElement* src = CreateElement("filesrc", state->Pipeline());

View File

@ -88,7 +88,10 @@ class Transcoder : public QObject {
class JobState : public GstPipelineBase { class JobState : public GstPipelineBase {
public: public:
JobState(const Job& job, Transcoder* parent) 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 PostFinished(bool success);
void ReportError(GstMessage* msg); void ReportError(GstMessage* msg);