OSDN Git Service

6f5f31b58b3ac743ae4dea8e5c9f30e0c977fe65
[lamexp/LameXP.git] / src / Encoder_Abstract.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2016 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 #pragma once
24
25 //Internal
26 #include "Global.h"
27 #include "Tool_Abstract.h"
28 #include "Model_AudioFile.h"
29
30 //MUtils
31 #include <MUtils/Exception.h>
32
33 class QProcess;
34 class QStringList;
35 class QMutex;
36
37 class AbstractEncoderInfo
38 {
39 public:
40         typedef enum
41         {
42                 TYPE_BITRATE = 0,
43                 TYPE_APPROX_BITRATE = 1,
44                 TYPE_QUALITY_LEVEL_INT = 2,
45                 TYPE_QUALITY_LEVEL_FLT = 3,
46                 TYPE_COMPRESSION_LEVEL = 4,
47                 TYPE_UNCOMPRESSED = 5
48         }
49         value_type_t;
50
51         virtual bool isModeSupported(int mode)   const = 0;     //Returns whether the encoder does support the current RC mode
52         virtual bool isResamplingSupported(void) const = 0;     //Returns whether the encoder has "native" resampling support
53         virtual int valueCount(int mode)         const = 0;     //The number of bitrate/quality values for current RC mode
54         virtual int valueAt(int mode, int index) const = 0;     //The bitrate/quality value at 'index' for the current RC mode
55         virtual int valueType(int mode)          const = 0;     //The display type of the values for the current RC mode
56         virtual const char* description(void)    const = 0;     //Description of the encoder that can be displayed to the user
57         virtual const char* extension(void)      const = 0;     //The default file extension for files created by this encoder
58 };
59
60 class AbstractEncoder : public AbstractTool
61 {
62         Q_OBJECT
63
64 public:
65         AbstractEncoder(void);
66         virtual ~AbstractEncoder(void);
67
68         //Internal encoder API
69         virtual bool encode(const QString &sourceFile, const AudioFileModel_MetaInfo &metaInfo, const unsigned int duration, const unsigned int channels, const QString &outputFile, volatile bool *abortFlag) = 0;
70         virtual bool isFormatSupported(const QString &containerType, const QString &containerProfile, const QString &formatType, const QString &formatProfile, const QString &formatVersion) = 0;
71         virtual const unsigned int *supportedSamplerates(void);
72         virtual const unsigned int *supportedChannelCount(void);
73         virtual const unsigned int *supportedBitdepths(void);
74         virtual const bool needsTimingInfo(void);
75
76         //Common setter methods
77         virtual void setBitrate(const int &bitrate);
78         virtual void setRCMode(const int &mode);
79         virtual void setSamplingRate(const int &value);
80         virtual void setCustomParams(const QString &customParams);
81
82         //Encoder info
83         virtual const AbstractEncoderInfo *toEncoderInfo(void) const = 0;
84         static const AbstractEncoderInfo *getEncoderInfo(void)
85         {
86                 MUTILS_THROW("This method shall be re-implemented in derived classes!");
87                 return NULL;
88         }
89
90 protected:
91         int m_configBitrate;                    //Bitrate *or* VBR-quality-level
92         int m_configRCMode;                             //Rate-control mode
93         int m_configSamplingRate;               //Target sampling rate
94         QString m_configCustomParams;   //Custom parameters, if any
95
96         //Helper functions
97         bool isUnicode(const QString &text);
98         QString cleanTag(const QString &text);
99 };