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 #ifndef SYMBIANAUDIOOUTPUT_H |
|
43 #define SYMBIANAUDIOOUTPUT_H |
|
44 |
|
45 #include <QtMultimedia/qaudioengine.h> |
|
46 #include <QTime> |
|
47 #include <QTimer> |
|
48 #include <sounddevice.h> |
|
49 #include "symbianaudio.h" |
|
50 |
|
51 QT_BEGIN_NAMESPACE |
|
52 |
|
53 class SymbianAudioOutput; |
|
54 |
|
55 class SymbianAudioOutputPrivate : public QIODevice |
|
56 { |
|
57 friend class SymbianAudioOutput; |
|
58 Q_OBJECT |
|
59 public: |
|
60 SymbianAudioOutputPrivate(SymbianAudioOutput *audio); |
|
61 ~SymbianAudioOutputPrivate(); |
|
62 |
|
63 qint64 readData(char *data, qint64 len); |
|
64 qint64 writeData(const char *data, qint64 len); |
|
65 |
|
66 private: |
|
67 SymbianAudioOutput *const m_audioDevice; |
|
68 }; |
|
69 |
|
70 class SymbianAudioOutput |
|
71 : public QAbstractAudioOutput |
|
72 , public MDevSoundObserver |
|
73 { |
|
74 friend class SymbianAudioOutputPrivate; |
|
75 Q_OBJECT |
|
76 public: |
|
77 SymbianAudioOutput(const QByteArray &device, |
|
78 const QAudioFormat &audioFormat); |
|
79 ~SymbianAudioOutput(); |
|
80 |
|
81 // QAbstractAudioOutput |
|
82 QIODevice* start(QIODevice *device = 0); |
|
83 void stop(); |
|
84 void reset(); |
|
85 void suspend(); |
|
86 void resume(); |
|
87 int bytesFree() const; |
|
88 int periodSize() const; |
|
89 void setBufferSize(int value); |
|
90 int bufferSize() const; |
|
91 void setNotifyInterval(int milliSeconds); |
|
92 int notifyInterval() const; |
|
93 qint64 processedUSecs() const; |
|
94 qint64 elapsedUSecs() const; |
|
95 QAudio::Error error() const; |
|
96 QAudio::State state() const; |
|
97 QAudioFormat format() const; |
|
98 |
|
99 // MDevSoundObserver |
|
100 void InitializeComplete(TInt aError); |
|
101 void ToneFinished(TInt aError); |
|
102 void BufferToBeFilled(CMMFBuffer *aBuffer); |
|
103 void PlayError(TInt aError); |
|
104 void BufferToBeEmptied(CMMFBuffer *aBuffer); |
|
105 void RecordError(TInt aError); |
|
106 void ConvertError(TInt aError); |
|
107 void DeviceMessage(TUid aMessageType, const TDesC8 &aMsg); |
|
108 |
|
109 private slots: |
|
110 void dataReady(); |
|
111 void underflowTimerExpired(); |
|
112 |
|
113 private: |
|
114 void open(); |
|
115 void startPlayback(); |
|
116 void startDevSoundL(); |
|
117 void writePaddingData(); |
|
118 qint64 pushData(const char *data, qint64 len); |
|
119 void pullData(); |
|
120 void bufferFilled(); |
|
121 void lastBufferFilled(); |
|
122 Q_INVOKABLE void close(); |
|
123 |
|
124 qint64 getSamplesPlayed() const; |
|
125 |
|
126 void setError(QAudio::Error error); |
|
127 void setState(SymbianAudio::State state); |
|
128 |
|
129 bool isDataReady() const; |
|
130 QAudio::State initializingState() const; |
|
131 |
|
132 private: |
|
133 const QByteArray m_device; |
|
134 const QAudioFormat m_format; |
|
135 |
|
136 int m_clientBufferSize; |
|
137 int m_notifyInterval; |
|
138 QScopedPointer<QTimer> m_notifyTimer; |
|
139 QTime m_elapsed; |
|
140 QAudio::Error m_error; |
|
141 |
|
142 SymbianAudio::State m_internalState; |
|
143 QAudio::State m_externalState; |
|
144 |
|
145 bool m_pullMode; |
|
146 QIODevice *m_source; |
|
147 |
|
148 QScopedPointer<CMMFDevSound> m_devSound; |
|
149 TUint32 m_nativeFourCC; |
|
150 TMMFCapabilities m_nativeFormat; |
|
151 |
|
152 // Buffer provided by DevSound, to be filled with data. |
|
153 CMMFDataBuffer *m_devSoundBuffer; |
|
154 |
|
155 int m_devSoundBufferSize; |
|
156 |
|
157 // Number of bytes transferred from QIODevice to QAudioOutput. It is |
|
158 // necessary to count this because data is dropped when suspend() is |
|
159 // called. The difference between the position reported by DevSound and |
|
160 // this value allows us to calculate m_bytesPadding; |
|
161 quint32 m_bytesWritten; |
|
162 |
|
163 // True if client has provided data while the audio subsystem was not |
|
164 // ready to consume it. |
|
165 bool m_pushDataReady; |
|
166 |
|
167 // Number of zero bytes which will be written when client calls resume(). |
|
168 quint32 m_bytesPadding; |
|
169 |
|
170 // True if PlayError(KErrUnderflow) has been called. |
|
171 bool m_underflow; |
|
172 |
|
173 // True if a buffer marked with the "last buffer" flag has been provided |
|
174 // to DevSound. |
|
175 bool m_lastBuffer; |
|
176 |
|
177 // Some DevSound implementations ignore all underflow errors raised by the |
|
178 // audio driver, unless the last buffer flag has been set by the client. |
|
179 // In push-mode playback, this flag will never be set, so the underflow |
|
180 // error will never be reported. In order to work around this, a timer |
|
181 // is used, which gets reset every time the client provides more data. If |
|
182 // the timer expires, an underflow error is raised by this object. |
|
183 QScopedPointer<QTimer> m_underflowTimer; |
|
184 |
|
185 // Result of previous call to CMMFDevSound::SamplesPlayed(). This value is |
|
186 // used to determine whether, when m_underflowTimer expires, an |
|
187 // underflow error has actually occurred. |
|
188 quint32 m_samplesPlayed; |
|
189 |
|
190 // Samples played up to the last call to suspend(). It is necessary |
|
191 // to cache this because suspend() is implemented using |
|
192 // CMMFDevSound::Stop(), which resets DevSound's SamplesPlayed() counter. |
|
193 quint32 m_totalSamplesPlayed; |
|
194 |
|
195 }; |
|
196 |
|
197 QT_END_NAMESPACE |
|
198 |
|
199 #endif |
|