aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authortrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2018-05-26 22:24:32 +0000
committertrialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38>2018-05-26 22:24:32 +0000
commita9e350153bb4e2c778f8c2f566d5d6ea6f9e0311 (patch)
treeae9c53bc49dc64de9911adee8e56c0ce6b5e93a8
parentcc01d8feb7ae39567746f85b1ec971dd7b54d0ae (diff)
downloadqmmp-a9e350153bb4e2c778f8c2f566d5d6ea6f9e0311.tar.gz
qmmp-a9e350153bb4e2c778f8c2f566d5d6ea6f9e0311.tar.bz2
qmmp-a9e350153bb4e2c778f8c2f566d5d6ea6f9e0311.zip
fixed some metadata issues
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@7960 90c681e8-e032-0410-971d-27865f9a5e38
-rw-r--r--src/qmmp/decoder.cpp29
-rw-r--r--src/qmmp/decoder.h4
-rw-r--r--src/qmmp/metadatamanager.cpp41
-rw-r--r--src/qmmp/metadatamanager.h2
-rw-r--r--src/qmmp/qmmpaudioengine.cpp43
-rw-r--r--src/qmmp/qmmpaudioengine_p.h2
6 files changed, 89 insertions, 32 deletions
diff --git a/src/qmmp/decoder.cpp b/src/qmmp/decoder.cpp
index d29ea5114..0db755592 100644
--- a/src/qmmp/decoder.cpp
+++ b/src/qmmp/decoder.cpp
@@ -34,18 +34,21 @@ void Decoder::setReplayGainInfo(const QMap<Qmmp::ReplayGainKey, double> &rg)
void Decoder::configure(quint32 srate, const ChannelMap &map, Qmmp::AudioFormat format)
{
- m_parameters = AudioParameters(srate, map, format);
+ configure(AudioParameters(srate, map, format));
}
void Decoder::configure(quint32 srate, int channels, Qmmp::AudioFormat f)
{
qDebug("Decoder: using internal channel order");
- m_parameters = AudioParameters(srate, ChannelMap(channels), f);
+ configure(AudioParameters(srate, ChannelMap(channels), f));
}
void Decoder::configure(const AudioParameters &p)
{
m_parameters = p;
+ setProperty(Qmmp::SAMPLERATE, m_parameters.sampleRate());
+ setProperty(Qmmp::CHANNELS, m_parameters.channels());
+ setProperty(Qmmp::BITS_PER_SAMPLE, m_parameters.validBitsPerSample());
}
void Decoder::next()
@@ -88,6 +91,28 @@ QMap<Qmmp::MetaData, QString> Decoder::takeMetaData()
return m_metaData;
}
+void Decoder::setProperty(Qmmp::TrackProperty key, const QVariant &value)
+{
+ QString strValue = value.toString();
+ if(strValue.isEmpty() || strValue == "0")
+ m_properties.remove(key);
+ else
+ m_properties[key] = strValue;
+}
+
+void Decoder::setProperties(const QMap<Qmmp::TrackProperty, QString> &properties)
+{
+ foreach(Qmmp::TrackProperty key, properties.keys())
+ {
+ setProperty(key, properties.value(key));
+ }
+}
+
+const QMap<Qmmp::TrackProperty, QString> &Decoder::properties() const
+{
+ return m_properties;
+}
+
// static methods
QStringList Decoder::m_disabledNames;
QList<QmmpPluginCache*> *Decoder::m_cache = 0;
diff --git a/src/qmmp/decoder.h b/src/qmmp/decoder.h
index dbaea31ae..c1327c77e 100644
--- a/src/qmmp/decoder.h
+++ b/src/qmmp/decoder.h
@@ -105,6 +105,9 @@ public:
* Attention: hasMetaData() should return \b true before use of this fuction.
*/
QMap<Qmmp::MetaData, QString> takeMetaData();
+ void setProperty(Qmmp::TrackProperty key, const QVariant &value);
+ void setProperties(const QMap<Qmmp::TrackProperty, QString> &properties);
+ const QMap<Qmmp::TrackProperty, QString> &properties() const;
/*!
* Returns DecoderFactory pointer which supports file \b path or 0 if file \b path is unsupported
* @param path Full local file path.
@@ -185,6 +188,7 @@ private:
static QList<QmmpPluginCache*> *m_cache;
static QStringList m_disabledNames;
AudioParameters m_parameters;
+ QMap<Qmmp::TrackProperty, QString> m_properties;
QIODevice *m_input;
bool m_hasMetaData;
QMap<Qmmp::MetaData, QString> m_metaData;
diff --git a/src/qmmp/metadatamanager.cpp b/src/qmmp/metadatamanager.cpp
index 9a401578d..c14da951e 100644
--- a/src/qmmp/metadatamanager.cpp
+++ b/src/qmmp/metadatamanager.cpp
@@ -47,7 +47,7 @@ MetaDataManager::~MetaDataManager()
m_instance = 0;
}
-QList<TrackInfo *> MetaDataManager::createPlayList(const QString &fileName, TrackInfo::Parts parts, QStringList *ignoredPaths) const
+QList<TrackInfo *> MetaDataManager::createPlayList(const QString &path, TrackInfo::Parts parts, QStringList *ignoredPaths) const
{
QList <TrackInfo *> list;
DecoderFactory *fact = 0;
@@ -56,30 +56,43 @@ QList<TrackInfo *> MetaDataManager::createPlayList(const QString &fileName, Trac
if(!ignoredPaths)
ignoredPaths = &dummyList;
- if (!fileName.contains("://")) //local file
+ if (!path.contains("://")) //local file
{
- if(!QFile::exists(fileName))
+ if(!QFile::exists(path))
return list;
- else if((fact = Decoder::findByFilePath(fileName, m_settings->determineFileTypeByContent())))
- return fact->createPlayList(fileName, parts, ignoredPaths);
- else if((efact = AbstractEngine::findByFilePath(fileName)))
- return efact->createPlayList(fileName, parts, ignoredPaths);
- return list;
+
+ if(!(fact = Decoder::findByFilePath(path, m_settings->determineFileTypeByContent())))
+ efact = AbstractEngine::findByFilePath(path);
}
else
{
- QString scheme = fileName.section("://",0,0);
+ QString scheme = path.section("://",0,0);
if(InputSource::protocols().contains(scheme))
{
- list << new TrackInfo(fileName);
- return list;
+ list << new TrackInfo(path);
}
- foreach(fact, Decoder::factories())
+ else
{
- if(fact->properties().protocols.contains(scheme) && Decoder::isEnabled(fact))
- return fact->createPlayList(fileName, parts, ignoredPaths);
+ foreach(fact, Decoder::factories())
+ {
+ if(fact->properties().protocols.contains(scheme) && Decoder::isEnabled(fact))
+ break;
+ }
}
}
+
+ if(fact)
+ list = fact->createPlayList(path, parts, ignoredPaths);
+ else if(efact)
+ list = efact->createPlayList(path, parts, ignoredPaths);
+
+ foreach(TrackInfo *info, list)
+ {
+ if(info->value(Qmmp::DECODER).isEmpty() && (fact || efact))
+ info->setValue(Qmmp::DECODER, fact ? fact->properties().shortName : efact->properties().shortName);
+ if(info->value(Qmmp::FILE_SIZE).isEmpty() && !path.contains("://"))
+ info->setValue(Qmmp::FILE_SIZE, QFileInfo(path).size());
+ }
return list;
}
diff --git a/src/qmmp/metadatamanager.h b/src/qmmp/metadatamanager.h
index 64947c739..ab2e9aec5 100644
--- a/src/qmmp/metadatamanager.h
+++ b/src/qmmp/metadatamanager.h
@@ -52,7 +52,7 @@ public:
/*!
* Extracts metadata and audio information from file \b path and returns a list of FileInfo items.
* One file may contain several playlist items (for example: cda disk or flac with embedded cue)
- * @param path Source file path.
+ * @param path Local file path or URL.
* @param ignoredPaths Pointer to a list of the files which should be ignored by the recursive search
* (useful to exclude cue data files from playlist)
*/
diff --git a/src/qmmp/qmmpaudioengine.cpp b/src/qmmp/qmmpaudioengine.cpp
index 719c07de1..f7997d184 100644
--- a/src/qmmp/qmmpaudioengine.cpp
+++ b/src/qmmp/qmmpaudioengine.cpp
@@ -156,6 +156,7 @@ bool QmmpAudioEngine::enqueue(InputSource *source)
delete decoder;
return false;
}
+ attachMetaData(decoder, factory, source);
mutex()->lock();
m_decoders.enqueue(decoder);
m_inputs.insert(decoder, source);
@@ -360,7 +361,6 @@ void QmmpAudioEngine::run()
StateHandler::instance()->dispatch(Qmmp::Buffering);
StateHandler::instance()->dispatch(m_decoder->totalTime());
StateHandler::instance()->dispatch(Qmmp::Playing);
- sendMetaData();
while (!m_done && !m_finish)
{
@@ -387,6 +387,7 @@ void QmmpAudioEngine::run()
QMap<Qmmp::MetaData, QString> m = m_decoder->takeMetaData();
TrackInfo info(m_inputs[m_decoder]->path());
info.setValues(m);
+ info.setValues(m_decoder->properties());
info.setDuration(m_decoder->totalTime());
if(StateHandler::instance()->dispatch(info))
m_trackInfo = QSharedPointer<TrackInfo>(new TrackInfo(info));
@@ -457,7 +458,6 @@ void QmmpAudioEngine::run()
m_output->seek(0); //reset counter
StateHandler::instance()->dispatch(Qmmp::Playing);
mutex()->unlock();
- sendMetaData();
addOffset(); //offset
}
else
@@ -477,7 +477,6 @@ void QmmpAudioEngine::run()
m_output->start();
StateHandler::instance()->dispatch(Qmmp::Playing);
StateHandler::instance()->dispatch(m_decoder->totalTime());
- sendMetaData();
addOffset(); //offset
}
}
@@ -586,22 +585,38 @@ void QmmpAudioEngine::addOffset()
}
}
-void QmmpAudioEngine::sendMetaData()
+void QmmpAudioEngine::attachMetaData(Decoder *decoder, DecoderFactory *factory, InputSource *source)
{
- if(!m_decoder || m_inputs.isEmpty())
- return;
- QString path = m_inputs.value(m_decoder)->path();
- if (QFileInfo(path).isFile()) //send metadata for local files only
+ QString path = source->path();
+ QString scheme = path.section("://",0,0);
+ QFileInfo fileInfo(path);
+
+ if(fileInfo.isFile() || factory->properties().protocols.contains(scheme))
{
- QList <TrackInfo *> list = MetaDataManager::instance()->createPlayList(path, TrackInfo::AllParts);
- if (!list.isEmpty())
+ QStringList ignoredPaths;
+ QList<TrackInfo *> list = factory->createPlayList(path, TrackInfo::AllParts, &ignoredPaths);
+ if(!list.isEmpty())
{
- StateHandler::instance()->dispatch(*list.first());
- m_trackInfo = QSharedPointer<TrackInfo>(list.first());
- while(list.size() > 1)
- delete list.takeLast();
+ TrackInfo *info = list.takeFirst();
+ qDeleteAll(list);
+ list.clear();
+ decoder->addMetaData(info->metaData());
+ if(info->parts() & TrackInfo::ReplayGainInfo)
+ decoder->setReplayGainInfo(info->replayGainInfo());
+ info->updateValues(decoder->properties());
+ info->setValue(Qmmp::DECODER, factory->properties().shortName);
+ if(QFileInfo(path).isFile() && !info->value(Qmmp::FILE_SIZE).isEmpty())
+ info->setValue(Qmmp::FILE_SIZE, fileInfo.size());
+ decoder->setProperties(info->properties());
+ delete info;
}
}
+ else
+ {
+ decoder->setProperty(Qmmp::DECODER, factory->properties().shortName);
+ if(!decoder->hasMetaData())
+ decoder->addMetaData(QMap<Qmmp::MetaData, QString>()); //add empty metadata to trigger track info update
+ }
}
OutputWriter *QmmpAudioEngine::createOutput()
diff --git a/src/qmmp/qmmpaudioengine_p.h b/src/qmmp/qmmpaudioengine_p.h
index a8eea6590..3443ff74b 100644
--- a/src/qmmp/qmmpaudioengine_p.h
+++ b/src/qmmp/qmmpaudioengine_p.h
@@ -76,7 +76,7 @@ private:
void flush(bool = false);
void addOffset();
qint64 produceSound(unsigned char *data, qint64 size, quint32 brate);
- void sendMetaData();
+ void attachMetaData(Decoder *decoder, DecoderFactory *factory, InputSource *source);
OutputWriter *createOutput();
void prepareEffects(Decoder *d);