Implemented parsing of cover art + code clean-up.
[LameXP.git] / src / Thread_FileAnalyzer_Task.h
blob9b30a63a420126a2e05dbeb0c5268dc8167d73ed
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,
90 propertyId_cover_mime,
91 propertyId_cover_data
93 MI_propertyId_t;
95 signals:
96 void fileAnalyzed(const unsigned int taskId, const int fileType, const AudioFileModel &file);
97 void taskCompleted(const unsigned int taskId);
99 protected:
100 void run(void);
101 void run_ex(void);
103 private:
104 const AudioFileModel& analyzeFile(const QString &filePath, AudioFileModel &audioFile, int *const type);
105 const AudioFileModel& analyzeMediaFile(const QString &filePath, AudioFileModel &audioFile);
106 const AudioFileModel& parseMediaInfo(const QByteArray &data, AudioFileModel &audioFile);
107 void parseFileInfo(QXmlStreamReader &xmlStream, AudioFileModel &audioFile);
108 void parseTrackInfo(QXmlStreamReader &xmlStream, const MI_trackType_t trackType, AudioFileModel &audioFile);
109 void parseProperty(const QString &value, const MI_propertyId_t propertyIdx, AudioFileModel &audioFile, QString &coverMimeType);
110 void retrieveCover(AudioFileModel &audioFile, const QString &coverType, const QString &coverData);
111 bool checkFile_CDDA(QFile &file);
112 bool analyzeAvisynthFile(const QString &filePath, AudioFileModel &info);
114 static const QMap<QPair<MI_trackType_t, QString>, MI_propertyId_t> &initMediaInfoIdx(void);
115 static const QMap<QString, MI_propertyId_t> &initAvisynthIdx(void);
116 static const QMap<QString, QString> &initMimeTypes(void);
117 static const QMap<QString, MI_trackType_t> &initTrackTypes(void);
119 static QString decodeStr(const QString &str, const QString &encoding);
120 static bool parseUnsigned(const QString &str, quint32 &value);
121 static bool parseDuration(const QString &str, quint32 &value);
122 static bool parseYear(const QString &st, quint32 &valuer);
123 static bool parseRCMode(const QString &str, quint32 &value);
124 static QString cleanAsciiStr(const QString &str);
125 static bool findNextElement(const QString &name, QXmlStreamReader &xmlStream);
126 static QString findAttribute(const QString &name, const QXmlStreamAttributes &xmlAttributes);
128 const QMap<QPair<MI_trackType_t, QString>, MI_propertyId_t> &m_mediaInfoIdx;
129 const QMap<QString, MI_propertyId_t> &m_avisynthIdx;
130 const QMap<QString, QString> &m_mimeTypes;
131 const QMap<QString, MI_trackType_t> &m_trackTypes;
133 const unsigned int m_taskId;
134 const QString m_mediaInfoBin;
135 const quint32 m_mediaInfoVer;
136 const QString m_avs2wavBin;
137 const QString m_inputFile;
139 QAtomicInt &m_abortFlag;
141 static QReadWriteLock s_lock;
142 static QScopedPointer<const QMap<QPair<MI_trackType_t, QString>, MI_propertyId_t>> s_pMediaInfoIdx;
143 static QScopedPointer<const QMap<QString, MI_propertyId_t>> s_pAvisynthIdx;
144 static QScopedPointer<const QMap<QString, QString>> s_pMimeTypes;
145 static QScopedPointer<const QMap<QString, MI_trackType_t>> s_pTrackTypes;