Switch to using QXmlStreamReader instead of SAX parser (part #2).
[LameXP.git] / src / Thread_FileAnalyzer_Task.h
blobf0f4263b9d31b5ee157675034235d8100566c635
1 ///////////////////////////////////////////////////////////////////////////////
2 // LameXP - Audio Encoder Front-End
3 // Copyright (C) 2004-2017 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.
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 protected:
61 typedef enum
63 trackType_non = 0,
64 trackType_gen = 1,
65 trackType_aud = 2
67 MI_trackType_t;
69 typedef enum
71 propertyId_container,
72 propertyId_container_profile,
73 propertyId_duration,
74 propertyId_title,
75 propertyId_artist,
76 propertyId_album,
77 propertyId_genre,
78 propertyId_released_date,
79 propertyId_track_position,
80 propertyId_comment,
81 propertyId_format,
82 propertyId_format_version,
83 propertyId_format_profile,
84 propertyId_channel_s_,
85 propertyId_samplingrate,
86 propertyId_bitdepth,
87 propertyId_bitrate,
88 propertyId_bitrate_mode,
89 propertyId_encoded_library
91 MI_propertyId_t;
93 signals:
94 void fileAnalyzed(const unsigned int taskId, const int fileType, const AudioFileModel &file);
95 void taskCompleted(const unsigned int taskId);
97 protected:
98 void run(void);
99 void run_ex(void);
101 private:
102 const AudioFileModel& analyzeFile(const QString &filePath, AudioFileModel &audioFile, int *const type);
103 const AudioFileModel& analyzeMediaFile(const QString &filePath, AudioFileModel &audioFile);
104 const AudioFileModel& parseMediaInfo(const QByteArray &data, AudioFileModel &audioFile);
105 void parseFileInfo(QXmlStreamReader &xmlStream, AudioFileModel &audioFile);
106 void parseTrackInfo(QXmlStreamReader &xmlStream, const MI_trackType_t trackType, AudioFileModel &audioFile);
107 void parseProperty(const QString &value, const MI_propertyId_t propertyIdx, AudioFileModel &audioFile);
108 bool checkFile_CDDA(QFile &file);
109 bool analyzeAvisynthFile(const QString &filePath, AudioFileModel &info);
111 static const QMap<QPair<AnalyzeTask::MI_trackType_t, QString>, MI_propertyId_t> &initPropertiesIdx(void);
112 static const QMap<QString, MI_trackType_t> &initTrackTypes(void);
113 static QString decodeStr(const QString &str, const QString &encoding);
114 static bool parseUnsigned(const QString &str, quint32 &value);
115 static bool parseDuration(const QString &str, quint32 &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);
122 const unsigned int m_taskId;
123 const QString m_mediaInfoBin;
124 const quint32 m_mediaInfoVer;
125 const QString m_avs2wavBin;
126 const QString m_inputFile;
127 const QMap<QPair<MI_trackType_t, QString>, MI_propertyId_t> &m_propertiesIdx;
128 const QMap<QString, MI_trackType_t> &m_trackTypes;
130 QAtomicInt &m_abortFlag;
132 static QReadWriteLock s_lock;
133 static QScopedPointer<const QMap<QPair<MI_trackType_t, QString>, MI_propertyId_t>> s_pPropertiesIdx;
134 static QScopedPointer<const QMap<QString, MI_trackType_t>> s_pTrackTypes;