|
1 /* |
|
2 * Copyright (c) 2006 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: Project file for EnhancedMediaClient Utility |
|
15 * |
|
16 */ |
|
17 |
|
18 |
|
19 #include "SourceOrientationEffectImpl.h" |
|
20 #include <SourceOrientationBase.h> |
|
21 #include <ControlObserver.h> |
|
22 |
|
23 using namespace multimedia; |
|
24 |
|
25 CSourceOrientationEffect::CSourceOrientationEffect() |
|
26 { |
|
27 // No Impl |
|
28 } |
|
29 |
|
30 CSourceOrientationEffect::~CSourceOrientationEffect() |
|
31 { |
|
32 delete iPrevSourceOrientationProxy; |
|
33 delete iSourceOrientationProxy; |
|
34 iObservers.Close(); |
|
35 } |
|
36 |
|
37 TInt CSourceOrientationEffect::PostConstructor() |
|
38 { |
|
39 TRAPD( status, CEffectControlBase::ConstructL(KUidSourceOrientationEffect) ); |
|
40 return status; |
|
41 } |
|
42 |
|
43 // From MControl begins |
|
44 TInt CSourceOrientationEffect::AddObserver( MControlObserver& aObserver ) |
|
45 { |
|
46 return iObservers.Append(&aObserver); |
|
47 } |
|
48 |
|
49 TInt CSourceOrientationEffect::RemoveObserver( MControlObserver& aObserver ) |
|
50 { |
|
51 TInt index = iObservers.Find(&aObserver); |
|
52 if( index != KErrNotFound ) |
|
53 { |
|
54 iObservers.Remove(index); |
|
55 } |
|
56 return index; |
|
57 } |
|
58 |
|
59 TUid CSourceOrientationEffect::Type() |
|
60 { |
|
61 return KSourceOrientationEffectControl; |
|
62 } |
|
63 |
|
64 TControlType CSourceOrientationEffect::ControlType() |
|
65 { |
|
66 return EEffectControl; |
|
67 } |
|
68 |
|
69 // From MControl ends |
|
70 |
|
71 // From MEffectControl begins |
|
72 TInt CSourceOrientationEffect::Apply() |
|
73 { |
|
74 return DoApply(); |
|
75 } |
|
76 |
|
77 // From MEffectControl ends |
|
78 |
|
79 TInt CSourceOrientationEffect::DoApply() |
|
80 { |
|
81 TInt error(KErrNone); |
|
82 if(iSourceOrientationProxy) |
|
83 { |
|
84 TRAP(error,iSourceOrientationProxy->ApplyL()); |
|
85 } |
|
86 else |
|
87 { |
|
88 error = KErrNotReady; |
|
89 } |
|
90 return error; |
|
91 } |
|
92 |
|
93 // From MSourceOrientationEffect begins |
|
94 /** |
|
95 * Get the orientation vectors for the position |
|
96 * @since 5.0 |
|
97 * @param aHeading The heading (thousandths of radians) |
|
98 * @param aPitch The Pitch (thousandths of radians) |
|
99 * @param aRoll The Roll (thousandths of radians) |
|
100 * @return - |
|
101 */ |
|
102 TInt CSourceOrientationEffect::Orientation( TInt& aHeading, TInt& aPitch, TInt& aRoll ) |
|
103 { |
|
104 TInt status(KErrNone); |
|
105 if(iSourceOrientationProxy) |
|
106 { |
|
107 TInt32 heading,pitch,roll; |
|
108 iSourceOrientationProxy->Orientation(heading,pitch,roll); |
|
109 aHeading = heading; |
|
110 aPitch = pitch; |
|
111 aRoll = roll; |
|
112 } |
|
113 else |
|
114 { |
|
115 status = KErrNotReady; |
|
116 } |
|
117 return status; |
|
118 } |
|
119 |
|
120 /** |
|
121 * Gets the orientation of the position. |
|
122 * @since 5.0 |
|
123 * @param aFrontX X value of Front vector |
|
124 * @param aFrontY Y value of Front vector |
|
125 * @param aFrontZ Z value of Front vector |
|
126 * @param aAboveX X value of Above vector |
|
127 * @param aAboveY Y value of Above vector |
|
128 * @param aAboveZ Z value of Above vector |
|
129 * @return - |
|
130 */ |
|
131 TInt CSourceOrientationEffect::OrientationVectors( TInt& aFrontX, TInt& aFrontY, TInt& aFrontZ, |
|
132 TInt& aAboveX, TInt& aAboveY, TInt& aAboveZ ) |
|
133 { |
|
134 TInt status(KErrNone); |
|
135 if(iSourceOrientationProxy) |
|
136 { |
|
137 TInt32 frontx; |
|
138 TInt32 fronty; |
|
139 TInt32 frontz; |
|
140 TInt32 abovex; |
|
141 TInt32 abovey; |
|
142 TInt32 abovez; |
|
143 |
|
144 iSourceOrientationProxy->OrientationVectors(frontx,fronty,frontz,abovex,abovey,abovez); |
|
145 aFrontX = frontx; |
|
146 aFrontY = fronty; |
|
147 aFrontZ = frontz; |
|
148 aAboveX = abovex;; |
|
149 aAboveY = abovey;; |
|
150 aAboveZ = abovez;; |
|
151 } |
|
152 else |
|
153 { |
|
154 status = KErrNotReady; |
|
155 } |
|
156 return status; |
|
157 } |
|
158 |
|
159 /** |
|
160 * Sets the Heading, Pitch, Roll values for the orientation of the source |
|
161 * @since 5.0 |
|
162 * @param aHeading The heading (thousandths of radians) |
|
163 * @param aPitch The Pitch (thousandths of radians) |
|
164 * @param aRoll The Roll (thousandths of radians) |
|
165 * @return - |
|
166 */ |
|
167 TInt CSourceOrientationEffect::SetOrientation( TInt aHeading, TInt aPitch, TInt aRoll ) |
|
168 { |
|
169 TInt status(KErrNone); |
|
170 if(iSourceOrientationProxy) |
|
171 { |
|
172 TInt32 heading = aHeading; |
|
173 TInt32 pitch = aPitch; |
|
174 TInt32 roll = aRoll; |
|
175 TRAP(status,iSourceOrientationProxy->SetOrientationL(heading,pitch,roll)); |
|
176 } |
|
177 else |
|
178 { |
|
179 status = KErrNotReady; |
|
180 } |
|
181 return status; |
|
182 } |
|
183 /** |
|
184 * Sets the Front and Above vectors for the orientation of the position. |
|
185 * @since 5.0 |
|
186 * @param aFrontX X value of Front vector |
|
187 * @param aFrontY Y value of Front vector |
|
188 * @param aFrontZ Z value of Front vector |
|
189 * @param aAboveX X value of Above vector |
|
190 * @param aAboveY Y value of Above vector |
|
191 * @param aAboveZ Z value of Above vector |
|
192 * @return - |
|
193 */ |
|
194 TInt CSourceOrientationEffect::SetOrientationVectors( TInt aFrontX, TInt aFrontY, TInt aFrontZ, |
|
195 TInt aAboveX, TInt aAboveY, TInt aAboveZ ) |
|
196 { |
|
197 TInt status(KErrNone); |
|
198 if(iSourceOrientationProxy) |
|
199 { |
|
200 TInt32 frontx = aFrontX; |
|
201 TInt32 fronty = aFrontY; |
|
202 TInt32 frontz = aFrontZ; |
|
203 TInt32 abovex = aAboveX; |
|
204 TInt32 abovey = aAboveY; |
|
205 TInt32 abovez = aAboveZ; |
|
206 TRAP(status,iSourceOrientationProxy->SetOrientationVectorsL(frontx,fronty,frontz,abovex,abovey,abovez)); |
|
207 } |
|
208 else |
|
209 { |
|
210 status = KErrNotReady; |
|
211 } |
|
212 return status; |
|
213 } |
|
214 |
|
215 // From MSourceOrientationEffect ends |
|
216 |
|
217 // From MAudioEffectControl |
|
218 /** |
|
219 * Disable the effect |
|
220 * @since 5.0 |
|
221 */ |
|
222 TInt CSourceOrientationEffect::Disable() |
|
223 { |
|
224 TInt status(KErrNone); |
|
225 if(iSourceOrientationProxy) |
|
226 { |
|
227 TRAP(status,iSourceOrientationProxy->DisableL()); |
|
228 } |
|
229 else |
|
230 { |
|
231 status = KErrNotReady; |
|
232 } |
|
233 return status; |
|
234 } |
|
235 |
|
236 /** |
|
237 * Enable the effect |
|
238 * @since 5.0 |
|
239 */ |
|
240 TInt CSourceOrientationEffect::Enable() |
|
241 { |
|
242 TInt status(KErrNone); |
|
243 RDebug::Print(_L("CSourceOrientationEffect::Enable() [%x]"),iSourceOrientationProxy); |
|
244 if(iSourceOrientationProxy) |
|
245 { |
|
246 TRAP(status,iSourceOrientationProxy->EnableL()); |
|
247 } |
|
248 else |
|
249 { |
|
250 status = KErrNotReady; |
|
251 } |
|
252 return status; |
|
253 } |
|
254 |
|
255 /** |
|
256 * Enforce the effect. |
|
257 * @since 5.0 |
|
258 * @param aEnforced Indicate the effect is to be enforced or not. ETrue = Enforced. |
|
259 */ |
|
260 TInt CSourceOrientationEffect::Enforce( TBool &aEnforced ) |
|
261 { |
|
262 TInt status(KErrNone); |
|
263 if(iSourceOrientationProxy) |
|
264 { |
|
265 TRAP(status,iSourceOrientationProxy->EnforceL(aEnforced)); |
|
266 } |
|
267 else |
|
268 { |
|
269 status = KErrNotReady; |
|
270 } |
|
271 return status; |
|
272 } |
|
273 |
|
274 /** |
|
275 * Check if this effect object currently has update rights. |
|
276 * A client can lose update rights in some hardware platforms where there are a limited |
|
277 * number of instances of an effect that can exist at the same time. When an effect instance |
|
278 * has lost update rights the user can still change settings, but any calls to Apply the |
|
279 * settings will be deferred until update rights are regained. |
|
280 * @since 5.0 |
|
281 * @return ETrue if this object currently has rights to update the settings of this effect, |
|
282 * EFalse otherwise. |
|
283 */ |
|
284 TInt CSourceOrientationEffect::HaveUpdateRights(TBool &aHaveUpdateRights) |
|
285 { |
|
286 TInt status(KErrNone); |
|
287 if(iSourceOrientationProxy) |
|
288 { |
|
289 aHaveUpdateRights = iSourceOrientationProxy->HaveUpdateRights(); |
|
290 } |
|
291 else |
|
292 { |
|
293 status = KErrNotReady; |
|
294 } |
|
295 return status; |
|
296 } |
|
297 |
|
298 /** |
|
299 * Check if the effect is enabled |
|
300 * @since 5.0 |
|
301 * @return ETrue if the effect is enabled, EFalse if the effect is disabled. |
|
302 */ |
|
303 TInt CSourceOrientationEffect::IsEnabled(TBool &aEnabled) |
|
304 { |
|
305 TInt status(KErrNone); |
|
306 if(iSourceOrientationProxy) |
|
307 { |
|
308 aEnabled = iSourceOrientationProxy->IsEnabled(); |
|
309 } |
|
310 else |
|
311 { |
|
312 status = KErrNotReady; |
|
313 } |
|
314 return status; |
|
315 } |
|
316 |
|
317 /** |
|
318 * Check if the effect is enforced. |
|
319 * @since 5.0 |
|
320 * @return ETrue if the effect is enforced, EFalse if the effect isn ot enforced. |
|
321 */ |
|
322 TInt CSourceOrientationEffect::IsEnforced(TBool &aEnforced) |
|
323 { |
|
324 TInt status(KErrNone); |
|
325 if(iSourceOrientationProxy) |
|
326 { |
|
327 aEnforced = iSourceOrientationProxy->IsEnforced(); |
|
328 } |
|
329 else |
|
330 { |
|
331 status = KErrNotReady; |
|
332 } |
|
333 return status; |
|
334 } |
|
335 |
|
336 /* |
|
337 * Get the unique identifier of the audio effect |
|
338 * @since 5.0 |
|
339 * @return Unique identifier of the audio effect object. |
|
340 */ |
|
341 TInt CSourceOrientationEffect::Uid(TUid &aUid) |
|
342 { |
|
343 TInt status(KErrNone); |
|
344 if(iSourceOrientationProxy) |
|
345 { |
|
346 aUid = iSourceOrientationProxy->Uid(); |
|
347 } |
|
348 else |
|
349 { |
|
350 status = KErrNotReady; |
|
351 } |
|
352 return status; |
|
353 } |
|
354 // From MAudioEffectControl Ends |
|
355 |
|
356 |
|
357 // From CEffectControlBase begins |
|
358 void CSourceOrientationEffect::Event( TEffectControlEvent aEvent ) |
|
359 { |
|
360 TInt status(KErrNone); |
|
361 // Controller Loaded with ECIBuilderCreated |
|
362 if ( aEvent == ECIBuilderCreated ) |
|
363 { |
|
364 RDebug::Print(_L("Deleting Proxy")); |
|
365 status = DeleteEffectProxy(); |
|
366 RDebug::Print(_L("Deleting Proxy [%d]"),status); |
|
367 status = CreateEffectProxy(); |
|
368 RDebug::Print(_L("Creating Proxy [%d]"),status); |
|
369 if(status == KErrNone) |
|
370 { |
|
371 SavePreviousSettings(); |
|
372 } |
|
373 else |
|
374 { |
|
375 for ( TInt i = 0; i < iObservers.Count(); i++ ) |
|
376 { |
|
377 iObservers[i]->Event(this,MAudioEffectControl::KDisabled,NULL); |
|
378 } |
|
379 } |
|
380 } |
|
381 else if ( aEvent == EMessageHandlerDeleted ) |
|
382 { |
|
383 if(status == KErrNone) |
|
384 { |
|
385 DeleteEffectProxy(); |
|
386 } |
|
387 } |
|
388 } |
|
389 |
|
390 // From CEffectControlBase ends |
|
391 |
|
392 TInt CSourceOrientationEffect::CreateEffectProxy() |
|
393 { |
|
394 TInt status(KErrNone); |
|
395 status = GetMessageHandle(iMsgHndlrHandlePckg); |
|
396 if(status != KErrNone) |
|
397 { |
|
398 return status; |
|
399 } |
|
400 iCustomCommand = GetCustomCommand(); |
|
401 if(!iCustomCommand) |
|
402 { |
|
403 return KErrNotReady; |
|
404 } |
|
405 |
|
406 TRAP(status,iSourceOrientationProxy = CSourceOrientationProxy::NewL(iMsgHndlrHandlePckg, *iCustomCommand, NULL)); |
|
407 if(status == KErrNone) |
|
408 { |
|
409 TRAP(status,iSourceOrientationProxy->RegisterObserverL(*this)); |
|
410 } |
|
411 |
|
412 return status; |
|
413 } |
|
414 |
|
415 TInt CSourceOrientationEffect::DeleteEffectProxy() |
|
416 { |
|
417 TInt status(KErrNone); |
|
418 if(iSourceOrientationProxy) |
|
419 { |
|
420 iPrevSourceOrientationProxy = iSourceOrientationProxy; |
|
421 } |
|
422 iSourceOrientationProxy = NULL; |
|
423 return status; |
|
424 } |
|
425 |
|
426 TInt CSourceOrientationEffect::SavePreviousSettings() |
|
427 { |
|
428 TInt status(KErrNone); |
|
429 if(iPrevSourceOrientationProxy) |
|
430 { |
|
431 TBool enforce = iPrevSourceOrientationProxy->IsEnforced(); |
|
432 iSourceOrientationProxy->EnforceL(enforce); |
|
433 |
|
434 TBool enable = iPrevSourceOrientationProxy->IsEnabled(); |
|
435 if(enable) |
|
436 { |
|
437 iSourceOrientationProxy->EnableL(); |
|
438 } |
|
439 |
|
440 delete iPrevSourceOrientationProxy; |
|
441 iPrevSourceOrientationProxy = NULL; |
|
442 } |
|
443 return status; |
|
444 } |
|
445 |
|
446 void CSourceOrientationEffect::EffectChanged( const CAudioEffect* /*aObservedEffect*/, TUint8 aEvent ) |
|
447 { |
|
448 for ( TInt i = 0; i < iObservers.Count(); i++ ) |
|
449 { |
|
450 iObservers[i]->Event(this,aEvent,NULL); |
|
451 } |
|
452 } |
|
453 |
|
454 // End of file |