Commit bb4325db authored by Andreas Cord-Landwehr's avatar Andreas Cord-Landwehr
Browse files

Change sound backends to plugin infrastructure.

parent 4e55c74b
......@@ -33,12 +33,11 @@ include_directories(
)
set(sound_LIB_SRCS
backendinterface.cpp
capturedevicecontroller.cpp
outputdevicecontroller.cpp
capturebackendinterface.cpp
outputbackendinterface.cpp
qtgstreamercapturebackend.cpp
qtgstreameroutputbackend.cpp
libsound_debug.cpp
)
......@@ -48,9 +47,7 @@ generate_export_header(artikulatesound BASE_NAME libsound)
target_link_libraries(
artikulatesound
LINK_PUBLIC
${QTGLIB_LIBRARIES}
${QTGLIB_LIBRARY}
${QTGSTREAMER_LIBRARIES}
KF5::CoreAddons
KF5::I18n
)
# internal library without any API or ABI guarantee
......@@ -67,3 +64,4 @@ install(
${INSTALL_TARGETS_DEFAULT_ARGS}
)
ecm_optional_add_subdirectory(qtgstreamerbackend)
/*
* Copyright 2016 Andreas Cord-Landwehr <cordlandwehr@kde.org>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "backendinterface.h"
BackendInterface::BackendInterface(const QString &name, QObject *parent)
: QObject(parent)
, m_name(name)
{
}
BackendInterface::~BackendInterface()
{
}
QString BackendInterface::name() const
{
return m_name;
}
/*
* Copyright 2016 Andreas Cord-Landwehr <cordlandwehr@kde.org>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef BACKENDINTERFACE_H
#define BACKENDINTERFACE_H
#include "libsound_export.h"
#include <QObject>
#include <QString>
class CaptureBackendInterface;
class OutputBackendInterface;
class LIBSOUND_EXPORT BackendInterface : public QObject
{
Q_OBJECT
public:
explicit BackendInterface(const QString &name, QObject *parent = nullptr);
virtual ~BackendInterface();
QString name() const;
virtual CaptureBackendInterface * captureBackend() const = 0;
virtual OutputBackendInterface * outputBackend() const = 0;
private:
const QString m_name;
};
#endif
......@@ -17,11 +17,17 @@
#include "capturedevicecontroller.h"
#include "capturebackendinterface.h"
#include "qtgstreamercapturebackend.h"
#include <QUrl>
#include <QStringList>
#include "backendinterface.h"
#include "libsound_debug.h"
#include <QCoreApplication>
#include <QPluginLoader>
#include <QStringList>
#include <KPluginLoader>
#include <KPluginFactory>
#include <KPluginMetaData>
/**
* \class CaptureDeviceControllerPrivate
* \internal
......@@ -38,6 +44,36 @@ public:
: m_parent(parent)
, m_initialized(false)
{
QStringList dirsToCheck;
foreach (const QString &directory, QCoreApplication::libraryPaths()) {
dirsToCheck << directory + "/artikulate/libsound";
}
// load plugins
QPluginLoader loader;
foreach (const QString &dir, dirsToCheck) {
QVector<KPluginMetaData> metadataList = KPluginLoader::findPlugins(dir,
[=](const KPluginMetaData &data)
{
return data.serviceTypes().contains("artikulate/libsound/backend");
});
foreach (const auto &metadata, metadataList) {
loader.setFileName(metadata.fileName());
qCDebug(LIBSOUND_LOG) << "Load Plugin: " << metadata.name();
if (!loader.load()) {
qCCritical(LIBSOUND_LOG) << "Error while loading plugin: " << metadata.name();
}
KPluginFactory *factory = KPluginLoader(loader.fileName()).factory();
BackendInterface *plugin = factory->create<BackendInterface>(parent, QList< QVariant >());
if (plugin->captureBackend()) {
qDebug() << "YYY";
m_backendList.append(plugin->captureBackend());
}
}
}
if (!m_backend && !m_backendList.isEmpty()) {
m_backend = m_backendList.first();
}
}
~CaptureDeviceControllerPrivate()
......@@ -51,7 +87,7 @@ public:
if (m_initialized) {
return;
}
m_backend = new QtGStreamerCaptureBackend();
//TODO currently nothing to do
m_initialized = true;
}
......@@ -63,6 +99,7 @@ public:
QObject *m_parent;
CaptureBackendInterface *m_backend;
QList<CaptureBackendInterface *> m_backendList;
bool m_initialized;
};
......
......@@ -17,8 +17,16 @@
#include "outputdevicecontroller.h"
#include "outputbackendinterface.h"
#include "qtgstreameroutputbackend.h"
#include "backendinterface.h"
#include <QCoreApplication>
#include <QPluginLoader>
#include <QUrl>
#include <KPluginLoader>
#include <KPluginFactory>
#include <KPluginMetaData>
#include "libsound_debug.h"
/**
......@@ -38,7 +46,35 @@ public:
, m_backend(nullptr)
, m_initialized(false)
{
m_backend = new QtGStreamerOutputBackend();
QStringList dirsToCheck;
foreach (const QString &directory, QCoreApplication::libraryPaths()) {
dirsToCheck << directory + "/artikulate/libsound";
}
// load plugins
QPluginLoader loader;
foreach (const QString &dir, dirsToCheck) {
QVector<KPluginMetaData> metadataList = KPluginLoader::findPlugins(dir,
[=](const KPluginMetaData &data)
{
return data.serviceTypes().contains("artikulate/libsound/backend");
});
foreach (const auto &metadata, metadataList) {
loader.setFileName(metadata.fileName());
qCDebug(LIBSOUND_LOG) << "Load Plugin: " << metadata.name();
if (!loader.load()) {
qCCritical(LIBSOUND_LOG) << "Error while loading plugin: " << metadata.name();
}
KPluginFactory *factory = KPluginLoader(loader.fileName()).factory();
BackendInterface *plugin = factory->create<BackendInterface>(parent, QList< QVariant >());
if (plugin->outputBackend()) {
m_backendList.append(plugin->outputBackend());
}
}
}
if (!m_backend && !m_backendList.isEmpty()) {
m_backend = m_backendList.first();
}
}
~OutputDeviceControllerPrivate()
......@@ -51,7 +87,6 @@ public:
if (m_initialized) {
return;
}
m_backend = new QtGStreamerOutputBackend();
m_parent->connect(m_backend, &OutputBackendInterface::stateChanged,
m_parent, &OutputDeviceController::emitChangedState);
m_volume = m_backend->volume();
......@@ -66,6 +101,7 @@ public:
OutputDeviceController *m_parent;
OutputBackendInterface *m_backend;
QList<OutputBackendInterface *> m_backendList;
int m_volume; // volume as cubic value
bool m_initialized;
};
......
###
# Copyright 2016 Andreas Cord-Landwehr <cordlandwehr@kde.org>
#
# Redistribution and use in source and binary forms, with or without
# modification, are permitted provided that the following conditions
# are met:
#
# 1. Redistributions of source code must retain the above copyright
# notice, this list of conditions and the following disclaimer.
# 2. Redistributions in binary form must reproduce the above copyright
# notice, this list of conditions and the following disclaimer in the
# documentation and/or other materials provided with the distribution.
#
# THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
# IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
# OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
# IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
# INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
# NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
# DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
# THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
# THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
###
set(qtgstreamerbackend_SRCS
qtgstreamerbackend.cpp
qtgstreamercapturebackend.cpp
qtgstreameroutputbackend.cpp
../libsound_debug.cpp
)
add_library(qtgstreamercapturebackend MODULE ${qtgstreamerbackend_SRCS})
target_link_libraries(
qtgstreamercapturebackend
LINK_PUBLIC
artikulatesound
KF5::CoreAddons
${QTGLIB_LIBRARIES}
${QTGLIB_LIBRARY}
${QTGSTREAMER_LIBRARIES}
)
install(TARGETS qtgstreamercapturebackend DESTINATION ${PLUGIN_INSTALL_DIR}/artikulate/libsound)
/*
* Copyright 2016 Andreas Cord-Landwehr <cordlandwehr@kde.org>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#include "qtgstreamerbackend.h"
#include "qtgstreamercapturebackend.h"
#include "qtgstreameroutputbackend.h"
#include "libsound_export.h"
#include <KPluginFactory>
K_PLUGIN_FACTORY_WITH_JSON( BackendFactory,
"qtgstreamerbackend.json",
registerPlugin<QtGStreamerBackend>();)
QtGStreamerBackend::QtGStreamerBackend(QObject *parent, const QList< QVariant >&)
: BackendInterface("qtgstreamer", parent)
, m_captureBackend(nullptr)
, m_outputBackend(nullptr)
{
}
QtGStreamerBackend::~QtGStreamerBackend()
{
if (m_captureBackend) {
m_captureBackend->deleteLater();
m_captureBackend = nullptr;
}
if (m_outputBackend) {
m_outputBackend->deleteLater();
m_outputBackend = nullptr;
}
}
CaptureBackendInterface * QtGStreamerBackend::captureBackend() const
{
if (!m_captureBackend) {
m_captureBackend = new QtGStreamerCaptureBackend();
}
return m_captureBackend;
}
OutputBackendInterface * QtGStreamerBackend::outputBackend() const
{
if (!m_outputBackend) {
m_outputBackend = new QtGStreamerOutputBackend();
}
return m_outputBackend;
}
#include "qtgstreamerbackend.moc"
/*
* Copyright 2016 Andreas Cord-Landwehr <cordlandwehr@kde.org>
*
* This library is free software; you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as published
* by the Free Software Foundation; either version 2.1 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef GSTREAMERBACKEND_H
#define GSTREAMERBACKEND_H
#include "../backendinterface.h"
#include "libsound_export.h"
class CaptureBackendInterface;
class OutputBackendInterface;
class QtGStreamerCaptureBackend;
class QtGStreamerOutputBackend;
class LIBSOUND_EXPORT QtGStreamerBackend : public BackendInterface
{
Q_OBJECT
public:
explicit QtGStreamerBackend(QObject *parent, const QList< QVariant >&);
virtual ~QtGStreamerBackend();
CaptureBackendInterface * captureBackend() const;
OutputBackendInterface * outputBackend() const;
private:
mutable QtGStreamerCaptureBackend *m_captureBackend;
mutable QtGStreamerOutputBackend *m_outputBackend;
};
#endif
{
"Encoding": "UTF-8",
"KPlugin": {
"Category": "Plugins",
"Description": "Sound backend for GStreamer.",
"Id": "artikulate_gstreamer_backend",
"License": "GPL",
"Name": "GStreamer Backend",
"ServiceTypes": [
"artikulate/libsound/backend"
],
"Version": "0.1"
}
}
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment