2018-02-27 18:06:05 +01:00
|
|
|
/***************************************************************************
|
2018-06-28 01:15:32 +02:00
|
|
|
* Copyright (C) 2017-2018 Jonas Kvinge <jonas@jkvinge.net> *
|
2018-02-27 18:06:05 +01:00
|
|
|
* Copyright (C) 2003-2005 by Mark Kretschmann <markey@web.de> *
|
|
|
|
* Copyright (C) 2005 by Jakub Stachowski <qbast@go2.pl> *
|
2018-06-28 01:15:32 +02:00
|
|
|
* Copyright (C) 2006 Paul Cifarelli <paul@cifarelli.net> *
|
2018-02-27 18:06:05 +01:00
|
|
|
* *
|
|
|
|
* This program 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 2 of the License, or *
|
|
|
|
* (at your option) any later version. *
|
|
|
|
* *
|
|
|
|
* This program 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 this program; if not, write to the *
|
|
|
|
* Free Software Foundation, Inc., *
|
|
|
|
* 51 Franklin Steet, Fifth Floor, Boston, MA 02111-1307, USA. *
|
|
|
|
***************************************************************************/
|
|
|
|
|
|
|
|
#ifndef GSTENGINE_H
|
|
|
|
#define GSTENGINE_H
|
|
|
|
|
|
|
|
#include "config.h"
|
|
|
|
|
|
|
|
#include <memory>
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <stdbool.h>
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
#include <gst/gst.h>
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QtGlobal>
|
|
|
|
#include <QObject>
|
2018-02-27 18:06:05 +01:00
|
|
|
#include <QFuture>
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QByteArray>
|
2018-02-27 18:06:05 +01:00
|
|
|
#include <QList>
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QVariant>
|
2018-02-27 18:06:05 +01:00
|
|
|
#include <QString>
|
2018-05-01 00:41:33 +02:00
|
|
|
#include <QUrl>
|
|
|
|
#include <QTimer>
|
2018-02-27 18:06:05 +01:00
|
|
|
#include <QTimerEvent>
|
|
|
|
|
|
|
|
#include "core/timeconstants.h"
|
2018-05-01 00:41:33 +02:00
|
|
|
#include "engine_fwd.h"
|
|
|
|
#include "enginebase.h"
|
|
|
|
#include "gstbufferconsumer.h"
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
class TaskManager;
|
2018-05-01 00:41:33 +02:00
|
|
|
class GstEnginePipeline;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2018-07-01 22:26:46 +02:00
|
|
|
#ifdef Q_OS_MACOS
|
2018-02-27 18:06:05 +01:00
|
|
|
struct _GTlsDatabase;
|
|
|
|
typedef struct _GTlsDatabase GTlsDatabase;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
/**
|
|
|
|
* @class GstEngine
|
|
|
|
* @short GStreamer engine plugin
|
|
|
|
* @author Mark Kretschmann <markey@web.de>
|
|
|
|
*/
|
2018-05-01 00:41:33 +02:00
|
|
|
class GstEngine : public Engine::Base, public GstBufferConsumer {
|
2018-02-27 18:06:05 +01:00
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
public:
|
|
|
|
GstEngine(TaskManager *task_manager);
|
|
|
|
~GstEngine();
|
|
|
|
|
|
|
|
bool Init();
|
2018-06-28 01:15:32 +02:00
|
|
|
Engine::State state() const;
|
2018-09-22 23:13:56 +02:00
|
|
|
void StartPreloading(const QUrl &media_url, const QUrl &original_url, bool force_stop_at_end, qint64 beginning_nanosec, qint64 end_nanosec);
|
|
|
|
bool Load(const QUrl &media_url, const QUrl &original_url, Engine::TrackChangeFlags change, bool force_stop_at_end, quint64 beginning_nanosec, qint64 end_nanosec);
|
2018-06-28 01:15:32 +02:00
|
|
|
bool Play(quint64 offset_nanosec);
|
|
|
|
void Stop(bool stop_after = false);
|
|
|
|
void Pause();
|
|
|
|
void Unpause();
|
|
|
|
void Seek(quint64 offset_nanosec);
|
|
|
|
protected:
|
|
|
|
void SetVolumeSW(uint percent);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2018-06-28 01:15:32 +02:00
|
|
|
public:
|
2018-02-27 18:06:05 +01:00
|
|
|
qint64 position_nanosec() const;
|
|
|
|
qint64 length_nanosec() const;
|
|
|
|
const Engine::Scope &scope(int chunk_length);
|
|
|
|
|
2018-06-28 01:15:32 +02:00
|
|
|
OutputDetailsList GetOutputsList() const;
|
2018-07-01 01:29:52 +02:00
|
|
|
bool ValidOutput(const QString &output);
|
2018-06-28 01:15:32 +02:00
|
|
|
QString DefaultOutput() { return kAutoSink; }
|
2018-07-01 01:29:52 +02:00
|
|
|
bool CustomDeviceSupport(const QString &output);
|
2018-09-21 23:29:00 +02:00
|
|
|
bool ALSADeviceSupport(const QString &output);
|
2018-06-07 19:38:40 +02:00
|
|
|
|
2018-06-28 01:15:32 +02:00
|
|
|
void EnsureInitialised() { initialising_.waitForFinished(); }
|
|
|
|
void InitialiseGStreamer();
|
|
|
|
void SetEnvironment();
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2018-06-28 01:15:32 +02:00
|
|
|
GstElement *CreateElement(const QString &factoryName, GstElement *bin = 0, bool fatal = true, bool showerror = true);
|
|
|
|
void ConsumeBuffer(GstBuffer *buffer, int pipeline_id);
|
2018-06-07 19:38:40 +02:00
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
public slots:
|
2018-06-28 01:15:32 +02:00
|
|
|
|
|
|
|
void ReloadSettings();
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
/** Set whether equalizer is enabled */
|
|
|
|
void SetEqualizerEnabled(bool);
|
|
|
|
|
|
|
|
/** Set equalizer preamp and gains, range -100..100. Gains are 10 values. */
|
|
|
|
void SetEqualizerParameters(int preamp, const QList<int> &bandGains);
|
|
|
|
|
|
|
|
/** Set Stereo balance, range -1.0f..1.0f */
|
|
|
|
void SetStereoBalance(float value);
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
void AddBufferConsumer(GstBufferConsumer *consumer);
|
|
|
|
void RemoveBufferConsumer(GstBufferConsumer *consumer);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
2018-07-01 22:26:46 +02:00
|
|
|
#ifdef Q_OS_MACOS
|
2018-02-27 18:06:05 +01:00
|
|
|
GTlsDatabase *tls_database() const { return tls_database_; }
|
|
|
|
#endif
|
|
|
|
|
|
|
|
protected:
|
|
|
|
void timerEvent(QTimerEvent*);
|
|
|
|
|
|
|
|
private slots:
|
|
|
|
void EndOfStreamReached(int pipeline_id, bool has_next_track);
|
|
|
|
void HandlePipelineError(int pipeline_id, const QString &message, int domain, int error_code);
|
|
|
|
void NewMetaData(int pipeline_id, const Engine::SimpleMetaBundle &bundle);
|
|
|
|
void AddBufferToScope(GstBuffer *buf, int pipeline_id);
|
|
|
|
void FadeoutFinished();
|
|
|
|
void FadeoutPauseFinished();
|
|
|
|
void SeekNow();
|
|
|
|
void PlayDone(QFuture<GstStateChangeReturn> future, const quint64, const int);
|
|
|
|
|
|
|
|
void BufferingStarted();
|
|
|
|
void BufferingProgress(int percent);
|
|
|
|
void BufferingFinished();
|
|
|
|
|
|
|
|
private:
|
2018-06-28 01:15:32 +02:00
|
|
|
static const char *kAutoSink;
|
2018-06-07 19:38:40 +02:00
|
|
|
static const char *kALSASink;
|
|
|
|
static const char *kOpenALSASink;
|
|
|
|
static const char *kOSSSink;
|
|
|
|
static const char *kOSS4Sink;
|
|
|
|
static const char *kJackAudioSink;
|
|
|
|
static const char *kPulseSink;
|
|
|
|
static const char *kA2DPSink;
|
|
|
|
static const char *kAVDTPSink;
|
|
|
|
static const char *InterAudiosink;
|
|
|
|
static const char *kDirectSoundSink;
|
|
|
|
static const char *kOSXAudioSink;
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
PluginDetailsList GetPluginList(const QString &classname) const;
|
2018-06-28 01:15:32 +02:00
|
|
|
QByteArray FixupUrl(const QUrl &url);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
void StartFadeout();
|
|
|
|
void StartFadeoutPause();
|
|
|
|
|
|
|
|
void StartTimers();
|
|
|
|
void StopTimers();
|
|
|
|
|
|
|
|
std::shared_ptr<GstEnginePipeline> CreatePipeline();
|
2018-09-22 23:13:56 +02:00
|
|
|
std::shared_ptr<GstEnginePipeline> CreatePipeline(const QByteArray &gst_url, const QUrl &original_url, qint64 end_nanosec);
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
void UpdateScope(int chunk_length);
|
|
|
|
|
|
|
|
private:
|
2018-06-28 01:15:32 +02:00
|
|
|
static const qint64 kTimerIntervalNanosec = 1000 * kNsecPerMsec; // 1s
|
|
|
|
static const qint64 kPreloadGapNanosec = 3000 * kNsecPerMsec; // 3s
|
|
|
|
static const qint64 kSeekDelayNanosec = 100 * kNsecPerMsec; // 100msec
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
TaskManager *task_manager_;
|
|
|
|
int buffering_task_id_;
|
|
|
|
|
|
|
|
QFuture<void> initialising_;
|
|
|
|
|
|
|
|
std::shared_ptr<GstEnginePipeline> current_pipeline_;
|
|
|
|
std::shared_ptr<GstEnginePipeline> fadeout_pipeline_;
|
|
|
|
std::shared_ptr<GstEnginePipeline> fadeout_pause_pipeline_;
|
|
|
|
QUrl preloaded_url_;
|
|
|
|
|
2018-05-01 00:41:33 +02:00
|
|
|
QList<GstBufferConsumer*> buffer_consumers_;
|
2018-02-27 18:06:05 +01:00
|
|
|
|
|
|
|
GstBuffer *latest_buffer_;
|
|
|
|
|
|
|
|
int equalizer_preamp_;
|
|
|
|
QList<int> equalizer_gains_;
|
|
|
|
float stereo_balance_;
|
|
|
|
|
|
|
|
mutable bool can_decode_success_;
|
|
|
|
mutable bool can_decode_last_;
|
|
|
|
|
|
|
|
// Hack to stop seeks happening too often
|
|
|
|
QTimer *seek_timer_;
|
|
|
|
bool waiting_to_seek_;
|
|
|
|
quint64 seek_pos_;
|
|
|
|
|
|
|
|
int timer_id_;
|
|
|
|
int next_element_id_;
|
|
|
|
|
|
|
|
bool is_fading_out_to_pause_;
|
|
|
|
bool has_faded_out_;
|
|
|
|
|
|
|
|
int scope_chunk_;
|
|
|
|
bool have_new_buffer_;
|
|
|
|
int scope_chunks_;
|
|
|
|
|
2018-07-01 22:26:46 +02:00
|
|
|
#ifdef Q_OS_MACOS
|
|
|
|
GTlsDatabase* tls_database_;
|
|
|
|
#endif
|
|
|
|
|
2018-02-27 18:06:05 +01:00
|
|
|
};
|
|
|
|
|
|
|
|
#endif /* GSTENGINE_H */
|