|
1 /**************************************************************************** |
|
2 ** |
|
3 ** Copyright (C) 2010 Nokia Corporation and/or its subsidiary(-ies). |
|
4 ** All rights reserved. |
|
5 ** Contact: Nokia Corporation (qt-info@nokia.com) |
|
6 ** |
|
7 ** This file is part of the QtMultimedia module of the Qt Toolkit. |
|
8 ** |
|
9 ** $QT_BEGIN_LICENSE:LGPL$ |
|
10 ** No Commercial Usage |
|
11 ** This file contains pre-release code and may not be distributed. |
|
12 ** You may use this file in accordance with the terms and conditions |
|
13 ** contained in the Technology Preview License Agreement accompanying |
|
14 ** this package. |
|
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 ** If you have questions regarding the use of this file, please contact |
|
29 ** Nokia at qt-info@nokia.com. |
|
30 ** |
|
31 ** |
|
32 ** |
|
33 ** |
|
34 ** |
|
35 ** |
|
36 ** |
|
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 <sounddevice.h> |
|
60 #include "qaudio_symbian_p.h" |
|
61 |
|
62 QT_BEGIN_NAMESPACE |
|
63 |
|
64 class QAudioInputPrivate; |
|
65 |
|
66 class SymbianAudioInputPrivate : public QIODevice |
|
67 { |
|
68 friend class QAudioInputPrivate; |
|
69 Q_OBJECT |
|
70 public: |
|
71 SymbianAudioInputPrivate(QAudioInputPrivate *audio); |
|
72 ~SymbianAudioInputPrivate(); |
|
73 |
|
74 qint64 readData(char *data, qint64 len); |
|
75 qint64 writeData(const char *data, qint64 len); |
|
76 |
|
77 void dataReady(); |
|
78 |
|
79 private: |
|
80 QAudioInputPrivate *const m_audioDevice; |
|
81 }; |
|
82 |
|
83 class QAudioInputPrivate |
|
84 : public QAbstractAudioInput |
|
85 , public MDevSoundObserver |
|
86 { |
|
87 friend class SymbianAudioInputPrivate; |
|
88 Q_OBJECT |
|
89 public: |
|
90 QAudioInputPrivate(const QByteArray &device, |
|
91 const QAudioFormat &audioFormat); |
|
92 ~QAudioInputPrivate(); |
|
93 |
|
94 // QAbstractAudioInput |
|
95 QIODevice* start(QIODevice *device = 0); |
|
96 void stop(); |
|
97 void reset(); |
|
98 void suspend(); |
|
99 void resume(); |
|
100 int bytesReady() const; |
|
101 int periodSize() const; |
|
102 void setBufferSize(int value); |
|
103 int bufferSize() const; |
|
104 void setNotifyInterval(int milliSeconds); |
|
105 int notifyInterval() const; |
|
106 qint64 processedUSecs() const; |
|
107 qint64 elapsedUSecs() const; |
|
108 QAudio::Error error() const; |
|
109 QAudio::State state() const; |
|
110 QAudioFormat format() const; |
|
111 |
|
112 // MDevSoundObserver |
|
113 void InitializeComplete(TInt aError); |
|
114 void ToneFinished(TInt aError); |
|
115 void BufferToBeFilled(CMMFBuffer *aBuffer); |
|
116 void PlayError(TInt aError); |
|
117 void BufferToBeEmptied(CMMFBuffer *aBuffer); |
|
118 void RecordError(TInt aError); |
|
119 void ConvertError(TInt aError); |
|
120 void DeviceMessage(TUid aMessageType, const TDesC8 &aMsg); |
|
121 |
|
122 private slots: |
|
123 void pullData(); |
|
124 |
|
125 private: |
|
126 void open(); |
|
127 void startRecording(); |
|
128 void startDevSoundL(); |
|
129 void startDataTransfer(); |
|
130 CMMFDataBuffer* currentBuffer() const; |
|
131 void pushData(); |
|
132 qint64 read(char *data, qint64 len); |
|
133 void bufferEmptied(); |
|
134 Q_INVOKABLE void close(); |
|
135 |
|
136 qint64 getSamplesRecorded() const; |
|
137 |
|
138 void setError(QAudio::Error error); |
|
139 void setState(SymbianAudio::State state); |
|
140 |
|
141 QAudio::State initializingState() const; |
|
142 |
|
143 private: |
|
144 const QByteArray m_device; |
|
145 const QAudioFormat m_format; |
|
146 |
|
147 int m_clientBufferSize; |
|
148 int m_notifyInterval; |
|
149 QScopedPointer<QTimer> m_notifyTimer; |
|
150 QTime m_elapsed; |
|
151 QAudio::Error m_error; |
|
152 |
|
153 SymbianAudio::State m_internalState; |
|
154 QAudio::State m_externalState; |
|
155 |
|
156 bool m_pullMode; |
|
157 QIODevice *m_sink; |
|
158 |
|
159 QScopedPointer<QTimer> m_pullTimer; |
|
160 |
|
161 QScopedPointer<CMMFDevSound> m_devSound; |
|
162 TUint32 m_nativeFourCC; |
|
163 TMMFCapabilities m_nativeFormat; |
|
164 |
|
165 // Latest buffer provided by DevSound, to be empied of data. |
|
166 CMMFDataBuffer *m_devSoundBuffer; |
|
167 |
|
168 int m_devSoundBufferSize; |
|
169 |
|
170 // Total amount of data in buffers provided by DevSound |
|
171 int m_totalBytesReady; |
|
172 |
|
173 // Queue of buffers returned after call to CMMFDevSound::Pause(). |
|
174 QList<CMMFDataBuffer *> m_devSoundBufferQ; |
|
175 |
|
176 // Current read position within m_devSoundBuffer |
|
177 qint64 m_devSoundBufferPos; |
|
178 |
|
179 // Samples recorded up to the last call to suspend(). It is necessary |
|
180 // to cache this because suspend() is implemented using |
|
181 // CMMFDevSound::Stop(), which resets DevSound's SamplesRecorded() counter. |
|
182 quint32 m_totalSamplesRecorded; |
|
183 |
|
184 }; |
|
185 |
|
186 QT_END_NAMESPACE |
|
187 |
|
188 #endif |