Skip to content

Commit

Permalink
App/Sys: Final fixes + optimizations before release
Browse files Browse the repository at this point in the history
  • Loading branch information
tallbl0nde committed Nov 1, 2020
1 parent cc3e30e commit 8491fbb
Show file tree
Hide file tree
Showing 15 changed files with 54 additions and 23 deletions.
3 changes: 3 additions & 0 deletions Application/include/utils/NX.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ namespace Utils::NX {
// Does nothing if state matches
void setCPUBoost(bool);

// Enable/disable low fs priority
void setLowFsPriority(bool);

// Enable/disable 'media playing' flag
// Does nothing if state matches
void setPlayingMedia(bool);
Expand Down
18 changes: 9 additions & 9 deletions Application/source/Application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ namespace Main {
this->setHighlightAnimation(nullptr);
this->display->setFadeIn();
this->display->setFadeOut();
this->display->setShowFPS(true);
// this->display->setShowFPS(true);
this->exitPrompt = nullptr;

// Setup screens
Expand All @@ -65,14 +65,14 @@ namespace Main {
// Start checking for an update
this->hasUpdate_ = false;
this->updateThread = std::async(std::launch::async, [this]() {
// Updater updater = Updater();
// if (updater.needsCheck(updateInterval)) {
// if (updater.checkForUpdate()) {
// this->hasUpdate_ = updater.availableUpdate();
// }
// } else {
// this->hasUpdate_ = updater.availableUpdate();
// }
Updater updater = Updater();
if (updater.needsCheck(updateInterval)) {
if (updater.checkForUpdate()) {
this->hasUpdate_ = updater.availableUpdate();
}
} else {
this->hasUpdate_ = updater.availableUpdate();
}
});
}

Expand Down
25 changes: 16 additions & 9 deletions Application/source/LibraryScanner.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
#include "LibraryScanner.hpp"
#include "Log.hpp"
#include "Paths.hpp"
#include "utils/Fs.hpp"
#include "utils/FS.hpp"
#include "utils/Image.hpp"
#include "utils/MP3.hpp"
#include "utils/NX.hpp"
#include "utils/Timer.hpp"
#include "utils/Utils.hpp"

Expand Down Expand Up @@ -101,15 +102,19 @@ LibraryScanner::Status LibraryScanner::parseFileUpdate(const FilePair & file) {

LibraryScanner::Status LibraryScanner::processFiles() {
// First get all paths within folder along with modified timestamp
Utils::NX::setLowFsPriority(true);
std::vector<FilePair> files;
for (auto & entry: std::filesystem::recursive_directory_iterator(this->searchPath)) {
if (entry.path().extension() == ".mp3") {
// Why is this conversion so hard?
auto time = entry.last_write_time();
auto clock = std::chrono::file_clock::to_sys(time);
unsigned int timestamp = (unsigned int)std::chrono::system_clock::to_time_t(clock);

files.push_back(FilePair{entry.path().string(), timestamp});

if (Utils::Fs::fileExists(this->searchPath)) {
for (auto & entry: std::filesystem::recursive_directory_iterator(this->searchPath)) {
if (entry.path().extension() == ".mp3") {
// Why is this conversion so hard?
auto time = entry.last_write_time();
auto clock = std::chrono::file_clock::to_sys(time);
unsigned int timestamp = (unsigned int)std::chrono::system_clock::to_time_t(clock);

files.push_back(FilePair{entry.path().string(), timestamp});
}
}
}
Log::writeInfo("[SCAN] Found " + std::to_string(files.size()) + " files");
Expand All @@ -124,6 +129,7 @@ LibraryScanner::Status LibraryScanner::processFiles() {
std::vector< std::pair<std::string, unsigned int> > tmp = this->database->getAllSongFileInfo(dbOK);
if (!dbOK) {
Log::writeError("[SCAN] Couldn't read filesystem info from database");
Utils::NX::setLowFsPriority(false);
return Status::ErrDatabase;
}
for (size_t i = 0; i < tmp.size(); i++) {
Expand Down Expand Up @@ -167,6 +173,7 @@ LibraryScanner::Status LibraryScanner::processFiles() {
// Wait for threads to finish
addThread.get();
updateThread.get();
Utils::NX::setLowFsPriority(false);

// Log status
Log::writeInfo("[SCAN] Adding " + std::to_string(this->addFiles.size()) + " files");
Expand Down
1 change: 1 addition & 0 deletions Application/source/ui/frame/settings/About.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,7 @@ namespace Frame::Settings {
this->addComment("JSON for Modern C++\nCopyright © 2013-2020 Niels Lohmann\nMIT License\nhttps://github.com/nlohmann/json");
this->addComment("libcURL\nCopyright © 1996-2020 Daniel Stenberg\nMIT/X Derivate License\nhttps://curl.haxx.se");
this->addComment("libmpg123\nLGPL 2.1 License\nhttps://www.mpg123.de");
this->addComment("libnx\nCopyright © 2017-2020 libnx Authors\nISC License\nhttps://github.com/switchbrew/libnx");
this->addComment("minIni\nCopyright © compuphase\nApache 2 License\nhttps://github.com/compuphase/minIni");
this->addComment("SDL2_gfx Extensions\nCopyright © 2018 Richard T. Russell\nzlib License\nhttps://github.com/rtrussell/BBCSDL");
this->addComment("Splash\nCopyright © 2020 Google\nApache 2 License\nhttps://github.com/tallbl0nde/Splash");
Expand Down
1 change: 1 addition & 0 deletions Application/source/ui/frame/settings/SysMP3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ namespace Frame::Settings {
this->addButton("Equalizer", [this]() {
this->showEqualizer();
});
this->addComment("Note: There may be a slight delay before any changes take effect.");

// Setup overlay
this->ovlEQ = new CustomOvl::Equalizer("Equalizer");
Expand Down
3 changes: 2 additions & 1 deletion Application/source/ui/screen/Update.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -300,7 +300,7 @@ namespace Screen {
} else {
this->presentInfo("Update installed!", "Both the sysmodule and this application will terminate.", [this]() {
this->msgbox->close();
// terminate services
this->app->sysmodule()->terminate();
this->app->exit(true);
});
}
Expand Down Expand Up @@ -347,6 +347,7 @@ namespace Screen {
}

void Update::onUnload() {
this->thread.get();
this->removeElement(this->bg);
this->removeElement(this->icon);
this->removeElement(this->container);
Expand Down
4 changes: 4 additions & 0 deletions Application/source/utils/NX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,10 @@ namespace Utils::NX {
boost = enable;
}

void setLowFsPriority(bool low) {
fsSetPriority(low ? FsPriority_Background : FsPriority_Normal);
}

static bool media = false;
void setPlayingMedia(bool enable) {
// Only set if different state
Expand Down
Empty file removed Images/.gitignore
Empty file.
Binary file added Images/screenshots.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ clean:
@echo -e '\033[1m>> Application\033[0m'
@$(MAKE) -s -C Application/ clean-all
@echo -e '\033[1m>> Overlay\033[0m'
@$(MAKE) -C Overlay/ clean
@$(MAKE) -s -C Overlay/ clean
@echo -e '\033[1m>> Sysmodule\033[0m'
@$(MAKE) -s -C Sysmodule/ clean
@echo -e '\033[1m>> SD Card\033[0m'
Expand Down
5 changes: 5 additions & 0 deletions Sysmodule/include/nx/NX.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,11 @@ namespace NX {
// Close any started services
void stopServices();

namespace Fs {
// Set whether or not to use a higher priority for fs operations
void setHighPriority(const bool);
};

namespace Gpio {
// Prepare gpio for use
bool prepare();
Expand Down
3 changes: 3 additions & 0 deletions Sysmodule/source/Service.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -657,6 +657,9 @@ void MainService::ipcThread() {
}

void MainService::playbackThread() {
// Request a higher priority for FS access
NX::Fs::setHighPriority(true);

while (!this->exit_) {
std::unique_lock<std::shared_mutex> sMtx(this->sMutex);
std::unique_lock<std::shared_mutex> sqMtx(this->sqMutex);
Expand Down
2 changes: 1 addition & 1 deletion Sysmodule/source/main.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
// DB: ~0.5MB
// IPC: ~0.2MB
// Queue: ~0.2MB
// MP3: ~0.3MB
// MP3: ~0.5MB
#define INNER_HEAP_SIZE (size_t)(2 * 1024 * 1024)

// It hangs if I don't use C... I wish I knew why!
Expand Down
4 changes: 2 additions & 2 deletions Sysmodule/source/nx/Audio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,8 @@
#include "nx/NX.hpp"
#include <switch.h>

constexpr size_t bufferSize = 0x3C00; // Size of each buffer (15kB)
constexpr size_t maxBuffers = 4; // Maximum number of buffer slots
constexpr size_t bufferSize = 0xC800; // Size of each buffer (50kB)
constexpr size_t maxBuffers = 6; // Maximum number of buffer slots (50KB * 6 = 300KB)
constexpr size_t outputChannels = 2; // Number of channels to output (should always be 2)

Audio * Audio::instance = nullptr; // Our singleton instance
Expand Down
6 changes: 6 additions & 0 deletions Sysmodule/source/nx/NX.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -159,6 +159,12 @@ namespace NX {
}
}

namespace Fs {
void setHighPriority(const bool b) {
fsSetPriority(b ? FsPriority_Realtime : FsPriority_Normal);
}
};

namespace Gpio {
static bool gpioPrepared = false; // Set true if ready to poll pad
static GpioPadSession gpioSession; // Current session used to read pad
Expand Down

0 comments on commit 8491fbb

Please sign in to comment.