Some code refactoring.

This commit is contained in:
LoRd_MuldeR 2017-10-30 23:01:56 +01:00
parent 6c82e017ec
commit 87bc566b26
3 changed files with 23 additions and 20 deletions

View File

@ -35,7 +35,7 @@
#define VER_LAMEXP_MINOR_LO 6 #define VER_LAMEXP_MINOR_LO 6
#define VER_LAMEXP_TYPE Alpha #define VER_LAMEXP_TYPE Alpha
#define VER_LAMEXP_PATCH 7 #define VER_LAMEXP_PATCH 7
#define VER_LAMEXP_BUILD 2036 #define VER_LAMEXP_BUILD 2037
#define VER_LAMEXP_CONFG 2002 #define VER_LAMEXP_CONFG 2002
/////////////////////////////////////////////////////////////////////////////// ///////////////////////////////////////////////////////////////////////////////

View File

@ -66,8 +66,8 @@
class AnalyzeTask_XmlHandler : public QXmlDefaultHandler class AnalyzeTask_XmlHandler : public QXmlDefaultHandler
{ {
public: public:
AnalyzeTask_XmlHandler(AudioFileModel &audioFile) : AnalyzeTask_XmlHandler(AudioFileModel &audioFile, const quint32 &version) :
m_audioFile(audioFile), m_trackType(trackType_non), m_trackIdx(0), m_properties(initializeProperties()) {} m_audioFile(audioFile), m_version(version), m_trackType(trackType_non), m_trackIdx(0), m_properties(initializeProperties()) {}
protected: protected:
virtual bool startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &atts); virtual bool startElement(const QString &namespaceURI, const QString &localName, const QString &qName, const QXmlAttributes &atts);
@ -96,18 +96,19 @@ private:
} }
propertyId_t; propertyId_t;
const quint32 m_version;
const QMap<QPair<trackType_t, QString>, propertyId_t> &m_properties; const QMap<QPair<trackType_t, QString>, propertyId_t> &m_properties;
QStack<QString> m_stack; QStack<QString> m_stack;
AudioFileModel &m_audioFile; AudioFileModel &m_audioFile;
trackType_t m_trackType; trackType_t m_trackType;
quint32 m_trackIdx; quint32 m_trackIdx;
QPair<trackType_t, QString> m_currentProperty; propertyId_t m_currentProperty;
static QReadWriteLock s_propertiesMutex; static QReadWriteLock s_propertiesMutex;
static QScopedPointer<const QMap<QPair<trackType_t, QString>, propertyId_t>> s_propertiesMap; static QScopedPointer<const QMap<QPair<trackType_t, QString>, propertyId_t>> s_propertiesMap;
bool updatePropertry(const QPair<trackType_t, QString> &id, const QString &value); bool updatePropertry(const propertyId_t &idx, const QString &value);
static const QMap<QPair<trackType_t, QString>, propertyId_t> &initializeProperties(); static const QMap<QPair<trackType_t, QString>, propertyId_t> &initializeProperties();
static bool parseUnsigned(const QString &str, quint32 &value); static bool parseUnsigned(const QString &str, quint32 &value);
@ -123,6 +124,7 @@ AnalyzeTask::AnalyzeTask(const int taskId, const QString &inputFile, QAtomicInt
m_taskId(taskId), m_taskId(taskId),
m_inputFile(inputFile), m_inputFile(inputFile),
m_mediaInfoBin(lamexp_tools_lookup("mediainfo.exe")), m_mediaInfoBin(lamexp_tools_lookup("mediainfo.exe")),
m_mediaInfoVer(lamexp_tools_version("mediainfo.exe")),
m_avs2wavBin(lamexp_tools_lookup("avs2wav.exe")), m_avs2wavBin(lamexp_tools_lookup("avs2wav.exe")),
m_abortFlag(abortFlag) m_abortFlag(abortFlag)
{ {
@ -357,7 +359,7 @@ const AudioFileModel& AnalyzeTask::parseMediaInfo(const QByteArray &data, AudioF
QXmlInputSource xmlSource; QXmlInputSource xmlSource;
xmlSource.setData(data); xmlSource.setData(data);
QScopedPointer<QXmlDefaultHandler> xmlHandler(new AnalyzeTask_XmlHandler(audioFile)); QScopedPointer<QXmlDefaultHandler> xmlHandler(new AnalyzeTask_XmlHandler(audioFile, m_mediaInfoVer));
QXmlSimpleReader xmlReader; QXmlSimpleReader xmlReader;
xmlReader.setContentHandler(xmlHandler.data()); xmlReader.setContentHandler(xmlHandler.data());
@ -604,7 +606,6 @@ const QMap<QPair<AnalyzeTask_XmlHandler::trackType_t, QString>, AnalyzeTask_XmlH
if (s_propertiesMap.isNull()) if (s_propertiesMap.isNull())
{ {
qWarning("!!! --- SETTING UP MAP --- !!!");
QMap<QPair<trackType_t, QString>, propertyId_t> *const builder = new QMap<QPair<trackType_t, QString>, propertyId_t>(); QMap<QPair<trackType_t, QString>, propertyId_t> *const builder = new QMap<QPair<trackType_t, QString>, propertyId_t>();
DEFINE_PROPTERY_MAPPING(gen, format); DEFINE_PROPTERY_MAPPING(gen, format);
DEFINE_PROPTERY_MAPPING(gen, format_profile); DEFINE_PROPTERY_MAPPING(gen, format_profile);
@ -631,6 +632,11 @@ bool AnalyzeTask_XmlHandler::startElement(const QString &namespaceURI, const QSt
qWarning("Invalid XML structure was detected! (1)"); qWarning("Invalid XML structure was detected! (1)");
return false; return false;
} }
if (!STR_EQ(atts.value("version"), QString().sprintf("0.%u.%02u", m_version / 100U, m_version % 100)))
{
qWarning("Invalid version property was detected!");
return false;
}
return true; return true;
case 2: case 2:
if (!STR_EQ(qName, "file")) if (!STR_EQ(qName, "file"))
@ -675,17 +681,17 @@ bool AnalyzeTask_XmlHandler::startElement(const QString &namespaceURI, const QSt
switch (m_trackType) switch (m_trackType)
{ {
case trackType_gen: case trackType_gen:
m_currentProperty = qMakePair(trackType_gen, qName.simplified().toLower()); m_currentProperty = m_properties.value(qMakePair(trackType_gen, qName.simplified().toLower()), propertyId_t(-1));
return true; return true;
case trackType_aud: case trackType_aud:
m_currentProperty = qMakePair(trackType_aud, qName.simplified().toLower()); m_currentProperty = m_properties.value(qMakePair(trackType_aud, qName.simplified().toLower()), propertyId_t(-1));
return true; return true;
default: default:
m_currentProperty = qMakePair(trackType_non, qName.simplified().toLower()); m_currentProperty = propertyId_t(-1);
return true; return true;
} }
default: default:
return false; return true;
} }
} }
@ -697,24 +703,20 @@ bool AnalyzeTask_XmlHandler::endElement(const QString &namespaceURI, const QStri
bool AnalyzeTask_XmlHandler::characters(const QString& ch) bool AnalyzeTask_XmlHandler::characters(const QString& ch)
{ {
if ((m_stack.size() == 4) && m_currentProperty.first) if ((m_currentProperty != propertyId_t(-1)) && (m_stack.size() == 4))
{ {
const QString value = ch.simplified(); const QString value = ch.simplified();
if (!value.isEmpty()) if (!value.isEmpty())
{ {
qDebug("Property: %u::%s --> \"%s\"", m_currentProperty.first, MUTILS_UTF8(m_currentProperty.second), MUTILS_UTF8(value)); updatePropertry(m_currentProperty, value);
if (!updatePropertry(m_currentProperty, value))
{
qWarning("Ignored property: %u::%s!", m_currentProperty.first, MUTILS_UTF8(m_currentProperty.second));
}
} }
} }
return true; return true;
} }
bool AnalyzeTask_XmlHandler::updatePropertry(const QPair<trackType_t, QString> &id, const QString &value) bool AnalyzeTask_XmlHandler::updatePropertry(const propertyId_t &idx, const QString &value)
{ {
switch (m_properties.value(id, propertyId_t(-1))) switch (idx)
{ {
case propertyId_gen_format: m_audioFile.techInfo().setContainerType(value); return true; case propertyId_gen_format: m_audioFile.techInfo().setContainerType(value); return true;
case propertyId_gen_format_profile: m_audioFile.techInfo().setContainerProfile(value); return true; case propertyId_gen_format_profile: m_audioFile.techInfo().setContainerProfile(value); return true;
@ -724,7 +726,7 @@ bool AnalyzeTask_XmlHandler::updatePropertry(const QPair<trackType_t, QString> &
case propertyId_aud_format_profile: m_audioFile.techInfo().setAudioProfile(value); return true; case propertyId_aud_format_profile: m_audioFile.techInfo().setAudioProfile(value); return true;
case propertyId_aud_channel_s_: SET_OPTIONAL(quint32, parseUnsigned(value, _tmp), m_audioFile.techInfo().setAudioChannels(_tmp)); return true; case propertyId_aud_channel_s_: SET_OPTIONAL(quint32, parseUnsigned(value, _tmp), m_audioFile.techInfo().setAudioChannels(_tmp)); return true;
case propertyId_aud_samplingrate: SET_OPTIONAL(quint32, parseUnsigned(value, _tmp), m_audioFile.techInfo().setAudioSamplerate(_tmp)); return true; case propertyId_aud_samplingrate: SET_OPTIONAL(quint32, parseUnsigned(value, _tmp), m_audioFile.techInfo().setAudioSamplerate(_tmp)); return true;
default: return false; default: MUTILS_THROW_FMT("Invalid property ID: %d", idx);
} }
} }

View File

@ -78,6 +78,7 @@ private:
const unsigned int m_taskId; const unsigned int m_taskId;
const QString m_mediaInfoBin; const QString m_mediaInfoBin;
const quint32 m_mediaInfoVer;
const QString m_avs2wavBin; const QString m_avs2wavBin;
const QString m_inputFile; const QString m_inputFile;