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

Port OutputDeviceController to use QtGStreamer backend.

parent a92478a8
/*
* Copyright 2013 Andreas Cord-Landwehr <cordlandwehr@kde.org>
* Copyright 2013-2014 Andreas Cord-Landwehr <cordlandwehr@kde.org>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
......@@ -19,6 +19,7 @@
*/
#include "outputdevicecontroller.h"
#include "qtgstreameroutputbackend.h"
#include <KUrl>
#include <KDebug>
......@@ -43,36 +44,33 @@ public:
// use this value only for initialization, will be modified in another thread / another
// static Settings object
//m_volume = Settings::audioOutputVolume(); //TODO currently not use anywhere
m_backend = new QtGStreamerOutputBackend();
}
~OutputDeviceControllerPrivate()
{
m_mediaObject->disconnect();
m_mediaObject->deleteLater();
m_audioOutput->deleteLater();
delete m_backend;
}
bool lazyInit()
void lazyInit()
{
if (m_initialized) {
return false;
return;
}
m_audioOutput = new Phonon::AudioOutput(Phonon::MusicCategory);
m_mediaObject = new Phonon::MediaObject();
// initialize
Phonon::createPath(m_mediaObject, m_audioOutput);
m_backend = new QtGStreamerOutputBackend();
m_initialized = true;
return true;
}
QtGStreamerOutputBackend * backend() const
{
Q_ASSERT(m_backend);
return m_backend;
}
OutputDeviceController *m_parent;
bool m_initialized;
Phonon::AudioOutput *m_audioOutput;
Phonon::MediaObject *m_mediaObject;
QtGStreamerOutputBackend *m_backend;
int m_volume; // output volume in Db
bool m_initialized;
};
OutputDeviceController::OutputDeviceController()
......@@ -88,49 +86,51 @@ OutputDeviceController::~OutputDeviceController()
OutputDeviceController & OutputDeviceController::self()
{
static OutputDeviceController instance;
if (instance.d->lazyInit()) {
connect(instance.d->m_mediaObject, SIGNAL(stateChanged(Phonon::State,Phonon::State)),
&instance, SLOT(updateState()));
}
instance.d->lazyInit();
return instance;
}
void OutputDeviceController::play(const QString& filePath)
{
play(KUrl::fromLocalFile(filePath));
d->backend()->setUri(filePath);
// d->m_audioOutput->setVolumeDecibel(d->m_volume); //TODO
d->backend()->play();
emit started();
}
void OutputDeviceController::play(const KUrl &filePath)
{
d->m_mediaObject->setCurrentSource(filePath);
// d->m_audioOutput->setVolumeDecibel(d->m_volume);
d->m_mediaObject->play();
play(filePath.toLocalFile());
}
void OutputDeviceController::stop()
{
d->m_mediaObject->stop();
d->backend()->stop();
emit stopped();
}
Phonon::State OutputDeviceController::state() const
OutputDeviceController::State OutputDeviceController::state() const
{
return d->m_mediaObject->state();
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;
}
}
/*
QString OutputDeviceController::currentSource() const
{
return d->m_mediaObject->currentSource().fileName();
}
}*/
void OutputDeviceController::updateState()
{
if (d->m_mediaObject->state() == Phonon::StoppedState) {
emit stopped();
}
if (d->m_mediaObject->state() == Phonon::PlayingState) {
emit started();
}
}
void OutputDeviceController::setVolume(int volumenDb)
{
......
......@@ -22,10 +22,7 @@
#define OUTPUTDEVICECONTROLLER_H
#include "libsound_export.h"
#include <QObject>
#include <Phonon/AudioOutput>
#include <Phonon/MediaObject>
class OutputDeviceControllerPrivate;
class KUrl;
......@@ -40,6 +37,13 @@ class LIBSOUND_EXPORT OutputDeviceController : public QObject
Q_OBJECT
public:
enum State
{
StoppedState,
PlayingState,
PausedState
};
/**
* Returns self reference to the controller. First call of this method initializes
* output device controller.
......@@ -50,7 +54,7 @@ public:
void play(const QString &filePath);
void play(const KUrl &filePath);
Phonon::State state() const;
OutputDeviceController::State state() const;
void stop();
QString currentSource() const;
/**
......@@ -64,9 +68,6 @@ Q_SIGNALS:
void started();
void stopped();
private Q_SLOTS:
void updateState();
private:
Q_DISABLE_COPY(OutputDeviceController)
/**
......
......@@ -26,6 +26,7 @@
#include <QGst/Pipeline>
#include <QGst/ElementFactory>
#include <QGst/Bus>
#include <QGst/Init>
#include <QGst/Message>
#include <QGst/Query>
#include <QGst/ClockTime>
......@@ -34,7 +35,7 @@
QtGStreamerOutputBackend::QtGStreamerOutputBackend()
{
QGst::init();
}
QtGStreamerOutputBackend::~QtGStreamerOutputBackend()
......@@ -106,7 +107,6 @@ int QtGStreamerOutputBackend::volume() const
return 0;
}
void QtGStreamerOutputBackend::setVolume(int volume)
{
if (m_pipeline) {
......
......@@ -27,7 +27,6 @@
#include <QGst/Global>
#include <QGst/Pipeline>
class QtGStreamerOutputBackend : public QObject
{
Q_OBJECT
......
......@@ -90,13 +90,13 @@ void Player::stop()
void Player::updateState()
{
if (OutputDeviceController::self().state() == Phonon::StoppedState
if (OutputDeviceController::self().state() == OutputDeviceController::StoppedState
&& state() == PlayingState
) {
m_playbackState = StoppedState;
emit stateChanged();
}
if (OutputDeviceController::self().state() == Phonon::PlayingState
if (OutputDeviceController::self().state() == OutputDeviceController::PlayingState
&& state() != PlayingState
) {
m_playbackState = PlayingState;
......
......@@ -94,7 +94,7 @@ void SoundDeviceDialogPage::saveSettings()
void SoundDeviceDialogPage::playTestSound()
{
if (OutputDeviceController::self().state() == Phonon::PlayingState) {
if (OutputDeviceController::self().state() == OutputDeviceController::PlayingState) {
OutputDeviceController::self().stop();
return;
}
......@@ -105,7 +105,7 @@ void SoundDeviceDialogPage::playTestSound()
void SoundDeviceDialogPage::playRecordedSound()
{
if (OutputDeviceController::self().state() == Phonon::PlayingState) {
if (OutputDeviceController::self().state() == OutputDeviceController::PlayingState) {
OutputDeviceController::self().stop();
return;
}
......@@ -132,10 +132,10 @@ void SoundDeviceDialogPage::updatePlayButtonIcons()
{
// default sound output test
switch (OutputDeviceController::self().state()) {
case Phonon::PlayingState:
case OutputDeviceController::PlayingState:
ui->buttonPlayTestSound->setIcon(KIcon("media-playback-stop"));
break;
case Phonon::StoppedState:
case OutputDeviceController::StoppedState:
ui->buttonPlayTestSound->setIcon(KIcon("media-playback-start"));
break;
default:
......@@ -144,10 +144,10 @@ void SoundDeviceDialogPage::updatePlayButtonIcons()
// recorded sound output test
switch (OutputDeviceController::self().state()) {
case Phonon::PlayingState:
case OutputDeviceController::PlayingState:
ui->buttonPlayRecordedTestSound->setIcon(KIcon("media-playback-stop"));
break;
case Phonon::StoppedState:
case OutputDeviceController::StoppedState:
ui->buttonPlayRecordedTestSound->setIcon(KIcon("media-playback-start"));
break;
default:
......
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