| 1 | /****************************************************************************
|
|---|
| 2 | **
|
|---|
| 3 | ** Copyright (C) 2011 Nokia Corporation and/or its subsidiary(-ies).
|
|---|
| 4 | ** All rights reserved.
|
|---|
| 5 | ** Contact: Nokia Corporation ([email protected])
|
|---|
| 6 | **
|
|---|
| 7 | ** This file is part of the QtMultimedia module of the Qt Toolkit.
|
|---|
| 8 | **
|
|---|
| 9 | ** $QT_BEGIN_LICENSE:LGPL$
|
|---|
| 10 | ** Commercial Usage
|
|---|
| 11 | ** Licensees holding valid Qt Commercial licenses may use this file in
|
|---|
| 12 | ** accordance with the Qt Commercial License Agreement provided with the
|
|---|
| 13 | ** Software or, alternatively, in accordance with the terms contained in
|
|---|
| 14 | ** a written agreement between you and Nokia.
|
|---|
| 15 | **
|
|---|
| 16 | ** GNU Lesser General Public License Usage
|
|---|
| 17 | ** Alternatively, this file may be used under the terms of the GNU Lesser
|
|---|
| 18 | ** General Public License version 2.1 as published by the Free Software
|
|---|
| 19 | ** Foundation and appearing in the file LICENSE.LGPL included in the
|
|---|
| 20 | ** packaging of this file. Please review the following information to
|
|---|
| 21 | ** ensure the GNU Lesser General Public License version 2.1 requirements
|
|---|
| 22 | ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
|
|---|
| 23 | **
|
|---|
| 24 | ** In addition, as a special exception, Nokia gives you certain additional
|
|---|
| 25 | ** rights. These rights are described in the Nokia Qt LGPL Exception
|
|---|
| 26 | ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
|
|---|
| 27 | **
|
|---|
| 28 | ** GNU General Public License Usage
|
|---|
| 29 | ** Alternatively, this file may be used under the terms of the GNU
|
|---|
| 30 | ** General Public License version 3.0 as published by the Free Software
|
|---|
| 31 | ** Foundation and appearing in the file LICENSE.GPL included in the
|
|---|
| 32 | ** packaging of this file. Please review the following information to
|
|---|
| 33 | ** ensure the GNU General Public License version 3.0 requirements will be
|
|---|
| 34 | ** met: http://www.gnu.org/copyleft/gpl.html.
|
|---|
| 35 | **
|
|---|
| 36 | ** If you have questions regarding the use of this file, please contact
|
|---|
| 37 | ** Nokia at [email protected].
|
|---|
| 38 | ** $QT_END_LICENSE$
|
|---|
| 39 | **
|
|---|
| 40 | ****************************************************************************/
|
|---|
| 41 |
|
|---|
| 42 | //
|
|---|
| 43 | // W A R N I N G
|
|---|
| 44 | // -------------
|
|---|
| 45 | //
|
|---|
| 46 | // This file is not part of the Qt API. It exists for the convenience
|
|---|
| 47 | // of other Qt classes. This header file may change from version to
|
|---|
| 48 | // version without notice, or even be removed.
|
|---|
| 49 | //
|
|---|
| 50 | // We mean it.
|
|---|
| 51 | //
|
|---|
| 52 |
|
|---|
| 53 | #ifndef QAUDIO_SYMBIAN_P_H
|
|---|
| 54 | #define QAUDIO_SYMBIAN_P_H
|
|---|
| 55 |
|
|---|
| 56 | #include <QtCore/QList>
|
|---|
| 57 | #include <QtCore/QString>
|
|---|
| 58 | #include <QtMultimedia/qaudioformat.h>
|
|---|
| 59 | #include <QtMultimedia/qaudio.h>
|
|---|
| 60 | #include <sounddevice.h>
|
|---|
| 61 |
|
|---|
| 62 | QT_BEGIN_NAMESPACE
|
|---|
| 63 |
|
|---|
| 64 | namespace SymbianAudio {
|
|---|
| 65 |
|
|---|
| 66 | /**
|
|---|
| 67 | * Default values used by audio input and output classes, when underlying
|
|---|
| 68 | * DevSound instance has not yet been created.
|
|---|
| 69 | */
|
|---|
| 70 |
|
|---|
| 71 | const int DefaultBufferSize = 4096; // bytes
|
|---|
| 72 | const int DefaultNotifyInterval = 1000; // ms
|
|---|
| 73 |
|
|---|
| 74 | /**
|
|---|
| 75 | * Enumeration used to track state of internal DevSound instances.
|
|---|
| 76 | * Values are translated to the corresponding QAudio::State values by
|
|---|
| 77 | * SymbianAudio::Utils::stateNativeToQt.
|
|---|
| 78 | */
|
|---|
| 79 | enum State {
|
|---|
| 80 | ClosedState
|
|---|
| 81 | , InitializingState
|
|---|
| 82 | , ActiveState
|
|---|
| 83 | , IdleState
|
|---|
| 84 | // QAudio is suspended; DevSound is paused
|
|---|
| 85 | , SuspendedPausedState
|
|---|
| 86 | // QAudio is suspended; DevSound is stopped
|
|---|
| 87 | , SuspendedStoppedState
|
|---|
| 88 | };
|
|---|
| 89 |
|
|---|
| 90 | /**
|
|---|
| 91 | * Wrapper around DevSound instance
|
|---|
| 92 | */
|
|---|
| 93 | class DevSoundWrapper
|
|---|
| 94 | : public QObject
|
|---|
| 95 | , public MDevSoundObserver
|
|---|
| 96 | {
|
|---|
| 97 | Q_OBJECT
|
|---|
| 98 |
|
|---|
| 99 | public:
|
|---|
| 100 | DevSoundWrapper(QAudio::Mode mode, QObject *parent = 0);
|
|---|
| 101 | ~DevSoundWrapper();
|
|---|
| 102 |
|
|---|
| 103 | public:
|
|---|
| 104 | // List of supported codecs; can be called once object is constructed
|
|---|
| 105 | const QList<QString>& supportedCodecs() const;
|
|---|
| 106 |
|
|---|
| 107 | // Asynchronous initialization function; emits devsoundInitializeComplete
|
|---|
| 108 | void initialize(const QString& codec);
|
|---|
| 109 |
|
|---|
| 110 | // Capabilities, for selected codec. Can be called once initialize has returned
|
|---|
| 111 | // successfully.
|
|---|
| 112 | const QList<int>& supportedFrequencies() const;
|
|---|
| 113 | const QList<int>& supportedChannels() const;
|
|---|
| 114 | const QList<int>& supportedSampleSizes() const;
|
|---|
| 115 | const QList<QAudioFormat::Endian>& supportedByteOrders() const;
|
|---|
| 116 | const QList<QAudioFormat::SampleType>& supportedSampleTypes() const;
|
|---|
| 117 |
|
|---|
| 118 | bool isFormatSupported(const QAudioFormat &format) const;
|
|---|
| 119 |
|
|---|
| 120 | int samplesProcessed() const;
|
|---|
| 121 | bool setFormat(const QAudioFormat &format);
|
|---|
| 122 | bool start();
|
|---|
| 123 |
|
|---|
| 124 | // If DevSound implementation supports pause, calls pause and returns true.
|
|---|
| 125 | // Otherwise calls stop and returns false. In this case, all DevSound buffers
|
|---|
| 126 | // currently held by the backend must be discarded.
|
|---|
| 127 | bool pause();
|
|---|
| 128 |
|
|---|
| 129 | void resume();
|
|---|
| 130 |
|
|---|
| 131 | void stop();
|
|---|
| 132 | void bufferProcessed();
|
|---|
| 133 |
|
|---|
| 134 | public:
|
|---|
| 135 | // MDevSoundObserver
|
|---|
| 136 | void InitializeComplete(TInt aError);
|
|---|
| 137 | void ToneFinished(TInt aError);
|
|---|
| 138 | void BufferToBeFilled(CMMFBuffer *aBuffer);
|
|---|
| 139 | void PlayError(TInt aError);
|
|---|
| 140 | void BufferToBeEmptied(CMMFBuffer *aBuffer);
|
|---|
| 141 | void RecordError(TInt aError);
|
|---|
| 142 | void ConvertError(TInt aError);
|
|---|
| 143 | void DeviceMessage(TUid aMessageType, const TDesC8 &aMsg);
|
|---|
| 144 |
|
|---|
| 145 | signals:
|
|---|
| 146 | void initializeComplete(int error);
|
|---|
| 147 | void bufferToBeProcessed(CMMFBuffer *buffer);
|
|---|
| 148 | void processingError(int error);
|
|---|
| 149 |
|
|---|
| 150 | private:
|
|---|
| 151 | void getSupportedCodecs();
|
|---|
| 152 | void populateCapabilities();
|
|---|
| 153 | bool isResumeSupported() const;
|
|---|
| 154 |
|
|---|
| 155 | private:
|
|---|
| 156 | const QAudio::Mode m_mode;
|
|---|
| 157 | TMMFState m_nativeMode;
|
|---|
| 158 |
|
|---|
| 159 | enum State {
|
|---|
| 160 | StateIdle,
|
|---|
| 161 | StateInitializing,
|
|---|
| 162 | StateInitialized
|
|---|
| 163 | } m_state;
|
|---|
| 164 |
|
|---|
| 165 | CMMFDevSound* m_devsound;
|
|---|
| 166 | TFourCC m_fourcc;
|
|---|
| 167 |
|
|---|
| 168 | QList<QString> m_supportedCodecs;
|
|---|
| 169 | QList<int> m_supportedFrequencies;
|
|---|
| 170 | QList<int> m_supportedChannels;
|
|---|
| 171 | QList<int> m_supportedSampleSizes;
|
|---|
| 172 | QList<QAudioFormat::Endian> m_supportedByteOrders;
|
|---|
| 173 | QList<QAudioFormat::SampleType> m_supportedSampleTypes;
|
|---|
| 174 |
|
|---|
| 175 | };
|
|---|
| 176 |
|
|---|
| 177 |
|
|---|
| 178 | namespace Utils {
|
|---|
| 179 |
|
|---|
| 180 | /**
|
|---|
| 181 | * Convert internal states to QAudio states.
|
|---|
| 182 | */
|
|---|
| 183 | QAudio::State stateNativeToQt(State nativeState);
|
|---|
| 184 |
|
|---|
| 185 | /**
|
|---|
| 186 | * Convert data length to number of samples.
|
|---|
| 187 | */
|
|---|
| 188 | qint64 bytesToSamples(const QAudioFormat &format, qint64 length);
|
|---|
| 189 |
|
|---|
| 190 | /**
|
|---|
| 191 | * Convert number of samples to data length.
|
|---|
| 192 | */
|
|---|
| 193 | qint64 samplesToBytes(const QAudioFormat &format, qint64 samples);
|
|---|
| 194 |
|
|---|
| 195 | } // namespace Utils
|
|---|
| 196 | } // namespace SymbianAudio
|
|---|
| 197 |
|
|---|
| 198 | QT_END_NAMESPACE
|
|---|
| 199 |
|
|---|
| 200 | #endif
|
|---|