GstEngine: Move CreateElement() to GstEnginePipeline

This commit is contained in:
Jonas Kvinge
2021-10-16 21:28:56 +02:00
parent 6d7a01fb4e
commit c3ce6cff72
4 changed files with 195 additions and 107 deletions

View File

@@ -45,7 +45,6 @@
#include <QUrl>
class QTimerEvent;
class GstEngine;
class GstBufferConsumer;
namespace Engine {
@@ -57,7 +56,7 @@ class GstEnginePipeline : public QObject {
Q_OBJECT
public:
explicit GstEnginePipeline(GstEngine *engine, QObject *parent = nullptr);
explicit GstEnginePipeline(QObject *parent = nullptr);
~GstEnginePipeline() override;
// Globally unique across all pipelines.
@@ -76,7 +75,7 @@ class GstEnginePipeline : public QObject {
void set_channels(const bool enabled, const int channels);
// Creates the pipeline, returns false on error
bool InitFromUrl(const QByteArray &stream_url, const QUrl &original_url, const qint64 end_nanosec);
bool InitFromUrl(const QByteArray &stream_url, const QUrl &original_url, const qint64 end_nanosec, QString &error);
// GstBufferConsumers get fed audio data. Thread-safe.
void AddBufferConsumer(GstBufferConsumer *consumer);
@@ -124,11 +123,11 @@ class GstEnginePipeline : public QObject {
void SetVolumeModifier(qreal mod);
signals:
void Error(int pipeline_id, QString message, const int domain, const int error_code);
void EndOfStreamReached(int pipeline_id, bool has_next_track);
void MetadataFound(int pipeline_id, const Engine::SimpleMetaBundle &bundle);
// This indicates an error, delegated from GStreamer, in the pipeline.
// The message, domain and error_code are related to GStreamer's GError.
void Error(int pipeline_id, QString message, int domain, int error_code);
void FaderFinished();
void BufferingStarted();
@@ -139,7 +138,8 @@ class GstEnginePipeline : public QObject {
void timerEvent(QTimerEvent*) override;
private:
bool InitAudioBin();
GstElement *CreateElement(const QString &factory_name, const QString &name, GstElement *bin, QString &error);
bool InitAudioBin(QString &error);
// Static callbacks. The GstEnginePipeline instance is passed in the last argument.
static GstPadProbeReturn EventHandoffCallback(GstPad*, GstPadProbeInfo*, gpointer);
@@ -176,8 +176,6 @@ class GstEnginePipeline : public QObject {
static const int kEqBandCount;
static const int kEqBandFrequencies[];
GstEngine *engine_;
// 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.
// Threading warning: access to the static ID field isn't protected by a mutex because all pipeline creation is currently done in the main thread.
static int sId;