Skip to content

Commit

Permalink
Make background steams build-optional
Browse files Browse the repository at this point in the history
  • Loading branch information
xif-fr committed Dec 1, 2021
1 parent 590ab22 commit 89de27a
Show file tree
Hide file tree
Showing 12 changed files with 135 additions and 32 deletions.
2 changes: 2 additions & 0 deletions CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -330,6 +330,8 @@ optional_component(VISUALISATIONS ON "Visualisations"
DEPENDS "opengl" OPENGL_FOUND
)

optional_component(BACKGROUND_STREAMS ON "Background streams")

optional_component(TRANSLATIONS ON "Translations"
DEPENDS "gettext" GETTEXT_XGETTEXT_EXECUTABLE
DEPENDS "Qt5LinguistTools" Qt5LinguistTools_FOUND
Expand Down
1 change: 1 addition & 0 deletions include/clementine-config.h.in
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
#cmakedefine HAVE_OPENGL
#cmakedefine HAVE_TRANSLATIONS
#cmakedefine HAVE_SPOTIFY
#cmakedefine HAVE_BACKGROUND_STREAMS
#cmakedefine TAGLIB_HAS_OPUS
#cmakedefine USE_INSTALL_PREFIX
#cmakedefine USE_SYSTEM_PROJECTM
Expand Down
20 changes: 14 additions & 6 deletions src/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ set(SOURCES

core/appearance.cpp
core/application.cpp
core/backgroundstreams.cpp
core/commandlineoptions.cpp
core/crashreporting.cpp
core/database.cpp
Expand Down Expand Up @@ -344,7 +343,6 @@ set(SOURCES
ui/albumcovermanagerlist.cpp
ui/albumcoversearcher.cpp
ui/appearancesettingspage.cpp
ui/backgroundstreamssettingspage.cpp
ui/behavioursettingspage.cpp
ui/console.cpp
ui/coverfromurldialog.cpp
Expand Down Expand Up @@ -390,7 +388,6 @@ set(SOURCES
widgets/fileviewlist.cpp
widgets/forcescrollperpixel.cpp
widgets/freespacebar.cpp
widgets/fullscreenhypnotoad.cpp
widgets/groupediconview.cpp
widgets/lineedit.cpp
widgets/linetextedit.cpp
Expand Down Expand Up @@ -425,7 +422,6 @@ set(HEADERS
analyzers/turbine.h

core/application.h
core/backgroundstreams.h
core/crashreporting.h
core/database.h
core/deletefiles.h
Expand Down Expand Up @@ -647,7 +643,6 @@ set(HEADERS
ui/albumcovermanagerlist.h
ui/albumcoversearcher.h
ui/appearancesettingspage.h
ui/backgroundstreamssettingspage.h
ui/behavioursettingspage.h
ui/console.h
ui/coverfromurldialog.h
Expand Down Expand Up @@ -786,7 +781,6 @@ set(UI
ui/albumcovermanager.ui
ui/albumcoversearcher.ui
ui/appearancesettingspage.ui
ui/backgroundstreamssettingspage.ui
ui/behavioursettingspage.ui
ui/console.ui
ui/coverfromurldialog.ui
Expand Down Expand Up @@ -846,6 +840,20 @@ endif(HAVE_TRANSLATIONS)

option(USE_INSTALL_PREFIX "Look for data in CMAKE_INSTALL_PREFIX" ON)

# Background streams
optional_source(HAVE_BACKGROUND_STREAMS
SOURCES
core/backgroundstreams.cpp
ui/backgroundstreamssettingspage.cpp
widgets/fullscreenhypnotoad.cpp
HEADERS
core/backgroundstreams.h
ui/backgroundstreamssettingspage.h
widgets/fullscreenhypnotoad.h
UI
ui/backgroundstreamssettingspage.ui
)

# Visualisations
optional_source(HAVE_VISUALISATIONS
SOURCES
Expand Down
19 changes: 16 additions & 3 deletions src/engines/gstengine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,8 @@ const char* GstEngine::kAutoSink = "autoaudiosink";
const char* GstEngine::kOutFormatDetect = "";
const char* GstEngine::kOutFormatS16LE = "S16LE";
const char* GstEngine::kOutFormatF32LE = "F32LE";

#ifdef HAVE_BACKGROUND_STREAMS
const char* GstEngine::kHypnotoadPipeline =
"audiotestsrc wave=6 ! "
"audioecho intensity=1 delay=50000000 ! "
Expand All @@ -100,6 +102,7 @@ const char* GstEngine::kHypnotoadPipeline =
const char* GstEngine::kEnterprisePipeline =
"audiotestsrc wave=5 ! "
"audiocheblimit mode=0 cutoff=120";
#endif // HAVE_BACKGROUND_STREAMS

GstEngine::GstEngine(Application* app)
: Engine::Base(),
Expand Down Expand Up @@ -850,19 +853,25 @@ shared_ptr<GstEnginePipeline> GstEngine::CreatePipeline(
const MediaPlaybackRequest& req, qint64 end_nanosec) {
shared_ptr<GstEnginePipeline> ret = CreatePipeline();

#ifdef HAVE_BACKGROUND_STREAMS
if (req.url_.scheme() == "hypnotoad") {
if (!ret->InitFromString(kHypnotoadPipeline)) {
qLog(Error) << "Could not initialize pipeline" << kHypnotoadPipeline;
ret.reset();
}
} else if (req.url_.scheme() == "enterprise") {
return ret;
}
if (req.url_.scheme() == "enterprise") {
if (!ret->InitFromString(kEnterprisePipeline)) {
qLog(Error) << "Could not initialize pipeline" << kEnterprisePipeline;
ret.reset();
}
} else {
if (!ret->InitFromReq(req, end_nanosec)) ret.reset();
return ret;
}
#endif // HAVE_BACKGROUND_STREAMS

if (!ret->InitFromReq(req, end_nanosec))
ret.reset();

return ret;
}
Expand All @@ -877,6 +886,8 @@ void GstEngine::RemoveBufferConsumer(BufferConsumer* consumer) {
if (current_pipeline_) current_pipeline_->RemoveBufferConsumer(consumer);
}

#ifdef HAVE_BACKGROUND_STREAMS

int GstEngine::AddBackgroundStream(shared_ptr<GstEnginePipeline> pipeline) {
// We don't want to get metadata messages or end notifications.
disconnect(pipeline.get(),
Expand Down Expand Up @@ -930,6 +941,8 @@ void GstEngine::SetBackgroundStreamVolume(int id, int volume) {
pipeline->SetVolume(volume);
}

#endif // HAVE_BACKGROUND_STREAMS

void GstEngine::BufferingStarted() {
if (buffering_task_id_ != -1) {
task_manager_->SetTaskFinished(buffering_task_id_);
Expand Down
9 changes: 9 additions & 0 deletions src/engines/gstengine.h
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@
#include <QTimerEvent>
#include <memory>

#include "config.h"
#include "bufferconsumer.h"
#include "core/timeconstants.h"
#include "enginebase.h"
Expand Down Expand Up @@ -84,9 +85,11 @@ class GstEngine : public Engine::Base, public BufferConsumer {
void EnsureInitialised() { initialising_.waitForFinished(); }
void InitialiseGstreamer();

#ifdef HAVE_BACKGROUND_STREAMS
int AddBackgroundStream(const QUrl& url);
void StopBackgroundStream(int id);
void SetBackgroundStreamVolume(int id, int volume);
#endif

qint64 position_nanosec() const;
qint64 length_nanosec() const;
Expand Down Expand Up @@ -152,8 +155,10 @@ class GstEngine : public Engine::Base, public BufferConsumer {
void FadeoutFinished();
void FadeoutPauseFinished();
void SeekNow();
#ifdef HAVE_BACKGROUND_STREAMS
void BackgroundStreamFinished();
void BackgroundStreamPlayDone(QFuture<GstStateChangeReturn>, int);
#endif
void PlayDone(QFuture<GstStateChangeReturn> future, const quint64, const int);

void BufferingStarted();
Expand Down Expand Up @@ -182,7 +187,9 @@ class GstEngine : public Engine::Base, public BufferConsumer {

void UpdateScope(int chunk_length);

#ifdef HAVE_BACKGROUND_STREAMS
int AddBackgroundStream(std::shared_ptr<GstEnginePipeline> pipeline);
#endif

bool IsCurrentPipeline(int id);

Expand Down Expand Up @@ -240,7 +247,9 @@ class GstEngine : public Engine::Base, public BufferConsumer {
int timer_id_;
int next_element_id_;

#ifdef HAVE_BACKGROUND_STREAMS
QHash<int, std::shared_ptr<GstEnginePipeline>> background_streams_;
#endif

bool is_fading_out_to_pause_;
bool has_faded_out_;
Expand Down
17 changes: 11 additions & 6 deletions src/ui/backgroundstreamssettingspage.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,24 @@

BackgroundStreamsSettingsPage::BackgroundStreamsSettingsPage(
SettingsDialog* dialog)
: SettingsPage(dialog), ui_(new Ui_BackgroundStreamsSettingsPage) {
: SettingsPage(dialog),
ui_(new Ui_BackgroundStreamsSettingsPage),
loaded_(false) {
ui_->setupUi(this);
setWindowIcon(
IconLoader::Load("weather-showers-scattered", IconLoader::Base));

for (const QString& name : dialog->background_streams()->streams()) {
AddStream(name);
}
}

BackgroundStreamsSettingsPage::~BackgroundStreamsSettingsPage() { delete ui_; }

void BackgroundStreamsSettingsPage::Load() {}
void BackgroundStreamsSettingsPage::Load() {
if (!loaded_ and dialog()->background_streams()) {
for (const QString& name : dialog()->background_streams()->streams()) {
AddStream(name);
}
loaded_ = true;
}
}

void BackgroundStreamsSettingsPage::Save() {
dialog()->background_streams()->SaveStreams();
Expand Down
1 change: 1 addition & 0 deletions src/ui/backgroundstreamssettingspage.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ class BackgroundStreamsSettingsPage : public SettingsPage {

private:
Ui_BackgroundStreamsSettingsPage* ui_;
bool loaded_;
};

#endif // BACKGROUNDSTREAMSSETTINGSPAGE_H
24 changes: 20 additions & 4 deletions src/ui/mainwindow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,9 @@

#include "core/appearance.h"
#include "core/application.h"
#ifdef HAVE_BACKGROUND_STREAMS
#include "core/backgroundstreams.h"
#endif
#include "core/commandlineoptions.h"
#include "core/database.h"
#include "core/deletefiles.h"
Expand Down Expand Up @@ -310,8 +312,10 @@ MainWindow::MainWindow(Application* app, SystemTrayIcon* tray_icon, OSD* osd,
// Start initialising the player
qLog(Debug) << "Initialising player";
app_->player()->Init();
#ifdef HAVE_BACKGROUND_STREAMS
background_streams_ = new BackgroundStreams(app_->player()->engine(), this);
background_streams_->LoadStreams();
#endif

// Models
qLog(Debug) << "Creating models";
Expand Down Expand Up @@ -392,13 +396,15 @@ MainWindow::MainWindow(Application* app, SystemTrayIcon* tray_icon, OSD* osd,
IconLoader::Load("document-save", IconLoader::Base));
ui_->action_full_library_scan->setIcon(
IconLoader::Load("view-refresh", IconLoader::Base));
#ifdef HAVE_BACKGROUND_STREAMS
ui_->action_rain->setIcon(
IconLoader::Load("weather-showers-scattered", IconLoader::Base));
ui_->action_hypnotoad->setIcon(
IconLoader::Load("hypnotoad", IconLoader::Base));
ui_->action_kittens->setIcon(IconLoader::Load("kittens", IconLoader::Base));
ui_->action_enterprise->setIcon(
IconLoader::Load("enterprise", IconLoader::Base));
IconLoader::Load("enterprise", IconLoader::Base));
#endif
ui_->action_kittens->setIcon(IconLoader::Load("kittens", IconLoader::Base));
ui_->action_love->setIcon(IconLoader::Load("love", IconLoader::Lastfm));

// File view connections
Expand Down Expand Up @@ -495,9 +501,15 @@ MainWindow::MainWindow(Application* app, SystemTrayIcon* tray_icon, OSD* osd,
connect(this, SIGNAL(NewDebugConsole(Console*)), app_,
SIGNAL(NewDebugConsole(Console*)));

#ifdef HAVE_BACKGROUND_STREAMS
background_streams_->AddAction("Rain", ui_->action_rain);
background_streams_->AddAction("Hypnotoad", ui_->action_hypnotoad);
background_streams_->AddAction("Make it so!", ui_->action_enterprise);
#else
ui_->action_rain->setVisible(false);
ui_->action_hypnotoad->setVisible(false);
ui_->action_enterprise->setVisible(false);
#endif // HAVE_BACKGROUND_STREAMS

// Playlist view actions
ui_->action_next_playlist->setShortcuts(
Expand Down Expand Up @@ -938,8 +950,10 @@ MainWindow::MainWindow(Application* app, SystemTrayIcon* tray_icon, OSD* osd,
connect(app_->player(), SIGNAL(Stopped()), ui_->now_playing, SLOT(Stopped()));
connect(ui_->now_playing, SIGNAL(ShowAboveStatusBarChanged(bool)),
SLOT(NowPlayingWidgetPositionChanged(bool)));
#ifdef HAVE_BACKGROUND_STREAMS
connect(ui_->action_hypnotoad, SIGNAL(toggled(bool)), ui_->now_playing,
SLOT(AllHail(bool)));
#endif
connect(ui_->action_kittens, SIGNAL(toggled(bool)), ui_->now_playing,
SLOT(EnableKittens(bool)));
connect(ui_->action_kittens, SIGNAL(toggled(bool)), app_->network_remote(),
Expand Down Expand Up @@ -2714,10 +2728,12 @@ void MainWindow::ChangeLibraryQueryMode(QAction* action) {
void MainWindow::ShowCoverManager() { cover_manager_->show(); }

SettingsDialog* MainWindow::CreateSettingsDialog() {
SettingsDialog* settings_dialog =
new SettingsDialog(app_, background_streams_);
SettingsDialog* settings_dialog = new SettingsDialog(app_);
settings_dialog->SetGlobalShortcutManager(global_shortcuts_);
settings_dialog->SetSongInfoView(song_info_view_);
#ifdef HAVE_BACKGROUND_STREAMS
settings_dialog->SetBackgroundStreams(background_streams_);
#endif

// Settings
connect(settings_dialog, SIGNAL(accepted()), SLOT(ReloadAllSettings()));
Expand Down
11 changes: 7 additions & 4 deletions src/ui/settingsdialog.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,13 @@
#include "settingsdialog.h"

#include "appearancesettingspage.h"
#ifdef HAVE_BACKGROUND_STREAMS
#include "backgroundstreamssettingspage.h"
#include "core/backgroundstreams.h"
#endif
#include "behavioursettingspage.h"
#include "config.h"
#include "core/application.h"
#include "core/backgroundstreams.h"
#include "core/logging.h"
#include "core/networkproxyfactory.h"
#include "core/player.h"
Expand Down Expand Up @@ -89,14 +91,13 @@ void SettingsItemDelegate::paint(QPainter* painter,
}
}

SettingsDialog::SettingsDialog(Application* app, BackgroundStreams* streams,
QWidget* parent)
SettingsDialog::SettingsDialog(Application* app, QWidget* parent)
: QDialog(parent),
app_(app),
model_(app_->directory_model()),
gst_engine_(qobject_cast<GstEngine*>(app_->player()->engine())),
song_info_view_(nullptr),
streams_(streams),
background_streams_(nullptr),
global_search_(app_->global_search()),
appearance_(app_->appearance()),
ui_(new Ui_SettingsDialog),
Expand All @@ -110,8 +111,10 @@ SettingsDialog::SettingsDialog(Application* app, BackgroundStreams* streams,
general->AddPage(Page_Behaviour, new BehaviourSettingsPage(this));
general->AddPage(Page_Library, new LibrarySettingsPage(this));
general->AddPage(Page_SongMetadata, new SongMetadataSettingsPage(this));
#ifdef HAVE_BACKGROUND_STREAMS
general->AddPage(Page_BackgroundStreams,
new BackgroundStreamsSettingsPage(this));
#endif
general->AddPage(Page_Proxy, new NetworkProxySettingsPage(this));
general->AddPage(Page_Transcoding, new TranscoderSettingsPage(this));
general->AddPage(Page_NetworkRemote, new NetworkRemoteSettingsPage(this));
Expand Down
8 changes: 4 additions & 4 deletions src/ui/settingsdialog.h
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,7 @@ class SettingsDialog : public QDialog {
Q_OBJECT

public:
SettingsDialog(Application* app, BackgroundStreams* streams,
QWidget* parent = nullptr);
SettingsDialog(Application* app, QWidget* parent = nullptr);
~SettingsDialog();

enum Page {
Expand Down Expand Up @@ -101,6 +100,7 @@ class SettingsDialog : public QDialog {
manager_ = manager;
}
void SetSongInfoView(SongInfoView* view) { song_info_view_ = view; }
void SetBackgroundStreams(BackgroundStreams* streams) { background_streams_ = streams; }

bool is_loading_settings() const { return loading_settings_; }

Expand All @@ -109,7 +109,7 @@ class SettingsDialog : public QDialog {
GlobalShortcuts* global_shortcuts_manager() const { return manager_; }
const GstEngine* gst_engine() const { return gst_engine_; }
SongInfoView* song_info_view() const { return song_info_view_; }
BackgroundStreams* background_streams() const { return streams_; }
BackgroundStreams* background_streams() const { return background_streams_; }
GlobalSearch* global_search() const { return global_search_; }
Appearance* appearance() const { return appearance_; }

Expand Down Expand Up @@ -149,7 +149,7 @@ class SettingsDialog : public QDialog {
GlobalShortcuts* manager_;
const GstEngine* gst_engine_;
SongInfoView* song_info_view_;
BackgroundStreams* streams_;
BackgroundStreams* background_streams_;
GlobalSearch* global_search_;
Appearance* appearance_;

Expand Down
Loading

0 comments on commit 89de27a

Please sign in to comment.