Wait for set state to finish before deleting pipeline
Setting state to GST_STATE_NULL sometimes blocks, to fix this use the threadpool to set the state to NULL and wait with deleting the pipeline until the state is changed. This fixes blocking the main thread when switching Spotify songs.
This commit is contained in:
@@ -35,18 +35,19 @@
|
||||
#include <QFuture>
|
||||
#include <QByteArray>
|
||||
#include <QList>
|
||||
#include <QMap>
|
||||
#include <QString>
|
||||
#include <QUrl>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "enginebase.h"
|
||||
#include "gststartup.h"
|
||||
#include "gstenginepipeline.h"
|
||||
#include "gstbufferconsumer.h"
|
||||
|
||||
class QTimer;
|
||||
class QTimerEvent;
|
||||
class TaskManager;
|
||||
class GstEnginePipeline;
|
||||
|
||||
class GstEngine : public EngineBase, public GstBufferConsumer {
|
||||
Q_OBJECT
|
||||
@@ -63,7 +64,7 @@ class GstEngine : public EngineBase, public GstBufferConsumer {
|
||||
State state() const override;
|
||||
void StartPreloading(const QUrl &media_url, const QUrl &stream_url, const bool force_stop_at_end, const qint64 beginning_nanosec, const qint64 end_nanosec) override;
|
||||
bool Load(const QUrl &media_url, const QUrl &stream_url, const EngineBase::TrackChangeFlags change, const bool force_stop_at_end, const quint64 beginning_nanosec, const qint64 end_nanosec, const std::optional<double> ebur128_integrated_loudness_lufs) override;
|
||||
bool Play(const quint64 offset_nanosec) override;
|
||||
bool Play(const bool pause, const quint64 offset_nanosec) override;
|
||||
void Stop(const bool stop_after = false) override;
|
||||
void Pause() override;
|
||||
void Unpause() override;
|
||||
@@ -115,26 +116,31 @@ class GstEngine : public EngineBase, public GstBufferConsumer {
|
||||
void HandlePipelineError(const int pipeline_id, const int domain, const int error_code, const QString &message, const QString &debugstr);
|
||||
void NewMetaData(const int pipeline_id, const EngineMetadata &engine_metadata);
|
||||
void AddBufferToScope(GstBuffer *buf, const int pipeline_id, const QString &format);
|
||||
void FadeoutFinished();
|
||||
void FadeoutFinished(const int pipeline_id);
|
||||
void FadeoutPauseFinished();
|
||||
void SeekNow();
|
||||
void PlayDone(const GstStateChangeReturn ret, const quint64, const int);
|
||||
void PlayDone(const GstStateChangeReturn ret, const bool pause, const quint64 offset_nanosec, const int pipeline_id);
|
||||
|
||||
void BufferingStarted();
|
||||
void BufferingProgress(int percent);
|
||||
void BufferingFinished();
|
||||
|
||||
void PipelineFinished(const int pipeline_id);
|
||||
|
||||
private:
|
||||
QByteArray FixupUrl(const QUrl &url);
|
||||
|
||||
void StartFadeout();
|
||||
void StartFadeoutPause();
|
||||
void StopFadeoutPause();
|
||||
|
||||
void StartTimers();
|
||||
void StopTimers();
|
||||
|
||||
SharedPtr<GstEnginePipeline> CreatePipeline();
|
||||
SharedPtr<GstEnginePipeline> CreatePipeline(const QUrl &media_url, const QUrl &stream_url, const QByteArray &gst_url, const qint64 end_nanosec, const double ebur128_loudness_normalizing_gain_db);
|
||||
GstEnginePipelinePtr CreatePipeline();
|
||||
GstEnginePipelinePtr CreatePipeline(const QUrl &media_url, const QUrl &stream_url, const QByteArray &gst_url, const qint64 end_nanosec, const double ebur128_loudness_normalizing_gain_db);
|
||||
|
||||
void FinishPipeline(GstEnginePipelinePtr pipeline);
|
||||
|
||||
void UpdateScope(int chunk_length);
|
||||
|
||||
@@ -142,6 +148,8 @@ class GstEngine : public EngineBase, public GstBufferConsumer {
|
||||
static void StreamDiscoveryFinished(GstDiscoverer*, gpointer);
|
||||
static QString GSTdiscovererErrorMessage(GstDiscovererResult result);
|
||||
|
||||
bool ExclusivePipelineActive() const;
|
||||
|
||||
private:
|
||||
SharedPtr<TaskManager> task_manager_;
|
||||
GstStartup *gst_startup_;
|
||||
@@ -149,9 +157,10 @@ class GstEngine : public EngineBase, public GstBufferConsumer {
|
||||
|
||||
int buffering_task_id_;
|
||||
|
||||
SharedPtr<GstEnginePipeline> current_pipeline_;
|
||||
SharedPtr<GstEnginePipeline> fadeout_pipeline_;
|
||||
SharedPtr<GstEnginePipeline> fadeout_pause_pipeline_;
|
||||
GstEnginePipelinePtr current_pipeline_;
|
||||
QMap<int, GstEnginePipelinePtr> fadeout_pipelines_;
|
||||
GstEnginePipelinePtr fadeout_pause_pipeline_;
|
||||
QMap<int, GstEnginePipelinePtr> old_pipelines_;
|
||||
|
||||
QList<GstBufferConsumer*> buffer_consumers_;
|
||||
|
||||
@@ -171,8 +180,7 @@ class GstEngine : public EngineBase, public GstBufferConsumer {
|
||||
|
||||
int timer_id_;
|
||||
|
||||
bool is_fading_out_to_pause_;
|
||||
bool has_faded_out_;
|
||||
bool has_faded_out_to_pause_;
|
||||
|
||||
int scope_chunk_;
|
||||
bool have_new_buffer_;
|
||||
@@ -181,6 +189,10 @@ class GstEngine : public EngineBase, public GstBufferConsumer {
|
||||
|
||||
int discovery_finished_cb_id_;
|
||||
int discovery_discovered_cb_id_;
|
||||
|
||||
State delayed_state_;
|
||||
bool delayed_state_pause_;
|
||||
quint64 delayed_state_offset_nanosec_;
|
||||
};
|
||||
|
||||
#endif // GSTENGINE_H
|
||||
|
||||
Reference in New Issue
Block a user