diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2016-01-15 20:57:46 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2016-01-15 20:57:46 +0000 |
| commit | 732cf510bc813bf11453f2f14dd5084d641793fa (patch) | |
| tree | bcb2a7bceab91c5d0903720afe4a8784c5b343bf /src/plugins/Input | |
| parent | 3a08cb8fbb96b7b7280e417fb2f3a954fda82d12 (diff) | |
| download | qmmp-732cf510bc813bf11453f2f14dd5084d641793fa.tar.gz qmmp-732cf510bc813bf11453f2f14dd5084d641793fa.tar.bz2 qmmp-732cf510bc813bf11453f2f14dd5084d641793fa.zip | |
ffmpeg: added replaygain support
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@6037 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/plugins/Input')
| -rw-r--r-- | src/plugins/Input/ffmpeg/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | src/plugins/Input/ffmpeg/decoder_ffmpeg.cpp | 6 | ||||
| -rw-r--r-- | src/plugins/Input/ffmpeg/ffmpeg.pro | 6 | ||||
| -rw-r--r-- | src/plugins/Input/ffmpeg/replaygainreader.cpp | 53 | ||||
| -rw-r--r-- | src/plugins/Input/ffmpeg/replaygainreader.h | 46 |
5 files changed, 111 insertions, 2 deletions
diff --git a/src/plugins/Input/ffmpeg/CMakeLists.txt b/src/plugins/Input/ffmpeg/CMakeLists.txt index ce2c84c04..d74b2e611 100644 --- a/src/plugins/Input/ffmpeg/CMakeLists.txt +++ b/src/plugins/Input/ffmpeg/CMakeLists.txt @@ -41,10 +41,12 @@ SET(libffmpeg_SRCS decoderffmpegfactory.cpp ffmpegmetadatamodel.cpp settingsdialog.cpp + replaygain.cpp ) SET(libffmpeg_HDRS decoder_ffmpeg.h + replaygain.h ) SET(libffmpeg_RCCS translations/translations.qrc) diff --git a/src/plugins/Input/ffmpeg/decoder_ffmpeg.cpp b/src/plugins/Input/ffmpeg/decoder_ffmpeg.cpp index 953f2f60e..16a6c3bff 100644 --- a/src/plugins/Input/ffmpeg/decoder_ffmpeg.cpp +++ b/src/plugins/Input/ffmpeg/decoder_ffmpeg.cpp @@ -20,6 +20,7 @@ #include <QObject> #include <QFile> +#include "replaygainreader.h" #include "decoder_ffmpeg.h" #if (LIBAVCODEC_VERSION_INT >= ((55<<16)+(34<<8)+0)) //libav-10: 55.34.1; ffmpeg-2.1: 55.39.100 extern "C"{ @@ -191,6 +192,11 @@ bool DecoderFFmpeg::initialize() addMetaData(metaData); } + //replay gain + ReplayGainReader rg(ic); + setReplayGainInfo(rg.replayGainInfo()); + + ic->flags |= AVFMT_FLAG_GENPTS; av_read_play(ic); for (wma_idx = 0; wma_idx < (int)ic->nb_streams; wma_idx++) diff --git a/src/plugins/Input/ffmpeg/ffmpeg.pro b/src/plugins/Input/ffmpeg/ffmpeg.pro index 0897240ff..32fefa1d3 100644 --- a/src/plugins/Input/ffmpeg/ffmpeg.pro +++ b/src/plugins/Input/ffmpeg/ffmpeg.pro @@ -3,11 +3,13 @@ FORMS += settingsdialog.ui HEADERS += decoderffmpegfactory.h \ decoder_ffmpeg.h \ settingsdialog.h \ - ffmpegmetadatamodel.h + ffmpegmetadatamodel.h \ + replaygainreader.h SOURCES += decoder_ffmpeg.cpp \ decoderffmpegfactory.cpp \ settingsdialog.cpp \ - ffmpegmetadatamodel.cpp + ffmpegmetadatamodel.cpp \ + replaygainreader.cpp INCLUDEPATH += ../../../ diff --git a/src/plugins/Input/ffmpeg/replaygainreader.cpp b/src/plugins/Input/ffmpeg/replaygainreader.cpp new file mode 100644 index 000000000..3ab6144fe --- /dev/null +++ b/src/plugins/Input/ffmpeg/replaygainreader.cpp @@ -0,0 +1,53 @@ +/*************************************************************************** + * Copyright (C) 2016 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#include "replaygainreader.h" + +ReplayGainReader::ReplayGainReader(AVFormatContext *ic) +{ + AVDictionaryEntry *t = 0; + while((t = av_dict_get(ic->metadata, "", t, AV_DICT_IGNORE_SUFFIX))) + { + if(!strcmp(t->key, "replaygain_album_gain")) + setValue(Qmmp::REPLAYGAIN_ALBUM_GAIN, t->value); + else if(!strcmp(t->key, "replaygain_album_peak")) + setValue(Qmmp::REPLAYGAIN_ALBUM_PEAK, t->value); + else if(!strcmp(t->key, "replaygain_track_gain")) + setValue(Qmmp::REPLAYGAIN_TRACK_GAIN, t->value); + else if(!strcmp(t->key, "replaygain_track_peak")) + setValue(Qmmp::REPLAYGAIN_TRACK_PEAK, t->value); + } +} + +QMap <Qmmp::ReplayGainKey, double> ReplayGainReader::replayGainInfo() const +{ + return m_values; +} + +void ReplayGainReader::setValue(Qmmp::ReplayGainKey key, QString value) +{ + value.remove(" dB"); + if(value.isEmpty()) + return; + bool ok; + double v = value.toDouble(&ok); + if(ok) + m_values[key] = v; +} diff --git a/src/plugins/Input/ffmpeg/replaygainreader.h b/src/plugins/Input/ffmpeg/replaygainreader.h new file mode 100644 index 000000000..236095beb --- /dev/null +++ b/src/plugins/Input/ffmpeg/replaygainreader.h @@ -0,0 +1,46 @@ +/*************************************************************************** + * Copyright (C) 2016 by Ilya Kotov * + * forkotov02@hotmail.ru * + * * + * This program is free software; you can redistribute it and/or modify * + * it under the terms of the GNU General Public License as published by * + * the Free Software Foundation; either version 2 of the License, or * + * (at your option) any later version. * + * * + * This program is distributed in the hope that it will be useful, * + * but WITHOUT ANY WARRANTY; without even the implied warranty of * + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * + * GNU General Public License for more details. * + * * + * You should have received a copy of the GNU General Public License * + * along with this program; if not, write to the * + * Free Software Foundation, Inc., * + * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * + ***************************************************************************/ + +#ifndef REPLAYGAINREADER_H +#define REPLAYGAINREADER_H + +#include <QMap> +#include <QString> +extern "C"{ +#include <libavformat/avformat.h> +#include <libavutil/dict.h> +} +#include <qmmp/qmmp.h> + +/** + @author Ilya Kotov <forkotov02@hotmail.ru> +*/ +class ReplayGainReader +{ +public: + ReplayGainReader(AVFormatContext *ic); + QMap <Qmmp::ReplayGainKey, double> replayGainInfo() const; + +private: + void setValue(Qmmp::ReplayGainKey key, QString value); + QMap <Qmmp::ReplayGainKey, double> m_values; +}; + +#endif // REPLAYGAINREADER_H |
