diff options
Diffstat (limited to 'src/plugins/symbian/openmaxal')
51 files changed, 9788 insertions, 0 deletions
diff --git a/src/plugins/symbian/openmaxal/mediaplayer/mediaplayer.pri b/src/plugins/symbian/openmaxal/mediaplayer/mediaplayer.pri new file mode 100644 index 000000000..7c6843e19 --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediaplayer/mediaplayer.pri @@ -0,0 +1,36 @@ +INCLUDEPATH += $$PWD + +LIBS += \ + -lws32 \ + -lcone + +#DEFINES += USE_VIDEOPLAYERUTILITY + +HEADERS += \ + $$PWD/qxametadatacontrol.h \ + $$PWD/qxamediastreamscontrol.h \ + $$PWD/qxamediaplayercontrol.h \ + $$PWD/qxaplaymediaservice.h \ + $$PWD/qxaplaysession.h \ + $$PWD/xaplaysessioncommon.h \ + $$PWD/qxavideowidgetcontrol.h \ + $$PWD/qxavideowindowcontrol.h \ + $$PWD/qxawidget.h \ + $$PWD/xaplaysessionimpl.h + +SOURCES += \ + $$PWD/qxamediaplayercontrol.cpp \ + $$PWD/qxametadatacontrol.cpp \ + $$PWD/qxamediastreamscontrol.cpp \ + $$PWD/qxaplaymediaservice.cpp \ + $$PWD/qxaplaysession.cpp \ + $$PWD/qxavideowidgetcontrol.cpp \ + $$PWD/qxavideowindowcontrol.cpp \ + $$PWD/qxawidget.cpp \ + $$PWD/xaplaysessionimpl.cpp + +# check for USE_VIDEOPLAYERUTILITY +contains(DEFINES, USE_VIDEOPLAYERUTILITY) { + message("Using VideoPlayerUtility instead of OpenMAX AL.") + LIBS += -lmediaclientvideo +} diff --git a/src/plugins/symbian/openmaxal/mediaplayer/qxamediaplayercontrol.cpp b/src/plugins/symbian/openmaxal/mediaplayer/qxamediaplayercontrol.cpp new file mode 100644 index 000000000..ee192105b --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediaplayer/qxamediaplayercontrol.cpp @@ -0,0 +1,288 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include <QtCore/qurl.h> +#include "qxamediaplayercontrol.h" +#include "qxaplaysession.h" +#include "qxacommon.h" + +QXAMediaPlayerControl::QXAMediaPlayerControl(QXAPlaySession *session, QObject *parent) + :QMediaPlayerControl(parent), mSession(session) +{ + QT_TRACE_FUNCTION_ENTRY; + connect(mSession, SIGNAL(mediaChanged(const QMediaContent &)), + this, SIGNAL(mediaChanged(const QMediaContent& ))); + connect(mSession, SIGNAL(durationChanged(qint64)), + this, SIGNAL(durationChanged(qint64))); + connect(mSession, SIGNAL(positionChanged(qint64)), + this, SIGNAL(positionChanged(qint64))); + connect(mSession, SIGNAL(stateChanged(QMediaPlayer::State)), + this, SIGNAL(stateChanged(QMediaPlayer::State))); + connect(mSession, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus)), + this, SIGNAL(mediaStatusChanged(QMediaPlayer::MediaStatus))); + connect(mSession, SIGNAL(volumeChanged(int)), + this, SIGNAL(volumeChanged(int))); + connect(mSession, SIGNAL(mutedChanged(bool)), + this, SIGNAL(mutedChanged(bool))); + connect(mSession, SIGNAL(audioAvailableChanged(bool)), + this, SIGNAL(audioAvailableChanged(bool))); + connect(mSession, SIGNAL(videoAvailableChanged(bool)), + this, SIGNAL(videoAvailableChanged(bool))); + connect(mSession,SIGNAL(bufferStatusChanged(int)), + this, SIGNAL(bufferStatusChanged(int))); + connect(mSession, SIGNAL(seekableChanged(bool)), + this, SIGNAL(seekableChanged(bool))); + connect(mSession, SIGNAL(availablePlaybackRangesChanged(const QMediaTimeRange&)), + this, SIGNAL(availablePlaybackRangesChanged(const QMediaTimeRange&))); + connect(mSession, SIGNAL(playbackRateChanged(qreal)), + this, SIGNAL(playbackRateChanged(qreal))); + connect(mSession, SIGNAL(error(int, const QString &)), + this, SIGNAL(error(int, const QString &))); + QT_TRACE_FUNCTION_EXIT; +} + +QXAMediaPlayerControl::~QXAMediaPlayerControl() +{ + QT_TRACE_FUNCTION_ENTRY_EXIT; +} + +QMediaPlayer::State QXAMediaPlayerControl::state() const +{ + QT_TRACE_FUNCTION_ENTRY; + QMediaPlayer::State retVal = QMediaPlayer::StoppedState; + RET_s_IF_p_IS_NULL(mSession, retVal); + retVal = mSession->state(); + QT_TRACE_FUNCTION_EXIT; + return retVal; +} + +QMediaPlayer::MediaStatus QXAMediaPlayerControl::mediaStatus() const +{ + QT_TRACE_FUNCTION_ENTRY; + QMediaPlayer::MediaStatus retVal = QMediaPlayer::NoMedia; + RET_s_IF_p_IS_NULL(mSession, retVal); + retVal = mSession->mediaStatus(); + QT_TRACE_FUNCTION_EXIT; + return retVal; +} + +qint64 QXAMediaPlayerControl::duration() const +{ + QT_TRACE_FUNCTION_ENTRY; + qint64 retVal = 0; + RET_s_IF_p_IS_NULL(mSession, retVal); + retVal = mSession->duration(); + QT_TRACE_FUNCTION_EXIT; + return retVal; +} + +qint64 QXAMediaPlayerControl::position() const +{ + QT_TRACE_FUNCTION_ENTRY; + qint64 retVal = 0; + RET_s_IF_p_IS_NULL(mSession, retVal); + retVal = mSession->position(); + QT_TRACE_FUNCTION_EXIT; + return retVal; +} + +void QXAMediaPlayerControl::setPosition(qint64 pos) +{ + QT_TRACE_FUNCTION_ENTRY; + RET_IF_p_IS_NULL(mSession); + mSession->setPosition(pos); + QT_TRACE_FUNCTION_EXIT; +} + +int QXAMediaPlayerControl::volume() const +{ + QT_TRACE_FUNCTION_ENTRY; + int retVal = 0; + RET_s_IF_p_IS_NULL(mSession, retVal); + retVal = mSession->volume(); + QT_TRACE_FUNCTION_EXIT; + return retVal; +} + +void QXAMediaPlayerControl::setVolume(int volume) +{ + QT_TRACE_FUNCTION_ENTRY; + RET_IF_p_IS_NULL(mSession); + mSession->setVolume(volume); + QT_TRACE_FUNCTION_EXIT; +} + +bool QXAMediaPlayerControl::isMuted() const +{ + QT_TRACE_FUNCTION_ENTRY; + bool retVal = false; + RET_s_IF_p_IS_NULL(mSession, retVal); + retVal = mSession->isMuted(); + QT_TRACE_FUNCTION_EXIT; + return retVal; +} + +void QXAMediaPlayerControl::setMuted(bool muted) +{ + QT_TRACE_FUNCTION_ENTRY; + RET_IF_p_IS_NULL(mSession); + mSession->setMuted(muted); + QT_TRACE_FUNCTION_EXIT; +} + +int QXAMediaPlayerControl::bufferStatus() const +{ + QT_TRACE_FUNCTION_ENTRY; + int retVal = 0; + RET_s_IF_p_IS_NULL(mSession, retVal); + retVal = mSession->bufferStatus(); + QT_TRACE_FUNCTION_EXIT; + return retVal; +} + +bool QXAMediaPlayerControl::isAudioAvailable() const +{ + QT_TRACE_FUNCTION_ENTRY; + bool retVal = false; + RET_s_IF_p_IS_NULL(mSession, retVal); + retVal = mSession->isAudioAvailable(); + QT_TRACE_FUNCTION_EXIT; + return retVal; +} + +bool QXAMediaPlayerControl::isVideoAvailable() const +{ + QT_TRACE_FUNCTION_ENTRY; + bool retVal = false; + RET_s_IF_p_IS_NULL(mSession, retVal); + retVal = mSession->isVideoAvailable(); + QT_TRACE_FUNCTION_EXIT; + return retVal; +} + +bool QXAMediaPlayerControl::isSeekable() const +{ + QT_TRACE_FUNCTION_ENTRY; + bool retVal = false; + RET_s_IF_p_IS_NULL(mSession, retVal); + retVal = mSession->isSeekable(); + QT_TRACE_FUNCTION_EXIT; + return retVal; +} + +QMediaTimeRange QXAMediaPlayerControl::availablePlaybackRanges() const +{ + QT_TRACE_FUNCTION_ENTRY; + QMediaTimeRange retVal; + RET_s_IF_p_IS_NULL(mSession, retVal); + if (mSession->isSeekable()) + retVal.addInterval(0, mSession->duration()); + QT_TRACE_FUNCTION_EXIT; + return retVal; +} + +float QXAMediaPlayerControl::playbackRate() const +{ + QT_TRACE_FUNCTION_ENTRY; + float retVal = 0; + RET_s_IF_p_IS_NULL(mSession, retVal); + retVal = mSession->playbackRate(); + QT_TRACE_FUNCTION_EXIT; + return retVal; +} + +void QXAMediaPlayerControl::setPlaybackRate(float rate) +{ + QT_TRACE_FUNCTION_ENTRY; + RET_IF_p_IS_NULL(mSession); + mSession->setPlaybackRate(rate); + QT_TRACE_FUNCTION_EXIT; +} + +QMediaContent QXAMediaPlayerControl::media() const +{ + QT_TRACE_FUNCTION_ENTRY; + QMediaContent retVal; + RET_s_IF_p_IS_NULL(mSession, retVal); + retVal = mSession->media(); + QT_TRACE_FUNCTION_EXIT; + return retVal; +} + +const QIODevice *QXAMediaPlayerControl::mediaStream() const +{ + QT_TRACE_FUNCTION_ENTRY_EXIT; + return mStream; +} + +void QXAMediaPlayerControl::setMedia(const QMediaContent &content, QIODevice *stream) +{ + QT_TRACE_FUNCTION_ENTRY; + RET_IF_p_IS_NULL(mSession); + mSession->setMedia(content); + mStream = stream; + QT_TRACE_FUNCTION_EXIT; +} + +void QXAMediaPlayerControl::play() +{ + QT_TRACE_FUNCTION_ENTRY; + RET_IF_p_IS_NULL(mSession); + mSession->play(); + QT_TRACE_FUNCTION_EXIT; +} + +void QXAMediaPlayerControl::pause() +{ + QT_TRACE_FUNCTION_ENTRY; + RET_IF_p_IS_NULL(mSession); + mSession->pause(); + QT_TRACE_FUNCTION_EXIT; +} + +void QXAMediaPlayerControl::stop() +{ + QT_TRACE_FUNCTION_ENTRY; + RET_IF_p_IS_NULL(mSession); + mSession->stop(); + QT_TRACE_FUNCTION_EXIT; +} diff --git a/src/plugins/symbian/openmaxal/mediaplayer/qxamediaplayercontrol.h b/src/plugins/symbian/openmaxal/mediaplayer/qxamediaplayercontrol.h new file mode 100644 index 000000000..b9d7802bd --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediaplayer/qxamediaplayercontrol.h @@ -0,0 +1,99 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXAMEDIAPLAYERCONTROL_H +#define QXAMEDIAPLAYERCONTROL_H + +#include "qmediaplayercontrol.h" +#include "qmediaplayer.h" + +QT_USE_NAMESPACE + +class QXAPlaySession; + +class QXAMediaPlayerControl : public QMediaPlayerControl +{ + Q_OBJECT +public: + QXAMediaPlayerControl(QXAPlaySession *session, QObject *parent = 0); + ~QXAMediaPlayerControl(); + + QMediaPlayer::State state() const; + QMediaPlayer::MediaStatus mediaStatus() const; + + qint64 duration() const; + + qint64 position() const; + void setPosition(qint64 position); + + int volume() const; + void setVolume(int volume); + + bool isMuted() const; + void setMuted(bool muted); + + int bufferStatus() const; + + bool isAudioAvailable() const; + bool isVideoAvailable() const; + + bool isSeekable() const; + + QMediaTimeRange availablePlaybackRanges() const; + + float playbackRate() const; + void setPlaybackRate(float rate); + + QMediaContent media() const; + const QIODevice *mediaStream() const; + void setMedia(const QMediaContent&, QIODevice *); + + void play(); + void pause(); + void stop(); + + +private: + QXAPlaySession *mSession; + QIODevice *mStream; +}; + +#endif /* QXAMEDIAPLAYERCONTROL_H */ diff --git a/src/plugins/symbian/openmaxal/mediaplayer/qxamediastreamscontrol.cpp b/src/plugins/symbian/openmaxal/mediaplayer/qxamediastreamscontrol.cpp new file mode 100644 index 000000000..528fb1837 --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediaplayer/qxamediastreamscontrol.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include <QtCore/qurl.h> + +#include "qxamediastreamscontrol.h" +#include "qxaplaysession.h" +#include "qxacommon.h" + +QXAMediaStreamsControl::QXAMediaStreamsControl(QXAPlaySession *session, QObject *parent) + :QMediaStreamsControl(parent), mSession(session) +{ + QT_TRACE_FUNCTION_ENTRY; + connect(mSession, SIGNAL(activeStreamsChanged()), + this, SIGNAL(activeStreamsChanged())); + connect(mSession, SIGNAL(streamsChanged()), + this, SIGNAL(streamsChanged())); + QT_TRACE_FUNCTION_EXIT; +} + +QXAMediaStreamsControl::~QXAMediaStreamsControl() +{ + QT_TRACE_FUNCTION_ENTRY_EXIT; +} + +bool QXAMediaStreamsControl::isActive (int stream) +{ + RET_s_IF_p_IS_NULL(mSession, false); + return mSession->isStreamActive(stream); +} + +QVariant QXAMediaStreamsControl::metaData (int stream, QtMultimediaKit::MetaData key) +{ + QVariant var; + RET_s_IF_p_IS_NULL(mSession, var); + QT_TRACE_FUNCTION_ENTRY; + var = mSession->metaData(stream, key); + QT_TRACE_FUNCTION_EXIT; + return var; +} + +void QXAMediaStreamsControl::setActive (int stream, bool state) +{ + Q_UNUSED(stream); + Q_UNUSED(state); +} + +int QXAMediaStreamsControl::streamCount() +{ + RET_s_IF_p_IS_NULL(mSession, 0); + return mSession->streamCount(); +} + +QMediaStreamsControl::StreamType QXAMediaStreamsControl::streamType (int stream) +{ + RET_s_IF_p_IS_NULL(mSession, QMediaStreamsControl::UnknownStream); + return mSession->streamType(stream); +} + diff --git a/src/plugins/symbian/openmaxal/mediaplayer/qxamediastreamscontrol.h b/src/plugins/symbian/openmaxal/mediaplayer/qxamediastreamscontrol.h new file mode 100644 index 000000000..d77b89ca5 --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediaplayer/qxamediastreamscontrol.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#ifndef QXAMEDIASTREAMSCONTROL_H +#define QXAMEDIASTREAMSCONTROL_H + + + +#include <QStringList> +#include <QList> +#include <QVariant> +#include <QString> + +#include <qtmedianamespace.h> + +#include <qmediastreamscontrol.h> + +QT_USE_NAMESPACE + +class QXAPlaySession; + +class QXAMediaStreamsControl : public QMediaStreamsControl +{ + Q_OBJECT +public: + QXAMediaStreamsControl(QXAPlaySession *session, QObject *parent = 0); + ~QXAMediaStreamsControl(); + + bool isActive (int stream); + QVariant metaData (int stream, QtMultimediaKit::MetaData key); + void setActive (int stream, bool state); + int streamCount(); + QMediaStreamsControl::StreamType streamType (int stream); +private: + QXAPlaySession *mSession; +}; + +#endif //QXAMEDIASTREAMSCONTROL_H diff --git a/src/plugins/symbian/openmaxal/mediaplayer/qxametadatacontrol.cpp b/src/plugins/symbian/openmaxal/mediaplayer/qxametadatacontrol.cpp new file mode 100644 index 000000000..9c6b906cf --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediaplayer/qxametadatacontrol.cpp @@ -0,0 +1,131 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QtCore/qurl.h> + +#include "qxametadatacontrol.h" +#include "qxaplaysession.h" +#include "qxacommon.h" + +QXAMetaDataControl::QXAMetaDataControl(QXAPlaySession *session, QObject *parent) + :QMetaDataReaderControl(parent), mSession(session) +{ + QT_TRACE_FUNCTION_ENTRY; + connect(mSession, SIGNAL(metaDataAvailableChanged(bool)), + this, SIGNAL(metaDataAvailableChanged(bool))); + connect(mSession, SIGNAL(metaDataChanged()), + this, SIGNAL(metaDataChanged())); + QT_TRACE_FUNCTION_EXIT; +} + +QXAMetaDataControl::~QXAMetaDataControl() +{ + QT_TRACE_FUNCTION_ENTRY_EXIT; +} + +QStringList QXAMetaDataControl::availableExtendedMetaData ()const +{ + QStringList list; + RET_s_IF_p_IS_NULL(mSession, list); + QT_TRACE_FUNCTION_ENTRY; + list = mSession->availableExtendedMetaData(); + QT_TRACE_FUNCTION_EXIT; + return list; +} + +QList<QtMultimediaKit::MetaData> QXAMetaDataControl::availableMetaData () const +{ + QList<QtMultimediaKit::MetaData> list; + RET_s_IF_p_IS_NULL(mSession, list); + QT_TRACE_FUNCTION_ENTRY; + list = mSession->availableMetaData(); + QT_TRACE_FUNCTION_EXIT; + return list; +} + +QVariant QXAMetaDataControl::extendedMetaData(const QString & key ) const +{ + QVariant var; + RET_s_IF_p_IS_NULL(mSession, var); + QT_TRACE_FUNCTION_ENTRY; + var = mSession->extendedMetaData(key); + QT_TRACE_FUNCTION_EXIT; + return var; +} + +bool QXAMetaDataControl::isMetaDataAvailable() const +{ + RET_s_IF_p_IS_NULL(mSession, false); + QT_TRACE_FUNCTION_ENTRY_EXIT; + return mSession->isMetaDataAvailable(); +} + +bool QXAMetaDataControl::isWritable() const +{ + RET_s_IF_p_IS_NULL(mSession, false); + QT_TRACE_FUNCTION_ENTRY_EXIT; + return mSession->isWritable(); +} + +QVariant QXAMetaDataControl::metaData( QtMultimediaKit::MetaData key ) const +{ + QVariant var; + RET_s_IF_p_IS_NULL(mSession, var); + QT_TRACE_FUNCTION_ENTRY; + var = mSession->metaData(key); + QT_TRACE_FUNCTION_ENTRY_EXIT; + return var; +} + +void QXAMetaDataControl::setExtendedMetaData( const QString & key, const QVariant & value ) +{ + RET_IF_p_IS_NULL(mSession); + QT_TRACE_FUNCTION_ENTRY_EXIT; + return mSession->setExtendedMetaData(key,value); +} + +void QXAMetaDataControl::setMetaData( QtMultimediaKit::MetaData key, const QVariant & value ) +{ + RET_IF_p_IS_NULL(mSession); + QT_TRACE_FUNCTION_ENTRY_EXIT; + return mSession->setMetaData(key,value); +} + diff --git a/src/plugins/symbian/openmaxal/mediaplayer/qxametadatacontrol.h b/src/plugins/symbian/openmaxal/mediaplayer/qxametadatacontrol.h new file mode 100644 index 000000000..8904a5ff4 --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediaplayer/qxametadatacontrol.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXAMETADATACONTROL_H +#define QXAMETADATACONTROL_H + + + +#include <QStringList> +#include <QList> +#include <QVariant> +#include <QString> + +#include <qmetadatareadercontrol.h> +#include <qtmedianamespace.h> +QT_USE_NAMESPACE + +class QXAPlaySession; + +class QXAMetaDataControl : public QMetaDataReaderControl +{ + Q_OBJECT +public: + QXAMetaDataControl(QXAPlaySession *session, QObject *parent = 0); + ~QXAMetaDataControl(); + + QStringList availableExtendedMetaData () const; + QList<QtMultimediaKit::MetaData> availableMetaData () const; + QVariant extendedMetaData(const QString & key ) const; + bool isMetaDataAvailable() const; + bool isWritable() const; + QVariant metaData( QtMultimediaKit::MetaData key ) const; + void setExtendedMetaData( const QString & key, const QVariant & value ); + void setMetaData( QtMultimediaKit::MetaData key, const QVariant & value ); + +private: + QXAPlaySession *mSession; +}; + +#endif //QXAMETADATACONTROL_H diff --git a/src/plugins/symbian/openmaxal/mediaplayer/qxaplaymediaservice.cpp b/src/plugins/symbian/openmaxal/mediaplayer/qxaplaymediaservice.cpp new file mode 100644 index 000000000..f2d3c4b15 --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediaplayer/qxaplaymediaservice.cpp @@ -0,0 +1,117 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + + +#include <QString> +#include "qxaplaymediaservice.h" +#include "qxaplaysession.h" +#include "qxamediaplayercontrol.h" +#include "qxacommon.h" +#include "qxavideowidgetcontrol.h" +#include "qxavideowindowcontrol.h" +#include "qxametadatacontrol.h" +#include "qxamediastreamscontrol.h" + +QXAPlayMediaService::QXAPlayMediaService(QObject *parent) : QMediaService(parent) +{ + mSession = NULL; + mMediaPlayerControl = NULL; + mVideowidgetControl = NULL; + mVideoWindowControl = NULL; + mMetaDataControl = NULL; + mMediaStreamsControl = NULL; + + mSession = new QXAPlaySession(this); + mMediaPlayerControl = new QXAMediaPlayerControl(mSession, this); + mMetaDataControl = new QXAMetaDataControl(mSession, this); + mMediaStreamsControl = new QXAMediaStreamsControl(mSession, this); +} + +QXAPlayMediaService::~QXAPlayMediaService() +{ + QT_TRACE_FUNCTION_ENTRY_EXIT; +} + +QMediaControl *QXAPlayMediaService::requestControl(const char *name) +{ + if (qstrcmp(name, QMediaPlayerControl_iid) == 0) { + return mMediaPlayerControl; + } + else if (qstrcmp(name, QVideoWidgetControl_iid) == 0) { + if (!mVideowidgetControl) { + mVideowidgetControl = new QXAVideoWidgetControl(mSession, this); + if (mSession && mVideowidgetControl) + mSession->setVideoWidgetControl(mVideowidgetControl); + } + return mVideowidgetControl; + } + else if (qstrcmp(name, QVideoWindowControl_iid) == 0) { + if (!mVideoWindowControl) { + mVideoWindowControl = new QXAVideoWindowControl(mSession, this); + if (mSession && mVideoWindowControl) + mSession->setVideoWindowControl(mVideoWindowControl); + } + return mVideoWindowControl; + } + else if (qstrcmp(name,QMetaDataReaderControl_iid) == 0) { + return mMetaDataControl; + } + else if (qstrcmp(name,QMediaStreamsControl_iid) == 0) { + return mMediaStreamsControl; + } + + return 0; +} + +void QXAPlayMediaService::releaseControl(QMediaControl *control) +{ + if (control == mVideowidgetControl) { + if (mSession) + mSession->unsetVideoWidgetControl(qobject_cast<QXAVideoWidgetControl*>(control)); + mVideowidgetControl = NULL; + } + else if (control == mVideoWindowControl) { + if (mSession) + mSession->unsetVideoWindowControl(qobject_cast<QXAVideoWindowControl*>(control)); + mVideoWindowControl = NULL; + } +} + diff --git a/src/plugins/symbian/openmaxal/mediaplayer/qxaplaymediaservice.h b/src/plugins/symbian/openmaxal/mediaplayer/qxaplaymediaservice.h new file mode 100644 index 000000000..4a344b087 --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediaplayer/qxaplaymediaservice.h @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXAPLAYMEDIASERVICE_H +#define QXAPLAYMEDIASERVICE_H + +#include <QtCore/qobject.h> +#include <qmediaservice.h> + +QT_USE_NAMESPACE + +class QXAPlaySession; +class QXAMediaPlayerControl; +class QXAVideoWidgetControl; +class QXAVideoWindowControl; +class QXAMetaDataControl; +class QXAMediaStreamsControl; + +class QXAPlayMediaService : public QMediaService +{ + Q_OBJECT +public: + QXAPlayMediaService(QObject *parent = 0); + ~QXAPlayMediaService(); + QMediaControl *requestControl(const char *name); + void releaseControl( QMediaControl *control); +private: + QXAPlaySession *mSession; + QXAMediaPlayerControl *mMediaPlayerControl; + QXAVideoWidgetControl *mVideowidgetControl; + QXAVideoWindowControl *mVideoWindowControl; + QXAMetaDataControl *mMetaDataControl; + QXAMediaStreamsControl *mMediaStreamsControl; +}; + +#endif /* QXAPLAYMEDIASERVICE_H */ diff --git a/src/plugins/symbian/openmaxal/mediaplayer/qxaplaysession.cpp b/src/plugins/symbian/openmaxal/mediaplayer/qxaplaysession.cpp new file mode 100644 index 000000000..2254a9363 --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediaplayer/qxaplaysession.cpp @@ -0,0 +1,610 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QMetaType> +#include "qxaplaysession.h" +#include "xaplaysessionimpl.h" +#include "qxacommon.h" +#include <COECNTRL.H> + +QXAPlaySession::QXAPlaySession(QObject *parent):QObject(parent), +m_state(QMediaPlayer::StoppedState), +m_mediaStatus(QMediaPlayer::NoMedia), +mSeekable(-1), +mNumStreams(0), +mbAudioAvailable(EFalse), +mbVideoAvailable(EFalse), +mImpl(NULL), +mVideowidgetControl(NULL), +mWidgetCtrlWindow(NULL), +mWidgetCtrlWindowId(NULL), +mVideoWindowControl(NULL), +mWindowCtrlWindow(NULL), +mWindowCtrlWindowId(NULL), +mWsSession(&(CCoeEnv::Static()->WsSession())) +{ + QT_TRACE_FUNCTION_ENTRY; + mImpl = new XAPlaySessionImpl(*this); + + if (mImpl && (mImpl->postConstruct() != KErrNone)) { + delete mImpl; + mImpl = NULL; + QT_TRACE1("Error initializing implementation"); + } + + if (!mImpl) + emit error(QMediaPlayer::ResourceError, tr("Service has not been started")); + + QT_TRACE_FUNCTION_EXIT; +} + +QXAPlaySession::~QXAPlaySession() +{ + QT_TRACE_FUNCTION_ENTRY; + delete mImpl; + QT_TRACE_FUNCTION_EXIT; +} + +void QXAPlaySession::setVideoWidgetControl( QXAVideoWidgetControl * videoWidgetControl ) +{ + QT_TRACE_FUNCTION_ENTRY; + if (mVideowidgetControl) { + disconnect(mVideowidgetControl, SIGNAL(widgetUpdated()), + this, SLOT(videoWidgetControlWidgetUpdated())); + RWindow* window = static_cast<RWindow*>(mVideowidgetControl->videoWidgetWId()->DrawableWindow()); + mImpl->removeNativeDisplay(window, mWsSession); + } + mVideowidgetControl = videoWidgetControl; + if (mVideowidgetControl) + connect(mVideowidgetControl, SIGNAL(widgetUpdated()), + this, SLOT(videoWidgetControlWidgetUpdated())); + QT_TRACE_FUNCTION_EXIT; +} + +void QXAPlaySession::unsetVideoWidgetControl( QXAVideoWidgetControl * videoWidgetControl ) +{ + QT_TRACE_FUNCTION_ENTRY; + if ((mVideowidgetControl == videoWidgetControl) && (mImpl)) { + disconnect(mVideowidgetControl, SIGNAL(widgetUpdated()), + this, SLOT(videoWidgetControlWidgetUpdated())); + RWindow* window = static_cast<RWindow*>(mVideowidgetControl->videoWidgetWId()->DrawableWindow()); + mImpl->removeNativeDisplay(window, mWsSession); + } + mVideowidgetControl = NULL; + mWidgetCtrlWindow = NULL; + mWidgetCtrlWindowId = NULL; + QT_TRACE_FUNCTION_EXIT; +} + +void QXAPlaySession::setVideoWindowControl( QXAVideoWindowControl * videoWindowControl ) +{ + QT_TRACE_FUNCTION_ENTRY; + if (mVideoWindowControl) { + disconnect(mVideoWindowControl, SIGNAL(windowUpdated()), + this, SLOT(videoWindowControlWindowUpdated())); + RWindow* window = static_cast<RWindow*>(mVideoWindowControl->winId()->DrawableWindow()); + mImpl->removeNativeDisplay(window, mWsSession); + } + mVideoWindowControl = videoWindowControl; + if (mVideoWindowControl) { + connect(mVideoWindowControl, SIGNAL(windowUpdated()), + this, SLOT(videoWindowControlWindowUpdated())); + videoWindowControlWindowUpdated(); + } + QT_TRACE_FUNCTION_EXIT; +} + +void QXAPlaySession::unsetVideoWindowControl( QXAVideoWindowControl * videoWindowControl ) +{ + QT_TRACE_FUNCTION_ENTRY; + if ((mVideoWindowControl == videoWindowControl) && (mImpl)) { + disconnect(mVideoWindowControl, SIGNAL(windowUpdated()), + this, SLOT(videoWindowControlWindowUpdated())); + RWindow* window = static_cast<RWindow*>(mVideoWindowControl->winId()->DrawableWindow()); + mImpl->removeNativeDisplay(window, mWsSession); + } + mVideoWindowControl = NULL; + mWindowCtrlWindow = NULL; + mWindowCtrlWindowId = NULL; + QT_TRACE_FUNCTION_EXIT; +} + +qint64 QXAPlaySession::duration() +{ + TInt64 dur(0); + if (mImpl) + mImpl->duration(dur); + + return (qint64)dur; +} + +qint64 QXAPlaySession::position() +{ + TInt64 pos(0); + if (mImpl) + mImpl->position(pos); + + return (qint64)pos; +} + +void QXAPlaySession::setPosition(qint64 ms) +{ + if (mImpl) { + qint64 currPos = position(); + mImpl->seek(ms); + + if(currPos != position()) { + emit positionChanged(position()); + + if(position()>=duration()) { + setMediaStatus(QMediaPlayer::EndOfMedia); + stop(); + } + } + } +} + +int QXAPlaySession::volume() +{ + if(mImpl) { + TInt v(0); + + TInt err = mImpl->volume(v); + if(KErrNone == err) + return v; + } + + return 50; +} + +void QXAPlaySession::setVolume(int v) +{ + if(mImpl) { + if(v != volume()) { + TInt err = mImpl->setVolume(v); + if(KErrNone == err) + emit volumeChanged(volume()); + } + } +} + + +bool QXAPlaySession::isMuted() +{ + if(mImpl) { + TBool bCurrMute = EFalse; + TInt err = mImpl->getMute(bCurrMute); + if(err == KErrNone) + return bCurrMute; + } + + return EFalse; +} + +void QXAPlaySession::setMuted(bool muted) +{ + if(muted != isMuted()) + { + if(mImpl) + { + TInt err = mImpl->setMute(muted); + + if(KErrNone == err) + { + emit mutedChanged(muted); + } + } + } +} + +int QXAPlaySession::bufferStatus() +{ + if(mImpl) { + TInt fillLevel = 0; + TInt err = mImpl->bufferStatus(fillLevel); + if(err == KErrNone) + return fillLevel; + } + + return 100;//default +} + +bool QXAPlaySession::isAudioAvailable() +{ + return mbAudioAvailable; +} + +bool QXAPlaySession::isVideoAvailable() +{ + return mbVideoAvailable; +} + +bool QXAPlaySession::isSeekable() +{ + return ((mSeekable==1) || (mSeekable==-1));//default seekable +} + +float QXAPlaySession::playbackRate() +{ + if(mImpl) { + TReal32 currPBRate = 0.0; + TInt ret = mImpl->getPlaybackRate(currPBRate); + if(ret == KErrNone) + return currPBRate; + } + + return 1.0; +} + +void QXAPlaySession::setPlaybackRate(float rate) +{ + if(mImpl) { + TReal32 currPBRate = 0.0; + TInt ret = mImpl->getPlaybackRate(currPBRate); + if( (ret == KErrNone) && + (rate!=currPBRate)) { + ret = mImpl->setPlaybackRate(rate); + if(ret == KErrNone) + emit playbackRateChanged(rate); + } + } +} + +QMediaContent QXAPlaySession::media() +{ + QT_TRACE_FUNCTION_ENTRY_EXIT; + return mMediaContent; +} + +void QXAPlaySession::setMedia(const QMediaContent& media) +{ + QT_TRACE_FUNCTION_ENTRY; + RET_IF_p_IS_NULL_EMIT_PLAYER_RESOURCE_ERROR(mImpl); + + if (media.isNull() || + mMediaContent == media) { + return; + } + + setMediaStatus(QMediaPlayer::NoMedia); + + QString urlStr = media.canonicalUrl().toString(); + TPtrC16 urlPtr(reinterpret_cast<const TUint16*>(urlStr.utf16())); + + setMediaStatus(QMediaPlayer::LoadingMedia); + if (mImpl->load(urlPtr) == 0) { + setMediaStatus(QMediaPlayer::LoadedMedia); + emit error(QMediaPlayer::NoError, ""); + mMediaContent = media; + setPlayerState(QMediaPlayer::StoppedState); + emit mediaChanged(mMediaContent); + + if(mImpl->isMetaDataAvailable()) { + emit metaDataAvailableChanged(true); + emit metaDataChanged(); + } + else { + emit metaDataAvailableChanged(false); + } + } + else { + setMediaStatus(QMediaPlayer::NoMedia); + emit error(QMediaPlayer::ResourceError, tr("Unable to load media")); + } + QT_TRACE_FUNCTION_EXIT; +} + +void QXAPlaySession::play() +{ + if (mImpl) { + setMediaStatus(QMediaPlayer::BufferingMedia); + + TInt err = mImpl->play(); + if (err != KErrNone) { + setMediaStatus(QMediaPlayer::NoMedia); + RET_IF_ERROR(err); + } + setPlayerState(QMediaPlayer::PlayingState); + + TInt fillLevel = 0; + err = mImpl->bufferStatus(fillLevel); + RET_IF_ERROR(err); + if (fillLevel == 100) { + setMediaStatus(QMediaPlayer::BufferedMedia); + } + } +} + +void QXAPlaySession::pause() +{ + if (mImpl) { + TInt err = mImpl->pause(); + RET_IF_ERROR(err); + setPlayerState(QMediaPlayer::PausedState); + } +} + +void QXAPlaySession::stop() +{ + if (mImpl) { + TInt err = mImpl->stop(); + RET_IF_ERROR(err); + setPlayerState(QMediaPlayer::StoppedState); + } +} + +void QXAPlaySession::cbDurationChanged(TInt64 new_dur) +{ + emit durationChanged((qint64)new_dur); +} + +void QXAPlaySession::cbPositionChanged(TInt64 new_pos) +{ + emit positionChanged((qint64)new_pos); +} + +void QXAPlaySession::cbSeekableChanged(TBool seekable) +{ + if( (mSeekable==-1) || + (seekable != (TBool)mSeekable)) { + mSeekable = seekable?1:0; + emit seekableChanged((bool)seekable); + } +} + +void QXAPlaySession::cbPlaybackStopped(TInt err) +{ + if (err) { + emit error(QMediaPlayer::ResourceError, tr("Resources Unavailable")); + SIGNAL_EMIT_TRACE1("emit error(QMediaPlayer::ResourceError, tr(\"Resources Unavailable\"))"); + emit positionChanged(position()); + setPlayerState(QMediaPlayer::StoppedState); + setMediaStatus(QMediaPlayer::NoMedia); + } + else { + setMediaStatus(QMediaPlayer::EndOfMedia); + /* Set player state to Stopped */ + stop(); + } +} + +void QXAPlaySession::cbPrefetchStatusChanged() +{ + if(mImpl) { + TInt fillLevel = 0; + TInt err = mImpl->bufferStatus(fillLevel); + if(err == KErrNone) { + emit bufferStatusChanged(fillLevel); + + if(fillLevel == 100) + setMediaStatus(QMediaPlayer::BufferedMedia); + else if(fillLevel ==0) + setMediaStatus(QMediaPlayer::StalledMedia); + } + } +} + +void QXAPlaySession::cbStreamInformation(TBool bFirstTime) +{ + updateStreamInfo(bFirstTime); +} + + + +void QXAPlaySession::videoWidgetControlWidgetUpdated() +{ + QT_TRACE_FUNCTION_ENTRY; + if (mVideowidgetControl) { + WId newId = mVideowidgetControl->videoWidgetWId(); + if ((newId != NULL) && (newId != mWidgetCtrlWindowId)) { + mWidgetCtrlWindow = static_cast<RWindow*>(newId->DrawableWindow()); + if (mWidgetCtrlWindowId == NULL) + mImpl->addNativeDisplay(mWidgetCtrlWindow, mWsSession); + else + mImpl->updateNativeDisplay(mWidgetCtrlWindow, mWsSession); + mWidgetCtrlWindowId = newId; + } + } + QT_TRACE_FUNCTION_EXIT; +} + +void QXAPlaySession::videoWindowControlWindowUpdated() +{ + QT_TRACE_FUNCTION_ENTRY; + if (mVideoWindowControl) { + WId newId = mVideoWindowControl->winId(); + if ((newId != NULL) && (newId != mWindowCtrlWindowId)) { + mWidgetCtrlWindow = static_cast<RWindow*>(newId->DrawableWindow()); + if (mWindowCtrlWindowId == NULL) + mImpl->addNativeDisplay(mWidgetCtrlWindow, mWsSession); + else + mImpl->updateNativeDisplay(mWidgetCtrlWindow, mWsSession); + mWindowCtrlWindowId = newId; + } + } + QT_TRACE_FUNCTION_EXIT; +} + +void QXAPlaySession::setMediaStatus(QMediaPlayer::MediaStatus status) +{ + if (m_mediaStatus != status) { + m_mediaStatus = status; + emit mediaStatusChanged(status); + } +} + +void QXAPlaySession::setPlayerState(QMediaPlayer::State state) +{ + if (m_state != state) { + m_state = state; + emit stateChanged(m_state); + } +} + +QStringList QXAPlaySession::availableExtendedMetaData () const +{ + QStringList list; + RET_s_IF_p_IS_NULL(mImpl, list); + list = mImpl->availableExtendedMetaData(); + return list; +} + +QList<QtMultimediaKit::MetaData> QXAPlaySession::availableMetaData () const +{ + QList<QtMultimediaKit::MetaData> list; + RET_s_IF_p_IS_NULL(mImpl, list); + return mImpl->availableMetaData(); +} + +QVariant QXAPlaySession::extendedMetaData(const QString & key ) const +{ + QVariant var; + RET_s_IF_p_IS_NULL(mImpl, var); + return mImpl->extendedMetaData(key); +} + +bool QXAPlaySession::isMetaDataAvailable() const +{ + RET_s_IF_p_IS_NULL(mImpl, false); + return mImpl->isMetaDataAvailable(); +} + +bool QXAPlaySession::isWritable() const +{ + RET_s_IF_p_IS_NULL(mImpl, false); + return mImpl->isWritable(); +} + +QVariant QXAPlaySession::metaData( QtMultimediaKit::MetaData key ) const +{ + QVariant var; + RET_s_IF_p_IS_NULL(mImpl, var); + return mImpl->metaData(key); +} + +void QXAPlaySession::setExtendedMetaData( const QString & key, const QVariant & value ) +{ + RET_IF_p_IS_NULL(mImpl); + mImpl->setExtendedMetaData(key, value); +} + +void QXAPlaySession::setMetaData( QtMultimediaKit::MetaData key, const QVariant & value ) +{ + RET_IF_p_IS_NULL(mImpl); + mImpl->setMetaData(key, value); +} + +void QXAPlaySession::updateStreamInfo(TBool emitSignal) +{ + if(mImpl) { + mNumStreams = 0; + TInt ret = mImpl->numMediaStreams(mNumStreams); + if(ret == KErrNone) { + TBool bAudioAvailable = EFalse;//lcoal variable + TBool bVideoAvailable = EFalse;//lcvoal variable + + for(TUint i = 0; i < mNumStreams; i++) { + QMediaStreamsControl::StreamType strType; + mImpl->streamType(i, strType); + if(strType == QMediaStreamsControl::AudioStream) + bAudioAvailable = ETrue; + else if(strType == QMediaStreamsControl::VideoStream) + bVideoAvailable = ETrue; + } + + if(emitSignal || (bAudioAvailable != mbAudioAvailable)) { + emit audioAvailableChanged(bAudioAvailable); + mbAudioAvailable = bAudioAvailable; + } + + if(emitSignal || (bVideoAvailable != mbVideoAvailable)) { + emit videoAvailableChanged(bVideoAvailable); + mbVideoAvailable = bVideoAvailable; + } + + emit streamsChanged(); + } + } +} + +bool QXAPlaySession::isStreamActive ( int stream ) +{ + RET_s_IF_p_IS_NULL(mImpl, false); + TBool isActive = EFalse; + mImpl->isStreamActive(stream,isActive); + return isActive; +} + +QVariant QXAPlaySession::metaData ( int /*stream*/, QtMultimediaKit::MetaData key ) +{ + return this->metaData(key); +} + +int QXAPlaySession::streamCount() +{ + return mNumStreams; +} + +QMediaStreamsControl::StreamType QXAPlaySession::streamType ( int stream ) +{ + QMediaStreamsControl::StreamType strType = QMediaStreamsControl::UnknownStream; + RET_s_IF_p_IS_NULL(mImpl, strType); + if(mImpl->streamType(stream, strType) == KErrNone) { + return strType; + } + + return QMediaStreamsControl::UnknownStream; +} + +////AspectRatioMode +void QXAPlaySession::setAspectRatioMode(Qt::AspectRatioMode aspectRatioMode) +{ + RET_IF_p_IS_NULL(mImpl); + mImpl->setAspectRatioMode(aspectRatioMode); +} + +Qt::AspectRatioMode QXAPlaySession::getAspectRatioMode() +{ + RET_s_IF_p_IS_NULL(mImpl, Qt::KeepAspectRatio); + return mImpl->getAspectRatioMode(); +} + + diff --git a/src/plugins/symbian/openmaxal/mediaplayer/qxaplaysession.h b/src/plugins/symbian/openmaxal/mediaplayer/qxaplaysession.h new file mode 100644 index 000000000..0d366518f --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediaplayer/qxaplaysession.h @@ -0,0 +1,192 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXAPLAYSESSION_H +#define QXAPLAYSESSION_H + +#include <QObject> +#include <QUrl> +#include <qtmedianamespace.h> + +#include "qxamediaplayercontrol.h" +#include "qxametadatacontrol.h" +#include "qmediaplayer.h" +#include "xaplaysessioncommon.h" +#include "qxavideowidgetcontrol.h" +#include "qxavideowindowcontrol.h" +#include "qmediastreamscontrol.h" + + +QT_USE_NAMESPACE + +class XAPlaySessionImpl; +class RWindow; +class RWsSession; +class QXAVideoWidgetControl; + +class QXAPlaySession : public QObject, + public XAPlayObserver +{ + Q_OBJECT +public: + QXAPlaySession(QObject *parent); + virtual ~QXAPlaySession(); + + void setVideoWidgetControl( QXAVideoWidgetControl * videoWidgetControl ); + void unsetVideoWidgetControl( QXAVideoWidgetControl * videoWidgetControl ); + void setVideoWindowControl( QXAVideoWindowControl * videoWindowControl ); + void unsetVideoWindowControl( QXAVideoWindowControl * videoWindowControl ); + + //QXAMediaPlayerControl + QMediaPlayer::State state() const { return m_state; } + QMediaPlayer::MediaStatus mediaStatus() const { return m_mediaStatus; } + qint64 duration(); + qint64 position(); + void setPosition(qint64 position); + int volume(); + void setVolume(int volume); + bool isMuted(); + void setMuted(bool muted); + int bufferStatus(); + bool isAudioAvailable(); + bool isVideoAvailable(); + bool isSeekable(); + float playbackRate(); + void setPlaybackRate(float rate); + QMediaContent media(); + void setMedia(const QMediaContent& media); + void play(); + void pause(); + void stop(); + + // Callback from XAPlaySessionImpl + void cbDurationChanged(TInt64 new_dur); + void cbPositionChanged(TInt64 new_pos); + void cbSeekableChanged(TBool seekable); + void cbPlaybackStopped(TInt error); + void cbPrefetchStatusChanged(); + void cbStreamInformation(TBool); + + //MetadataControl methods + QStringList availableExtendedMetaData () const; + QList<QtMultimediaKit::MetaData> availableMetaData () const; + QVariant extendedMetaData(const QString & key ) const; + bool isMetaDataAvailable() const; + bool isWritable() const; + QVariant metaData( QtMultimediaKit::MetaData key ) const; + void setExtendedMetaData( const QString & key, const QVariant & value ); + void setMetaData( QtMultimediaKit::MetaData key, const QVariant & value ); + + //QMediaStreamsControl + bool isStreamActive ( int stream ) ; + QVariant metaData ( int stream, QtMultimediaKit::MetaData key ); + int streamCount(); + QMediaStreamsControl::StreamType streamType ( int stream ); + + //QVideoWidgetControl + void setAspectRatioMode(Qt::AspectRatioMode); + Qt::AspectRatioMode getAspectRatioMode(); + +public Q_SLOTS: + void videoWidgetControlWidgetUpdated(); + void videoWindowControlWindowUpdated(); + +Q_SIGNALS: + void mediaChanged(const QMediaContent& content); + void durationChanged(qint64 duration); + void positionChanged(qint64 position); + void stateChanged(QMediaPlayer::State newState); + void mediaStatusChanged(QMediaPlayer::MediaStatus status); + void volumeChanged(int volume); + void mutedChanged(bool muted); + void audioAvailableChanged(bool audioAvailable); + void videoAvailableChanged(bool videoAvailable); + void bufferStatusChanged(int percentFilled); + void seekableChanged(bool); + void availablePlaybackRangesChanged(const QMediaTimeRange&); + void error(int errorCode, const QString &errorString); + void playbackRateChanged(qreal rate); + + //metadata + void metaDataAvailableChanged(bool); + void metaDataChanged(); + void writableChanged(bool); + + //QMediaStreamsControl + void streamsChanged(); + void activeStreamsChanged(); + +private: + void setMediaStatus(QMediaPlayer::MediaStatus); + void setPlayerState(QMediaPlayer::State state); + void updateStreamInfo(TBool emitSignal = EFalse); + +private: + QMediaPlayer::State m_state; + QMediaPlayer::MediaStatus m_mediaStatus; + + QMap<QString,QVariant> m_tags; + QList< QMap<QString,QVariant> > m_streamProperties; + + //seekable + int mSeekable; //-1 =unintialized, 0=nonseekable, 1=seekable + + //StreamInfo + TUint mNumStreams; + TBool mbAudioAvailable; + TBool mbVideoAvailable; + + //Own + XAPlaySessionImpl* mImpl; + + // Does not own + QXAVideoWidgetControl *mVideowidgetControl; + RWindow *mWidgetCtrlWindow; + WId mWidgetCtrlWindowId; + QXAVideoWindowControl *mVideoWindowControl; + RWindow *mWindowCtrlWindow; + WId mWindowCtrlWindowId; + RWsSession *mWsSession; + + QMediaContent mMediaContent; +}; + +#endif /* QXAPLAYSESSION_H */ diff --git a/src/plugins/symbian/openmaxal/mediaplayer/qxavideowidgetcontrol.cpp b/src/plugins/symbian/openmaxal/mediaplayer/qxavideowidgetcontrol.cpp new file mode 100644 index 000000000..6e9c833fd --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediaplayer/qxavideowidgetcontrol.cpp @@ -0,0 +1,182 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qxavideowidgetcontrol.h" +#include "qxacommon.h" +#include "qxawidget.h" +#include <QEvent> + +QXAVideoWidgetControl::QXAVideoWidgetControl(QXAPlaySession *session, QObject *parent) + : QVideoWidgetControl(parent), mSession(session) +{ + QT_TRACE_FUNCTION_ENTRY; + mWidget = new QXAWidget; + if (mWidget) + mWidget->installEventFilter(this); + QT_TRACE_FUNCTION_EXIT; +} + +QXAVideoWidgetControl::~QXAVideoWidgetControl() +{ + QT_TRACE_FUNCTION_ENTRY; + delete mWidget; + QT_TRACE_FUNCTION_EXIT; +} + +QWidget* QXAVideoWidgetControl::videoWidget() +{ + QT_TRACE_FUNCTION_ENTRY_EXIT; + return mWidget; +} + +Qt::AspectRatioMode QXAVideoWidgetControl::aspectRatioMode() const +{ + QT_TRACE_FUNCTION_ENTRY; + RET_s_IF_p_IS_NULL(mSession, Qt::IgnoreAspectRatio); + QT_TRACE_FUNCTION_EXIT; + return mSession->getAspectRatioMode(); +} + +void QXAVideoWidgetControl::setAspectRatioMode(Qt::AspectRatioMode mode) +{ + QT_TRACE_FUNCTION_ENTRY; + RET_IF_p_IS_NULL(mSession); + mSession->setAspectRatioMode(mode); + QT_TRACE_FUNCTION_EXIT; +} + +bool QXAVideoWidgetControl::isFullScreen() const +{ + QT_TRACE_FUNCTION_ENTRY; + bool retVal = false; + RET_s_IF_p_IS_NULL(mWidget, retVal); + retVal = mWidget->isFullScreen(); + QT_TRACE_FUNCTION_EXIT; + return retVal; +} + +void QXAVideoWidgetControl::setFullScreen(bool fullScreen) +{ + QT_TRACE_FUNCTION_ENTRY; + RET_IF_p_IS_NULL(mWidget); + if (fullScreen == mWidget->isFullScreen()) + return; + else if (fullScreen) + mWidget->showFullScreen(); + else + mWidget->showNormal(); + + emit fullScreenChanged(fullScreen); + + QT_TRACE_FUNCTION_EXIT; +} + +int QXAVideoWidgetControl::brightness() const +{ + QT_TRACE_FUNCTION_ENTRY_EXIT; + return 0; +} + +void QXAVideoWidgetControl::setBrightness(int brightness) +{ + QT_TRACE_FUNCTION_ENTRY_EXIT; + Q_UNUSED(brightness); +} + +int QXAVideoWidgetControl::contrast() const +{ + QT_TRACE_FUNCTION_ENTRY_EXIT; + return 0; +} + +void QXAVideoWidgetControl::setContrast(int contrast) +{ + QT_TRACE_FUNCTION_ENTRY_EXIT; + Q_UNUSED(contrast); +} + +int QXAVideoWidgetControl::hue() const +{ + QT_TRACE_FUNCTION_ENTRY_EXIT; + return 0; +} + +void QXAVideoWidgetControl::setHue(int hue) +{ + QT_TRACE_FUNCTION_ENTRY_EXIT; + Q_UNUSED(hue); +} + +int QXAVideoWidgetControl::saturation() const +{ + QT_TRACE_FUNCTION_ENTRY_EXIT; + return 0; +} + +void QXAVideoWidgetControl::setSaturation(int saturation) +{ + QT_TRACE_FUNCTION_ENTRY_EXIT; + Q_UNUSED(saturation); +} + +bool QXAVideoWidgetControl::eventFilter(QObject *object, QEvent *event) +{ + if (object == mWidget) { + if ( event->type() == QEvent::Resize + || event->type() == QEvent::Move + || event->type() == QEvent::WinIdChange + || event->type() == QEvent::ParentChange + || event->type() == QEvent::Show) { + emit widgetUpdated(); + } + } + return false; +} + +WId QXAVideoWidgetControl::videoWidgetWId() +{ + if (mWidget->internalWinId()) + return mWidget->internalWinId(); + else if (mWidget->effectiveWinId()) + return mWidget->effectiveWinId(); + + return NULL; +} diff --git a/src/plugins/symbian/openmaxal/mediaplayer/qxavideowidgetcontrol.h b/src/plugins/symbian/openmaxal/mediaplayer/qxavideowidgetcontrol.h new file mode 100644 index 000000000..7a0eda765 --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediaplayer/qxavideowidgetcontrol.h @@ -0,0 +1,93 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXAVIDEOWIDGETCONTROL_H +#define QXAVIDEOWIDGETCONTROL_H + +#include <QObject> +#include <qvideowidgetcontrol.h> +#include "qxaplaysession.h" + +QT_USE_NAMESPACE + +class QXAWidget; + +class QXAVideoWidgetControl : public QVideoWidgetControl +{ + Q_OBJECT +public: + QXAVideoWidgetControl(QXAPlaySession *session, QObject *parent = 0); + ~QXAVideoWidgetControl(); + + QWidget *videoWidget(); + + Qt::AspectRatioMode aspectRatioMode() const; + void setAspectRatioMode(Qt::AspectRatioMode mode); + + bool isFullScreen() const; + void setFullScreen(bool fullScreen); + + int brightness() const; + void setBrightness(int brightness); + + int contrast() const; + void setContrast(int contrast); + + int hue() const; + void setHue(int hue); + + int saturation() const; + void setSaturation(int saturation); + + bool eventFilter(QObject *object, QEvent *event); + + WId videoWidgetWId(); + +Q_SIGNALS: + void widgetUpdated(); + +private: + QXAPlaySession *mSession; + QXAWidget *mWidget; + +}; + +#endif // QXAVIDEOWIDGETCONTROL_H diff --git a/src/plugins/symbian/openmaxal/mediaplayer/qxavideowindowcontrol.cpp b/src/plugins/symbian/openmaxal/mediaplayer/qxavideowindowcontrol.cpp new file mode 100644 index 000000000..c19b949ac --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediaplayer/qxavideowindowcontrol.cpp @@ -0,0 +1,222 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qxavideowindowcontrol.h" +#include "qxacommon.h" +#include <QEvent> +#include "qxaplaysession.h" + +QXAVideoWindowControl::QXAVideoWindowControl(QXAPlaySession* session, QObject *parent) + :QVideoWindowControl(parent), + mWid(NULL), + mWidget(NULL), + mAspectRatioMode(Qt::IgnoreAspectRatio), + mSession(session) +{ + QT_TRACE_FUNCTION_ENTRY_EXIT; +} + +QXAVideoWindowControl::~QXAVideoWindowControl() +{ + QT_TRACE_FUNCTION_ENTRY; + if (mWidget) + mWidget->removeEventFilter(this); + QT_TRACE_FUNCTION_EXIT; +} + +WId QXAVideoWindowControl::winId() const +{ + QT_TRACE_FUNCTION_ENTRY_EXIT; + return mWid; +} + +void QXAVideoWindowControl::setWinId(WId id) +{ + QT_TRACE_FUNCTION_ENTRY; + if (mWid != id) { + if (mWidget) + mWidget->removeEventFilter(this); + mWid = id; + mWidget = QWidget::find(mWid); + if (mWidget) + mWidget->installEventFilter(this); + emit windowUpdated(); + } + QT_TRACE_FUNCTION_EXIT; +} + +QRect QXAVideoWindowControl::displayRect() const +{ + QT_TRACE_FUNCTION_ENTRY_EXIT; + return mDisplayRect; +} + +void QXAVideoWindowControl::setDisplayRect(const QRect &rect) +{ + QT_TRACE_FUNCTION_ENTRY; + mDisplayRect = rect; + QT_TRACE_FUNCTION_EXIT; +} + +bool QXAVideoWindowControl::isFullScreen() const +{ + QT_TRACE_FUNCTION_ENTRY; + bool retVal(false); + if (mWidget) + retVal = mWidget->isFullScreen(); + QT_TRACE_FUNCTION_EXIT; + return retVal; +} + +void QXAVideoWindowControl::setFullScreen(bool fullScreen) +{ + QT_TRACE_FUNCTION_ENTRY; + if (mWidget && (fullScreen != mWidget->isFullScreen())) { + if (fullScreen) + mWidget->showFullScreen(); + else + mWidget->showNormal(); + emit fullScreenChanged(fullScreen); + } + QT_TRACE_FUNCTION_EXIT; +} + +void QXAVideoWindowControl::repaint() +{ +} + +QSize QXAVideoWindowControl::nativeSize() const +{ + QT_TRACE_FUNCTION_ENTRY; + QSize size(0, 0); + RET_s_IF_p_IS_NULL(mSession, size); + QVariant sizeBundle = mSession->metaData(QtMultimediaKit::Resolution); + QString metadata = sizeBundle.toString(); + if (!metadata.isNull() && !metadata.isEmpty()) { + int xIndex = metadata.indexOf('x'); + if (xIndex > 0) { + size.setWidth(metadata.left(xIndex).toInt()); + xIndex = metadata.length() - (xIndex + 1); + if (xIndex > 0) + size.setHeight(metadata.right(xIndex).toInt()); + } + } + QT_TRACE_FUNCTION_EXIT; + return size; +} + +Qt::AspectRatioMode QXAVideoWindowControl::aspectRatioMode() const +{ + QT_TRACE_FUNCTION_ENTRY; + RET_s_IF_p_IS_NULL(mSession, Qt::IgnoreAspectRatio); + QT_TRACE_FUNCTION_EXIT; + return mSession->getAspectRatioMode(); +} + +void QXAVideoWindowControl::setAspectRatioMode(Qt::AspectRatioMode mode) +{ + QT_TRACE_FUNCTION_ENTRY; + RET_IF_p_IS_NULL(mSession); + mSession->setAspectRatioMode(mode); + QT_TRACE_FUNCTION_EXIT; +} + +int QXAVideoWindowControl::brightness() const +{ + QT_TRACE_FUNCTION_ENTRY_EXIT; + return 0; +} + +void QXAVideoWindowControl::setBrightness(int brightness) +{ + QT_TRACE_FUNCTION_ENTRY_EXIT; + Q_UNUSED(brightness); +} + +int QXAVideoWindowControl::contrast() const +{ + QT_TRACE_FUNCTION_ENTRY_EXIT; + return 0; +} + +void QXAVideoWindowControl::setContrast(int contrast) +{ + QT_TRACE_FUNCTION_ENTRY_EXIT; + Q_UNUSED(contrast); +} + +int QXAVideoWindowControl::hue() const +{ + QT_TRACE_FUNCTION_ENTRY_EXIT; + return 0; +} + +void QXAVideoWindowControl::setHue(int hue) +{ + QT_TRACE_FUNCTION_ENTRY_EXIT; + Q_UNUSED(hue); +} + +int QXAVideoWindowControl::saturation() const +{ + QT_TRACE_FUNCTION_ENTRY_EXIT; + return 0; +} + +void QXAVideoWindowControl::setSaturation(int saturation) +{ + QT_TRACE_FUNCTION_ENTRY_EXIT; + Q_UNUSED(saturation); +} + +bool QXAVideoWindowControl::eventFilter(QObject *object, QEvent *event) +{ + if (object == mWidget) { + if (event->type() == QEvent::Resize + || event->type() == QEvent::Move + || event->type() == QEvent::WinIdChange + || event->type() == QEvent::ParentChange + || event->type() == QEvent::Show) { + emit windowUpdated(); + } + } + return false; +} diff --git a/src/plugins/symbian/openmaxal/mediaplayer/qxavideowindowcontrol.h b/src/plugins/symbian/openmaxal/mediaplayer/qxavideowindowcontrol.h new file mode 100644 index 000000000..879349822 --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediaplayer/qxavideowindowcontrol.h @@ -0,0 +1,105 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXAVIDEOWINDOWCONTROL_H +#define QXAVIDEOWINDOWCONTROL_H + +#include <QObject> +#include <QVideoWindowControl> + +QT_USE_NAMESPACE + +class QXAPlaySession; + +class QXAVideoWindowControl : public QVideoWindowControl +{ + Q_OBJECT + +public: + QXAVideoWindowControl(QXAPlaySession* session, QObject *parent = 0); + ~QXAVideoWindowControl(); + + // QVideoWindowControl virtual functions + WId winId() const; + void setWinId(WId id); + + QRect displayRect() const; + void setDisplayRect(const QRect &rect); + + bool isFullScreen() const; + void setFullScreen(bool fullScreen); + + void repaint(); + + QSize nativeSize() const; + + Qt::AspectRatioMode aspectRatioMode() const; + void setAspectRatioMode(Qt::AspectRatioMode mode); + + int brightness() const; + void setBrightness(int brightness); + + int contrast() const; + void setContrast(int contrast); + + int hue() const; + void setHue(int hue); + + int saturation() const; + void setSaturation(int saturation); + + //Callback function to receive event from Qt framework + //for object represented by mWid + bool eventFilter(QObject *object, QEvent *event); + +Q_SIGNALS: + void windowUpdated(); + +private: + WId mWid; + QWidget* mWidget; /* QWidget represented by mWid */ + QRect mDisplayRect; + Qt::AspectRatioMode mAspectRatioMode; + + QXAPlaySession* mSession; +}; + +#endif /* QXAVIDEOWINDOWCONTROL_H */ diff --git a/src/plugins/symbian/openmaxal/mediaplayer/qxawidget.cpp b/src/plugins/symbian/openmaxal/mediaplayer/qxawidget.cpp new file mode 100644 index 000000000..4685226fd --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediaplayer/qxawidget.cpp @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qxawidget.h" +#include <coemain.h> + +QXAWidget::QXAWidget(QWidget *parent) + : QWidget(parent) +{ + setSizePolicy(QSizePolicy::Expanding, QSizePolicy::Expanding); + setAttribute(Qt::WA_OpaquePaintEvent, true); + setAttribute(Qt::WA_NoSystemBackground, true); + setAutoFillBackground(false); + setPalette(QPalette(Qt::black)); + /* Initialize the native window*/ + winId(); +} + +QXAWidget::~QXAWidget() +{ +} + +void QXAWidget::paintEvent(QPaintEvent *event) +{ + Q_UNUSED(event); +} diff --git a/src/plugins/symbian/openmaxal/mediaplayer/qxawidget.h b/src/plugins/symbian/openmaxal/mediaplayer/qxawidget.h new file mode 100644 index 000000000..d36be1fa4 --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediaplayer/qxawidget.h @@ -0,0 +1,63 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXAWIDGET_H +#define QXAWIDGET_H + +#include <QObject> +#include <qwidget.h> + +QT_USE_NAMESPACE + +class QXAWidget : public QWidget +{ + Q_OBJECT + +public: + QXAWidget(QWidget *parent = 0); + virtual ~QXAWidget(); + +protected: + void paintEvent(QPaintEvent *event); +}; + + +#endif /* QXAWIDGET_H */ diff --git a/src/plugins/symbian/openmaxal/mediaplayer/xaplaysessioncommon.h b/src/plugins/symbian/openmaxal/mediaplayer/xaplaysessioncommon.h new file mode 100644 index 000000000..a9497e475 --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediaplayer/xaplaysessioncommon.h @@ -0,0 +1,58 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef XAPLAYSESSIONCOMMON_H +#define XAPLAYSESSIONCOMMON_H + +#include <e32base.h> + +class XAPlayObserver + { +public: + virtual void cbDurationChanged(TInt64 new_dur) = 0; + virtual void cbPositionChanged(TInt64 new_pos) = 0; + virtual void cbSeekableChanged(TBool seekable) = 0; + virtual void cbPlaybackStopped(TInt error) = 0; + virtual void cbPrefetchStatusChanged() = 0; + virtual void cbStreamInformation(TBool bFirstTime) = 0; + }; + +#endif /*XAPLAYSESSIONCOMMON_H*/ diff --git a/src/plugins/symbian/openmaxal/mediaplayer/xaplaysessionimpl.cpp b/src/plugins/symbian/openmaxal/mediaplayer/xaplaysessionimpl.cpp new file mode 100644 index 000000000..88a06807f --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediaplayer/xaplaysessionimpl.cpp @@ -0,0 +1,1259 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QString> +#include <QVariant> +#include <QList> +#include <QStringList> +#include <QImage> + +#include "xaplaysessionimpl.h" +#include "xaplaysessioncommon.h" +#include "xacommon.h" + +#ifdef USE_VIDEOPLAYERUTILITY +#include <COECNTRL.H> +#endif + +_LIT8(K8WAVMIMETYPE, "audio/wav"); + +#define RET_ERR_IF_ERR(e) \ + if (e != 0) {\ + return e; \ + } \ + +#define MAX_NUMBER_INTERFACES 20 +const TUint KPlayPosUpdatePeriod = 1000; + +/* Local functions for callback registation */ +void MediaPlayerCallback( XAObjectItf caller, + const void *pContext, + XAuint32 event, + XAresult result, + XAuint32 param, + void *pInterface); + +void PlayItfCallback( XAPlayItf caller, + void *pContext, + XAuint32 event); + +void PrefetchItfCallback( XAPrefetchStatusItf caller, + void * pContext, + XAuint32 event); + +void StreamInformationItfCallback( XAStreamInformationItf caller, + XAuint32 eventId, + XAuint32 streamIndex, + void * pEventData, + void * pContext); + +XAPlaySessionImpl::XAPlaySessionImpl(XAPlayObserver& parent) +:mParent(parent), +mEOEngine(NULL), +mMOPlayer(NULL), +mPlayItf(NULL), +mSeekItf(NULL), +mURIName(NULL), +mWAVMime(NULL), +mbMetadataAvailable(EFalse), +mbVolEnabled(EFalse), +mbMuteEnabled(EFalse), +mbPrefetchStatusChange(EFalse), +mbStreamInfoAvailable(EFalse), +mbPlaybackRateItfAvailable(EFalse), +mbScalable(EFalse), +mCurrAspectRatioMode(Qt::KeepAspectRatio) +#ifdef USE_VIDEOPLAYERUTILITY +, mVideoPlayUtil(NULL) +, mActiveSchedulerWait(NULL) +#endif +{ +} + +XAPlaySessionImpl::~XAPlaySessionImpl() +{ + if (mMOPlayer) + (*mMOPlayer)->Destroy(mMOPlayer); + + if (mEOEngine) + (*mEOEngine)->Destroy(mEOEngine); + + delete mURIName; + delete mWAVMime; + + //clear metadata datastructures + alKeyMap.clear(); + keyMap.clear(); + extendedKeyMap.clear(); + +#ifdef USE_VIDEOPLAYERUTILITY + delete mVideoPlayUtil; + if (mActiveSchedulerWait && \ + mActiveSchedulerWait->IsStarted()) { + mActiveSchedulerWait->AsyncStop(); + } + + delete mActiveSchedulerWait; +#endif + +} + +TInt XAPlaySessionImpl::postConstruct() +{ + TInt retVal; + XAresult xaRes; + XAEngineOption engineOption[] = { (XAuint32) XA_ENGINEOPTION_THREADSAFE, + (XAuint32) XA_BOOLEAN_TRUE + }; + XAEngineItf engineItf; + + mNativeDisplay.locatorType = XA_DATALOCATOR_NATIVEDISPLAY; + mNativeDisplay.hWindow = NULL; + mNativeDisplay.hDisplay = NULL; + mVideoSink.pLocator = (void*)&mNativeDisplay; + mVideoSink.pFormat = NULL; + + // Create and realize Engine object + xaRes = xaCreateEngine (&mEOEngine, 1, engineOption, 0, NULL, NULL); + retVal = mapError(xaRes, ETrue); + RET_ERR_IF_ERR(retVal); + xaRes = (*mEOEngine)->Realize(mEOEngine, XA_BOOLEAN_FALSE); + retVal = mapError(xaRes, ETrue); + RET_ERR_IF_ERR(retVal); + + // Create and realize Output Mix object to be used by player + xaRes = (*mEOEngine)->GetInterface(mEOEngine, XA_IID_ENGINE, (void**) &engineItf); + retVal = mapError(xaRes, ETrue); + RET_ERR_IF_ERR(retVal); + + TRAP(retVal, mWAVMime = HBufC8::NewL(K8WAVMIMETYPE().Length() + 1)); + RET_ERR_IF_ERR(retVal); + TPtr8 ptr = mWAVMime->Des(); + ptr = K8WAVMIMETYPE(); // copy uri name into local variable + ptr.PtrZ(); // append zero terminator to end of URI + +#ifdef USE_VIDEOPLAYERUTILITY + TRAP(retVal, mVideoPlayUtil = + CVideoPlayerUtility2::NewL( *this, + EMdaPriorityNormal, + EMdaPriorityPreferenceTimeAndQuality) + ); + mActiveSchedulerWait = new CActiveSchedulerWait; +#endif + + return retVal; +} + +TInt XAPlaySessionImpl::addNativeDisplay(RWindow* window, RWsSession* wssession) + { + TInt retVal(KErrNotReady); + + if (!mMOPlayer && !mPlayItf) { + // window can only be set before player creation + mNativeDisplay.locatorType = XA_DATALOCATOR_NATIVEDISPLAY; + mNativeDisplay.hWindow = (void*)window; + mNativeDisplay.hDisplay = (void*)wssession; + retVal = KErrNone; + } + return retVal; +} + +TInt XAPlaySessionImpl::updateNativeDisplay(RWindow* /*window*/, RWsSession* /*wssession*/) +{ + return KErrNone; +} + +TInt XAPlaySessionImpl::removeNativeDisplay(RWindow* /*window*/, RWsSession* /*wssession*/) +{ + return KErrNone; +} + +TInt XAPlaySessionImpl::load(const TDesC& aURI) +{ + TInt retVal; + XAresult xaRes; + XAEngineItf engineItf; + XADynamicSourceItf dynamicSourceItf; + XAboolean required[MAX_NUMBER_INTERFACES]; + XAInterfaceID iidArray[MAX_NUMBER_INTERFACES]; + XAuint32 noOfInterfaces = 0; + TInt i; + + XAmillisecond dur(0); + TPtr8 uriPtr(0,0,0); + TPtr8 mimeTypePtr(0,0,0); + +#ifdef USE_VIDEOPLAYERUTILITY + TRAP(m_VPError, mVideoPlayUtil->OpenFileL(_L("C:\\data\\test.3gp"))); + if (m_VPError) + return 0; + + if(!mActiveSchedulerWait->IsStarted()) + mActiveSchedulerWait->Start(); + + if (m_VPError) + return 0; + + mVideoPlayUtil->Prepare(); + + if(!mActiveSchedulerWait->IsStarted()) + mActiveSchedulerWait->Start(); + + return 0; +#endif + + delete mURIName; + mURIName = NULL; + TRAP(retVal, mURIName = HBufC8::NewL(aURI.Length()+1)); + RET_ERR_IF_ERR(retVal); + uriPtr.Set(mURIName->Des()); + + // This has to be done here since we can not destroy the Player + // in the Resource Lost callback. + if (mbMediaPlayerUnrealized) { + if (mMOPlayer) { + (*mMOPlayer)->Destroy(mMOPlayer); + mMOPlayer = NULL; + } + } + + //py uri name into local variable + //TODO fix copy issue from 16 bit to 8 bit + uriPtr.Copy(aURI); + + //If media player object already exists, just switch source + //using dynamic source interface + if (mMOPlayer && mPlayItf) { + dynamicSourceItf = NULL; + xaRes = (*mMOPlayer)->GetInterface(mMOPlayer, XA_IID_DYNAMICSOURCE, &dynamicSourceItf); + retVal = mapError(xaRes, ETrue); + RET_ERR_IF_ERR(retVal); + + //Setup the data source + //TODO Hard coded locator type + mUri.locatorType = XA_DATALOCATOR_URI; + + //append zero terminator to end of URI + mUri.URI = (XAchar*) uriPtr.PtrZ(); + + //TODO Hard coded locator type + mMime.containerType = XA_CONTAINERTYPE_WAV; + + //TODO Hard coded locator type + mMime.formatType = XA_DATAFORMAT_MIME; + mimeTypePtr.Set(mWAVMime->Des()); + mMime.mimeType = (XAchar*)mimeTypePtr.Ptr(); + mDataSource.pFormat = (void*)&mMime; + mDataSource.pLocator = (void*)&mUri; + + xaRes = (*dynamicSourceItf)->SetSource(dynamicSourceItf, &mDataSource); + retVal = mapError(xaRes, ETrue); + RET_ERR_IF_ERR(retVal); + } + else { // Create media player object + + // Setup the data source + // TODO Hard coded locator type + mUri.locatorType = XA_DATALOCATOR_URI; + + //append zero terminator to end of URI + mUri.URI = (XAchar*) uriPtr.PtrZ(); + + //TODO Hard coded locator type + mMime.containerType = XA_CONTAINERTYPE_WAV; + + //TODO Hard coded locator type + mMime.formatType = XA_DATAFORMAT_MIME; + mimeTypePtr.Set(mWAVMime->Des()); + mMime.mimeType = (XAchar*)mimeTypePtr.Ptr(); + mDataSource.pFormat = (void*)&mMime; + mDataSource.pLocator = (void*)&mUri; + + //Setup the audio data sink + mLocatorOutputDevice.locatorType = XA_DATALOCATOR_IODEVICE; + mLocatorOutputDevice.deviceType = 6; + mAudioSink.pLocator = (void*) &mLocatorOutputDevice; + mAudioSink.pFormat = NULL; + + //Init arrays required[] and iidArray[] + for (i = 0; i < MAX_NUMBER_INTERFACES; i++) { + required[i] = XA_BOOLEAN_FALSE; + iidArray[i] = XA_IID_NULL; + } + + noOfInterfaces = 0; + required[noOfInterfaces] = XA_BOOLEAN_FALSE; + iidArray[noOfInterfaces] = XA_IID_SEEK; + noOfInterfaces++; + required[noOfInterfaces] = XA_BOOLEAN_FALSE; + iidArray[noOfInterfaces] = XA_IID_DYNAMICSOURCE; + noOfInterfaces++; + required[noOfInterfaces] = XA_BOOLEAN_FALSE; + iidArray[noOfInterfaces] = XA_IID_METADATAEXTRACTION; + noOfInterfaces++; + required[noOfInterfaces] = XA_BOOLEAN_FALSE; + iidArray[noOfInterfaces] = XA_IID_NOKIALINEARVOLUME; + noOfInterfaces++; + required[noOfInterfaces] = XA_BOOLEAN_FALSE; + iidArray[noOfInterfaces] = XA_IID_NOKIAVOLUMEEXT; + noOfInterfaces++; + required[noOfInterfaces] = XA_BOOLEAN_FALSE; + iidArray[noOfInterfaces] = XA_IID_PREFETCHSTATUS; + noOfInterfaces++; + required[noOfInterfaces] = XA_BOOLEAN_FALSE; + iidArray[noOfInterfaces] = XA_IID_STREAMINFORMATION; + noOfInterfaces++; + required[noOfInterfaces] = XA_BOOLEAN_FALSE; + iidArray[noOfInterfaces] = XA_IID_PLAYBACKRATE; + noOfInterfaces++; + required[noOfInterfaces] = XA_BOOLEAN_FALSE; + iidArray[noOfInterfaces] = XA_IID_VIDEOPOSTPROCESSING; + noOfInterfaces++; + + xaRes = (*mEOEngine)->GetInterface(mEOEngine, XA_IID_ENGINE, (void**) &engineItf); + retVal = mapError(xaRes, ETrue); + RET_ERR_IF_ERR(retVal); + + xaRes = (*engineItf)->CreateMediaPlayer(engineItf, + &mMOPlayer, + &mDataSource, + NULL, + &mAudioSink, + &mVideoSink, + NULL, + NULL, + noOfInterfaces, + iidArray, + required); + retVal = mapError(xaRes, ETrue); + RET_ERR_IF_ERR(retVal); + + xaRes = (*mMOPlayer)->Realize(mMOPlayer, XA_BOOLEAN_FALSE); + retVal = mapError(xaRes, ETrue); + RET_ERR_IF_ERR(retVal); + + mbMediaPlayerUnrealized = FALSE; + + xaRes = (*mMOPlayer)->RegisterCallback(mMOPlayer, MediaPlayerCallback, (void*)this); + retVal = mapError(xaRes, ETrue); + RET_ERR_IF_ERR(retVal); + + xaRes = (*mMOPlayer)->GetInterface(mMOPlayer, XA_IID_PLAY, &mPlayItf); + retVal = mapError(xaRes, ETrue); + RET_ERR_IF_ERR(retVal); + + xaRes = (*mPlayItf)->RegisterCallback(mPlayItf, PlayItfCallback, (void*)this); + retVal = mapError(xaRes, ETrue); + RET_ERR_IF_ERR(retVal); + + xaRes = (*mPlayItf)->SetPositionUpdatePeriod(mPlayItf, (XAmillisecond)KPlayPosUpdatePeriod); + retVal = mapError(xaRes, ETrue); + RET_ERR_IF_ERR(retVal); + + xaRes = (*mPlayItf)->SetCallbackEventsMask( mPlayItf, + ( XA_PLAYEVENT_HEADATEND | + XA_PLAYEVENT_HEADATNEWPOS | + XA_PLAYEVENT_HEADMOVING ) + ); + retVal = mapError(xaRes, ETrue); + RET_ERR_IF_ERR(retVal); + + xaRes = (*mMOPlayer)->GetInterface(mMOPlayer, XA_IID_SEEK, &mSeekItf); + retVal = mapError(xaRes, ETrue); + + //Metadata + xaRes = (*mMOPlayer)->GetInterface(mMOPlayer, XA_IID_METADATAEXTRACTION, &mMetadataExtItf); + if(mapError(xaRes, ETrue)==KErrNone) { + mbMetadataAvailable = ETrue; + setupALKeyMap(); //done only once at creation of meadia player + } + + //volume + xaRes = (*mMOPlayer)->GetInterface(mMOPlayer, XA_IID_NOKIALINEARVOLUME, &mNokiaLinearVolumeItf); + if(mapError(xaRes, ETrue)==KErrNone) + mbVolEnabled = ETrue; + + xaRes = (*mMOPlayer)->GetInterface(mMOPlayer, XA_IID_NOKIAVOLUMEEXT, &mNokiaVolumeExtItf); + if(mapError(xaRes, ETrue)==KErrNone) + mbMuteEnabled = ETrue; + + //buffer status + xaRes = (*mMOPlayer)->GetInterface(mMOPlayer, XA_IID_PREFETCHSTATUS, &mPrefetchStatusItf); + if(mapError(xaRes, ETrue)==KErrNone) { + mbPrefetchStatusChange = ETrue; + (*mPrefetchStatusItf)->RegisterCallback(mPrefetchStatusItf, PrefetchItfCallback, (void*)this); + (*mPrefetchStatusItf)->SetCallbackEventsMask(mPrefetchStatusItf, XA_PREFETCHEVENT_FILLLEVELCHANGE); + } + + //stream information + xaRes = (*mMOPlayer)->GetInterface(mMOPlayer, XA_IID_STREAMINFORMATION, &mStreamInformationItf); + if(mapError(xaRes, ETrue)==KErrNone) { + mbStreamInfoAvailable = ETrue; + mParent.cbStreamInformation(ETrue); //indicate first time + (*mStreamInformationItf)->RegisterStreamChangeCallback(mStreamInformationItf, StreamInformationItfCallback, (void*)this); + } + + //playback rate + xaRes = (*mMOPlayer)->GetInterface(mMOPlayer, XA_IID_PLAYBACKRATE, &mPlaybackRateItf); + if(mapError(xaRes, ETrue)==KErrNone) + mbPlaybackRateItfAvailable = ETrue; + + + //videopostprocessing + xaRes = (*mMOPlayer)->GetInterface(mMOPlayer, XA_IID_VIDEOPOSTPROCESSING, &mVideoPostProcessingItf); + if(mapError(xaRes, ETrue)==KErrNone) + mbScalable = ETrue; + + } + + if(mbMetadataAvailable) { + keyMap.clear(); + extendedKeyMap.clear(); + setupMetaData(); //done every time source is changed + } + else { //send signal for seekable + mParent.cbSeekableChanged(ETrue); + } + + mCurPosition = 0; + mParent.cbPositionChanged(mCurPosition); + + xaRes = (*mPlayItf)->GetDuration(mPlayItf, &dur); + retVal = mapError(xaRes, ETrue); + RET_ERR_IF_ERR(retVal); + + mDuration = dur; + mParent.cbDurationChanged(mDuration); + + return retVal; +} + +void XAPlaySessionImpl::unload() +{ + mPlayItf = NULL; + mSeekItf = NULL; + + //Metadata + mbMetadataAvailable = FALSE; + mMetadataExtItf = NULL; + alKeyMap.clear(); + keyMap.clear(); + extendedKeyMap.clear(); + //Volume + mNokiaLinearVolumeItf = NULL; + mbVolEnabled = FALSE; + mNokiaVolumeExtItf = NULL; + mbMuteEnabled = NULL; + + //buffer status + mPrefetchStatusItf = NULL; + mbPrefetchStatusChange = FALSE; + + //stream information + mStreamInformationItf = NULL; + mbStreamInfoAvailable = FALSE; + mbAudioStream = FALSE; + mbVideoStream = FALSE; + mNumStreams = 0; + + //Playbackrate + mPlaybackRateItf = NULL; + mbPlaybackRateItfAvailable = FALSE; + + mVideoPostProcessingItf = NULL; + mbScalable = FALSE; + mCurrAspectRatioMode = Qt::KeepAspectRatio; + + //internal + mCurPosition = 0; // in milliseconds + mDuration = 0; // in milliseconds + + + mbMediaPlayerUnrealized = TRUE; + + delete mURIName; + mURIName = NULL; + +} + +TInt XAPlaySessionImpl::play() +{ + TInt retVal(KErrGeneral); + XAresult xaRes; + XAuint32 state; + +#ifdef USE_VIDEOPLAYERUTILITY + mVideoPlayUtil->Play(); + return 0; +#endif + + if (!mMOPlayer || !mPlayItf) + return retVal; + + xaRes = (*mPlayItf)->GetPlayState(mPlayItf, &state); + retVal = mapError(xaRes, ETrue); + RET_ERR_IF_ERR(retVal); + + if ((state == XA_PLAYSTATE_STOPPED) || + (state == XA_PLAYSTATE_PAUSED)) { + xaRes = (*mPlayItf)->SetPlayState(mPlayItf, XA_PLAYSTATE_PLAYING); + retVal = mapError(xaRes, ETrue); + RET_ERR_IF_ERR(retVal); + } + return retVal; +} + +TInt XAPlaySessionImpl::pause() +{ + TInt retVal(KErrGeneral); + XAresult xaRes; + XAuint32 state; + +#ifdef USE_VIDEOPLAYERUTILITY + TRAPD(err, mVideoPlayUtil->PauseL()); + return 0; +#endif + + if (!mMOPlayer || !mPlayItf) + return retVal; + + xaRes = (*mPlayItf)->GetPlayState(mPlayItf, &state); + retVal = mapError(xaRes, ETrue); + RET_ERR_IF_ERR(retVal); + + if ((state == XA_PLAYSTATE_STOPPED) || + (state == XA_PLAYSTATE_PLAYING)) { + xaRes = (*mPlayItf)->SetPlayState(mPlayItf, XA_PLAYSTATE_PAUSED); + retVal = mapError(xaRes, ETrue); + RET_ERR_IF_ERR(retVal); + } + + return retVal; +} + +TInt XAPlaySessionImpl::stop() +{ + TInt retVal(KErrGeneral); + XAresult xaRes; + XAuint32 state; + +#ifdef USE_VIDEOPLAYERUTILITY + mVideoPlayUtil->Stop(); + return 0; +#endif + + if (!mMOPlayer || !mPlayItf) + return retVal; + + xaRes = (*mPlayItf)->GetPlayState(mPlayItf, &state); + retVal = mapError(xaRes, ETrue); + RET_ERR_IF_ERR(retVal); + + if ((state == XA_PLAYSTATE_PAUSED) || + (state == XA_PLAYSTATE_PLAYING)) { + xaRes = (*mPlayItf)->SetPlayState(mPlayItf, XA_PLAYSTATE_STOPPED); + retVal = mapError(xaRes, ETrue); + RET_ERR_IF_ERR(retVal); + mCurPosition += KPlayPosUpdatePeriod; + mParent.cbPositionChanged(mCurPosition); + } + + return retVal; +} + +TInt XAPlaySessionImpl::duration(TInt64& aDur) +{ + TInt retVal(KErrGeneral); + +#ifdef USE_VIDEOPLAYERUTILITY + TTimeIntervalMicroSeconds dur(0); + TRAPD(err, mVideoPlayUtil->DurationL()); + if (!err) + aDur = dur.Int64() / 1000; + return 0; +#endif + if (!mMOPlayer || !mPlayItf) + return retVal; + aDur = mDuration; + return retVal; +} + +TInt XAPlaySessionImpl::position(TInt64& aPos) +{ + TInt retVal(KErrGeneral); +#ifdef USE_VIDEOPLAYERUTILITY + TTimeIntervalMicroSeconds dur(0); + TRAPD(err, mVideoPlayUtil->PositionL()); + if (!err) + aPos = dur.Int64() / 1000; + return 0; +#endif + +/* XAresult xaRes; + XAmillisecond pos(0);*/ + + if (!mMOPlayer || !mPlayItf) + return retVal; + + aPos = mCurPosition; + return retVal; +} + +TInt XAPlaySessionImpl::getSeekable(TBool& seekable) +{ + TInt retVal(KErrGeneral); + + if (!mMOPlayer || !mSeekItf) + return retVal; + + retVal = ETrue; + seekable = ETrue; + + return retVal; +} + +TInt XAPlaySessionImpl::seek(TInt64 pos) +{ + TInt retVal(KErrGeneral); + XAresult xaRes; + + if (!mMOPlayer || !mSeekItf) + return retVal; + + xaRes = (*mSeekItf)->SetPosition(mSeekItf, (XAmillisecond)pos, XA_SEEKMODE_FAST); + retVal = mapError(xaRes, ETrue); + RET_ERR_IF_ERR(retVal); + mCurPosition = pos; + + return retVal; +} + +void XAPlaySessionImpl::cbMediaPlayer(XAObjectItf /*caller*/, + const void */*pContext*/, + XAuint32 event, + XAresult result, + XAuint32 /*param*/, + void */*pInterface*/) + +{ + switch (event) { + case XA_OBJECT_EVENT_RESOURCES_LOST: + unload(); + mParent.cbPlaybackStopped(result); + break; + case XA_OBJECT_EVENT_RUNTIME_ERROR: + { + switch (result) { + case XA_RESULT_RESOURCE_LOST: + unload(); + mParent.cbPlaybackStopped(result); + break; + default: + break; + }; /* of switch (result) */ + } + default: + break; + } /* of switch (event) */ +} + +void XAPlaySessionImpl::cbPlayItf(XAPlayItf /*caller*/, + void */*pContext*/, + XAuint32 event) +{ + switch(event) { + case XA_PLAYEVENT_HEADATEND: + mParent.cbPlaybackStopped(KErrNone); + break; + case XA_PLAYEVENT_HEADATMARKER: + break; + case XA_PLAYEVENT_HEADATNEWPOS: + mCurPosition += KPlayPosUpdatePeriod; + mParent.cbPositionChanged(mCurPosition); + break; + case XA_PLAYEVENT_HEADMOVING: + break; + case XA_PLAYEVENT_HEADSTALLED: + break; + default: + break; + } +} + +void XAPlaySessionImpl::cbPrefetchItf(XAuint32 event) +{ + if(event == XA_PREFETCHEVENT_FILLLEVELCHANGE) + mParent.cbPrefetchStatusChanged(); +} + +void XAPlaySessionImpl::cbStreamInformationItf( XAuint32 /*eventId*/, + XAuint32 /*streamIndex*/, + void * /*pEventData*/) +{ + mParent.cbStreamInformation(EFalse); +} + +void XAPlaySessionImpl::setAspectRatioMode(Qt::AspectRatioMode aspectRatioMode) +{ + if( !mbScalable || + (mCurrAspectRatioMode == aspectRatioMode)) { + return; + } + + XAuint32 scaleOptions;; + XAuint32 backgrndColor = 1; + XAuint32 renderingHints = 1; + + switch(aspectRatioMode) { + case Qt::IgnoreAspectRatio: + scaleOptions = XA_VIDEOSCALE_STRETCH; + break; + case Qt::KeepAspectRatio: + scaleOptions = XA_VIDEOSCALE_FIT; + break; + case Qt::KeepAspectRatioByExpanding: + scaleOptions = XA_VIDEOSCALE_CROP; + break; + default: + return; + } + + XAresult xaRes = (*mVideoPostProcessingItf)->SetScaleOptions(mVideoPostProcessingItf, \ + scaleOptions, backgrndColor, renderingHints); + if(mapError(xaRes, ETrue) == KErrNone) + xaRes = (*mVideoPostProcessingItf)->Commit(mVideoPostProcessingItf); + + if(mapError(xaRes, ETrue) == KErrNone) + mCurrAspectRatioMode = aspectRatioMode; +} + +Qt::AspectRatioMode XAPlaySessionImpl::getAspectRatioMode() +{ + return mCurrAspectRatioMode; +} + + +#ifdef USE_VIDEOPLAYERUTILITY +void XAPlaySessionImpl::MvpuoOpenComplete(TInt aError) +{ + TRACE_FUNCTION_ENTRY; + m_VPError = aError; + if (mActiveSchedulerWait->IsStarted()) + mActiveSchedulerWait->AsyncStop(); + TRACE_FUNCTION_EXIT; +} + +void XAPlaySessionImpl::MvpuoPrepareComplete(TInt aError) +{ + TRACE_FUNCTION_ENTRY; + m_VPError = aError; + if (mActiveSchedulerWait->IsStarted()) + mActiveSchedulerWait->AsyncStop(); + + RWindow* window = (RWindow*)mNativeDisplay.hWindow; + RWsSession* wssession = (RWsSession*)mNativeDisplay.hDisplay; + + if (window) { + TRect videoExtent = TRect(window->Size()); + TRect clipRect = TRect(window->Size()); + TRAP_IGNORE(mVideoPlayUtil->AddDisplayWindowL(*wssession, *(CCoeEnv::Static()->ScreenDevice()), *window, videoExtent, clipRect)); + TRAP_IGNORE(mVideoPlayUtil->SetAutoScaleL(*window, EAutoScaleBestFit)); + } + TRACE_FUNCTION_EXIT; +} + +void XAPlaySessionImpl::MvpuoFrameReady(CFbsBitmap& /*aFrame*/,TInt /*aError*/) +{ + TRACE_FUNCTION_ENTRY_EXIT; +} + +void XAPlaySessionImpl::MvpuoPlayComplete(TInt /*aError*/) +{ + TRACE_FUNCTION_ENTRY; + mParent.cbPlaybackStopped_EOS(); + TRACE_FUNCTION_EXIT; +} + +void XAPlaySessionImpl::MvpuoEvent(const TMMFEvent& /*aEvent*/) +{ + TRACE_FUNCTION_ENTRY_EXIT; +} + +#endif + +TInt XAPlaySessionImpl::mapError(XAresult xa_err, TBool /*debPrn*/) +{ + TInt retVal(KErrGeneral); + + switch(xa_err) { + case XA_RESULT_SUCCESS: + retVal = KErrNone; + break; + case XA_RESULT_PRECONDITIONS_VIOLATED: + break; + case XA_RESULT_PARAMETER_INVALID: + break; + case XA_RESULT_MEMORY_FAILURE: + break; + case XA_RESULT_RESOURCE_ERROR: + break; + case XA_RESULT_RESOURCE_LOST: + break; + case XA_RESULT_IO_ERROR: + break; + case XA_RESULT_BUFFER_INSUFFICIENT: + break; + case XA_RESULT_CONTENT_CORRUPTED: + break; + case XA_RESULT_CONTENT_UNSUPPORTED: + break; + case XA_RESULT_CONTENT_NOT_FOUND: + break; + case XA_RESULT_PERMISSION_DENIED: + break; + case XA_RESULT_FEATURE_UNSUPPORTED: + break; + case XA_RESULT_INTERNAL_ERROR: + break; + case XA_RESULT_UNKNOWN_ERROR: + break; + case XA_RESULT_OPERATION_ABORTED: + break; + case XA_RESULT_CONTROL_LOST: + break; + default: + break; + } + + return retVal; +} + + +QStringList XAPlaySessionImpl::availableExtendedMetaData () const +{ + QStringList retList; + + //create a qlist with all keys in keyMap hash + QHashIterator<QString, int> it(extendedKeyMap); + while(it.hasNext()) { + it.next(); + retList << it.key(); + } + + return retList; +} + +QList<QtMultimediaKit::MetaData> XAPlaySessionImpl::availableMetaData () const +{ + QList<QtMultimediaKit::MetaData> retList; + + //create a qlist with all keys in keyMap hash + QHashIterator<QtMultimediaKit::MetaData, int> it(keyMap); + while( it.hasNext() ) { + it.next(); + retList << it.key(); + } + + return retList; +} + +QVariant XAPlaySessionImpl::getMetaData( int alIndex ) const +{ + QVariant ret; //invalid variant + + //find index for the given key + if(mMetadataExtItf) { + XAuint32 valueSize = 0; + XAresult res = (*mMetadataExtItf)->GetValueSize(mMetadataExtItf, alIndex, &valueSize); + if(res == XA_RESULT_SUCCESS) { + XAMetadataInfo * value = (XAMetadataInfo*)calloc(valueSize, 1); + if(value) { + res = (*mMetadataExtItf)->GetValue(mMetadataExtItf, alIndex, valueSize, value); + if(res == XA_RESULT_SUCCESS) { + if(value->encoding == XA_CHARACTERENCODING_ASCII) + ret = QVariant ((const char*)value->data); + else if(value->encoding == XA_CHARACTERENCODING_UTF16LE) + ret = QVariant(QString::fromUtf16((ushort*)value->data, (value->size/2)-1)); //dont include null terminating character + else if(value->encoding == XA_CHARACTERENCODING_BINARY) + ret = QVariant(QImage::fromData(value->data, value->size)); + } + + free(value); + } + } + } + + return ret; +} + +QVariant XAPlaySessionImpl::metaData( QtMultimediaKit::MetaData key ) const +{ + QVariant ret; + if(keyMap.contains(key)) + ret = getMetaData(keyMap[key]); + return ret; +} + +QVariant XAPlaySessionImpl::extendedMetaData(const QString & key ) const +{ + QVariant ret; + if(extendedKeyMap.contains(key)) + ret = getMetaData(extendedKeyMap[key]); + + return ret; +} + +bool XAPlaySessionImpl::isMetaDataAvailable() const +{ + return ((keyMap.size()>0) || (extendedKeyMap.size()>0)); +} + +bool XAPlaySessionImpl::isWritable() const +{ + return false; +} + +void XAPlaySessionImpl::setExtendedMetaData( const QString&, const QVariant&) +{ + //Do Nothing +} + +void XAPlaySessionImpl::setMetaData( QtMultimediaKit::MetaData, const QVariant& ) +{ + //Do Nothing +} + +void XAPlaySessionImpl::setupALKeyMap() +{ + alKeyMap["KhronosTitle"] = QtMultimediaKit::Title; + alKeyMap["KhronosComment"] = QtMultimediaKit::Comment; + alKeyMap["KhronosTrackNumber"] = QtMultimediaKit::TrackNumber; + alKeyMap["KhronosAlbumArtJPEG"] = QtMultimediaKit::CoverArtImage; + alKeyMap["KhronosAlbumArtPNG"] = QtMultimediaKit::CoverArtImage; + alKeyMap["KhronosAlbum"] = QtMultimediaKit::AlbumTitle; + alKeyMap["KhronosArtist"] = QtMultimediaKit::AlbumArtist; + alKeyMap["KhronosGenre"] = QtMultimediaKit::Genre; + alKeyMap["KhronosYear"] = QtMultimediaKit::Year; + alKeyMap["KhronosYear"] = QtMultimediaKit::Date; + alKeyMap["KhronosRating"] = QtMultimediaKit::UserRating; + alKeyMap["KhronosCopyright"] = QtMultimediaKit::Copyright; + alKeyMap["Author"] = QtMultimediaKit::Author; + alKeyMap["Duration"] = QtMultimediaKit::Duration; + alKeyMap["Stream Count"] = QtMultimediaKit::ChannelCount; + alKeyMap["Composer"] = QtMultimediaKit::Composer; + alKeyMap["Resolution"] = QtMultimediaKit::Resolution; + alKeyMap["FrameRate"] = QtMultimediaKit::VideoFrameRate; + alKeyMap["ClipBitRate"] = QtMultimediaKit::VideoBitRate; + alKeyMap["Codec"] = QtMultimediaKit::VideoCodec; + alKeyMap["attachedpicture"] = QtMultimediaKit::CoverArtImage; + + /*Keys not available + QtMedia::SubTitle + QtMedia::Description + QtMedia::Category + QtMedia::Keywords + QtMedia::Language + QtMedia::Publisher + QtMedia::ParentalRating + QtMedia::RatingOrganisation + QtMedia::Size + QtMedia::MediaType + QtMedia::AudioBitrate + QtMedia::AudioCodec + QtMedia::AverageLevel + QtMedia::PeakValue + QtMedia::Frequency + QtMedia::ContributingArtist + QtMedia::Conductor + QtMedia::Lyrics + QtMedia::Mood + QtMedia::TrackCount + QtMedia::PixelAspectRatio + QtMedia::PosterUri + QtMedia::ChapterNumber + QtMedia::Director + QtMedia::LeadPerformer + QtMedia::Writer */ +} + +TInt XAPlaySessionImpl::mapMetaDataKey(const char* asckey, QtMultimediaKit::MetaData& key) +{ + if(alKeyMap.contains(asckey)) { + key = alKeyMap[asckey]; + return KErrNone; + } + + return KErrNotFound; +} + +TInt XAPlaySessionImpl::setupMetaData() +{ + XAresult res; + if(mMetadataExtItf) { + XAuint32 numItems = 0; + res = (*mMetadataExtItf)->GetItemCount(mMetadataExtItf, &numItems); + RET_ERR_IF_ERR(mapError(res, ETrue)); + + for(int i=0; i<numItems; ++i) { + XAuint32 keySize; + res = (*mMetadataExtItf)->GetKeySize(mMetadataExtItf, i, &keySize); + RET_ERR_IF_ERR(mapError(res, ETrue)); + + XAMetadataInfo *key = (XAMetadataInfo *)calloc(keySize,1); + if(key) { + res = (*mMetadataExtItf)->GetKey(mMetadataExtItf, i, keySize, key); + RET_ERR_IF_ERR(mapError(res, ETrue)); + + if(key->encoding == XA_CHARACTERENCODING_ASCII) { //only handle ASCII keys ignore others + QtMultimediaKit::MetaData qtKey; + if(mapMetaDataKey((const char*)key->data, qtKey) == KErrNone)//qt metadata + keyMap[qtKey] = i; + else //extended metadata + extendedKeyMap[(const char*)key->data] = i; + } + + free(key); + } + } + + //check for seek property to generate seekable signal + QVariant var = extendedMetaData("Seekable"); + if(!var.isValid() || (var.toString() == "1")) + mParent.cbSeekableChanged(ETrue); + else + mParent.cbSeekableChanged(EFalse); + + } + + return KErrGeneral; +} + +//Volume +TInt XAPlaySessionImpl::volume(TInt& v) +{ + if(mbVolEnabled) { + XAresult res = (*mNokiaLinearVolumeItf)->GetVolumeLevel(mNokiaLinearVolumeItf, (XAuint32 *)&v); + return mapError(res, ETrue); + } + + return KErrNotFound; +} + +TInt XAPlaySessionImpl::setVolume(TInt v) +{ + if(mbVolEnabled) { + XAresult res = (*mNokiaLinearVolumeItf)->SetVolumeLevel(mNokiaLinearVolumeItf, (XAuint32*)&v); + return mapError(res, ETrue); + } + + return KErrNotFound; +} + +TInt XAPlaySessionImpl::setMute(TBool bMute) +{ + if(mbMuteEnabled) { + XAresult res = (*mNokiaVolumeExtItf)->SetMute(mNokiaVolumeExtItf, (XAboolean)bMute); + return mapError(res, ETrue); + } + + return KErrNotFound; + +} + +TInt XAPlaySessionImpl::getMute(TBool& bIsMute) +{ + if(mbMuteEnabled) { + XAboolean xaMute; + XAresult res = (*mNokiaVolumeExtItf)->GetMute(mNokiaVolumeExtItf, &xaMute); + bIsMute = xaMute; + return mapError(res, ETrue); + } + + return KErrNotFound; +} + + +TInt XAPlaySessionImpl::bufferStatus(TInt &bs) +{ + TInt ret = KErrNotFound; + + if(mbPrefetchStatusChange) { + XApermille satusPerThousand; + XAresult res = (*mPrefetchStatusItf)->GetFillLevel(mPrefetchStatusItf, &satusPerThousand); + ret = mapError(res, ETrue); + if(ret == KErrNone) + bs = satusPerThousand/10.0; //convert to parts per hundred + } + return ret; +} + +QMediaStreamsControl::StreamType XAPlaySessionImpl::mapStreamType(XAuint32& alStreamType) +{ + switch(alStreamType) { + case XA_DOMAINTYPE_AUDIO: + return QMediaStreamsControl::AudioStream; + case XA_DOMAINTYPE_VIDEO: + return QMediaStreamsControl::VideoStream; + case XA_DOMAINTYPE_IMAGE: + return QMediaStreamsControl::DataStream; + } + return QMediaStreamsControl::UnknownStream; +} + + +TInt XAPlaySessionImpl::numMediaStreams(TUint& numStreams) +{ + TInt ret = KErrNotFound; + numStreams = 0; + if(mbStreamInfoAvailable) { + XAMediaContainerInformation mediaContainerInfo; + XAresult res = (*mStreamInformationItf)->QueryMediaContainerInformation(mStreamInformationItf, &mediaContainerInfo); + ret = mapError(res, ETrue); + if(ret == KErrNone) + numStreams = mediaContainerInfo.numStreams; + } + return ret; +} + +TInt XAPlaySessionImpl::streamType(TUint index, QMediaStreamsControl::StreamType& type) +{ + TInt ret = KErrNotFound; + type = QMediaStreamsControl::UnknownStream; + if(mbStreamInfoAvailable) { + XAuint32 strType; + XAresult res = (*mStreamInformationItf)->QueryStreamType(mStreamInformationItf, (XAuint32)(index+1), &strType); + ret = mapError(res, ETrue); + if(ret == KErrNone) + type = mapStreamType(strType); + } + return ret; +} + +TInt XAPlaySessionImpl::isStreamActive(TUint index, TBool& isActive) +{ + TUint numStreams; + TInt ret = numMediaStreams(numStreams); + if((ret == KErrNone) && (index < numStreams)) { + isActive = EFalse; + if(numStreams > 0) { + //create array of bools + XAboolean *activeStreams = new XAboolean[numStreams+1]; + XAresult res = (*mStreamInformationItf)->QueryActiveStreams(mStreamInformationItf, (XAuint32*)&numStreams, activeStreams); + ret = mapError(res, ETrue); + if(ret == KErrNone) + isActive = activeStreams[index+1]; + delete[] activeStreams; + } + } + return ret; +} + +TInt XAPlaySessionImpl::getPlaybackRate(TReal32 &rate) +{ + TInt ret = KErrNotFound; + + if(mbPlaybackRateItfAvailable) { + XApermille perMilleRate = 0; + ret = (*mPlaybackRateItf)->GetRate(mPlaybackRateItf, &perMilleRate); + rate = perMilleRate / 1000.0; + } + return ret; +} + +TInt XAPlaySessionImpl::setPlaybackRate(TReal32 rate) +{ + TInt ret = KErrNotFound; + if(mbPlaybackRateItfAvailable) + ret = (*mPlaybackRateItf)->SetRate(mPlaybackRateItf, (XApermille)(rate * 1000.0)); + return ret; +} + + +/* Local function implementation */ +void MediaPlayerCallback( XAObjectItf caller, + const void *pContext, + XAuint32 event, + XAresult result, + XAuint32 param, + void *pInterface) +{ + if (pContext) + ((XAPlaySessionImpl*)pContext)->cbMediaPlayer( caller, + pContext, + event, + result, + param, + pInterface); +} + +void PlayItfCallback( XAPlayItf caller, + void *pContext, + XAuint32 event) +{ + if (pContext) + ((XAPlaySessionImpl*)pContext)->cbPlayItf(caller, + pContext, + event); +} + +void PrefetchItfCallback( XAPrefetchStatusItf /*caller*/, + void *pContext, + XAuint32 event) +{ + if (pContext) + ((XAPlaySessionImpl*)pContext)->cbPrefetchItf(event); +} + +void StreamInformationItfCallback( XAStreamInformationItf /*caller*/, + XAuint32 eventId, + XAuint32 streamIndex, + void * pEventData, + void * pContext) +{ + if (pContext) + ((XAPlaySessionImpl*)pContext)->cbStreamInformationItf( eventId, + streamIndex, + pEventData); +} + + + +// End of file diff --git a/src/plugins/symbian/openmaxal/mediaplayer/xaplaysessionimpl.h b/src/plugins/symbian/openmaxal/mediaplayer/xaplaysessionimpl.h new file mode 100644 index 000000000..30144712a --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediaplayer/xaplaysessionimpl.h @@ -0,0 +1,210 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef XAPLAYSESSIONIMPL_H +#define XAPLAYSESSIONIMPL_H + +#include <OpenMAXAL.h> +#include <xanokiavolumeextitf.h> +#include <xanokialinearvolumeitf.h> +#ifdef USE_VIDEOPLAYERUTILITY +#include <VideoPlayer2.h> +#endif + +#include "qtmedianamespace.h" +#include "qmediastreamscontrol.h" + +class XAPlayObserver; +class RWindow; +class RWsSession; + +class XAPlaySessionImpl +#ifdef USE_VIDEOPLAYERUTILITY + : public MVideoPlayerUtilityObserver +#endif +{ +public: + XAPlaySessionImpl(XAPlayObserver& parent); + ~XAPlaySessionImpl(); + TInt postConstruct(); + TInt addNativeDisplay(RWindow* window, RWsSession* wssession); + TInt updateNativeDisplay(RWindow* window, RWsSession* wssession); + TInt removeNativeDisplay(RWindow* window, RWsSession* wssession); + TInt load(const TDesC& aURI); + void unload(); + TInt play(); + TInt pause(); + TInt stop(); + TInt duration(TInt64& aDur); + TInt position(TInt64& aPos); + TInt getSeekable(TBool& seekable); + TInt seek(TInt64 pos); + + //Metadata + QStringList availableExtendedMetaData () const; + QList<QtMultimediaKit::MetaData> availableMetaData () const; + QVariant extendedMetaData(const QString & key ) const; + bool isMetaDataAvailable() const; + bool isWritable() const; + QVariant metaData( QtMultimediaKit::MetaData key ) const; + void setExtendedMetaData( const QString & key, const QVariant & value ); + void setMetaData( QtMultimediaKit::MetaData key, const QVariant & value ); + + TInt volume(TInt&); + TInt setVolume(TInt); + TInt setMute(TBool); + TInt getMute(TBool&); + + TInt bufferStatus(TInt &); + + + TInt numMediaStreams(TUint& numStreams); + TInt streamType(TUint index, QMediaStreamsControl::StreamType& type); + TInt isStreamActive(TUint index, TBool& isActive); + + TInt getPlaybackRate(TReal32 &rate); + TInt setPlaybackRate(TReal32 rate); + + //AspectRatioMode + void setAspectRatioMode(Qt::AspectRatioMode); + Qt::AspectRatioMode getAspectRatioMode(); + +public: + void cbMediaPlayer( XAObjectItf caller, + const void *pContext, + XAuint32 event, + XAresult result, + XAuint32 param, + void *pInterface); + + void cbPlayItf(XAPlayItf caller, + void *pContext, + XAuint32 event); + + + void cbPrefetchItf(XAuint32); + + void cbStreamInformationItf(XAuint32, XAuint32, void*); + +#ifdef USE_VIDEOPLAYERUTILITY + //MVideoPlayerUtilityObserver + void MvpuoOpenComplete(TInt aError); + void MvpuoPrepareComplete(TInt aError); + void MvpuoFrameReady(CFbsBitmap& aFrame,TInt aError); + void MvpuoPlayComplete(TInt aError); + void MvpuoEvent(const TMMFEvent& aEvent); +#endif + +private: + TInt mapError(XAresult xa_err, + TBool debPrn); + void setupALKeyMap(); + TInt setupMetaData(); + TInt mapMetaDataKey(const char* asckey, QtMultimediaKit::MetaData& key); + QVariant getMetaData( int alIndex ) const; + + QMediaStreamsControl::StreamType mapStreamType(XAuint32& alStreamType); + + +private: + XAPlayObserver& mParent; + XAObjectItf mEOEngine; + XAObjectItf mMOPlayer; + XAPlayItf mPlayItf; + XASeekItf mSeekItf; + HBufC8* mURIName; + HBufC8* mWAVMime; + // Audio Source + XADataSource mDataSource; + XADataFormat_MIME mMime; + XADataLocator_URI mUri; + //Audio Sink + XADataSink mAudioSink; + XADataLocator_IODevice mLocatorOutputDevice; + //Video Sink + XADataSink mVideoSink; + XADataLocator_NativeDisplay mNativeDisplay; + + //Metadata + TBool mbMetadataAvailable; + XAMetadataExtractionItf mMetadataExtItf; + QHash<QString, QtMultimediaKit::MetaData> alKeyMap; + QHash<QtMultimediaKit::MetaData, int> keyMap; + QHash<QString,int> extendedKeyMap; + + //Volume + XANokiaLinearVolumeItf mNokiaLinearVolumeItf; + TBool mbVolEnabled; + XANokiaVolumeExtItf mNokiaVolumeExtItf; + TBool mbMuteEnabled; + + //buffer status + XAPrefetchStatusItf mPrefetchStatusItf; + TBool mbPrefetchStatusChange; + + //stream information + XAStreamInformationItf mStreamInformationItf; + TBool mbStreamInfoAvailable; + TBool mbAudioStream; + TBool mbVideoStream; + TInt mNumStreams; + + //Playbackrate + XAPlaybackRateItf mPlaybackRateItf; + TBool mbPlaybackRateItfAvailable; + + XAVideoPostProcessingItf mVideoPostProcessingItf; + TBool mbScalable; + Qt::AspectRatioMode mCurrAspectRatioMode; + + //internal + TInt64 mCurPosition; // in milliseconds + TInt64 mDuration; // in milliseconds + + TBool mbMediaPlayerUnrealized; +#ifdef USE_VIDEOPLAYERUTILITY + CVideoPlayerUtility2* mVideoPlayUtil; + CActiveSchedulerWait* mActiveSchedulerWait; + TInt m_VPError; +#endif +}; + +#endif /* XAPLAYSESSIONIMPL_H */ diff --git a/src/plugins/symbian/openmaxal/mediarecorder/mediarecorder.pri b/src/plugins/symbian/openmaxal/mediarecorder/mediarecorder.pri new file mode 100644 index 000000000..ee78e8348 --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediarecorder/mediarecorder.pri @@ -0,0 +1,24 @@ +INCLUDEPATH += $$PWD + +# Input +HEADERS += \ + $$PWD/qxarecordmediaservice.h \ + $$PWD/qxarecordsession.h \ + $$PWD/qxaaudioendpointselector.h \ + $$PWD/qxaaudioencodercontrol.h \ + $$PWD/qxamediacontainercontrol.h \ + $$PWD/qxamediarecordercontrol.h \ + $$PWD/xarecordsessionimpl.h \ + $$PWD/xarecordsessioncommon.h + +SOURCES += \ + $$PWD/qxarecordmediaservice.cpp \ + $$PWD/qxarecordsession.cpp \ + $$PWD/qxaaudioendpointselector.cpp \ + $$PWD/qxaaudioencodercontrol.cpp \ + $$PWD/qxamediacontainercontrol.cpp \ + $$PWD/qxamediarecordercontrol.cpp \ + $$PWD/xarecordsessionimpl.cpp + +LIBS += \ + -lbafl diff --git a/src/plugins/symbian/openmaxal/mediarecorder/qxaaudioencodercontrol.cpp b/src/plugins/symbian/openmaxal/mediarecorder/qxaaudioencodercontrol.cpp new file mode 100644 index 000000000..2826f79a2 --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediarecorder/qxaaudioencodercontrol.cpp @@ -0,0 +1,111 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qxaaudioencodercontrol.h" +#include "qxarecordsession.h" +#include "qxacommon.h" + +QXAAudioEncoderControl::QXAAudioEncoderControl(QXARecordSession *session, QObject *parent) +:QAudioEncoderControl(parent), m_session(session) +{ +} + +QXAAudioEncoderControl::~QXAAudioEncoderControl() +{ + QT_TRACE_FUNCTION_ENTRY_EXIT; +} + +QStringList QXAAudioEncoderControl::supportedAudioCodecs() const +{ + if (m_session) + return m_session->supportedAudioCodecs(); + return QStringList(); +} + +QString QXAAudioEncoderControl::codecDescription(const QString &codecName) const +{ + if (m_session) + return m_session->codecDescription(codecName); + return QString(); +} + +QList<int> QXAAudioEncoderControl::supportedSampleRates( + const QAudioEncoderSettings &settings, + bool *continuous) const +{ + if (m_session) + return m_session->supportedSampleRates(settings, continuous); + return QList<int>(); +} + +QAudioEncoderSettings QXAAudioEncoderControl::audioSettings() const +{ + if (m_session) + return m_session->audioSettings(); + return QAudioEncoderSettings(); +} + +void QXAAudioEncoderControl::setAudioSettings(const QAudioEncoderSettings &settings) +{ + if (m_session) + m_session->setAudioSettings(settings); +} + +QStringList QXAAudioEncoderControl::supportedEncodingOptions(const QString &codec) const +{ + if (m_session) + return m_session->supportedEncodingOptions(codec); + return QStringList(); +} + +QVariant QXAAudioEncoderControl::encodingOption(const QString &codec, const QString &name) const +{ + if (m_session) + return m_session->encodingOption(codec, name); + return QVariant(); +} + +void QXAAudioEncoderControl::setEncodingOption( + const QString &codec, const QString &name, const QVariant &value) +{ + if (m_session) + m_session->setEncodingOption(codec, name, value); +} diff --git a/src/plugins/symbian/openmaxal/mediarecorder/qxaaudioencodercontrol.h b/src/plugins/symbian/openmaxal/mediarecorder/qxaaudioencodercontrol.h new file mode 100644 index 000000000..117d36fdc --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediarecorder/qxaaudioencodercontrol.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXAAUDIOENCODERCONTROL_H +#define QXAAUDIOENCODERCONTROL_H + +#include <qaudioencodercontrol.h> + +QT_USE_NAMESPACE + +/* + * This class implements QAudioEncoderControl interface. + */ +class QXARecordSession; + +class QXAAudioEncoderControl : public QAudioEncoderControl +{ + Q_OBJECT + +public: + QXAAudioEncoderControl(QXARecordSession *session, QObject *parent = 0); + virtual ~QXAAudioEncoderControl(); + + QStringList supportedAudioCodecs() const; + QString codecDescription(const QString &codecName) const; + + QList<int> supportedSampleRates(const QAudioEncoderSettings &settings, + bool *continuous = 0) const; + + QAudioEncoderSettings audioSettings() const; + void setAudioSettings(const QAudioEncoderSettings &settings); + + QStringList supportedEncodingOptions(const QString &codec) const; + QVariant encodingOption(const QString &codec, const QString &name) const; + void setEncodingOption(const QString &codec, const QString &name, const QVariant &value); + +private: + QXARecordSession *m_session; +}; + +#endif /* QXAAUDIOENCODERCONTROL_H */ diff --git a/src/plugins/symbian/openmaxal/mediarecorder/qxaaudioendpointselector.cpp b/src/plugins/symbian/openmaxal/mediarecorder/qxaaudioendpointselector.cpp new file mode 100644 index 000000000..7e546595c --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediarecorder/qxaaudioendpointselector.cpp @@ -0,0 +1,98 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qxaaudioendpointselector.h" +#include "qxarecordsession.h" +#include "qxacommon.h" + +QXAAudioEndpointSelector::QXAAudioEndpointSelector(QXARecordSession *session, QObject *parent) +:QAudioEndpointSelector(parent), m_session(session) +{ + connect(m_session, SIGNAL(availableAudioInputsChanged()), + this, SLOT(availableAudioInputsChanged())); + connect(m_session, SIGNAL(activeEndpointChanged(QString)), + this, SIGNAL(activeEndpointChanged(QString))); +} + +QXAAudioEndpointSelector::~QXAAudioEndpointSelector() +{ + QT_TRACE_FUNCTION_ENTRY_EXIT; +} + +QList<QString> QXAAudioEndpointSelector::availableEndpoints() const +{ + if (m_session) + return m_session->availableEndpoints(); + return QList<QString>(); +} + +QString QXAAudioEndpointSelector::endpointDescription(const QString &name) const +{ + if (m_session) + return m_session->endpointDescription(name); + return QString(); +} + +QString QXAAudioEndpointSelector::defaultEndpoint() const +{ + if (m_session) + return m_session->defaultEndpoint(); + return QString(); +} + +QString QXAAudioEndpointSelector::activeEndpoint() const +{ + if (m_session) + return m_session->activeEndpoint(); + return QString(); +} + +void QXAAudioEndpointSelector::setActiveEndpoint(const QString &name) +{ + if (m_session) + m_session->setActiveEndpoint(name); +} + +void QXAAudioEndpointSelector::availableAudioInputsChanged() + { + emit availableEndpointsChanged(); + } + diff --git a/src/plugins/symbian/openmaxal/mediarecorder/qxaaudioendpointselector.h b/src/plugins/symbian/openmaxal/mediarecorder/qxaaudioendpointselector.h new file mode 100644 index 000000000..5fbadbc64 --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediarecorder/qxaaudioendpointselector.h @@ -0,0 +1,77 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXAAUDIOENDPOINTSELECTOR_H +#define QXAAUDIOENDPOINTSELECTOR_H + +#include <qaudioendpointselector.h> + +QT_USE_NAMESPACE + +/* + * This class implements QAudioEncoderControl interface. + */ +class QXARecordSession; + +class QXAAudioEndpointSelector : public QAudioEndpointSelector +{ + Q_OBJECT + +public: + QXAAudioEndpointSelector(QXARecordSession *session, QObject *parent); + ~QXAAudioEndpointSelector(); + + QList<QString> availableEndpoints() const; + QString endpointDescription(const QString &name) const; + QString defaultEndpoint() const; + QString activeEndpoint() const; + +public Q_SLOTS: + void setActiveEndpoint(const QString &name); + +private Q_SLOTS: + void availableAudioInputsChanged(); + +private: + QXARecordSession *m_session; +}; + +#endif /* QXAAUDIOENDPOINTSELECTOR_H */ diff --git a/src/plugins/symbian/openmaxal/mediarecorder/qxamediacontainercontrol.cpp b/src/plugins/symbian/openmaxal/mediarecorder/qxamediacontainercontrol.cpp new file mode 100644 index 000000000..0d97fd5e5 --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediarecorder/qxamediacontainercontrol.cpp @@ -0,0 +1,81 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qxamediacontainercontrol.h" +#include "qxarecordsession.h" +#include "qxacommon.h" + +QXAMediaContainerControl::QXAMediaContainerControl(QXARecordSession *session, QObject *parent) +:QMediaContainerControl(parent), m_session(session) +{ +} + +QXAMediaContainerControl::~QXAMediaContainerControl() +{ + QT_TRACE_FUNCTION_ENTRY_EXIT; +} + +QStringList QXAMediaContainerControl::supportedContainers() const +{ + if (m_session) + return m_session->supportedContainers(); + return QStringList(); +} + +QString QXAMediaContainerControl::containerMimeType() const +{ + if (m_session) + return m_session->containerMimeType(); + return QString(); +} + +void QXAMediaContainerControl::setContainerMimeType(const QString &formatMimeType) +{ + if (m_session) + m_session->setContainerMimeType(formatMimeType); +} + +QString QXAMediaContainerControl::containerDescription(const QString &formatMimeType) const +{ + if (m_session) + return m_session->containerDescription(formatMimeType); + return QString(); +} diff --git a/src/plugins/symbian/openmaxal/mediarecorder/qxamediacontainercontrol.h b/src/plugins/symbian/openmaxal/mediarecorder/qxamediacontainercontrol.h new file mode 100644 index 000000000..4b05fc190 --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediarecorder/qxamediacontainercontrol.h @@ -0,0 +1,71 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXAMEDIACONTAINERCONTROL_H +#define QXAMEDIACONTAINERCONTROL_H + +#include <qmediacontainercontrol.h> + +QT_USE_NAMESPACE + +/* + * This class implements QMediaContainerControl interface. + */ +class QXARecordSession; + +class QXAMediaContainerControl : public QMediaContainerControl +{ + Q_OBJECT + +public: + QXAMediaContainerControl(QXARecordSession *session, QObject *parent = 0); + virtual ~QXAMediaContainerControl(); + + QStringList supportedContainers() const; + QString containerMimeType() const; + void setContainerMimeType(const QString &formatMimeType); + QString containerDescription(const QString &formatMimeType) const; + +private: + QXARecordSession *m_session; +}; + +#endif /* QXAMEDIACONTAINERCONTROL_H */ diff --git a/src/plugins/symbian/openmaxal/mediarecorder/qxamediarecordercontrol.cpp b/src/plugins/symbian/openmaxal/mediarecorder/qxamediarecordercontrol.cpp new file mode 100644 index 000000000..330edf008 --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediarecorder/qxamediarecordercontrol.cpp @@ -0,0 +1,122 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qxamediarecordercontrol.h" +#include "qxarecordsession.h" +#include "qxacommon.h" + +QXAMediaRecoderControl::QXAMediaRecoderControl(QXARecordSession *session, QObject *parent) +:QMediaRecorderControl(parent), m_session(session) +{ + connect(m_session, SIGNAL(stateChanged(QMediaRecorder::State)), + this, SIGNAL(stateChanged(QMediaRecorder::State))); + connect(m_session, SIGNAL(error(int,QString)), + this,SIGNAL(error(int,QString))); + connect(m_session, SIGNAL(durationChanged(qint64)), + this, SIGNAL(durationChanged(qint64))); +} + +QXAMediaRecoderControl::~QXAMediaRecoderControl() +{ + QT_TRACE_FUNCTION_ENTRY_EXIT; +} + +QUrl QXAMediaRecoderControl::outputLocation() const +{ + if (m_session) + return m_session->outputLocation(); + return QUrl(); +} + +bool QXAMediaRecoderControl::setOutputLocation(const QUrl &location) +{ + if (m_session) + return m_session->setOutputLocation(location); + return false; +} + +QMediaRecorder::State QXAMediaRecoderControl::state() const +{ + if (m_session) + return m_session->state(); + return QMediaRecorder::StoppedState; +} + +qint64 QXAMediaRecoderControl::duration() const +{ + if (m_session) + return m_session->duration(); + return 0; +} + +void QXAMediaRecoderControl::record() +{ + if (m_session) + m_session->record(); +} + +void QXAMediaRecoderControl::pause() +{ + if (m_session) + m_session->pause(); +} + +void QXAMediaRecoderControl::stop() +{ + if (m_session) + m_session->stop(); +} + +void QXAMediaRecoderControl::applySettings() +{ + if (m_session) + m_session->applySettings(); +} + +bool QXAMediaRecoderControl::isMuted() const +{ + return false; +} + +void QXAMediaRecoderControl::setMuted(bool) +{ + +} diff --git a/src/plugins/symbian/openmaxal/mediarecorder/qxamediarecordercontrol.h b/src/plugins/symbian/openmaxal/mediarecorder/qxamediarecordercontrol.h new file mode 100644 index 000000000..c6495f2e4 --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediarecorder/qxamediarecordercontrol.h @@ -0,0 +1,83 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXAMEDIARECORDERCONTROL_H +#define QXAMEDIARECORDERCONTROL_H + +#include <qmediarecorder.h> +#include <qmediarecordercontrol.h> + +QT_USE_NAMESPACE + +/* + * This class implements QMediaRecorderControl interface. + */ + +class QXARecordSession; + +class QXAMediaRecoderControl : public QMediaRecorderControl +{ + Q_OBJECT + +public: + QXAMediaRecoderControl(QXARecordSession *session, QObject *parent = 0); + virtual ~QXAMediaRecoderControl(); + + QUrl outputLocation() const; + bool setOutputLocation(const QUrl &location); + + QMediaRecorder::State state() const; + + qint64 duration() const; + bool isMuted() const; + void applySettings(); + +public Q_SLOTS: + void record(); + void pause(); + void stop(); + void setMuted(bool); + +private: + QXARecordSession *m_session; +}; + +#endif /* QXAMEDIARECORDERCONTROL_H */ diff --git a/src/plugins/symbian/openmaxal/mediarecorder/qxarecordmediaservice.cpp b/src/plugins/symbian/openmaxal/mediarecorder/qxarecordmediaservice.cpp new file mode 100644 index 000000000..05c57feb7 --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediarecorder/qxarecordmediaservice.cpp @@ -0,0 +1,86 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QString> + +#include "qxarecordmediaservice.h" +#include "qxarecordsession.h" +#include "qxamediarecordercontrol.h" +#include "qxaaudioendpointselector.h" +#include "qxaaudioencodercontrol.h" +#include "qxamediacontainercontrol.h" +#include "qxacommon.h" + +QXARecodMediaService::QXARecodMediaService(QObject *parent) +:QMediaService(parent) +{ + QT_TRACE_FUNCTION_ENTRY; + m_session = new QXARecordSession(this); + m_control = new QXAMediaRecoderControl(m_session, this); + m_endpoint = new QXAAudioEndpointSelector(m_session, this); + m_encoder = new QXAAudioEncoderControl(m_session, this); + m_container = new QXAMediaContainerControl(m_session, this); +} + +QXARecodMediaService::~QXARecodMediaService() +{ + QT_TRACE_FUNCTION_ENTRY_EXIT; +} + +QMediaControl* QXARecodMediaService::requestControl(const char *name) +{ + QT_TRACE_FUNCTION_ENTRY; + if (qstrcmp(name, QMediaRecorderControl_iid) == 0) + return m_control; + else if (qstrcmp(name, QAudioEndpointSelector_iid) == 0) + return m_endpoint; + else if (qstrcmp(name, QAudioEncoderControl_iid) == 0) + return m_encoder; + else if (qstrcmp(name, QMediaContainerControl_iid) == 0) + return m_container; + QT_TRACE_FUNCTION_EXIT; + return 0; +} + +void QXARecodMediaService::releaseControl(QMediaControl *control) +{ + Q_UNUSED(control) +} diff --git a/src/plugins/symbian/openmaxal/mediarecorder/qxarecordmediaservice.h b/src/plugins/symbian/openmaxal/mediarecorder/qxarecordmediaservice.h new file mode 100644 index 000000000..98f5136e8 --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediarecorder/qxarecordmediaservice.h @@ -0,0 +1,78 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXARECORDMEDIASERVICE_H +#define QXARECORDMEDIASERVICE_H + +#include <QtCore/qobject.h> +#include <qmediaservice.h> + +QT_USE_NAMESPACE + +/* + * This class implements QMediaService interface. + */ + +class QXARecordSession; +class QXAMediaRecoderControl; +class QXAAudioEndpointSelector; +class QXAAudioEncoderControl; +class QXAMediaContainerControl; + +class QXARecodMediaService : public QMediaService +{ + + Q_OBJECT + +public: + QXARecodMediaService(QObject *parent = 0); + ~QXARecodMediaService(); + QMediaControl *requestControl(const char *name); + void releaseControl( QMediaControl *control); +private: + QXARecordSession *m_session; + QXAMediaRecoderControl *m_control; + QXAAudioEndpointSelector *m_endpoint; + QXAAudioEncoderControl *m_encoder; + QXAMediaContainerControl *m_container; +}; + +#endif /* QXARECORDMEDIASERVICE_H */ diff --git a/src/plugins/symbian/openmaxal/mediarecorder/qxarecordsession.cpp b/src/plugins/symbian/openmaxal/mediarecorder/qxarecordsession.cpp new file mode 100644 index 000000000..76cdfc3da --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediarecorder/qxarecordsession.cpp @@ -0,0 +1,766 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QVariant> +#include <QtCore/qdir.h> +#include <qtmedianamespace.h> +#include "qxarecordsession.h" +#include "xarecordsessionimpl.h" +#include "qxacommon.h" + +/* The following declaration is required to allow QList<int> to be added to + * QVariant + */ +Q_DECLARE_METATYPE(QList<uint>) + +/* This macro checks for m_impl null pointer. If it is, emits an error signal + * error(QMediaRecorder::ResourceError, tr("Service has not been started")); + * and returns from function immediately with value 's'. + */ + +#define RETURN_s_IF_m_impl_IS_NULL(s) \ + if (!m_impl) { \ + emit error(QMediaRecorder::ResourceError, QXARecordSession::tr("Service has not been started")); \ + SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::ResourceError, tr(\"Service has not been started\"))"); \ + return s; \ + } + +/* This macro checks for m_impl null pointer. If it is, emits an error signal + * error(QMediaRecorder::ResourceError, tr("Service has not been started")); + * and returns from function immediately. + */ +#define RETURN_IF_m_impl_IS_NULL \ + if (!m_impl) { \ + emit error(QMediaRecorder::ResourceError, QXARecordSession::tr("Service has not been started")); \ + SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::ResourceError, tr(\"Service has not been started\"))"); \ + return; \ + } + +QXARecordSession::QXARecordSession(QObject *parent) +:QObject(parent), +m_state(QMediaRecorder::StoppedState), +m_previousState(QMediaRecorder::StoppedState) +{ + QT_TRACE_FUNCTION_ENTRY; + m_impl = NULL; + m_impl = new XARecordSessionImpl(*this); + if (m_impl) { + if (m_impl->postConstruct() == KErrNone) { + initCodecsList(); + initContainersList(); + m_containerMimeType = QString("audio/wav"); + m_audioencodersettings.setCodec("pcm"); + m_audioencodersettings.setBitRate(0); + m_audioencodersettings.setChannelCount(-1); + m_audioencodersettings.setEncodingMode(QtMultimediaKit::ConstantQualityEncoding); + m_audioencodersettings.setQuality(QtMultimediaKit::NormalQuality); + m_audioencodersettings.setSampleRate(-1); + setEncoderSettingsToImpl(); + m_URItoImplSet = false; + QT_TRACE1("Initialized implementation"); + } + else { + delete m_impl; + m_impl = NULL; + QT_TRACE1("Error initializing implementation"); + } + } + else { + emit error(QMediaRecorder::ResourceError, tr("Unable to start Service")); + } + QT_TRACE_FUNCTION_EXIT; +} + +QXARecordSession::~QXARecordSession() +{ + QT_TRACE_FUNCTION_ENTRY; + delete m_impl; + QT_TRACE_FUNCTION_EXIT; +} + +QUrl QXARecordSession::outputLocation() +{ + return m_outputLocation; +} + +bool QXARecordSession::setOutputLocation(const QUrl &location) +{ + QT_TRACE_FUNCTION_ENTRY; + + RETURN_s_IF_m_impl_IS_NULL(false); + + // Location can be set only when recorder is in stopped state. + if (state() != QMediaRecorder::StoppedState) + return false; + + // Validate URL + if (!location.isValid()) + return false; + + // If old and new locations are same, do nothing. + QString newUrlStr = (QUrl::fromUserInput(location.toString())).toString(); + QString curUrlStr = (QUrl::fromUserInput(m_outputLocation.toString())).toString(); + if (curUrlStr.compare(newUrlStr) == KErrNone) + return true; + + QT_TRACE2("Location:", newUrlStr); + m_outputLocation = location; + /* New file, so user can set new settings */ + m_previousState = QMediaRecorder::StoppedState; + m_URItoImplSet = false; + + QT_TRACE_FUNCTION_EXIT; + return true; +} + +QMediaRecorder::State QXARecordSession::state() +{ + return m_state; +} + +qint64 QXARecordSession::duration() +{ + TInt64 dur(0); + + QT_TRACE_FUNCTION_ENTRY; + + RETURN_s_IF_m_impl_IS_NULL(dur); + + m_impl->duration(dur); + + QT_TRACE_FUNCTION_EXIT; + return (qint64)dur; +} + +void QXARecordSession::applySettings() +{ + /* Settings can only be applied when the recorder is in the stopped + * state after creation. */ + if ((state() == QMediaRecorder::StoppedState) && (m_state == m_previousState)) { + if (m_appliedaudioencodersettings != m_audioencodersettings) + setEncoderSettingsToImpl(); + } + else { + emit error(QMediaRecorder::FormatError, tr("Settings cannot be changed once recording started")); + SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::FormatError, tr(\"Settings cannot be changed once recording started\"))"); + } +} + +void QXARecordSession::record() +{ + QT_TRACE_FUNCTION_ENTRY; + + RETURN_IF_m_impl_IS_NULL; + + /* No op if object is already in recording state */ + if (state() == QMediaRecorder::RecordingState) + return; + + /* 1. Set encoder settings here */ + if (m_appliedaudioencodersettings != m_audioencodersettings) + RET_IF_FALSE(setEncoderSettingsToImpl()); + + /* 2. Set URI to impl */ + RET_IF_FALSE(setURIToImpl()); + + /* 3. Start recording... + * If successful, setRecorderState(QMediaRecorder::RecordingState); + * will be called from the callback cbRecordingStarted() + */ + if (m_impl->record() != KErrNone) { + emit error(QMediaRecorder::ResourceError, tr("Generic error")); + SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::ResourceError, tr(\"Generic error\"))"); + } + + QT_TRACE_FUNCTION_EXIT; +} + +void QXARecordSession::pause() +{ + QT_TRACE_FUNCTION_ENTRY; + + RETURN_IF_m_impl_IS_NULL; + + /* No op if object is already in paused/stopped state */ + if ((state() == QMediaRecorder::PausedState) || (state() == QMediaRecorder::StoppedState)) { + return; + } + + if (m_impl->pause() == KErrNone) { + setRecorderState(QMediaRecorder::PausedState); + } + else { + emit error(QMediaRecorder::ResourceError, tr("Unable to pause")); + SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::ResourceError, tr(\"Unable to pause\"))"); + } + + QT_TRACE_FUNCTION_EXIT; +} + +void QXARecordSession::stop() +{ + QT_TRACE_FUNCTION_ENTRY; + + RETURN_IF_m_impl_IS_NULL; + + /* No op if object is already in paused state */ + if (state() == QMediaRecorder::StoppedState) + return; + + if ((m_impl->stop() == KErrNone)) { + setRecorderState(QMediaRecorder::StoppedState); + } + else { + emit error(QMediaRecorder::ResourceError, tr("Unable to stop")); + SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::ResourceError, tr(\"Unable to stop\"))"); + } + + QT_TRACE_FUNCTION_EXIT; +} + +void QXARecordSession::cbDurationChanged(TInt64 new_pos) +{ + QT_TRACE_FUNCTION_ENTRY; + + emit durationChanged((qint64)new_pos); + SIGNAL_EMIT_TRACE1("emit durationChanged((qint64)new_pos);"); + + QT_TRACE_FUNCTION_EXIT; +} + +void QXARecordSession::cbAvailableAudioInputsChanged() +{ + QT_TRACE_FUNCTION_ENTRY; + + emit availableAudioInputsChanged(); + SIGNAL_EMIT_TRACE1("emit availableAudioInputsChanged();"); + + QT_TRACE_FUNCTION_EXIT; +} + +void QXARecordSession::cbRecordingStarted() +{ + QT_TRACE_FUNCTION_ENTRY; + + setRecorderState(QMediaRecorder::RecordingState); + + QT_TRACE_FUNCTION_EXIT; +} + +void QXARecordSession::cbRecordingStopped() +{ + QT_TRACE_FUNCTION_ENTRY; + + emit error(QMediaRecorder::ResourceError, tr("Resources Unavailable")); + SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::ResourceError, tr(\"Resources Unavailable\"))"); + setRecorderState(QMediaRecorder::StoppedState); + /* Set record state to Stopped */ + if (m_impl) + m_impl->stop(); + + QT_TRACE_FUNCTION_EXIT; +} + +/* For QAudioEndpointSelector begin */ +QList<QString> QXARecordSession::availableEndpoints() +{ + QT_TRACE_FUNCTION_ENTRY; + + QList<QString> strList; + + RETURN_s_IF_m_impl_IS_NULL(strList); + + QString str; + RArray<TPtrC> names; + m_impl->getAudioInputDeviceNames(names); + for (TInt index = 0; index < names.Count(); index++) { + str = QString((QChar*)names[index].Ptr(), names[index].Length()); + strList.append(str); + } + + QT_TRACE_FUNCTION_EXIT; + return strList; +} + +QString QXARecordSession::endpointDescription(const QString &name) +{ + /* From AL we get only device name */ + return name; +} + +QString QXARecordSession::defaultEndpoint() +{ + QT_TRACE_FUNCTION_ENTRY; + + QString str; + + RETURN_s_IF_m_impl_IS_NULL(str); + + TPtrC name; + if(m_impl->defaultAudioInputDevice(name) == KErrNone) + str = QString((QChar*)name.Ptr(), name.Length()); + + QT_TRACE_FUNCTION_EXIT; + return str; +} + +QString QXARecordSession::activeEndpoint() +{ + QT_TRACE_FUNCTION_ENTRY; + + QString str; + + RETURN_s_IF_m_impl_IS_NULL(str); + + TPtrC name; + if(m_impl->activeAudioInputDevice(name) == KErrNone) + str = QString((QChar*)name.Ptr(), name.Length()); + + QT_TRACE_FUNCTION_EXIT; + return str; +} + +void QXARecordSession::setActiveEndpoint(const QString &name) +{ + QT_TRACE_FUNCTION_ENTRY; + + RETURN_IF_m_impl_IS_NULL; + + if (name.isNull() || name.isEmpty()) + return; + + TPtrC16 tempPtr(reinterpret_cast<const TUint16*>(name.utf16())); + if (m_impl->setAudioInputDevice(tempPtr) == true) { + emit activeEndpointChanged(name); + SIGNAL_EMIT_TRACE1("emit activeEndpointChanged(name)"); + } + else { + emit error(QMediaRecorder::ResourceError, tr("Invalid endpoint")); + SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::ResourceError, tr(\"Invalid endpoint\"))"); + } + + QT_TRACE_FUNCTION_EXIT; +} +/* For QAudioEndpointSelector end */ + +/* For QAudioEncoderControl begin */ +QStringList QXARecordSession::supportedAudioCodecs() +{ + return m_codecs; +} + +QString QXARecordSession::codecDescription(const QString &codecName) +{ + if (m_codecs.contains(codecName)) + return QString(codecName); + return QString(); +} + +QList<int> QXARecordSession::supportedSampleRates( + const QAudioEncoderSettings &settings, + bool *continuous) +{ + QT_TRACE_FUNCTION_ENTRY; + + QList<int> srList; + + RETURN_s_IF_m_impl_IS_NULL(srList); + + QString selectedCodec = settings.codec(); + if (selectedCodec.isNull() || selectedCodec.isEmpty()) + selectedCodec = QString("pcm"); + + if (m_codecs.indexOf(selectedCodec) >= 0) { + RArray<TInt32> sampleRates; + TBool isContinuous; + TPtrC16 tempPtr(reinterpret_cast<const TUint16*>(selectedCodec.utf16())); + if (m_impl->getSampleRates(tempPtr, sampleRates, isContinuous) == KErrNone) { + for (TInt index = 0; index < sampleRates.Count(); index++) + srList.append(sampleRates[index]); + sampleRates.Close(); + if (continuous) + { + *continuous = false; + if (isContinuous == true) + *continuous = true; + } + } + } + + QT_TRACE_FUNCTION_EXIT; + return srList; +} + +QAudioEncoderSettings QXARecordSession::audioSettings() +{ + return m_appliedaudioencodersettings; +} + +void QXARecordSession::setAudioSettings(const QAudioEncoderSettings &settings) +{ + /* Settings can only be set when the recorder is in the stopped + * state after creation. */ + if ((state() == QMediaRecorder::StoppedState) && (m_state == m_previousState)) { + /* Validate and ignore rest of the settings */ + m_audioencodersettings = settings; + } + else { + emit error(QMediaRecorder::FormatError, tr("Settings cannot be changed once recording started")); + SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::FormatError, tr(\"Settings cannot be changed once recording started\"))"); + } +} + +QStringList QXARecordSession::supportedEncodingOptions(const QString &codec) +{ + QT_TRACE_FUNCTION_ENTRY; + Q_UNUSED(codec); + QStringList options; + if ((codec.compare("aac") == 0) || + (codec.compare("amr") == 0)) + { + options << "bitrate" << "quality"; + } + + + QT_TRACE_FUNCTION_EXIT; + return options; +} + +QVariant QXARecordSession::encodingOption(const QString &codec, const QString &name) +{ + QT_TRACE_FUNCTION_ENTRY; + + QVariant encodingOption; + QMap<QString, QVariant> map; + RETURN_s_IF_m_impl_IS_NULL(encodingOption); + + if (name.compare("bitrate") == 0) { + TPtrC16 tempPtr(reinterpret_cast<const TUint16*>(codec.utf16())); + QList<uint> bitrateList; + RArray<TUint32> bitrates; + TBool continuous; + if (m_impl->getBitrates(tempPtr, bitrates, continuous) == KErrNone) { + for (TInt index = 0; index < bitrates.Count(); index++) + bitrateList.append(bitrates[index]); + bitrates.Close(); + } + encodingOption.setValue(bitrateList); + map.insert("continuous", QVariant(continuous)); + map.insert("bitrates", encodingOption); + } + + QT_TRACE_FUNCTION_EXIT; + return map; +} + +void QXARecordSession::setEncodingOption( + const QString &codec, + const QString &name, + const QVariant &value) +{ + /* + * Currently nothing can be set via this function. + * Bitrate is set via QAudioEncoderSettings::setBitrate(). + */ + Q_UNUSED(codec); + Q_UNUSED(name); + Q_UNUSED(value); +} +/* For QAudioEncoderControl end */ + +QStringList QXARecordSession::supportedContainers() +{ + return m_containers; +} + +QString QXARecordSession::containerMimeType() +{ + return m_containerMimeType; +} + +void QXARecordSession::setContainerMimeType(const QString &formatMimeType) +{ + if (formatMimeType.isNull() || formatMimeType.isEmpty()) + return; + else if (m_containers.indexOf(formatMimeType) >= 0 ) + m_containerMimeType = formatMimeType; + else { + emit error(QMediaRecorder::FormatError, tr("Invalid container")); + SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::FormatError, tr(\"Invalid container\"))"); + } +} + +QString QXARecordSession::containerDescription(const QString &formatMimeType) +{ + int index = m_containers.indexOf(formatMimeType); + if (index >= 0) { + return m_containersDesc.at(index); + } + else { + emit error(QMediaRecorder::FormatError, tr("Invalid container")); + SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::FormatError, tr(\"Invalid container\"))"); + } + return QString(); +} + +void QXARecordSession::setRecorderState(QMediaRecorder::State state) +{ + if (state != m_state) { + m_previousState = m_state; + m_state = state; + emit stateChanged(m_state); + SIGNAL_EMIT_TRACE1("emit stateChanged(m_state);"); + } +} + +void QXARecordSession::initCodecsList() +{ + QT_TRACE_FUNCTION_ENTRY; + + RETURN_IF_m_impl_IS_NULL; + + m_codecs.clear(); + + const RArray<TPtrC>& names = m_impl->getAudioEncoderNames(); + QString str; + + for (TInt index = 0; index < names.Count(); index++) { + str = QString((QChar*)names[index].Ptr(), names[index].Length()); + m_codecs.append(str); + } + QT_TRACE_FUNCTION_EXIT; +} + +void QXARecordSession::initContainersList() +{ + QT_TRACE_FUNCTION_ENTRY; + + RETURN_IF_m_impl_IS_NULL; + + m_containers.clear(); + m_containersDesc.clear(); + + const RArray<TPtrC>& names = m_impl->getContainerNames(); + const RArray<TPtrC>& descs = m_impl->getContainerDescs(); + QString str; + + for (TInt32 index = 0; index < names.Count(); index++) { + str = QString((QChar*)names[index].Ptr(), names[index].Length()); + m_containers.append(str); + str = QString((QChar*)descs[index].Ptr(), descs[index].Length()); + m_containersDesc.append(str); + } + QT_TRACE_FUNCTION_EXIT; +} + +bool QXARecordSession::setEncoderSettingsToImpl() +{ + QT_TRACE_FUNCTION_ENTRY; + + RETURN_s_IF_m_impl_IS_NULL(false); + + m_impl->resetEncoderAttributes(); + + /* m_containerMimeType is alredy validated in ::setContainerMimeType() */ + QString tempStr = m_containerMimeType; + TPtrC16 tempPtr(reinterpret_cast<const TUint16 *>(tempStr.utf16())); + m_impl->setContainerType(tempPtr); + + /* vaidate and assign codec */ + if (m_audioencodersettings.codec().isNull() || m_audioencodersettings.codec().isEmpty()) { + m_audioencodersettings.setCodec(m_appliedaudioencodersettings.codec()); + } + tempStr = m_audioencodersettings.codec(); + if (m_codecs.indexOf(tempStr) >= 0) { + tempPtr.Set(reinterpret_cast<const TUint16*>(tempStr.utf16())); + /* We already did validation above, so function always returns true */ + m_impl->setCodec(tempPtr); + } + else { + QT_TRACE2("Codec selected is :", m_audioencodersettings.codec()); + emit error(QMediaRecorder::FormatError, tr("Invalid codec")); + SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::FormatError, tr(\"Invalid codec\"));"); + return false; + } + + /* Validate and set bitrate only if encoding mode is other than quality encoding and container type is not wav*/ + if ((m_audioencodersettings.encodingMode() != QtMultimediaKit::ConstantQualityEncoding) && + (m_containerMimeType.compare("audio/wav") != 0)) { + m_impl->setBitRate(m_audioencodersettings.bitRate()); + m_audioencodersettings.setBitRate(m_impl->getBitRate()); + } + + if (m_audioencodersettings.channelCount() == -1) { + m_impl->setOptimalChannelCount(); + } + else { + m_impl->setChannels(m_audioencodersettings.channelCount()); + m_audioencodersettings.setChannelCount(m_impl->getChannels()); + } + + switch (m_audioencodersettings.encodingMode()) { + case QtMultimediaKit::ConstantQualityEncoding: { + switch (m_audioencodersettings.quality()) { + case QtMultimediaKit::VeryLowQuality: + m_impl->setVeryLowQuality(); + m_audioencodersettings.setBitRate(m_impl->getBitRate()); + break; + case QtMultimediaKit::LowQuality: + m_impl->setLowQuality(); + m_audioencodersettings.setBitRate(m_impl->getBitRate()); + break; + case QtMultimediaKit::NormalQuality: + m_impl->setNormalQuality(); + m_audioencodersettings.setBitRate(m_impl->getBitRate()); + break; + case QtMultimediaKit::HighQuality: + m_impl->setHighQuality(); + m_audioencodersettings.setBitRate(m_impl->getBitRate()); + break; + case QtMultimediaKit::VeryHighQuality: + m_impl->setVeryHighQuality(); + m_audioencodersettings.setBitRate(m_impl->getBitRate()); + break; + default: + break; + }; /* end of switch (m_audioencodersettings.quality())*/ + } + break; + case QtMultimediaKit::ConstantBitRateEncoding: { + TInt32 status = m_impl->setCBRMode(); + if (status == KErrNotSupported) { + emit error(QMediaRecorder::FormatError, tr("Invalid encoding mode setting")); + SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::FormatError, tr(\"Invalid encoding mode setting\"));"); + return false; + } + else if (status != KErrNone) { + emit error(QMediaRecorder::ResourceError, tr("Internal error")); + SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::ResourceError, tr(\"Internal error\"));"); + return false; + } + } + break; + case QtMultimediaKit::AverageBitRateEncoding: { + TInt32 status = m_impl->setVBRMode(); + if (status == KErrNotSupported) { + emit error(QMediaRecorder::FormatError, tr("Invalid encoding mode setting")); + SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::FormatError, tr(\"Invalid encoding mode setting\"));"); + return false; + } + else if (status != KErrNone) { + emit error(QMediaRecorder::ResourceError, tr("Internal error")); + SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::ResourceError, tr(\"Internal error\"));"); + return false; + } + } + break; + case QtMultimediaKit::TwoPassEncoding: + // fall through + default: { + emit error(QMediaRecorder::FormatError, tr("Invalid encoding mode setting")); + SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::FormatError, tr(\"Invalid encoding mode setting\"));"); + return false; + } + }; /* switch (m_audioencodersettings.encodingMode()) */ + + if (m_audioencodersettings.sampleRate() == -1) { + m_impl->setOptimalSampleRate(); + } + else { + m_impl->setSampleRate(m_audioencodersettings.sampleRate()); + m_audioencodersettings.setSampleRate(m_impl->getSampleRate()); + } + m_appliedaudioencodersettings = m_audioencodersettings; + + QT_TRACE_FUNCTION_EXIT; + return true; +} + +bool QXARecordSession::setURIToImpl() +{ + QT_TRACE_FUNCTION_ENTRY; + if (m_URItoImplSet) + return true; + + /* If m_outputLocation is null, set a default location */ + if (m_outputLocation.isEmpty()) { + QDir outputDir(QDir::rootPath()); + + int lastImage = 0; + int fileCount = 0; + foreach(QString fileName, outputDir.entryList(QStringList() << "recordclip_*")) { + int imgNumber = fileName.mid(5, fileName.size() - 9).toInt(); + lastImage = qMax(lastImage, imgNumber); + if (outputDir.exists(fileName)) + fileCount += 1; + } + lastImage += fileCount; + m_outputLocation = QUrl(QDir::toNativeSeparators(outputDir.canonicalPath() + QString("/recordclip_%1").arg(lastImage + 1, 4, 10, QLatin1Char('0')))); + } + + QString newUrlStr = (QUrl::fromUserInput(m_outputLocation.toString())).toString(); + // append file prefix if required + if (newUrlStr.lastIndexOf('.') == -1) { + QString fileExtension; + if ((m_containerMimeType.compare("audio/wav")) == KErrNone) { + fileExtension = QString(".wav"); + } + else if ((m_containerMimeType.compare("audio/amr")) == KErrNone) { + fileExtension = QString(".amr"); + } + else if ((m_containerMimeType.compare("audio/mpeg")) == KErrNone) { + fileExtension = QString(".mp4"); + } + newUrlStr.append(fileExtension); + } + + QT_TRACE2("Filename selected is :", newUrlStr); + TPtrC16 tempPtr(reinterpret_cast<const TUint16 *>(newUrlStr.utf16())); + if (m_impl->setURI(tempPtr) != 0) { + emit error(QMediaRecorder::ResourceError, tr("Generic error")); + SIGNAL_EMIT_TRACE1("emit error(QMediaRecorder::ResourceError, tr(\"Generic error\"))"); + return false; + } + m_URItoImplSet = true; + m_outputLocation = QUrl(newUrlStr); + QT_TRACE_FUNCTION_EXIT; + return true; +} diff --git a/src/plugins/symbian/openmaxal/mediarecorder/qxarecordsession.h b/src/plugins/symbian/openmaxal/mediarecorder/qxarecordsession.h new file mode 100644 index 000000000..cabe58fc9 --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediarecorder/qxarecordsession.h @@ -0,0 +1,144 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXARECORDSESSION_H +#define QXARECORDSESSION_H + +#include <QObject> +#include <QUrl> +#include "qmediarecorder.h" +#include "xarecordsessioncommon.h" + +QT_USE_NAMESPACE + +class XARecordSessionImpl; + +/* + * This is a backend class for all QXXXControl objects. + * This class contains actual implementation of recording functionality + * from the control object's perspective. + */ + + +class QXARecordSession : public QObject, + public XARecordObserver +{ +Q_OBJECT + +public: + QXARecordSession(QObject *parent); + virtual ~QXARecordSession(); + + /* For QMediaRecorderControl begin */ + QUrl outputLocation(); + bool setOutputLocation(const QUrl &location); + QMediaRecorder::State state(); + qint64 duration(); + void applySettings(); + + void record(); + void pause(); + void stop(); + + void cbDurationChanged(TInt64 new_pos); + void cbAvailableAudioInputsChanged(); + void cbRecordingStarted(); + void cbRecordingStopped(); + /* For QMediaRecorderControl end */ + + /* For QAudioEndpointSelector begin */ + QList<QString> availableEndpoints(); + QString endpointDescription(const QString &name); + QString defaultEndpoint(); + QString activeEndpoint(); + void setActiveEndpoint(const QString &name); + /* For QAudioEndpointSelector end */ + + /* For QAudioEncoderControl begin */ + QStringList supportedAudioCodecs(); + QString codecDescription(const QString &codecName); + QList<int> supportedSampleRates( + const QAudioEncoderSettings &settings, + bool *continuous); + QAudioEncoderSettings audioSettings(); + void setAudioSettings(const QAudioEncoderSettings &settings); + QStringList supportedEncodingOptions(const QString &codec); + QVariant encodingOption(const QString &codec, const QString &name); + void setEncodingOption(const QString &codec, const QString &name, const QVariant &value); + /* For QAudioEncoderControl end */ + + /* For QMediaContainerControl begin */ + QStringList supportedContainers(); + QString containerMimeType(); + void setContainerMimeType(const QString &formatMimeType); + QString containerDescription(const QString &formatMimeType); + /* For QMediaContainerControl end */ + +Q_SIGNALS: + void stateChanged(QMediaRecorder::State state); + void durationChanged(qint64 duration); + void error(int error, const QString &errorString); + void activeEndpointChanged(const QString& name); + void availableAudioInputsChanged(); + +private: + void setRecorderState(QMediaRecorder::State state); + void initCodecsList(); + void initContainersList(); + bool setEncoderSettingsToImpl(); + bool setURIToImpl(); + +private: + /* Own */ + XARecordSessionImpl *m_impl; + QUrl m_outputLocation; + bool m_URItoImplSet; + QMediaRecorder::State m_state; + QMediaRecorder::State m_previousState; + QStringList m_codecs; + QAudioEncoderSettings m_audioencodersettings; + QAudioEncoderSettings m_appliedaudioencodersettings; + QStringList m_containers; + QStringList m_containersDesc; + QString m_containerMimeType; +}; + +#endif /* QXARECORDSESSION_H */ diff --git a/src/plugins/symbian/openmaxal/mediarecorder/xarecordsessioncommon.h b/src/plugins/symbian/openmaxal/mediarecorder/xarecordsessioncommon.h new file mode 100644 index 000000000..cdf8c1886 --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediarecorder/xarecordsessioncommon.h @@ -0,0 +1,67 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef XARECORDSESSIONCOMMON_H +#define XARECORDSESSIONCOMMON_H + +#include <e32base.h> +#include "xacommon.h" + +#define MAX_NUMBER_INTERFACES 20 +#define MAX_NUMBER_INPUT_DEVICES 10 +#define MAX_NUMBER_ENCODERS 10 + +//const TInt32 KExtErr = (TInt32)(-2147483648); +const TInt32 KExtErr = -32768; +const TInt32 KExtErrUnspecifiedCodecForContainer = (KExtErr+1); +const TInt32 KExtErrUnsupportedCodecForContainer = (KExtErr+2); +const TInt32 KExtErrUnsupportedURISuffixForContainer = (KExtErr+3); + +class XARecordObserver +{ +public: + virtual void cbDurationChanged(TInt64 new_pos) = 0; + virtual void cbAvailableAudioInputsChanged() = 0; + virtual void cbRecordingStarted() = 0; + virtual void cbRecordingStopped() = 0; +}; + +#endif /* XARECORDSESSIONCOMMON_H */ diff --git a/src/plugins/symbian/openmaxal/mediarecorder/xarecordsessionimpl.cpp b/src/plugins/symbian/openmaxal/mediarecorder/xarecordsessionimpl.cpp new file mode 100644 index 000000000..d18c781d4 --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediarecorder/xarecordsessionimpl.cpp @@ -0,0 +1,1378 @@ +/**************************************************************************** + ** + ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). + ** All rights reserved. + ** Contact: Nokia Corporation (qt-info@nokia.com) + ** + ** This file is part of the Qt Mobility Components. + ** + ** $QT_BEGIN_LICENSE:LGPL$ + ** No Commercial Usage + ** This file contains pre-release code and may not be distributed. + ** You may use this file in accordance with the terms and conditions + ** contained in the Technology Preview License Agreement accompanying + ** this package. + ** + ** GNU Lesser General Public License Usage + ** Alternatively, 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. + ** + ** If you have questions regarding the use of this file, please contact + ** Nokia at qt-info@nokia.com. + ** + ** + ** + ** + ** + ** + ** + ** + ** $QT_END_LICENSE$ + ** + ****************************************************************************/ +#include "xarecordsessionimpl.h" +#include "xarecordsessioncommon.h" +_LIT8(K8WAVMIMETYPE, "audio/x-wav"); +/* + * These codec names are not part of AL. Hence we need to define names here. + * */ +_LIT(KAUDIOCODECPCM, "pcm"); +_LIT(KAUDIOCODECAMR, "amr"); +_LIT(KAUDIOCODECAAC, "aac"); +_LIT(KCONTAINERWAV, "audio/wav"); +_LIT(KCONTAINERWAVDESC, "wav container"); +_LIT(KCONTAINERAMR, "audio/amr"); +_LIT(KCONTAINERAMRDESC, "amr File format"); +_LIT(KCONTAINERMP4, "audio/mpeg"); +_LIT(KCONTAINERMP4DESC, "mpeg container"); + +const TUint KRecordPosUpdatePeriod = 1000; +const TUint KMilliToHz = 1000; +const TUint KMaxNameLength = 256; + +/* Local functions for callback registation */ +void cbXAObjectItf( + XAObjectItf caller, + const void *pContext, + XAuint32 event, + XAresult result, + XAuint32 param, + void *pInterface); + +void cbXARecordItf( + XARecordItf caller, + void *pContext, + XAuint32 event); + +void cbXAAvailableAudioInputsChanged( + XAAudioIODeviceCapabilitiesItf caller, + void *pContext, + XAuint32 deviceID, + XAint32 numInputs, + XAboolean isNew); + +XARecordSessionImpl::XARecordSessionImpl(XARecordObserver &parent) : + m_Parent(parent), + m_EOEngine(NULL), + m_MORecorder(NULL), + m_RecordItf(NULL), + m_AudioEncItf(NULL), + m_WAVMime(NULL), + m_URIName(NULL), + m_InputDeviceId(0), + m_ContainerType(0), + m_BitRate(0), + m_RateControl(0), + m_ChannelsOut(1), + m_SampleRate(0), + m_AudioIODevCapsItf(NULL), + m_AudioInputDeviceNames(NULL), + m_DefaultAudioInputDeviceNames(NULL), + m_AudioEncCapsItf(NULL) +{ + TRACE_FUNCTION_ENTRY_EXIT; +} + +XARecordSessionImpl::~XARecordSessionImpl() +{ + TRACE_FUNCTION_ENTRY; + + if (m_MORecorder) + (*m_MORecorder)->Destroy(m_MORecorder); + + if (m_EOEngine) + (*m_EOEngine)->Destroy(m_EOEngine); + + delete m_WAVMime; + delete m_URIName; + + m_InputDeviceIDs.Close(); + if (m_AudioInputDeviceNames) + m_AudioInputDeviceNames->Reset(); + delete m_AudioInputDeviceNames; + m_DefaultInputDeviceIDs.Close(); + if (m_DefaultAudioInputDeviceNames) + m_DefaultAudioInputDeviceNames->Reset(); + delete m_DefaultAudioInputDeviceNames; + m_EncoderIds.Close(); + m_EncoderNames.Close(); + m_ContainerNames.Close(); + m_ContainerDescs.Close(); + + TRACE_FUNCTION_EXIT; +} + +TInt32 XARecordSessionImpl::postConstruct() +{ + TRACE_FUNCTION_ENTRY; + + XAEngineOption engineOption[] = { (XAuint32) XA_ENGINEOPTION_THREADSAFE, (XAuint32) XA_BOOLEAN_TRUE}; + + /* Create and realize Engine object */ + TRACE_LOG(_L("XARecordSessionImpl: Creating Engine...")); + XAresult xa_result = xaCreateEngine(&m_EOEngine, 1, engineOption, 0, NULL, NULL); + TInt returnValue = mapError(xa_result, ETrue); + RET_ERR_IF_ERR(returnValue); + TRACE_LOG(_L("XARecordSessionImpl: Realizing engine...")); + xa_result = (*m_EOEngine)->Realize(m_EOEngine, XA_BOOLEAN_FALSE); + returnValue = mapError(xa_result, ETrue); + RET_ERR_IF_ERR(returnValue); + TRACE_LOG(_L("XARecordSessionImpl: OMX AL Engine realized successfully")); + + XAEngineItf engineItf; + xa_result = (*m_EOEngine)->GetInterface(m_EOEngine, XA_IID_ENGINE, (void**) &engineItf); + returnValue = mapError(xa_result, ETrue); + RET_ERR_IF_ERR(returnValue); + + xa_result = (*m_EOEngine)->GetInterface(m_EOEngine, + XA_IID_AUDIOIODEVICECAPABILITIES, + (void**) &m_AudioIODevCapsItf); + returnValue = mapError(xa_result, ETrue); + RET_ERR_IF_ERR(returnValue); + xa_result = (*m_AudioIODevCapsItf)->RegisterAvailableAudioInputsChangedCallback( + m_AudioIODevCapsItf, + cbXAAvailableAudioInputsChanged, + (void*)this); + + xa_result = (*m_EOEngine)->GetInterface( + m_EOEngine, + XA_IID_AUDIOENCODERCAPABILITIES, + (void**) &m_AudioEncCapsItf); + returnValue = mapError(xa_result, ETrue); + RET_ERR_IF_ERR(returnValue); + + TRAP(returnValue, m_WAVMime = HBufC8::NewL(K8WAVMIMETYPE().Length() + 1)); + RET_ERR_IF_ERR(returnValue); + TPtr8 ptr = m_WAVMime->Des(); + ptr = K8WAVMIMETYPE(); // copy uri name into local variable + ptr.PtrZ(); // append zero terminator to end of URI + + m_AudioInputDeviceNames = new CDesC16ArrayFlat(2); + if (m_AudioInputDeviceNames == NULL) + returnValue = KErrNoMemory; + RET_ERR_IF_ERR(returnValue); + + m_DefaultAudioInputDeviceNames = new CDesC16ArrayFlat(2); + if (m_DefaultAudioInputDeviceNames == NULL) + returnValue = KErrNoMemory; + RET_ERR_IF_ERR(returnValue); + + returnValue = initContainersList(); + RET_ERR_IF_ERR(returnValue); + returnValue = initAudioEncodersList(); + RET_ERR_IF_ERR(returnValue); + returnValue = initAudioInputDevicesList(); + RET_ERR_IF_ERR(returnValue); + + TRACE_FUNCTION_EXIT; + return returnValue; +} + +TInt32 XARecordSessionImpl::setURI(const TDesC &aURI) +{ + TRACE_FUNCTION_ENTRY; + + /* This function will only get called when aURI is different than m_URIName + * and only when recorder is in stopped state. + * If the recorder object was created for a different URI (than aURI), we + * need to tear it down here. + */ + if (m_MORecorder) { + (*m_MORecorder)->Destroy(m_MORecorder); + m_MORecorder = NULL; + m_RecordItf = NULL; + } + + delete m_URIName; + m_URIName = NULL; + TRAPD(returnValue, m_URIName = HBufC8::NewL(aURI.Length()+1)); + RET_ERR_IF_ERR(returnValue); + + TPtr8 uriPtr = m_URIName->Des(); + /* copy uri name into local variable */ + uriPtr.Copy(aURI); + + TRACE_FUNCTION_EXIT; + return returnValue; +} + +TInt32 XARecordSessionImpl::record() +{ + TRACE_FUNCTION_ENTRY; + + TInt32 returnValue(KErrGeneral); + if (!m_MORecorder || !m_RecordItf) { + TRACE_LOG(_L("XARecordSessionImpl::Record: MORecorder/RecordItf is not created")); + returnValue = createMediaRecorderObject(); + RET_ERR_IF_ERR(returnValue); + + returnValue = setEncoderSettingsToMediaRecorder(); + RET_ERR_IF_ERR(returnValue); + } + + XAuint32 state; + XAresult xa_result = (*m_RecordItf)->GetRecordState(m_RecordItf, &state); + returnValue = mapError(xa_result, ETrue); + RET_ERR_IF_ERR(returnValue); + + if ((state == XA_RECORDSTATE_STOPPED) + || (state == XA_RECORDSTATE_PAUSED)) { + TRACE_LOG(_L("XARecordSessionImpl::Record: Setting State to Recording...")); + xa_result = (*m_RecordItf)->SetRecordState(m_RecordItf, XA_RECORDSTATE_RECORDING); + returnValue = mapError(xa_result, ETrue); + RET_ERR_IF_ERR(returnValue); + TRACE_LOG(_L("XARecordSessionImpl::Record: SetState to Recording")); + } + + TRACE_FUNCTION_EXIT; + return returnValue; +} + +TInt32 XARecordSessionImpl::pause() +{ + TRACE_FUNCTION_ENTRY; + + TInt32 returnValue(KErrGeneral); + if (!m_MORecorder || !m_RecordItf) { + TRACE_LOG(_L("XARecordSessionImpl::Record: MORecorder/RecordItf is not created")); + return returnValue; + } + + XAuint32 state; + XAresult xa_result = (*m_RecordItf)->GetRecordState(m_RecordItf, &state); + returnValue = mapError(xa_result, ETrue); + RET_ERR_IF_ERR(returnValue); + + if ((state == XA_RECORDSTATE_STOPPED) + || (state == XA_RECORDSTATE_RECORDING)) { + TRACE_LOG(_L("XARecordSessionImpl::Record: Setting State to Paused...")); + xa_result = (*m_RecordItf)->SetRecordState(m_RecordItf, XA_RECORDSTATE_PAUSED); + returnValue = mapError(xa_result, ETrue); + RET_ERR_IF_ERR(returnValue); + TRACE_LOG(_L("XARecordSessionImpl::Record: SetState to Paused")); + } + + TRACE_FUNCTION_EXIT; + return returnValue; +} + +TInt32 XARecordSessionImpl::stop() +{ + TRACE_FUNCTION_ENTRY; + + TInt32 returnValue(KErrGeneral); + if (!m_MORecorder || !m_RecordItf) { + TRACE_LOG(_L("XARecordSessionImpl::Record: MORecorder/RecordItf is not created")); + return returnValue; + } + + XAuint32 state; + XAresult xa_result = (*m_RecordItf)->GetRecordState(m_RecordItf, &state); + returnValue = mapError(xa_result, ETrue); + RET_ERR_IF_ERR(returnValue); + + if ((state == XA_RECORDSTATE_PAUSED) + || (state == XA_RECORDSTATE_RECORDING)) { + TRACE_LOG(_L("XARecordSessionImpl::Record: Setting State to Stopped...")); + xa_result = (*m_RecordItf)->SetRecordState(m_RecordItf, XA_RECORDSTATE_STOPPED); + returnValue = mapError(xa_result, ETrue); + RET_ERR_IF_ERR(returnValue); + TRACE_LOG(_L("XARecordSessionImpl::Record: SetState to Stopped")); + } + + TRACE_FUNCTION_EXIT; + return returnValue; +} + +TInt32 XARecordSessionImpl::duration(TInt64 &aDur) +{ + TRACE_FUNCTION_ENTRY; + + TInt32 returnValue(KErrGeneral); + + if (!m_MORecorder || !m_RecordItf) { + TRACE_LOG(_L("XARecordSessionImpl::Duration: MORecoder/RecordItf is not created")); + return returnValue; + } + + XAmillisecond milliSec; + XAresult xa_result = (*m_RecordItf)->GetPosition(m_RecordItf, &milliSec); + returnValue = mapError(xa_result, ETrue); + if (returnValue == KErrNone) + aDur = (TInt64)milliSec; + + TRACE_FUNCTION_EXIT; + return returnValue; +} + +void XARecordSessionImpl::cbMediaRecorder( + XAObjectItf /*caller*/, + const void */*pContext*/, + XAuint32 event, + XAresult result, + XAuint32 /*param*/, + void */*pInterface*/) +{ + TRACE_FUNCTION_ENTRY; + + switch (event) { + case XA_OBJECT_EVENT_RESOURCES_LOST: + m_Parent.cbRecordingStopped(); + break; + case XA_OBJECT_EVENT_RUNTIME_ERROR: { + switch (result) { + case XA_RESULT_RESOURCE_LOST: + m_Parent.cbRecordingStopped(); + break; + default: + break; + }; /* of switch (result) */ + } + default: + break; + } /* of switch (event) */ + + TRACE_FUNCTION_EXIT; +} + +void XARecordSessionImpl::cbRecordItf( + XARecordItf /*caller*/, + void */*pContext*/, + XAuint32 event) +{ + TRACE_FUNCTION_ENTRY; + + switch(event) { + case XA_RECORDEVENT_HEADATLIMIT: + TRACE_LOG(_L("XA_RECORDEVENT_HEADATLIMIT")); + break; + case XA_RECORDEVENT_HEADATMARKER: + TRACE_LOG(_L("XA_RECORDEVENT_HEADATMARKER")); + break; + case XA_RECORDEVENT_HEADATNEWPOS: { + TInt32 returnValue; + XAresult xa_result; + XAmillisecond milliSec; + xa_result = (*m_RecordItf)->GetPosition(m_RecordItf, &milliSec); + returnValue = mapError(xa_result, ETrue); + if (returnValue == KErrNone) + m_Parent.cbDurationChanged((TInt64) milliSec); + } + break; + case XA_RECORDEVENT_HEADMOVING: + TRACE_LOG(_L("XA_RECORDEVENT_HEADMOVING")); + m_Parent.cbRecordingStarted(); + break; + case XA_RECORDEVENT_HEADSTALLED: + TRACE_LOG(_L("XA_RECORDEVENT_HEADSTALLED")); + break; + case XA_RECORDEVENT_BUFFER_FULL: + TRACE_LOG(_L("XA_RECORDEVENT_BUFFER_FULL")); + break; + default: + TRACE_LOG(_L("UNKNOWN RECORDEVENT EVENT")); + break; + } /* of switch(event) */ + + TRACE_FUNCTION_EXIT; +} + +/* For QAudioEndpointSelector begin */ +void XARecordSessionImpl::getAudioInputDeviceNames(RArray<TPtrC> &aArray) +{ + TRACE_FUNCTION_ENTRY; + + for (TInt index = 0; index < m_AudioInputDeviceNames->MdcaCount(); index++) + aArray.Append(m_AudioInputDeviceNames->MdcaPoint(index)); + TRACE_FUNCTION_EXIT; +} + +TInt32 XARecordSessionImpl::defaultAudioInputDevice(TPtrC &endPoint) +{ + TRACE_FUNCTION_ENTRY; + + TInt32 err(KErrGeneral); + if (m_DefaultAudioInputDeviceNames->MdcaCount() >= 0) { + endPoint.Set(m_DefaultAudioInputDeviceNames->MdcaPoint(0)); + err = KErrNone; + } + + TRACE_FUNCTION_EXIT; + return err; +} + +TInt32 XARecordSessionImpl::activeAudioInputDevice(TPtrC &endPoint) +{ + TRACE_FUNCTION_ENTRY; + + TInt32 returnValue(KErrGeneral); + TBool found(EFalse); + TInt index = 0; + for (; index < m_InputDeviceIDs.Count(); index++) { + if (m_InputDeviceIDs[index] == m_InputDeviceId) { + found = ETrue; + break; + } + } + + /* Comparing found with ETrue produces linker error */ + if (found == true) { + endPoint.Set(m_AudioInputDeviceNames->MdcaPoint(index)); + returnValue = KErrNone; + } + + TRACE_FUNCTION_EXIT; + return returnValue; +} + +TBool XARecordSessionImpl::setAudioInputDevice(const TDesC &aDevice) +{ + TRACE_FUNCTION_ENTRY; + + /* validate if we can set input device id */ + TBool found(EFalse); + m_InputDeviceId = 0; + TInt index = 0; + for (; index < m_AudioInputDeviceNames->MdcaCount(); index++) { + if (m_AudioInputDeviceNames->MdcaPoint(index).Compare(aDevice) == 0) { + found = ETrue; + break; + } + } + if (found == true) { + m_InputDeviceId = m_InputDeviceIDs[index]; + } + + TRACE_FUNCTION_EXIT; + return found; +} + +void XARecordSessionImpl::cbAvailableAudioInputsChanged( + XAAudioIODeviceCapabilitiesItf /*caller*/, + void */*pContext*/, + XAuint32 deviceID, + XAint32 /*numInputs*/, + XAboolean isNew) +{ + TRACE_FUNCTION_ENTRY; + + /* If a new device is added into the system, append it to available input list */ + if (isNew == XA_BOOLEAN_TRUE) { + XAAudioInputDescriptor audioInputDescriptor; + m_InputDeviceIDs.Append(deviceID); + + XAresult xa_result = (*m_AudioIODevCapsItf)->QueryAudioInputCapabilities( + m_AudioIODevCapsItf, + deviceID, + &audioInputDescriptor); + + if ((mapError(xa_result, ETrue)) == KErrNone) { + TUint8* inDevNamePtr = audioInputDescriptor.deviceName; + TUint8* tempPtr = audioInputDescriptor.deviceName; + TInt32 inDevNameLength = 0; + while (*tempPtr++) + inDevNameLength++; + TPtrC8 ptr(inDevNamePtr, inDevNameLength); + /* Convert 8 bit to 16 bit */ + TBuf16<KMaxNameLength> name; + name.Copy(ptr); + /* Using TRAP with returnValue results in compiler error */ + TRAP_IGNORE(m_AudioInputDeviceNames->AppendL(name)); + } + } + else { + /* an available device has been removed from the the system, remove it from + * available input list and also default list */ + TBool found(EFalse); + TInt index = 0; + for (; index < m_InputDeviceIDs.Count(); index++) { + if (deviceID == m_InputDeviceIDs[index]) { + found = ETrue; + break; + } + } + if (found == true) { + m_InputDeviceIDs.Remove(index); + m_AudioInputDeviceNames->Delete(index); + } + if (deviceID == m_InputDeviceId) + m_InputDeviceId = 0; + + found = EFalse; + for (index = 0; index < m_DefaultInputDeviceIDs.Count(); index++) { + if (deviceID == m_DefaultInputDeviceIDs[index]) { + found = ETrue; + break; + } + } + if (found == true) { + m_DefaultInputDeviceIDs.Remove(index); + m_DefaultAudioInputDeviceNames->Delete(index); + } + } + m_Parent.cbAvailableAudioInputsChanged(); + + TRACE_FUNCTION_EXIT; +} +/* For QAudioEndpointSelector end */ + +/* For QAudioEncoderControl begin */ +const RArray<TPtrC>& XARecordSessionImpl::getAudioEncoderNames() +{ + TRACE_FUNCTION_ENTRY_EXIT; + return m_EncoderNames; +} + +TInt32 XARecordSessionImpl::getSampleRates( + const TDesC& aEncoder, + RArray<TInt32> &aSampleRates, + TBool &aIsContinuous) +{ + TRACE_FUNCTION_ENTRY; + + aSampleRates.Reset(); + aIsContinuous = EFalse; + + XAuint32 encoderId = 0; + TBool found(EFalse); + for (TInt index = 0; index < m_EncoderIds.Count(); index++) { + if (m_EncoderNames[index].Compare(aEncoder) == 0) { + found = ETrue; + encoderId = m_EncoderIds[index]; + break; + } + } + + TInt32 returnValue(KErrGeneral); + if (found == false) + return returnValue; + + returnValue = getSampleRatesByAudioCodecID(encoderId, aSampleRates); + + TRACE_FUNCTION_EXIT; + return returnValue; +} + +TInt32 XARecordSessionImpl::getBitrates( + const TDesC& aEncoder, + RArray<TUint32> &aBitrates, + TBool& aContinuous) +{ + TRACE_FUNCTION_ENTRY; + + aBitrates.Reset(); + + XAuint32 encoderId = 0; + TBool found(EFalse); + for (TInt index = 0; index < m_EncoderIds.Count(); index++) { + if (m_EncoderNames[index].Compare(aEncoder) == 0) { + found = ETrue; + encoderId = m_EncoderIds[index]; + break; + } + } + + TInt32 returnValue(KErrNotSupported); + XAboolean cont; + if (found == false) + return returnValue; + + returnValue = getBitratesByAudioCodecID(encoderId, aBitrates, cont); + aContinuous = cont; + + TRACE_FUNCTION_EXIT; + return returnValue; +} + +/* For QAudioEncoderControl end */ + +/* For QMediaContainerControl begin */ +const RArray<TPtrC>& XARecordSessionImpl::getContainerNames() +{ + TRACE_FUNCTION_ENTRY_EXIT; + return m_ContainerNames; +} + +const RArray<TPtrC>& XARecordSessionImpl::getContainerDescs() +{ + TRACE_FUNCTION_ENTRY_EXIT; + return m_ContainerDescs; +} + +/* For QMediaContainerControl end */ + +void XARecordSessionImpl::resetEncoderAttributes() +{ + m_ContainerType = 0; + m_AudioEncoderId = 0; + m_ProfileSetting = 0; + m_BitRate = 0; + m_ChannelsOut = 1; + m_SampleRate = 0; + m_RateControl = 0; +} + +void XARecordSessionImpl::setContainerType(const TDesC &aURI) +{ + TRACE_FUNCTION_ENTRY; + + if (aURI.Compare(KCONTAINERWAV()) == 0) + m_ContainerType = XA_CONTAINERTYPE_WAV; + else if (aURI.Compare(KCONTAINERAMR()) == 0) + m_ContainerType = XA_CONTAINERTYPE_AMR; + else if (aURI.Compare(KCONTAINERMP4()) == 0) + m_ContainerType = XA_CONTAINERTYPE_MP4; + + TRACE_FUNCTION_EXIT; +} + +TBool XARecordSessionImpl::setCodec(const TDesC &aCodec) +{ + TRACE_FUNCTION_ENTRY; + + TBool returnValue(EFalse); + if (aCodec.Compare(KAUDIOCODECPCM()) == 0) { + m_AudioEncoderId = XA_AUDIOCODEC_PCM; + m_ProfileSetting = XA_AUDIOPROFILE_PCM; + returnValue = ETrue; + } + else if (aCodec.Compare(KAUDIOCODECAAC()) == 0) { + m_AudioEncoderId = XA_AUDIOCODEC_AAC; + m_ProfileSetting = XA_AUDIOPROFILE_AAC_AAC; + returnValue = ETrue; + } + else if (aCodec.Compare(KAUDIOCODECAMR()) == 0) { + m_AudioEncoderId = XA_AUDIOCODEC_AMR; + m_ProfileSetting = XA_AUDIOPROFILE_AMR; + returnValue = ETrue; + } + + TRACE_FUNCTION_EXIT; + return returnValue; +} + +TUint32 XARecordSessionImpl::getBitRate() +{ + return m_BitRate; +} + +void XARecordSessionImpl::setBitRate(TUint32 aBitRate) +{ + TRACE_FUNCTION_ENTRY; + RArray<TUint32> bitrates; + XAboolean isContinuous; + m_BitRate = 0; + if (getBitratesByAudioCodecID(m_AudioEncoderId, bitrates, isContinuous) == KErrNone) { + bitrates.SortUnsigned(); + TInt loopIndex(0); + while (loopIndex < bitrates.Count() + && aBitRate <= bitrates[loopIndex]) { + m_BitRate = bitrates[loopIndex]; + loopIndex++; + } + bitrates.Close(); + } + TRACE_LOG((_L("BitRate[%d]"), m_BitRate)); + TRACE_FUNCTION_EXIT; +} + +TUint32 XARecordSessionImpl::getChannels() +{ + return m_ChannelsOut; +} + +void XARecordSessionImpl::setChannels(TUint32 aChannels) +{ + TRACE_FUNCTION_ENTRY; + switch (m_AudioEncoderId) { + case XA_AUDIOCODEC_PCM: + case XA_AUDIOCODEC_AAC: + m_ChannelsOut = 1; + if ((aChannels >= 1) && (aChannels <= 2)) + m_ChannelsOut = aChannels; + break; + case XA_AUDIOCODEC_AMR: + m_ChannelsOut = 1; + break; + default: + break; + } + TRACE_LOG((_L("ChannelCount[%d]"), m_ChannelsOut)); + TRACE_FUNCTION_EXIT; +} + +void XARecordSessionImpl::setOptimalChannelCount() +{ + TRACE_FUNCTION_ENTRY; + m_ChannelsOut = 1; + TRACE_FUNCTION_EXIT; +} + +TUint32 XARecordSessionImpl::getSampleRate() +{ + return m_SampleRate; +} + +void XARecordSessionImpl::setSampleRate(TUint32 aSampleRate) +{ + TRACE_FUNCTION_ENTRY; + + m_SampleRate = 0; + + RArray<TInt32> samplerates; + if (getSampleRatesByAudioCodecID(m_AudioEncoderId, samplerates) == KErrNone) { + samplerates.SortUnsigned(); + TInt loopIndex(0); + while (loopIndex < samplerates.Count()) { + m_SampleRate = samplerates[loopIndex]; + if (samplerates[loopIndex] > aSampleRate) + break; + loopIndex++; + } + samplerates.Close(); + } + + /* convert Hz to MilliHz */ + m_SampleRate *= KMilliToHz; + TRACE_LOG((_L("SampleRate[%d]"), m_SampleRate)); + TRACE_FUNCTION_EXIT; +} + +void XARecordSessionImpl::setOptimalSampleRate() +{ + TRACE_FUNCTION_ENTRY; + m_SampleRate = 0; + + if (m_AudioEncoderId == XA_AUDIOCODEC_AAC) { + m_SampleRate = 32000 * KMilliToHz; + } + else if (m_AudioEncoderId == XA_AUDIOCODEC_AMR) { + m_SampleRate = 8000 * KMilliToHz; + } + else { + RArray<TInt32> sampleRates; + TInt res = getSampleRatesByAudioCodecID(m_AudioEncoderId, sampleRates); + if ((res == KErrNone) && (sampleRates.Count() > 0)) { + /* Sort the array and pick the middle range sample rate */ + sampleRates.SortUnsigned(); + m_SampleRate = sampleRates[sampleRates.Count() / 2] * KMilliToHz; + } + sampleRates.Close(); + } + + TRACE_FUNCTION_EXIT; +} + +TInt32 XARecordSessionImpl::setCBRMode() +{ + TRACE_FUNCTION_ENTRY; + + m_RateControl = XA_RATECONTROLMODE_CONSTANTBITRATE; + + TRACE_FUNCTION_EXIT; + return KErrNone; +} + +TInt32 XARecordSessionImpl::setVBRMode() +{ + TRACE_FUNCTION_ENTRY; + + m_RateControl = XA_RATECONTROLMODE_VARIABLEBITRATE; + + TRACE_FUNCTION_EXIT; + return KErrNone; +} + +void XARecordSessionImpl::setVeryLowQuality() +{ + /* Set to very low quality encoder preset */ + RArray<TUint32> bitrates; + XAboolean continuous; + TInt res = getBitratesByAudioCodecID(m_AudioEncoderId, bitrates, continuous); + if ((res == KErrNone) && (bitrates.Count() > 0)) { + /* Sort the array and pick the lowest bit rate */ + bitrates.SortUnsigned(); + m_BitRate = bitrates[0]; + } + bitrates.Close(); +} + +void XARecordSessionImpl::setLowQuality() +{ + /* Set to low quality encoder preset */ + RArray<TUint32> bitrates; + XAboolean continuous; + TInt res = getBitratesByAudioCodecID(m_AudioEncoderId, bitrates, continuous); + if ((res == KErrNone) && (bitrates.Count() > 0)) { + /* Sort the array and pick the low quality bit rate */ + bitrates.SortUnsigned(); + if (continuous == XA_BOOLEAN_FALSE) + m_BitRate = bitrates[bitrates.Count() / 4]; + else + m_BitRate = (bitrates[1] - bitrates[0]) / 4; + } + bitrates.Close(); +} + +void XARecordSessionImpl::setNormalQuality() +{ + /* Set to normal quality encoder preset */ + RArray<TUint32> bitrates; + XAboolean continuous; + TInt res = getBitratesByAudioCodecID(m_AudioEncoderId, bitrates, continuous); + if ((res == KErrNone) && (bitrates.Count() > 0)) { + /* Sort the array and pick the middle range bit rate */ + bitrates.SortUnsigned(); + if (continuous == XA_BOOLEAN_FALSE) + m_BitRate = bitrates[bitrates.Count() / 2]; + else + m_BitRate = (bitrates[1] - bitrates[0]) / 2; + } + bitrates.Close(); +} + +void XARecordSessionImpl::setHighQuality() +{ + /* Set to high quality encoder preset */ + RArray<TUint32> bitrates; + XAboolean continuous; + TInt res = getBitratesByAudioCodecID(m_AudioEncoderId, bitrates, continuous); + if ((res == KErrNone) && (bitrates.Count() > 0)) { + /* Sort the array and pick the high quality bit rate */ + bitrates.SortUnsigned(); + if (continuous == XA_BOOLEAN_FALSE) + m_BitRate = bitrates[bitrates.Count() * 3 / 4]; + else + m_BitRate = (bitrates[1] - bitrates[0]) * 3 / 4; + } + bitrates.Close(); +} + +void XARecordSessionImpl::setVeryHighQuality() +{ + /* Set to very high quality encoder preset */ + RArray<TUint32> bitrates; + XAboolean continuous; + TInt res = getBitratesByAudioCodecID(m_AudioEncoderId, bitrates, continuous); + if ((res == KErrNone) && (bitrates.Count() > 0)) { + /* Sort the array and pick the highest bit rate */ + bitrates.SortUnsigned(); + m_BitRate = bitrates[bitrates.Count() - 1]; + } + bitrates.Close(); +} + +/* Internal function */ +TInt32 XARecordSessionImpl::createMediaRecorderObject() +{ + TRACE_FUNCTION_ENTRY; + + if (!m_EOEngine) + return KErrGeneral; + + TInt32 returnValue(KErrNone); + + TRACE_LOG(_L("XARecordSessionImpl::CreateMediaRecorderObject")); + if (!m_MORecorder && !m_RecordItf) { + + /* Setup the data source */ + m_LocatorMic.locatorType = XA_DATALOCATOR_IODEVICE; + m_LocatorMic.deviceType = XA_IODEVICE_AUDIOINPUT; + m_LocatorMic.deviceID = m_InputDeviceId; + m_LocatorMic.device = NULL; + m_DataSource.pLocator = (void*) &m_LocatorMic; + m_DataSource.pFormat = NULL; + + /* Setup the data sink structure */ + m_Uri.locatorType = XA_DATALOCATOR_URI; + /* append zero terminator to end of URI */ + TPtr8 uriPtr = m_URIName->Des(); + m_Uri.URI = (XAchar*) uriPtr.PtrZ(); + m_Mime.formatType = XA_DATAFORMAT_MIME; + m_Mime.containerType = m_ContainerType; + TPtr8 mimeTypePtr(m_WAVMime->Des()); + m_Mime.mimeType = (XAchar*) mimeTypePtr.Ptr(); + m_DataSink.pLocator = (void*) &m_Uri; + m_DataSink.pFormat = (void*) &m_Mime; + + /* Init arrays required[] and iidArray[] */ + XAboolean required[MAX_NUMBER_INTERFACES]; + XAInterfaceID iidArray[MAX_NUMBER_INTERFACES]; + for (TInt32 i = 0; i < MAX_NUMBER_INTERFACES; i++) { + required[i] = XA_BOOLEAN_FALSE; + iidArray[i] = XA_IID_NULL; + } + XAuint32 noOfInterfaces = 0; + required[noOfInterfaces] = XA_BOOLEAN_FALSE; + iidArray[noOfInterfaces] = XA_IID_RECORD; + noOfInterfaces++; + required[noOfInterfaces] = XA_BOOLEAN_FALSE; + iidArray[noOfInterfaces] = XA_IID_AUDIOENCODER; + noOfInterfaces++; + + XAEngineItf engineItf; + XAresult xa_result = (*m_EOEngine)->GetInterface(m_EOEngine, XA_IID_ENGINE, (void**) &engineItf); + returnValue = mapError(xa_result, ETrue); + RET_ERR_IF_ERR(returnValue); + + TRACE_LOG(_L("XARecordSessionImpl::CreateMediaRecorderObject: Create Media Recorder...")); + + /* Create recorder with NULL for a the image/video source, since this is for audio-only recording */ + xa_result = (*engineItf)->CreateMediaRecorder( + engineItf, + &m_MORecorder, + &m_DataSource, + NULL, + &m_DataSink, + noOfInterfaces, + iidArray, + required); + returnValue = mapError(xa_result, ETrue); + RET_ERR_IF_ERR(returnValue); + + TRACE_LOG(_L("XARecordSessionImpl::CreateMediaRecorderObject: Realize Media Recorder...")); + xa_result = (*m_MORecorder)->Realize(m_MORecorder, XA_BOOLEAN_FALSE); + returnValue = mapError(xa_result, ETrue); + RET_ERR_IF_ERR(returnValue); + + TRACE_LOG(_L("XARecordSessionImpl::CreateMediaRecorderObject: Register Callback on recorder...")); + xa_result = (*m_MORecorder)->RegisterCallback(m_MORecorder, cbXAObjectItf, (void*) this); + returnValue = mapError(xa_result, ETrue); + RET_ERR_IF_ERR(returnValue); + + TRACE_LOG(_L("XARecordSessionImpl::CreateMediaRecorderObject: Getting Record Interface...")); + xa_result = (*m_MORecorder)->GetInterface(m_MORecorder, XA_IID_RECORD, &m_RecordItf); + returnValue = mapError(xa_result, ETrue); + RET_ERR_IF_ERR(returnValue); + + TRACE_LOG(_L("XARecordSessionImpl::CreateMediaRecorderObject: Registering Callback on record Interface...")); + xa_result = (*m_RecordItf)->RegisterCallback(m_RecordItf, cbXARecordItf, (void*) this); + returnValue = mapError(xa_result, ETrue); + RET_ERR_IF_ERR(returnValue); + + TRACE_LOG(_L("XARecordSessionImpl::CreateMediaRecorderObject: SetPositionUpdatePeriod on record Interface...")); + xa_result = (*m_RecordItf)->SetPositionUpdatePeriod(m_RecordItf, (XAmillisecond)KRecordPosUpdatePeriod); + returnValue = mapError(xa_result, ETrue); + RET_ERR_IF_ERR(returnValue); + + TRACE_LOG(_L("XARecordSessionImpl::CreateMediaRecorderObject: SetCallbackEventsMask on record Interface...")); + xa_result = (*m_RecordItf)->SetCallbackEventsMask(m_RecordItf, XA_RECORDEVENT_HEADATNEWPOS | + XA_RECORDEVENT_HEADMOVING | + XA_RECORDEVENT_HEADSTALLED); + returnValue = mapError(xa_result, ETrue); + RET_ERR_IF_ERR(returnValue); + + TRACE_LOG(_L("XARecordSessionImpl::CreateMediaRecorderObject: Getting Audio Encoder Interface...")); + xa_result = (*m_MORecorder)->GetInterface(m_MORecorder, XA_IID_AUDIOENCODER, &m_AudioEncItf); + returnValue = mapError(xa_result, ETrue); + RET_ERR_IF_ERR(returnValue); + } + + TRACE_FUNCTION_EXIT; + return returnValue; +} + +TInt32 XARecordSessionImpl::mapError(XAresult xa_err, TBool debPrn) +{ + TInt32 returnValue(KErrGeneral); + switch (xa_err) { + case XA_RESULT_SUCCESS: + returnValue = KErrNone; + break; + case XA_RESULT_PRECONDITIONS_VIOLATED: + if (debPrn) + TRACE_LOG(_L("XA_RESULT_PRECONDITIONS_VIOLATED")); + break; + case XA_RESULT_PARAMETER_INVALID: + if (debPrn) + TRACE_LOG(_L("XA_RESULT_PARAMETER_INVALID")); + break; + case XA_RESULT_MEMORY_FAILURE: + if (debPrn) + TRACE_LOG(_L("XA_RESULT_MEMORY_FAILURE")); + break; + case XA_RESULT_RESOURCE_ERROR: + if (debPrn) + TRACE_LOG(_L("XA_RESULT_RESOURCE_ERROR")); + break; + case XA_RESULT_RESOURCE_LOST: + if (debPrn) + TRACE_LOG(_L("XA_RESULT_RESOURCE_LOST")); + break; + case XA_RESULT_IO_ERROR: + if (debPrn) + TRACE_LOG(_L("XA_RESULT_IO_ERROR")); + break; + case XA_RESULT_BUFFER_INSUFFICIENT: + if (debPrn) + TRACE_LOG(_L("XA_RESULT_BUFFER_INSUFFICIENT")); + break; + case XA_RESULT_CONTENT_CORRUPTED: + if (debPrn) + TRACE_LOG(_L("XA_RESULT_CONTENT_CORRUPTED")); + break; + case XA_RESULT_CONTENT_UNSUPPORTED: + if (debPrn) + TRACE_LOG(_L("XA_RESULT_CONTENT_UNSUPPORTED")); + break; + case XA_RESULT_CONTENT_NOT_FOUND: + if (debPrn) + TRACE_LOG(_L("XA_RESULT_CONTENT_NOT_FOUND")); + break; + case XA_RESULT_PERMISSION_DENIED: + if (debPrn) + TRACE_LOG(_L("XA_RESULT_PERMISSION_DENIED")); + break; + case XA_RESULT_FEATURE_UNSUPPORTED: + if (debPrn) + TRACE_LOG(_L("XA_RESULT_FEATURE_UNSUPPORTED")); + break; + case XA_RESULT_INTERNAL_ERROR: + if (debPrn) + TRACE_LOG(_L("XA_RESULT_INTERNAL_ERROR")); + break; + case XA_RESULT_UNKNOWN_ERROR: + if (debPrn) + TRACE_LOG(_L("XA_RESULT_UNKNOWN_ERROR")); + break; + case XA_RESULT_OPERATION_ABORTED: + if (debPrn) + TRACE_LOG(_L("XA_RESULT_OPERATION_ABORTED")); + break; + case XA_RESULT_CONTROL_LOST: + if (debPrn) + TRACE_LOG(_L("XA_RESULT_CONTROL_LOST")); + break; + default: + if (debPrn) + TRACE_LOG(_L("Unknown Error!!!")); + break; + } + return returnValue; +} + +TInt32 XARecordSessionImpl::initContainersList() +{ + TRACE_FUNCTION_ENTRY; + + m_ContainerNames.Reset(); + m_ContainerDescs.Reset(); + + m_ContainerNames.Append(KCONTAINERWAV()); + m_ContainerNames.Append(KCONTAINERAMR()); + m_ContainerNames.Append(KCONTAINERMP4()); + + m_ContainerDescs.Append(KCONTAINERWAVDESC()); + m_ContainerDescs.Append(KCONTAINERAMRDESC()); + m_ContainerDescs.Append(KCONTAINERMP4DESC()); + + TRACE_FUNCTION_EXIT; + return KErrNone; +} + +TInt32 XARecordSessionImpl::initAudioEncodersList() +{ + TRACE_FUNCTION_ENTRY; + + m_EncoderIds.Reset(); + m_EncoderNames.Reset(); + + XAuint32 encoderIds[MAX_NUMBER_ENCODERS]; + + for (TInt index = 0; index < MAX_NUMBER_ENCODERS; index++) + encoderIds[index] = 0; + + XAuint32 numEncoders = MAX_NUMBER_ENCODERS; + XAresult xa_result = (*m_AudioEncCapsItf)->GetAudioEncoders( + m_AudioEncCapsItf, + &numEncoders, + encoderIds); + TInt32 returnValue = mapError(xa_result, ETrue); + RET_ERR_IF_ERR(returnValue); + + for (TInt index = 0; index < numEncoders; index++) { + m_EncoderIds.Append(encoderIds[index]); + switch (encoderIds[index]) { + case XA_AUDIOCODEC_PCM: + m_EncoderNames.Append(KAUDIOCODECPCM()); + break; + case XA_AUDIOCODEC_AMR: + m_EncoderNames.Append(KAUDIOCODECAMR()); + break; + case XA_AUDIOCODEC_AAC: + m_EncoderNames.Append(KAUDIOCODECAAC()); + break; + default: + break; + }; + } + + TRACE_FUNCTION_EXIT; + return returnValue; +} + +TInt32 XARecordSessionImpl::initAudioInputDevicesList() +{ + TRACE_FUNCTION_ENTRY; + + m_InputDeviceIDs.Reset(); + + XAuint32 deviceIds[MAX_NUMBER_INPUT_DEVICES]; + for (TInt index = 0; index < MAX_NUMBER_INPUT_DEVICES; index++) + deviceIds[index] = 0; + + XAint32 numInputs = MAX_NUMBER_INPUT_DEVICES; + XAresult xa_result = (*m_AudioIODevCapsItf)->GetAvailableAudioInputs( + m_AudioIODevCapsItf, + &numInputs, + deviceIds); + TInt32 returnValue = mapError(xa_result, ETrue); + RET_ERR_IF_ERR(returnValue); + + XAAudioInputDescriptor audioInputDescriptor; + for (TInt index = 0; index < numInputs; index++) { + xa_result = (*m_AudioIODevCapsItf)->QueryAudioInputCapabilities( + m_AudioIODevCapsItf, + deviceIds[index], + &audioInputDescriptor); + returnValue = mapError(xa_result, ETrue); + if (returnValue != KErrNone) + continue; + + TUint8 * inDevNamePtr = audioInputDescriptor.deviceName; + TUint8 * tempPtr = audioInputDescriptor.deviceName; + TInt32 inDevNameLength = 0; + while (*tempPtr++) + inDevNameLength++; + TPtrC8 ptr(inDevNamePtr, inDevNameLength); + /* Convert 8 bit to 16 bit */ + TBuf16<KMaxNameLength> name; + name.Copy(ptr); + /* Using TRAP with returnValue results in compiler error */ + TRAPD(err2, m_AudioInputDeviceNames->AppendL(name)); + returnValue = err2; + if (returnValue != KErrNone) + continue; + m_InputDeviceIDs.Append(deviceIds[index]); + } + + numInputs = MAX_NUMBER_INPUT_DEVICES; + for (TInt index = 0; index < MAX_NUMBER_INPUT_DEVICES; index++) + deviceIds[index] = 0; + xa_result = (*m_AudioIODevCapsItf)->GetDefaultAudioDevices( + m_AudioIODevCapsItf, + XA_DEFAULTDEVICEID_AUDIOINPUT, + &numInputs, + deviceIds); + returnValue = mapError(xa_result, ETrue); + RET_ERR_IF_ERR(returnValue); + + for (TInt index = 0; index < numInputs; index++) { + xa_result = (*m_AudioIODevCapsItf)->QueryAudioInputCapabilities( + m_AudioIODevCapsItf, + deviceIds[index], + &audioInputDescriptor); + returnValue = mapError(xa_result, ETrue); + if (returnValue != KErrNone) + continue; + TUint8* inDevNamePtr = audioInputDescriptor.deviceName; + TUint8* tempPtr = audioInputDescriptor.deviceName; + TInt32 inDevNameLength = 0; + while (*tempPtr++) + inDevNameLength++; + TPtrC8 ptr(inDevNamePtr, inDevNameLength); + /* Convert 8 bit to 16 bit */ + TBuf16<KMaxNameLength> name; + name.Copy(ptr); + /* Using TRAP with returnValue results in compiler error */ + TRAPD(err2, m_DefaultAudioInputDeviceNames->AppendL(name)); + returnValue = err2; + if (returnValue != KErrNone) + continue; + m_DefaultInputDeviceIDs.Append(deviceIds[index]); + m_InputDeviceId = deviceIds[index]; + } + + TRACE_FUNCTION_EXIT; + return returnValue; +} + +TInt32 XARecordSessionImpl::setEncoderSettingsToMediaRecorder() +{ + TRACE_FUNCTION_EXIT; + + /* Get current settings */ + XAAudioEncoderSettings settings; + XAresult xa_result = (*m_AudioEncItf)->GetEncoderSettings( + m_AudioEncItf, + &settings); + TInt32 returnValue = mapError(xa_result, ETrue); + + settings.encoderId = m_AudioEncoderId; + settings.channelsOut = m_ChannelsOut; + if ((m_SampleRate != 0) && (m_SampleRate != 0xffffffff)) + settings.sampleRate = m_SampleRate; + if ((m_BitRate != 0) && (m_BitRate != 0xffffffff)) + settings.bitRate = m_BitRate; + if (m_RateControl != 0) + settings.rateControl = m_RateControl; + settings.profileSetting = m_ProfileSetting; + xa_result = (*m_AudioEncItf)->SetEncoderSettings( + m_AudioEncItf, + &settings); + returnValue = mapError(xa_result, ETrue); + + TRACE_FUNCTION_EXIT; + return returnValue; +} + +TInt32 XARecordSessionImpl::getBitratesByAudioCodecID( + XAuint32 encoderId, + RArray<TUint32> &aBitrates, + XAboolean& aContinuous) +{ + TRACE_FUNCTION_ENTRY; + + if (!m_AudioEncCapsItf) + return KErrGeneral; + + XAuint32 numCaps = 0; + XAAudioCodecDescriptor codecDesc; + XAresult xa_result = (*m_AudioEncCapsItf)->GetAudioEncoderCapabilities( + m_AudioEncCapsItf, + encoderId, + &numCaps, + &codecDesc); + TInt32 returnValue = mapError(xa_result, ETrue); + RET_ERR_IF_ERR(returnValue); + aContinuous = codecDesc.isBitrateRangeContinuous; + /* TODO What do we do if we have more than one caps?? */ + if (codecDesc.isBitrateRangeContinuous == XA_BOOLEAN_TRUE) { + aBitrates.Append(codecDesc.minBitRate); + aBitrates.Append(codecDesc.maxBitRate); + } + else { + XAuint32 numBrSupported = codecDesc.numBitratesSupported; + XAuint32 * pBitratesSupported(NULL); + pBitratesSupported = codecDesc.pBitratesSupported; + TInt32 index = 0; + for (index = 0; index < numBrSupported; index++) + aBitrates.Append(*(pBitratesSupported + index)); + } + + TRACE_FUNCTION_ENTRY; + return returnValue; +} + +TInt32 XARecordSessionImpl::getSampleRatesByAudioCodecID(XAuint32 encoderId, + RArray<TInt32> &aSampleRates) +{ + TRACE_FUNCTION_ENTRY; + + if (!m_AudioEncCapsItf) + return KErrGeneral; + + XAuint32 numCaps = 0; + XAAudioCodecDescriptor codecDesc; + XAresult xa_result = (*m_AudioEncCapsItf)->GetAudioEncoderCapabilities( + m_AudioEncCapsItf, + encoderId, + &numCaps, + &codecDesc); + TInt returnValue = mapError(xa_result, ETrue); + RET_ERR_IF_ERR(returnValue); + + /* TODO What do we do if we have more than one caps?? */ + if (codecDesc.isFreqRangeContinuous == XA_BOOLEAN_TRUE) { + aSampleRates.Append(codecDesc.minSampleRate / KMilliToHz); + aSampleRates.Append(codecDesc.maxSampleRate / KMilliToHz); + } + else { + XAuint32 numSRSupported = codecDesc.numSampleRatesSupported; + XAmilliHertz *pSampleRatesSupported(NULL); + pSampleRatesSupported = codecDesc.pSampleRatesSupported; + for (TInt index = 0; index < numSRSupported; index++) + aSampleRates.Append((*(pSampleRatesSupported + index)) / KMilliToHz); + } + + TRACE_FUNCTION_ENTRY; + return returnValue; +} + +/* Local function implementation */ +void cbXAObjectItf( + XAObjectItf caller, + const void *pContext, + XAuint32 event, + XAresult result, + XAuint32 param, + void *pInterface) +{ + if (pContext) { + ((XARecordSessionImpl*)pContext)->cbMediaRecorder( + caller, + pContext, + event, + result, + param, + pInterface); + } +} + +void cbXARecordItf( + XARecordItf caller, + void *pContext, + XAuint32 event) +{ + if (pContext) { + ((XARecordSessionImpl*)pContext)->cbRecordItf( + caller, + pContext, + event); + } +} + +void cbXAAvailableAudioInputsChanged( + XAAudioIODeviceCapabilitiesItf caller, + void * pContext, + XAuint32 deviceID, + XAint32 numInputs, + XAboolean isNew) +{ + if (pContext) { + ((XARecordSessionImpl*)pContext)->cbAvailableAudioInputsChanged( + caller, + pContext, + deviceID, + numInputs, + isNew); + } +} diff --git a/src/plugins/symbian/openmaxal/mediarecorder/xarecordsessionimpl.h b/src/plugins/symbian/openmaxal/mediarecorder/xarecordsessionimpl.h new file mode 100644 index 000000000..81e4ac763 --- /dev/null +++ b/src/plugins/symbian/openmaxal/mediarecorder/xarecordsessionimpl.h @@ -0,0 +1,179 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef XARECORDSESSIONIMPL_H +#define XARECORDSESSIONIMPL_H + +#include <OpenMAXAL.h> +#include <badesca.h> + + +class XARecordObserver; +class XARecordSessionImpl +{ +public: + XARecordSessionImpl(XARecordObserver &parent); + ~XARecordSessionImpl(); + TInt32 postConstruct(); + + /* For QMediaRecorderControl begin */ + TInt32 setURI(const TDesC &aURI); + TInt32 record(); + TInt32 pause(); + TInt32 stop(); + TInt32 duration(TInt64 &aDur); + /* For QMediaRecorderControl end */ + + void cbMediaRecorder(XAObjectItf caller, + const void *pContext, + XAuint32 event, + XAresult result, + XAuint32 param, + void *pInterface); + void cbRecordItf(XARecordItf caller, + void *pContext, + XAuint32 event); + + /* For QAudioEndpointSelector begin */ + void getAudioInputDeviceNames(RArray<TPtrC> &aArray); + TInt32 defaultAudioInputDevice(TPtrC &endPoint); + TInt32 activeAudioInputDevice(TPtrC &endPoint); + TBool setAudioInputDevice(const TDesC &aDevice); + void cbAvailableAudioInputsChanged(XAAudioIODeviceCapabilitiesItf caller, + void *pContext, + XAuint32 deviceID, + XAint32 numInputs, + XAboolean isNew); + /* For QAudioEndpointSelector end */ + + /* For QAudioEncoderControl begin */ + const RArray<TPtrC>& getAudioEncoderNames(); + TInt32 getSampleRates(const TDesC &aEncoder, + RArray<TInt32> &aSampleRates, + TBool &aIsContinuous); + TInt32 getBitrates(const TDesC &aEncoder, + RArray<TUint32> &aBitrates, + TBool& aContinuous); + /* For QAudioEncoderControl end */ + + /* For QMediaContainerControl begin */ + const RArray<TPtrC>& getContainerNames(); + const RArray<TPtrC>& getContainerDescs(); + /* For QMediaContainerControl end */ + + void resetEncoderAttributes(); + void setContainerType(const TDesC &aURI); + TBool setCodec(const TDesC &aURI); + TUint32 getBitRate(); + void setBitRate(TUint32 aBitRate); + TUint32 getChannels(); + void setChannels(TUint32 aChannels); + void setOptimalChannelCount(); + TUint32 getSampleRate(); + void setSampleRate(TUint32 aSampleRate); + void setOptimalSampleRate(); + TInt32 setCBRMode(); + TInt32 setVBRMode(); + void setVeryLowQuality(); + void setLowQuality(); + void setNormalQuality(); + void setHighQuality(); + void setVeryHighQuality(); + +private: + TInt32 createMediaRecorderObject(); + TInt32 mapError(XAresult xa_err, + TBool debPrn); + TInt32 initContainersList(); + TInt32 initAudioEncodersList(); + TInt32 initAudioInputDevicesList(); + TInt32 setEncoderSettingsToMediaRecorder(); + TInt32 getBitratesByAudioCodecID(XAuint32 encoderId, + RArray<TUint32> &aBitrates, + XAboolean& aContinuous); + TInt32 getSampleRatesByAudioCodecID(XAuint32 encoderId, + RArray<TInt32> &aSampleRates); + + +private: + XARecordObserver &m_Parent; + XAObjectItf m_EOEngine; + XAObjectItf m_MORecorder; + XARecordItf m_RecordItf; + XAAudioEncoderItf m_AudioEncItf; + /* Audio Source */ + XADataSource m_DataSource; + XADataLocator_IODevice m_LocatorMic; + XADataFormat_MIME m_Mime; + XADataLocator_URI m_Uri; + /*Audio Sink*/ + XADataSink m_DataSink; + HBufC8 *m_WAVMime; + + /* Set by client*/ + HBufC8 *m_URIName; + XAuint32 m_AudioEncoderId; + XAuint32 m_InputDeviceId; + XAuint32 m_ContainerType; + XAuint32 m_BitRate; + XAuint32 m_RateControl; + XAuint32 m_ProfileSetting; + XAuint32 m_ChannelsOut; + XAuint32 m_SampleRate; + + /* For QAudioEndpointSelector begin */ + XAAudioIODeviceCapabilitiesItf m_AudioIODevCapsItf; + RArray<TUint32> m_InputDeviceIDs; + CDesC16ArrayFlat *m_AudioInputDeviceNames; + RArray<TUint32> m_DefaultInputDeviceIDs; + CDesC16ArrayFlat *m_DefaultAudioInputDeviceNames; + /* For QAudioEndpointSelector end */ + + /* For QAudioEncoderControl begin */ + XAAudioEncoderCapabilitiesItf m_AudioEncCapsItf; + RArray<XAuint32> m_EncoderIds; + RArray<TPtrC> m_EncoderNames; + RArray<TPtrC> m_ContainerNames; + RArray<TPtrC> m_ContainerDescs; + /* For QAudioEncoderControl begin */ +}; + +#endif /* XARECORDSESSIONIMPL_H */ diff --git a/src/plugins/symbian/openmaxal/openmaxal.pro b/src/plugins/symbian/openmaxal/openmaxal.pro new file mode 100644 index 000000000..0565536a4 --- /dev/null +++ b/src/plugins/symbian/openmaxal/openmaxal.pro @@ -0,0 +1,58 @@ +TEMPLATE = lib + +CONFIG += plugin +TARGET = $$qtLibraryTarget(qtmultimediakit_openmaxalengine) +PLUGIN_TYPE = mediaservice +include (../../../../common.pri) +qtAddLibrary(QtMultimediaKit) + +#includes here so that all defines are added here also +include(mediaplayer/mediaplayer.pri) +include(mediarecorder/mediarecorder.pri) +include(radiotuner/radiotuner.pri) + +DEPENDPATH += . + +HEADERS += qxamediaserviceproviderplugin.h \ + qxacommon.h \ + xacommon.h + +SOURCES += qxamediaserviceproviderplugin.cpp + +# Input parameters for the generated bld.inf file +# ----------------------------------------------- +SYMBIAN_PLATFORMS = DEFAULT + +# Input parameters for the generated mmp file +# ------------------------------------------- +load(data_caging_paths) +TARGET.UID3 = 0x10207CA1 +TARGET.CAPABILITY = ALL -TCB +TARGET.EPOCALLOWDLLDATA = 1 +MMP_RULES += EXPORTUNFROZEN + +# Macros controlling debug traces +#DEFINES += PROFILE_TIME +#DEFINES += PROFILE_RAM_USAGE +#DEFINES += PROFILE_HEAP_USAGE +#DEFINES += PLUGIN_QT_TRACE_ENABLED +#DEFINES += PLUGIN_QT_SIGNAL_EMIT_TRACE_ENABLED +#DEFINES += PLUGIN_SYMBIAN_TRACE_ENABLED + +INCLUDEPATH += $$MW_LAYER_SYSTEMINCLUDE +INCLUDEPATH += /epoc32/include/platform/mw/khronos + + +# Input parameters for qmake to make the dll a qt plugin +pluginDep.sources = $${TARGET}.dll +pluginDep.path = $${QT_PLUGINS_BASE_DIR}/$${PLUGIN_TYPE} +DEPLOYMENT += pluginDep + +LIBS += \ + -lQtMultimediaKit \ + -lopenmaxal + +# check for PROFILE_RAM_USAGE +contains(DEFINES, PROFILE_RAM_USAGE) { + LIBS += -lhal +} diff --git a/src/plugins/symbian/openmaxal/qxacommon.h b/src/plugins/symbian/openmaxal/qxacommon.h new file mode 100644 index 000000000..f19a75d1c --- /dev/null +++ b/src/plugins/symbian/openmaxal/qxacommon.h @@ -0,0 +1,203 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXACOMMON_H +#define QXACOMMON_H + +#if defined(PLUGIN_QT_TRACE_ENABLED) \ + || defined(PLUGIN_QT_SIGNAL_EMIT_TRACE_ENABLED) \ + || defined(PROFILE_TIME) \ + || defined(PROFILE_RAM_USAGE) \ + || defined(PROFILE_HEAP_USAGE) +# include <QDebug> +#endif /* PLUGIN_QT_TRACE_ENABLED */ + +#ifdef PROFILE_RAM_USAGE +# include <hal.h> +#endif + + +#ifdef PLUGIN_QT_TRACE_ENABLED +# define QT_TRACE_FUNCTION_ENTRY qDebug() << __PRETTY_FUNCTION__ << ">" +# define QT_TRACE_FUNCTION_EXIT qDebug() << __PRETTY_FUNCTION__ << "<" +# define QT_TRACE_FUNCTION_ENTRY_EXIT qDebug() << __PRETTY_FUNCTION__ << "><" +# define QT_TRACE1(v1) qDebug() << v1 +# define QT_TRACE2(v1, v2) qDebug() << v1 << v2 +#else +# define QT_TRACE_FUNCTION_ENTRY +# define QT_TRACE_FUNCTION_EXIT +# define QT_TRACE_FUNCTION_ENTRY_EXIT +# define QT_TRACE1(v1) +# define QT_TRACE2(v1, v2) +#endif /*PLUGIN_QT_TRACE_ENABLED*/ + +#ifdef PLUGIN_QT_SIGNAL_EMIT_TRACE_ENABLED +# define SIGNAL_EMIT_TRACE1(v1) qDebug() << __PRETTY_FUNCTION__ << v1 +#else +# define SIGNAL_EMIT_TRACE1(v1) +#endif /*PLUGIN_QT_SIGNAL_EMIT_TRACE_ENABLED*/ + +#ifdef PROFILE_TIME_ELAPSED +# define TAG_TIME_PROFILING_BEGIN \ + TTime beginProfilingTime; \ + beginProfilingTime.HomeTime() + +# define TAG_TIME_PROFILING_END \ + TTime endProfilingTime; \ + endProfilingTime.HomeTime(); \ + TTimeIntervalMicroSeconds diffInMicroSecs = endProfilingTime.MicroSecondsFrom(beginProfilingTime) + +# define QT_PRINT_TO_CONSOLE_TIME_DIFF \ + qDebug() << "VPROFILEDAT: " << __PRETTY_FUNCTION__ << ": Time taken " << diffInMicroSecs.Int64() << " microseconds" +#else /* Empty macros */ +# define TAG_TIME_PROFILING_BEGIN +# define TAG_TIME_PROFILING_END +# define QT_PRINT_TO_CONSOLE_TIME_DIFF +#endif /*PROFILE_TIME_ELAPSED*/ + +#ifdef PROFILE_RAM_USAGE +# define TAG_RAM_PROFILING_BEGIN \ + TInt beginProfilingRAM; \ + TInt err1 = HAL::Get(HALData::EMemoryRAMFree, beginProfilingRAM) + +# define TAG_RAM_PROFILING_END \ + TInt endProfilingRAM; \ + TInt err2 = HAL::Get(HALData::EMemoryRAMFree, endProfilingRAM) + +# define QT_PRINT_TO_CONSOLE_RAM_DIFF \ + if ((err1 == KErrNone) && (err2 == KErrNone)) \ + { \ + TInt diffRAM = (beginProfilingRAM - endProfilingRAM); \ + if ( diffRAM > 0 ) \ + { \ + qDebug() << "VPROFILEDAT: " << __PRETTY_FUNCTION__ << ": " << diffRAM << " bytes of RAM used"; \ + } \ + else \ + { \ + qDebug() << "VPROFILEDAT: " << __PRETTY_FUNCTION__ << ": " << -(diffRAM) << " bytes of RAM freed"; \ + } \ + } \ + else \ + { \ + qDebug() << "VPROFILEDAT: " << __PRETTY_FUNCTION__ << "Error1[" << err1 << "] Error2[" << err2; \ + } + +#else /* Empty macros */ +# define TAG_RAM_PROFILING_BEGIN +# define TAG_RAM_PROFILING_END +# define QT_PRINT_TO_CONSOLE_RAM_DIFF +#endif /*PROFILE_RAM_USAGE*/ + +#ifdef PROFILE_HEAP_USAGE +# define TAG_DEFAULT_HEAP_PROFILING_BEGIN \ + TInt beginProfilingHEAPBiggestBlock; \ + TInt beginProfilingHEAP = User::Available(beginProfilingHEAPBiggestBlock) \ + +# define TAG_DEFAULT_HEAP_PROFILING_END \ + TInt endProfilingHEAPBiggestBlock; \ + TInt endProfilingHEAP = User::Available(endProfilingHEAPBiggestBlock) \ + +# define QT_PRINT_TO_CONSOLE_HEAP_DIFF \ + TInt diffHEAP = beginProfilingHEAP - endProfilingHEAP; \ + if ( diffHEAP > 0 ) \ + { \ + qDebug() << "VPROFILEDAT: " << __PRETTY_FUNCTION__ << ": " << diffHEAP << " bytes in default HEAP used"; \ + } \ + else \ + { \ + qDebug() << "VPROFILEDAT: " << __PRETTY_FUNCTION__ << ": " << -(diffHEAP) << " bytes in default HEAP freed"; \ + } +#else /* Empty macros */ +# define TAG_DEFAULT_HEAP_PROFILING_BEGIN +# define TAG_DEFAULT_HEAP_PROFILING_END +# define QT_PRINT_TO_CONSOLE_HEAP_DIFF +#endif /*PROFILE_HEAP_USAGE*/ + +/* This macro checks p pointer for null. If it is, returns value 's' from + * function immediately. + */ +#define RET_s_IF_p_IS_NULL(p, s) \ + if (p == NULL) { \ + return s; \ + } + +/* This macro checks p pointer for null. If it is, returns from function + * immediately. + */ +#define RET_IF_p_IS_NULL(p) \ + if (p == NULL) { \ + return; \ + } + +/* This macro checks p pointer for null. If it is, emits an error signal + * error(QMediaPlayer::ResourceError, tr("Resource Error")); + * and returns value 's' from function immediately. + */ +#define RET_s_IF_p_IS_NULL_EMIT_PLAYER_RESOURCE_ERROR(p, s) \ + if (p == NULL) { \ + emit error(QMediaPlayer::ResourceError, tr("Resource Error")); \ + SIGNAL_EMIT_TRACE1("emit error(QMediaPlayer::ResourceError, tr(\"Resource Error\"))"); \ + return s; \ + } + +/* This macro checks p pointer for null. If it is, emits an error signal + * error(QMediaPlayer::ResourceError, tr("Resource Error")); + * and returns from function immediately. + */ +#define RET_IF_p_IS_NULL_EMIT_PLAYER_RESOURCE_ERROR(p) \ + if (p == NULL) { \ + emit error(QMediaPlayer::ResourceError, tr("Resource Error")); \ + SIGNAL_EMIT_TRACE1("emit error(QMediaPlayer::ResourceError, tr(\"Resource Error\"))"); \ + return; \ + } + +/* This macro checks p pointer for null. If it is, emits an error signal + * error(QMediaPlayer::ResourceError, tr("Resource Error")); + * and returns from function immediately. + */ +#define RET_IF_ERROR(p) \ + if (p != KErrNone) { \ + emit error(QMediaPlayer::ResourceError, tr("Resource Error")); \ + SIGNAL_EMIT_TRACE1("emit error(QMediaPlayer::ResourceError, tr(\"Resource Error\"))"); \ + return; \ + } + +#endif /* QXACOMMON_H */ diff --git a/src/plugins/symbian/openmaxal/qxamediaserviceproviderplugin.cpp b/src/plugins/symbian/openmaxal/qxamediaserviceproviderplugin.cpp new file mode 100644 index 000000000..bfbb4333a --- /dev/null +++ b/src/plugins/symbian/openmaxal/qxamediaserviceproviderplugin.cpp @@ -0,0 +1,87 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QString> +#include "qxamediaserviceproviderplugin.h" +#include "qxaplaymediaservice.h" +#include "qxarecordmediaservice.h" +#include "qxaradiomediaservice.h" +#include "qxacommon.h" + +QStringList QXAMediaServiceProviderPlugin::keys() const +{ + return QStringList() + << QLatin1String(Q_MEDIASERVICE_MEDIAPLAYER) + << QLatin1String(Q_MEDIASERVICE_AUDIOSOURCE) + << QLatin1String(Q_MEDIASERVICE_RADIO); +} + +QMediaService* QXAMediaServiceProviderPlugin::create(QString const& key) +{ + QT_TRACE_FUNCTION_ENTRY; + QMediaService* service = NULL; + if (key == QLatin1String(Q_MEDIASERVICE_MEDIAPLAYER) ) { + service = new QXAPlayMediaService; + QT_TRACE1("Created QXAPlayMediaService"); + } + else if (key == QLatin1String(Q_MEDIASERVICE_AUDIOSOURCE)) { + service = new QXARecodMediaService; + QT_TRACE1("Created QXARecodMediaService"); + } + else if (key == QLatin1String(Q_MEDIASERVICE_RADIO) ) { + service = new QXARadioMediaService; + QT_TRACE1("Created QXARadioMediaService"); + } + else { + QT_TRACE2("unsupported key:", key); + } + QT_TRACE_FUNCTION_EXIT; + return service; +} + +void QXAMediaServiceProviderPlugin::release(QMediaService *service) +{ + QT_TRACE_FUNCTION_ENTRY; + delete service; + QT_TRACE_FUNCTION_EXIT; +} + +Q_EXPORT_PLUGIN2(qtmultimediakit_openmaxalengine, QXAMediaServiceProviderPlugin); diff --git a/src/plugins/symbian/openmaxal/qxamediaserviceproviderplugin.h b/src/plugins/symbian/openmaxal/qxamediaserviceproviderplugin.h new file mode 100644 index 000000000..6d3530349 --- /dev/null +++ b/src/plugins/symbian/openmaxal/qxamediaserviceproviderplugin.h @@ -0,0 +1,60 @@ +/**************************************************************************** +** +** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXAMEDIASERVICEPROVIDERPLUGIN_H +#define QXAMEDIASERVICEPROVIDERPLUGIN_H + +#include <QtCore/qobject.h> +#include <qmediaserviceprovider.h> +#include <qmediaserviceproviderplugin.h> + +QT_USE_NAMESPACE + +class QXAMediaServiceProviderPlugin : public QMediaServiceProviderPlugin +{ + Q_OBJECT +public: + QStringList keys() const; + QMediaService* create(QString const& key); + void release(QMediaService *service); +}; + +#endif /* QXAMEDIASERVICEPROVIDERPLUGIN_H */ diff --git a/src/plugins/symbian/openmaxal/radiotuner/qxaradiocontrol.cpp b/src/plugins/symbian/openmaxal/radiotuner/qxaradiocontrol.cpp new file mode 100644 index 000000000..9666b0410 --- /dev/null +++ b/src/plugins/symbian/openmaxal/radiotuner/qxaradiocontrol.cpp @@ -0,0 +1,202 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "qxaradiocontrol.h" +#include "qxaradiosession.h" +#include "xaradiosessionimpl.h" + +QXARadioControl::QXARadioControl(QXARadioSession *session, QObject *parent) +:QRadioTunerControl(parent), m_session(session) +{ + + connect(m_session, SIGNAL(stateChanged(QRadioTuner::State)), this, SIGNAL(stateChanged(QRadioTuner::State))); + + connect(m_session, SIGNAL(bandChanged(QRadioTuner::Band)), this, SIGNAL(bandChanged(QRadioTuner::Band))); + + connect(m_session, SIGNAL(frequencyChanged(int)), this, SIGNAL(frequencyChanged(int))); + + connect(m_session, SIGNAL(stereoStatusChanged(bool)), this, SIGNAL(stereoStatusChanged(bool))); + + connect(m_session, SIGNAL(searchingChanged(bool)), this, SIGNAL(searchingChanged(bool))); + + connect(m_session, SIGNAL(signalStrengthChanged(int)), this, SIGNAL(signalStrengthChanged(int))); + + connect(m_session, SIGNAL(volumeChanged(int)), this, SIGNAL(volumeChanged(int))); + + connect(m_session, SIGNAL(mutedChanged(bool)), this, SIGNAL(mutedChanged(bool))); + +// connect(m_session, SIGNAL(error(int,QString)), this,SIGNAL(error(int,QString))); +} + +QXARadioControl::~QXARadioControl() +{ + +} + +QtMultimediaKit::AvailabilityError QXARadioControl::availabilityError() const +{ + return m_session->availabilityError(); +} + +bool QXARadioControl::isAvailable() const +{ + return m_session->isAvailable(); +} + +QRadioTuner::State QXARadioControl::state() const +{ + return m_session->state(); +} + +QRadioTuner::Band QXARadioControl::band() const +{ + return m_session->band(); +} + +void QXARadioControl::setBand(QRadioTuner::Band band) +{ + m_session->setBand(band); +} + +bool QXARadioControl::isBandSupported(QRadioTuner::Band band) const +{ + return m_session->isBandSupported(band); +} + +int QXARadioControl::frequency() const +{ + return m_session->frequency(); +} + +int QXARadioControl::frequencyStep(QRadioTuner::Band band) const +{ + return m_session->frequencyStep(band); +} + +QPair<int,int> QXARadioControl::frequencyRange(QRadioTuner::Band band) const +{ + return m_session->frequencyRange(band); +} + +void QXARadioControl::setFrequency(int freq) +{ + m_session->setFrequency(freq); +} + +bool QXARadioControl::isStereo() const +{ + return m_session->isStereo(); +} + +QRadioTuner::StereoMode QXARadioControl::stereoMode() const +{ + return m_session->stereoMode(); +} + +void QXARadioControl::setStereoMode(QRadioTuner::StereoMode stereoMode) +{ + m_session->setStereoMode(stereoMode); +} + +int QXARadioControl::signalStrength() const +{ + return m_session->signalStrength(); +} + +int QXARadioControl::volume() const +{ + return m_session->volume(); +} + +void QXARadioControl::setVolume(int volume) +{ + m_session->setVolume(volume); +} + +bool QXARadioControl::isMuted() const +{ + return m_session->isMuted(); +} + +void QXARadioControl::setMuted(bool muted) +{ + m_session->setMuted(muted); +} + +bool QXARadioControl::isSearching() const +{ + return m_session->isSearching(); +} + +void QXARadioControl::searchForward() +{ + m_session->searchForward(); +} + +void QXARadioControl::searchBackward() +{ + m_session->searchBackward(); +} + +void QXARadioControl::cancelSearch() +{ + m_session->cancelSearch(); +} + +void QXARadioControl::start() +{ + m_session->start(); +} + +void QXARadioControl::stop() +{ + m_session->stop(); +} + +QRadioTuner::Error QXARadioControl::error() const +{ + return m_session->error(); +} + +QString QXARadioControl::errorString() const +{ + return m_session->errorString(); +} diff --git a/src/plugins/symbian/openmaxal/radiotuner/qxaradiocontrol.h b/src/plugins/symbian/openmaxal/radiotuner/qxaradiocontrol.h new file mode 100644 index 000000000..47d4f827d --- /dev/null +++ b/src/plugins/symbian/openmaxal/radiotuner/qxaradiocontrol.h @@ -0,0 +1,95 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXARADIOCONTROL_H +#define QXARADIOCONTROL_H + +#include <QObject> +#include <QRadioTunerControl> + +QT_USE_NAMESPACE + +class QXARadioSession; + +class QXARadioControl : public QRadioTunerControl +{ + Q_OBJECT + +public: + QXARadioControl(QXARadioSession *session, QObject *parent = 0); + virtual ~QXARadioControl(); + QRadioTuner::State state() const; + + QRadioTuner::Band band() const; + void setBand(QRadioTuner::Band band); + bool isBandSupported(QRadioTuner::Band band) const; + int frequency() const; + int frequencyStep(QRadioTuner::Band band) const; + QPair<int,int> frequencyRange(QRadioTuner::Band band) const; + void setFrequency(int freq); + bool isStereo() const; + QRadioTuner::StereoMode stereoMode() const; + void setStereoMode(QRadioTuner::StereoMode stereoMode); + int signalStrength() const; + int volume() const; + void setVolume(int volume); + bool isMuted() const; + void setMuted(bool muted); + bool isSearching() const; + void searchForward(); + void searchBackward(); + void cancelSearch(); + bool isValid() const; + bool isAvailable() const; + QtMultimediaKit::AvailabilityError availabilityError() const; + void start(); + void stop(); + QRadioTuner::Error error() const; + QString errorString() const; + +private: + QXARadioSession *m_session; + +protected: + QXARadioControl(QObject* parent = 0); +}; + +#endif /* QXARADIOCONTROL_H */ diff --git a/src/plugins/symbian/openmaxal/radiotuner/qxaradiomediaservice.cpp b/src/plugins/symbian/openmaxal/radiotuner/qxaradiomediaservice.cpp new file mode 100644 index 000000000..f399ef8c5 --- /dev/null +++ b/src/plugins/symbian/openmaxal/radiotuner/qxaradiomediaservice.cpp @@ -0,0 +1,72 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <QString> + +#include "qxaradiomediaservice.h" +#include "qxaradiosession.h" +#include "qxaradiocontrol.h" +#include <qradiotunercontrol.h> + +QXARadioMediaService::QXARadioMediaService(QObject *parent) + : QMediaService(parent) +{ + m_session = new QXARadioSession(this); + m_control = new QXARadioControl(m_session, this); +} + +QXARadioMediaService::~QXARadioMediaService() +{ +} + +QMediaControl* QXARadioMediaService::requestControl(const char *name) +{ + + if (qstrcmp(name, QRadioTunerControl_iid) == 0) { + return m_control; + } + return 0; +} + +void QXARadioMediaService::releaseControl(QMediaControl *control) +{ + Q_UNUSED(control) +} diff --git a/src/plugins/symbian/openmaxal/radiotuner/qxaradiomediaservice.h b/src/plugins/symbian/openmaxal/radiotuner/qxaradiomediaservice.h new file mode 100644 index 000000000..7ac014f8f --- /dev/null +++ b/src/plugins/symbian/openmaxal/radiotuner/qxaradiomediaservice.h @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXARADIOMEDIASERVICE_H +#define QXARADIOMEDIASERVICE_H + +#include <QtCore/qobject.h> +#include <qmediaservice.h> + +QT_USE_NAMESPACE + +class QXARadioSession; +class QXARadioControl; + +class QXARadioMediaService : public QMediaService +{ + Q_OBJECT +public: + QXARadioMediaService(QObject *parent = 0); + ~QXARadioMediaService(); + QMediaControl *requestControl(const char *name); + void releaseControl( QMediaControl *control); +private: + QXARadioSession *m_session; + QXARadioControl *m_control; +}; + +#endif /*QXARADIOMEDIASERVICE_H*/ diff --git a/src/plugins/symbian/openmaxal/radiotuner/qxaradiosession.cpp b/src/plugins/symbian/openmaxal/radiotuner/qxaradiosession.cpp new file mode 100644 index 000000000..6822813c4 --- /dev/null +++ b/src/plugins/symbian/openmaxal/radiotuner/qxaradiosession.cpp @@ -0,0 +1,323 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include <qradiotuner.h> +#include "qxaradiosession.h" +#include "xaradiosessionimpl.h" +#include "qxacommon.h" + +QXARadioSession::QXARadioSession(QObject *parent) +:QObject(parent) +{ + QT_TRACE_FUNCTION_ENTRY; + m_impl = new XARadioSessionImpl(*this); + if (!m_impl) { + QT_TRACE1("RadioSession::RadioSession(): ERROR creating RadioSessionImpl..."); + return; + } + if (m_impl->PostConstruct() != QRadioTuner::NoError) { + QT_TRACE1("RadioSession::RadioSession(): ERROR from RadioSessionImpl::PostContstruct..."); + delete m_impl; + m_impl = NULL; + } + QT_TRACE_FUNCTION_EXIT; +} + +QXARadioSession::~QXARadioSession() +{ + delete m_impl; +} + +QRadioTuner::State QXARadioSession::state() const +{ + QRadioTuner::State state = QRadioTuner::StoppedState; + if (m_impl) + state = m_impl->State(); + return state; + } +QtMultimediaKit::AvailabilityError QXARadioSession::availabilityError() const +{ + QtMultimediaKit::AvailabilityError error = QtMultimediaKit::NoError; + if (m_impl) + error = m_impl->AvailabilityError(); + return error; +} + +QRadioTuner::Band QXARadioSession::band() const +{ + QRadioTuner::Band band = QRadioTuner::FM; + if (m_impl) + band = m_impl->Band(); + return band; +} + +void QXARadioSession::setBand(QRadioTuner::Band band) +{ + if (m_impl) + m_impl->SetBand(band); +} + +bool QXARadioSession::isBandSupported(QRadioTuner::Band band) const +{ + if (m_impl) + return m_impl->IsBandSupported(band); + return false; +} + +bool QXARadioSession::isAvailable() const +{ + if (m_impl) + return m_impl->IsAvailable(); + return false; +} + +int QXARadioSession::frequency() const +{ + TInt frequency = 0; + if (m_impl) + frequency = m_impl->GetFrequency(); + return (int)frequency; +} + +int QXARadioSession::frequencyStep(QRadioTuner::Band band) const +{ + TInt freqStep = 0; + if (m_impl) + freqStep = m_impl->FrequencyStep(band); + return (int)freqStep; +} + +QPair<int, int> QXARadioSession::frequencyRange(QRadioTuner::Band /*band*/) const +{ + QPair<int, int> freqRange; + freqRange.first = 0; + freqRange.second =0; + + if (m_impl) { + TInt freqRangeType = m_impl->GetFrequencyRange(); + m_impl->GetFrequencyRangeProperties(freqRangeType, freqRange.first, freqRange.second); + } + + return freqRange; +} + +void QXARadioSession::setFrequency(int frequency) +{ + if (m_impl) + m_impl->SetFrequency(frequency); +} + +bool QXARadioSession::isStereo() const +{ + bool isStereo = false; + if (m_impl) + isStereo = m_impl->IsStereo(); + return isStereo; +} + +QRadioTuner::StereoMode QXARadioSession::stereoMode() const +{ + QRadioTuner::StereoMode mode(QRadioTuner::Auto); + if (m_impl) + mode = m_impl->StereoMode(); + return mode; +} + +void QXARadioSession::setStereoMode(QRadioTuner::StereoMode mode) +{ + if (m_impl) + m_impl->SetStereoMode(mode); +} + +int QXARadioSession::signalStrength() const +{ + TInt signalStrength = 0; + if (m_impl) + signalStrength = m_impl->GetSignalStrength(); + return (int)signalStrength; +} + +int QXARadioSession::volume() const +{ + TInt volume = 0; + if (m_impl) + volume = m_impl->GetVolume(); + return volume; +} + +int QXARadioSession::setVolume(int volume) +{ + TInt newVolume = 0; + if (m_impl) { + m_impl->SetVolume(volume); + newVolume = m_impl->GetVolume(); + } + return newVolume; +} + +bool QXARadioSession::isMuted() const +{ + bool isMuted = false; + if (m_impl) + isMuted = m_impl->IsMuted(); + return isMuted; +} + +void QXARadioSession::setMuted(bool muted) +{ + if (m_impl) + m_impl->SetMuted(muted); +} + +bool QXARadioSession::isSearching() const +{ + bool isSearching = false; + if (m_impl) + isSearching = m_impl->IsSearching(); + return isSearching; +} + +void QXARadioSession::searchForward() +{ + if (m_impl) + m_impl->Seek(true); +} + +void QXARadioSession::searchBackward() +{ + if (m_impl) + m_impl->Seek(false); +} + +void QXARadioSession::cancelSearch() +{ + if (m_impl) + m_impl->StopSeeking(); +} + +void QXARadioSession::start() +{ + if (m_impl) + m_impl->Start(); +} + +void QXARadioSession::stop() +{ + if (m_impl) + m_impl->Stop(); +} + +QRadioTuner::Error QXARadioSession::error() const +{ + QRadioTuner::Error err(QRadioTuner::NoError); + if (m_impl) + err = m_impl->Error(); + return err; +} + +QString QXARadioSession::errorString() const +{ + QString str = NULL; + switch (iError) { + case QRadioTuner::ResourceError: + str = "Resource Error"; + break; + case QRadioTuner::OpenError: + str = "Open Error"; + break; + case QRadioTuner::OutOfRangeError: + str = "Out of Range Error"; + break; + default: + break; + } + + return str; +} + +// Callbacks, which will emit signals to client: +void QXARadioSession::CBStateChanged(QRadioTuner::State state) +{ + emit stateChanged(state); +} + +void QXARadioSession::CBBandChanged(QRadioTuner::Band band) +{ + emit bandChanged(band); +} + +void QXARadioSession::CBFrequencyChanged(TInt newFrequency) +{ + emit frequencyChanged(newFrequency); +} + +void QXARadioSession::CBStereoStatusChanged(bool isStereo) +{ + emit stereoStatusChanged(isStereo); +} + +void QXARadioSession::CBSignalStrengthChanged(int signalStrength) +{ + emit signalStrengthChanged(signalStrength); +} + +void QXARadioSession::CBVolumeChanged(int volume) +{ + emit volumeChanged(volume); +} + +void QXARadioSession::CBMutedChanged(bool isMuted) +{ + emit mutedChanged(isMuted); +} + +void QXARadioSession::CBSearchingChanged(bool isSearching) +{ + emit searchingChanged(isSearching); +} + +void QXARadioSession::CBError(QRadioTuner::Error err) +{ + iError = err; + emit error((int)err, errorString()); +} + + diff --git a/src/plugins/symbian/openmaxal/radiotuner/qxaradiosession.h b/src/plugins/symbian/openmaxal/radiotuner/qxaradiosession.h new file mode 100644 index 000000000..72f6a7a01 --- /dev/null +++ b/src/plugins/symbian/openmaxal/radiotuner/qxaradiosession.h @@ -0,0 +1,118 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef QXARADIOSESSION_H +#define QXARADIOSESSION_H + +#include <QObject> +#include <QUrl> +#include <qradiotuner.h> +#include "xaradiosessionimplobserver.h" + +QT_USE_NAMESPACE + +class XARadioSessionImpl; + +class QXARadioSession : public QObject, public XARadioSessionImplObserver +{ +Q_OBJECT + +public: + QXARadioSession(QObject *parent); + virtual ~QXARadioSession(); + + QRadioTuner::State state() const; + QRadioTuner::Band band() const; + void setBand(QRadioTuner::Band band); + bool isBandSupported(QRadioTuner::Band band) 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; + int setVolume(int volume); + bool isMuted() const; + void setMuted(bool muted); + bool isSearching() const; + void searchForward(); + void searchBackward(); + void cancelSearch(); + void start(); + void stop(); + bool isAvailable() const; + QtMultimediaKit::AvailabilityError availabilityError() const; + QRadioTuner::Error error() const; + QString errorString() const; + + /* Callbacks from XARadioSessionImplObserver begin */ + void CBBandChanged(QRadioTuner::Band band); + void CBStateChanged(QRadioTuner::State state); + void CBFrequencyChanged(TInt newFrequency); + void CBStereoStatusChanged(bool isStereo); + void CBSignalStrengthChanged(int signalStrength); + void CBVolumeChanged(int volume); + void CBMutedChanged(bool isMuted); + void CBSearchingChanged(bool isSearching); + void CBError(QRadioTuner::Error err); + /* Callbacks from XARadioSessionImplObserver end */ + +signals: + void stateChanged(QRadioTuner::State state); + void bandChanged(QRadioTuner::Band band); + void frequencyChanged(int frequency); + void stereoStatusChanged(bool stereo); + void searchingChanged(bool stereo); + void signalStrengthChanged(int signalStrength); + void volumeChanged(int volume); + void mutedChanged(bool muted); + void error(int err, QString str); + +private: + /* Own */ + QRadioTuner::Error iError; + XARadioSessionImpl* m_impl; +}; + +#endif /*QXARADIOSESSION_H*/ diff --git a/src/plugins/symbian/openmaxal/radiotuner/radiotuner.pri b/src/plugins/symbian/openmaxal/radiotuner/radiotuner.pri new file mode 100644 index 000000000..bf83d05fc --- /dev/null +++ b/src/plugins/symbian/openmaxal/radiotuner/radiotuner.pri @@ -0,0 +1,18 @@ +INCLUDEPATH += $$PWD + +# Input +HEADERS += \ + $$PWD/qxaradiomediaservice.h \ + $$PWD/qxaradiosession.h \ + $$PWD/qxaradiocontrol.h \ + $$PWD/xaradiosessionimpl.h \ + $$PWD/xaradiosessionimplobserver.h + +SOURCES += \ + $$PWD/qxaradiomediaservice.cpp \ + $$PWD/qxaradiosession.cpp \ + $$PWD/qxaradiocontrol.cpp \ + $$PWD/xaradiosessionimpl.cpp + +LIBS += \ + -lbafl diff --git a/src/plugins/symbian/openmaxal/radiotuner/xaradiosessionimpl.cpp b/src/plugins/symbian/openmaxal/radiotuner/xaradiosessionimpl.cpp new file mode 100644 index 000000000..94bebc373 --- /dev/null +++ b/src/plugins/symbian/openmaxal/radiotuner/xaradiosessionimpl.cpp @@ -0,0 +1,715 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "xaradiosessionimpl.h" +#include "xaradiosessionimplobserver.h" +#include <xaradioitfext.h> +#include "xacommon.h" + +#define MAX_NUMBER_INTERFACES 20 +#define FM_STEP 100000; // Hz (.1 MHz) + +/* + * function declarations. + * */ +void EngineObjectCallback(XAObjectItf caller, const void */*pContext*/, + XAuint32 event, XAresult result, XAuint32 /*param*/, + void */*pInterface*/); + +void RadioCallback(XARadioItf caller, void* pContext, XAuint32 event, XAuint32 eventIntData, XAboolean eventBooleanData); +void NokiaVolumeExtItfCallback(XANokiaVolumeExtItf caller, void* pContext, XAuint32 event, XAboolean eventBooleanData); +void NokiaLinearVolumeItfCallback(XANokiaLinearVolumeItf caller, void* pContext, XAuint32 event, XAboolean eventBooleanData); +void PlayItfCallbackForRadio(XAPlayItf caller, void* pContext, XAuint32 event); + +XARadioSessionImpl::XARadioSessionImpl(XARadioSessionImplObserver& parent) +:iParent(parent), +iRadio(NULL), +iEngine(NULL), +iPlayer(NULL), +iSearching(EFalse), +iRadioAvailable(EFalse), +iState(QRadioTuner::StoppedState) +{ + iAvailabilityError = QtMultimediaKit::NoError; +} + +XARadioSessionImpl::~XARadioSessionImpl() +{ + if (iRadio) { + TRACE_LOG((_L("XARadioSessionImpl::~XARadioSessionImpl(): Deleting Radio Device..."))); + (*iRadio)->Destroy(iRadio); + iRadio = NULL; + TRACE_LOG((_L("XARadioSessionImpl::~XARadioSessionImpl(): Deleted Radio Device"))); + } + if (iPlayer) { + TRACE_LOG((_L("XARadioSessionImpl::~XARadioSessionImpl(): Deleting player..."))); + (*iPlayer)->Destroy(iPlayer); + iPlayer = NULL; + TRACE_LOG((_L("XARadioSessionImpl::~XARadioSessionImpl(): Deleted iPlayer"))); + } + if ( iEngine ) { + TRACE_LOG((_L("XARadioSessionImpl::~XARadioSessionImpl(): Deleting engine..."))); + (*iEngine)->Destroy(iEngine); + iEngine = NULL; + TRACE_LOG((_L("XARadioSessionImpl::~XARadioSessionImpl(): Deleted engine"))); + } +} + +QRadioTuner::Error XARadioSessionImpl::PostConstruct() +{ + XAresult res = CreateEngine(); + if (res != KErrNone) + return QRadioTuner::ResourceError; + else + return QRadioTuner::NoError; +} + +TInt XARadioSessionImpl::CreateEngine() +{ + TRACE_FUNCTION_ENTRY; + XAboolean required[MAX_NUMBER_INTERFACES]; + XAInterfaceID iidArray[MAX_NUMBER_INTERFACES]; + XAuint32 noOfInterfaces = 0; + int i; + XAresult res; + + XAEngineOption EngineOption[] = + { + { + (XAuint32) XA_ENGINEOPTION_THREADSAFE, + (XAuint32) XA_BOOLEAN_TRUE + } + }; + + /* Create XA engine */ + if (!iEngine) { + TRACE_LOG((_L("XARadioSessionImpl::CreateEngine: Creating Engine..."))); + res = xaCreateEngine(&iEngine, 1, EngineOption, 0, NULL, NULL); + RET_ERR_IF_ERR(CheckErr(res)); + res = (*iEngine)->RegisterCallback(iEngine, EngineObjectCallback, NULL); + RET_ERR_IF_ERR(CheckErr(res)); + + TRACE_LOG((_L("XARadioSessionImpl::CreateEngine: Realizing..."))); + res = (*iEngine)->Realize(iEngine, XA_BOOLEAN_FALSE); + RET_ERR_IF_ERR(CheckErr(res)); + + // Create Engine Interface: + TRACE_LOG((_L("XARadioSessionImpl::CreateEngine: Creating Engine Interface"))); + RET_ERR_IF_ERR(CheckErr((*iEngine)->GetInterface(iEngine, XA_IID_ENGINE, (void*)&iEngineItf))); + + // Create Radio Device and interface(s): + if (!iRadio) { + TRACE_LOG((_L("XARadioSessionImpl::CreateEngine: Creating Radio Device"))); + res = (*iEngineItf)->CreateRadioDevice(iEngineItf,&iRadio, 0, NULL, NULL); + RET_ERR_IF_ERR(CheckErr(res)); + + TRACE_LOG((_L("XARadioSessionImpl::CreateEngine: Realize Radio Device"))); + res = (*iRadio)->Realize(iRadio, XA_BOOLEAN_FALSE); + RET_ERR_IF_ERR(CheckErr(res)); + + // Get Radio interface: + TRACE_LOG((_L("XARadioSessionImpl::CreateEngine: Get Radio Interface"))); + res = (*iRadio)->GetInterface(iRadio, XA_IID_RADIO, (void*)&iRadioItf); + RET_ERR_IF_ERR(CheckErr(res)); + iRadioAvailable = ETrue; + // Register Radio Callback: + TRACE_LOG((_L("XARadioSessionImpl::CreateEngine: Create Radio Callback:"))); + res = (*iRadioItf)->RegisterRadioCallback(iRadioItf, RadioCallback, (void*)this); + RET_ERR_IF_ERR(CheckErr(res)); + } + XADataSource audioSource; + XADataLocator_IODevice locatorIODevice; + XADataSink audioSink; + XADataLocator_OutputMix locator_outputmix; + + /* Init arrays required[] and iidArray[] */ + for (i = 0; i < MAX_NUMBER_INTERFACES; i++) { + required[i] = XA_BOOLEAN_FALSE; + iidArray[i] = XA_IID_NULL; + } + + iidArray[0] = XA_IID_NOKIAVOLUMEEXT; + iidArray[1] = XA_IID_NOKIALINEARVOLUME; + noOfInterfaces = 2; + + locatorIODevice.locatorType = XA_DATALOCATOR_IODEVICE; + locatorIODevice.deviceType = XA_IODEVICE_RADIO; + locatorIODevice.deviceID = 0; /* ignored */ + locatorIODevice.device = iRadio; + audioSource.pLocator = (void*) &locatorIODevice; + audioSource.pFormat = NULL; + + /* Setup the data sink structure */ + locator_outputmix.locatorType = XA_DEFAULTDEVICEID_AUDIOOUTPUT; + locator_outputmix.outputMix = NULL; + audioSink.pLocator = (void*) &locator_outputmix; + audioSink.pFormat = NULL; + + TRACE_LOG((_L("XARadioSessionImpl::CreateEngine: Create Media Player:"))); + res = (*iEngineItf)->CreateMediaPlayer(iEngineItf, &iPlayer, &audioSource, NULL, &audioSink, NULL, NULL, NULL, noOfInterfaces, iidArray, required); + RET_ERR_IF_ERR(CheckErr(res)); + + TRACE_LOG((_L("XARadioSessionImpl::CreateEngine: Realize Media Player:"))); + res = (*iPlayer)->Realize(iPlayer, XA_BOOLEAN_FALSE); + RET_ERR_IF_ERR(CheckErr(res)); + TRACE_LOG((_L("XARadioSessionImpl::CreateEngine: Get Play Interface from player:"))); + res = (*iPlayer)->GetInterface(iPlayer, XA_IID_PLAY, (void*) &iPlayItf); + RET_ERR_IF_ERR(CheckErr(res)); + TRACE_LOG((_L("XARadioSessionImpl::CreateEngine: Create PlayItf Callback:"))); + res = (*iPlayItf)->RegisterCallback(iPlayItf, PlayItfCallbackForRadio, (void*)this); + RET_ERR_IF_ERR(CheckErr(res)); + + // Get Volume Interfaces specific for Nokia impl: + TRACE_LOG((_L("XARadioSessionImpl::CreateEngine: Get NokiaVolumeExt Interface"))); + res = (*iPlayer)->GetInterface(iPlayer, XA_IID_NOKIAVOLUMEEXT, (void*)&iNokiaVolumeExtItf); + RET_ERR_IF_ERR(CheckErr(res)); + + TRACE_LOG((_L("XARadioSessionImpl::CreateEngine: Get NokiaLinearVolume Interface"))); + res = (*iPlayer)->GetInterface(iPlayer, XA_IID_NOKIALINEARVOLUME, (void*)&iNokiaLinearVolumeItf); + RET_ERR_IF_ERR(CheckErr(res)); + + // Register Volume Callbacks: + TRACE_LOG((_L("XARadioSessionImpl::CreateEngine: Create NokiaVolumeExtItf Callback:"))); + res = (*iNokiaVolumeExtItf)->RegisterVolumeCallback(iNokiaVolumeExtItf, NokiaVolumeExtItfCallback, (void*)this); + RET_ERR_IF_ERR(CheckErr(res)); + res = (*iNokiaVolumeExtItf)->SetCallbackEventsMask(iNokiaVolumeExtItf,(XA_NOKIAVOLUMEEXT_EVENT_MUTE_CHANGED)); + RET_ERR_IF_ERR(CheckErr(res)); + TRACE_LOG((_L("XARadioSessionImpl::CreateEngine: Create NokiaLinearVolumeItf Callback:"))); + res = (*iNokiaLinearVolumeItf)->RegisterVolumeCallback(iNokiaLinearVolumeItf, NokiaLinearVolumeItfCallback, (void*)this); + RET_ERR_IF_ERR(CheckErr(res)); + res = (*iNokiaLinearVolumeItf)->SetCallbackEventsMask(iNokiaLinearVolumeItf,(XA_NOKIALINEARVOLUME_EVENT_VOLUME_CHANGED)); + RET_ERR_IF_ERR(CheckErr(res)); + } + + TRACE_FUNCTION_EXIT; + return EFalse; +} + +QRadioTuner::State XARadioSessionImpl::State() const +{ + TRACE_FUNCTION_ENTRY_EXIT; + return iState; +} + +QtMultimediaKit::AvailabilityError XARadioSessionImpl::AvailabilityError() const +{ + TRACE_FUNCTION_ENTRY_EXIT; + return iAvailabilityError; +} + + bool XARadioSessionImpl::IsAvailable() const +{ + TRACE_FUNCTION_ENTRY_EXIT; + return iRadioAvailable; +} + +QRadioTuner::Band XARadioSessionImpl::Band() const +{ + TRACE_FUNCTION_ENTRY_EXIT; + return iBand; +} + +void XARadioSessionImpl::SetBand(QRadioTuner::Band band) +{ + if (band != QRadioTuner::FM) + iParent.CBError(QRadioTuner::OpenError); + else + iBand = band; +} + +bool XARadioSessionImpl::IsBandSupported(QRadioTuner::Band band) const +{ + if (band == QRadioTuner::FM) + return ETrue; + else + return EFalse; +} + +// Returns the number of Hertz to increment the frequency by when stepping through frequencies within a given band. +TInt XARadioSessionImpl::FrequencyStep(QRadioTuner::Band /*band*/) const +{ + TInt freqStep = FM_STEP; + return (int)freqStep; +} + +bool XARadioSessionImpl::IsStereo() //const +{ + bool isStereo = EFalse; + QRadioTuner::StereoMode mode = StereoMode(); + if (mode == QRadioTuner::ForceStereo || mode == QRadioTuner::Auto) + isStereo = ETrue; + return isStereo; +} + +bool XARadioSessionImpl::IsMuted() const +{ + TRACE_FUNCTION_ENTRY; + XAboolean isMuted = EFalse; + (*iNokiaVolumeExtItf)->GetMute(iNokiaVolumeExtItf, &isMuted ); + TRACE_LOG((_L("XARadioSessionImpl::IsMuted: isMuted = %d"), isMuted)); + + TRACE_FUNCTION_EXIT; + return isMuted; +} + +bool XARadioSessionImpl::IsSearching() const +{ + //iSearching is set when seek (QT:searchForward-backward) + // iSearching is cleared when SearchingStatusChanged is called or StopSeeking is called + return iSearching; +} + +TInt XARadioSessionImpl::GetFrequency() +{ + TRACE_FUNCTION_ENTRY; + + XAuint32 freq = 0; + XAresult res = (*iRadioItf)->GetFrequency(iRadioItf, &freq ); + RET_ERR_IF_ERR(CheckErr(res)); + TRACE_LOG((_L("XARadioSessionImpl::GetFrequency: Frequency = %d"), freq)); + + TRACE_FUNCTION_EXIT; + return (int)freq; +} + +TInt XARadioSessionImpl::GetFrequencyRange() +{ + TRACE_FUNCTION_ENTRY; + XAuint8 range = 0; + + XAresult res = (*iRadioItf)->GetFreqRange(iRadioItf, &range); + RET_ERR_IF_ERR(CheckErr(res)); + TRACE_LOG((_L("XARadioSessionImpl::GetFrequencyRange: Frequency Range = %d"), range)); + + TRACE_FUNCTION_EXIT; + return (int)range; +} + +TInt XARadioSessionImpl::GetFrequencyRangeProperties(TInt range, TInt &minFreq, TInt &maxFreq) +{ + TRACE_FUNCTION_ENTRY; + XAuint32 freqInterval = 0; + XAresult res = (*iRadioItf)->GetFreqRangeProperties(iRadioItf, (XAuint8)range, (XAuint32*)&minFreq,(XAuint32*)&maxFreq, (XAuint32*)&freqInterval); + RET_ERR_IF_ERR(CheckErr(res)); + TRACE_LOG((_L("XARadioSessionImpl::GetFrequencyRangeProperties: minFreq = %d, maxFreq = %d"), minFreq, maxFreq)); + + TRACE_FUNCTION_EXIT; + return res; +} + +TInt XARadioSessionImpl::SetFrequency(TInt aFreq) +{ + TRACE_FUNCTION_ENTRY; + + TRACE_LOG((_L("XARadioSessionImpl::SetFrequency: Setting Frequency to: %d"), aFreq)); + XAresult res = (*iRadioItf)->SetFrequency(iRadioItf, aFreq ); + RET_ERR_IF_ERR(CheckErr(res)); + + TRACE_FUNCTION_EXIT; + return res; +} + +QRadioTuner::StereoMode XARadioSessionImpl::StereoMode() +{ + TRACE_FUNCTION_ENTRY; + QRadioTuner::StereoMode qtStereoMode; + XAuint32 symStereoMode; + (*iRadioItf)->GetStereoMode(iRadioItf, &symStereoMode); + + if (symStereoMode == XA_STEREOMODE_MONO) + qtStereoMode = QRadioTuner::ForceMono; + else if (symStereoMode == XA_STEREOMODE_STEREO) + qtStereoMode = QRadioTuner::ForceStereo; + else + qtStereoMode = QRadioTuner::Auto; + + TRACE_FUNCTION_EXIT; + return qtStereoMode; +} + +TInt XARadioSessionImpl::SetStereoMode(QRadioTuner::StereoMode qtStereoMode) +{ + TRACE_FUNCTION_ENTRY; + XAuint32 symStereoMode; + + if (qtStereoMode == QRadioTuner::ForceMono) + symStereoMode = XA_STEREOMODE_MONO; + else if (qtStereoMode == QRadioTuner::ForceStereo) + symStereoMode = XA_STEREOMODE_STEREO; + else + symStereoMode = XA_STEREOMODE_AUTO; + + XAresult res = (*iRadioItf)->SetStereoMode(iRadioItf, (symStereoMode)); + TRACE_FUNCTION_EXIT; + return res; +} + +TInt XARadioSessionImpl::GetSignalStrength() +{ + TRACE_FUNCTION_ENTRY; + XAuint32 signalStrength = 0; + + (*iRadioItf)->GetSignalStrength(iRadioItf, &signalStrength ); + TRACE_LOG((_L("XARadioSessionImpl::GetSignalStrength: Signal Strength = %d"), signalStrength)); + TRACE_FUNCTION_EXIT; + return (int)signalStrength; +} + +TInt XARadioSessionImpl::GetVolume() +{ + TRACE_FUNCTION_ENTRY; + XAuint32 vol; + if (iPlayer && iNokiaLinearVolumeItf) { + (*iNokiaLinearVolumeItf)->GetVolumeLevel(iNokiaLinearVolumeItf, &vol ); + TRACE_LOG((_L("XARadioSessionImpl::GetVolume: Volume = %d"), vol)); + } + TRACE_FUNCTION_EXIT; + return (TInt)vol; +} + +TInt XARadioSessionImpl::SetVolume(TInt aVolume) +{ + TRACE_FUNCTION_ENTRY; + XAuint32 newVolume = 0; + TRACE_LOG((_L("XARadioSessionImpl::SetVolume: Setting volume to: %d"), aVolume)); + if (iPlayer && iNokiaLinearVolumeItf) { + newVolume = aVolume; + XAresult res = (*iNokiaLinearVolumeItf)->SetVolumeLevel(iNokiaLinearVolumeItf, &newVolume); + } + TRACE_FUNCTION_EXIT; + return (TInt)newVolume; +} + +TInt XARadioSessionImpl::SetMuted(TBool aMuted) +{ + TRACE_FUNCTION_ENTRY; + XAresult res = (*iNokiaVolumeExtItf)->SetMute(iNokiaVolumeExtItf, aMuted); + TRACE_FUNCTION_EXIT; + return res; +} + +TInt XARadioSessionImpl::Seek(TBool aDirection) +{ + TRACE_FUNCTION_ENTRY; + iSearching = true; + XAresult res = (*iRadioItf)->Seek(iRadioItf, aDirection ); + TRACE_FUNCTION_EXIT; + return res; +} + +TInt XARadioSessionImpl::StopSeeking() +{ + TRACE_FUNCTION_ENTRY; + XAresult res = (*iRadioItf)->StopSeeking(iRadioItf); + iSearching = EFalse; + TRACE_FUNCTION_EXIT; + return res; +} + +void XARadioSessionImpl::Start() +{ + TRACE_FUNCTION_ENTRY; + if (iPlayItf) { + XAresult res = (*iPlayItf)->SetPlayState(iPlayItf, XA_PLAYSTATE_PLAYING); + // add error handling if res != 0 (call errorCB) + } + TRACE_FUNCTION_EXIT; +} + +void XARadioSessionImpl::Stop() +{ + TRACE_FUNCTION_ENTRY; + if (iPlayItf) { + XAresult res = (*iPlayItf)->SetPlayState(iPlayItf, XA_PLAYSTATE_STOPPED); + // add error handling if res != 0 (call errorCB) + } + TRACE_FUNCTION_EXIT; +} + +QRadioTuner::Error XARadioSessionImpl::Error() +{ + TRACE_FUNCTION_ENTRY_EXIT; + return QRadioTuner::NoError; +} + +//TInt XARadioSessionImpl::ErrorString(); +// { +// TRACE_FUNCTION_ENTRY; + +// TRACE_FUNCTION_EXIT; +// } + +void XARadioSessionImpl::StateChanged(QRadioTuner::State state) +{ + TRACE_FUNCTION_ENTRY; + iState = state; + iParent.CBStateChanged(state); + TRACE_FUNCTION_EXIT; +} + +void XARadioSessionImpl::FrequencyChanged(XAuint32 freq) +{ + TRACE_FUNCTION_ENTRY; + iParent.CBFrequencyChanged(freq); + TRACE_FUNCTION_EXIT; +} + +void XARadioSessionImpl::SearchingChanged(TBool isSearching) +{ + TRACE_FUNCTION_ENTRY; + iSearching = EFalse; + iParent.CBSearchingChanged(isSearching); + TRACE_FUNCTION_EXIT; +} + +void XARadioSessionImpl::StereoStatusChanged(TBool stereoStatus) +{ + TRACE_FUNCTION_ENTRY; + iParent.CBStereoStatusChanged(stereoStatus); + TRACE_FUNCTION_EXIT; +} + +void XARadioSessionImpl::SignalStrengthChanged(TBool stereoStatus) +{ + TRACE_FUNCTION_ENTRY; + iParent.CBSignalStrengthChanged(stereoStatus); + TRACE_FUNCTION_EXIT; +} + +void XARadioSessionImpl::VolumeChanged() +{ + TRACE_FUNCTION_ENTRY; + int vol = 0; + iParent.CBVolumeChanged(vol); + TRACE_FUNCTION_EXIT; +} + +void XARadioSessionImpl::MutedChanged(TBool mute) +{ + TRACE_FUNCTION_ENTRY; + iParent.CBMutedChanged(mute); + TRACE_FUNCTION_EXIT; +} + +void EngineObjectCallback(XAObjectItf /*caller*/, + const void */*pContext*/, +#ifdef PLUGIN_SYMBIAN_TRACE_ENABLED + XAuint32 event, +#else + XAuint32 /*event*/, +#endif /*PLUGIN_SYMBIAN_TRACE_ENABLED*/ + XAresult /*result*/, + XAuint32 /*param*/, + void */*pInterface*/) +{ +#ifdef PLUGIN_SYMBIAN_TRACE_ENABLED + TRACE_LOG((_L("Engine object event: 0x%x\n"), (int)event)); +#endif /*PLUGIN_SYMBIAN_TRACE_ENABLED*/ +} + +void RadioCallback(XARadioItf /*caller*/, + void* pContext, + XAuint32 event, + XAuint32 eventIntData, + XAboolean eventBooleanData) +{ + XAuint32 freq; + XAboolean stereoStatus(XA_BOOLEAN_FALSE); + + switch (event) { + case XA_RADIO_EVENT_ANTENNA_STATUS_CHANGED: + TRACE_LOG((_L("RadioCallback: XA_RADIO_EVENT_ANTENNA_STATUS_CHANGED"))); + // Qt API has no callback defined for this event. + break; + case XA_RADIO_EVENT_FREQUENCY_CHANGED: + freq = eventIntData; + TRACE_LOG((_L("RadioCallback: XA_RADIO_EVENT_FREQUENCY_CHANGED to: %d"), freq)); + if (pContext) + ((XARadioSessionImpl*)pContext)->FrequencyChanged(freq); + break; + case XA_RADIO_EVENT_FREQUENCY_RANGE_CHANGED: + TRACE_LOG((_L("RadioCallback: XA_RADIO_EVENT_FREQUENCY_RANGE_CHANGED"))); + // Qt API has no callback defined for this event. + break; + case XA_RADIO_EVENT_PRESET_CHANGED: + TRACE_LOG((_L("RadioCallback: XA_RADIO_EVENT_PRESET_CHANGED"))); + // Qt API has no callback defined for this event. + break; + case XA_RADIO_EVENT_SEEK_COMPLETED: + TRACE_LOG((_L("RadioCallback: XA_RADIO_EVENT_SEEK_COMPLETED"))); + if (pContext) + ((XARadioSessionImpl*)pContext)->SearchingChanged(false); + break; + case XA_RADIO_EVENT_STEREO_STATUS_CHANGED: + stereoStatus = eventBooleanData; + TRACE_LOG((_L("RadioCallback: XA_RADIO_EVENT_STEREO_STATUS_CHANGED: %d"), stereoStatus)); + if (pContext) + ((XARadioSessionImpl*)pContext)->StereoStatusChanged(stereoStatus); + break; + case XA_RADIO_EVENT_SIGNAL_STRENGTH_CHANGED: + TRACE_LOG((_L("RadioCallback: XA_RADIO_EVENT_SIGNAL_STRENGTH_CHANGED"))); + if (pContext) + ((XARadioSessionImpl*)pContext)->SignalStrengthChanged(stereoStatus); + break; + default: + TRACE_LOG((_L("RadioCallback: default"))); + break; + } +} + +void NokiaVolumeExtItfCallback(XANokiaVolumeExtItf /*caller*/, + void* pContext, + XAuint32 event, + XAboolean eventBooleanData) +{ + XAboolean mute; + switch (event) { + case XA_NOKIAVOLUMEEXT_EVENT_MUTE_CHANGED: + mute = eventBooleanData; + TRACE_LOG((_L("NokiaVolumeExtItfCallback: XA_NOKIAVOLUMEEXT_EVENT_MUTE_CHANGED to: %d"), mute)); + if (pContext) + ((XARadioSessionImpl*)pContext)->MutedChanged(mute); + break; + default: + TRACE_LOG((_L("NokiaVolumeExtItfCallback: default"))); + break; + } +} + +void NokiaLinearVolumeItfCallback(XANokiaLinearVolumeItf /*caller*/, + void* pContext, + XAuint32 event, + XAboolean /*eventBooleanData*/) +{ + switch (event) { + case XA_NOKIALINEARVOLUME_EVENT_VOLUME_CHANGED: + if (pContext) + ((XARadioSessionImpl*)pContext)->VolumeChanged(); + break; + default: + TRACE_LOG((_L("NokiaLinearVolumeItfCallback: default"))); + break; + } +} + +void PlayItfCallbackForRadio(XAPlayItf /*caller*/, + void* pContext, + XAuint32 event) +{ + switch (event) { + case XA_PLAYEVENT_HEADMOVING: + if (pContext) + ((XARadioSessionImpl*)pContext)->StateChanged(QRadioTuner::ActiveState); + break; + case XA_PLAYEVENT_HEADSTALLED: + if (pContext) + ((XARadioSessionImpl*)pContext)->StateChanged(QRadioTuner::StoppedState); + break; + default: + TRACE_LOG((_L("NokiaLinearVolumeItfCallback: default"))); + break; + } +} + +TInt XARadioSessionImpl::CheckErr(XAresult res) +{ + TInt status(KErrGeneral); + switch(res) { + case XA_RESULT_SUCCESS: + //TRACE_LOG((_L("XA_RESULT_SUCCESS"))); + status = KErrNone; + break; + case XA_RESULT_PRECONDITIONS_VIOLATED: + TRACE_LOG((_L("XA_RESULT_PRECONDITIONS_VIOLATED"))); + break; + case XA_RESULT_PARAMETER_INVALID: + TRACE_LOG((_L("XA_RESULT_PARAMETER_INVALID"))); + break; + case XA_RESULT_MEMORY_FAILURE: + TRACE_LOG((_L("XA_RESULT_MEMORY_FAILURE"))); + iAvailabilityError = QtMultimediaKit::ResourceError; + break; + case XA_RESULT_RESOURCE_ERROR: + TRACE_LOG((_L("XA_RESULT_RESOURCE_ERROR"))); + iAvailabilityError = QtMultimediaKit::ResourceError; + break; + case XA_RESULT_RESOURCE_LOST: + TRACE_LOG((_L("XA_RESULT_RESOURCE_LOST"))); + iAvailabilityError = QtMultimediaKit::ResourceError; + break; + case XA_RESULT_IO_ERROR: + TRACE_LOG((_L("XA_RESULT_IO_ERROR"))); + break; + case XA_RESULT_BUFFER_INSUFFICIENT: + TRACE_LOG((_L("XA_RESULT_BUFFER_INSUFFICIENT"))); + break; + case XA_RESULT_CONTENT_CORRUPTED: + TRACE_LOG((_L("XA_RESULT_CONTENT_CORRUPTED"))); + break; + case XA_RESULT_CONTENT_UNSUPPORTED: + TRACE_LOG((_L("XA_RESULT_CONTENT_UNSUPPORTED"))); + break; + case XA_RESULT_CONTENT_NOT_FOUND: + TRACE_LOG((_L("XA_RESULT_CONTENT_NOT_FOUND"))); + break; + case XA_RESULT_PERMISSION_DENIED: + TRACE_LOG((_L("XA_RESULT_PERMISSION_DENIED"))); + break; + case XA_RESULT_FEATURE_UNSUPPORTED: + TRACE_LOG((_L("XA_RESULT_FEATURE_UNSUPPORTED"))); + break; + case XA_RESULT_INTERNAL_ERROR: + TRACE_LOG((_L("XA_RESULT_INTERNAL_ERROR"))); + break; + case XA_RESULT_UNKNOWN_ERROR: + TRACE_LOG((_L("XA_RESULT_UNKNOWN_ERROR"))); + break; + case XA_RESULT_OPERATION_ABORTED: + TRACE_LOG((_L("XA_RESULT_OPERATION_ABORTED"))); + break; + case XA_RESULT_CONTROL_LOST: + TRACE_LOG((_L("XA_RESULT_CONTROL_LOST"))); + break; + default: + TRACE_LOG((_L("Unknown Error!!!"))); + } + return status; +} diff --git a/src/plugins/symbian/openmaxal/radiotuner/xaradiosessionimpl.h b/src/plugins/symbian/openmaxal/radiotuner/xaradiosessionimpl.h new file mode 100644 index 000000000..ee5f53a2f --- /dev/null +++ b/src/plugins/symbian/openmaxal/radiotuner/xaradiosessionimpl.h @@ -0,0 +1,128 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef XARADIOSESSIONIMPL_H +#define XARADIOSESSIONIMPL_H + +#include <OpenMAXAL.h> +#include <xanokialinearvolumeitf.h> +#include <xanokiavolumeextitf.h> +#include <qradiotuner.h> +#include <qtmedianamespace.h> + +QT_USE_NAMESPACE + +class XARadioSessionImplObserver; + +class XARadioSessionImpl +{ +public: + XARadioSessionImpl(XARadioSessionImplObserver& parent); + ~XARadioSessionImpl(); + QRadioTuner::Error PostConstruct(); + QRadioTuner::Band Band() const; + QRadioTuner::State State() const; + QtMultimediaKit::AvailabilityError AvailabilityError() const; + bool IsAvailable() const; + void SetBand(QRadioTuner::Band band); + bool IsBandSupported(QRadioTuner::Band band) const; + TInt FrequencyStep(QRadioTuner::Band band) const; + bool IsStereo(); //const; + bool IsMuted() const; + bool IsSearching() const; + TInt GetFrequency(); + TInt GetFrequencyRange(); + TInt GetFrequencyRangeProperties(TInt range, TInt &minFreq, TInt &maxFreq); + TInt SetFrequency(TInt aFreq); + QRadioTuner::StereoMode StereoMode(); + TInt SetStereoMode(QRadioTuner::StereoMode stereoMode); + TInt GetSignalStrength(); + TInt GetVolume(); + TInt SetVolume(TInt aVolume); + TInt SetMuted(TBool aMuted); + TInt Seek(TBool aDirection); + TInt StopSeeking(); + void Start(); + void Stop(); + QRadioTuner::Error Error(); +//TInt ErrorString(); + void StateChanged(QRadioTuner::State state); + void FrequencyChanged(XAuint32 freq); + void SearchingChanged(TBool isSearching); + void StereoStatusChanged(TBool stereoStatus); + void SignalStrengthChanged(TBool stereoStatus); + void VolumeChanged(); + void MutedChanged(TBool mute); + +private: + TInt CreateEngine(); + TInt CheckErr(XAresult res); + + +private: + XARadioSessionImplObserver& iParent; + XAObjectItf iRadio; + XAObjectItf iEngine; + XAObjectItf iPlayer; + XAEngineItf iEngineItf; + XARecordItf iRecordItf; + XAPlayItf iPlayItf; + XARadioItf iRadioItf; + XARDSItf iRdsItf; + XANokiaVolumeExtItf iNokiaVolumeExtItf; // used for mute functionality + XANokiaLinearVolumeItf iNokiaLinearVolumeItf; // used for volume functionality + + /* Audio Source */ + XADataSource iDataSource; + + /*Audio Sink*/ + XADataSink iAudioSink; + XADataLocator_OutputMix iLocator_outputmix; + + TBool iAutoFlag; + TBool iSearching; + TBool iRadioAvailable; + QtMultimediaKit::AvailabilityError iAvailabilityError; + QRadioTuner::Band iBand; + QRadioTuner::State iState; +}; + +#endif /* XARADIOSESSIONIMPL_H */ diff --git a/src/plugins/symbian/openmaxal/radiotuner/xaradiosessionimplobserver.h b/src/plugins/symbian/openmaxal/radiotuner/xaradiosessionimplobserver.h new file mode 100644 index 000000000..73c734fd3 --- /dev/null +++ b/src/plugins/symbian/openmaxal/radiotuner/xaradiosessionimplobserver.h @@ -0,0 +1,64 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef XARADIOSESSIONIMPLOBSERVER_H +#define XARADIOSESSIONIMPLOBSERVER_H + +#include <e32base.h> +#include <qradiotuner.h> + +QT_USE_NAMESPACE + +class XARadioSessionImplObserver +{ +public: + virtual void CBStateChanged(QRadioTuner::State state) = 0; + virtual void CBBandChanged(QRadioTuner::Band band) = 0; + virtual void CBFrequencyChanged(TInt newFrequency) = 0; + virtual void CBStereoStatusChanged(bool isStereo) = 0; + virtual void CBSignalStrengthChanged(int signalStrength) = 0; + virtual void CBVolumeChanged(int volume) = 0; + virtual void CBMutedChanged(bool isMuted) = 0; + virtual void CBSearchingChanged(bool isSearching) = 0; + virtual void CBError(QRadioTuner::Error err) = 0; +}; + +#endif /*XARADIOSESSIONIMPLOBSERVER_H*/ diff --git a/src/plugins/symbian/openmaxal/xacommon.h b/src/plugins/symbian/openmaxal/xacommon.h new file mode 100644 index 000000000..9aecbc8f5 --- /dev/null +++ b/src/plugins/symbian/openmaxal/xacommon.h @@ -0,0 +1,79 @@ +/**************************************************************************** +** +** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). +** All rights reserved. +** Contact: Nokia Corporation (qt-info@nokia.com) +** +** This file is part of the Qt Mobility Components. +** +** $QT_BEGIN_LICENSE:LGPL$ +** No Commercial Usage +** This file contains pre-release code and may not be distributed. +** You may use this file in accordance with the terms and conditions +** contained in the Technology Preview License Agreement accompanying +** this package. +** +** GNU Lesser General Public License Usage +** Alternatively, 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. +** +** If you have questions regarding the use of this file, please contact +** Nokia at qt-info@nokia.com. +** +** +** +** +** +** +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef XACOMMON_H +#define XACOMMON_H + +#ifdef PLUGIN_SYMBIAN_TRACE_ENABLED +# include <e32debug.h> +#endif /* PLUGIN_SYMBIAN_TRACE_ENABLED */ + +#ifdef PLUGIN_SYMBIAN_TRACE_ENABLED +# define TRACE_FUNCTION_ENTRY RDebug::Printf( "%s >", __PRETTY_FUNCTION__) +# define TRACE_FUNCTION_EXIT RDebug::Printf( "%s <", __PRETTY_FUNCTION__) +# define TRACE_FUNCTION_ENTRY_EXIT RDebug::Printf( "%s ><", __PRETTY_FUNCTION__) +# define TRACE_LOG(s) RDebug::Print s +#else +# define TRACE_FUNCTION_ENTRY +# define TRACE_FUNCTION_EXIT +# define TRACE_FUNCTION_ENTRY_EXIT +# define TRACE_LOG +#endif /* PLUGIN_SYMBIAN_TRACE_ENABLED */ + +#define RET_IF_FALSE(e) \ + if (e == false) \ + { \ + return; \ + } + +#define RET_BOOL_IF_FALSE(e) \ + if (e == false) \ + { \ + return e; \ + } + +#define RET_ERR_IF_ERR(e) \ + if (e != 0) \ + { \ + return e; \ + } + +#endif /* XACOMMON_H */ |