diff options
Diffstat (limited to 'src/plugins/Input/ffmpeg/decoderffmpegfactory.cpp')
| -rw-r--r-- | src/plugins/Input/ffmpeg/decoderffmpegfactory.cpp | 62 |
1 files changed, 55 insertions, 7 deletions
diff --git a/src/plugins/Input/ffmpeg/decoderffmpegfactory.cpp b/src/plugins/Input/ffmpeg/decoderffmpegfactory.cpp index 6c5c1c53a..040819ba9 100644 --- a/src/plugins/Input/ffmpeg/decoderffmpegfactory.cpp +++ b/src/plugins/Input/ffmpeg/decoderffmpegfactory.cpp @@ -22,6 +22,7 @@ #include <QMessageBox> #include <QFileInfo> #include <QRegularExpression> +#include <QtDebug> #include <qmmp/cueparser.h> extern "C"{ #include <libavformat/avformat.h> @@ -34,6 +35,7 @@ extern "C"{ #include "settingsdialog.h" #include "decoder_ffmpeg.h" #include "decoder_ffmpegcue.h" +#include "decoder_ffmpegm4b.h" #include "decoderffmpegfactory.h" @@ -96,10 +98,13 @@ DecoderProperties DecoderFFmpegFactory::properties() const { QSettings settings(Qmmp::configFile(), QSettings::IniFormat); QStringList filters = { - "*.wma", "*.ape", "*.tta", "*.m4a", "*.aac", "*.ra", "*.shn", "*.vqf", "*.ac3", "*.tak", "*.dsf", "*.dsdiff" + "*.wma", "*.ape", "*.tta", "*.m4a", "*.m4b", "*.aac", "*.ra", "*.shn", "*.vqf", "*.ac3", "*.tak", "*.dsf", "*.dsdiff" }; filters = settings.value("FFMPEG/filters", filters).toStringList(); + if(filters.contains("*.m4a") && !filters.contains("*.m4b")) + filters << "*.m4b"; + if(!avcodec_find_decoder(AV_CODEC_ID_WMAV1)) filters.removeAll("*.wma"); if(!avcodec_find_decoder(AV_CODEC_ID_APE)) @@ -111,7 +116,10 @@ DecoderProperties DecoderFFmpegFactory::properties() const if(!avcodec_find_decoder(AV_CODEC_ID_MP3)) filters.removeAll("*.mp3"); if(!avcodec_find_decoder(AV_CODEC_ID_AAC) && !avcodec_find_decoder(AV_CODEC_ID_ALAC)) + { filters.removeAll("*.m4a"); + filters.removeAll("*.m4b"); + } if(!avcodec_find_decoder(AV_CODEC_ID_RA_288)) filters.removeAll("*.ra"); if(!avcodec_find_decoder(AV_CODEC_ID_SHORTEN)) @@ -160,7 +168,7 @@ DecoderProperties DecoderFFmpegFactory::properties() const properties.hasAbout = true; properties.hasSettings = true; properties.noInput = false; - properties.protocols << "ffmpeg"; + properties.protocols << "ffmpeg" << "m4b"; properties.priority = 10; return properties; } @@ -169,24 +177,28 @@ Decoder *DecoderFFmpegFactory::create(const QString &path, QIODevice *input) { if(path.startsWith("ffmpeg://")) return new DecoderFFmpegCue(path); + else if(path.startsWith("m4b://")) + return new DecoderFFmpegM4b(this, path); else return new DecoderFFmpeg(path, input); } QList<TrackInfo *> DecoderFFmpegFactory::createPlayList(const QString &path, TrackInfo::Parts parts, QStringList *) { - int cueTrack = -1; //cue track + qDebug() << path; + int trackNumber = -1; //cue/m4b track QString filePath = path; if(path.contains("://")) //is it cue track? { filePath.remove("ffmpeg://"); + filePath.remove("m4b://"); filePath.remove(QRegularExpression("#\\d+$")); - cueTrack = path.section("#", -1).toInt(); - parts = TrackInfo::AllParts; //extract all metadata for single cue track + trackNumber = path.section("#", -1).toInt(); + parts = TrackInfo::AllParts; //extract all metadata for single cue/m4b track } - TrackInfo *info = new TrackInfo(filePath); + TrackInfo *info = new TrackInfo(filePath); if(parts == TrackInfo::Parts()) return QList<TrackInfo*>() << info; @@ -241,7 +253,7 @@ QList<TrackInfo *> DecoderFFmpegFactory::createPlayList(const QString &path, Tra avformat_close_input(&in); delete info; - return (cueTrack > 0) ? parser.createPlayList(cueTrack) : parser.createPlayList(); + return (trackNumber > 0) ? parser.createPlayList(trackNumber) : parser.createPlayList(); } AVDictionaryEntry *album = av_dict_get(in->metadata,"album",nullptr,0); @@ -288,6 +300,14 @@ QList<TrackInfo *> DecoderFFmpegFactory::createPlayList(const QString &path, Tra info->setValue(Qmmp::YEAR, year->value); if(track) info->setValue(Qmmp::TRACK, track->value); + + if(in->nb_chapters > 1 && filePath.endsWith(".m4b", Qt::CaseInsensitive)) + { + QList<TrackInfo *> tracks = createPlayListFromChapters(in, info, trackNumber); + avformat_close_input(&in); + delete info; + return tracks; + } } avformat_close_input(&in); @@ -330,3 +350,31 @@ QString DecoderFFmpegFactory::translation() const { return QLatin1String(":/ffmpeg_plugin_"); } + +QList<TrackInfo *> DecoderFFmpegFactory::createPlayListFromChapters(AVFormatContext *in, + TrackInfo *extraInfo, + int trackNumber) +{ + QList<TrackInfo *> tracks; + + for(unsigned int i = 0; i < in->nb_chapters; ++i) + { + if((trackNumber > 0) && (int(i + 1) != trackNumber)) + continue; + + AVChapter *chapter = in->chapters[i]; + TrackInfo *info = new TrackInfo(QString("m4b://%1#%2").arg(extraInfo->path()).arg(i + 1)); + info->setDuration((chapter->end - chapter->start) * av_q2d(chapter->time_base) * 1000); + info->setValues(extraInfo->properties()); + info->setValues(extraInfo->metaData()); + info->setValue(Qmmp::TRACK, i + 1); + + AVDictionaryEntry *title = av_dict_get(chapter->metadata,"title", nullptr, 0); + if(title) + info->setValue(Qmmp::TITLE, QString::fromUtf8(title->value).trimmed()); + + tracks << info; + } + + return tracks; +} |
