2010-04-11 21:47:21 +02:00
|
|
|
/* This file is part of Clementine.
|
2010-11-20 14:27:10 +01:00
|
|
|
Copyright 2010, David Sansome <me@davidsansome.com>
|
2010-04-11 21:47:21 +02:00
|
|
|
|
|
|
|
Clementine is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Clementine is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Clementine. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef GSTENGINEPIPELINE_H
|
|
|
|
#define GSTENGINEPIPELINE_H
|
|
|
|
|
2010-05-15 19:55:36 +02:00
|
|
|
#include <QBasicTimer>
|
2010-08-04 14:13:43 +02:00
|
|
|
#include <QFuture>
|
2010-06-06 16:06:23 +02:00
|
|
|
#include <QMutex>
|
2010-08-04 14:13:43 +02:00
|
|
|
#include <QObject>
|
|
|
|
#include <QTimeLine>
|
|
|
|
#include <QUrl>
|
2010-04-11 21:47:21 +02:00
|
|
|
|
|
|
|
#include <gst/gst.h>
|
2010-05-19 15:26:23 +02:00
|
|
|
#include <boost/scoped_ptr.hpp>
|
2010-04-11 21:47:21 +02:00
|
|
|
|
|
|
|
#include "engine_fwd.h"
|
|
|
|
|
2010-09-23 00:22:02 +02:00
|
|
|
class GstElementDeleter;
|
2010-04-11 21:47:21 +02:00
|
|
|
class GstEngine;
|
2010-06-06 16:06:23 +02:00
|
|
|
class BufferConsumer;
|
2010-04-11 21:47:21 +02:00
|
|
|
|
2012-01-23 15:58:10 +01:00
|
|
|
struct GstQueue;
|
2010-05-08 19:39:12 +02:00
|
|
|
struct GstURIDecodeBin;
|
|
|
|
|
2010-04-11 21:47:21 +02:00
|
|
|
class GstEnginePipeline : public QObject {
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
2010-04-21 13:14:12 +02:00
|
|
|
GstEnginePipeline(GstEngine* engine);
|
2010-04-11 21:47:21 +02:00
|
|
|
~GstEnginePipeline();
|
|
|
|
|
2011-03-20 22:40:53 +01:00
|
|
|
// Globally unique across all pipelines.
|
|
|
|
int id() const { return id_; }
|
|
|
|
|
2010-04-11 21:47:21 +02:00
|
|
|
// Call these setters before Init
|
|
|
|
void set_output_device(const QString& sink, const QString& device);
|
2010-05-23 15:07:15 +02:00
|
|
|
void set_replaygain(bool enabled, int mode, float preamp, bool compression);
|
2011-02-13 19:29:27 +01:00
|
|
|
void set_buffer_duration_nanosec(qint64 duration_nanosec);
|
2010-04-11 21:47:21 +02:00
|
|
|
|
|
|
|
// Creates the pipeline, returns false on error
|
2011-03-06 17:35:47 +01:00
|
|
|
bool InitFromUrl(const QUrl& url, qint64 end_nanosec);
|
2010-07-14 13:16:56 +02:00
|
|
|
bool InitFromString(const QString& pipeline);
|
2010-04-11 21:47:21 +02:00
|
|
|
|
2010-06-06 16:06:23 +02:00
|
|
|
// BufferConsumers get fed audio data. Thread-safe.
|
|
|
|
void AddBufferConsumer(BufferConsumer* consumer);
|
|
|
|
void RemoveBufferConsumer(BufferConsumer* consumer);
|
|
|
|
void RemoveAllBufferConsumers();
|
|
|
|
|
2010-04-11 21:47:21 +02:00
|
|
|
// Control the music playback
|
2011-05-04 00:38:24 +02:00
|
|
|
QFuture<GstStateChangeReturn> SetState(GstState state);
|
2011-03-06 19:11:53 +01:00
|
|
|
Q_INVOKABLE bool Seek(qint64 nanosec);
|
2010-04-11 21:47:21 +02:00
|
|
|
void SetEqualizerEnabled(bool enabled);
|
|
|
|
void SetEqualizerParams(int preamp, const QList<int>& band_gains);
|
|
|
|
void SetVolume(int percent);
|
2011-02-13 19:29:27 +01:00
|
|
|
void StartFader(qint64 duration_nanosec,
|
2010-04-12 01:03:39 +02:00
|
|
|
QTimeLine::Direction direction = QTimeLine::Forward,
|
|
|
|
QTimeLine::CurveShape shape = QTimeLine::LinearCurve);
|
2010-04-11 21:47:21 +02:00
|
|
|
|
2010-05-08 19:39:12 +02:00
|
|
|
// If this is set then it will be loaded automatically when playback finishes
|
|
|
|
// for gapless playback
|
2011-03-06 17:35:47 +01:00
|
|
|
void SetNextUrl(const QUrl& url, qint64 beginning_nanosec, qint64 end_nanosec);
|
2011-01-03 19:03:15 +01:00
|
|
|
bool has_next_valid_url() const { return next_url_.isValid(); }
|
2010-05-08 19:39:12 +02:00
|
|
|
|
2010-04-11 21:47:21 +02:00
|
|
|
// Get information about the music playback
|
2010-05-08 19:39:12 +02:00
|
|
|
QUrl url() const { return url_; }
|
2010-04-11 21:47:21 +02:00
|
|
|
bool is_valid() const { return valid_; }
|
2011-01-02 19:53:45 +01:00
|
|
|
// Please note that this method (unlike GstEngine's.position()) is
|
|
|
|
// multiple-section media unaware.
|
2010-04-11 21:47:21 +02:00
|
|
|
qint64 position() const;
|
2011-01-02 19:53:45 +01:00
|
|
|
// Please note that this method (unlike GstEngine's.length()) is
|
|
|
|
// multiple-section media unaware.
|
2010-04-11 21:47:21 +02:00
|
|
|
qint64 length() const;
|
2011-03-12 14:24:30 +01:00
|
|
|
// Returns this pipeline's state. May return GST_STATE_NULL if the state check
|
|
|
|
// timed out. The timeout value is a reasonable default.
|
2010-04-11 21:47:21 +02:00
|
|
|
GstState state() const;
|
2010-07-11 15:31:03 +02:00
|
|
|
qint64 segment_start() const { return segment_start_; }
|
2010-04-11 21:47:21 +02:00
|
|
|
|
2012-01-23 15:58:10 +01:00
|
|
|
// Don't allow the user to change the playback state (playing/paused) while
|
|
|
|
// the pipeline is buffering.
|
|
|
|
bool is_buffering() const { return buffering_; }
|
|
|
|
|
2010-06-23 13:47:54 +02:00
|
|
|
QUrl redirect_url() const { return redirect_url_; }
|
|
|
|
|
2011-08-10 00:49:36 +02:00
|
|
|
QString source_device() const { return source_device_; }
|
|
|
|
|
2010-04-11 23:40:26 +02:00
|
|
|
public slots:
|
|
|
|
void SetVolumeModifier(qreal mod);
|
|
|
|
|
2010-04-11 21:47:21 +02:00
|
|
|
signals:
|
2011-03-20 22:40:53 +01:00
|
|
|
void EndOfStreamReached(int pipeline_id, bool has_next_track);
|
|
|
|
void MetadataFound(int pipeline_id, const Engine::SimpleMetaBundle& bundle);
|
2011-03-10 19:01:35 +01:00
|
|
|
// This indicates an error, delegated from GStreamer, in the pipeline.
|
|
|
|
// The message, domain and error_code are related to GStreamer's GError.
|
2011-03-20 22:40:53 +01:00
|
|
|
void Error(int pipeline_id, const QString& message, int domain, int error_code);
|
2010-04-12 01:03:39 +02:00
|
|
|
void FaderFinished();
|
2010-04-11 21:47:21 +02:00
|
|
|
|
2012-01-23 15:58:10 +01:00
|
|
|
void BufferingStarted();
|
|
|
|
void BufferingProgress(int percent);
|
|
|
|
void BufferingFinished();
|
|
|
|
|
2010-05-15 19:55:36 +02:00
|
|
|
protected:
|
|
|
|
void timerEvent(QTimerEvent *);
|
|
|
|
|
2010-04-11 21:47:21 +02:00
|
|
|
private:
|
|
|
|
// Static callbacks. The GstEnginePipeline instance is passed in the last
|
|
|
|
// argument.
|
|
|
|
static GstBusSyncReply BusCallbackSync(GstBus*, GstMessage*, gpointer);
|
|
|
|
static gboolean BusCallback(GstBus*, GstMessage*, gpointer);
|
2010-05-08 15:54:12 +02:00
|
|
|
static void NewPadCallback(GstElement*, GstPad*, gpointer);
|
2010-04-12 03:59:21 +02:00
|
|
|
static bool HandoffCallback(GstPad*, GstBuffer*, gpointer);
|
2010-07-11 15:31:03 +02:00
|
|
|
static bool EventHandoffCallback(GstPad*, GstEvent*, gpointer);
|
2010-05-08 19:39:12 +02:00
|
|
|
static void SourceDrainedCallback(GstURIDecodeBin*, gpointer);
|
2011-08-10 00:49:36 +02:00
|
|
|
static void SourceSetupCallback(GstURIDecodeBin*, GParamSpec *pspec, gpointer);
|
2011-03-10 19:01:35 +01:00
|
|
|
|
2010-04-15 01:59:11 +02:00
|
|
|
void TagMessageReceived(GstMessage*);
|
2010-04-19 14:04:35 +02:00
|
|
|
void ErrorMessageReceived(GstMessage*);
|
2010-08-28 20:48:16 +02:00
|
|
|
void ElementMessageReceived(GstMessage*);
|
2011-03-06 19:11:53 +01:00
|
|
|
void StateChangedMessageReceived(GstMessage*);
|
2012-01-23 15:58:10 +01:00
|
|
|
void BufferingMessageReceived(GstMessage*);
|
2011-03-10 19:01:35 +01:00
|
|
|
|
2010-06-23 13:47:54 +02:00
|
|
|
QString ParseTag(GstTagList* list, const char* tag) const;
|
2010-04-11 21:47:21 +02:00
|
|
|
|
2010-07-14 13:16:56 +02:00
|
|
|
bool Init();
|
|
|
|
GstElement* CreateDecodeBinFromString(const char* pipeline);
|
|
|
|
|
2010-04-11 23:40:26 +02:00
|
|
|
void UpdateVolume();
|
2010-07-12 22:55:09 +02:00
|
|
|
void UpdateEqualizer();
|
2011-09-25 20:24:44 +02:00
|
|
|
bool ReplaceDecodeBin(GstElement* new_bin);
|
2010-05-08 19:39:12 +02:00
|
|
|
bool ReplaceDecodeBin(const QUrl& url);
|
2010-04-11 23:40:26 +02:00
|
|
|
|
2011-03-06 17:35:47 +01:00
|
|
|
void TransitionToNext();
|
|
|
|
|
2011-11-28 19:11:09 +01:00
|
|
|
// If the decodebin is special (ie. not really a uridecodebin) then it'll have
|
|
|
|
// a src pad immediately and we can link it after everything's created.
|
|
|
|
void MaybeLinkDecodeToAudio();
|
|
|
|
|
2010-05-15 19:55:36 +02:00
|
|
|
private slots:
|
|
|
|
void FaderTimelineFinished();
|
|
|
|
|
2010-04-11 21:47:21 +02:00
|
|
|
private:
|
2010-05-15 19:55:36 +02:00
|
|
|
static const int kGstStateTimeoutNanosecs;
|
|
|
|
static const int kFaderFudgeMsec;
|
2010-07-12 22:55:09 +02:00
|
|
|
static const int kEqBandCount;
|
|
|
|
static const int kEqBandFrequencies[];
|
2010-04-11 21:47:21 +02:00
|
|
|
|
2010-09-23 00:22:02 +02:00
|
|
|
static GstElementDeleter* sElementDeleter;
|
|
|
|
|
2010-04-21 13:14:12 +02:00
|
|
|
GstEngine* engine_;
|
|
|
|
|
2011-03-20 22:40:53 +01:00
|
|
|
// 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_;
|
|
|
|
|
2010-06-06 16:06:23 +02:00
|
|
|
// General settings for the pipeline
|
2010-04-11 21:47:21 +02:00
|
|
|
bool valid_;
|
|
|
|
QString sink_;
|
|
|
|
QString device_;
|
|
|
|
|
2010-06-06 16:06:23 +02:00
|
|
|
// These get called when there is a new audio buffer available
|
|
|
|
QList<BufferConsumer*> buffer_consumers_;
|
|
|
|
QMutex buffer_consumers_mutex_;
|
2010-07-11 15:31:03 +02:00
|
|
|
qint64 segment_start_;
|
2010-07-12 21:09:59 +02:00
|
|
|
bool segment_start_received_;
|
2011-04-17 16:11:37 +02:00
|
|
|
bool emit_track_ended_on_segment_start_;
|
2010-06-06 16:06:23 +02:00
|
|
|
|
2010-07-12 22:55:09 +02:00
|
|
|
// Equalizer
|
|
|
|
bool eq_enabled_;
|
|
|
|
int eq_preamp_;
|
|
|
|
QList<int> eq_band_gains_;
|
|
|
|
|
2010-06-06 16:06:23 +02:00
|
|
|
// ReplayGain
|
2010-05-23 15:07:15 +02:00
|
|
|
bool rg_enabled_;
|
|
|
|
int rg_mode_;
|
|
|
|
float rg_preamp_;
|
|
|
|
bool rg_compression_;
|
2012-01-23 15:58:10 +01:00
|
|
|
|
2011-02-13 19:29:27 +01:00
|
|
|
quint64 buffer_duration_nanosec_;
|
2012-01-23 15:58:10 +01:00
|
|
|
bool buffering_;
|
2010-05-23 15:07:15 +02:00
|
|
|
|
2010-06-06 16:06:23 +02:00
|
|
|
// The URL that is currently playing, and the URL that is to be preloaded
|
|
|
|
// when the current track is close to finishing.
|
2010-05-08 19:39:12 +02:00
|
|
|
QUrl url_;
|
|
|
|
QUrl next_url_;
|
|
|
|
|
2011-03-06 17:35:47 +01:00
|
|
|
// If this is > 0 then the pipeline will be forced to stop when playback goes
|
|
|
|
// past this position.
|
|
|
|
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_;
|
|
|
|
|
|
|
|
// Set temporarily when moving to the next contiguous section in a multi-part
|
|
|
|
// file.
|
|
|
|
bool ignore_next_seek_;
|
|
|
|
|
2010-09-04 15:50:53 +02:00
|
|
|
// 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_;
|
|
|
|
|
2010-06-23 13:47:54 +02:00
|
|
|
// 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.
|
|
|
|
QUrl redirect_url_;
|
|
|
|
|
2011-08-10 00:49:36 +02:00
|
|
|
// When we need to specify the device to use as source (for CD device)
|
|
|
|
QString source_device_;
|
|
|
|
|
2011-03-06 19:11:53 +01:00
|
|
|
// 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 decodebin to be connected.
|
|
|
|
bool pipeline_is_initialised_;
|
|
|
|
bool pipeline_is_connected_;
|
|
|
|
qint64 pending_seek_nanosec_;
|
|
|
|
|
2010-04-11 23:40:26 +02:00
|
|
|
int volume_percent_;
|
|
|
|
qreal volume_modifier_;
|
|
|
|
|
2010-05-19 15:26:23 +02:00
|
|
|
boost::scoped_ptr<QTimeLine> fader_;
|
2010-05-15 19:55:36 +02:00
|
|
|
QBasicTimer fader_fudge_timer_;
|
2010-04-12 01:03:39 +02:00
|
|
|
|
2010-04-11 21:47:21 +02:00
|
|
|
GstElement* pipeline_;
|
|
|
|
|
|
|
|
// Bins
|
2011-09-25 20:24:44 +02:00
|
|
|
// uridecodebin ! audiobin
|
2010-05-08 15:54:12 +02:00
|
|
|
GstElement* uridecodebin_;
|
2010-04-11 21:47:21 +02:00
|
|
|
GstElement* audiobin_;
|
|
|
|
|
2011-08-19 22:56:53 +02:00
|
|
|
// Elements in the audiobin. See comments in Init()'s definition.
|
2011-04-16 16:04:12 +02:00
|
|
|
GstElement* queue_;
|
2010-04-11 21:47:21 +02:00
|
|
|
GstElement* audioconvert_;
|
2010-05-23 15:07:15 +02:00
|
|
|
GstElement* rgvolume_;
|
|
|
|
GstElement* rglimiter_;
|
|
|
|
GstElement* audioconvert2_;
|
2010-07-12 22:55:09 +02:00
|
|
|
GstElement* equalizer_preamp_;
|
2010-04-11 21:47:21 +02:00
|
|
|
GstElement* equalizer_;
|
|
|
|
GstElement* volume_;
|
|
|
|
GstElement* audioscale_;
|
|
|
|
GstElement* audiosink_;
|
|
|
|
|
2010-04-19 14:04:35 +02:00
|
|
|
uint bus_cb_id_;
|
2010-04-11 21:47:21 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif // GSTENGINEPIPELINE_H
|