1 /**************************************************************************** 2 ** 3 ** Copyright (C) 2015 The Qt Company Ltd. 4 ** Contact: http://www.qt.io/licensing/ 5 ** 6 ** This file is part of the QtMultimedia module of the Qt Toolkit. 7 ** 8 ** $QT_BEGIN_LICENSE:LGPL$ 9 ** Commercial License Usage 10 ** Licensees holding valid commercial Qt licenses may use this file in 11 ** accordance with the commercial license agreement provided with the 12 ** Software or, alternatively, in accordance with the terms contained in 13 ** a written agreement between you and The Qt Company. For licensing terms 14 ** and conditions see http://www.qt.io/terms-conditions. For further 15 ** information use the contact form at http://www.qt.io/contact-us. 16 ** 17 ** GNU Lesser General Public License Usage 18 ** Alternatively, this file may be used under the terms of the GNU Lesser 19 ** General Public License version 2.1 or version 3 as published by the Free 20 ** Software Foundation and appearing in the file LICENSE.LGPLv21 and 21 ** LICENSE.LGPLv3 included in the packaging of this file. Please review the 22 ** following information to ensure the GNU Lesser General Public License 23 ** requirements will be met: https://www.gnu.org/licenses/lgpl.html and 24 ** http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. 25 ** 26 ** As a special exception, The Qt Company gives you certain additional 27 ** rights. These rights are described in The Qt Company LGPL Exception 28 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. 29 ** 30 ** GNU General Public License Usage 31 ** Alternatively, this file may be used under the terms of the GNU 32 ** General Public License version 3.0 as published by the Free Software 33 ** Foundation and appearing in the file LICENSE.GPL included in the 34 ** packaging of this file. Please review the following information to 35 ** ensure the GNU General Public License version 3.0 requirements will be 36 ** met: http://www.gnu.org/copyleft/gpl.html. 37 ** 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 QAUDIOINPUT_SYMBIAN_P_H 54 #define QAUDIOINPUT_SYMBIAN_P_H 55 56 #include <QtMultimedia/qaudioengine.h> 57 #include <QTime> 58 #include <QTimer> 59 #include "qaudio_symbian_p.h" 60 61 QT_BEGIN_NAMESPACE 62 63 class QAudioInputPrivate; 64 65 class SymbianAudioInputPrivate : public QIODevice 66 { 67 friend class QAudioInputPrivate; 68 Q_OBJECT 69 public: 70 SymbianAudioInputPrivate(QAudioInputPrivate *audio); 71 ~SymbianAudioInputPrivate(); 72 73 qint64 readData(char *data, qint64 len); 74 qint64 writeData(const char *data, qint64 len); 75 76 void dataReady(); 77 78 private: 79 QAudioInputPrivate *const m_audioDevice; 80 }; 81 82 class QAudioInputPrivate 83 : public QAbstractAudioInput 84 { 85 friend class SymbianAudioInputPrivate; 86 Q_OBJECT 87 public: 88 QAudioInputPrivate(const QByteArray &device, 89 const QAudioFormat &audioFormat); 90 ~QAudioInputPrivate(); 91 92 // QAbstractAudioInput 93 QIODevice* start(QIODevice *device = 0); 94 void stop(); 95 void reset(); 96 void suspend(); 97 void resume(); 98 int bytesReady() const; 99 int periodSize() const; 100 void setBufferSize(int value); 101 int bufferSize() const; 102 void setNotifyInterval(int milliSeconds); 103 int notifyInterval() const; 104 qint64 processedUSecs() const; 105 qint64 elapsedUSecs() const; 106 QAudio::Error error() const; 107 QAudio::State state() const; 108 QAudioFormat format() const; 109 110 private slots: 111 void pullData(); 112 void devsoundInitializeComplete(int err); 113 void devsoundBufferToBeEmptied(CMMFBuffer *); 114 void devsoundRecordError(int err); 115 116 private: 117 void open(); 118 void startRecording(); 119 void startDataTransfer(); 120 CMMFDataBuffer* currentBuffer() const; 121 void pushData(); 122 qint64 read(char *data, qint64 len); 123 void bufferEmptied(); 124 Q_INVOKABLE void close(); 125 126 qint64 getSamplesRecorded() const; 127 128 void setError(QAudio::Error error); 129 void setState(SymbianAudio::State state); 130 131 private: 132 const QByteArray m_device; 133 const QAudioFormat m_format; 134 135 int m_clientBufferSize; 136 int m_notifyInterval; 137 QScopedPointer<QTimer> m_notifyTimer; 138 QTime m_elapsed; 139 QAudio::Error m_error; 140 141 SymbianAudio::State m_internalState; 142 QAudio::State m_externalState; 143 144 bool m_pullMode; 145 QIODevice *m_sink; 146 147 QScopedPointer<QTimer> m_pullTimer; 148 149 SymbianAudio::DevSoundWrapper* m_devSound; 150 151 // Latest buffer provided by DevSound, to be empied of data. 152 CMMFDataBuffer *m_devSoundBuffer; 153 154 int m_devSoundBufferSize; 155 156 // Total amount of data in buffers provided by DevSound 157 int m_totalBytesReady; 158 159 // Queue of buffers returned after call to CMMFDevSound::Pause(). 160 QList<CMMFDataBuffer *> m_devSoundBufferQ; 161 162 // Current read position within m_devSoundBuffer 163 qint64 m_devSoundBufferPos; 164 165 // Samples recorded up to the last call to suspend(). It is necessary 166 // to cache this because suspend() is implemented using 167 // CMMFDevSound::Stop(), which resets DevSound's SamplesRecorded() counter. 168 quint32 m_totalSamplesRecorded; 169 170 }; 171 172 QT_END_NAMESPACE 173 174 #endif 175