[175] | 1 | /* smplayer, GUI front-end for mplayer.
|
---|
[188] | 2 | Copyright (C) 2006-2017 Ricardo Villalba <rvm@users.sourceforge.net>
|
---|
[175] | 3 |
|
---|
| 4 | This program is free software; you can redistribute it and/or modify
|
---|
| 5 | it under the terms of the GNU General Public License as published by
|
---|
| 6 | the Free Software Foundation; either version 2 of the License, or
|
---|
| 7 | (at your option) any later version.
|
---|
| 8 |
|
---|
| 9 | This program is distributed in the hope that it will be useful,
|
---|
| 10 | but WITHOUT ANY WARRANTY; without even the implied warranty of
|
---|
| 11 | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
---|
| 12 | GNU General Public License for more details.
|
---|
| 13 |
|
---|
| 14 | You should have received a copy of the GNU General Public License
|
---|
| 15 | along with this program; if not, write to the Free Software
|
---|
| 16 | Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
---|
| 17 | */
|
---|
| 18 |
|
---|
| 19 | #include "inforeadermpv.h"
|
---|
| 20 | #include "mplayerversion.h"
|
---|
| 21 | #include <QStringList>
|
---|
| 22 | #include <QProcess>
|
---|
| 23 | #include <QDebug>
|
---|
| 24 |
|
---|
| 25 |
|
---|
| 26 | InfoReaderMPV::InfoReaderMPV( QString mplayer_bin, QObject * parent )
|
---|
| 27 | : QObject(parent)
|
---|
| 28 | , mplayer_svn(0)
|
---|
| 29 | {
|
---|
| 30 | mplayerbin = mplayer_bin;
|
---|
| 31 | }
|
---|
| 32 |
|
---|
| 33 | InfoReaderMPV::~InfoReaderMPV() {
|
---|
| 34 | }
|
---|
| 35 |
|
---|
| 36 | void InfoReaderMPV::getInfo() {
|
---|
| 37 | vo_list.clear();
|
---|
| 38 | ao_list.clear();
|
---|
| 39 | #if ALLOW_DEMUXER_CODEC_CHANGE
|
---|
| 40 | demuxer_list.clear();
|
---|
| 41 | vc_list.clear();
|
---|
| 42 | ac_list.clear();
|
---|
| 43 | #endif
|
---|
| 44 | vf_list.clear();
|
---|
| 45 | mplayer_svn = -1;
|
---|
| 46 |
|
---|
| 47 | vo_list = getList(run("--vo help"));
|
---|
| 48 | ao_list = getList(run("--ao help"));
|
---|
| 49 | #if ALLOW_DEMUXER_CODEC_CHANGE
|
---|
| 50 | demuxer_list = getList(run("--demuxer help"));
|
---|
| 51 | vc_list = getList(run("--vd help"));
|
---|
| 52 | ac_list = getList(run("--ad help"));
|
---|
| 53 | #endif
|
---|
| 54 | {
|
---|
| 55 | InfoList list = getList(run("--vf help"));
|
---|
| 56 | for (int n = 0; n < list.count(); n++) {
|
---|
| 57 | vf_list.append(list[n].name());
|
---|
| 58 | }
|
---|
| 59 | }
|
---|
| 60 |
|
---|
| 61 | QList<QByteArray> lines = run("--version");
|
---|
| 62 |
|
---|
| 63 | QString mpv_version_line;
|
---|
| 64 | if (lines.count() >= 1) {
|
---|
| 65 | mpv_version_line = lines[0];
|
---|
| 66 | mplayer_svn = MplayerVersion::mplayerVersion(mpv_version_line);
|
---|
| 67 | mpv_version = MplayerVersion::mpvVersion();
|
---|
| 68 | }
|
---|
| 69 |
|
---|
| 70 | qDebug() << "InfoReaderMPV::getInfo: version_line" << mpv_version_line;
|
---|
| 71 | qDebug() << "InfoReaderMPV::getInfo: mplayer_svn" << mplayer_svn;
|
---|
| 72 |
|
---|
| 73 | option_list = getOptionsList(run("--list-options"));
|
---|
| 74 |
|
---|
| 75 | //list();
|
---|
| 76 | }
|
---|
| 77 |
|
---|
| 78 | void InfoReaderMPV::list() {
|
---|
| 79 | qDebug("InfoReaderMPV::list");
|
---|
| 80 |
|
---|
| 81 | InfoList::iterator it;
|
---|
| 82 |
|
---|
| 83 | qDebug(" vo_list:");
|
---|
| 84 | for ( it = vo_list.begin(); it != vo_list.end(); ++it ) {
|
---|
| 85 | qDebug( "driver: '%s', desc: '%s'", (*it).name().toUtf8().data(), (*it).desc().toUtf8().data());
|
---|
| 86 | }
|
---|
| 87 |
|
---|
| 88 | qDebug(" ao_list:");
|
---|
| 89 | for ( it = ao_list.begin(); it != ao_list.end(); ++it ) {
|
---|
| 90 | qDebug( "driver: '%s', desc: '%s'", (*it).name().toUtf8().data(), (*it).desc().toUtf8().data());
|
---|
| 91 | }
|
---|
| 92 |
|
---|
| 93 | #if ALLOW_DEMUXER_CODEC_CHANGE
|
---|
| 94 | qDebug(" demuxer_list:");
|
---|
| 95 | for ( it = demuxer_list.begin(); it != demuxer_list.end(); ++it ) {
|
---|
| 96 | qDebug( "demuxer: '%s', desc: '%s'", (*it).name().toUtf8().data(), (*it).desc().toUtf8().data());
|
---|
| 97 | }
|
---|
| 98 |
|
---|
| 99 | qDebug(" vc_list:");
|
---|
| 100 | for ( it = vc_list.begin(); it != vc_list.end(); ++it ) {
|
---|
| 101 | qDebug( "codec: '%s', desc: '%s'", (*it).name().toUtf8().data(), (*it).desc().toUtf8().data());
|
---|
| 102 | }
|
---|
| 103 |
|
---|
| 104 | qDebug(" ac_list:");
|
---|
| 105 | for ( it = ac_list.begin(); it != ac_list.end(); ++it ) {
|
---|
| 106 | qDebug( "codec: '%s', desc: '%s'", (*it).name().toUtf8().data(), (*it).desc().toUtf8().data());
|
---|
| 107 | }
|
---|
| 108 | #endif
|
---|
| 109 | }
|
---|
| 110 |
|
---|
| 111 | QList<QByteArray> InfoReaderMPV::run(QString options) {
|
---|
| 112 | qDebug("InfoReaderMPV::run: '%s'", options.toUtf8().data());
|
---|
| 113 |
|
---|
| 114 | QList<QByteArray> r;
|
---|
| 115 |
|
---|
| 116 | QProcess proc(this);
|
---|
| 117 | proc.setProcessChannelMode( QProcess::MergedChannels );
|
---|
| 118 |
|
---|
| 119 | QStringList args = options.split(" ");
|
---|
| 120 |
|
---|
| 121 | proc.start(mplayerbin, args);
|
---|
| 122 | if (!proc.waitForStarted()) {
|
---|
| 123 | qWarning("InfoReaderMPV::run: process can't start!");
|
---|
| 124 | return r;
|
---|
| 125 | }
|
---|
| 126 |
|
---|
| 127 | //Wait until finish
|
---|
| 128 | if (!proc.waitForFinished()) {
|
---|
| 129 | qWarning("InfoReaderMPV::run: process didn't finish. Killing it...");
|
---|
| 130 | proc.kill();
|
---|
| 131 | }
|
---|
| 132 |
|
---|
| 133 | QByteArray data = proc.readAll().replace("\r", "");
|
---|
| 134 | r = data.split('\n');
|
---|
| 135 | return r;
|
---|
| 136 | }
|
---|
| 137 |
|
---|
| 138 | InfoList InfoReaderMPV::getList(const QList<QByteArray> & lines) {
|
---|
| 139 | InfoList l;
|
---|
| 140 |
|
---|
| 141 | foreach(QByteArray line, lines) {
|
---|
| 142 | //qDebug() << "InfoReaderMPV::getList: line:" << line;
|
---|
| 143 |
|
---|
| 144 | line.replace("\n", "");
|
---|
| 145 | line = line.simplified();
|
---|
| 146 | if (line.startsWith("Available") || line.startsWith("demuxer:") ||
|
---|
| 147 | line.startsWith("Video decoders:") || line.startsWith("Audio decoders:"))
|
---|
| 148 | {
|
---|
| 149 | line = QByteArray();
|
---|
| 150 | }
|
---|
| 151 | if (!line.isEmpty()) {
|
---|
| 152 | int pos = line.indexOf(' ');
|
---|
| 153 | if (pos > -1) {
|
---|
| 154 | QString name = line.left(pos);
|
---|
| 155 | if (name.endsWith(':')) name = name.left(name.count()-1);
|
---|
| 156 | QString desc = line.mid(pos+1);
|
---|
| 157 | desc = desc.replace(": ", "").replace("- ", "");
|
---|
| 158 | //qDebug() << "InfoReaderMPV::getList: name:" << name << "desc:" << desc;
|
---|
| 159 | l.append(InfoData(name, desc));
|
---|
| 160 | }
|
---|
| 161 | }
|
---|
| 162 | }
|
---|
| 163 |
|
---|
| 164 | return l;
|
---|
| 165 | }
|
---|
| 166 |
|
---|
| 167 | QStringList InfoReaderMPV::getOptionsList(const QList<QByteArray> & lines) {
|
---|
| 168 | QStringList l;
|
---|
| 169 |
|
---|
| 170 | foreach(QByteArray line, lines) {
|
---|
| 171 | //qDebug() << "InfoReaderMPV::getOptionsList: line:" << line;
|
---|
| 172 | line.replace("\n", "");
|
---|
| 173 | line = line.simplified();
|
---|
| 174 | if (line.startsWith("--")) {
|
---|
| 175 | int pos = line.indexOf(' ');
|
---|
| 176 | if (pos > -1) {
|
---|
| 177 | QString option_name = line.left(pos);
|
---|
| 178 | //qDebug() << "InfoReaderMPV::getOptionsList: option:" << option_name;
|
---|
| 179 | l << option_name;
|
---|
| 180 | }
|
---|
| 181 | }
|
---|
| 182 | }
|
---|
| 183 |
|
---|
| 184 | return l;
|
---|
| 185 | }
|
---|
| 186 |
|
---|
| 187 | #include "moc_inforeadermpv.cpp"
|
---|