1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2015 LoRd_MuldeR <MuldeR2@GMX.de>
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2 of the License, or
8 // (at your option) any later version, but always including the *additional*
9 // restrictions defined in the "License.txt" file.
11 // This program is distributed in the hope that it will be useful,
12 // but WITHOUT ANY WARRANTY; without even the implied warranty of
13 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 // GNU General Public License for more details.
16 // You should have received a copy of the GNU General Public License along
17 // with this program; if not, write to the Free Software Foundation, Inc.,
18 // 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
20 // http://www.gnu.org/licenses/gpl-2.0.txt
21 ///////////////////////////////////////////////////////////////////////////////
23 #include "Registry_Decoder.h"
26 #include "Decoder_AAC.h"
27 #include "Decoder_AC3.h"
28 #include "Decoder_ADPCM.h"
29 #include "Decoder_ALAC.h"
30 #include "Decoder_Avisynth.h"
31 #include "Decoder_FLAC.h"
32 #include "Decoder_MAC.h"
33 #include "Decoder_MP3.h"
34 #include "Decoder_Musepack.h"
35 #include "Decoder_Shorten.h"
36 #include "Decoder_Speex.h"
37 #include "Decoder_TTA.h"
38 #include "Decoder_Vorbis.h"
39 #include "Decoder_Wave.h"
40 #include "Decoder_WavPack.h"
41 #include "Decoder_Opus.h"
42 #include "Decoder_WMA.h"
43 #include "PlaylistImporter.h"
44 #include "Model_Settings.h"
47 #include <MUtils/Exception.h>
51 #include <QStringList>
55 #define PROBE_DECODER(DEC) if(DEC::isDecoderAvailable() && DEC::isFormatSupported(containerType, containerProfile, formatType, formatProfile, formatVersion)) { return new DEC(); }
57 #define GET_FILETYPES(LIST, DEC) do \
59 if(DEC::isDecoderAvailable()) (LIST) << DEC::supportedTypes(); \
63 QMutex
DecoderRegistry::m_lock(QMutex::Recursive
);
64 QScopedPointer
<QStringList
> DecoderRegistry::m_supportedExts
;
65 QScopedPointer
<QStringList
> DecoderRegistry::m_supportedTypes
;
66 QScopedPointer
<DecoderRegistry::typeList_t
> DecoderRegistry::m_availableTypes
;
68 ////////////////////////////////////////////////////////////
70 ////////////////////////////////////////////////////////////
72 AbstractDecoder
*DecoderRegistry::lookup(const QString
&containerType
, const QString
&containerProfile
, const QString
&formatType
, const QString
&formatProfile
, const QString
&formatVersion
)
74 PROBE_DECODER(MP3Decoder
);
75 PROBE_DECODER(VorbisDecoder
);
76 PROBE_DECODER(AACDecoder
);
77 PROBE_DECODER(AC3Decoder
);
78 PROBE_DECODER(FLACDecoder
);
79 PROBE_DECODER(WavPackDecoder
);
80 PROBE_DECODER(MusepackDecoder
);
81 PROBE_DECODER(ShortenDecoder
);
82 PROBE_DECODER(MACDecoder
);
83 PROBE_DECODER(TTADecoder
);
84 PROBE_DECODER(SpeexDecoder
);
85 PROBE_DECODER(ALACDecoder
);
86 PROBE_DECODER(WMADecoder
);
87 PROBE_DECODER(ADPCMDecoder
);
88 PROBE_DECODER(WaveDecoder
);
89 PROBE_DECODER(OpusDecoder
);
90 PROBE_DECODER(AvisynthDecoder
);
95 const QStringList
&DecoderRegistry::getSupportedExts(void)
97 QMutexLocker
locker(&m_lock
);
99 if(!m_supportedExts
.isNull())
101 return (*m_supportedExts
);
104 m_supportedExts
.reset(new QStringList());
106 const typeList_t
&types
= getAvailableDecoderTypes();
107 for(QList
<const AbstractDecoder::supportedType_t
*>::ConstIterator iter
= types
.constBegin(); iter
!= types
.constEnd(); iter
++)
109 for(size_t i
= 0; (*iter
)[i
].name
; i
++)
111 for(size_t j
= 0; (*iter
)[i
].exts
[j
]; j
++)
113 const QString ext
= QString().sprintf("*.%s", (*iter
)[i
].exts
[j
]);
114 if(!m_supportedExts
->contains(ext
, Qt::CaseInsensitive
))
116 (*m_supportedExts
) << ext
;
122 const char *const *const playlistPtr
= PlaylistImporter::getSupportedExtensions();
123 for(size_t i
= 0; playlistPtr
[i
]; i
++)
125 const QString ext
= QString().sprintf("*.%s", playlistPtr
[i
]);
126 if(!m_supportedExts
->contains(ext
, Qt::CaseInsensitive
))
128 (*m_supportedExts
) << ext
;
132 m_supportedExts
->sort();
133 return (*m_supportedExts
);
136 const QStringList
&DecoderRegistry::getSupportedTypes(void)
138 QMutexLocker
locker(&m_lock
);
140 if(!m_supportedTypes
.isNull())
142 return (*m_supportedTypes
);
145 m_supportedTypes
.reset(new QStringList());
146 (*m_supportedTypes
) << QString("%1 (%2)").arg(tr("All supported types"), getSupportedExts().join(" "));
148 const typeList_t
&types
= getAvailableDecoderTypes();
149 for(QList
<const AbstractDecoder::supportedType_t
*>::ConstIterator iter
= types
.constBegin(); iter
!= types
.constEnd(); iter
++)
151 for(size_t i
= 0; (*iter
)[i
].name
; i
++)
154 for(size_t j
= 0; (*iter
)[i
].exts
[j
]; j
++)
156 extList
<< QString().sprintf("*.%s", (*iter
)[i
].exts
[j
]);
158 if(!extList
.isEmpty())
160 (*m_supportedTypes
) << QString("%1 (%2)").arg(QString::fromLatin1((*iter
)[i
].name
), extList
.join(" "));
165 const char *const *const playlistPtr
= PlaylistImporter::getSupportedExtensions();
166 QStringList playListExts
;
167 for(size_t i
= 0; playlistPtr
[i
]; i
++)
169 const QString ext
= QString().sprintf("*.%s", playlistPtr
[i
]);
170 if(!playListExts
.contains(ext
, Qt::CaseInsensitive
))
176 (*m_supportedTypes
) << QString("%1 (%2)").arg(tr("Playlists"), playListExts
.join(" "));
177 (*m_supportedTypes
) << QString("%1 (*.*)").arg(tr("All files"));
179 return (*m_supportedTypes
);
182 void DecoderRegistry::configureDecoders(const SettingsModel
*settings
)
184 OpusDecoder::setDisableResampling(settings
->opusDisableResample());
187 ////////////////////////////////////////////////////////////
189 ////////////////////////////////////////////////////////////
191 const DecoderRegistry::typeList_t
&DecoderRegistry::getAvailableDecoderTypes(void)
193 if(!m_availableTypes
.isNull())
195 return (*m_availableTypes
);
198 m_availableTypes
.reset(new typeList_t());
200 GET_FILETYPES(*m_availableTypes
, WaveDecoder
);
201 GET_FILETYPES(*m_availableTypes
, MP3Decoder
);
202 GET_FILETYPES(*m_availableTypes
, VorbisDecoder
);
203 GET_FILETYPES(*m_availableTypes
, AACDecoder
);
204 GET_FILETYPES(*m_availableTypes
, AC3Decoder
);
205 GET_FILETYPES(*m_availableTypes
, FLACDecoder
);
206 GET_FILETYPES(*m_availableTypes
, WavPackDecoder
);
207 GET_FILETYPES(*m_availableTypes
, MusepackDecoder
);
208 GET_FILETYPES(*m_availableTypes
, ShortenDecoder
);
209 GET_FILETYPES(*m_availableTypes
, MACDecoder
);
210 GET_FILETYPES(*m_availableTypes
, TTADecoder
);
211 GET_FILETYPES(*m_availableTypes
, SpeexDecoder
);
212 GET_FILETYPES(*m_availableTypes
, ALACDecoder
);
213 GET_FILETYPES(*m_availableTypes
, WMADecoder
);
214 GET_FILETYPES(*m_availableTypes
, ADPCMDecoder
);
215 GET_FILETYPES(*m_availableTypes
, OpusDecoder
);
216 GET_FILETYPES(*m_availableTypes
, AvisynthDecoder
);
218 return (*m_availableTypes
);