Initialize gstreamer independent of witch engine is used

This commit is contained in:
Jonas Kvinge
2019-04-20 15:25:31 +02:00
parent ba76385a2f
commit 3ed6817ac9
10 changed files with 207 additions and 82 deletions

View File

@@ -78,6 +78,7 @@
#include "database.h"
#include "player.h"
#include "appearance.h"
#include "engine/enginetype.h"
#include "engine/enginebase.h"
#include "dialogs/errordialog.h"
#include "dialogs/about.h"
@@ -281,6 +282,7 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co
app_->player()->SetAnalyzer(ui_->analyzer);
app_->player()->SetEqualizer(equalizer_.get());
app_->player()->Init();
EngineChanged(app_->player()->engine()->type());
int volume = app_->player()->GetVolume();
ui_->volume->setValue(volume);
VolumeChanged(volume);
@@ -450,6 +452,7 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co
// Player connections
connect(ui_->volume, SIGNAL(valueChanged(int)), app_->player(), SLOT(SetVolume(int)));
connect(app_->player(), SIGNAL(EngineChanged(Engine::EngineType)), SLOT(EngineChanged(Engine::EngineType)));
connect(app_->player(), SIGNAL(Error(QString)), SLOT(ShowErrorDialog(QString)));
connect(app_->player(), SIGNAL(SongChangeRequestProcessed(QUrl,bool)), app_->playlist_manager(), SLOT(SongChangeRequestProcessed(QUrl,bool)));
@@ -479,16 +482,18 @@ MainWindow::MainWindow(Application *app, SystemTrayIcon *tray_icon, OSD *osd, co
connect(app_->playlist_manager(), SIGNAL(PlayRequested(QModelIndex)), SLOT(PlayIndex(QModelIndex)));
connect(ui_->playlist->view(), SIGNAL(doubleClicked(QModelIndex)), SLOT(PlaylistDoubleClick(QModelIndex)));
//connect(ui_->playlist->view(), SIGNAL(doubleClicked(QModelIndex)), SLOT(PlayIndex(QModelIndex)));
connect(ui_->playlist->view(), SIGNAL(PlayItem(QModelIndex)), SLOT(PlayIndex(QModelIndex)));
connect(ui_->playlist->view(), SIGNAL(PlayPause()), app_->player(), SLOT(PlayPause()));
connect(ui_->playlist->view(), SIGNAL(RightClicked(QPoint,QModelIndex)), SLOT(PlaylistRightClick(QPoint,QModelIndex)));
//connect(ui_->playlist->view(), SIGNAL(SeekTrack(int)), ui_->track_slider, SLOT(Seek(int)));
connect(ui_->playlist->view(), SIGNAL(SeekForward()), app_->player(), SLOT(SeekForward()));
connect(ui_->playlist->view(), SIGNAL(SeekBackward()), app_->player(), SLOT(SeekBackward()));
connect(ui_->playlist->view(), SIGNAL(BackgroundPropertyChanged()), SLOT(RefreshStyleSheet()));
connect(ui_->track_slider, SIGNAL(ValueChangedSeconds(int)), app_->player(), SLOT(SeekTo(int)));
connect(ui_->track_slider, SIGNAL(SeekForward()), app_->player(), SLOT(SeekForward()));
connect(ui_->track_slider, SIGNAL(SeekBackward()), app_->player(), SLOT(SeekBackward()));
connect(ui_->track_slider, SIGNAL(Previous()), app_->player(), SLOT(Previous()));
connect(ui_->track_slider, SIGNAL(Next()), app_->player(), SLOT(Next()));
// Context connections
@@ -884,6 +889,17 @@ void MainWindow::RefreshStyleSheet() {
setStyleSheet(contents);
}
void MainWindow::EngineChanged(Engine::EngineType enginetype) {
if (enginetype == Engine::EngineType::GStreamer) {
ui_->action_open_cd->setEnabled(true);
}
else {
ui_->action_open_cd->setEnabled(false);
}
}
void MainWindow::MediaStopped() {
setWindowTitle("Strawberry Music Player");
@@ -1316,6 +1332,7 @@ void MainWindow::AddToPlaylist(QMimeData *data) {
}
app_->playlist_manager()->current()->dropMimeData(data, Qt::CopyAction, -1, 0, QModelIndex());
delete data;
}
void MainWindow::AddToPlaylist(QAction *action) {

View File

@@ -49,6 +49,7 @@
#include "core/lazy.h"
#include "core/tagreaderclient.h"
#include "engine/enginetype.h"
#include "engine/engine_fwd.h"
#include "mac_startup.h"
#include "widgets/osd.h"
@@ -135,6 +136,7 @@ signals:
private slots:
void FilePathChanged(const QString& path);
void EngineChanged(Engine::EngineType enginetype);
void MediaStopped();
void MediaPaused();
void MediaPlaying();

View File

@@ -49,6 +49,7 @@
#ifdef HAVE_GSTREAMER
# include "engine/gstengine.h"
# include "engine/gststartup.h"
#endif
#ifdef HAVE_XINE
# include "engine/xineengine.h"
@@ -75,12 +76,17 @@
#include "scrobbler/audioscrobbler.h"
using std::shared_ptr;
using std::unique_ptr;
const char *Player::kSettingsGroup = "Player";
Player::Player(Application *app, QObject *parent)
: PlayerInterface(parent),
app_(app),
engine_(nullptr),
#ifdef HAVE_GSTREAMER
gst_startup_(new GstStartup(this)),
#endif
analyzer_(nullptr),
equalizer_(nullptr),
stream_change_type_(Engine::First),
@@ -117,10 +123,13 @@ Engine::EngineType Player::CreateEngine(Engine::EngineType enginetype) {
switch(enginetype) {
case Engine::None:
#ifdef HAVE_GSTREAMER
case Engine::GStreamer:
case Engine::GStreamer:{
use_enginetype=Engine::GStreamer;
engine_.reset(new GstEngine(app_->task_manager()));
unique_ptr<GstEngine> gst_engine(new GstEngine(app_->task_manager()));
gst_engine->SetStartup(gst_startup_);
engine_.reset(gst_engine.release());
break;
}
#endif
#ifdef HAVE_XINE
case Engine::Xine:
@@ -160,6 +169,8 @@ Engine::EngineType Player::CreateEngine(Engine::EngineType enginetype) {
qFatal("Failed to create engine!");
}
emit EngineChanged(use_enginetype);
return use_enginetype;
}

View File

@@ -38,6 +38,9 @@
#include "urlhandler.h"
#include "engine/engine_fwd.h"
#include "engine/enginetype.h"
#ifdef HAVE_GSTREAMER
#include "engine/gststartup.h"
#endif
#include "playlist/playlistitem.h"
class Application;
@@ -45,6 +48,8 @@ class Song;
class AnalyzerContainer;
class Equalizer;
using std::unique_ptr;
namespace Engine {
struct SimpleMetaBundle;
} // namespace Engine
@@ -183,6 +188,9 @@ class Player : public PlayerInterface {
void HandleAuthentication();
signals:
void EngineChanged(Engine::EngineType enginetype);
private slots:
void EngineStateChanged(Engine::State);
void EngineMetadataReceived(const Engine::SimpleMetaBundle &bundle);
@@ -207,6 +215,10 @@ class Player : public PlayerInterface {
private:
Application *app_;
std::unique_ptr<EngineBase> engine_;
#ifdef HAVE_GSTREAMER
GstStartup *gst_startup_;
#endif
AnalyzerContainer *analyzer_;
Equalizer *equalizer_;
@@ -214,7 +226,6 @@ class Player : public PlayerInterface {
PlaylistItemPtr current_item_;
std::unique_ptr<EngineBase> engine_;
Engine::TrackChangeFlags stream_change_type_;
Engine::State last_state_;
int nb_errors_received_;