Bump version.
[LameXP.git] / src / Thread_FileAnalyzer_Task.h
blob92675d075b5bb79e5cff2d0b4307c5f235bfc8ad
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2021 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!
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 #pragma once
25 #include <QRunnable>
26 #include <QReadWriteLock>
27 #include <QWaitCondition>
28 #include <QStringList>
29 #include <QMutex>
30 #include <QSemaphore>
31 #include <QPair>
33 class AudioFileModel;
34 class QFile;
35 class QXmlStreamReader;
36 class QXmlStreamAttributes;
38 ////////////////////////////////////////////////////////////
39 // Splash Thread
40 ////////////////////////////////////////////////////////////
42 class AnalyzeTask: public QObject, public QRunnable
44 Q_OBJECT
46 public:
47 AnalyzeTask(const int taskId, const QString &inputFile, QAtomicInt &abortFlag);
48 ~AnalyzeTask(void);
50 typedef enum
52 fileTypeNormal = 0,
53 fileTypeCDDA = 1,
54 fileTypeDenied = 2,
55 fileTypeCueSheet = 3,
56 fileTypeUnknown = 4
58 fileType_t;
60 typedef enum
62 trackType_non = 0,
63 trackType_gen = 1,
64 trackType_aud = 2
66 MI_trackType_t;
68 typedef enum
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
92 MI_propertyId_t;
94 signals:
95 void fileAnalyzed(const unsigned int taskId, const int fileType, const AudioFileModel &file);
96 void taskCompleted(const unsigned int taskId);
98 protected:
99 void run(void);
100 void run_ex(void);
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);
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);
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;
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;
134 QAtomicInt &m_abortFlag;