1
0
mirror of https://github.com/clementine-player/Clementine synced 2024-12-22 15:58:45 +01:00

transcoder: Add an enum for known codecs

Add CodecType to enumerate codecs available for settings and a MimeType
to provide the mime string.
This commit is contained in:
Jim Broadus 2021-02-04 23:31:24 -08:00 committed by John Maguire
parent 8f3772b593
commit 79d81283a8
2 changed files with 48 additions and 14 deletions

View File

@ -248,33 +248,55 @@ QList<TranscoderPreset> Transcoder::GetAllPresets() {
return ret;
}
QString Transcoder::MimeType(CodecType type) {
switch (type) {
case Codec_None:
return QString();
case Codec_Flac:
return "audio/x-flac";
case Codec_Mp4:
return "audio/mpeg, mpegversion=(int)4";
case Codec_Mp3:
return "audio/mpeg, mpegversion=(int)1, layer=(int)3";
case Codec_Vorbis:
return "audio/x-vorbis";
case Codec_Speex:
return "audio/x-speex";
case Codec_Opus:
return "audio/x-opus";
case Codec_Wma:
return "audio/x-wma";
}
return "unknown";
}
TranscoderPreset Transcoder::PresetForFileType(Song::FileType type) {
switch (type) {
case Song::Type_Flac:
return TranscoderPreset(type, tr("FLAC"), "flac", "audio/x-flac");
return TranscoderPreset(type, tr("FLAC"), "flac", MimeType(Codec_Flac));
case Song::Type_Mp4:
return TranscoderPreset(type, tr("M4A AAC"), "mp4",
"audio/mpeg, mpegversion=(int)4", "audio/mp4");
return TranscoderPreset(type, tr("M4A AAC"), "mp4", MimeType(Codec_Mp4),
"audio/mp4");
case Song::Type_Mpeg:
return TranscoderPreset(type, tr("MP3"), "mp3",
"audio/mpeg, mpegversion=(int)1, layer=(int)3");
return TranscoderPreset(type, tr("MP3"), "mp3", MimeType(Codec_Mp3));
case Song::Type_OggVorbis:
return TranscoderPreset(type, tr("Ogg Vorbis"), "ogg", "audio/x-vorbis",
"application/ogg");
return TranscoderPreset(type, tr("Ogg Vorbis"), "ogg",
MimeType(Codec_Vorbis), "application/ogg");
case Song::Type_OggFlac:
return TranscoderPreset(type, tr("Ogg Flac"), "ogg", "audio/x-flac",
return TranscoderPreset(type, tr("Ogg Flac"), "ogg", MimeType(Codec_Flac),
"application/ogg");
case Song::Type_OggSpeex:
return TranscoderPreset(type, tr("Ogg Speex"), "spx", "audio/x-speex",
"application/ogg");
return TranscoderPreset(type, tr("Ogg Speex"), "spx",
MimeType(Codec_Speex), "application/ogg");
case Song::Type_OggOpus:
return TranscoderPreset(type, tr("Ogg Opus"), "opus", "audio/x-opus",
"application/ogg");
return TranscoderPreset(type, tr("Ogg Opus"), "opus",
MimeType(Codec_Opus), "application/ogg");
case Song::Type_Asf:
return TranscoderPreset(type, tr("Windows Media audio"), "wma",
"audio/x-wma", "video/x-ms-asf");
MimeType(Codec_Wma), "video/x-ms-asf");
case Song::Type_Wav:
return TranscoderPreset(type, tr("Wav"), "wav", QString(), "audio/x-wav");
return TranscoderPreset(type, tr("Wav"), "wav", MimeType(Codec_None),
"audio/x-wav");
default:
qLog(Warning) << "Unsupported format in PresetForFileType:" << type;
return TranscoderPreset();

View File

@ -49,10 +49,22 @@ class Transcoder : public QObject {
Q_OBJECT
public:
enum CodecType {
Codec_None = 0,
Codec_Flac = 1,
Codec_Mp4 = 2,
Codec_Mp3 = 3,
Codec_Vorbis = 4,
Codec_Speex = 5,
Codec_Opus = 6,
Codec_Wma = 7
};
Transcoder(QObject* parent = nullptr, const QString& settings_postfix = "");
static TranscoderPreset PresetForFileType(Song::FileType type);
static QList<TranscoderPreset> GetAllPresets();
static QString MimeType(CodecType type);
static Song::FileType PickBestFormat(QList<Song::FileType> supported);
int max_threads() const { return max_threads_; }