OSDN Git Service

Updated changelog.
[lamexp/LameXP.git] / src / Thread_FileAnalyzer_Task.h
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2023 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; always including the non-optional
9 // LAMEXP GNU GENERAL PUBLIC LICENSE ADDENDUM. See "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 #include <QRunnable>
26 #include <QReadWriteLock>
27 #include <QWaitCondition>
28 #include <QStringList>
29 #include <QMutex>
30 #include <QSemaphore>
31 #include <QPair>
32
33 class AudioFileModel;
34 class QFile;
35 class QXmlStreamReader;
36 class QXmlStreamAttributes;
37
38 ////////////////////////////////////////////////////////////
39 // Splash Thread
40 ////////////////////////////////////////////////////////////
41
42 class AnalyzeTask: public QObject, public QRunnable
43 {
44         Q_OBJECT
45
46 public:
47         AnalyzeTask(const int taskId, const QString &inputFile, QAtomicInt &abortFlag);
48         ~AnalyzeTask(void);
49         
50         typedef enum
51         {
52                 fileTypeNormal   = 0,
53                 fileTypeCDDA     = 1,
54                 fileTypeDenied   = 2,
55                 fileTypeCueSheet = 3,
56                 fileTypeUnknown  = 4
57         }
58         fileType_t;
59
60         typedef enum
61         {
62                 trackType_non = 0,
63                 trackType_gen = 1,
64                 trackType_aud = 2
65         }
66         MI_trackType_t;
67
68         typedef enum
69         {
70                 propertyId_container,
71                 propertyId_container_profile,
72                 propertyId_duration,
73                 propertyId_title,
74                 propertyId_artist,
75                 propertyId_album,
76                 propertyId_genre,
77                 propertyId_released_date,
78                 propertyId_track_position,
79                 propertyId_comment,
80                 propertyId_format,
81                 propertyId_format_version,
82                 propertyId_format_profile,
83                 propertyId_channel_s_,
84                 propertyId_samplingrate,
85                 propertyId_bitdepth,
86                 propertyId_bitrate,
87                 propertyId_bitrate_mode,
88                 propertyId_encoded_library,
89                 propertyId_cover_mime,
90                 propertyId_cover_data
91         }
92         MI_propertyId_t;
93
94 signals:
95         void fileAnalyzed(const unsigned int taskId, const int fileType, const AudioFileModel &file);
96         void taskCompleted(const unsigned int taskId);
97
98 protected:
99         void run(void);
100         void run_ex(void);
101
102 private:
103         const AudioFileModel& analyzeFile(const QString &filePath, AudioFileModel &audioFile, int *const type);
104         const AudioFileModel& analyzeMediaFile(const QString &filePath, AudioFileModel &audioFile);
105         const AudioFileModel& parseMediaInfo(const QByteArray &data, AudioFileModel &audioFile);
106         void parseFileInfo(QXmlStreamReader &xmlStream, AudioFileModel &audioFile);
107         void parseTrackInfo(QXmlStreamReader &xmlStream, const MI_trackType_t trackType, AudioFileModel &audioFile);
108         void parseProperty(const QString &value, const MI_propertyId_t propertyIdx, AudioFileModel &audioFile, QString &coverMimeType);
109         void retrieveCover(AudioFileModel &audioFile, const QString &coverType, const QString &coverData);
110         bool checkFile_CDDA(QFile &file);
111         bool analyzeAvisynthFile(const QString &filePath, AudioFileModel &info);
112
113         static QString decodeStr(const QString &str, const QString &encoding);
114         static bool parseUnsigned(const QString &str, quint32 &value);
115         static bool parseFloat(const QString &str, double &value);
116         static bool parseYear(const QString &st, quint32 &valuer);
117         static bool parseRCMode(const QString &str, quint32 &value);
118         static QString cleanAsciiStr(const QString &str);
119         static bool findNextElement(const QString &name, QXmlStreamReader &xmlStream);
120         static QString findAttribute(const QString &name, const QXmlStreamAttributes &xmlAttributes);
121         static bool checkVersionStr(const QString &str, const quint32 expectedMajor, const quint32 expectedMinor);
122
123         const QMap<QPair<MI_trackType_t, QString>, MI_propertyId_t> &m_mediaInfoIdx;
124         const QMap<QString, MI_propertyId_t> &m_avisynthIdx;
125         const QMap<QString, QString> &m_mimeTypes;
126         const QMap<QString, MI_trackType_t> &m_trackTypes;
127
128         const unsigned int m_taskId;
129         const QString m_mediaInfoBin;
130         const quint32 m_mediaInfoVer;
131         const QString m_avs2wavBin;
132         const QString m_inputFile;
133
134         QAtomicInt &m_abortFlag;
135 };