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;
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_;

View File

@ -21,8 +21,8 @@
std::atomic<int> 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;
}

View File

@ -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.

View File

@ -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());

View File

@ -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);