diff --git a/libsound/src/qtmultimediabackend/qtmultimediabackend.cpp b/libsound/src/qtmultimediabackend/qtmultimediabackend.cpp index 6446f67..f17e19e 100644 --- a/libsound/src/qtmultimediabackend/qtmultimediabackend.cpp +++ b/libsound/src/qtmultimediabackend/qtmultimediabackend.cpp @@ -1,64 +1,50 @@ /* * Copyright 2016 Andreas Cord-Landwehr * * 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 . */ #include "qtmultimediabackend.h" #include "qtmultimediacapturebackend.h" #include "qtmultimediaoutputbackend.h" #include "libsound_export.h" #include K_PLUGIN_FACTORY_WITH_JSON( BackendFactory, "qtmultimediabackend.json", registerPlugin();) QtMultimediaBackend::QtMultimediaBackend(QObject *parent, const QList< QVariant >&) : BackendInterface("qtmultimedia", parent) - , m_captureBackend(nullptr) - , m_outputBackend(nullptr) + , m_captureBackend(new QtMultimediaCaptureBackend(this)) + , m_outputBackend(new QtMultimediaOutputBackend(this)) { } QtMultimediaBackend::~QtMultimediaBackend() { - if (m_captureBackend) { - m_captureBackend->deleteLater(); - 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" diff --git a/libsound/src/qtmultimediabackend/qtmultimediabackend.h b/libsound/src/qtmultimediabackend/qtmultimediabackend.h index e408a44..98e1d1d 100644 --- a/libsound/src/qtmultimediabackend/qtmultimediabackend.h +++ b/libsound/src/qtmultimediabackend/qtmultimediabackend.h @@ -1,47 +1,47 @@ /* * Copyright 2016 Andreas Cord-Landwehr * * 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 . */ #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; + QtMultimediaCaptureBackend *m_captureBackend; + QtMultimediaOutputBackend *m_outputBackend; }; #endif diff --git a/libsound/src/qtmultimediabackend/qtmultimediacapturebackend.cpp b/libsound/src/qtmultimediabackend/qtmultimediacapturebackend.cpp index b9205cd..20c140c 100644 --- a/libsound/src/qtmultimediabackend/qtmultimediacapturebackend.cpp +++ b/libsound/src/qtmultimediabackend/qtmultimediacapturebackend.cpp @@ -1,83 +1,84 @@ /* * Copyright 2016 Andreas Cord-Landwehr * * 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 . */ #include "qtmultimediacapturebackend.h" #include "libsound_debug.h" #include #include #include -QtMultimediaCaptureBackend::QtMultimediaCaptureBackend() - : m_recorder(new QAudioRecorder) +QtMultimediaCaptureBackend::QtMultimediaCaptureBackend(QObject *parent) + : CaptureBackendInterface(parent) + , 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; } } diff --git a/libsound/src/qtmultimediabackend/qtmultimediacapturebackend.h b/libsound/src/qtmultimediabackend/qtmultimediacapturebackend.h index b147942..56b56f4 100644 --- a/libsound/src/qtmultimediabackend/qtmultimediacapturebackend.h +++ b/libsound/src/qtmultimediabackend/qtmultimediacapturebackend.h @@ -1,53 +1,53 @@ /* * Copyright 2016 Andreas Cord-Landwehr * * 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 . */ #ifndef QTMULTIMEDIACAPTUREBACKEND_H #define QTMULTIMEDIACAPTUREBACKEND_H #include "capturedevicecontroller.h" #include "capturebackendinterface.h" #include #include class QAudioRecorder; class QMediaRecorder; class QMediaObject; class QtMultimediaCaptureBackend : public CaptureBackendInterface { Q_OBJECT public: - QtMultimediaCaptureBackend(); + explicit QtMultimediaCaptureBackend(QObject *parent); 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 diff --git a/libsound/src/qtmultimediabackend/qtmultimediaoutputbackend.cpp b/libsound/src/qtmultimediabackend/qtmultimediaoutputbackend.cpp index 4a055d1..eb73b9a 100644 --- a/libsound/src/qtmultimediabackend/qtmultimediaoutputbackend.cpp +++ b/libsound/src/qtmultimediabackend/qtmultimediaoutputbackend.cpp @@ -1,80 +1,81 @@ /* * Copyright 2016 Andreas Cord-Landwehr * * 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 . */ #include "qtmultimediaoutputbackend.h" #include #include #include -QtMultimediaOutputBackend::QtMultimediaOutputBackend() - : m_player(new QMediaPlayer) +QtMultimediaOutputBackend::QtMultimediaOutputBackend(QObject *parent) + : OutputBackendInterface(parent) + , 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(); } diff --git a/libsound/src/qtmultimediabackend/qtmultimediaoutputbackend.h b/libsound/src/qtmultimediabackend/qtmultimediaoutputbackend.h index 0e78087..dd5ee34 100644 --- a/libsound/src/qtmultimediabackend/qtmultimediaoutputbackend.h +++ b/libsound/src/qtmultimediabackend/qtmultimediaoutputbackend.h @@ -1,52 +1,52 @@ /* * Copyright 2016 Andreas Cord-Landwehr * * 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 . */ #ifndef QTMULTIMEDIAOUTPUTBACKEND_H #define QTMULTIMEDIAOUTPUTBACKEND_H #include "outputbackendinterface.h" #include class QMediaPlayer; class QtMultimediaOutputBackend : public OutputBackendInterface { Q_OBJECT public: - QtMultimediaOutputBackend(); + explicit QtMultimediaOutputBackend(QObject *parent = nullptr); 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