Add mutexes
This commit is contained in:
@@ -44,6 +44,7 @@
|
||||
#include <QUrl>
|
||||
|
||||
#include "core/shared_ptr.h"
|
||||
#include "core/mutex_protected.h"
|
||||
#include "enginemetadata.h"
|
||||
|
||||
class QTimer;
|
||||
@@ -59,7 +60,7 @@ class GstEnginePipeline : public QObject {
|
||||
~GstEnginePipeline() override;
|
||||
|
||||
// Globally unique across all pipelines.
|
||||
int id() const { return id_; }
|
||||
int id() const { return id_.value(); }
|
||||
|
||||
// Call these setters before Init
|
||||
void set_output_device(const QString &output, const QVariant &device);
|
||||
@@ -97,69 +98,63 @@ class GstEnginePipeline : public QObject {
|
||||
Q_INVOKABLE bool Seek(const qint64 nanosec);
|
||||
void SeekAsync(const qint64 nanosec);
|
||||
void SeekDelayed(const qint64 nanosec);
|
||||
void SetEBUR128LoudnessNormalizingGain_dB(const double ebur128_loudness_normalizing_gain_db);
|
||||
|
||||
void SetVolume(const uint volume_percent);
|
||||
void SetStereoBalance(const float value);
|
||||
void SetEqualizerParams(const int preamp, const QList<int> &band_gains);
|
||||
|
||||
void StartFader(const qint64 duration_nanosec, const QTimeLine::Direction direction = QTimeLine::Forward, const QEasingCurve::Type shape = QEasingCurve::Linear, const bool use_fudge_timer = true);
|
||||
void SetEBUR128LoudnessNormalizingGain_dB(const double ebur128_loudness_normalizing_gain_db);
|
||||
|
||||
// If this is set then it will be loaded automatically when playback finishes for gapless playback
|
||||
bool HasNextUrl() const;
|
||||
void PrepareNextUrl(const QUrl &media_url, const QUrl &stream_url, const QByteArray &gst_url, const qint64 beginning_nanosec, const qint64 end_nanosec);
|
||||
void SetNextUrl();
|
||||
bool has_next_valid_url() const { return next_stream_url_.isValid(); }
|
||||
|
||||
void SetSourceDevice(const QString &device) { source_device_ = device; }
|
||||
void SetSourceDevice(const QString &device);
|
||||
|
||||
void StartFader(const qint64 duration_nanosec, const QTimeLine::Direction direction = QTimeLine::Forward, const QEasingCurve::Type shape = QEasingCurve::Linear, const bool use_fudge_timer = true);
|
||||
|
||||
// Get information about the music playback
|
||||
QUrl media_url() const { return media_url_; }
|
||||
QUrl stream_url() const { return stream_url_; }
|
||||
double ebur128_loudness_normalizing_gain_db() const { return ebur128_loudness_normalizing_gain_db_; }
|
||||
QByteArray gst_url() const { return gst_url_; }
|
||||
QMutex *mutex_url() const { return &mutex_url_; }
|
||||
QUrl next_media_url() const { return next_media_url_; }
|
||||
QUrl next_stream_url() const { return next_stream_url_; }
|
||||
QByteArray next_gst_url() const { return next_gst_url_; }
|
||||
bool is_valid() const { return valid_; }
|
||||
QMutex *mutex_next_url() const { return &mutex_next_url_; }
|
||||
double ebur128_loudness_normalizing_gain_db() const { return ebur128_loudness_normalizing_gain_db_; }
|
||||
|
||||
// Please note that this method (unlike GstEngine's.position()) is multiple-section media unaware.
|
||||
qint64 position() const;
|
||||
// Please note that this method (unlike GstEngine's.length()) is multiple-section media unaware.
|
||||
qint64 length() const;
|
||||
// Returns this pipeline's state. May return GST_STATE_NULL if the state check timed out. The timeout value is a reasonable default.
|
||||
GstState state() const;
|
||||
qint64 segment_start() const { return segment_start_; }
|
||||
// Please note that this method (unlike GstEngine's.length()) is multiple-section media unaware.
|
||||
qint64 length() const;
|
||||
// Please note that this method (unlike GstEngine's.position()) is multiple-section media unaware.
|
||||
qint64 position() const;
|
||||
qint64 segment_start() const { return segment_start_.value(); }
|
||||
|
||||
// Don't allow the user to change the playback state (playing/paused) while the pipeline is buffering.
|
||||
bool is_buffering() const { return buffering_; }
|
||||
|
||||
QByteArray redirect_url() const { return redirect_url_; }
|
||||
|
||||
QString source_device() const { return source_device_; }
|
||||
bool is_buffering() const { return buffering_.value(); }
|
||||
|
||||
bool exclusive_mode() const { return exclusive_mode_; }
|
||||
|
||||
public Q_SLOTS:
|
||||
void SetFaderVolume(const qreal volume);
|
||||
QByteArray redirect_url() const { return redirect_url_; }
|
||||
QMutex *mutex_redirect_url() { return &mutex_redirect_url_; }
|
||||
|
||||
QString source_device() const { return source_device_; }
|
||||
|
||||
Q_SIGNALS:
|
||||
void SetStateFinished(const GstStateChangeReturn state_change_return);
|
||||
void Error(const int pipeline_id, const int domain, const int error_code, const QString &message, const QString &debug);
|
||||
|
||||
void EndOfStreamReached(const int pipeline_id, const bool has_next_track);
|
||||
void MetadataFound(const int pipeline_id, const EngineMetadata &bundle);
|
||||
|
||||
void AboutToFinish();
|
||||
void Finished();
|
||||
void VolumeChanged(const uint volume);
|
||||
void FaderFinished(const int pipeline_id);
|
||||
|
||||
void BufferingStarted();
|
||||
void BufferingProgress(const int percent);
|
||||
void BufferingFinished();
|
||||
|
||||
void AboutToFinish();
|
||||
|
||||
void Finished();
|
||||
|
||||
void SetStateFinished(const GstStateChangeReturn state);
|
||||
|
||||
protected:
|
||||
void timerEvent(QTimerEvent*) override;
|
||||
|
||||
@@ -199,27 +194,28 @@ class GstEnginePipeline : public QObject {
|
||||
void UpdateEqualizer();
|
||||
|
||||
void Disconnect();
|
||||
|
||||
void ResumeFaderAsync();
|
||||
|
||||
private Q_SLOTS:
|
||||
void SetStateAsyncFinished(const GstState state, const GstStateChangeReturn state_change);
|
||||
void SetStateAsyncFinished(const GstState state, const GstStateChangeReturn state_change_return);
|
||||
void SetFaderVolume(const qreal volume);
|
||||
void FaderTimelineFinished();
|
||||
|
||||
private:
|
||||
// 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;
|
||||
int id_;
|
||||
mutex_protected<int> id_;
|
||||
|
||||
QThreadPool set_state_threadpool_;
|
||||
|
||||
// General settings for the pipeline
|
||||
bool valid_;
|
||||
QString output_;
|
||||
QVariant device_;
|
||||
bool exclusive_mode_;
|
||||
bool volume_enabled_;
|
||||
bool fading_enabled_;
|
||||
bool strict_ssl_enabled_;
|
||||
mutex_protected<bool> strict_ssl_enabled_;
|
||||
|
||||
// Buffering
|
||||
quint64 buffer_duration_nanosec_;
|
||||
@@ -231,6 +227,7 @@ class GstEnginePipeline : public QObject {
|
||||
bool proxy_authentication_;
|
||||
QString proxy_user_;
|
||||
QString proxy_pass_;
|
||||
QMutex mutex_proxy_;
|
||||
|
||||
// Channels
|
||||
bool channels_enabled_;
|
||||
@@ -270,43 +267,52 @@ class GstEnginePipeline : public QObject {
|
||||
QUrl media_url_;
|
||||
QUrl stream_url_;
|
||||
QByteArray gst_url_;
|
||||
mutable QMutex mutex_url_;
|
||||
|
||||
QUrl next_media_url_;
|
||||
QUrl next_stream_url_;
|
||||
QByteArray next_gst_url_;
|
||||
mutable QMutex mutex_next_url_;
|
||||
|
||||
double ebur128_loudness_normalizing_gain_db_;
|
||||
|
||||
// These get called when there is a new audio buffer available
|
||||
QList<GstBufferConsumer*> buffer_consumers_;
|
||||
QMutex mutex_buffer_consumers_;
|
||||
qint64 segment_start_;
|
||||
bool segment_start_received_;
|
||||
|
||||
mutex_protected<qint64> segment_start_;
|
||||
mutex_protected<bool> segment_start_received_;
|
||||
GstSegment last_playbin_segment_{};
|
||||
|
||||
// If this is > 0 then the pipeline will be forced to stop when playback goes past this position.
|
||||
qint64 end_offset_nanosec_;
|
||||
mutex_protected<qint64> end_offset_nanosec_;
|
||||
|
||||
// We store the beginning and end for the preloading song too, so we can just carry on without reloading the file if the sections carry on from each other.
|
||||
qint64 next_beginning_offset_nanosec_;
|
||||
qint64 next_end_offset_nanosec_;
|
||||
mutex_protected<qint64> next_beginning_offset_nanosec_;
|
||||
mutex_protected<qint64> next_end_offset_nanosec_;
|
||||
|
||||
// Set temporarily when moving to the next contiguous section in a multipart file.
|
||||
bool ignore_next_seek_;
|
||||
mutex_protected<bool> ignore_next_seek_;
|
||||
|
||||
// Set temporarily when switching out the decode bin, so metadata doesn't get sent while the Player still thinks it's playing the last song
|
||||
bool ignore_tags_;
|
||||
mutex_protected<bool> ignore_tags_;
|
||||
|
||||
// When the gstreamer source requests a redirect we store the URL here and callers can pick it up after the state change to PLAYING fails.
|
||||
mutable QMutex mutex_redirect_url_;
|
||||
QByteArray redirect_url_;
|
||||
|
||||
// When we need to specify the device to use as source (for CD device)
|
||||
QString source_device_;
|
||||
QMutex mutex_source_device_;
|
||||
|
||||
// Seeking while the pipeline is in the READY state doesn't work, so we have to wait until it goes to PAUSED or PLAYING.
|
||||
// Also, we have to wait for the playbin to be connected.
|
||||
bool pipeline_connected_;
|
||||
bool pipeline_active_;
|
||||
mutex_protected<bool> pipeline_connected_;
|
||||
mutex_protected<bool> pipeline_active_;
|
||||
mutex_protected<bool> buffering_;
|
||||
|
||||
GstState pending_state_;
|
||||
qint64 pending_seek_nanosec_;
|
||||
mutex_protected<GstState> pending_state_;
|
||||
mutex_protected<qint64> pending_seek_nanosec_;
|
||||
|
||||
// We can only use gst_element_query_position() when the pipeline is in
|
||||
// PAUSED nor PLAYING state. Whenever we get a new position (e.g. after a correct call to gst_element_query_position() or after a seek), we store
|
||||
@@ -314,15 +320,14 @@ class GstEnginePipeline : public QObject {
|
||||
mutable gint64 last_known_position_ns_;
|
||||
|
||||
// Complete the transition to the next song when it starts playing
|
||||
bool next_uri_set_;
|
||||
bool next_uri_reset_;
|
||||
mutex_protected<bool> next_uri_set_;
|
||||
mutex_protected<bool> next_uri_reset_;
|
||||
|
||||
bool volume_set_;
|
||||
gdouble volume_internal_;
|
||||
uint volume_percent_;
|
||||
|
||||
bool buffering_;
|
||||
mutex_protected<bool> volume_set_;
|
||||
mutex_protected<gdouble> volume_internal_;
|
||||
mutex_protected<uint> volume_percent_;
|
||||
|
||||
mutex_protected<bool> fader_active_;
|
||||
SharedPtr<QTimeLine> fader_;
|
||||
QBasicTimer fader_fudge_timer_;
|
||||
bool use_fudge_timer_;
|
||||
@@ -351,16 +356,10 @@ class GstEnginePipeline : public QObject {
|
||||
glong about_to_finish_cb_id_;
|
||||
glong notify_volume_cb_id_;
|
||||
|
||||
QThreadPool set_state_threadpool_;
|
||||
|
||||
GstSegment last_playbin_segment_{};
|
||||
|
||||
bool logged_unsupported_analyzer_format_;
|
||||
|
||||
bool about_to_finish_;
|
||||
|
||||
bool finish_requested_;
|
||||
bool finished_;
|
||||
mutex_protected<bool> about_to_finish_;
|
||||
mutex_protected<bool> finish_requested_;
|
||||
mutex_protected<bool> finished_;
|
||||
};
|
||||
|
||||
using GstEnginePipelinePtr = SharedPtr<GstEnginePipeline>;
|
||||
|
||||
Reference in New Issue
Block a user