Added RDS functionality to the QRadioTuner/QDeclarativeRadio

Change-Id: I865e3caba82977002cf1f01f1d64ee0a42de77c6
Reviewed-by: Jonas Rabbe <jonas.rabbe@nokia.com>
Reviewed-by: Michael Goddard <michael.goddard@nokia.com>
This commit is contained in:
Sami Nurmenniemi
2011-10-11 09:06:12 +03:00
committed by Qt by Nokia
parent cbb21e30d5
commit 6aea1a22ee
33 changed files with 2076 additions and 10 deletions

View File

@@ -10,13 +10,14 @@ DESTDIR = $$QT.multimedia.plugins/$${PLUGIN_TYPE}
HEADERS += \
fakeradioserviceplugin.h \
fakeradioservice.h \
fakeradiotunercontrol.h
fakeradiotunercontrol.h \
fakeradiodatacontrol.h
SOURCES += \
fakeradioserviceplugin.cpp \
fakeradioservice.cpp \
fakeradiotunercontrol.cpp
fakeradiotunercontrol.cpp \
fakeradiodatacontrol.cpp
target.path += $$[QT_INSTALL_PLUGINS]/$${PLUGIN_TYPE}
INSTALLS += target

View File

@@ -0,0 +1,226 @@
/****************************************************************************
**
** 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 "fakeradiodatacontrol.h"
#include "fakeradioservice.h"
#include <QtCore/qdebug.h>
FakeRadioDataControl::FakeRadioDataControl(QObject *parent)
:QRadioDataControl(parent)
{
initializeProgramTypeMapping();
m_rdsTimer = new QTimer(this);
connect(m_rdsTimer,SIGNAL(timeout()),this,SLOT(rdsUpdate()));
m_rdsTimer->start(5000);
rdsUpdate();
qsrand(QTime::currentTime().msec());
}
FakeRadioDataControl::~FakeRadioDataControl()
{
}
bool FakeRadioDataControl::isAvailable() const
{
return true;
}
QtMultimedia::AvailabilityError FakeRadioDataControl::availabilityError() const
{
return QtMultimedia::NoError;
}
QString FakeRadioDataControl::stationId() const
{
return "12345678";
}
QRadioData::ProgramType FakeRadioDataControl::programType() const
{
return QRadioData::Drama;
}
QString FakeRadioDataControl::programTypeName() const
{
return "Cycling";
}
QString FakeRadioDataControl::stationName() const
{
return "Fake FM";
}
void FakeRadioDataControl::rdsUpdate()
{
static int index = 0;
QString rdsStrings[] = {
"This is radio Fake FM",
"There is nothing to listen to here",
"Please remain calm" };
setradioText(rdsStrings[index%3]);
index++;
}
void FakeRadioDataControl::setradioText(QString text)
{
m_radioText = text;
emit radioTextChanged(m_radioText);
}
QString FakeRadioDataControl::radioText() const
{
return m_radioText;
}
void FakeRadioDataControl::setAlternativeFrequenciesEnabled(bool enabled)
{
m_alternativeFrequenciesEnabled = enabled;
}
bool FakeRadioDataControl::isAlternativeFrequenciesEnabled() const
{
return m_alternativeFrequenciesEnabled;
}
QRadioData::Error FakeRadioDataControl::error() const
{
return QRadioData::NoError;
}
QString FakeRadioDataControl::errorString() const
{
return QString();
}
void FakeRadioDataControl::initializeProgramTypeMapping()
{
m_programTypeMapRDS[0] = QRadioData::Undefined;
m_programTypeMapRDS[1] = QRadioData::News;
m_programTypeMapRDS[2] = QRadioData::CurrentAffairs;
m_programTypeMapRDS[3] = QRadioData::Information;
m_programTypeMapRDS[4] = QRadioData::Sport;
m_programTypeMapRDS[5] = QRadioData::Education;
m_programTypeMapRDS[6] = QRadioData::Drama;
m_programTypeMapRDS[7] = QRadioData::Culture;
m_programTypeMapRDS[8] = QRadioData::Science;
m_programTypeMapRDS[9] = QRadioData::Varied;
m_programTypeMapRDS[10] = QRadioData::PopMusic;
m_programTypeMapRDS[11] = QRadioData::RockMusic;
m_programTypeMapRDS[12] = QRadioData::EasyListening;
m_programTypeMapRDS[13] = QRadioData::LightClassical;
m_programTypeMapRDS[14] = QRadioData::SeriousClassical;
m_programTypeMapRDS[15] = QRadioData::OtherMusic;
m_programTypeMapRDS[16] = QRadioData::Weather;
m_programTypeMapRDS[17] = QRadioData::Finance;
m_programTypeMapRDS[18] = QRadioData::ChildrensProgrammes;
m_programTypeMapRDS[19] = QRadioData::SocialAffairs;
m_programTypeMapRDS[20] = QRadioData::Religion;
m_programTypeMapRDS[21] = QRadioData::PhoneIn;
m_programTypeMapRDS[22] = QRadioData::Travel;
m_programTypeMapRDS[23] = QRadioData::Leisure;
m_programTypeMapRDS[24] = QRadioData::JazzMusic;
m_programTypeMapRDS[25] = QRadioData::CountryMusic;
m_programTypeMapRDS[26] = QRadioData::NationalMusic;
m_programTypeMapRDS[27] = QRadioData::OldiesMusic;
m_programTypeMapRDS[28] = QRadioData::FolkMusic;
m_programTypeMapRDS[29] = QRadioData::Documentary;
m_programTypeMapRDS[30] = QRadioData::AlarmTest;
m_programTypeMapRDS[31] = QRadioData::Alarm;
m_programTypeMapRBDS[0] = QRadioData::Undefined,
m_programTypeMapRBDS[1] = QRadioData::News;
m_programTypeMapRBDS[2] = QRadioData::Information;
m_programTypeMapRBDS[3] = QRadioData::Sport;
m_programTypeMapRBDS[4] = QRadioData::Talk;
m_programTypeMapRBDS[5] = QRadioData::RockMusic;
m_programTypeMapRBDS[6] = QRadioData::ClassicRock;
m_programTypeMapRBDS[7] = QRadioData::AdultHits;
m_programTypeMapRBDS[8] = QRadioData::SoftRock;
m_programTypeMapRBDS[9] = QRadioData::Top40;
m_programTypeMapRBDS[10] = QRadioData::CountryMusic;
m_programTypeMapRBDS[11] = QRadioData::OldiesMusic;
m_programTypeMapRBDS[12] = QRadioData::Soft;
m_programTypeMapRBDS[13] = QRadioData::Nostalgia;
m_programTypeMapRBDS[14] = QRadioData::JazzMusic;
m_programTypeMapRBDS[15] = QRadioData::Classical;
m_programTypeMapRBDS[16] = QRadioData::RhythmAndBlues;
m_programTypeMapRBDS[17] = QRadioData::SoftRhythmAndBlues;
m_programTypeMapRBDS[18] = QRadioData::Language;
m_programTypeMapRBDS[19] = QRadioData::ReligiousMusic;
m_programTypeMapRBDS[20] = QRadioData::ReligiousTalk;
m_programTypeMapRBDS[21] = QRadioData::Personality;
m_programTypeMapRBDS[22] = QRadioData::Public;
m_programTypeMapRBDS[23] = QRadioData::College;
m_programTypeMapRBDS[24] = QRadioData::Undefined;
m_programTypeMapRBDS[25] = QRadioData::Undefined;
m_programTypeMapRBDS[26] = QRadioData::Undefined;
m_programTypeMapRBDS[27] = QRadioData::Undefined;
m_programTypeMapRBDS[28] = QRadioData::Undefined;
m_programTypeMapRBDS[29] = QRadioData::Weather;
m_programTypeMapRBDS[30] = QRadioData::AlarmTest;
m_programTypeMapRBDS[31] = QRadioData::Alarm;
}
bool FakeRadioDataControl::usingRBDS()
{
switch ( QLocale::system().country() )
{
case QLocale::Canada:
case QLocale::Mexico:
case QLocale::UnitedStates:
return true;
default:
return false;
}
return false;
}
QRadioData::ProgramType FakeRadioDataControl::fromRawProgramType(int rawProgramType)
{
if ( usingRBDS() )
return m_programTypeMapRBDS.value(rawProgramType, QRadioData::Undefined);
return m_programTypeMapRDS.value(rawProgramType, QRadioData::Undefined);
}

View File

@@ -0,0 +1,96 @@
/****************************************************************************
**
** 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 FAKERADIODATACONTROL_H
#define FAKERADIODATACONTROL_H
#include <QtCore/qobject.h>
#include <QtCore/qtimer.h>
#include <QtCore/qdatetime.h>
#include <qradiodatacontrol.h>
QT_USE_NAMESPACE
class FakeRadioService;
class FakeRadioDataControl : public QRadioDataControl
{
Q_OBJECT
public:
FakeRadioDataControl(QObject *parent = 0);
~FakeRadioDataControl();
bool isAvailable() const;
QtMultimedia::AvailabilityError availabilityError() const;
QString stationId() const;
QRadioData::ProgramType programType() const;
QString programTypeName() const;
QString stationName() const;
QString radioText() const;
void setAlternativeFrequenciesEnabled(bool enabled);
bool isAlternativeFrequenciesEnabled() const;
QRadioData::Error error() const;
QString errorString() const;
private slots:
void rdsUpdate();
private:
void setradioText(QString);
void initializeProgramTypeMapping();
bool usingRBDS();
QRadioData::ProgramType fromRawProgramType(int rawProgramType);
private: //data
bool m_alternativeFrequenciesEnabled;
QString m_radioText;
QTimer *m_rdsTimer;
QMap<int, QRadioData::ProgramType> m_programTypeMapRDS;
QMap<int, QRadioData::ProgramType> m_programTypeMapRBDS;
};
#endif // FAKERADIODATACONTROL_H

View File

@@ -46,21 +46,46 @@
#include "fakeradioservice.h"
#include "fakeradiotunercontrol.h"
#include "fakeradiodatacontrol.h"
Q_GLOBAL_STATIC( QMutex, fakeRadioServiceMutex );
FakeRadioService* FakeRadioService::m_instance = 0;
int FakeRadioService::m_referenceCount = 0;
FakeRadioService::FakeRadioService(QObject *parent):
QMediaService(parent)
{
m_control = new FakeRadioTunerControl(this);
m_tunerControl = new FakeRadioTunerControl(this);
m_dataControl = new FakeRadioDataControl(this);
}
FakeRadioService::~FakeRadioService()
{
}
FakeRadioService* FakeRadioService::instance()
{
QMutexLocker lock(fakeRadioServiceMutex());
if (!m_instance)
m_instance = new FakeRadioService;
m_referenceCount++;
return m_instance;
}
void FakeRadioService::release()
{
QMutexLocker lock(fakeRadioServiceMutex());
m_referenceCount--;
if (m_referenceCount == 0)
delete m_instance;
}
QMediaControl *FakeRadioService::requestControl(const char* name)
{
if (qstrcmp(name,QRadioTunerControl_iid) == 0)
return m_control;
return m_tunerControl;
if (qstrcmp(name,QRadioDataControl_iid) == 0)
return m_dataControl;
return 0;
}

View File

@@ -43,25 +43,36 @@
#define FAKERADIOSERVICE_H
#include <QtCore/qobject.h>
#include <QMutex>
#include <qmediaservice.h>
QT_USE_NAMESPACE
class FakeRadioTunerControl;
class FakeRadioDataControl;
class FakeRadioService : public QMediaService
{
Q_OBJECT
public:
private:
FakeRadioService(QObject *parent = 0);
~FakeRadioService();
public:
static FakeRadioService* instance();
void release();
QMediaControl *requestControl(const char* name);
void releaseControl(QMediaControl *);
private:
FakeRadioTunerControl *m_control;
static FakeRadioService* m_instance;
static int m_referenceCount;
FakeRadioTunerControl *m_tunerControl;
FakeRadioDataControl *m_dataControl;
};
#endif // FAKERADIOSERVICE_H

View File

@@ -59,14 +59,16 @@ QStringList FakeRadioServicePlugin::keys() const
QMediaService* FakeRadioServicePlugin::create(QString const& key)
{
if (key == QLatin1String(Q_MEDIASERVICE_RADIO))
return new FakeRadioService;
return FakeRadioService::instance();
return 0;
}
void FakeRadioServicePlugin::release(QMediaService *service)
{
delete service;
FakeRadioService* fakeRadio = qobject_cast<FakeRadioService*>(service);
if (fakeRadio)
fakeRadio->release();
}
QList<QByteArray> FakeRadioServicePlugin::devices(const QByteArray &service) const

View File

@@ -60,10 +60,16 @@ FakeRadioTunerControl::FakeRadioTunerControl(QObject *parent)
m_searching = false;
m_forward = true;
m_searchMode = QRadioTuner::SearchFast;
m_piCounter = 0;
m_searchTimer = new QTimer(this);
m_searchTimer->setSingleShot(true);
connect(m_searchTimer, SIGNAL(timeout()), this, SLOT(searchEnded()));
m_allStationSeekTimer = new QTimer(this);
m_allStationSeekTimer->setSingleShot(true);
connect(m_allStationSeekTimer,SIGNAL(timeout()),this,SLOT(newStationFound()));
QTimer::singleShot(300, this, SLOT(delayedInit()));
qsrand(QTime::currentTime().msec());
@@ -269,6 +275,42 @@ void FakeRadioTunerControl::searchBackward()
performSearch();
}
void FakeRadioTunerControl::searchAllStations(QRadioTuner::SearchMode searchMode)
{
m_searchMode = searchMode;
m_seekingStartFreq = m_currentFreq;
m_searching = true;
m_allStationSeekTimer->start(10);
emit searchingChanged(m_searching);
}
void FakeRadioTunerControl::newStationFound()
{
QPair<int, int> fRange = frequencyRange(m_currentBand);
if (m_currentFreq == fRange.second)
m_currentFreq = fRange.first;
else
m_currentFreq += 100000;
emit frequencyChanged(m_currentFreq);
// There are 200 ticks, we want to find average of 5 stations per scan
if (qrand() < (RAND_MAX/40)) {
QString programmeId;
if (m_searchMode == QRadioTuner::SearchGetStationId)
programmeId = QString("FakeProgrammeID") + QString::number(m_piCounter++);
emit stationFound(m_currentFreq, programmeId);
}
if (m_currentFreq == m_seekingStartFreq) {
m_searching = false;
emit searchingChanged(m_searching);
}else {
m_allStationSeekTimer->start(10);
}
}
void FakeRadioTunerControl::start()
{
if (isAvailable() && m_state != QRadioTuner::ActiveState) {

View File

@@ -90,6 +90,7 @@ public:
void searchForward();
void searchBackward();
void searchAllStations(QRadioTuner::SearchMode searchMode = QRadioTuner::SearchFast);
void start();
void stop();
@@ -101,6 +102,7 @@ private slots:
void delayedInit();
void performSearch();
void searchEnded();
void newStationFound();
private: //data
QRadioTuner::State m_state;
@@ -108,6 +110,7 @@ private: //data
qint64 m_freqMin;
qint64 m_freqMax;
qint64 m_currentFreq;
qint64 m_seekingStartFreq;
bool m_stereo;
QRadioTuner::StereoMode m_stereoMode;
int m_signalStrength;
@@ -117,7 +120,11 @@ private: //data
// searching
bool m_searching;
bool m_forward;
QRadioTuner::SearchMode m_searchMode;
int m_piCounter;
QTimer *m_searchTimer;
QTimer *m_allStationSeekTimer;
};
#endif // FAKERADIOTUNERCONTROL_H