Made compilation work with unity builds

This commit is contained in:
emeric
2025-04-20 11:26:47 +02:00
parent a5b130305e
commit 7767ddb78f
28 changed files with 206 additions and 160 deletions
+6
View File
@@ -26,11 +26,17 @@ if (${LMS_IMAGE_BACKEND} STREQUAL "stb")
target_sources(lmsimage PRIVATE
impl/stb/Image.cpp
impl/stb/Exception.cpp
impl/stb/RawImage.cpp
impl/stb/StbImage.cpp
impl/stb/StbImageResize.cpp
impl/stb/StbImageWrite.cpp
)
set_property(SOURCE impl/stb/StbImage.cpp PROPERTY SKIP_UNITY_BUILD_INCLUSION ON)
set_property(SOURCE impl/stb/StbImageResize.cpp PROPERTY SKIP_UNITY_BUILD_INCLUSION ON)
set_property(SOURCE impl/stb/StbImageWrite.cpp PROPERTY SKIP_UNITY_BUILD_INCLUSION ON)
target_compile_options(lmsimage PRIVATE "-DSTB_IMAGE_RESIZE_VERSION=${STB_IMAGE_RESIZE_VERSION}")
target_include_directories(lmsimage PRIVATE ${STB_IMAGE_INCLUDE_DIR})
+36
View File
@@ -0,0 +1,36 @@
/*
* Copyright (C) 2020 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 <http://www.gnu.org/licenses/>.
*/
#include "Exception.hpp"
#include "StbImage.hpp"
namespace lms::image
{
StbiException::StbiException(std::string_view desc)
: Exception{ std::string{ desc } + ": " + getLastFailureReason() }
{
}
std::string StbiException::getLastFailureReason()
{
const char* failureReason{ ::stbi_failure_reason() };
return failureReason ? failureReason : "unknown reason";
}
} // namespace lms::image
+36
View File
@@ -0,0 +1,36 @@
/*
* Copyright (C) 2020 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 <http://www.gnu.org/licenses/>.
*/
#pragma once
#include <string_view>
#include "image/Exception.hpp"
namespace lms::image
{
class StbiException : public Exception
{
public:
StbiException(std::string_view desc);
private:
static std::string getLastFailureReason();
};
} // namespace lms::image
+1
View File
@@ -21,6 +21,7 @@
#include <array>
#include "Exception.hpp"
#include "StbImage.hpp"
#include "StbImageWrite.hpp"
+1
View File
@@ -19,6 +19,7 @@
#include "RawImage.hpp"
#include "Exception.hpp"
#include "StbImage.hpp"
#include "StbImageResize.hpp"
-14
View File
@@ -19,17 +19,3 @@
#define STB_IMAGE_IMPLEMENTATION
#include "StbImage.hpp"
namespace lms::image
{
StbiException::StbiException(std::string_view desc)
: Exception{ std::string{ desc } + ": " + getLastFailureReason() }
{
}
std::string StbiException::getLastFailureReason()
{
const char* failureReason{ ::stbi_failure_reason() };
return failureReason ? failureReason : "unknown reason";
}
} // namespace lms::image
+1 -16
View File
@@ -16,6 +16,7 @@
* You should have received a copy of the GNU General Public License
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
#pragma once
#define STBI_ONLY_JPEG
@@ -24,19 +25,3 @@
#define STBI_FAILURE_USERMSG
#include <stb_image.h>
#include <string_view>
#include "image/Exception.hpp"
namespace lms::image
{
class StbiException : public Exception
{
public:
StbiException(std::string_view desc);
private:
static std::string getLastFailureReason();
};
} // namespace lms::image
+3 -3
View File
@@ -30,7 +30,7 @@ namespace lms::metadata
namespace
{
// Mapping to internal avformat names and/or common alternative custom names
static const std::unordered_map<TagType, std::vector<std::string>> tagMapping{
static const std::unordered_map<TagType, std::vector<std::string>> avFormatTagMapping{
{ TagType::AcoustID, { "ACOUSTID_ID", "ACOUSTID ID" } },
{ TagType::Advisory, { "ITUNESADVISORY" } },
{ TagType::Album, { "ALBUM", "TALB", "WM/ALBUMTITLE" } },
@@ -171,8 +171,8 @@ namespace lms::metadata
void AvFormatTagReader::visitTagValues(TagType tag, TagValueVisitor visitor) const
{
auto itTagNames{ tagMapping.find(tag) };
if (itTagNames == std::cend(tagMapping))
auto itTagNames{ avFormatTagMapping.find(tag) };
if (itTagNames == std::cend(avFormatTagMapping))
return;
for (const std::string& tagName : itTagNames->second)
+2 -2
View File
@@ -48,7 +48,7 @@ namespace lms::metadata
{
namespace
{
class ParsingFailedException : public Exception
class ImageParsingFailedException : public Exception
{
};
@@ -362,7 +362,7 @@ namespace lms::metadata
if (_file.isNull())
{
LMS_LOG(METADATA, ERROR, "File " << p << ": parsing failed");
throw ParsingFailedException{};
throw ImageParsingFailedException{};
}
}
+6 -6
View File
@@ -55,12 +55,12 @@ namespace lms::metadata
{
namespace
{
class ParsingFailedException : public Exception
class TagParsingFailedException : public Exception
{
};
// Mapping to internal taglib names and/or common alternative custom names
const std::unordered_map<TagType, std::vector<std::string>> tagMapping{
const std::unordered_map<TagType, std::vector<std::string>> tagLibTagMapping{
{ TagType::AcoustID, { "ACOUSTID_ID", "ACOUSTID ID" } },
{ TagType::Advisory, { "ITUNESADVISORY" } },
{ TagType::Album, { "ALBUM" } },
@@ -228,13 +228,13 @@ namespace lms::metadata
if (_file.isNull())
{
LMS_LOG(METADATA, ERROR, "File " << p << ": parsing failed");
throw ParsingFailedException{};
throw TagParsingFailedException{};
}
if (!_file.audioProperties())
{
LMS_LOG(METADATA, ERROR, "File " << p << ": no audio properties");
throw ParsingFailedException{};
throw TagParsingFailedException{};
}
computeAudioProperties();
@@ -465,8 +465,8 @@ namespace lms::metadata
void TagLibTagReader::visitTagValues(TagType tag, TagValueVisitor visitor) const
{
auto itTagNames{ tagMapping.find(tag) };
if (itTagNames == std::cend(tagMapping))
auto itTagNames{ tagLibTagMapping.find(tag) };
if (itTagNames == std::cend(tagLibTagMapping))
return;
for (const std::string& tagName : itTagNames->second)
@@ -51,7 +51,7 @@ namespace lms::scanner
};
using ArtistImageAssociationContainer = std::deque<ArtistImageAssociation>;
struct SearchImageContext
struct SearchArtistImageContext
{
db::Session& session;
db::ArtistId lastRetrievedArtistId;
@@ -59,7 +59,7 @@ namespace lms::scanner
std::span<const std::string> artistFileNames;
};
db::Image::pointer findImageInDirectory(SearchImageContext& searchContext, const std::filesystem::path& directoryPath, std::span<const std::string> fileStemsToSearch)
db::Image::pointer findImageInDirectory(SearchArtistImageContext& searchContext, const std::filesystem::path& directoryPath, std::span<const std::string> fileStemsToSearch)
{
db::Image::pointer image;
@@ -85,7 +85,7 @@ namespace lms::scanner
return image;
}
db::Image::pointer getImageFromMbid(SearchImageContext& searchContext, const core::UUID& mbid)
db::Image::pointer getImageFromMbid(SearchArtistImageContext& searchContext, const core::UUID& mbid)
{
db::Image::pointer image;
@@ -98,7 +98,7 @@ namespace lms::scanner
return image;
}
db::Image::pointer searchImageInArtistInfoDirectory(SearchImageContext& searchContext, db::ArtistId artistId)
db::Image::pointer searchImageInArtistInfoDirectory(SearchArtistImageContext& searchContext, db::ArtistId artistId)
{
db::Image::pointer image;
@@ -116,7 +116,7 @@ namespace lms::scanner
return image;
}
db::Image::pointer searchImageInDirectories(SearchImageContext& searchContext, db::ArtistId artistId)
db::Image::pointer searchImageInDirectories(SearchArtistImageContext& searchContext, db::ArtistId artistId)
{
db::Image::pointer image;
@@ -169,7 +169,7 @@ namespace lms::scanner
return image;
}
db::Image::pointer computeBestArtistImage(SearchImageContext& searchContext, const db::Artist::pointer& artist)
db::Image::pointer computeBestArtistImage(SearchArtistImageContext& searchContext, const db::Artist::pointer& artist)
{
db::Image::pointer image;
@@ -185,7 +185,7 @@ namespace lms::scanner
return image;
}
bool fetchNextArtistImagesToUpdate(SearchImageContext& searchContext, ArtistImageAssociationContainer& artistImageAssociations)
bool fetchNextArtistImagesToUpdate(SearchArtistImageContext& searchContext, ArtistImageAssociationContainer& artistImageAssociations)
{
const db::ArtistId artistId{ searchContext.lastRetrievedArtistId };
@@ -271,7 +271,7 @@ namespace lms::scanner
context.currentStepStats.totalElems = db::Artist::getCount(session);
}
SearchImageContext searchContext{
SearchArtistImageContext searchContext{
.session = session,
.lastRetrievedArtistId = {},
.artistFileNames = _artistFileNames,
@@ -32,9 +32,6 @@ namespace lms::scanner
{
namespace
{
constexpr std::size_t readBatchSize{ 100 };
constexpr std::size_t writeBatchSize{ 20 };
struct TrackLyricsAssociation
{
db::TrackLyricsId trackLyricsId;
@@ -83,6 +80,8 @@ namespace lms::scanner
bool fetchNextTrackLyricsToUpdate(SearchTrackLyricsContext& searchContext, TrackLyricsAssociationContainer& trackLyricsAssociations)
{
constexpr std::size_t readBatchSize{ 100 };
const db::TrackLyricsId trackLyricsId{ searchContext.lastRetrievedTrackLyricsId };
{
@@ -125,6 +124,8 @@ namespace lms::scanner
void updateTrackLyrics(db::Session& session, TrackLyricsAssociationContainer& lyricsAssociations)
{
constexpr std::size_t writeBatchSize{ 20 };
while (!lyricsAssociations.empty())
{
auto transaction{ session.createWriteTransaction() };
@@ -37,9 +37,6 @@ namespace lms::scanner
{
namespace
{
constexpr std::size_t readBatchSize{ 20 };
constexpr std::size_t writeBatchSize{ 5 };
struct TrackInfo
{
db::TrackId trackId;
@@ -118,6 +115,8 @@ namespace lms::scanner
const db::PlayListFileId playListFileIdId{ searchContext.lastRetrievedPlayListFileId };
{
constexpr std::size_t readBatchSize{ 20 };
auto transaction{ searchContext.session.createReadTransaction() };
db::PlayListFile::find(searchContext.session, searchContext.lastRetrievedPlayListFileId, readBatchSize, [&](const db::PlayListFile::pointer& playListFile) {
@@ -199,6 +198,8 @@ namespace lms::scanner
void updatePlayListFiles(db::Session& session, PlayListFileAssociationContainer& playListFileAssociations)
{
constexpr std::size_t writeBatchSize{ 5 };
while (!playListFileAssociations.empty())
{
auto transaction{ session.createWriteTransaction() };
@@ -38,9 +38,6 @@ namespace lms::scanner
{
namespace
{
constexpr std::size_t readBatchSize{ 100 };
constexpr std::size_t writeBatchSize{ 20 };
struct ReleaseImageAssociation
{
db::ReleaseId releaseId;
@@ -48,7 +45,7 @@ namespace lms::scanner
};
using ReleaseImageAssociationContainer = std::deque<ReleaseImageAssociation>;
struct SearchImageContext
struct SearchReleaseImageContext
{
db::Session& session;
db::ReleaseId lastRetrievedReleaseId;
@@ -56,7 +53,7 @@ namespace lms::scanner
const std::vector<std::string>& releaseFileNames;
};
db::Image::pointer findImageInDirectory(SearchImageContext& searchContext, const std::filesystem::path& directoryPath)
db::Image::pointer findImageInDirectory(SearchReleaseImageContext& searchContext, const std::filesystem::path& directoryPath)
{
db::Image::pointer image;
@@ -82,7 +79,7 @@ namespace lms::scanner
return image;
}
db::Image::pointer computeBestReleaseImage(SearchImageContext& searchContext, const db::Release::pointer& release)
db::Image::pointer computeBestReleaseImage(SearchReleaseImageContext& searchContext, const db::Release::pointer& release)
{
db::Image::pointer image;
@@ -130,11 +127,13 @@ namespace lms::scanner
return image;
}
bool fetchNextReleaseImagesToUpdate(SearchImageContext& searchContext, ReleaseImageAssociationContainer& releaseImageAssociations)
bool fetchNextReleaseImagesToUpdate(SearchReleaseImageContext& searchContext, ReleaseImageAssociationContainer& releaseImageAssociations)
{
const db::ReleaseId releaseId{ searchContext.lastRetrievedReleaseId };
{
constexpr std::size_t readBatchSize{ 100 };
auto transaction{ searchContext.session.createReadTransaction() };
db::Release::find(searchContext.session, searchContext.lastRetrievedReleaseId, readBatchSize, [&](const db::Release::pointer& release) {
@@ -166,6 +165,8 @@ namespace lms::scanner
void updateReleaseImages(db::Session& session, ReleaseImageAssociationContainer& imageAssociations)
{
constexpr std::size_t writeBatchSize{ 20 };
while (!imageAssociations.empty())
{
auto transaction{ session.createWriteTransaction() };
@@ -216,7 +217,7 @@ namespace lms::scanner
context.currentStepStats.totalElems = db::Release::getCount(session);
}
SearchImageContext searchContext{
SearchReleaseImageContext searchContext{
.session = session,
.lastRetrievedReleaseId = {},
.releaseFileNames = _releaseFileNames,
@@ -62,7 +62,7 @@ namespace lms::api::subsonic
return res;
}
ReleaseId getReleaseFromDirectory(Session& session, DirectoryId directory)
ReleaseId getReleaseIdFromDirectory(Session& session, DirectoryId directory)
{
auto transaction{ session.createReadTransaction() };
@@ -117,7 +117,7 @@ namespace lms::api::subsonic
for (const DirectoryId id : params.directoryIds)
{
if (const ReleaseId releaseId{ getReleaseFromDirectory(context.dbSession, id) }; releaseId.isValid())
if (const ReleaseId releaseId{ getReleaseIdFromDirectory(context.dbSession, id) }; releaseId.isValid())
core::Service<feedback::IFeedbackService>::get()->star(context.user->getId(), releaseId);
}
@@ -139,7 +139,7 @@ namespace lms::api::subsonic
for (const DirectoryId id : params.directoryIds)
{
if (const ReleaseId releaseId{ getReleaseFromDirectory(context.dbSession, id) }; releaseId.isValid())
if (const ReleaseId releaseId{ getReleaseIdFromDirectory(context.dbSession, id) }; releaseId.isValid())
core::Service<feedback::IFeedbackService>::get()->unstar(context.user->getId(), releaseId);
}
@@ -163,7 +163,7 @@ namespace lms::api::subsonic
core::Service<feedback::IFeedbackService>::get()->setRating(context.user->getId(), *artistId, params.rating);
else if (const DirectoryId * directoryId{ std::get_if<DirectoryId>(&params.id) })
{
if (const ReleaseId releaseId{ getReleaseFromDirectory(context.dbSession, *directoryId) }; releaseId.isValid())
if (const ReleaseId releaseId{ getReleaseIdFromDirectory(context.dbSession, *directoryId) }; releaseId.isValid())
core::Service<feedback::IFeedbackService>::get()->setRating(context.user->getId(), releaseId, params.rating);
}
else if (const ReleaseId * releaseId{ std::get_if<ReleaseId>(&params.id) })