From ecd95ef11c94e7442728df4fc7307b387769d7eb Mon Sep 17 00:00:00 2001 From: trialuser02 Date: Wed, 11 Nov 2015 05:24:51 +0000 Subject: adding support of Qt Multimedia output (patch by Ivan Ponomarev) git-svn-id: http://svn.code.sf.net/p/qmmp-dev/code/trunk/qmmp@5741 90c681e8-e032-0410-971d-27865f9a5e38 --- src/plugins/Output/qtmultimedia/CMakeLists.txt | 56 +++++++++ .../Output/qtmultimedia/outputqtmultimedia.cpp | 136 +++++++++++++++++++++ .../Output/qtmultimedia/outputqtmultimedia.h | 53 ++++++++ .../qtmultimedia/outputqtmultimediafactory.cpp | 70 +++++++++++ .../qtmultimedia/outputqtmultimediafactory.h | 47 +++++++ src/plugins/Output/qtmultimedia/qtmultimedia.pro | 42 +++++++ src/plugins/Output/qtmultimedia/settingsdialog.cpp | 62 ++++++++++ src/plugins/Output/qtmultimedia/settingsdialog.h | 41 +++++++ src/plugins/Output/qtmultimedia/settingsdialog.ui | 87 +++++++++++++ .../translations/qtmultimedia_plugin_en.ts | 45 +++++++ .../translations/qtmultimedia_plugin_ru.ts | 45 +++++++ .../qtmultimedia/translations/translations.qrc | 6 + 12 files changed, 690 insertions(+) create mode 100644 src/plugins/Output/qtmultimedia/CMakeLists.txt create mode 100644 src/plugins/Output/qtmultimedia/outputqtmultimedia.cpp create mode 100644 src/plugins/Output/qtmultimedia/outputqtmultimedia.h create mode 100644 src/plugins/Output/qtmultimedia/outputqtmultimediafactory.cpp create mode 100644 src/plugins/Output/qtmultimedia/outputqtmultimediafactory.h create mode 100644 src/plugins/Output/qtmultimedia/qtmultimedia.pro create mode 100644 src/plugins/Output/qtmultimedia/settingsdialog.cpp create mode 100644 src/plugins/Output/qtmultimedia/settingsdialog.h create mode 100644 src/plugins/Output/qtmultimedia/settingsdialog.ui create mode 100644 src/plugins/Output/qtmultimedia/translations/qtmultimedia_plugin_en.ts create mode 100644 src/plugins/Output/qtmultimedia/translations/qtmultimedia_plugin_ru.ts create mode 100644 src/plugins/Output/qtmultimedia/translations/translations.qrc (limited to 'src/plugins/Output/qtmultimedia') diff --git a/src/plugins/Output/qtmultimedia/CMakeLists.txt b/src/plugins/Output/qtmultimedia/CMakeLists.txt new file mode 100644 index 000000000..686739002 --- /dev/null +++ b/src/plugins/Output/qtmultimedia/CMakeLists.txt @@ -0,0 +1,56 @@ +project(libqtmultimedia) + +cmake_minimum_required(VERSION 2.4.7) + +if(COMMAND cmake_policy) +cmake_policy(SET CMP0003 NEW) +endif(COMMAND cmake_policy) + +# qt plugin +ADD_DEFINITIONS( -Wall ) +ADD_DEFINITIONS(${QT_DEFINITIONS}) +ADD_DEFINITIONS(-DQT_PLUGIN) +ADD_DEFINITIONS(-DQT_NO_DEBUG) +ADD_DEFINITIONS(-DQT_SHARED) +ADD_DEFINITIONS(-DQT_THREAD) + +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +SET(QT_INCLUDES + ${QT_INCLUDES} + ${CMAKE_CURRENT_SOURCE_DIR}/../../../ +) + +# libqmmp +include_directories(${CMAKE_CURRENT_SOURCE_DIR}/../../../) +link_directories(${CMAKE_CURRENT_BINARY_DIR}/../../../qmmp) + +SET(libqtmultimedia_SRCS + outputqtmultimedia.cpp + outputqtmultimediafactory.cpp + settingsdialog.cpp +) + +SET(libqtmultimedia_HDRS + outputqtmultimedia.h +) + +SET(libqtmultimedia_RCCS translations/translations.qrc) + +QT4_ADD_RESOURCES(libqtmultimedia_RCC_SRCS ${libqtmultimedia_RCCS}) + +SET(libqtmultimedia_UIS + settingsdialog.ui +) +QT4_WRAP_UI(libqtmultimedia_UIS_H ${libqtmultimedia_UIS}) + +# Don't forget to include output directory, otherwise +# the UI file won't be wrapped! +include_directories(${CMAKE_CURRENT_BINARY_DIR}) + +IF(${QT_QTMULTIMEDIA_FOUND}) + ADD_LIBRARY(qtmultimedia MODULE ${libqtmultimedia_SRCS} ${libqtmultimedia_UIS_H} ${libqtmultimedia_RCC_SRCS} ${libqtmultimedia_HDRS}) + add_dependencies(qtmultimedia qmmp) + target_link_libraries(qtmultimedia ${QT_LIBRARIES} -lqmmp) + install(TARGETS qtmultimedia DESTINATION ${LIB_DIR}/qmmp/Output) +ENDIF(${QT_QTMULTIMEDIA_FOUND}) \ No newline at end of file diff --git a/src/plugins/Output/qtmultimedia/outputqtmultimedia.cpp b/src/plugins/Output/qtmultimedia/outputqtmultimedia.cpp new file mode 100644 index 000000000..142292bdd --- /dev/null +++ b/src/plugins/Output/qtmultimedia/outputqtmultimedia.cpp @@ -0,0 +1,136 @@ +/*************************************************************************** + * Copyright (C) 2015 by Ivan Ponomarev * + * ivantrue@gmail.com * + * * + * 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 "outputqtmultimedia.h" + +#include +#include +#include +#include +#include +#include + + +OutputQtMultimedia::OutputQtMultimedia() : Output(), m_buffer(NULL) +{ +} + +OutputQtMultimedia::~OutputQtMultimedia() +{ +} + +bool OutputQtMultimedia::initialize(quint32 freq, ChannelMap map, Qmmp::AudioFormat format) +{ + QAudioFormat qformat; + qformat.setCodec("audio/pcm"); + qformat.setFrequency(freq); + qformat.setByteOrder(QAudioFormat::LittleEndian); + qformat.setChannels(map.size()); + qformat.setSampleType(QAudioFormat::SignedInt); + switch (format) + { + case Qmmp::PCM_S8: + qformat.setSampleSize(8); + break; + case Qmmp::PCM_S16LE: + qformat.setSampleSize(16); + break; + case Qmmp::PCM_S24LE: + qformat.setSampleSize(24); + break; + case Qmmp::PCM_S32LE: + qformat.setSampleSize(32); + break; + default: + break; + } + + if (!qformat.isValid()) + return false; + + const QSettings settings(Qmmp::configFile(), QSettings::IniFormat); + const QString saved_device_name = settings.value("QTMULTIMEDIA/device").toString(); + + QAudioDeviceInfo device_info; + if (!saved_device_name.isEmpty()) + { + const QList devices = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput); + foreach (const QAudioDeviceInfo &info, devices) + { + if (info.deviceName()==saved_device_name) + { + if (info.isFormatSupported(qformat)) + { + device_info = info; + break; + } + else + qDebug() << "OutputQtMultimedia: Output device: " << saved_device_name << " is not supported"; + } + } + } + + if (device_info.isNull()) + { + device_info = QAudioDeviceInfo::defaultOutputDevice(); + if (!device_info.isFormatSupported(qformat)) + return false; + } + + qDebug() << "OutputQtMultimedia: Using output device: " << device_info.deviceName(); + + m_output.reset(new QAudioOutput(device_info, qformat)); + m_buffer = m_output->start(); + + configure(freq, map, format); + return true; +} + + +qint64 OutputQtMultimedia::latency() +{ + return 0; +} + +qint64 OutputQtMultimedia::writeAudio(unsigned char *data, qint64 maxSize) +{ + return m_buffer->write((const char*)data, maxSize); +} + +void OutputQtMultimedia::drain() +{ + m_buffer->waitForBytesWritten(-1); +} + +void OutputQtMultimedia::reset() +{ + m_buffer->reset(); + m_buffer = m_output->start(); +} + +void OutputQtMultimedia::suspend() +{ + m_output->suspend(); +} + +void OutputQtMultimedia::resume() +{ + m_output->resume(); +} diff --git a/src/plugins/Output/qtmultimedia/outputqtmultimedia.h b/src/plugins/Output/qtmultimedia/outputqtmultimedia.h new file mode 100644 index 000000000..ab60ce290 --- /dev/null +++ b/src/plugins/Output/qtmultimedia/outputqtmultimedia.h @@ -0,0 +1,53 @@ +/*************************************************************************** + * Copyright (C) 2015 by Ivan Ponomarev * + * ivantrue@gmail.com * + * * + * 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 OUTPUTQTMULTIMEDIA_H +#define OUTPUTQTMULTIMEDIA_H + +#include +#include + +/** + @author Ivan Ponomarev ivantrue@gmail.com +*/ +class QAudioOutput; +class QIODevice; + +class OutputQtMultimedia : public Output +{ +public: + OutputQtMultimedia(); + ~OutputQtMultimedia(); + + virtual bool initialize(quint32, ChannelMap map, Qmmp::AudioFormat format); + virtual qint64 latency(); + virtual qint64 writeAudio(unsigned char *data, qint64 maxSize); + virtual void drain(); + virtual void reset(); + virtual void suspend(); + virtual void resume(); + +private: + QScopedPointer m_output; + QIODevice *m_buffer; +}; + + +#endif // OUTPUTQTMULTIMEDIA_H diff --git a/src/plugins/Output/qtmultimedia/outputqtmultimediafactory.cpp b/src/plugins/Output/qtmultimedia/outputqtmultimediafactory.cpp new file mode 100644 index 000000000..93a698391 --- /dev/null +++ b/src/plugins/Output/qtmultimedia/outputqtmultimediafactory.cpp @@ -0,0 +1,70 @@ +/*************************************************************************** + * Copyright (C) 2015 by Ivan Ponomarev * + * ivantrue@gmail.com * + * * + * 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 "outputqtmultimediafactory.h" +#include "settingsdialog.h" + +#include +#include +#include "outputqtmultimedia.h" + + +const OutputProperties OutputQtMultimediaFactory::properties() const +{ + OutputProperties properties; + properties.name = tr("Qt Multimedia Plugin"); + properties.hasAbout = true; + properties.hasSettings = true; + properties.shortName = "qtmultimedia"; + return properties; +} + +Output* OutputQtMultimediaFactory::create() +{ + return new OutputQtMultimedia(); +} + +Volume *OutputQtMultimediaFactory::createVolume() +{ + return 0; +} + +void OutputQtMultimediaFactory::showSettings(QWidget* parent) +{ + SettingsDialog *s = new SettingsDialog(parent); + s->show(); +} + +void OutputQtMultimediaFactory::showAbout(QWidget *parent) +{ + QMessageBox::about (parent, tr("About Qt Multimedia Output Plugin"), + tr("Qmmp Qt Multimedia Output Plugin")+"\n"+ + tr("Written by: Ivan Ponomarev ")); +} + +QTranslator *OutputQtMultimediaFactory::createTranslator(QObject *parent) +{ + QTranslator *translator = new QTranslator(parent); + QString locale = Qmmp::systemLanguageID(); + translator->load(QString(":/qtmultimedia_plugin_") + locale); + return translator; +} + +Q_EXPORT_PLUGIN2(qtmultimedia, OutputQtMultimediaFactory) diff --git a/src/plugins/Output/qtmultimedia/outputqtmultimediafactory.h b/src/plugins/Output/qtmultimedia/outputqtmultimediafactory.h new file mode 100644 index 000000000..d8ccbf97c --- /dev/null +++ b/src/plugins/Output/qtmultimedia/outputqtmultimediafactory.h @@ -0,0 +1,47 @@ +/*************************************************************************** + * Copyright (C) 2015 by Ivan Ponomarev * + * ivantrue@gmail.com * + * * + * 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 OUTPUTQTMULTIMEDIAFACTORY_H +#define OUTPUTQTMULTIMEDIAFACTORY_H + + +#include +#include +#include +#include + +#include +#include + + +class OutputQtMultimediaFactory : public QObject, OutputFactory +{ +Q_OBJECT +Q_INTERFACES(OutputFactory) + +public: + virtual const OutputProperties properties() const; + virtual Output* create(); + virtual Volume *createVolume(); + virtual void showSettings(QWidget* parent); + virtual void showAbout(QWidget *parent); + virtual QTranslator *createTranslator(QObject *parent); +}; + +#endif diff --git a/src/plugins/Output/qtmultimedia/qtmultimedia.pro b/src/plugins/Output/qtmultimedia/qtmultimedia.pro new file mode 100644 index 000000000..f9e92d75d --- /dev/null +++ b/src/plugins/Output/qtmultimedia/qtmultimedia.pro @@ -0,0 +1,42 @@ +include(../../plugins.pri) + +QT += multimedia + +FORMS += settingsdialog.ui + +HEADERS += outputqtmultimediafactory.h \ + outputqtmultimedia.h \ + settingsdialog.h + +SOURCES += outputqtmultimediafactory.cpp \ + outputqtmultimedia.cpp \ + settingsdialog.cpp + +TARGET=$$PLUGINS_PREFIX/Output/qtmultimedia + +INCLUDEPATH += ../../../ +QMAKE_LIBDIR += ../../../../lib + +CONFIG += warn_on \ +thread \ +plugin + +TEMPLATE = lib + +RESOURCES = translations/translations.qrc + +unix { + isEmpty (LIB_DIR){ + LIB_DIR = /lib + } + + target.path = $$LIB_DIR/qmmp/Output + INSTALLS += target + LIBS += -lqmmp + QMAKE_CLEAN =$$PLUGINS_PREFIX/Output/libqtmultimedia.so +} + +win32 { + LIBS += -lqmmp0 + QMAKE_LIBDIR += ../../../../bin +} diff --git a/src/plugins/Output/qtmultimedia/settingsdialog.cpp b/src/plugins/Output/qtmultimedia/settingsdialog.cpp new file mode 100644 index 000000000..7b4fd0600 --- /dev/null +++ b/src/plugins/Output/qtmultimedia/settingsdialog.cpp @@ -0,0 +1,62 @@ +/*************************************************************************** + * Copyright (C) 2015 by Ivan Ponomarev * + * ivantrue@gmail.com * + * * + * 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 +#include +#include +#include + +#include "settingsdialog.h" + +SettingsDialog::SettingsDialog (QWidget *parent) : QDialog (parent) +{ + ui.setupUi(this); + setAttribute(Qt::WA_DeleteOnClose); + + const QSettings settings(Qmmp::configFile(), QSettings::IniFormat); + const QString default_device = settings.value("QTMULTIMEDIA/device").toString(); + + //Default item always has index = 0 + ui.deviceComboBox->addItem(tr("Default")); + ui.deviceComboBox->setCurrentIndex(0); + + const QList devices = QAudioDeviceInfo::availableDevices(QAudio::AudioOutput); + int index = 1; + foreach (const QAudioDeviceInfo &info, devices) + { + const QString device_name = info.deviceName(); + ui.deviceComboBox->addItem(device_name); + if (device_name==default_device) + ui.deviceComboBox->setCurrentIndex(index); + ++index; + } +} + +SettingsDialog::~SettingsDialog() +{ +} + +void SettingsDialog::accept() +{ + qDebug("%s", Q_FUNC_INFO); + QSettings settings(Qmmp::configFile(), QSettings::IniFormat); + //0 index means default value, we save empty string for it. + settings.setValue("QTMULTIMEDIA/device", ui.deviceComboBox->currentIndex() ? ui.deviceComboBox->currentText() : QString()); + QDialog::accept(); +} diff --git a/src/plugins/Output/qtmultimedia/settingsdialog.h b/src/plugins/Output/qtmultimedia/settingsdialog.h new file mode 100644 index 000000000..19fc13386 --- /dev/null +++ b/src/plugins/Output/qtmultimedia/settingsdialog.h @@ -0,0 +1,41 @@ +/*************************************************************************** + * Copyright (C) 2015 by Ivan Ponomarev * + * ivantrue@gmail.com * + * * + * 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 SETTINGSDIALOG_H +#define SETTINGSDIALOG_H + +#include +#include "ui_settingsdialog.h" + +/** + @author Ivan Ponomarev +*/ +class SettingsDialog : public QDialog +{ +Q_OBJECT +public: + SettingsDialog(QWidget *parent); + ~SettingsDialog(); + +private: + virtual void accept(); + Ui::SettingsDialog ui; +}; + +#endif diff --git a/src/plugins/Output/qtmultimedia/settingsdialog.ui b/src/plugins/Output/qtmultimedia/settingsdialog.ui new file mode 100644 index 000000000..582b86511 --- /dev/null +++ b/src/plugins/Output/qtmultimedia/settingsdialog.ui @@ -0,0 +1,87 @@ + + + SettingsDialog + + + + 0 + 0 + 276 + 86 + + + + Qt Multimedia Plugin Settings + + + + + + + 0 + 0 + + + + false + + + + + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + + + + + 0 + 0 + + + + Device: + + + + + + + + + buttonBox + accepted() + SettingsDialog + accept() + + + 179 + 51 + + + 274 + 2 + + + + + buttonBox + rejected() + SettingsDialog + reject() + + + 231 + 46 + + + 271 + 44 + + + + + diff --git a/src/plugins/Output/qtmultimedia/translations/qtmultimedia_plugin_en.ts b/src/plugins/Output/qtmultimedia/translations/qtmultimedia_plugin_en.ts new file mode 100644 index 000000000..728e9cfb1 --- /dev/null +++ b/src/plugins/Output/qtmultimedia/translations/qtmultimedia_plugin_en.ts @@ -0,0 +1,45 @@ + + + + + OutputQtMultimediaFactory + + + Qt Multimedia Plugin + + + + + About Qt Multimedia Output Plugin + + + + + Qmmp Qt Multimedia Output Plugin + + + + + Written by: Ivan Ponomarev <ivantrue@gmail.com> + + + + + SettingsDialog + + + Qt Multimedia Plugin Settings + + + + + Device: + + + + + Default + + + + diff --git a/src/plugins/Output/qtmultimedia/translations/qtmultimedia_plugin_ru.ts b/src/plugins/Output/qtmultimedia/translations/qtmultimedia_plugin_ru.ts new file mode 100644 index 000000000..bbee87585 --- /dev/null +++ b/src/plugins/Output/qtmultimedia/translations/qtmultimedia_plugin_ru.ts @@ -0,0 +1,45 @@ + + + + + OutputQtMultimediaFactory + + + Qt Multimedia Plugin + Модуль Qt Multimedia + + + + About Qt Multimedia Output Plugin + О модуле вывода Qt Multimedia + + + + Qmmp Qt Multimedia Output Plugin + Модуль вывода Qt Multimedia для Qmmp + + + + Written by: Ivan Ponomarev <ivantrue@gmail.com> + Разработчик: Иван Пономарев <ivantrue@gmail.com> + + + + SettingsDialog + + + Qt Multimedia Plugin Settings + Настройки модуля Qt Multimedia + + + + Device: + Устройство: + + + + Default + По умолчанию + + + diff --git a/src/plugins/Output/qtmultimedia/translations/translations.qrc b/src/plugins/Output/qtmultimedia/translations/translations.qrc new file mode 100644 index 000000000..f6d2dbb40 --- /dev/null +++ b/src/plugins/Output/qtmultimedia/translations/translations.qrc @@ -0,0 +1,6 @@ + + + qtmultimedia_plugin_en.qm + qtmultimedia_plugin_ru.qm + + -- cgit v1.2.3-13-gbd6f