|
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 Panic category and codes that CDevAudio raises on the client |
|
48 */ |
|
49 _LIT(KMMFDevAudioPanicCategory, "CDevAudio"); |
|
50 |
|
51 enum TMMFDevAudioPanicCodes |
|
52 { |
|
53 EValidStateBeforeCommit =1 |
|
54 }; |
|
55 |
|
56 enum TDevSoundAdaptorState |
|
57 { |
|
58 EDevSoundAdaptorCreated_Uninitialised, |
|
59 EDevSoundAdaptorRemovingProcessingUnits, |
|
60 EDevSoundAdaptorUnitialised_Uninitialised, |
|
61 EDevSoundAdaptorUninitialising, |
|
62 EDevSoundAdaptorInitialising, |
|
63 EDevSoundAdaptorInitialised_Initialised, |
|
64 EDevSoundAdaptorLoading, |
|
65 EDevSoundAdaptorUnloading, |
|
66 EDevSoundAdaptorInitialised_Idle, |
|
67 EDevSoundAdaptorGoingActive, |
|
68 EDevSoundAdaptorPreempted, |
|
69 EDevSoundAdaptorBeingPreempted, |
|
70 EDevSoundAdaptorStopping, |
|
71 EDevSoundAdaptorActivating, |
|
72 EDevSoundAdaptorActive_Active, |
|
73 EDevSoundAdaptorPausing, |
|
74 EDevSoundAdaptorPaused_Primed |
|
75 }; |
|
76 |
|
77 /** |
|
78 * CDevAudio. |
|
79 * |
|
80 * ?description |
|
81 * |
|
82 * @lib mmfdevsoundadaptation.lib |
|
83 * @since |
|
84 */ |
|
85 NONSHARABLE_CLASS(CDevAudio) : public CBase, |
|
86 public MAudioContextObserver, |
|
87 public MA3FDevSoundAdaptationInfoObserver, |
|
88 public MA3FDevSoundAutoPauseResumeObserver |
|
89 { |
|
90 friend class CDevAudioControl; |
|
91 friend class CDevPlayControl; |
|
92 friend class CDevRecordControl; |
|
93 friend class CDevToneControl; |
|
94 friend class CDevGenControl; |
|
95 friend class CDevCommonControl; |
|
96 |
|
97 public: |
|
98 |
|
99 ~CDevAudio(); |
|
100 |
|
101 static CDevAudio* NewL(MDevSoundAdaptationObserver& aDevSoundObserver, |
|
102 MGlobalProperties& aGlobalProperties); |
|
103 |
|
104 void ConstructL(MGlobalProperties& aGlobalProperties); |
|
105 |
|
106 // 2nd phase async construct - will callback to aDevSoundObserver |
|
107 TInt PostOpen(); |
|
108 |
|
109 /** |
|
110 * Sets control operating mode (playing/recording...) |
|
111 * @since |
|
112 * @param aMode new control mode |
|
113 * @param aFormat codec format |
|
114 * @return error code |
|
115 */ |
|
116 TInt Initialize(TUid aFormat, TMMFState aMode); |
|
117 |
|
118 /** |
|
119 * Cancels Initialization |
|
120 * @since |
|
121 * @return error code |
|
122 */ |
|
123 TInt CancelInitialize(); |
|
124 |
|
125 /** |
|
126 * Returns pointer to audio control instance for current operating mode |
|
127 * @since |
|
128 * @param aAudioControl on return, contains pointer to audio control |
|
129 * @return error code |
|
130 */ |
|
131 CDevAudioControl* GetAudioControl(); |
|
132 |
|
133 /** |
|
134 * Defines the priority settings that should be used for this instance. |
|
135 * @since |
|
136 * @param const TMMFPrioritySettings &aPrioritySettings A class type |
|
137 * representing the client's priority, priority preference and |
|
138 * state |
|
139 * @return Err |
|
140 */ |
|
141 TInt SetPrioritySettings(const TMMFPrioritySettings& aPrioritySettings); |
|
142 |
|
143 /** |
|
144 * Sets client configuration |
|
145 * @since |
|
146 * @param aProcessId DevSound's client process |
|
147 * @param aActualProcessId DevSound's effective/actual client (supplied by SetClientThreadInfo) |
|
148 */ |
|
149 TInt SetClientConfig(const TProcessId& aProcessId); |
|
150 TInt SetClientConfig(const TProcessId& aActualProcessId, const TProcessId& aProcessId); |
|
151 |
|
152 |
|
153 /** |
|
154 * Retrieve the current A3F state |
|
155 * @since |
|
156 * @return the current A3F state. See TAudioState |
|
157 */ |
|
158 TDevSoundAdaptorState ActiveState() const; |
|
159 |
|
160 /** |
|
161 * Retrieve the previous DevSound adaptor state |
|
162 * @return void |
|
163 */ |
|
164 TDevSoundAdaptorState PreviousState() const; |
|
165 |
|
166 /** |
|
167 * Set the current DevSound adaptor state |
|
168 * @return void |
|
169 */ |
|
170 void SetActiveState(TDevSoundAdaptorState aAdaptorState); |
|
171 |
|
172 /** |
|
173 * Set the previous DevSound adaptor state |
|
174 * @return void |
|
175 */ |
|
176 void SetPreviousState(TDevSoundAdaptorState aAdaptorState); |
|
177 |
|
178 /** |
|
179 * SetVolume for DevSound |
|
180 */ |
|
181 TInt SetDevSoundVolume(TInt aVolume, TBool& aAsyncCompletion); |
|
182 |
|
183 /** |
|
184 * SetGain for DevSound |
|
185 */ |
|
186 TInt SetDevSoundGain(TInt aGain, TBool& aAsyncCompletion); |
|
187 |
|
188 /** |
|
189 * SetPlayBalance for DevSound |
|
190 */ |
|
191 TInt SetDevSoundPlayBalance(TInt aLeftPercentage, TInt aRightPercentage, TBool& aAsyncCompletion); |
|
192 |
|
193 /** |
|
194 * SetPlayBalance for DevSound |
|
195 */ |
|
196 TInt SetDevSoundRecordBalance(TInt aLeftPercentage, TInt aRightPercentage, TBool& aAsyncCompletion); |
|
197 |
|
198 /** |
|
199 * SetVolumeRamp for DevSound |
|
200 */ |
|
201 TInt SetVolumeRamp(const TTimeIntervalMicroSeconds& aRampDuration); |
|
202 |
|
203 /** |
|
204 * MaxVolume for DevSound |
|
205 */ |
|
206 TInt DevSoundMaxVolume() const; |
|
207 /** |
|
208 * MaxGain for DevSound |
|
209 */ |
|
210 TInt DevSoundMaxGain() const; |
|
211 /** |
|
212 * Volume setting |
|
213 */ |
|
214 TInt DevSoundVolume() const; |
|
215 /** |
|
216 * Gain setting |
|
217 */ |
|
218 TInt DevSoundGain() const; |
|
219 |
|
220 /** |
|
221 * GetPlayBalance for DevSound |
|
222 */ |
|
223 void GetDevSoundPlayBalance(TInt& aLeftPercentage, TInt& aRightPercentage); |
|
224 |
|
225 /** |
|
226 * GetRecordBalance for DevSound |
|
227 */ |
|
228 void GetDevSoundRecordBalance(TInt& aLeftPercentage, TInt& aRightPercentage); |
|
229 |
|
230 /** |
|
231 * GetSupportedDataTypes for DevSound |
|
232 */ |
|
233 void DevSoundSupportedDataTypesL(RArray<TFourCC>& aSupportedDataTypes, TUint aDataType); |
|
234 |
|
235 /** |
|
236 * Call from control - generates appropriate SetGainAndBalance() call |
|
237 */ |
|
238 TInt RequestGainAndBalance(CDevAudioControl* aCallingControl); |
|
239 |
|
240 // From base class MAudioContextObserver |
|
241 /** |
|
242 * Callback to context observer to show progression through Commit() and pre-emption cycles |
|
243 * |
|
244 * @param aEvent a Uid giving the specific event. |
|
245 * @param aError an error code. KErrNone if successful, otherwise one of the system wide error codes. |
|
246 */ |
|
247 virtual void ContextEvent(TUid aEvent, TInt aError); |
|
248 |
|
249 // from MA3FDevSoundAdaptationInfoObserver |
|
250 void RequestMaxGainComplete (TUid aCodecType, TInt aError, TInt aResult); |
|
251 void RequestSupportedFormatsComplete(TUid aCodecType, TInt aError); |
|
252 |
|
253 /** |
|
254 * Queries if the low layers does support resume operation. |
|
255 * @since |
|
256 * @return TBool ETrue if Resume is supported |
|
257 * EFalse otherwise |
|
258 */ |
|
259 TBool IsResumeSupported(); |
|
260 |
|
261 void ConvertToFourCcL(RArray<TFourCC>& aSupportedDataTypes, RArray<TUid>& iSupportedFormats); |
|
262 |
|
263 //from MA3FDevSoundAutoPauseResume |
|
264 TInt RegisterAsClient(TUid aEventType, const TDesC8& aNotificationRegistrationData); |
|
265 TInt CancelRegisterAsClient(TUid aEventType); |
|
266 TInt WillResumePlay(); |
|
267 |
|
268 //from MA3FDevSoundAutoPauseResumeObserver |
|
269 virtual void NotifyResume(); |
|
270 |
|
271 /** |
|
272 * GetPrioritySettings for DevSound |
|
273 */ |
|
274 void GetPrioritySettings(TAudioTypeSettings& astorage); |
|
275 |
|
276 TBool IsPrioritySet(); |
|
277 |
|
278 //Panic function |
|
279 void Panic(TMMFDevAudioPanicCodes aCode); |
|
280 |
|
281 protected: |
|
282 |
|
283 CDevAudio(MDevSoundAdaptationObserver& aAdaptationObserver); |
|
284 |
|
285 // If active, apply devsound volume and balance changes |
|
286 TInt SetGainAndBalance(TBool aCallBack, TBool& aAsyncCompletion); |
|
287 |
|
288 // Helper methods |
|
289 TInt CreateAudioProcessingUnits(TUid aSource, TUid aSink, TUid aCodec); |
|
290 void DeleteAudioProcessingUnits(); |
|
291 |
|
292 TInt CommitAudioContext(); |
|
293 TBool IsMidState(TDevSoundAdaptorState aAdaptorState); |
|
294 |
|
295 /* |
|
296 * most of member data is protected for DevAudioControl access |
|
297 */ |
|
298 protected: // data |
|
299 |
|
300 /** |
|
301 * adaptation observer - used to indicate async callbacks etc |
|
302 */ |
|
303 MDevSoundAdaptationObserver& iAdaptationObserver; |
|
304 |
|
305 /** |
|
306 * Pointer to audio context factory - context creation |
|
307 * Own. |
|
308 */ |
|
309 CAudioContextFactory *iAudioContextFactory; |
|
310 |
|
311 /** |
|
312 * Pointer to audio context. |
|
313 * Not own. |
|
314 */ |
|
315 MAudioContext *iAudioContext; |
|
316 |
|
317 /** |
|
318 * Pointer to audio stream. |
|
319 * Not own. |
|
320 */ |
|
321 MAudioStream *iAudioStream; |
|
322 |
|
323 /** |
|
324 * Pointer to audio source. |
|
325 * Not own. |
|
326 */ |
|
327 MAudioProcessingUnit* iAudioSource; |
|
328 |
|
329 /** |
|
330 * Pointer to audio codec. |
|
331 * Not own. |
|
332 */ |
|
333 MAudioProcessingUnit* iAudioCodec; |
|
334 |
|
335 /** |
|
336 * Pointer to audio gain control |
|
337 * Not own. |
|
338 */ |
|
339 MAudioProcessingUnit* iGainControl; |
|
340 |
|
341 /** |
|
342 * Pointer to audio sink |
|
343 * Not own. |
|
344 */ |
|
345 MAudioProcessingUnit* iAudioSink; |
|
346 |
|
347 /** |
|
348 * Mode to which this DevAudio is initialized in |
|
349 */ |
|
350 TMMFState iMode; |
|
351 |
|
352 TUid iFormat; |
|
353 |
|
354 /** |
|
355 * Active DevSound Adaptor state |
|
356 */ |
|
357 TDevSoundAdaptorState iActiveState; |
|
358 |
|
359 /** |
|
360 * Previous DevSound Adaptor state |
|
361 */ |
|
362 TDevSoundAdaptorState iPreviousState; |
|
363 |
|
364 TAudioState iActiveStreamState; |
|
365 |
|
366 TBool iReinitializing; |
|
367 TBool iClosing; |
|
368 TBool iStop; |
|
369 TUid iTargetFormat; |
|
370 TMMFState iTargetMode; |
|
371 |
|
372 TInt iDevSoundMaxGain; |
|
373 TInt iDevSoundMaxVolume; |
|
374 TInt iDevSoundGain; |
|
375 TInt iDevSoundVolume; |
|
376 TInt iDevSoundPlayBalance[2]; |
|
377 TInt iDevSoundRecordBalance[2]; |
|
378 TTimeIntervalMicroSeconds iRampDuration; |
|
379 private: |
|
380 enum TPreOpenState |
|
381 { |
|
382 EPreOpenStateIdle, |
|
383 EPreOpenStateRequestingMaxVolume, |
|
384 EPreOpenStateRequestingMaxGain, |
|
385 EPreOpenStateRequestingInputFormats, |
|
386 EPreOpenStateRequestingOutputFormats, |
|
387 }; |
|
388 |
|
389 TPreOpenState iPreOpenState; |
|
390 |
|
391 RArray<TUid> iSupportedInputFormats; |
|
392 RArray<TUid> iSupportedOutputFormats; |
|
393 |
|
394 CA3FDevSoundAdaptationInfo* iAdaptationInfo; |
|
395 |
|
396 CDevPlayControl* iDevPlayControl; |
|
397 CDevRecordControl* iDevRecordControl; |
|
398 CDevToneControl* iDevToneControl; |
|
399 CDevGenControl* iDevGenControl; |
|
400 |
|
401 /** |
|
402 * Points to whichever control is active |
|
403 * Not own. |
|
404 */ |
|
405 CDevAudioControl* iCurrentAudioControl; |
|
406 |
|
407 // Pointer to global properties |
|
408 // Not owned. |
|
409 MGlobalProperties* iGlobalProperties; |
|
410 |
|
411 TAudioTypeSettings iPrioritySettings; |
|
412 TBool iPriorityFlag; |
|
413 |
|
414 }; |
|
415 |
|
416 inline TInt CDevAudio::DevSoundMaxVolume() const |
|
417 { |
|
418 return iDevSoundMaxVolume; |
|
419 } |
|
420 |
|
421 inline TInt CDevAudio::DevSoundMaxGain() const |
|
422 { |
|
423 return iDevSoundMaxGain; |
|
424 } |
|
425 |
|
426 inline TInt CDevAudio::DevSoundVolume() const |
|
427 { |
|
428 return iDevSoundVolume; |
|
429 } |
|
430 |
|
431 inline TInt CDevAudio::DevSoundGain() const |
|
432 { |
|
433 return iDevSoundGain; |
|
434 } |
|
435 |
|
436 #endif // CDEVAUDIO_H |