|
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 QAUDIOOUTPUT_SYMBIAN_P_H |
|
54 #define QAUDIOOUTPUT_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 QAudioOutputPrivate; |
|
65 |
|
66 class SymbianAudioOutputPrivate : public QIODevice |
|
67 { |
|
68 friend class QAudioOutputPrivate; |
|
69 Q_OBJECT |
|
70 public: |
|
71 SymbianAudioOutputPrivate(QAudioOutputPrivate *audio); |
|
72 ~SymbianAudioOutputPrivate(); |
|
73 |
|
74 qint64 readData(char *data, qint64 len); |
|
75 qint64 writeData(const char *data, qint64 len); |
|
76 |
|
77 private: |
|
78 QAudioOutputPrivate *const m_audioDevice; |
|
79 }; |
|
80 |
|
81 class QAudioOutputPrivate |
|
82 : public QAbstractAudioOutput |
|
83 , public MDevSoundObserver |
|
84 { |
|
85 friend class SymbianAudioOutputPrivate; |
|
86 Q_OBJECT |
|
87 public: |
|
88 QAudioOutputPrivate(const QByteArray &device, |
|
89 const QAudioFormat &audioFormat); |
|
90 ~QAudioOutputPrivate(); |
|
91 |
|
92 // QAbstractAudioOutput |
|
93 QIODevice* start(QIODevice *device = 0); |
|
94 void stop(); |
|
95 void reset(); |
|
96 void suspend(); |
|
97 void resume(); |
|
98 int bytesFree() 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 // MDevSoundObserver |
|
111 void InitializeComplete(TInt aError); |
|
112 void ToneFinished(TInt aError); |
|
113 void BufferToBeFilled(CMMFBuffer *aBuffer); |
|
114 void PlayError(TInt aError); |
|
115 void BufferToBeEmptied(CMMFBuffer *aBuffer); |
|
116 void RecordError(TInt aError); |
|
117 void ConvertError(TInt aError); |
|
118 void DeviceMessage(TUid aMessageType, const TDesC8 &aMsg); |
|
119 |
|
120 private slots: |
|
121 void dataReady(); |
|
122 void underflowTimerExpired(); |
|
123 |
|
124 private: |
|
125 void open(); |
|
126 void startPlayback(); |
|
127 void startDevSoundL(); |
|
128 void writePaddingData(); |
|
129 qint64 pushData(const char *data, qint64 len); |
|
130 void pullData(); |
|
131 void bufferFilled(); |
|
132 void lastBufferFilled(); |
|
133 Q_INVOKABLE void close(); |
|
134 |
|
135 qint64 getSamplesPlayed() const; |
|
136 |
|
137 void setError(QAudio::Error error); |
|
138 void setState(SymbianAudio::State state); |
|
139 |
|
140 bool isDataReady() const; |
|
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_source; |
|
158 |
|
159 QScopedPointer<CMMFDevSound> m_devSound; |
|
160 TUint32 m_nativeFourCC; |
|
161 TMMFCapabilities m_nativeFormat; |
|
162 |
|
163 // Buffer provided by DevSound, to be filled with data. |
|
164 CMMFDataBuffer *m_devSoundBuffer; |
|
165 |
|
166 int m_devSoundBufferSize; |
|
167 |
|
168 // Number of bytes transferred from QIODevice to QAudioOutput. It is |
|
169 // necessary to count this because data is dropped when suspend() is |
|
170 // called. The difference between the position reported by DevSound and |
|
171 // this value allows us to calculate m_bytesPadding; |
|
172 quint32 m_bytesWritten; |
|
173 |
|
174 // True if client has provided data while the audio subsystem was not |
|
175 // ready to consume it. |
|
176 bool m_pushDataReady; |
|
177 |
|
178 // Number of zero bytes which will be written when client calls resume(). |
|
179 quint32 m_bytesPadding; |
|
180 |
|
181 // True if PlayError(KErrUnderflow) has been called. |
|
182 bool m_underflow; |
|
183 |
|
184 // True if a buffer marked with the "last buffer" flag has been provided |
|
185 // to DevSound. |
|
186 bool m_lastBuffer; |
|
187 |
|
188 // Some DevSound implementations ignore all underflow errors raised by the |
|
189 // audio driver, unless the last buffer flag has been set by the client. |
|
190 // In push-mode playback, this flag will never be set, so the underflow |
|
191 // error will never be reported. In order to work around this, a timer |
|
192 // is used, which gets reset every time the client provides more data. If |
|
193 // the timer expires, an underflow error is raised by this object. |
|
194 QScopedPointer<QTimer> m_underflowTimer; |
|
195 |
|
196 // Result of previous call to CMMFDevSound::SamplesPlayed(). This value is |
|
197 // used to determine whether, when m_underflowTimer expires, an |
|
198 // underflow error has actually occurred. |
|
199 quint32 m_samplesPlayed; |
|
200 |
|
201 // Samples played up to the last call to suspend(). It is necessary |
|
202 // to cache this because suspend() is implemented using |
|
203 // CMMFDevSound::Stop(), which resets DevSound's SamplesPlayed() counter. |
|
204 quint32 m_totalSamplesPlayed; |
|
205 |
|
206 }; |
|
207 |
|
208 QT_END_NAMESPACE |
|
209 |
|
210 #endif |