Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make background steams build-optional #7129

Open
wants to merge 3 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ find_library(PROTOBUF_STATIC_LIBRARY libprotobuf.a libprotobuf)

pkg_check_modules(CDIO libcdio)
pkg_check_modules(CHROMAPRINT REQUIRED libchromaprint)
pkg_search_module(CRYPTOPP cryptopp libcrypto++)
pkg_search_module(CRYPTOPP libcryptopp libcrypto++)
pkg_check_modules(GIO gio-2.0)
pkg_check_modules(GLIB REQUIRED glib-2.0)
pkg_check_modules(GOBJECT REQUIRED gobject-2.0)
Expand Down 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
46 changes: 34 additions & 12 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,7 @@ 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));
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));
ui_->action_love->setIcon(IconLoader::Load("love", IconLoader::Lastfm));

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

background_streams_->AddAction("Rain", ui_->action_rain);
background_streams_->AddAction("Hypnotoad", ui_->action_hypnotoad);
background_streams_->AddAction("Make it so!", ui_->action_enterprise);
// Add menus for background streams
#ifdef HAVE_BACKGROUND_STREAMS
QAction* action_rain =
ui_->menu_extras->addAction(tr("Rain"));
action_rain->setIcon(
IconLoader::Load("weather-showers-scattered", IconLoader::Base));
action_rain->setCheckable(true);
background_streams_->AddAction("Rain", action_rain);

QAction* action_hypnotoad =
ui_->menu_extras->addAction(tr("All Glory to the Hypnotoad!"));
action_hypnotoad->setIcon(
IconLoader::Load("hypnotoad", IconLoader::Base));
action_hypnotoad->setCheckable(true);
background_streams_->AddAction("Hypnotoad", action_hypnotoad);

QAction* action_enterprise =
ui_->menu_extras->addAction(tr("Make it so!"));
action_enterprise->setIcon(
IconLoader::Load("enterprise", IconLoader::Base));
action_enterprise->setCheckable(true);
background_streams_->AddAction("Make it so!", action_enterprise);
#endif

// Playlist view actions
ui_->action_next_playlist->setShortcuts(
Expand Down Expand Up @@ -938,8 +956,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)));
connect(ui_->action_hypnotoad, SIGNAL(toggled(bool)), ui_->now_playing,
#ifdef HAVE_BACKGROUND_STREAMS
connect(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 +2734,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
27 changes: 0 additions & 27 deletions src/ui/mainwindow.ui
Original file line number Diff line number Diff line change
Expand Up @@ -541,9 +541,6 @@
<property name="title">
<string>&amp;Extras</string>
</property>
<addaction name="action_rain"/>
<addaction name="action_hypnotoad"/>
<addaction name="action_enterprise"/>
<addaction name="action_kittens"/>
<addaction name="action_console"/>
<addaction name="separator"/>
Expand Down Expand Up @@ -735,30 +732,6 @@
<string>Cover Manager</string>
</property>
</action>
<action name="action_rain">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string comment="Label for button to enable/disable rain background sound.">Rain</string>
</property>
</action>
<action name="action_hypnotoad">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string comment="Label for button to enable/disable Hypnotoad background sound.">All Glory to the Hypnotoad!</string>
</property>
</action>
<action name="action_enterprise">
<property name="checkable">
<bool>true</bool>
</property>
<property name="text">
<string comment="Label for button to enable/disable Enterprise background sound.">Make it so!</string>
</property>
</action>
<action name="action_kittens">
<property name="checkable">
<bool>true</bool>
Expand Down
Loading