OSDN Git Service

Fixed detection of AAC streams with latest MediaInfo version. AAC profile is now...
[lamexp/LameXP.git] / src / Encoder_Abstract.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2018 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 "Encoder_Abstract.h"
24
25 //Internal
26 #include "Global.h"
27
28 //MUtils
29 #include <MUtils/Global.h>
30
31 AbstractEncoder::AbstractEncoder(void)
32 {
33         m_configBitrate = 0;
34         m_configRCMode = 0;
35         m_configCustomParams.clear();
36         m_configSamplingRate = 0;
37 }
38
39 AbstractEncoder::~AbstractEncoder(void)
40 {
41 }
42
43
44 /*
45  * Setters
46  */
47
48 void AbstractEncoder::setRCMode(const int &mode)
49 {
50         if (!toEncoderInfo()->isModeSupported(qMax(0, mode)))
51         {
52                 MUTILS_THROW("This RC mode is not supported by the encoder!");
53         }
54         m_configRCMode = qMax(0, mode);
55         m_configBitrate = qBound(0, m_configBitrate, toEncoderInfo()->valueCount(m_configRCMode) - 1);
56 }
57
58 void AbstractEncoder::setBitrate(const int &bitrate)
59 {
60         const int valueCount = toEncoderInfo()->valueCount(m_configRCMode);
61         if ((valueCount > 0) && (qMax(0, bitrate) >= valueCount))
62         {
63                 MUTILS_THROW("The specified bitrate/quality is out of range!");
64         }
65         m_configBitrate = qMax(0, bitrate);
66 }
67
68 void AbstractEncoder::setCustomParams(const QString &customParams)
69 {
70         m_configCustomParams = customParams.trimmed();
71 }
72
73 void AbstractEncoder::setSamplingRate(const int &value)
74 {
75         if (!toEncoderInfo()->isResamplingSupported())
76         {
77                 MUTILS_THROW("This encoder does *not* support native resampling!");
78         }
79         m_configSamplingRate = qBound(0, value, 48000);
80 };
81
82
83 /*
84  * Default implementation
85  */
86
87 // Does encoder require the input to be downmixed to stereo?
88 const unsigned int *AbstractEncoder::supportedChannelCount(void)
89 {
90         return NULL;
91 }
92
93 // Does encoder require the input to be downsampled? (NULL-terminated array of supported sampling rates)
94 const unsigned int *AbstractEncoder::supportedSamplerates(void)
95 {
96         return NULL;
97 }
98
99 // What bitdepths does the encoder support as input? (NULL-terminated array of supported bits per sample)
100 const unsigned int *AbstractEncoder::supportedBitdepths(void)
101 {
102         return NULL;
103 }
104
105 //Does the encoder need the exact duration of the source?
106 const bool AbstractEncoder::needsTimingInfo(void)
107 {
108         return false;
109 }
110
111
112 /*
113  * Helper functions
114  */
115
116 //Does this text contain Non-ASCII characters?
117 bool AbstractEncoder::isUnicode(const QString &original)
118 {
119         if(!original.isEmpty())
120         {
121                 QString asLatin1 = QString::fromLatin1(original.toLatin1().constData());
122                 return (wcscmp(MUTILS_WCHR(original), MUTILS_WCHR(asLatin1)) != 0);
123         }
124         return false;
125 }
126
127 //Remove "problematic" characters from tag
128 QString AbstractEncoder::cleanTag(const QString &text)
129 {
130         QString result(text);
131         result.replace(QChar('"'), "'");
132         result.replace(QChar('\\'), "/");
133         return result;
134 }