|
1 /* |
|
2 * Copyright (c) 2006-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
3 * All rights reserved. |
|
4 * This component and the accompanying materials are made available |
|
5 * under the terms of "Eclipse Public License v1.0" |
|
6 * which accompanies this distribution, and is available |
|
7 * at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
8 * |
|
9 * Initial Contributors: |
|
10 * Nokia Corporation - initial contribution. |
|
11 * |
|
12 * Contributors: |
|
13 * |
|
14 * Description: |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 |
|
20 #ifndef CDEVAUDIO_H |
|
21 #define CDEVAUDIO_H |
|
22 |
|
23 #include <e32base.h> |
|
24 |
|
25 #include "mmfdevsoundadaptationbody.h" |
|
26 #include <a3f/maudiocontextobserver.h> |
|
27 #include <a3f/maudiostreamobserver.h> |
|
28 #include "mdevsoundadaptationinfoobserver.h" |
|
29 |
|
30 #include <a3f/a3f_trace_utils.h> |
|
31 #include <a3f/a3fdevsoundaudiopauseresume.h> |
|
32 |
|
33 |
|
34 // CLASS FORWARD |
|
35 class CDevAudioControl; |
|
36 class CDevPlayControl; |
|
37 class CDevRecordControl; |
|
38 class CDevToneControl; |
|
39 class CDevGenControl; |
|
40 class CAudioContextFactory; |
|
41 class CA3FDevSoundAdaptationInfo; |
|
42 class MAudioContext; |
|
43 class MAudioStream; |
|
44 class MGlobalProperties; |
|
45 |
|
46 |
|
47 enum TDevSoundAdaptorState |
|
48 { |
|
49 EDevSoundAdaptorCreated_Uninitialised, |
|
50 EDevSoundAdaptorRemovingProcessingUnits, |
|
51 EDevSoundAdaptorUnitialised_Uninitialised, |
|
52 EDevSoundAdaptorUninitialising, |
|
53 EDevSoundAdaptorInitialising, |
|
54 EDevSoundAdaptorInitialised_Initialised, |
|
55 EDevSoundAdaptorLoading, |
|
56 EDevSoundAdaptorUnloading, |
|
57 EDevSoundAdaptorInitialised_Idle, |
|
58 EDevSoundAdaptorGoingActive, |
|
59 EDevSoundAdaptorPreempted, |
|
60 EDevSoundAdaptorBeingPreempted, |
|
61 EDevSoundAdaptorStopping, |
|
62 EDevSoundAdaptorActivating, |
|
63 EDevSoundAdaptorActive_Active, |
|
64 EDevSoundAdaptorPausing, |
|
65 EDevSoundAdaptorPaused_Primed |
|
66 }; |
|
67 |
|
68 /** |
|
69 * CDevAudio. |
|
70 * |
|
71 * ?description |
|
72 * |
|
73 * @lib mmfdevsoundadaptation.lib |
|
74 * @since |
|
75 */ |
|
76 NONSHARABLE_CLASS(CDevAudio) : public CBase, |
|
77 public MAudioContextObserver, |
|
78 public MA3FDevSoundAdaptationInfoObserver, |
|
79 public MA3FDevSoundAutoPauseResumeObserver |
|
80 { |
|
81 friend class CDevAudioControl; |
|
82 friend class CDevPlayControl; |
|
83 friend class CDevRecordControl; |
|
84 friend class CDevToneControl; |
|
85 friend class CDevGenControl; |
|
86 friend class CDevCommonControl; |
|
87 |
|
88 public: |
|
89 |
|
90 ~CDevAudio(); |
|
91 |
|
92 static CDevAudio* NewL(MDevSoundAdaptationObserver& aDevSoundObserver, |
|
93 MGlobalProperties& aGlobalProperties); |
|
94 |
|
95 void ConstructL(MGlobalProperties& aGlobalProperties); |
|
96 |
|
97 // 2nd phase async construct - will callback to aDevSoundObserver |
|
98 TInt PostOpen(); |
|
99 |
|
100 /** |
|
101 * Sets control operating mode (playing/recording...) |
|
102 * @since |
|
103 * @param aMode new control mode |
|
104 * @param aFormat codec format |
|
105 * @return error code |
|
106 */ |
|
107 TInt Initialize(TUid aFormat, TMMFState aMode); |
|
108 |
|
109 /** |
|
110 * Cancels Initialization |
|
111 * @since |
|
112 * @return error code |
|
113 */ |
|
114 TInt CancelInitialize(); |
|
115 |
|
116 /** |
|
117 * Returns pointer to audio control instance for current operating mode |
|
118 * @since |
|
119 * @param aAudioControl on return, contains pointer to audio control |
|
120 * @return error code |
|
121 */ |
|
122 CDevAudioControl* GetAudioControl(); |
|
123 |
|
124 /** |
|
125 * Defines the priority settings that should be used for this instance. |
|
126 * @since |
|
127 * @param const TMMFPrioritySettings &aPrioritySettings A class type |
|
128 * representing the client's priority, priority preference and |
|
129 * state |
|
130 * @return Err |
|
131 */ |
|
132 TInt SetPrioritySettings(const TMMFPrioritySettings& aPrioritySettings); |
|
133 |
|
134 /** |
|
135 * Sets client configuration |
|
136 * @since |
|
137 * @param TMMFClientConfig& aClientConfig A reference to client |
|
138 * configuration object. |
|
139 */ |
|
140 TInt SetClientConfig(const TMMFClientConfig& aClientConfig); |
|
141 |
|
142 |
|
143 /** |
|
144 * Retrieve the current A3F state |
|
145 * @since |
|
146 * @return the current A3F state. See TAudioState |
|
147 */ |
|
148 TDevSoundAdaptorState ActiveState() const; |
|
149 |
|
150 /** |
|
151 * SetVolume for DevSound |
|
152 */ |
|
153 TInt SetDevSoundVolume(TInt aVolume, TBool& aAsyncCompletion); |
|
154 |
|
155 /** |
|
156 * SetGain for DevSound |
|
157 */ |
|
158 TInt SetDevSoundGain(TInt aGain, TBool& aAsyncCompletion); |
|
159 |
|
160 /** |
|
161 * SetPlayBalance for DevSound |
|
162 */ |
|
163 TInt SetDevSoundPlayBalance(TInt aLeftPercentage, TInt aRightPercentage, TBool& aAsyncCompletion); |
|
164 |
|
165 /** |
|
166 * SetPlayBalance for DevSound |
|
167 */ |
|
168 TInt SetDevSoundRecordBalance(TInt aLeftPercentage, TInt aRightPercentage, TBool& aAsyncCompletion); |
|
169 |
|
170 /** |
|
171 * SetVolumeRamp for DevSound |
|
172 */ |
|
173 TInt SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration); |
|
174 |
|
175 /** |
|
176 * MaxVolume for DevSound |
|
177 */ |
|
178 TInt DevSoundMaxVolume() const; |
|
179 /** |
|
180 * MaxGain for DevSound |
|
181 */ |
|
182 TInt DevSoundMaxGain() const; |
|
183 /** |
|
184 * Volume setting |
|
185 */ |
|
186 TInt DevSoundVolume() const; |
|
187 /** |
|
188 * Gain setting |
|
189 */ |
|
190 TInt DevSoundGain() const; |
|
191 |
|
192 /** |
|
193 * GetPlayBalance for DevSound |
|
194 */ |
|
195 void GetDevSoundPlayBalance(TInt& aLeftPercentage, TInt& aRightPercentage); |
|
196 |
|
197 /** |
|
198 * GetRecordBalance for DevSound |
|
199 */ |
|
200 void GetDevSoundRecordBalance(TInt& aLeftPercentage, TInt& aRightPercentage); |
|
201 |
|
202 /** |
|
203 * GetSupportedDataTypes for DevSound |
|
204 */ |
|
205 void DevSoundSupportedDataTypesL(RArray<TFourCC>& aSupportedDataTypes, TUint aDataType); |
|
206 |
|
207 /** |
|
208 * Call from control - generates appropriate SetGainAndBalance() call |
|
209 */ |
|
210 TInt RequestGainAndBalance(CDevAudioControl* aCallingControl); |
|
211 |
|
212 // From base class MAudioContextObserver |
|
213 /** |
|
214 * Callback to context observer to show progression through Commit() and pre-emption cycles |
|
215 * |
|
216 * @param aEvent a Uid giving the specific event. |
|
217 * @param aError an error code. KErrNone if successful, otherwise one of the system wide error codes. |
|
218 */ |
|
219 virtual void ContextEvent(TUid aEvent, TInt aError); |
|
220 |
|
221 // from MA3FDevSoundAdaptationInfoObserver |
|
222 void RequestMaxGainComplete (TUid aCodecType, TInt aError, TInt aResult); |
|
223 void RequestSupportedFormatsComplete(TUid aCodecType, TInt aError); |
|
224 |
|
225 /** |
|
226 * Queries if the low layers does support resume operation. |
|
227 * @since |
|
228 * @return TBool ETrue if Resume is supported |
|
229 * EFalse otherwise |
|
230 */ |
|
231 TBool IsResumeSupported(); |
|
232 |
|
233 void ConvertToFourCcL(RArray<TFourCC>& aSupportedDataTypes, RArray<TUid>& iSupportedFormats); |
|
234 |
|
235 //from MA3FDevSoundAutoPauseResume |
|
236 TInt RegisterAsClient(TUid aEventType, const TDesC8& aNotificationRegistrationData); |
|
237 TInt CancelRegisterAsClient(TUid aEventType); |
|
238 TInt WillResumePlay(); |
|
239 |
|
240 //from MA3FDevSoundAutoPauseResumeObserver |
|
241 virtual void NotifyResume(); |
|
242 |
|
243 /** |
|
244 * GetPrioritySettings for DevSound |
|
245 */ |
|
246 void GetPrioritySettings(TAudioTypeSettings& astorage); |
|
247 |
|
248 TBool IsPrioritySet(); |
|
249 |
|
250 protected: |
|
251 |
|
252 CDevAudio(MDevSoundAdaptationObserver& aAdaptationObserver); |
|
253 |
|
254 // If active, apply devsound volume and balance changes |
|
255 TInt SetGainAndBalance(TBool aCallBack, TBool& aAsyncCompletion); |
|
256 |
|
257 // Helper methods |
|
258 TInt CreateAudioProcessingUnits(TUid aSource, TUid aSink, TUid aCodec); |
|
259 void DeleteAudioProcessingUnits(); |
|
260 |
|
261 /* |
|
262 * most of member data is protected for DevAudioControl access |
|
263 */ |
|
264 protected: // data |
|
265 |
|
266 /** |
|
267 * adaptation observer - used to indicate async callbacks etc |
|
268 */ |
|
269 MDevSoundAdaptationObserver& iAdaptationObserver; |
|
270 |
|
271 /** |
|
272 * Pointer to audio context factory - context creation |
|
273 * Own. |
|
274 */ |
|
275 CAudioContextFactory *iAudioContextFactory; |
|
276 |
|
277 /** |
|
278 * Pointer to audio context. |
|
279 * Not own. |
|
280 */ |
|
281 MAudioContext *iAudioContext; |
|
282 |
|
283 /** |
|
284 * Pointer to audio stream. |
|
285 * Not own. |
|
286 */ |
|
287 MAudioStream *iAudioStream; |
|
288 |
|
289 /** |
|
290 * Pointer to audio source. |
|
291 * Not own. |
|
292 */ |
|
293 MAudioProcessingUnit* iAudioSource; |
|
294 |
|
295 /** |
|
296 * Pointer to audio codec. |
|
297 * Not own. |
|
298 */ |
|
299 MAudioProcessingUnit* iAudioCodec; |
|
300 |
|
301 /** |
|
302 * Pointer to audio gain control |
|
303 * Not own. |
|
304 */ |
|
305 MAudioProcessingUnit* iGainControl; |
|
306 |
|
307 /** |
|
308 * Pointer to audio sink |
|
309 * Not own. |
|
310 */ |
|
311 MAudioProcessingUnit* iAudioSink; |
|
312 |
|
313 /** |
|
314 * Mode to which this DevAudio is initialized in |
|
315 */ |
|
316 TMMFState iMode; |
|
317 |
|
318 TUid iFormat; |
|
319 |
|
320 /** |
|
321 * Active DevSound Adaptor state |
|
322 */ |
|
323 TDevSoundAdaptorState iActiveState; |
|
324 |
|
325 TAudioState iActiveStreamState; |
|
326 |
|
327 TBool iReinitializing; |
|
328 TBool iClosing; |
|
329 TBool iStop; |
|
330 TUid iTargetFormat; |
|
331 TMMFState iTargetMode; |
|
332 |
|
333 TInt iDevSoundMaxGain; |
|
334 TInt iDevSoundMaxVolume; |
|
335 TInt iDevSoundGain; |
|
336 TInt iDevSoundVolume; |
|
337 TInt iDevSoundPlayBalance[2]; |
|
338 TInt iDevSoundRecordBalance[2]; |
|
339 TTimeIntervalMicroSeconds iRampDuration; |
|
340 private: |
|
341 enum TPreOpenState |
|
342 { |
|
343 EPreOpenStateIdle, |
|
344 EPreOpenStateRequestingMaxVolume, |
|
345 EPreOpenStateRequestingMaxGain, |
|
346 EPreOpenStateRequestingInputFormats, |
|
347 EPreOpenStateRequestingOutputFormats, |
|
348 }; |
|
349 |
|
350 TPreOpenState iPreOpenState; |
|
351 |
|
352 RArray<TUid> iSupportedInputFormats; |
|
353 RArray<TUid> iSupportedOutputFormats; |
|
354 |
|
355 CA3FDevSoundAdaptationInfo* iAdaptationInfo; |
|
356 |
|
357 CDevPlayControl* iDevPlayControl; |
|
358 CDevRecordControl* iDevRecordControl; |
|
359 CDevToneControl* iDevToneControl; |
|
360 CDevGenControl* iDevGenControl; |
|
361 |
|
362 /** |
|
363 * Points to whichever control is active |
|
364 * Not own. |
|
365 */ |
|
366 CDevAudioControl* iCurrentAudioControl; |
|
367 |
|
368 // Pointer to global properties |
|
369 // Not owned. |
|
370 MGlobalProperties* iGlobalProperties; |
|
371 |
|
372 TAudioTypeSettings iPrioritySettings; |
|
373 TBool iPriorityFlag; |
|
374 |
|
375 }; |
|
376 |
|
377 inline TInt CDevAudio::DevSoundMaxVolume() const |
|
378 { |
|
379 return iDevSoundMaxVolume; |
|
380 } |
|
381 |
|
382 inline TInt CDevAudio::DevSoundMaxGain() const |
|
383 { |
|
384 return iDevSoundMaxGain; |
|
385 } |
|
386 |
|
387 inline TInt CDevAudio::DevSoundVolume() const |
|
388 { |
|
389 return iDevSoundVolume; |
|
390 } |
|
391 |
|
392 inline TInt CDevAudio::DevSoundGain() const |
|
393 { |
|
394 return iDevSoundGain; |
|
395 } |
|
396 |
|
397 #endif // CDEVAUDIO_H |