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

Add QtMultimedia backend plugin.

Note that QtMultimedia must be build with gstreamer=1.0, since otherwise
the GStreamer and the QtMultimedia plugin clash because of different
gstreamer API use.
parent 3f49faea
......@@ -24,6 +24,7 @@
###
find_package(Qt5GStreamer 1.2.0 REQUIRED)
find_package(Qt5Multimedia REQUIRED)
# enable exceptions for this library
kde_enable_exceptions()
......@@ -65,3 +66,4 @@ install(
)
ecm_optional_add_subdirectory(qtgstreamerbackend)
ecm_optional_add_subdirectory(qtmultimediabackend)
###
# 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(qtmultimediabackend_SRCS
qtmultimediabackend.cpp
qtmultimediacapturebackend.cpp
qtmultimediaoutputbackend.cpp
../libsound_debug.cpp
)
add_library(qtmultimediabackend MODULE ${qtmultimediabackend_SRCS})
target_link_libraries(
qtmultimediabackend
LINK_PUBLIC
artikulatesound
Qt5::Multimedia
KF5::CoreAddons
)
install(TARGETS qtmultimediabackend 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 "qtmultimediabackend.h"
#include "qtmultimediacapturebackend.h"
#include "qtmultimediaoutputbackend.h"
#include "libsound_export.h"
#include <KPluginFactory>
K_PLUGIN_FACTORY_WITH_JSON( BackendFactory,
"qtmultimediabackend.json",
registerPlugin<QtMultimediaBackend>();)
QtMultimediaBackend::QtMultimediaBackend(QObject *parent, const QList< QVariant >&)
: BackendInterface("qtmultimedia", parent)
, m_captureBackend(nullptr)
, m_outputBackend(nullptr)
{
}
QtMultimediaBackend::~QtMultimediaBackend()
{
if (m_captureBackend) {
m_captureBackend->deleteLater();//TODO
m_captureBackend = nullptr;
}
if (m_outputBackend) {
m_outputBackend->deleteLater();
m_outputBackend = nullptr;
}
}
CaptureBackendInterface * QtMultimediaBackend::captureBackend() const
{
if (!m_captureBackend) {
m_captureBackend = new QtMultimediaCaptureBackend();
}
return m_captureBackend;
}
OutputBackendInterface * QtMultimediaBackend::outputBackend() const
{
if (!m_outputBackend) {
m_outputBackend = new QtMultimediaOutputBackend();
}
return m_outputBackend;
}
#include "qtmultimediabackend.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 QTMULTIMEDIABACKEND_H
#define QTMULTIMEDIABACKEND_H
#include "../backendinterface.h"
#include "libsound_export.h"
class CaptureBackendInterface;
class OutputBackendInterface;
class QtMultimediaCaptureBackend;
class QtMultimediaOutputBackend;
class LIBSOUND_EXPORT QtMultimediaBackend : public BackendInterface
{
Q_OBJECT
public:
explicit QtMultimediaBackend(QObject *parent, const QList< QVariant >&);
virtual ~QtMultimediaBackend();
CaptureBackendInterface * captureBackend() const;
OutputBackendInterface * outputBackend() const;
private:
mutable QtMultimediaCaptureBackend *m_captureBackend;
mutable QtMultimediaOutputBackend *m_outputBackend;
};
#endif
{
"Encoding": "UTF-8",
"KPlugin": {
"Category": "Plugins",
"Description": "Sound backend for QtMultimedia.",
"Id": "artikulate_qtmultimedia_backend",
"License": "GPL",
"Name": "QtMultimedia Backend",
"ServiceTypes": [
"artikulate/libsound/backend"
],
"Version": "0.1"
}
}
/*
* 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 "qtmultimediacapturebackend.h"
#include "libsound_debug.h"
#include <QAudioRecorder>
#include <QUrl>
#include <KLocalizedString>
QtMultimediaCaptureBackend::QtMultimediaCaptureBackend()
: m_recorder(new QAudioRecorder)
{
QString selectedInput = m_recorder->defaultAudioInput();
QAudioEncoderSettings audioSettings;
audioSettings.setCodec("audio/vorbis");
audioSettings.setQuality(QMultimedia::HighQuality);
m_recorder->setAudioSettings(audioSettings);
}
QtMultimediaCaptureBackend::~QtMultimediaCaptureBackend()
{
m_recorder->deleteLater();
m_recorder = nullptr;
}
CaptureDeviceController::State QtMultimediaCaptureBackend::captureState() const
{
switch (m_recorder->state()) {
case QMediaRecorder::StoppedState:
return CaptureDeviceController::StoppedState;
break;
case QMediaRecorder::RecordingState:
return CaptureDeviceController::RecordingState;
break;
case QMediaRecorder::PausedState:
return CaptureDeviceController::PausedState;
break;
default:
return CaptureDeviceController::StoppedState;
}
}
void QtMultimediaCaptureBackend::startCapture(const QString &filePath)
{
m_recorder->setOutputLocation(QUrl::fromLocalFile(filePath));
m_recorder->record();
}
void QtMultimediaCaptureBackend::stopCapture()
{
m_recorder->stop();
}
QStringList QtMultimediaCaptureBackend::devices() const
{
return m_recorder->audioInputs();
}
void QtMultimediaCaptureBackend::setDevice(const QString &deviceIdentifier)
{
if (devices().contains(deviceIdentifier)) {
m_recorder->setAudioInput(deviceIdentifier);
} else {
qCDebug(LIBSOUND_LOG) << "Could not set unknown capture device:" << deviceIdentifier;
}
}
/*
* 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 QTMULTIMEDIACAPTUREBACKEND_H
#define QTMULTIMEDIACAPTUREBACKEND_H
#include "capturedevicecontroller.h"
#include "capturebackendinterface.h"
#include <QMap>
#include <QString>
class QAudioRecorder;
class QMediaRecorder;
class QMediaObject;
class QtMultimediaCaptureBackend : public CaptureBackendInterface
{
Q_OBJECT
public:
QtMultimediaCaptureBackend();
virtual ~QtMultimediaCaptureBackend();
void startCapture(const QString &filePath);
void stopCapture();
CaptureDeviceController::State captureState() const;
QStringList devices() const;
void setDevice(const QString &deviceIdentifier);
private:
QAudioRecorder *m_recorder;
QString m_device;
};
#endif
/*
* 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 "qtmultimediaoutputbackend.h"
#include <QDir>
#include <QUrl>
#include <QMediaPlayer>
QtMultimediaOutputBackend::QtMultimediaOutputBackend()
: m_player(new QMediaPlayer)
{
connect(m_player, &QMediaPlayer::stateChanged,
this, &QtMultimediaOutputBackend::stateChanged);
}
QtMultimediaOutputBackend::~QtMultimediaOutputBackend()
{
m_player->deleteLater();
}
void QtMultimediaOutputBackend::setUri(const QString &uri)
{
m_player->setMedia(QUrl::fromLocalFile(uri));
}
int QtMultimediaOutputBackend::volume() const
{
return m_player->volume(); //TODO check if this is really a cubic value
}
void QtMultimediaOutputBackend::setVolume(int volume)
{
m_player->setVolume(volume); //TODO check if value is cubic
}
OutputDeviceController::State QtMultimediaOutputBackend::state() const
{
switch (m_player->state()) {
case QMediaPlayer::StoppedState:
return OutputDeviceController::StoppedState;
break;
case QMediaPlayer::PlayingState:
return OutputDeviceController::PlayingState;
break;
case QMediaPlayer::PausedState:
return OutputDeviceController::PausedState;
break;
default:
return OutputDeviceController::StoppedState;
}
}
void QtMultimediaOutputBackend::play()
{
m_player->play();
}
void QtMultimediaOutputBackend::pause()
{
m_player->pause();
}
void QtMultimediaOutputBackend::stop()
{
m_player->stop();
}
/*
* 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 QTMULTIMEDIAOUTPUTBACKEND_H
#define QTMULTIMEDIAOUTPUTBACKEND_H
#include "outputbackendinterface.h"
#include <QString>
class QMediaPlayer;
class QtMultimediaOutputBackend : public OutputBackendInterface
{
Q_OBJECT
public:
QtMultimediaOutputBackend();
virtual ~QtMultimediaOutputBackend();
void setUri(const QString & uri);
/**
* volume as cubic value
*/
int volume() const;
OutputDeviceController::State state() const;
public Q_SLOTS:
void play();
void pause();
void stop();
void setVolume(int volume);
private:
QMediaPlayer *m_player;
};
#endif
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