Introduction of fake radio backend to enable testing the radio APIs
Includes some behavior for all standard methods. Also fixes a typo in qradiotunercontrol.h and a couple of minor bugs in the radio example that came to light using this new backend. Change-Id: I65b8b8715a46f0fd702f9630ea81f7d5df527055 Reviewed-on: http://codereview.qt.nokia.com/3619 Reviewed-by: Qt Sanity Bot <qt_sanity_bot@ovi.com> Reviewed-by: Dmytro Poplavskiy <dmytro.poplavskiy@nokia.com> Reviewed-by: Michael Goddard <michael.goddard@nokia.com>
This commit is contained in:
@@ -45,8 +45,6 @@
|
||||
Radio::Radio()
|
||||
{
|
||||
radio = new QRadioTuner;
|
||||
connect(radio,SIGNAL(frequencyChanged(int)),this,SLOT(freqChanged(int)));
|
||||
connect(radio,SIGNAL(signalStrengthChanged(int)),this,SLOT(signalChanged(int)));
|
||||
connect(radio, SIGNAL(error(QRadioTuner::Error)), this, SLOT(error(QRadioTuner::Error)));
|
||||
|
||||
if(radio->isBandSupported(QRadioTuner::FM))
|
||||
@@ -62,6 +60,7 @@ Radio::Radio()
|
||||
freq = new QLabel;
|
||||
freq->setText(QString("%1 kHz").arg(radio->frequency()/1000));
|
||||
topBar->addWidget(freq);
|
||||
connect(radio,SIGNAL(frequencyChanged(int)),this,SLOT(freqChanged(int)));
|
||||
|
||||
signal = new QLabel;
|
||||
if (radio->isAvailable())
|
||||
@@ -69,6 +68,8 @@ Radio::Radio()
|
||||
else
|
||||
signal->setText(tr("No radio found"));
|
||||
topBar->addWidget(signal);
|
||||
connect(radio,SIGNAL(signalStrengthChanged(int)),this,SLOT(signalChanged(int)));
|
||||
|
||||
volumeSlider = new QSlider(Qt::Vertical,this);
|
||||
volumeSlider->setRange(0,100);
|
||||
volumeSlider->setValue(50);
|
||||
|
||||
@@ -97,7 +97,7 @@ Q_SIGNALS:
|
||||
void bandChanged(QRadioTuner::Band band);
|
||||
void frequencyChanged(int frequency);
|
||||
void stereoStatusChanged(bool stereo);
|
||||
void searchingChanged(bool stereo);
|
||||
void searchingChanged(bool searching);
|
||||
void signalStrengthChanged(int signalStrength);
|
||||
void volumeChanged(int volume);
|
||||
void mutedChanged(bool muted);
|
||||
|
||||
23
src/plugins/fakeradio/fakeradio.pro
Normal file
23
src/plugins/fakeradio/fakeradio.pro
Normal file
@@ -0,0 +1,23 @@
|
||||
load(qt_module)
|
||||
|
||||
TARGET = qtmedia_fakeradio
|
||||
QT += multimediakit-private
|
||||
PLUGIN_TYPE = mediaservice
|
||||
|
||||
load(qt_plugin)
|
||||
DESTDIR = $$QT.multimediakit.plugins/$${PLUGIN_TYPE}
|
||||
|
||||
HEADERS += \
|
||||
fakeradioserviceplugin.h \
|
||||
fakeradioservice.h \
|
||||
fakeradiotunercontrol.h
|
||||
|
||||
SOURCES += \
|
||||
fakeradioserviceplugin.cpp \
|
||||
fakeradioservice.cpp \
|
||||
fakeradiotunercontrol.cpp
|
||||
|
||||
|
||||
target.path += $$[QT_INSTALL_PLUGINS]/$${PLUGIN_TYPE}
|
||||
INSTALLS += target
|
||||
|
||||
71
src/plugins/fakeradio/fakeradioservice.cpp
Normal file
71
src/plugins/fakeradio/fakeradioservice.cpp
Normal file
@@ -0,0 +1,71 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** GNU Lesser General Public License Usage
|
||||
** This file may be used under the terms of the GNU Lesser General Public
|
||||
** License version 2.1 as published by the Free Software Foundation and
|
||||
** appearing in the file LICENSE.LGPL included in the packaging of this
|
||||
** file. Please review the following information to ensure the GNU Lesser
|
||||
** General Public License version 2.1 requirements will be met:
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU General
|
||||
** Public License version 3.0 as published by the Free Software Foundation
|
||||
** and appearing in the file LICENSE.GPL included in the packaging of this
|
||||
** file. Please review the following information to ensure the GNU General
|
||||
** Public License version 3.0 requirements will be met:
|
||||
** http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** Other Usage
|
||||
** Alternatively, this file may be used in accordance with the terms and
|
||||
** conditions contained in a signed written agreement between you and Nokia.
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtCore/qvariant.h>
|
||||
#include <QtCore/qdebug.h>
|
||||
#include <QtCore/qfile.h>
|
||||
#include <QtGui/qwidget.h>
|
||||
|
||||
#include "fakeradioservice.h"
|
||||
#include "fakeradiotunercontrol.h"
|
||||
|
||||
FakeRadioService::FakeRadioService(QObject *parent):
|
||||
QMediaService(parent)
|
||||
{
|
||||
m_control = new FakeRadioTunerControl(this);
|
||||
}
|
||||
|
||||
FakeRadioService::~FakeRadioService()
|
||||
{
|
||||
}
|
||||
|
||||
QMediaControl *FakeRadioService::requestControl(const char* name)
|
||||
{
|
||||
if (qstrcmp(name,QRadioTunerControl_iid) == 0)
|
||||
return m_control;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
void FakeRadioService::releaseControl(QMediaControl *)
|
||||
{
|
||||
}
|
||||
67
src/plugins/fakeradio/fakeradioservice.h
Normal file
67
src/plugins/fakeradio/fakeradioservice.h
Normal file
@@ -0,0 +1,67 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** GNU Lesser General Public License Usage
|
||||
** This file may be used under the terms of the GNU Lesser General Public
|
||||
** License version 2.1 as published by the Free Software Foundation and
|
||||
** appearing in the file LICENSE.LGPL included in the packaging of this
|
||||
** file. Please review the following information to ensure the GNU Lesser
|
||||
** General Public License version 2.1 requirements will be met:
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU General
|
||||
** Public License version 3.0 as published by the Free Software Foundation
|
||||
** and appearing in the file LICENSE.GPL included in the packaging of this
|
||||
** file. Please review the following information to ensure the GNU General
|
||||
** Public License version 3.0 requirements will be met:
|
||||
** http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** Other Usage
|
||||
** Alternatively, this file may be used in accordance with the terms and
|
||||
** conditions contained in a signed written agreement between you and Nokia.
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef FAKERADIOSERVICE_H
|
||||
#define FAKERADIOSERVICE_H
|
||||
|
||||
#include <QtCore/qobject.h>
|
||||
|
||||
#include <qmediaservice.h>
|
||||
QT_USE_NAMESPACE
|
||||
|
||||
class FakeRadioTunerControl;
|
||||
|
||||
class FakeRadioService : public QMediaService
|
||||
{
|
||||
Q_OBJECT
|
||||
|
||||
public:
|
||||
FakeRadioService(QObject *parent = 0);
|
||||
~FakeRadioService();
|
||||
|
||||
QMediaControl *requestControl(const char* name);
|
||||
void releaseControl(QMediaControl *);
|
||||
|
||||
private:
|
||||
FakeRadioTunerControl *m_control;
|
||||
};
|
||||
|
||||
#endif // FAKERADIOSERVICE_H
|
||||
84
src/plugins/fakeradio/fakeradioserviceplugin.cpp
Normal file
84
src/plugins/fakeradio/fakeradioserviceplugin.cpp
Normal file
@@ -0,0 +1,84 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** GNU Lesser General Public License Usage
|
||||
** This file may be used under the terms of the GNU Lesser General Public
|
||||
** License version 2.1 as published by the Free Software Foundation and
|
||||
** appearing in the file LICENSE.LGPL included in the packaging of this
|
||||
** file. Please review the following information to ensure the GNU Lesser
|
||||
** General Public License version 2.1 requirements will be met:
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU General
|
||||
** Public License version 3.0 as published by the Free Software Foundation
|
||||
** and appearing in the file LICENSE.GPL included in the packaging of this
|
||||
** file. Please review the following information to ensure the GNU General
|
||||
** Public License version 3.0 requirements will be met:
|
||||
** http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** Other Usage
|
||||
** Alternatively, this file may be used in accordance with the terms and
|
||||
** conditions contained in a signed written agreement between you and Nokia.
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include <QtCore/qstring.h>
|
||||
#include <QtCore/qfile.h>
|
||||
#include <QtCore/qdebug.h>
|
||||
#include <QtCore/qdir.h>
|
||||
|
||||
#include "fakeradioserviceplugin.h"
|
||||
#include "fakeradioservice.h"
|
||||
|
||||
#include <qmediaserviceprovider.h>
|
||||
|
||||
|
||||
QStringList FakeRadioServicePlugin::keys() const
|
||||
{
|
||||
return QStringList() <<
|
||||
QLatin1String(Q_MEDIASERVICE_RADIO);
|
||||
}
|
||||
|
||||
QMediaService* FakeRadioServicePlugin::create(QString const& key)
|
||||
{
|
||||
if (key == QLatin1String(Q_MEDIASERVICE_RADIO))
|
||||
return new FakeRadioService;
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
void FakeRadioServicePlugin::release(QMediaService *service)
|
||||
{
|
||||
delete service;
|
||||
}
|
||||
|
||||
QList<QByteArray> FakeRadioServicePlugin::devices(const QByteArray &service) const
|
||||
{
|
||||
return QList<QByteArray>();
|
||||
}
|
||||
|
||||
QString FakeRadioServicePlugin::deviceDescription(const QByteArray &service, const QByteArray &device)
|
||||
{
|
||||
return QString();
|
||||
}
|
||||
|
||||
|
||||
Q_EXPORT_PLUGIN2(qtmedia_fakeradio, FakeRadioServicePlugin);
|
||||
|
||||
63
src/plugins/fakeradio/fakeradioserviceplugin.h
Normal file
63
src/plugins/fakeradio/fakeradioserviceplugin.h
Normal file
@@ -0,0 +1,63 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** GNU Lesser General Public License Usage
|
||||
** This file may be used under the terms of the GNU Lesser General Public
|
||||
** License version 2.1 as published by the Free Software Foundation and
|
||||
** appearing in the file LICENSE.LGPL included in the packaging of this
|
||||
** file. Please review the following information to ensure the GNU Lesser
|
||||
** General Public License version 2.1 requirements will be met:
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU General
|
||||
** Public License version 3.0 as published by the Free Software Foundation
|
||||
** and appearing in the file LICENSE.GPL included in the packaging of this
|
||||
** file. Please review the following information to ensure the GNU General
|
||||
** Public License version 3.0 requirements will be met:
|
||||
** http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** Other Usage
|
||||
** Alternatively, this file may be used in accordance with the terms and
|
||||
** conditions contained in a signed written agreement between you and Nokia.
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
|
||||
#ifndef FAKERADIOSERVICEPLUGIN_H
|
||||
#define FAKERADIOSERVICEPLUGIN_H
|
||||
|
||||
#include <qmediaserviceproviderplugin.h>
|
||||
|
||||
QT_USE_NAMESPACE
|
||||
|
||||
class FakeRadioServicePlugin : public QMediaServiceProviderPlugin, public QMediaServiceSupportedDevicesInterface
|
||||
{
|
||||
Q_OBJECT
|
||||
Q_INTERFACES(QMediaServiceSupportedDevicesInterface)
|
||||
public:
|
||||
QStringList keys() const;
|
||||
QMediaService* create(QString const& key);
|
||||
void release(QMediaService *service);
|
||||
|
||||
QList<QByteArray> devices(const QByteArray &service) const;
|
||||
QString deviceDescription(const QByteArray &service, const QByteArray &device);
|
||||
};
|
||||
|
||||
#endif // FAKERADIOSERVICEPLUGIN_H
|
||||
335
src/plugins/fakeradio/fakeradiotunercontrol.cpp
Normal file
335
src/plugins/fakeradio/fakeradiotunercontrol.cpp
Normal file
@@ -0,0 +1,335 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** GNU Lesser General Public License Usage
|
||||
** This file may be used under the terms of the GNU Lesser General Public
|
||||
** License version 2.1 as published by the Free Software Foundation and
|
||||
** appearing in the file LICENSE.LGPL included in the packaging of this
|
||||
** file. Please review the following information to ensure the GNU Lesser
|
||||
** General Public License version 2.1 requirements will be met:
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU General
|
||||
** Public License version 3.0 as published by the Free Software Foundation
|
||||
** and appearing in the file LICENSE.GPL included in the packaging of this
|
||||
** file. Please review the following information to ensure the GNU General
|
||||
** Public License version 3.0 requirements will be met:
|
||||
** http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** Other Usage
|
||||
** Alternatively, this file may be used in accordance with the terms and
|
||||
** conditions contained in a signed written agreement between you and Nokia.
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#include "fakeradiotunercontrol.h"
|
||||
#include "fakeradioservice.h"
|
||||
|
||||
#include <QtCore/qdebug.h>
|
||||
|
||||
FakeRadioTunerControl::FakeRadioTunerControl(QObject *parent)
|
||||
:QRadioTunerControl(parent)
|
||||
{
|
||||
m_state = QRadioTuner::StoppedState;
|
||||
m_freqMin = 520000;
|
||||
m_freqMax = 108000000;
|
||||
m_currentBand = QRadioTuner::FM;
|
||||
m_currentFreq = 0;
|
||||
m_stereo = true;
|
||||
m_stereoMode = QRadioTuner::Auto;
|
||||
m_signalStrength = 0;
|
||||
m_volume = 50;
|
||||
m_muted = false;
|
||||
|
||||
m_searching = false;
|
||||
m_forward = true;
|
||||
m_searchTimer = new QTimer(this);
|
||||
m_searchTimer->setSingleShot(true);
|
||||
connect(m_searchTimer, SIGNAL(timeout()), this, SLOT(searchEnded()));
|
||||
|
||||
QTimer::singleShot(300, this, SLOT(delayedInit()));
|
||||
|
||||
qsrand(QTime::currentTime().msec());
|
||||
}
|
||||
|
||||
FakeRadioTunerControl::~FakeRadioTunerControl()
|
||||
{
|
||||
m_searchTimer->stop();
|
||||
}
|
||||
|
||||
bool FakeRadioTunerControl::isAvailable() const
|
||||
{
|
||||
return true;
|
||||
}
|
||||
|
||||
QtMultimediaKit::AvailabilityError FakeRadioTunerControl::availabilityError() const
|
||||
{
|
||||
return QtMultimediaKit::NoError;
|
||||
}
|
||||
|
||||
QRadioTuner::State FakeRadioTunerControl::state() const
|
||||
{
|
||||
return m_state;
|
||||
}
|
||||
|
||||
QRadioTuner::Band FakeRadioTunerControl::band() const
|
||||
{
|
||||
return m_currentBand;
|
||||
}
|
||||
|
||||
bool FakeRadioTunerControl::isBandSupported(QRadioTuner::Band b) const
|
||||
{
|
||||
switch (b) {
|
||||
case QRadioTuner::FM:
|
||||
if (m_freqMin <= 87500000 && m_freqMax >= 108000000)
|
||||
return true;
|
||||
break;
|
||||
case QRadioTuner::LW:
|
||||
if (m_freqMin <= 148500 && m_freqMax >= 283500)
|
||||
return true;
|
||||
case QRadioTuner::AM:
|
||||
if (m_freqMin <= 520000 && m_freqMax >= 1610000)
|
||||
return true;
|
||||
default:
|
||||
if (m_freqMin <= 1711000 && m_freqMax >= 30000000)
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
void FakeRadioTunerControl::setBand(QRadioTuner::Band b)
|
||||
{
|
||||
if (isBandSupported(b)) {
|
||||
m_currentBand = b;
|
||||
emit bandChanged(m_currentBand);
|
||||
|
||||
int f = m_currentFreq;
|
||||
QPair<int, int> fRange = frequencyRange(m_currentBand);
|
||||
|
||||
if (f < fRange.first)
|
||||
f = fRange.first;
|
||||
if (f > fRange.second)
|
||||
f = fRange.second;
|
||||
|
||||
if (f != m_currentFreq) {
|
||||
m_currentFreq = f;
|
||||
emit frequencyChanged(m_currentFreq);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int FakeRadioTunerControl::frequency() const
|
||||
{
|
||||
return m_currentFreq;
|
||||
}
|
||||
|
||||
int FakeRadioTunerControl::frequencyStep(QRadioTuner::Band b) const
|
||||
{
|
||||
int step = 0;
|
||||
|
||||
if (b == QRadioTuner::FM)
|
||||
step = 100000; // 100kHz steps
|
||||
else if (b == QRadioTuner::LW)
|
||||
step = 1000; // 1kHz steps
|
||||
else if (b == QRadioTuner::AM)
|
||||
step = 1000; // 1kHz steps
|
||||
else if (b == QRadioTuner::SW)
|
||||
step = 500; // 500Hz steps
|
||||
|
||||
return step;
|
||||
}
|
||||
|
||||
QPair<int,int> FakeRadioTunerControl::frequencyRange(QRadioTuner::Band b) const
|
||||
{
|
||||
if (b == QRadioTuner::FM)
|
||||
return qMakePair<int,int>(87500000,108000000);
|
||||
else if (b == QRadioTuner::LW)
|
||||
return qMakePair<int,int>(148500,283500);
|
||||
else if (b == QRadioTuner::AM)
|
||||
return qMakePair<int,int>(520000,1710000);
|
||||
else if (b == QRadioTuner::SW)
|
||||
return qMakePair<int,int>(1711111,30000000);
|
||||
|
||||
return qMakePair<int,int>(0,0);
|
||||
}
|
||||
|
||||
void FakeRadioTunerControl::setFrequency(int frequency)
|
||||
{
|
||||
qint64 f = frequency;
|
||||
QPair<int, int> fRange = frequencyRange(m_currentBand);
|
||||
|
||||
if (frequency < fRange.first)
|
||||
f = fRange.first;
|
||||
if (frequency > fRange.second)
|
||||
f = fRange.second;
|
||||
|
||||
m_currentFreq = f;
|
||||
emit frequencyChanged(m_currentFreq);
|
||||
}
|
||||
|
||||
bool FakeRadioTunerControl::isStereo() const
|
||||
{
|
||||
return m_stereo;
|
||||
}
|
||||
|
||||
QRadioTuner::StereoMode FakeRadioTunerControl::stereoMode() const
|
||||
{
|
||||
return m_stereoMode;
|
||||
}
|
||||
|
||||
void FakeRadioTunerControl::setStereoMode(QRadioTuner::StereoMode mode)
|
||||
{
|
||||
bool stereo = true;
|
||||
|
||||
if (mode == QRadioTuner::ForceMono)
|
||||
stereo = false;
|
||||
else
|
||||
stereo = true;
|
||||
|
||||
m_stereo = stereo;
|
||||
m_stereoMode = mode;
|
||||
|
||||
emit stereoStatusChanged(stereo);
|
||||
}
|
||||
|
||||
int FakeRadioTunerControl::signalStrength() const
|
||||
{
|
||||
return m_signalStrength;
|
||||
}
|
||||
|
||||
int FakeRadioTunerControl::volume() const
|
||||
{
|
||||
return m_volume;
|
||||
}
|
||||
|
||||
void FakeRadioTunerControl::setVolume(int volume)
|
||||
{
|
||||
int v = volume;
|
||||
|
||||
if (v < 0)
|
||||
v = 0;
|
||||
if (100 > v)
|
||||
v = 100;
|
||||
|
||||
m_volume = v;
|
||||
}
|
||||
|
||||
bool FakeRadioTunerControl::isMuted() const
|
||||
{
|
||||
return m_muted;
|
||||
}
|
||||
|
||||
void FakeRadioTunerControl::setMuted(bool muted)
|
||||
{
|
||||
if (muted != m_muted) {
|
||||
m_muted = muted;
|
||||
emit mutedChanged(m_muted);
|
||||
}
|
||||
}
|
||||
|
||||
bool FakeRadioTunerControl::isSearching() const
|
||||
{
|
||||
return m_searching;
|
||||
}
|
||||
|
||||
void FakeRadioTunerControl::cancelSearch()
|
||||
{
|
||||
m_searching = false;
|
||||
m_searchTimer->stop();
|
||||
emit searchingChanged(m_searching);
|
||||
}
|
||||
|
||||
void FakeRadioTunerControl::searchForward()
|
||||
{
|
||||
m_forward = true;
|
||||
performSearch();
|
||||
}
|
||||
|
||||
void FakeRadioTunerControl::searchBackward()
|
||||
{
|
||||
m_forward = false;
|
||||
performSearch();
|
||||
}
|
||||
|
||||
void FakeRadioTunerControl::start()
|
||||
{
|
||||
if (isAvailable() && m_state != QRadioTuner::ActiveState) {
|
||||
m_state = QRadioTuner::ActiveState;
|
||||
emit stateChanged(m_state);
|
||||
}
|
||||
}
|
||||
|
||||
void FakeRadioTunerControl::stop()
|
||||
{
|
||||
if (m_state != QRadioTuner::StoppedState) {
|
||||
m_state = QRadioTuner::StoppedState;
|
||||
emit stateChanged(m_state);
|
||||
}
|
||||
}
|
||||
|
||||
QRadioTuner::Error FakeRadioTunerControl::error() const
|
||||
{
|
||||
return QRadioTuner::NoError;
|
||||
}
|
||||
|
||||
QString FakeRadioTunerControl::errorString() const
|
||||
{
|
||||
return QString();
|
||||
}
|
||||
|
||||
void FakeRadioTunerControl::delayedInit()
|
||||
{
|
||||
m_signalStrength = 50;
|
||||
emit signalStrengthChanged(m_signalStrength);
|
||||
}
|
||||
|
||||
void FakeRadioTunerControl::performSearch()
|
||||
{
|
||||
m_searching = true;
|
||||
m_searchTimer->start(qrand() % 1000);
|
||||
emit searchingChanged(m_searching);
|
||||
}
|
||||
|
||||
void FakeRadioTunerControl::searchEnded()
|
||||
{
|
||||
int minFreq, maxFreq, newFreq;
|
||||
QPair<int, int> fRange = frequencyRange(m_currentBand);
|
||||
|
||||
if (m_forward) {
|
||||
minFreq = m_currentFreq;
|
||||
maxFreq = fRange.second;
|
||||
} else {
|
||||
minFreq = fRange.first;
|
||||
maxFreq = m_currentFreq;
|
||||
}
|
||||
|
||||
if ((qreal)(maxFreq - minFreq) / (qreal)(fRange.second - fRange.first) < 0.02) { // don't want to do anything if we have less than 2% of the range to move
|
||||
return;
|
||||
}
|
||||
|
||||
newFreq = (qrand() % (maxFreq - minFreq)) + minFreq;
|
||||
newFreq -= newFreq % frequencyStep(m_currentBand);
|
||||
|
||||
m_searching = false;
|
||||
m_currentFreq = newFreq;
|
||||
emit searchingChanged(m_searching);
|
||||
emit frequencyChanged(m_currentFreq);
|
||||
}
|
||||
123
src/plugins/fakeradio/fakeradiotunercontrol.h
Normal file
123
src/plugins/fakeradio/fakeradiotunercontrol.h
Normal file
@@ -0,0 +1,123 @@
|
||||
/****************************************************************************
|
||||
**
|
||||
** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
||||
** All rights reserved.
|
||||
** Contact: Nokia Corporation (qt-info@nokia.com)
|
||||
**
|
||||
** This file is part of the Qt Toolkit.
|
||||
**
|
||||
** $QT_BEGIN_LICENSE:LGPL$
|
||||
** GNU Lesser General Public License Usage
|
||||
** This file may be used under the terms of the GNU Lesser General Public
|
||||
** License version 2.1 as published by the Free Software Foundation and
|
||||
** appearing in the file LICENSE.LGPL included in the packaging of this
|
||||
** file. Please review the following information to ensure the GNU Lesser
|
||||
** General Public License version 2.1 requirements will be met:
|
||||
** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
||||
**
|
||||
** In addition, as a special exception, Nokia gives you certain additional
|
||||
** rights. These rights are described in the Nokia Qt LGPL Exception
|
||||
** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
||||
**
|
||||
** GNU General Public License Usage
|
||||
** Alternatively, this file may be used under the terms of the GNU General
|
||||
** Public License version 3.0 as published by the Free Software Foundation
|
||||
** and appearing in the file LICENSE.GPL included in the packaging of this
|
||||
** file. Please review the following information to ensure the GNU General
|
||||
** Public License version 3.0 requirements will be met:
|
||||
** http://www.gnu.org/copyleft/gpl.html.
|
||||
**
|
||||
** Other Usage
|
||||
** Alternatively, this file may be used in accordance with the terms and
|
||||
** conditions contained in a signed written agreement between you and Nokia.
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
**
|
||||
** $QT_END_LICENSE$
|
||||
**
|
||||
****************************************************************************/
|
||||
|
||||
#ifndef FAKERADIOTUNERCONTROL_H
|
||||
#define FAKERADIOTUNERCONTROL_H
|
||||
|
||||
#include <QtCore/qobject.h>
|
||||
#include <QtCore/qtimer.h>
|
||||
#include <QtCore/qdatetime.h>
|
||||
|
||||
#include <qradiotunercontrol.h>
|
||||
|
||||
QT_USE_NAMESPACE
|
||||
|
||||
class FakeRadioService;
|
||||
|
||||
class FakeRadioTunerControl : public QRadioTunerControl
|
||||
{
|
||||
Q_OBJECT
|
||||
public:
|
||||
FakeRadioTunerControl(QObject *parent = 0);
|
||||
~FakeRadioTunerControl();
|
||||
|
||||
bool isAvailable() const;
|
||||
QtMultimediaKit::AvailabilityError availabilityError() const;
|
||||
|
||||
QRadioTuner::State state() const;
|
||||
|
||||
QRadioTuner::Band band() const;
|
||||
void setBand(QRadioTuner::Band b);
|
||||
bool isBandSupported(QRadioTuner::Band b) const;
|
||||
|
||||
int frequency() const;
|
||||
int frequencyStep(QRadioTuner::Band b) const;
|
||||
QPair<int,int> frequencyRange(QRadioTuner::Band b) const;
|
||||
void setFrequency(int frequency);
|
||||
|
||||
bool isStereo() const;
|
||||
QRadioTuner::StereoMode stereoMode() const;
|
||||
void setStereoMode(QRadioTuner::StereoMode mode);
|
||||
|
||||
int signalStrength() const;
|
||||
|
||||
int volume() const;
|
||||
void setVolume(int volume);
|
||||
|
||||
bool isMuted() const;
|
||||
void setMuted(bool muted);
|
||||
|
||||
bool isSearching() const;
|
||||
void cancelSearch();
|
||||
|
||||
void searchForward();
|
||||
void searchBackward();
|
||||
|
||||
void start();
|
||||
void stop();
|
||||
|
||||
QRadioTuner::Error error() const;
|
||||
QString errorString() const;
|
||||
|
||||
private slots:
|
||||
void delayedInit();
|
||||
void performSearch();
|
||||
void searchEnded();
|
||||
|
||||
private: //data
|
||||
QRadioTuner::State m_state;
|
||||
QRadioTuner::Band m_currentBand;
|
||||
qint64 m_freqMin;
|
||||
qint64 m_freqMax;
|
||||
qint64 m_currentFreq;
|
||||
bool m_stereo;
|
||||
QRadioTuner::StereoMode m_stereoMode;
|
||||
int m_signalStrength;
|
||||
int m_volume;
|
||||
bool m_muted;
|
||||
|
||||
// searching
|
||||
bool m_searching;
|
||||
bool m_forward;
|
||||
QTimer *m_searchTimer;
|
||||
};
|
||||
|
||||
#endif // FAKERADIOTUNERCONTROL_H
|
||||
@@ -33,7 +33,8 @@ unix:!mac {
|
||||
SUBDIRS += audiocapture
|
||||
}
|
||||
|
||||
!maemo*:SUBDIRS += v4l
|
||||
# v4l is turned off because it is not supported in Qt 5
|
||||
# !maemo*:SUBDIRS += v4l
|
||||
|
||||
contains(config_test_pulseaudio, yes) {
|
||||
SUBDIRS += pulseaudio
|
||||
@@ -44,3 +45,7 @@ mac:!simulator {
|
||||
SUBDIRS += audiocapture
|
||||
!qpa: SUBDIRS += qt7
|
||||
}
|
||||
|
||||
# fake radio to test the radio APIs
|
||||
SUBDIRS += fakeradio
|
||||
|
||||
|
||||
Reference in New Issue
Block a user