Minor cleanup on audio codecs
This commit is contained in:
@@ -0,0 +1,68 @@
|
||||
/*
|
||||
* Copyright (C) 2025 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 "core/media/Codec.hpp"
|
||||
#include "core/Exception.hpp"
|
||||
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
|
||||
namespace lms::core::media
|
||||
{
|
||||
namespace
|
||||
{
|
||||
constexpr std::array codecDescs{
|
||||
CodecDesc{ Codec::AAC, "AAC", "Advanced Audio Coding", false },
|
||||
CodecDesc{ Codec::AC3, "AC3", "Dolby AC-3", false },
|
||||
CodecDesc{ Codec::ALAC, "ALAC", "Apple Lossless Audio Codec", true },
|
||||
CodecDesc{ Codec::APE, "APE", "Monkey's Audio", true },
|
||||
CodecDesc{ Codec::DSD, "DSD", "Direct Stream Digital", true },
|
||||
CodecDesc{ Codec::EAC3, "E-AC3", "Dolby Digital Plus", false },
|
||||
CodecDesc{ Codec::FLAC, "FLAC", "Free Lossless Audio Codec", true },
|
||||
CodecDesc{ Codec::MP3, "MP3", "MPEG-3", false },
|
||||
CodecDesc{ Codec::MP4ALS, "MP4ALS", "MPEG-4 Audio Lossless Coding", true },
|
||||
CodecDesc{ Codec::MPC7, "MPC7", "Musepack7", false },
|
||||
CodecDesc{ Codec::MPC8, "MPC8", "Musepack8", false },
|
||||
CodecDesc{ Codec::Opus, "Opus", "Opus", false },
|
||||
CodecDesc{ Codec::PCM, "PCM", "Pulse-code modulation", false },
|
||||
CodecDesc{ Codec::Shorten, "Shorten", "Shorten", true },
|
||||
CodecDesc{ Codec::TrueAudio, "TTA", "The True Audio", true },
|
||||
CodecDesc{ Codec::Vorbis, "Vorbis", "Vorbis", false },
|
||||
CodecDesc{ Codec::WavPack, "WavPack", "WavPack", true },
|
||||
CodecDesc{ Codec::WMA1, "WMA1", "Windows Media Audio", false },
|
||||
CodecDesc{ Codec::WMA2, "WMA2", "Windows Media Audio 2", false },
|
||||
CodecDesc{ Codec::WMA9Pro, "WMA9Pro", "Windows Media Audio Professional", false },
|
||||
CodecDesc{ Codec::WMA9Lossless, "WMA9Lossless", "Windows Media Audio Lossless", true },
|
||||
};
|
||||
} // namespace
|
||||
|
||||
void visitCodecs(const std::function<void(const CodecDesc&)>& visitor)
|
||||
{
|
||||
std::for_each(std::cbegin(codecDescs), std::cend(codecDescs), visitor);
|
||||
}
|
||||
|
||||
const CodecDesc& getCodecDesc(Codec type)
|
||||
{
|
||||
const auto it{ std::find_if(codecDescs.begin(), codecDescs.end(), [type](const auto& desc) { return desc.type == type; }) };
|
||||
if (it == codecDescs.end()) [[unlikely]]
|
||||
throw LmsException{ "Unknown codec type" };
|
||||
|
||||
return *it;
|
||||
}
|
||||
} // namespace lms::core::media
|
||||
@@ -1,108 +0,0 @@
|
||||
/*
|
||||
* Copyright (C) 2025 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 "core/media/CodecType.hpp"
|
||||
|
||||
namespace lms::core::media
|
||||
{
|
||||
core::LiteralString codecTypeToString(CodecType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case CodecType::AAC:
|
||||
return "AAC";
|
||||
case CodecType::AC3:
|
||||
return "AC3";
|
||||
case CodecType::ALAC:
|
||||
return "ALAC";
|
||||
case CodecType::APE:
|
||||
return "APE";
|
||||
case CodecType::DSD:
|
||||
return "DSD";
|
||||
case CodecType::EAC3:
|
||||
return "E-AC3";
|
||||
case CodecType::FLAC:
|
||||
return "FLAC";
|
||||
case CodecType::MP3:
|
||||
return "MP3";
|
||||
case CodecType::MP4ALS:
|
||||
return "MP4ALS";
|
||||
case CodecType::MPC7:
|
||||
return "MPC7";
|
||||
case CodecType::MPC8:
|
||||
return "MPC8";
|
||||
case CodecType::Opus:
|
||||
return "Opus";
|
||||
case CodecType::PCM:
|
||||
return "PCM";
|
||||
case CodecType::Shorten:
|
||||
return "Shorten";
|
||||
case CodecType::TrueAudio:
|
||||
return "TrueAudio";
|
||||
case CodecType::Vorbis:
|
||||
return "Vorbis";
|
||||
case CodecType::WavPack:
|
||||
return "WavPack";
|
||||
case CodecType::WMA1:
|
||||
return "WMA1";
|
||||
case CodecType::WMA2:
|
||||
return "WMA2";
|
||||
case CodecType::WMA9Pro:
|
||||
return "WMA9Pro";
|
||||
case CodecType::WMA9Lossless:
|
||||
return "WMA9Lossless";
|
||||
}
|
||||
|
||||
return "Unknown";
|
||||
}
|
||||
|
||||
bool isCodecLossless(CodecType type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case CodecType::ALAC:
|
||||
case CodecType::APE:
|
||||
case CodecType::DSD:
|
||||
|
||||
case CodecType::FLAC:
|
||||
case CodecType::MP4ALS:
|
||||
case CodecType::PCM:
|
||||
case CodecType::Shorten:
|
||||
case CodecType::TrueAudio:
|
||||
case CodecType::WavPack:
|
||||
case CodecType::WMA9Lossless:
|
||||
return true;
|
||||
|
||||
case CodecType::AAC:
|
||||
case CodecType::AC3:
|
||||
case CodecType::EAC3:
|
||||
case CodecType::MP3:
|
||||
case CodecType::MPC7:
|
||||
case CodecType::MPC8:
|
||||
case CodecType::Opus:
|
||||
case CodecType::Vorbis:
|
||||
case CodecType::WMA1:
|
||||
case CodecType::WMA2:
|
||||
case CodecType::WMA9Pro:
|
||||
return false;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
} // namespace lms::core::media
|
||||
+15
-15
@@ -17,39 +17,39 @@
|
||||
* along with LMS. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "core/media/ContainerType.hpp"
|
||||
#include "core/media/Container.hpp"
|
||||
|
||||
namespace lms::core::media
|
||||
{
|
||||
core::LiteralString containerTypeToString(ContainerType type)
|
||||
core::LiteralString containerToString(Container type)
|
||||
{
|
||||
switch (type)
|
||||
{
|
||||
case ContainerType::AIFF:
|
||||
case Container::AIFF:
|
||||
return "AIFF";
|
||||
case ContainerType::APE:
|
||||
case Container::APE:
|
||||
return "APE";
|
||||
case ContainerType::ASF:
|
||||
case Container::ASF:
|
||||
return "ASF";
|
||||
case ContainerType::DSF:
|
||||
case Container::DSF:
|
||||
return "DSF";
|
||||
case ContainerType::FLAC:
|
||||
case Container::FLAC:
|
||||
return "FLAC";
|
||||
case ContainerType::MP4:
|
||||
case Container::MP4:
|
||||
return "MP4";
|
||||
case ContainerType::MPC:
|
||||
case Container::MPC:
|
||||
return "MPC";
|
||||
case ContainerType::MPEG:
|
||||
case Container::MPEG:
|
||||
return "MPEG";
|
||||
case ContainerType::Ogg:
|
||||
case Container::Ogg:
|
||||
return "Ogg";
|
||||
case ContainerType::Shorten:
|
||||
case Container::Shorten:
|
||||
return "Shorten";
|
||||
case ContainerType::TrueAudio:
|
||||
case Container::TrueAudio:
|
||||
return "TrueAudio";
|
||||
case ContainerType::WAV:
|
||||
case Container::WAV:
|
||||
return "WAV";
|
||||
case ContainerType::WavPack:
|
||||
case Container::WavPack:
|
||||
return "WavPack";
|
||||
}
|
||||
|
||||
@@ -21,57 +21,57 @@
|
||||
|
||||
namespace lms::core::media
|
||||
{
|
||||
core::LiteralString getMimeType(ContainerType container, CodecType codec)
|
||||
core::LiteralString getMimeType(Container container, Codec codec)
|
||||
{
|
||||
switch (container)
|
||||
{
|
||||
case ContainerType::AIFF:
|
||||
case Container::AIFF:
|
||||
return "audio/x-aiff";
|
||||
case ContainerType::APE:
|
||||
case Container::APE:
|
||||
return "audio/x-monkeys-audio";
|
||||
case ContainerType::ASF:
|
||||
case Container::ASF:
|
||||
return "audio/x-ms-wma";
|
||||
case ContainerType::DSF:
|
||||
case Container::DSF:
|
||||
return "audio/x-dsd-dsf";
|
||||
case ContainerType::FLAC:
|
||||
case Container::FLAC:
|
||||
return "audio/flac";
|
||||
case ContainerType::MP4:
|
||||
case Container::MP4:
|
||||
switch (codec)
|
||||
{
|
||||
case CodecType::AAC:
|
||||
case Codec::AAC:
|
||||
return "audio/mp4; codecs=\"mp4a.40.2\"";
|
||||
case CodecType::ALAC:
|
||||
case Codec::ALAC:
|
||||
return "audio/mp4; codecs=\"alac\"";
|
||||
case CodecType::MP4ALS:
|
||||
case Codec::MP4ALS:
|
||||
return "audio/mp4; codecs=\"mp4als\"";
|
||||
default:
|
||||
return "audio/mp4";
|
||||
}
|
||||
|
||||
case ContainerType::MPC:
|
||||
case Container::MPC:
|
||||
return "audio/x-musepack";
|
||||
case ContainerType::MPEG:
|
||||
case Container::MPEG:
|
||||
return "audio/mpeg";
|
||||
case ContainerType::Ogg:
|
||||
case Container::Ogg:
|
||||
switch (codec)
|
||||
{
|
||||
case CodecType::Opus:
|
||||
case Codec::Opus:
|
||||
return "audio/opus";
|
||||
case CodecType::Vorbis:
|
||||
case Codec::Vorbis:
|
||||
return "audio/ogg; codecs=\"vorbis\"";
|
||||
case CodecType::FLAC:
|
||||
case Codec::FLAC:
|
||||
return "audio/ogg; codecs=\"flac\"";
|
||||
default:
|
||||
return "audio/ogg";
|
||||
}
|
||||
|
||||
case ContainerType::Shorten:
|
||||
case Container::Shorten:
|
||||
return "audio/x-shn";
|
||||
case ContainerType::TrueAudio:
|
||||
case Container::TrueAudio:
|
||||
return "audio/x-tta";
|
||||
case ContainerType::WAV:
|
||||
case Container::WAV:
|
||||
return "audio/wav";
|
||||
case ContainerType::WavPack:
|
||||
case Container::WavPack:
|
||||
return "audio/x-wavpack";
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user