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

Introduce interface for output backend.

parent 56dfe5ed
......@@ -35,6 +35,7 @@ include_directories(
set(sound_LIB_SRCS
capturedevicecontroller.cpp
outputdevicecontroller.cpp
outputbackendinterface.cpp
qtgstreamercapturebackend.cpp
qtgstreameroutputbackend.cpp
libsound_debug.cpp
......
/*
* 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 "outputbackendinterface.h"
OutputBackendInterface::OutputBackendInterface(QObject *parent)
: QObject(parent)
{
}
OutputBackendInterface::~OutputBackendInterface()
{
}
/*
* 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 OUTPUTBACKENDINTERFACE_H
#define OUTPUTBACKENDINTERFACE_H
#include "outputdevicecontroller.h"
#include "libsound_export.h"
#include <QObject>
class LIBSOUND_EXPORT OutputBackendInterface : public QObject
{
Q_OBJECT
public:
explicit OutputBackendInterface(QObject *parent = nullptr);
virtual ~OutputBackendInterface();
virtual void setUri(const QString & uri) = 0;
/**
* volume as cubic value
*/
virtual int volume() const = 0;
virtual OutputDeviceController::State state() const = 0;
public Q_SLOTS:
virtual void play() = 0;
virtual void pause() = 0;
virtual void stop() = 0;
virtual void setVolume(int volume) = 0;
Q_SIGNALS:
void positionChanged();
void stateChanged();
};
#endif
......@@ -16,6 +16,7 @@
*/
#include "outputdevicecontroller.h"
#include "outputbackendinterface.h"
#include "qtgstreameroutputbackend.h"
#include <QUrl>
#include "libsound_debug.h"
......@@ -34,7 +35,7 @@ class OutputDeviceControllerPrivate
public:
OutputDeviceControllerPrivate(OutputDeviceController *parent)
: m_parent(parent)
, m_backend(0)
, m_backend(nullptr)
, m_initialized(false)
{
m_backend = new QtGStreamerOutputBackend();
......@@ -51,20 +52,20 @@ public:
return;
}
m_backend = new QtGStreamerOutputBackend();
m_parent->connect(m_backend, &QtGStreamerOutputBackend::stateChanged,
m_parent->connect(m_backend, &OutputBackendInterface::stateChanged,
m_parent, &OutputDeviceController::emitChangedState);
m_volume = m_backend->volume();
m_initialized = true;
}
QtGStreamerOutputBackend * backend() const
OutputBackendInterface * backend() const
{
Q_ASSERT(m_backend);
return m_backend;
}
OutputDeviceController *m_parent;
QtGStreamerOutputBackend *m_backend;
OutputBackendInterface *m_backend;
int m_volume; // volume as cubic value
bool m_initialized;
};
......@@ -107,19 +108,7 @@ void OutputDeviceController::stop()
OutputDeviceController::State OutputDeviceController::state() const
{
switch (d->backend()->state()) {
case QGst::StateNull:
return OutputDeviceController::StoppedState;
break;
case QGst::StatePaused:
return OutputDeviceController::PlayingState;
break;
case QGst::StatePlaying:
return OutputDeviceController::PlayingState;
break;
default:
return OutputDeviceController::StoppedState;
}
return d->backend()->state();
}
void OutputDeviceController::setVolume(int volume)
......
......@@ -132,9 +132,22 @@ QTime QtGStreamerOutputBackend::length() const
}
}
QGst::State QtGStreamerOutputBackend::state() const
OutputDeviceController::State QtGStreamerOutputBackend::state() const
{
return m_pipeline ? m_pipeline->currentState() : QGst::StateNull;
const QGst::State state = m_pipeline ? m_pipeline->currentState() : QGst::StateNull;
switch (state) {
case QGst::StateNull:
return OutputDeviceController::StoppedState;
break;
case QGst::StatePaused:
return OutputDeviceController::PlayingState;
break;
case QGst::StatePlaying:
return OutputDeviceController::PlayingState;
break;
default:
return OutputDeviceController::StoppedState;
}
}
void QtGStreamerOutputBackend::play()
......
......@@ -21,19 +21,19 @@
#ifndef QTGSTREAMEROUTPUTBACKEND_H
#define QTGSTREAMEROUTPUTBACKEND_H
#include "capturedevicecontroller.h"
#include "outputbackendinterface.h"
#include <QString>
#include <QTimer>
#include <QGst/Global>
#include <QGst/Pipeline>
class QtGStreamerOutputBackend : public QObject
class QtGStreamerOutputBackend : public OutputBackendInterface
{
Q_OBJECT
public:
QtGStreamerOutputBackend();
~QtGStreamerOutputBackend();
virtual ~QtGStreamerOutputBackend();
void setUri(const QString & uri);
......@@ -45,7 +45,7 @@ public:
int volume() const;
QTime length() const;
QGst::State state() const;
OutputDeviceController::State state() const;
public Q_SLOTS:
void play();
......@@ -65,5 +65,4 @@ private:
QTimer m_positionTimer;
};
#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