diff --git a/src/libs/image/impl/graphicsmagick/JPEGImage.cpp b/src/libs/image/impl/graphicsmagick/JPEGImage.cpp index 8cf7dfdc..85b2fac3 100644 --- a/src/libs/image/impl/graphicsmagick/JPEGImage.cpp +++ b/src/libs/image/impl/graphicsmagick/JPEGImage.cpp @@ -19,11 +19,11 @@ #include "JPEGImage.hpp" -#include "Exception.hpp" #include "RawImage.hpp" +#include "image/Exception.hpp" #include "utils/Logger.hpp" -namespace CoverArt::GraphicsMagick +namespace Image::GraphicsMagick { JPEGImage::JPEGImage(const RawImage& rawImage, unsigned quality) { diff --git a/src/libs/image/impl/graphicsmagick/JPEGImage.hpp b/src/libs/image/impl/graphicsmagick/JPEGImage.hpp index 37a5e163..9ead9f3c 100644 --- a/src/libs/image/impl/graphicsmagick/JPEGImage.hpp +++ b/src/libs/image/impl/graphicsmagick/JPEGImage.hpp @@ -25,9 +25,9 @@ #include -#include "cover/IEncodedImage.hpp" +#include "image/IEncodedImage.hpp" -namespace CoverArt::GraphicsMagick +namespace Image::GraphicsMagick { class RawImage; class JPEGImage : public IEncodedImage diff --git a/src/libs/image/impl/graphicsmagick/RawImage.cpp b/src/libs/image/impl/graphicsmagick/RawImage.cpp index ad4f2b70..fc74ae37 100644 --- a/src/libs/image/impl/graphicsmagick/RawImage.cpp +++ b/src/libs/image/impl/graphicsmagick/RawImage.cpp @@ -21,41 +21,43 @@ #include -#include "utils/Logger.hpp" #include "JPEGImage.hpp" -#include "Exception.hpp" +#include "image/Exception.hpp" +#include "utils/Logger.hpp" -namespace Image::GraphicsMagick +namespace Image { - std::unique_ptr decodeImage(const std::byte* encodedData, std::size_t encodedDataSize) { - return std::make_unique(encodedData, encodedDataSize); + return std::make_unique(encodedData, encodedDataSize); } std::unique_ptr decodeImage(const std::filesystem::path& path) { - return std::make_unique(path) + return std::make_unique(path); + } + + void + init(const std::filesystem::path& path) + { + Magick::InitializeMagick(path.string().c_str()); + + if (auto nbThreads {MagickLib::GetMagickResourceLimit(MagickLib::ThreadsResource)}; nbThreads != 1) + LMS_LOG(COVER, WARNING) << "Consider setting env var OMP_NUM_THREADS=1 to save resources"; + + if (!MagickLib::SetMagickResourceLimit(MagickLib::ThreadsResource, 1)) + LMS_LOG(COVER, ERROR) << "Cannot set Magick thread resource limit to 1!"; + + if (!MagickLib::SetMagickResourceLimit(MagickLib::DiskResource, 0)) + LMS_LOG(COVER, ERROR) << "Cannot set Magick disk resource limit to 0!"; + + LMS_LOG(COVER, INFO) << "Magick threads resource limit = " << GetMagickResourceLimit(MagickLib::ThreadsResource); + LMS_LOG(COVER, INFO) << "Magick Disk resource limit = " << GetMagickResourceLimit(MagickLib::DiskResource); } } -void -init(const std::filesystem::path& path) +namespace Image::GraphicsMagick { - Magick::InitializeMagick(path.string().c_str()); - - if (auto nbThreads {MagickLib::GetMagickResourceLimit(MagickLib::ThreadsResource)}; nbThreads != 1) - LMS_LOG(COVER, WARNING) << "Consider setting env var OMP_NUM_THREADS=1 to save resources"; - - if (!MagickLib::SetMagickResourceLimit(MagickLib::ThreadsResource, 1)) - LMS_LOG(COVER, ERROR) << "Cannot set Magick thread resource limit to 1!"; - - if (!MagickLib::SetMagickResourceLimit(MagickLib::DiskResource, 0)) - LMS_LOG(COVER, ERROR) << "Cannot set Magick disk resource limit to 0!"; - - LMS_LOG(COVER, INFO) << "Magick threads resource limit = " << GetMagickResourceLimit(MagickLib::ThreadsResource); - LMS_LOG(COVER, INFO) << "Magick Disk resource limit = " << GetMagickResourceLimit(MagickLib::DiskResource); -} RawImage::RawImage(const std::byte* encodedData, std::size_t encodedDataSize) { diff --git a/src/libs/image/impl/graphicsmagick/RawImage.hpp b/src/libs/image/impl/graphicsmagick/RawImage.hpp index 354c07c0..d1c180ed 100644 --- a/src/libs/image/impl/graphicsmagick/RawImage.hpp +++ b/src/libs/image/impl/graphicsmagick/RawImage.hpp @@ -28,14 +28,12 @@ #include #include -#include "cover/IEncodedImage.hpp" -#include "IRawImage.hpp" +#include "image/IEncodedImage.hpp" +#include "image/IRawImage.hpp" -namespace CoverArt::GraphicsMagick +namespace Image::GraphicsMagick { - void init(const std::filesystem::path& path); - - class RawImage : IRawImage + class RawImage : public IRawImage { public: RawImage(const std::byte* encodedData, std::size_t encodedDataSize); diff --git a/src/libs/image/impl/stb/RawImage.cpp b/src/libs/image/impl/stb/RawImage.cpp index 8ad944bc..df49ec9c 100644 --- a/src/libs/image/impl/stb/RawImage.cpp +++ b/src/libs/image/impl/stb/RawImage.cpp @@ -43,6 +43,12 @@ namespace Image { return std::make_unique(path); } + + void + init(const std::filesystem::path& path) + { + } +{ } namespace Image::STB diff --git a/src/libs/image/include/image/IRawImage.hpp b/src/libs/image/include/image/IRawImage.hpp index 67968ed0..79d8587f 100644 --- a/src/libs/image/include/image/IRawImage.hpp +++ b/src/libs/image/include/image/IRawImage.hpp @@ -19,6 +19,7 @@ #pragma once +#include #include #include "image/IEncodedImage.hpp" @@ -33,6 +34,7 @@ namespace Image virtual std::unique_ptr encodeToJPEG(unsigned quality) const = 0; }; + void init(const std::filesystem::path& path); std::unique_ptr decodeImage(const std::byte* encodedData, std::size_t encodedDataSize); std::unique_ptr decodeImage(const std::filesystem::path& path); } diff --git a/src/libs/services/database/impl/SqlQuery.hpp b/src/libs/services/database/impl/SqlQuery.hpp index 7c013aa7..5a11fe99 100644 --- a/src/libs/services/database/impl/SqlQuery.hpp +++ b/src/libs/services/database/impl/SqlQuery.hpp @@ -41,7 +41,6 @@ class WhereClause private: std::string _clause; // WHERE clause std::list _bindArgs; - }; class InnerJoinClause diff --git a/src/libs/services/database/include/services/database/Track.hpp b/src/libs/services/database/include/services/database/Track.hpp index 38297cb3..3f0bf099 100644 --- a/src/libs/services/database/include/services/database/Track.hpp +++ b/src/libs/services/database/include/services/database/Track.hpp @@ -184,7 +184,6 @@ class Track : public Object } private: - static const std::size_t _maxNameLength = 128; static const std::size_t _maxCopyrightLength = 128; static const std::size_t _maxCopyrightURLLength = 128; diff --git a/src/libs/services/scrobbling/impl/ScrobblerBase.cpp b/src/libs/services/scrobbling/impl/ScrobblerBase.cpp deleted file mode 100644 index a21d312b..00000000 --- a/src/libs/services/scrobbling/impl/ScrobblerBase.cpp +++ /dev/null @@ -1,72 +0,0 @@ -/* - * Copyright (C) 2021 Emeric Poupon - * - * This file is part of LMS. - * - * LMS is free software: you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation, either version 3 of the License, or - * (at your option) any later version. - * - * LMS is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with LMS. If not, see . - */ - -#pragma once - -#include -#include "services/scrobbling/Listen.hpp" - -namespace Scrobbling -{ - ScrobblerBase::ScrobblerBase(Database::Db& db) - : _db {db} - { - } - - Database::TrackListId - ScrobberBase::getListensTrackList(Database::UserId userId, std::string_view trackListName) - { - std::string_view listensTrackListName {getListensTrackListName()}; - Database::Session& session {_db.getTLSSession()}; - - { - auto transaction {session.createSharedTransaction()}; - - if (auto trackList {Database::TrackList::get(session, listensTrackListName, Database::TrackList::Type::Internal, userId)}) - return trackList->getId(); - } - - { - auto transaction {session.createUniqueTransaction()}; - if (auto trackList {Database::TrackList::get(session, listensTrackListName, Database::TrackList::Type::Internal, userId)}) - return trackList->getId(); - - const Database::User::pointer user {Database::User::getById(session, userId)}; - if (!user) - return {}; - - Database::TrackList::pointer trackList {Database::TrackList::create(session, listensTrackListName, Database::TrackList::Type::Internal, false, user)}; - return trackList->getId(); - } - } - - bool - ScrobberBase::saveTimedListen(const TimedListen& listen, std::string_view trackListName) - { - const Database::TrackListId trackListId {getListensTrackList(listen.userId)}; - if (!trackListId) - return false; - - { - - return true; - } - } -} // ns Scrobbling - diff --git a/src/lms/main.cpp b/src/lms/main.cpp index 34f82676..8ad33f19 100644 --- a/src/lms/main.cpp +++ b/src/lms/main.cpp @@ -25,6 +25,7 @@ #include #include +#include "image/IRawImage.hpp" #include "services/auth/IAuthTokenService.hpp" #include "services/auth/IPasswordService.hpp" #include "services/auth/IEnvService.hpp" @@ -254,6 +255,7 @@ int main(int argc, char* argv[]) else throw LmsException {"Bad value '" + authenticationBackend + "' for 'authentication-backend'"}; + Image::init(argv[0]); Service coverService {Cover::createCoverService(database, argv[0], server.appRoot() + "/images/unknown-cover.jpg")}; Service recommendationService {Recommendation::createRecommendationService(database)}; Service scannerService {Scanner::createScannerService(database, *recommendationService)};