Auto reformatted the base, ref #470

This commit is contained in:
emeric
2024-05-24 23:31:52 +02:00
parent 83b868673c
commit 39941d90a3
460 changed files with 8583 additions and 8514 deletions
+70 -51
View File
@@ -53,7 +53,8 @@ namespace lms::av
public:
AudioFileException(int avError)
: Exception{ "AudioFileException: " + averror_to_string(avError) }
{}
{
}
};
void getMetaDataFromDictionnary(AVDictionary* dictionnary, AudioFile::MetadataMap& res)
@@ -72,32 +73,52 @@ namespace lms::av
{
switch (codec)
{
case AV_CODEC_ID_MP3: return DecodingCodec::MP3;
case AV_CODEC_ID_AAC: return DecodingCodec::AAC;
case AV_CODEC_ID_AC3: return DecodingCodec::AC3;
case AV_CODEC_ID_VORBIS: return DecodingCodec::VORBIS;
case AV_CODEC_ID_WMAV1: return DecodingCodec::WMAV1;
case AV_CODEC_ID_WMAV2: return DecodingCodec::WMAV2;
case AV_CODEC_ID_FLAC: return DecodingCodec::FLAC;
case AV_CODEC_ID_ALAC: return DecodingCodec::ALAC;
case AV_CODEC_ID_WAVPACK: return DecodingCodec::WAVPACK;
case AV_CODEC_ID_MUSEPACK7: return DecodingCodec::MUSEPACK7;
case AV_CODEC_ID_MUSEPACK8: return DecodingCodec::MUSEPACK8;
case AV_CODEC_ID_APE: return DecodingCodec::APE;
case AV_CODEC_ID_EAC3: return DecodingCodec::EAC3;
case AV_CODEC_ID_MP4ALS: return DecodingCodec::MP4ALS;
case AV_CODEC_ID_OPUS: return DecodingCodec::OPUS;
case AV_CODEC_ID_SHORTEN: return DecodingCodec::SHORTEN;
case AV_CODEC_ID_DSD_LSBF: return DecodingCodec::DSD_LSBF;
case AV_CODEC_ID_DSD_LSBF_PLANAR: return DecodingCodec::DSD_LSBF_PLANAR;
case AV_CODEC_ID_DSD_MSBF: return DecodingCodec::DSD_MSBF;
case AV_CODEC_ID_DSD_MSBF_PLANAR: return DecodingCodec::DSD_MSBF_PLANAR;
case AV_CODEC_ID_MP3:
return DecodingCodec::MP3;
case AV_CODEC_ID_AAC:
return DecodingCodec::AAC;
case AV_CODEC_ID_AC3:
return DecodingCodec::AC3;
case AV_CODEC_ID_VORBIS:
return DecodingCodec::VORBIS;
case AV_CODEC_ID_WMAV1:
return DecodingCodec::WMAV1;
case AV_CODEC_ID_WMAV2:
return DecodingCodec::WMAV2;
case AV_CODEC_ID_FLAC:
return DecodingCodec::FLAC;
case AV_CODEC_ID_ALAC:
return DecodingCodec::ALAC;
case AV_CODEC_ID_WAVPACK:
return DecodingCodec::WAVPACK;
case AV_CODEC_ID_MUSEPACK7:
return DecodingCodec::MUSEPACK7;
case AV_CODEC_ID_MUSEPACK8:
return DecodingCodec::MUSEPACK8;
case AV_CODEC_ID_APE:
return DecodingCodec::APE;
case AV_CODEC_ID_EAC3:
return DecodingCodec::EAC3;
case AV_CODEC_ID_MP4ALS:
return DecodingCodec::MP4ALS;
case AV_CODEC_ID_OPUS:
return DecodingCodec::OPUS;
case AV_CODEC_ID_SHORTEN:
return DecodingCodec::SHORTEN;
case AV_CODEC_ID_DSD_LSBF:
return DecodingCodec::DSD_LSBF;
case AV_CODEC_ID_DSD_LSBF_PLANAR:
return DecodingCodec::DSD_LSBF_PLANAR;
case AV_CODEC_ID_DSD_MSBF:
return DecodingCodec::DSD_MSBF;
case AV_CODEC_ID_DSD_MSBF_PLANAR:
return DecodingCodec::DSD_MSBF_PLANAR;
default:
return DecodingCodec::UNKNOWN;
}
}
}
} // namespace
std::unique_ptr<IAudioFile> parseAudioFile(const std::filesystem::path& p)
{
@@ -183,8 +204,8 @@ namespace lms::av
{
int res = ::av_find_best_stream(_context,
AVMEDIA_TYPE_AUDIO,
-1, // Auto
-1, // Auto
-1, // Auto
-1, // Auto
NULL,
0);
@@ -218,8 +239,7 @@ namespace lms::av
void AudioFile::visitAttachedPictures(std::function<void(const Picture&)> func) const
{
static const std::unordered_map<int, std::string> codecMimeMap =
{
static const std::unordered_map<int, std::string> codecMimeMap{
{ AV_CODEC_ID_BMP, "image/x-bmp" },
{ AV_CODEC_ID_GIF, "image/gif" },
{ AV_CODEC_ID_MJPEG, "image/jpeg" },
@@ -305,31 +325,30 @@ namespace lms::av
// List should be sync with the demuxers shipped in the lms's docker version
// + the _audioFileExtensions in ScanSettings
// std::filesystem::path does not seem to have std::hash specialization on freebsd
static const std::unordered_map<std::string, std::string_view> entries
{
{".mp3", "audio/mpeg"},
{".ogg", "audio/ogg"},
{".oga", "audio/ogg"},
{".opus", "audio/opus"},
{".aac", "audio/aac"},
{".alac", "audio/mp4"},
{".m4a", "audio/mp4"},
{".m4b", "audio/mp4"},
{".flac", "audio/flac"},
{".webm", "audio/webm"},
{".wav", "audio/x-wav"},
{".wma", "audio/x-ms-wma"},
{".ape", "audio/x-monkeys-audio"},
{".mpc", "audio/x-musepack"},
{".shn", "audio/x-shn"},
{".aif", "audio/x-aiff"},
{".aiff", "audio/x-aiff"},
{".m3u", "audio/x-mpegurl"},
{".pls", "audio/x-scpls"},
{".dsf", "audio/x-dsd"},
{".wv", "audio/x-wavpack"},
{".wvp", "audio/x-wavpack"},
{".mka", "audio/x-matroska"},
static const std::unordered_map<std::string, std::string_view> entries{
{ ".mp3", "audio/mpeg" },
{ ".ogg", "audio/ogg" },
{ ".oga", "audio/ogg" },
{ ".opus", "audio/opus" },
{ ".aac", "audio/aac" },
{ ".alac", "audio/mp4" },
{ ".m4a", "audio/mp4" },
{ ".m4b", "audio/mp4" },
{ ".flac", "audio/flac" },
{ ".webm", "audio/webm" },
{ ".wav", "audio/x-wav" },
{ ".wma", "audio/x-ms-wma" },
{ ".ape", "audio/x-monkeys-audio" },
{ ".mpc", "audio/x-musepack" },
{ ".shn", "audio/x-shn" },
{ ".aif", "audio/x-aiff" },
{ ".aiff", "audio/x-aiff" },
{ ".m3u", "audio/x-mpegurl" },
{ ".pls", "audio/x-scpls" },
{ ".dsf", "audio/x-dsd" },
{ ".wv", "audio/x-wavpack" },
{ ".wvp", "audio/x-wavpack" },
{ ".mka", "audio/x-matroska" },
};
auto it{ entries.find(core::stringUtils::stringToLower(fileExtension.string())) };
+9 -12
View File
@@ -17,8 +17,6 @@
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
/* This file contains some classes in order to get info from file using the libavconv */
#pragma once
#include "av/IAudioFile.hpp"
@@ -35,23 +33,22 @@ namespace lms::av
~AudioFile();
const std::filesystem::path& getPath() const override;
ContainerInfo getContainerInfo() const override;
MetadataMap getMetaData() const override;
std::vector<StreamInfo> getStreamInfo() const override;
std::optional<StreamInfo> getBestStreamInfo() const override;
std::optional<std::size_t> getBestStreamIndex() const override;
bool hasAttachedPictures() const override;
void visitAttachedPictures(std::function<void(const Picture&)> func) const override;
ContainerInfo getContainerInfo() const override;
MetadataMap getMetaData() const override;
std::vector<StreamInfo> getStreamInfo() const override;
std::optional<StreamInfo> getBestStreamInfo() const override;
std::optional<std::size_t> getBestStreamIndex() const override;
bool hasAttachedPictures() const override;
void visitAttachedPictures(std::function<void(const Picture&)> func) const override;
private:
AudioFile(const AudioFile&) = delete;
AudioFile& operator=(const AudioFile&) = delete;
std::optional<StreamInfo> getStreamInfo(std::size_t streamIndex) const;
std::optional<StreamInfo> getStreamInfo(std::size_t streamIndex) const;
const std::filesystem::path _p;
const std::filesystem::path _p;
AVFormatContext* _context{};
};
} // namespace lms::av
@@ -29,4 +29,4 @@ namespace lms::av
std::string_view mimeType{ getMimeType(path.extension()) };
return createFileResourceHandler(path, mimeType.empty() ? "application/octet-stream" : mimeType);
}
}
} // namespace lms::av
+18 -14
View File
@@ -24,27 +24,32 @@
#include "core/IChildProcessManager.hpp"
#include "core/IConfig.hpp"
#include "core/Path.hpp"
#include "core/ILogger.hpp"
#include "core/Path.hpp"
#include "core/Service.hpp"
namespace lms::av::transcoding
{
#define LOG(severity, message) LMS_LOG(TRANSCODING, severity, "[" << _debugId << "] - " << message)
#define LOG(severity, message) LMS_LOG(TRANSCODING, severity, "[" << _debugId << "] - " << message)
static std::atomic<size_t> globalId{};
static std::filesystem::path ffmpegPath;
static std::atomic<size_t> globalId{};
static std::filesystem::path ffmpegPath;
std::string_view formatToMimetype(OutputFormat format)
{
switch (format)
{
case OutputFormat::MP3: return "audio/mpeg";
case OutputFormat::OGG_OPUS: return "audio/opus";
case OutputFormat::MATROSKA_OPUS: return "audio/x-matroska";
case OutputFormat::OGG_VORBIS: return "audio/ogg";
case OutputFormat::WEBM_VORBIS: return "audio/webm";
case OutputFormat::MP3:
return "audio/mpeg";
case OutputFormat::OGG_OPUS:
return "audio/opus";
case OutputFormat::MATROSKA_OPUS:
return "audio/x-matroska";
case OutputFormat::OGG_VORBIS:
return "audio/ogg";
case OutputFormat::WEBM_VORBIS:
return "audio/webm";
}
throw Exception{ "Invalid encoding" };
@@ -195,10 +200,9 @@ namespace lms::av::transcoding
{
assert(_childProcess);
return _childProcess->asyncRead(buffer, bufferSize, [readCallback{ std::move(readCallback) }](core::IChildProcess::ReadResult /*res*/, std::size_t nbBytesRead)
{
readCallback(nbBytesRead);
});
return _childProcess->asyncRead(buffer, bufferSize, [readCallback{ std::move(readCallback) }](core::IChildProcess::ReadResult /*res*/, std::size_t nbBytesRead) {
readCallback(nbBytesRead);
});
}
std::size_t Transcoder::readSome(std::byte* buffer, std::size_t bufferSize)
@@ -215,4 +219,4 @@ namespace lms::av::transcoding
return _childProcess->finished();
}
} // namespace lms::av::Transcoding
} // namespace lms::av::transcoding
+9 -9
View File
@@ -45,24 +45,24 @@ namespace lms::av::transcoding
// non blocking calls
using ReadCallback = std::function<void(std::size_t nbReadBytes)>;
void asyncRead(std::byte* buffer, std::size_t bufferSize, ReadCallback);
std::size_t readSome(std::byte* buffer, std::size_t bufferSize);
void asyncRead(std::byte* buffer, std::size_t bufferSize, ReadCallback);
std::size_t readSome(std::byte* buffer, std::size_t bufferSize);
const std::string& getOutputMimeType() const { return _outputMimeType; }
const OutputParameters& getOutputParameters() const { return _outputParameters; }
bool finished() const;
bool finished() const;
private:
static void init();
void start();
const std::size_t _debugId{};
const InputParameters _inputParameters;
const OutputParameters _outputParameters;
std::string _outputMimeType;
const std::size_t _debugId{};
const InputParameters _inputParameters;
const OutputParameters _outputParameters;
std::string _outputMimeType;
std::unique_ptr<core::IChildProcess> _childProcess;
std::unique_ptr<core::IChildProcess> _childProcess;
};
}
} // namespace lms::av::transcoding
@@ -29,7 +29,7 @@ namespace lms::av::transcoding
const std::size_t estimatedContentLength{ outputParameters.bitrate / 8 * static_cast<std::size_t>(std::chrono::duration_cast<std::chrono::milliseconds>(inputParameters.duration).count()) / 1000 };
return estimatedContentLength;
}
}
} // namespace
std::unique_ptr<IResourceHandler> createResourceHandler(const InputParameters& inputParameters, const OutputParameters& outputParameters, bool estimateContentLength)
{
@@ -68,14 +68,13 @@ namespace lms::av::transcoding
{
Wt::Http::ResponseContinuation* continuation{ response.createContinuation() };
continuation->waitForMoreData();
_transcoder.asyncRead(_buffer.data(), _buffer.size(), [this, continuation](std::size_t nbBytesRead)
{
LMS_LOG(TRANSCODING, DEBUG, "Have " << nbBytesRead << " more bytes to send back");
_transcoder.asyncRead(_buffer.data(), _buffer.size(), [this, continuation](std::size_t nbBytesRead) {
LMS_LOG(TRANSCODING, DEBUG, "Have " << nbBytesRead << " more bytes to send back");
assert(_bytesReadyCount == 0);
_bytesReadyCount = nbBytesRead;
continuation->haveMoreData();
});
assert(_bytesReadyCount == 0);
_bytesReadyCount = nbBytesRead;
continuation->haveMoreData();
});
return continuation;
}
@@ -99,5 +98,4 @@ namespace lms::av::transcoding
return {};
}
}
} // namespace lms::av::transcoding
@@ -25,6 +25,7 @@
#include "av/TranscodingParameters.hpp"
#include "core/IResourceHandler.hpp"
#include "Transcoder.hpp"
namespace lms::av::transcoding
@@ -36,7 +37,7 @@ namespace lms::av::transcoding
private:
Wt::Http::ResponseContinuation* processRequest(const Wt::Http::Request& request, Wt::Http::Response& reponse) override;
void abort() override {};
void abort() override{};
static constexpr std::size_t _chunkSize{ 262'144 };
std::optional<std::size_t> _estimatedContentLength;
@@ -45,5 +46,4 @@ namespace lms::av::transcoding
std::size_t _totalServedByteCount{};
Transcoder _transcoder;
};
}
} // namespace lms::av::transcoding
+22 -25
View File
@@ -17,17 +17,15 @@
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
*/
/* This file contains some classes in order to get info from file using the libavconv */
#pragma once
#include <chrono>
#include <filesystem>
#include <functional>
#include <unordered_map>
#include <optional>
#include <string>
#include <string_view>
#include <unordered_map>
#include <vector>
#include "Types.hpp"
@@ -44,13 +42,13 @@ namespace lms::av
VORBIS,
WMAV1,
WMAV2,
FLAC, // Flac
ALAC, // Apple Lossless Audio Codec (ALAC)
WAVPACK, // WavPack
MUSEPACK7, // Musepack
FLAC, // Flac
ALAC, // Apple Lossless Audio Codec (ALAC)
WAVPACK, // WavPack
MUSEPACK7, // Musepack
MUSEPACK8,
APE, // Monkey's Audio
EAC3, // Enhanced AC-3
EAC3, // Enhanced AC-3
MP4ALS, // MPEG-4 Audio Lossless Coding
OPUS, // Opus
SHORTEN, // Shorten (shn)
@@ -63,9 +61,9 @@ namespace lms::av
struct Picture
{
std::string mimeType;
std::string mimeType;
const std::byte* data{};
std::size_t dataSize{};
std::size_t dataSize{};
};
struct ContainerInfo
@@ -77,13 +75,13 @@ namespace lms::av
struct StreamInfo
{
size_t index{};
std::size_t bitrate{};
std::size_t bitsPerSample{};
std::size_t channelCount{};
std::size_t sampleRate{};
DecodingCodec codec;
std::string codecName;
size_t index{};
std::size_t bitrate{};
std::size_t bitsPerSample{};
std::size_t channelCount{};
std::size_t sampleRate{};
DecodingCodec codec;
std::string codecName;
};
class IAudioFile
@@ -95,13 +93,13 @@ namespace lms::av
using MetadataMap = std::unordered_map<std::string, std::string>;
virtual const std::filesystem::path& getPath() const = 0;
virtual ContainerInfo getContainerInfo() const = 0;
virtual MetadataMap getMetaData() const = 0;
virtual std::vector<StreamInfo> getStreamInfo() const = 0;
virtual std::optional<StreamInfo> getBestStreamInfo() const = 0; // none if failure/unknown
virtual std::optional<std::size_t> getBestStreamIndex() const = 0; // none if failure/unknown
virtual bool hasAttachedPictures() const = 0;
virtual void visitAttachedPictures(std::function<void(const Picture&)> func) const = 0;
virtual ContainerInfo getContainerInfo() const = 0;
virtual MetadataMap getMetaData() const = 0;
virtual std::vector<StreamInfo> getStreamInfo() const = 0;
virtual std::optional<StreamInfo> getBestStreamInfo() const = 0; // none if failure/unknown
virtual std::optional<std::size_t> getBestStreamIndex() const = 0; // none if failure/unknown
virtual bool hasAttachedPictures() const = 0;
virtual void visitAttachedPictures(std::function<void(const Picture&)> func) const = 0;
};
std::unique_ptr<IAudioFile> parseAudioFile(const std::filesystem::path& p);
@@ -115,4 +113,3 @@ namespace lms::av
std::string_view getMimeType(const std::filesystem::path& fileExtension);
} // namespace lms::av
@@ -46,11 +46,10 @@ namespace lms::av::transcoding
struct OutputParameters
{
OutputFormat format;
std::size_t bitrate{ 128000 };
std::optional<std::size_t> stream; // Id of the stream to be transcoded (auto detect by default)
std::chrono::milliseconds offset{ 0 };
bool stripMetadata{ true };
OutputFormat format;
std::size_t bitrate{ 128000 };
std::optional<std::size_t> stream; // Id of the stream to be transcoded (auto detect by default)
std::chrono::milliseconds offset{ 0 };
bool stripMetadata{ true };
};
} // namespace lms::av::Transcoding
} // namespace lms::av::transcoding
@@ -25,8 +25,8 @@
namespace lms::av::transcoding
{
struct InputParameters;
struct OutputParameters;
struct InputParameters;
struct OutputParameters;
std::unique_ptr<IResourceHandler> createResourceHandler(const InputParameters& inputParameters, const OutputParameters& outputParameters, bool estimateContentLength);
}
std::unique_ptr<IResourceHandler> createResourceHandler(const InputParameters& inputParameters, const OutputParameters& outputParameters, bool estimateContentLength);
} // namespace lms::av::transcoding
+1 -1
View File
@@ -28,4 +28,4 @@ namespace lms::av
public:
using LmsException::LmsException;
};
}
} // namespace lms::av