diff options
| author | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2008-12-31 13:22:43 +0000 |
|---|---|---|
| committer | trialuser02 <trialuser02@90c681e8-e032-0410-971d-27865f9a5e38> | 2008-12-31 13:22:43 +0000 |
| commit | b9e03a0340c9f16330142caed6f8a09f1e42f0a4 (patch) | |
| tree | 32bd482f678dbe194f5e1c6c1355979e3559fe3e /src/plugins/Input/mplayer | |
| parent | 5090db94c269d951fe0c1a488a81519c03ef4659 (diff) | |
| download | qmmp-b9e03a0340c9f16330142caed6f8a09f1e42f0a4.tar.gz qmmp-b9e03a0340c9f16330142caed6f8a09f1e42f0a4.tar.bz2 qmmp-b9e03a0340c9f16330142caed6f8a09f1e42f0a4.zip | |
added mplayer and phonon plugins
git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@722 90c681e8-e032-0410-971d-27865f9a5e38
Diffstat (limited to 'src/plugins/Input/mplayer')
| -rw-r--r-- | src/plugins/Input/mplayer/decoder_mplayer.cpp | 207 | ||||
| -rw-r--r-- | src/plugins/Input/mplayer/decoder_mplayer.h | 81 | ||||
| -rw-r--r-- | src/plugins/Input/mplayer/decodermplayerfactory.cpp | 103 | ||||
| -rw-r--r-- | src/plugins/Input/mplayer/decodermplayerfactory.h | 50 | ||||
| -rw-r--r-- | src/plugins/Input/mplayer/mplayer.pro | 35 |
5 files changed, 476 insertions, 0 deletions
diff --git a/src/plugins/Input/mplayer/decoder_mplayer.cpp b/src/plugins/Input/mplayer/decoder_mplayer.cpp new file mode 100644 index 000000000..924b3c7ea --- /dev/null +++ b/src/plugins/Input/mplayer/decoder_mplayer.cpp @@ -0,0 +1,207 @@ +/*************************************************************************** + * Copyright (C) 2008 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., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#include <qmmp/constants.h> +#include <qmmp/buffer.h> +#include <qmmp/output.h> +#include <qmmp/recycler.h> +#include <qmmp/fileinfo.h> +#include <qmmp/decoderfactory.h> + +#include <QObject> +#include <QProcess> +#include <QFile> +#include <QApplication> +#include <QAction> +#include <QMetaObject> +#include <QKeyEvent> +#include <QMenu> +#include <QRegExp> + +#include "decoder_mplayer.h" + +#define MPLAYER_DEBUG + +static QRegExp rx_av("^[AV]: *([0-9,:.-]+)"); +static QRegExp rx_pause("^(.*)=(.*)PAUSE(.*)"); +static QRegExp rx_end("^(.*)End of file(.*)"); +static QRegExp rx_quit("^(.*)Quit(.*)"); +static QRegExp rx_audio("^AUDIO: *([0-9,.]+) *Hz.*([0-9,.]+) *ch.*([0-9]+).* ([0-9,.]+) *kbit.*"); + + +FileInfo *MplayerInfo::createFileInfo(const QString &path) +{ + QRegExp rx_id_length("^ID_LENGTH=([0-9,.]+)*"); + QStringList args; + args << "-slave"; + args << "-identify"; + args << "-frames"; + args << "0"; + args << "-vo"; + args << "null"; + args << "-ao"; + args << "null"; + args << path; + QProcess mplayer_process; + mplayer_process.start("mplayer", args); + mplayer_process.waitForFinished(); + QString str = QString::fromLocal8Bit(mplayer_process.readAll()).trimmed(); + FileInfo *info = new FileInfo(path); + QStringList lines = str.split("\n"); + foreach(QString line, lines) + { + if (rx_id_length.indexIn(line) > -1) + info->setLength((qint64) rx_id_length.cap(1).toDouble()); + } +#ifdef MPLAYER_DEBUG + qDebug(qPrintable(str)); +#endif + return info; +} + +QStringList MplayerInfo::filters() +{ + QStringList filters; + filters << "*.avi" << "*.mpg" << "*.mpeg" << "*.divx" << "*.qt" << "*.mov" << "*.wmv" << "*.asf"; + return filters; +} + +DecoderMplayer::DecoderMplayer(QObject *parent, DecoderFactory *d, const QString &url) + : Decoder(parent, d) +{ + m_url = url; + m_bitrate = 0; + m_samplerate = 0; + m_channels = 0; + m_bitsPerSample = 0; + m_length = 0; + m_currentTime = 0; + m_process = new QProcess(this); +} + +DecoderMplayer::~DecoderMplayer() +{ + qDebug(__FUNCTION__); + m_process->close(); +} + +bool DecoderMplayer::initialize() +{ + FileInfo *info = MplayerInfo::createFileInfo(m_url); + m_length = info->length(); + delete info; + m_args.clear(); + m_args << "-slave"; + m_args << m_url; + connect(m_process, SIGNAL(readyReadStandardOutput()), SLOT(readStdOut())); + return TRUE; +} + +qint64 DecoderMplayer::lengthInSeconds() +{ + return m_length; +} + +void DecoderMplayer::seek(qint64 pos) +{ + if (m_process->state() == QProcess::Running) + m_process->write(QString("seek %1 \n").arg(pos - m_currentTime).toLocal8Bit ()); +} + +void DecoderMplayer::stop() +{ + if (m_process->state() == QProcess::Running) + { + m_process->write("quit\n"); + m_process->waitForFinished(200); + } + StateHandler::instance()->dispatch(Qmmp::Stopped); +} + +void DecoderMplayer::pause() +{ + m_process->write("pause\n"); +} + +void DecoderMplayer::setEQ(double bands[10], double preamp) +{ +} + +void DecoderMplayer::setEQEnabled(bool on) +{ +} + +void DecoderMplayer::run() +{ + QMetaObject::invokeMethod(this, "startMplayerProcess"); + StateHandler::instance()->dispatch(Qmmp::Playing); +} + +void DecoderMplayer::readStdOut() +{ + QString line = QString::fromLocal8Bit(m_process->readAll ()).trimmed(); + QStringList lines = line.split("\n"); + foreach(line, lines) + { + if (rx_av.indexIn(line) > -1) + { + StateHandler::instance()->dispatch(Qmmp::Playing); + m_currentTime = (qint64) rx_av.cap(1).toDouble(); + StateHandler::instance()->dispatch(m_currentTime, + m_length, + m_bitrate, + m_samplerate, + m_bitsPerSample, + m_channels); + } + else if (rx_pause.indexIn(line) > -1) + { + StateHandler::instance()->dispatch(Qmmp::Paused); + } + else if (rx_end.indexIn(line) > -1) + { + if (m_process->state() == QProcess::Running) + m_process->waitForFinished(500); + finish(); + } + else if (rx_quit.indexIn(line) > -1) + { + if (m_process->state() == QProcess::Running) + m_process->waitForFinished(500); + StateHandler::instance()->dispatch(Qmmp::Stopped); + } + else if (rx_audio.indexIn(line) > -1) + { + m_samplerate = rx_audio.cap(1).toInt(); + m_channels = rx_audio.cap(2).toInt(); + m_bitsPerSample = rx_audio.cap(3).toDouble(); + m_bitrate = rx_audio.cap(4).toDouble(); + } +#ifdef MPLAYER_DEBUG + else + qDebug(qPrintable(line)); +#endif + } +} + +void DecoderMplayer::startMplayerProcess() +{ + m_process->start ("mplayer", m_args); +} diff --git a/src/plugins/Input/mplayer/decoder_mplayer.h b/src/plugins/Input/mplayer/decoder_mplayer.h new file mode 100644 index 000000000..2a754239e --- /dev/null +++ b/src/plugins/Input/mplayer/decoder_mplayer.h @@ -0,0 +1,81 @@ +/*************************************************************************** + * Copyright (C) 2008 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., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ + +#ifndef DECODER_MPLAYER_H +#define DECODER_MPLAYER_H + +#include <qmmp/decoder.h> +#include <qmmp/statehandler.h> + +class Output; +class QIDevice; +class DecoderPhonon; +class QMenu; +class QProcess; + + +class MplayerInfo +{ +public: + static FileInfo *createFileInfo(const QString &path); + static QStringList filters(); +}; + + + +class DecoderMplayer : public Decoder +{ + Q_OBJECT +public: + DecoderMplayer(QObject *, DecoderFactory *, const QString &url); + virtual ~DecoderMplayer(); + + // Standard Decoder API + bool initialize(); + qint64 lengthInSeconds(); + void seek(qint64); + void stop(); + void pause(); + + // Equalizer + void setEQ(double bands[10], double preamp); + void setEQEnabled(bool on); + +private slots: + void readStdOut(); + void startMplayerProcess(); + +private: + // thread run function + void run(); + int mplayer_pipe[2]; + QString m_url; + QStringList m_args; + QProcess *m_process; + int m_bitrate; + int m_samplerate; + int m_channels; + int m_bitsPerSample; + qint64 m_currentTime; + qint64 m_length; +}; + + +#endif // DECODER_MPLAYER_H diff --git a/src/plugins/Input/mplayer/decodermplayerfactory.cpp b/src/plugins/Input/mplayer/decodermplayerfactory.cpp new file mode 100644 index 000000000..b274cdb07 --- /dev/null +++ b/src/plugins/Input/mplayer/decodermplayerfactory.cpp @@ -0,0 +1,103 @@ +/*************************************************************************** + * Copyright (C) 2008 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., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#include <QtGui> + +#include "decoder_mplayer.h" +#include "decodermplayerfactory.h" + + +// DecoderMplayerFactory + +bool DecoderMplayerFactory::supports(const QString &source) const +{ + QStringList filters = MplayerInfo::filters(); + foreach(QString filter, filters) + { + QRegExp regexp(filter, Qt::CaseInsensitive, QRegExp::Wildcard); + if (regexp.exactMatch(source)) + return TRUE; + } + return FALSE; +} + +bool DecoderMplayerFactory::canDecode(QIODevice *) const +{ + return FALSE; +} + +const DecoderProperties DecoderMplayerFactory::properties() const +{ + DecoderProperties properties; + properties.name = tr("Mplayer Plugin"); + properties.shortName = "mplayer"; + properties.filter = MplayerInfo::filters().join(" "); + properties.description = tr("Video Files"); + //properties.contentType = "application/ogg;audio/x-vorbis+ogg"; + properties.protocols = "file"; + properties.hasAbout = TRUE; + properties.hasSettings = FALSE; + properties.noInput = TRUE; + properties.noOutput = TRUE; + return properties; +} + +Decoder *DecoderMplayerFactory::create(QObject *parent, QIODevice *input, + Output *output, const QString &url) +{ + Q_UNUSED(input); + Q_UNUSED(output); + return new DecoderMplayer(parent, this, url); +} + +QList<FileInfo *> DecoderMplayerFactory::createPlayList(const QString &fileName, bool useMetaData) +{ + Q_UNUSED(useMetaData); + QList<FileInfo *> info; + info << MplayerInfo::createFileInfo(fileName); + return info; +} + +QObject* DecoderMplayerFactory::showDetails(QWidget *, const QString &) +{ + return 0; +} + +void DecoderMplayerFactory::showSettings(QWidget *) +{ + /*SettingsDialog *s = new SettingsDialog(parent); + s->show();*/ +} + +void DecoderMplayerFactory::showAbout(QWidget *parent) +{ + QMessageBox::about (parent, tr("About Mplayer Audio Plugin"), + tr("Qmmp Mplayer Audio Plugin")+"\n"+ + tr("Writen by: Ilya Kotov <forkotov02@hotmail.ru>")); +} + +QTranslator *DecoderMplayerFactory::createTranslator(QObject *parent) +{ + QTranslator *translator = new QTranslator(parent); + QString locale = QLocale::system().name(); + translator->load(QString(":/phonon_plugin_") + locale); + return translator; +} + +Q_EXPORT_PLUGIN(DecoderMplayerFactory) diff --git a/src/plugins/Input/mplayer/decodermplayerfactory.h b/src/plugins/Input/mplayer/decodermplayerfactory.h new file mode 100644 index 000000000..a752d5a43 --- /dev/null +++ b/src/plugins/Input/mplayer/decodermplayerfactory.h @@ -0,0 +1,50 @@ +/*************************************************************************** + * Copyright (C) 2006-2008 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., * + * 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. * + ***************************************************************************/ +#ifndef DECODERMPLAYERFACTORY_H +#define DECODERMPLAYERFACTORY_H + +#include <QObject> +#include <QString> +#include <QIODevice> +#include <QWidget> + +#include <qmmp/decoder.h> +#include <qmmp/output.h> +#include <qmmp/decoderfactory.h> +#include <qmmp/fileinfo.h> + +class DecoderMplayerFactory : public QObject, DecoderFactory +{ +Q_OBJECT +Q_INTERFACES(DecoderFactory); + +public: + bool supports(const QString &source) const; + bool canDecode(QIODevice *input) const; + const DecoderProperties properties() const; + Decoder *create(QObject *, QIODevice *, Output *, const QString &); + QList<FileInfo *> createPlayList(const QString &fileName, bool useMetaData); + QObject* showDetails(QWidget *parent, const QString &path); + void showSettings(QWidget *parent); + void showAbout(QWidget *parent); + QTranslator *createTranslator(QObject *parent); +}; + +#endif diff --git a/src/plugins/Input/mplayer/mplayer.pro b/src/plugins/Input/mplayer/mplayer.pro new file mode 100644 index 000000000..c3472ebd8 --- /dev/null +++ b/src/plugins/Input/mplayer/mplayer.pro @@ -0,0 +1,35 @@ +include(../../plugins.pri) + +HEADERS += decodermplayerfactory.h \ + decoder_mplayer.h + +SOURCES += decoder_mplayer.cpp \ + decodermplayerfactory.cpp + +TARGET =$$PLUGINS_PREFIX/Input/mplayer +QMAKE_CLEAN =$$PLUGINS_PREFIX/Input/libmplayer.so + +INCLUDEPATH += ../../../ +CONFIG += release \ +warn_on \ +plugin + +TEMPLATE = lib + +QMAKE_LIBDIR += ../../../../lib +LIBS += -lqmmp -L/usr/lib + +#TRANSLATIONS = translations/mplayer_plugin_ru.ts +# translations/mplayer_plugin_uk_UA.ts +# translations/mplayer_plugin_zh_CN.ts +# translations/mplayer_plugin_zh_TW.ts +# translations/mplayer_plugin_cs.ts +# translations/mplayer_plugin_de.ts +#RESOURCES = translations/translations.qrc + +isEmpty(LIB_DIR){ + LIB_DIR = /lib +} +target.path = $$LIB_DIR/qmmp/Input +INSTALLS += target + |
