OSDN Git Service

Added project/solution files for VS2019.
[lamexp/LameXP.git] / src / Registry_Decoder.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2019 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
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.
10 //
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.
15 //
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.
19 //
20 // http://www.gnu.org/licenses/gpl-2.0.txt
21 ///////////////////////////////////////////////////////////////////////////////
22
23 #include "Registry_Decoder.h"
24
25 //Internal
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"
45
46 //MUtils
47 #include <MUtils/Exception.h>
48
49 //Qt
50 #include <QString>
51 #include <QStringList>
52 #include <QMutex>
53 #include <QRegExp>
54
55 #define PROBE_DECODER(DEC) if(DEC::isDecoderAvailable() && DEC::isFormatSupported(containerType, containerProfile, formatType, formatProfile, formatVersion)) { return new DEC(); }
56
57 #define GET_FILETYPES(LIST, DEC) do \
58 { \
59         if(DEC::isDecoderAvailable()) (LIST) << DEC::supportedTypes(); \
60 } \
61 while(0)
62
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;
67
68 ////////////////////////////////////////////////////////////
69 // Public Functions
70 ////////////////////////////////////////////////////////////
71
72 AbstractDecoder *DecoderRegistry::lookup(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion)
73 {
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);
91         
92         return NULL;
93 }
94
95 const QStringList &DecoderRegistry::getSupportedExts(void)
96 {
97         QMutexLocker locker(&m_lock);
98
99         if(!m_supportedExts.isNull())
100         {
101                 return (*m_supportedExts);
102         }
103
104         m_supportedExts.reset(new QStringList());
105
106         const typeList_t &types = getAvailableDecoderTypes();
107         for(QList<const AbstractDecoder::supportedType_t*>::ConstIterator iter = types.constBegin(); iter != types.constEnd(); iter++)
108         {
109                 for(size_t i = 0; (*iter)[i].name; i++)
110                 {
111                         for(size_t j = 0; (*iter)[i].exts[j]; j++)
112                         {
113                                 const QString ext = QString().sprintf("*.%s", (*iter)[i].exts[j]);
114                                 if(!m_supportedExts->contains(ext, Qt::CaseInsensitive))
115                                 {
116                                         (*m_supportedExts) << ext;
117                                 }
118                         }
119                 }
120         }
121
122         const char *const *const playlistPtr = PlaylistImporter::getSupportedExtensions();
123         for(size_t i = 0; playlistPtr[i]; i++)
124         {
125                 const QString ext = QString().sprintf("*.%s", playlistPtr[i]);
126                 if(!m_supportedExts->contains(ext, Qt::CaseInsensitive))
127                 {
128                         (*m_supportedExts) << ext;
129                 }
130         }
131
132         m_supportedExts->sort();
133         return (*m_supportedExts);
134 }
135
136 const QStringList &DecoderRegistry::getSupportedTypes(void)
137 {
138         QMutexLocker locker(&m_lock);
139
140         if(!m_supportedTypes.isNull())
141         {
142                 return (*m_supportedTypes);
143         }
144
145         m_supportedTypes.reset(new QStringList());
146         (*m_supportedTypes) << QString("%1 (%2)").arg(tr("All supported types"), getSupportedExts().join(" "));
147
148         const typeList_t &types = getAvailableDecoderTypes();
149         for(QList<const AbstractDecoder::supportedType_t*>::ConstIterator iter = types.constBegin(); iter != types.constEnd(); iter++)
150         {
151                 for(size_t i = 0; (*iter)[i].name; i++)
152                 {
153                         QStringList extList;
154                         for(size_t j = 0; (*iter)[i].exts[j]; j++)
155                         {
156                                 extList << QString().sprintf("*.%s", (*iter)[i].exts[j]);
157                         }
158                         if(!extList.isEmpty())
159                         {
160                                 (*m_supportedTypes) << QString("%1 (%2)").arg(QString::fromLatin1((*iter)[i].name), extList.join(" "));
161                         }
162                 }
163         }
164
165         const char *const *const playlistPtr = PlaylistImporter::getSupportedExtensions();
166         QStringList playListExts;
167         for(size_t i = 0; playlistPtr[i]; i++)
168         {
169                 const QString ext = QString().sprintf("*.%s", playlistPtr[i]);
170                 if(!playListExts.contains(ext, Qt::CaseInsensitive))
171                 {
172                         playListExts << ext;
173                 }
174         }
175
176         (*m_supportedTypes) << QString("%1 (%2)").arg(tr("Playlists"), playListExts.join(" "));
177         (*m_supportedTypes) << QString("%1 (*.*)").arg(tr("All files"));
178
179         return (*m_supportedTypes);
180 }
181
182 void DecoderRegistry::configureDecoders(const SettingsModel *settings)
183 {
184         OpusDecoder::setDisableResampling(settings->opusDisableResample());
185 }
186
187 ////////////////////////////////////////////////////////////
188 // Private Functions
189 ////////////////////////////////////////////////////////////
190
191 const DecoderRegistry::typeList_t &DecoderRegistry::getAvailableDecoderTypes(void)
192 {
193         if(!m_availableTypes.isNull())
194         {
195                 return (*m_availableTypes);
196         }
197
198         m_availableTypes.reset(new typeList_t());
199
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);
217
218         return (*m_availableTypes);
219 }