Fadeout in gstreamer engine
This commit is contained in:
parent
656fbba37f
commit
b19fdbf272
@ -36,6 +36,7 @@
|
|||||||
#include <QSettings>
|
#include <QSettings>
|
||||||
#include <QtDebug>
|
#include <QtDebug>
|
||||||
#include <QCoreApplication>
|
#include <QCoreApplication>
|
||||||
|
#include <QTimeLine>
|
||||||
|
|
||||||
#include <gst/gst.h>
|
#include <gst/gst.h>
|
||||||
#include <iostream>
|
#include <iostream>
|
||||||
@ -100,6 +101,8 @@ void GstEngine::ReloadSettings() {
|
|||||||
|
|
||||||
sink_ = s.value("sink", kAutoSink).toString();
|
sink_ = s.value("sink", kAutoSink).toString();
|
||||||
device_ = s.value("device").toString();
|
device_ = s.value("device").toString();
|
||||||
|
fadeout_enabled_ = s.value("FadeoutEnabled", true).toBool();
|
||||||
|
fadeout_duration_ = s.value("FadeoutDuration", 2000).toInt();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -307,6 +310,9 @@ bool GstEngine::play( uint offset ) {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Stop any active fadeout
|
||||||
|
fadeout_pipeline_.reset();
|
||||||
|
|
||||||
// If "Resume playback on start" is enabled, we must seek to the last position
|
// If "Resume playback on start" is enabled, we must seek to the last position
|
||||||
if (offset) seek(offset);
|
if (offset) seek(offset);
|
||||||
|
|
||||||
@ -320,10 +326,27 @@ bool GstEngine::play( uint offset ) {
|
|||||||
void GstEngine::stop() {
|
void GstEngine::stop() {
|
||||||
m_url = QUrl(); // To ensure we return Empty from state()
|
m_url = QUrl(); // To ensure we return Empty from state()
|
||||||
|
|
||||||
|
if (fadeout_enabled_) {
|
||||||
|
fadeout_pipeline_ = current_pipeline_;
|
||||||
|
disconnect(fadeout_pipeline_.get(), 0, 0, 0);
|
||||||
|
ClearScopeQ();
|
||||||
|
|
||||||
|
QTimeLine* fadeout = new QTimeLine(fadeout_duration_, this);
|
||||||
|
connect(fadeout, SIGNAL(valueChanged(qreal)), fadeout_pipeline_.get(), SLOT(SetVolumeModifier(qreal)));
|
||||||
|
connect(fadeout, SIGNAL(finished()), SLOT(FadeoutFinished()));
|
||||||
|
connect(fadeout_pipeline_.get(), SIGNAL(destroyed()), fadeout, SLOT(deleteLater()));
|
||||||
|
fadeout->setDirection(QTimeLine::Backward);
|
||||||
|
fadeout->start();
|
||||||
|
}
|
||||||
|
|
||||||
current_pipeline_.reset();
|
current_pipeline_.reset();
|
||||||
emit stateChanged(Engine::Empty);
|
emit stateChanged(Engine::Empty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void GstEngine::FadeoutFinished() {
|
||||||
|
fadeout_pipeline_.reset();
|
||||||
|
}
|
||||||
|
|
||||||
void GstEngine::pause() {
|
void GstEngine::pause() {
|
||||||
if (!current_pipeline_)
|
if (!current_pipeline_)
|
||||||
return;
|
return;
|
||||||
|
@ -103,6 +103,7 @@ class GstEngine : public Engine::Base {
|
|||||||
void NewMetaData(const Engine::SimpleMetaBundle& bundle);
|
void NewMetaData(const Engine::SimpleMetaBundle& bundle);
|
||||||
void NewBuffer(GstBuffer* buf);
|
void NewBuffer(GstBuffer* buf);
|
||||||
void ClearScopeQ();
|
void ClearScopeQ();
|
||||||
|
void FadeoutFinished();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
// Callbacks
|
// Callbacks
|
||||||
@ -127,7 +128,11 @@ class GstEngine : public Engine::Base {
|
|||||||
QString sink_;
|
QString sink_;
|
||||||
QString device_;
|
QString device_;
|
||||||
|
|
||||||
|
bool fadeout_enabled_;
|
||||||
|
int fadeout_duration_;
|
||||||
|
|
||||||
boost::shared_ptr<GstEnginePipeline> current_pipeline_;
|
boost::shared_ptr<GstEnginePipeline> current_pipeline_;
|
||||||
|
boost::shared_ptr<GstEnginePipeline> fadeout_pipeline_;
|
||||||
|
|
||||||
//////////
|
//////////
|
||||||
// scope
|
// scope
|
||||||
|
@ -24,6 +24,8 @@ GstEnginePipeline::GstEnginePipeline()
|
|||||||
: QObject(NULL),
|
: QObject(NULL),
|
||||||
valid_(false),
|
valid_(false),
|
||||||
sink_(GstEngine::kAutoSink),
|
sink_(GstEngine::kAutoSink),
|
||||||
|
volume_percent_(100),
|
||||||
|
volume_modifier_(1.0),
|
||||||
pipeline_(NULL),
|
pipeline_(NULL),
|
||||||
src_(NULL),
|
src_(NULL),
|
||||||
decodebin_(NULL),
|
decodebin_(NULL),
|
||||||
@ -293,5 +295,16 @@ void GstEnginePipeline::SetEqualizerParams(int preamp, const QList<int>& band_ga
|
|||||||
}
|
}
|
||||||
|
|
||||||
void GstEnginePipeline::SetVolume(int percent) {
|
void GstEnginePipeline::SetVolume(int percent) {
|
||||||
g_object_set(G_OBJECT(volume_), "volume", double(percent) * 0.01, NULL);
|
volume_percent_ = percent;
|
||||||
|
UpdateVolume();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GstEnginePipeline::SetVolumeModifier(qreal mod) {
|
||||||
|
volume_modifier_ = mod;
|
||||||
|
UpdateVolume();
|
||||||
|
}
|
||||||
|
|
||||||
|
void GstEnginePipeline::UpdateVolume() {
|
||||||
|
float vol = double(volume_percent_) * 0.01 * volume_modifier_;
|
||||||
|
g_object_set(G_OBJECT(volume_), "volume", vol, NULL);
|
||||||
}
|
}
|
||||||
|
@ -53,6 +53,9 @@ class GstEnginePipeline : public QObject {
|
|||||||
qint64 length() const;
|
qint64 length() const;
|
||||||
GstState state() const;
|
GstState state() const;
|
||||||
|
|
||||||
|
public slots:
|
||||||
|
void SetVolumeModifier(qreal mod);
|
||||||
|
|
||||||
signals:
|
signals:
|
||||||
void EndOfStreamReached();
|
void EndOfStreamReached();
|
||||||
void MetadataFound(const Engine::SimpleMetaBundle& bundle);
|
void MetadataFound(const Engine::SimpleMetaBundle& bundle);
|
||||||
@ -68,6 +71,8 @@ class GstEnginePipeline : public QObject {
|
|||||||
static void HandoffCallback(GstPad*, GstBuffer*, gpointer);
|
static void HandoffCallback(GstPad*, GstBuffer*, gpointer);
|
||||||
static void EventCallback(GstPad*, GstEvent*, gpointer);
|
static void EventCallback(GstPad*, GstEvent*, gpointer);
|
||||||
|
|
||||||
|
void UpdateVolume();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
static const int kGstStateTimeout = 10000000;
|
static const int kGstStateTimeout = 10000000;
|
||||||
|
|
||||||
@ -76,6 +81,9 @@ class GstEnginePipeline : public QObject {
|
|||||||
QString device_;
|
QString device_;
|
||||||
bool forwards_buffers_;
|
bool forwards_buffers_;
|
||||||
|
|
||||||
|
int volume_percent_;
|
||||||
|
qreal volume_modifier_;
|
||||||
|
|
||||||
GstElement* pipeline_;
|
GstElement* pipeline_;
|
||||||
|
|
||||||
// Bins
|
// Bins
|
||||||
|
Loading…
x
Reference in New Issue
Block a user