17 |
17 |
18 // INCLUDE FILES |
18 // INCLUDE FILES |
19 #include <AudioPreference.h> |
19 #include <AudioPreference.h> |
20 #include <jdebug.h> |
20 #include <jdebug.h> |
21 #include "cammsaudiooutputcontrol.h" |
21 #include "cammsaudiooutputcontrol.h" |
|
22 #include "cmmavolumecontrol.h" |
22 #include <cmmaplayerevent.h> |
23 #include <cmmaplayerevent.h> |
23 #include <cmmaaudioplayer.h> |
24 #include <cmmaaudioplayer.h> |
24 #include <cmmavideoplayer.h> |
25 #include <cmmavideoplayer.h> |
25 #include <mmfcontroller.h> |
26 #include <mmfcontroller.h> |
26 #include <midiclientutility.h> |
27 #include <midiclientutility.h> |
187 // Gets the current device preference used as default |
187 // Gets the current device preference used as default |
188 // ---------------------------------------------------------------------------------------- |
188 // ---------------------------------------------------------------------------------------- |
189 TInt CAMMSAudioOutputControl::GetDeviceDefaultPreference() |
189 TInt CAMMSAudioOutputControl::GetDeviceDefaultPreference() |
190 { |
190 { |
191 DEBUG_INT("AMMS::CAMMSAudioOutputControl::GetDeviceDefaultPreference %d", (TInt)iDefaultDevicePreference); |
191 DEBUG_INT("AMMS::CAMMSAudioOutputControl::GetDeviceDefaultPreference %d", (TInt)iDefaultDevicePreference); |
192 array.Reset(); |
192 iArray.Reset(); |
193 TInt temp = 0; |
193 TInt temp = 0; |
194 TRAPD(err,iAccMonitor->GetConnectedAccessoriesL(array)); |
194 TRAPD(err,iAccMonitor->GetConnectedAccessoriesL(iArray)); |
195 if (err) |
195 if (err) |
196 { |
196 { |
197 temp = -1; |
197 temp = -1; |
198 } |
198 } |
199 TInt count = array.Count(); |
199 TInt count = iArray.Count(); |
200 if (count == 0) |
200 if (count == 0) |
201 { |
201 { |
202 temp = (TInt)CAudioOutput::EPublic; |
202 temp = (TInt)CAudioOutput::EPublic; |
203 } |
203 } |
204 DEBUG_INT("AMMS::CAMMSAudioOutputControl::GetDeviceDefaultPreference :RConnectedAccessories count = %d",count); |
204 DEBUG_INT("AMMS::CAMMSAudioOutputControl::GetDeviceDefaultPreference :RConnectedAccessories count = %d",count); |
205 for (TInt i = 0; i != count; i++) |
205 for (TInt i = 0; i != count; i++) |
206 { |
206 { |
207 TAccMonCapability deviceType = array[ i ]->AccDeviceType(); |
207 TAccMonCapability deviceType = iArray[ i ]->AccDeviceType(); |
208 if ((deviceType == KAccMonHeadset)||(deviceType == KAccMonBluetooth)) |
208 if (deviceType == KAccMonHeadset) |
209 { |
209 { |
210 DEBUG("AMMS::CAMMSAudioOutputControl::CreateHeadsetStateObserverL info = Headset Connected "); |
210 DEBUG("AMMS::CAMMSAudioOutputControl::CreateHeadsetStateObserverL info = Headset Connected "); |
211 temp = (TInt)CAudioOutput::EPrivate; |
211 temp = (TInt)CAudioOutput::EPrivate; |
212 break; |
212 break; |
213 } |
213 } |
220 // Called when player state is changed. |
220 // Called when player state is changed. |
221 // ----------------------------------------------------------------------------- |
221 // ----------------------------------------------------------------------------- |
222 void CAMMSAudioOutputControl::StateChanged(TInt aState) |
222 void CAMMSAudioOutputControl::StateChanged(TInt aState) |
223 { |
223 { |
224 DEBUG_INT("AMMS::CAMMSAudioOutputControl::StateChanged +, state = %d", aState); |
224 DEBUG_INT("AMMS::CAMMSAudioOutputControl::StateChanged +, state = %d", aState); |
225 playerState = (CMMAPlayer::TPlayerState)aState; |
225 iPlayerState = (CMMAPlayer::TPlayerState)aState; |
226 if (aState == CMMAPlayer::EStarted) |
226 if (aState == CMMAPlayer::EStarted) |
227 { |
227 { |
228 NotifyJavaOnChange(); |
228 NotifyJavaOnChange(); |
229 } |
229 } |
230 } |
230 } |
240 // Scales the given AMMS priority to MMF priority and sets it to MMF. |
240 // Scales the given AMMS priority to MMF priority and sets it to MMF. |
241 // ----------------------------------------------------------------------------- |
241 // ----------------------------------------------------------------------------- |
242 TInt CAMMSAudioOutputControl::SetAudioOutputToMmf(CAudioOutput::TAudioOutputPreference aPref) |
242 TInt CAMMSAudioOutputControl::SetAudioOutputToMmf(CAudioOutput::TAudioOutputPreference aPref) |
243 { |
243 { |
244 DEBUG("AMMS::CAMMSAudioOutputControl::SetAudioOutputToMmfL +"); |
244 DEBUG("AMMS::CAMMSAudioOutputControl::SetAudioOutputToMmfL +"); |
245 CAudioOutput::TAudioOutputPreference tempPreference = iRoutingUserPreference ; |
|
246 iRoutingUserPreference = aPref; |
|
247 TRAPD(err,CreateNativeAudioOutputControlL(); |
245 TRAPD(err,CreateNativeAudioOutputControlL(); |
248 iAudioOutput->SetAudioOutputL(aPref)); |
246 iAudioOutput->SetAudioOutputL(aPref)); |
249 if (KErrNone != err) |
247 if (KErrNone != err) |
250 { |
248 { |
251 iRoutingUserPreference = tempPreference; |
|
252 TBuf<KEventMessageSize> errorMessage; |
249 TBuf<KEventMessageSize> errorMessage; |
253 errorMessage.Format(KErrAudioOutputControlError, err); |
250 errorMessage.Format(KErrAudioOutputControlError, err); |
254 iPlayer->PostStringEvent(CMMAPlayerEvent::EError, errorMessage); |
251 iPlayer->PostStringEvent(CMMAPlayerEvent::EError, errorMessage); |
|
252 return (TInt)iRoutingUserPreference; |
|
253 } |
|
254 iRoutingUserPreference = aPref; |
|
255 if (iVolumeControl) |
|
256 { |
|
257 TRAPD(err, |
|
258 { |
|
259 // If current audio o/p preference is default and Headset or |
|
260 // Bluetooth device is connected or if preference is private then |
|
261 // set the audio preference as private to volume control else set it |
|
262 // as public |
|
263 if ( (iRoutingUserPreference == (TInt)(CAudioOutput::ENoPreference) && |
|
264 GetDeviceDefaultPreference() == (TInt)(CAudioOutput::EPrivate))|| |
|
265 iRoutingUserPreference == (TInt)(CAudioOutput::EPrivate)) |
|
266 { |
|
267 iVolumeControl->SetAudioOutputPreferenceL( |
|
268 (TInt)(CAudioOutput::EPrivate)); |
|
269 } |
|
270 else |
|
271 { |
|
272 iVolumeControl->SetAudioOutputPreferenceL( |
|
273 (TInt)(CAudioOutput::EPublic)); |
|
274 } |
|
275 }); |
|
276 if (KErrNone > err) |
|
277 { |
|
278 TBuf<KEventMessageSize> errorMessage; |
|
279 errorMessage.Format(KErrAudioOutputControlError, err); |
|
280 iPlayer->PostStringEvent(CMMAPlayerEvent::EError, errorMessage); |
|
281 } |
255 } |
282 } |
256 // if during play user set a preference event should be sent to java |
283 // if during play user set a preference event should be sent to java |
257 if (playerState == CMMAPlayer::EStarted) |
284 if (iPlayerState == CMMAPlayer::EStarted) |
258 { |
285 { |
259 NotifyJavaOnChange(); |
286 NotifyJavaOnChange(); |
260 } |
287 } |
261 return (TInt)iRoutingUserPreference; |
288 return (TInt)iRoutingUserPreference; |
262 } |
|
263 // ----------------------------------------------------------------------------- |
|
264 // CAMMSAudioOutputControl::DefaultAudioOutputChanged |
|
265 // MAudioOutputObserver's function is implemented to notify about the change in routing preference |
|
266 // ----------------------------------------------------------------------------- |
|
267 |
|
268 void CAMMSAudioOutputControl::DefaultAudioOutputChanged(CAudioOutput& /*aAudioOutput*/, |
|
269 CAudioOutput::TAudioOutputPreference /*aNewDefault*/) |
|
270 { |
|
271 DEBUG("AMMS::CAMMSAudioOutputControl::DefaultAudioOutputChanged "); |
|
272 |
|
273 } |
289 } |
274 |
290 |
275 void CAMMSAudioOutputControl::NotifyJavaOnChange() |
291 void CAMMSAudioOutputControl::NotifyJavaOnChange() |
276 { |
292 { |
277 TInt tempPref = GetCurrentPrefInt(); |
293 TInt tempPref = GetCurrentPrefInt(); |
285 iCurrentPreference = tempPref; |
301 iCurrentPreference = tempPref; |
286 DEBUG("AMMS::CAMMSAudioOutputControl::NotifyJavaOnChange - Sending Event "); |
302 DEBUG("AMMS::CAMMSAudioOutputControl::NotifyJavaOnChange - Sending Event "); |
287 iPlayer->PostObjectEvent(CMMAPlayerEvent::EAudioOutputPreferenceChangeEvent, iJavaAudioOutputObj); |
303 iPlayer->PostObjectEvent(CMMAPlayerEvent::EAudioOutputPreferenceChangeEvent, iJavaAudioOutputObj); |
288 } |
304 } |
289 |
305 |
290 void CAMMSAudioOutputControl::AccMonitorObserverError(TInt /*aError*/) |
306 void CAMMSAudioOutputControl::AccMonitorObserverError(TInt aError) |
291 { |
307 { |
292 DEBUG("AMMS::CAMMSAudioOutputControl::AccMonitorObserverError"); |
308 DEBUG("AMMS::CAMMSAudioOutputControl::AccMonitorObserverError"); |
|
309 TBuf<KEventMessageSize> errorMessage; |
|
310 errorMessage.Format(KErrAudioOutputControlError, aError); |
|
311 iPlayer->PostStringEvent(CMMAPlayerEvent::EError, errorMessage); |
293 } |
312 } |
294 // ----------------------------------------------------------------------------- |
313 // ----------------------------------------------------------------------------- |
295 // CAMMSAudioOutputControl::CAMMSAudioOutputControl |
314 // CAMMSAudioOutputControl::CAMMSAudioOutputControl |
296 // C++ default constructor can NOT contain any code, that |
315 // C++ default constructor can NOT contain any code, that |
297 // might leave. |
316 // might leave. |
301 iRoutingUserPreference(CAudioOutput::ENoPreference) |
320 iRoutingUserPreference(CAudioOutput::ENoPreference) |
302 { |
321 { |
303 } |
322 } |
304 // HEADSET CONNECTED OR NOT |
323 // HEADSET CONNECTED OR NOT |
305 void CAMMSAudioOutputControl::ConnectedL(CAccMonitorInfo* aAccessoryInfo) |
324 void CAMMSAudioOutputControl::ConnectedL(CAccMonitorInfo* aAccessoryInfo) |
306 { // Reserve memory for the accessory information instance if necessary |
325 { |
307 DEBUG("AMMS::CAMMSAudioOutputControl::ConnectedL +"); |
326 DEBUG("AMMS::CAMMSAudioOutputControl::ConnectedL +"); |
308 if (!iAccessoryInfo) |
327 TAccMonCapability deviceType = aAccessoryInfo->AccDeviceType() ; |
309 { |
328 if (deviceType == KAccMonHeadset) |
310 iAccessoryInfo = CAccMonitorInfo::NewL(); |
|
311 DEBUG("AMMS::CAMMSAudioOutputControl::ConnectedL iAccessoryInfo created"); |
|
312 } |
|
313 // Otherwise just reset accessory information instance |
|
314 else |
|
315 { |
|
316 iAccessoryInfo->Reset(); |
|
317 } |
|
318 iAccessoryInfo->CopyL(aAccessoryInfo); |
|
319 TAccMonCapability deviceType = iAccessoryInfo->AccDeviceType() ; |
|
320 if ((deviceType == KAccMonHeadset) || (deviceType == KAccMonBluetooth)) |
|
321 { |
329 { |
322 DEBUG("AMMS::CAMMSAudioOutputControl::DisconnectedL: Headset connected"); |
330 DEBUG("AMMS::CAMMSAudioOutputControl::DisconnectedL: Headset connected"); |
|
331 // If audio o/p preference is default set the preference as private |
|
332 // to volume control |
|
333 if ( iRoutingUserPreference == (TInt)(CAudioOutput::ENoPreference)) |
|
334 { |
|
335 if (iVolumeControl) |
|
336 { |
|
337 iVolumeControl->SetAudioOutputPreferenceL( |
|
338 (TInt)(CAudioOutput::EPrivate)); |
|
339 } |
|
340 } |
323 //send a callback |
341 //send a callback |
324 if (iRoutingUserPreference == (TInt)(CAudioOutput::ENoPreference)) |
342 if (iRoutingUserPreference == (TInt)(CAudioOutput::ENoPreference)) |
325 { |
343 { |
326 NotifyJavaOnChange(); |
344 NotifyJavaOnChange(); |
327 } |
345 } |
329 DEBUG("AMMS::CAMMSAudioOutputControl::ConnectedL -"); |
347 DEBUG("AMMS::CAMMSAudioOutputControl::ConnectedL -"); |
330 } |
348 } |
331 |
349 |
332 |
350 |
333 void CAMMSAudioOutputControl::DisconnectedL(CAccMonitorInfo* aAccessoryInfo) |
351 void CAMMSAudioOutputControl::DisconnectedL(CAccMonitorInfo* aAccessoryInfo) |
334 { // Reserve memory for the accessory information instance if necessary |
352 { |
335 |
|
336 DEBUG("AMMS::CAMMSAudioOutputControl::DisconnectedL +"); |
353 DEBUG("AMMS::CAMMSAudioOutputControl::DisconnectedL +"); |
337 if (!iAccessoryInfo) |
354 TAccMonCapability deviceType = aAccessoryInfo->AccDeviceType(); |
338 { |
355 if (deviceType == KAccMonHeadset) |
339 iAccessoryInfo = CAccMonitorInfo::NewL(); |
|
340 DEBUG("AMMS::CAMMSAudioOutputControl::DisconnectedL: iAccessoryInfo created"); |
|
341 } |
|
342 else |
|
343 { |
|
344 iAccessoryInfo->Reset(); |
|
345 } |
|
346 iAccessoryInfo->CopyL(aAccessoryInfo); |
|
347 TAccMonCapability deviceType = iAccessoryInfo->AccDeviceType(); |
|
348 if ((deviceType == KAccMonHeadset)||(deviceType == KAccMonBluetooth)) |
|
349 { |
356 { |
350 DEBUG("AMMS::CAMMSAudioOutputControl::DisconnectedL: Headset Disconnected"); |
357 DEBUG("AMMS::CAMMSAudioOutputControl::DisconnectedL: Headset Disconnected"); |
|
358 // If audio o/p preference is default and no accessories is connected or |
|
359 // o/p preference is not private then set the preference as public to |
|
360 // volume control |
|
361 if ( (iRoutingUserPreference == (TInt)(CAudioOutput::ENoPreference) && |
|
362 GetDeviceDefaultPreference() == (TInt)(CAudioOutput::EPublic)) || |
|
363 iRoutingUserPreference != (TInt)(CAudioOutput::EPrivate)) |
|
364 { |
|
365 if (iVolumeControl) |
|
366 { |
|
367 iVolumeControl->SetAudioOutputPreferenceL( |
|
368 (TInt)(CAudioOutput::EPublic)); |
|
369 } |
|
370 } |
351 //send a callback |
371 //send a callback |
352 if (iRoutingUserPreference == (TInt)(CAudioOutput::ENoPreference)) |
372 if (iRoutingUserPreference == (TInt)(CAudioOutput::ENoPreference)) |
353 { |
373 { |
354 NotifyJavaOnChange(); |
374 NotifyJavaOnChange(); |
355 } |
375 } |
360 // start observing headset connection disconnection |
380 // start observing headset connection disconnection |
361 |
381 |
362 void CAMMSAudioOutputControl::CreateHeadsetStateObserverL() |
382 void CAMMSAudioOutputControl::CreateHeadsetStateObserverL() |
363 { |
383 { |
364 // Headset connection and disconnection |
384 // Headset connection and disconnection |
365 iAccessoryInfo = NULL; |
385 RAccMonCapabilityArray capabilityArray; |
366 capabilityArray.Append(KAccMonHeadset); |
386 capabilityArray.Append(KAccMonHeadset); |
367 capabilityArray.Append(KAccMonBluetooth); |
|
368 |
387 |
369 iAccMonitor = CAccMonitor::NewL(); |
388 iAccMonitor = CAccMonitor::NewL(); |
370 iDefaultDevicePreference = (CAudioOutput::TAudioOutputPreference)GetDeviceDefaultPreference(); |
389 iDefaultDevicePreference = (CAudioOutput::TAudioOutputPreference) |
|
390 GetDeviceDefaultPreference(); |
371 iCurrentPreference = (TInt)iDefaultDevicePreference; |
391 iCurrentPreference = (TInt)iDefaultDevicePreference; |
372 TBool isObserving = iAccMonitor->IsObserving(); |
392 TBool isObserving = iAccMonitor->IsObserving(); |
373 if (!isObserving) |
393 if (!isObserving) |
374 { |
394 { |
375 iAccMonitor->StartObservingL(this, capabilityArray); |
395 iAccMonitor->StartObservingL(this, capabilityArray); |
385 // ----------------------------------------------------------------------------- |
405 // ----------------------------------------------------------------------------- |
386 void CAMMSAudioOutputControl::ConstructL() |
406 void CAMMSAudioOutputControl::ConstructL() |
387 { |
407 { |
388 DEBUG("AMMS::CAMMSAudioOutputControl::ConstructL +"); |
408 DEBUG("AMMS::CAMMSAudioOutputControl::ConstructL +"); |
389 // create an observer to notify the state of headset |
409 // create an observer to notify the state of headset |
390 //and initialize iDefaultDevicePreference with CAudioOutput::EPrivate if headset is connected. |
410 // and initialize iDefaultDevicePreference with CAudioOutput::EPrivate |
|
411 // if headset is connected. |
391 CreateHeadsetStateObserverL(); |
412 CreateHeadsetStateObserverL(); |
392 iPlayer->AddStateListenerL(this); |
413 iPlayer->AddStateListenerL(this); |
|
414 // set the current preference to volume control |
|
415 iVolumeControl = GetVolumeControl(); |
|
416 if (iVolumeControl) |
|
417 { |
|
418 iVolumeControl->SetAudioOutputPreferenceL(iCurrentPreference); |
|
419 } |
|
420 |
|
421 } |
|
422 |
|
423 CMMAVolumeControl* CAMMSAudioOutputControl::GetVolumeControl() |
|
424 { |
|
425 // loop through all the available controls of player and return |
|
426 // volume control if found else return null. |
|
427 TInt count(iPlayer->ControlCount()); |
|
428 for (TInt i(0); i < count; i++) |
|
429 { |
|
430 CMMAControl* control = iPlayer->Control(i); |
|
431 // Check that if this control supports volume control |
|
432 if (control->ClassName() == KMMAVolumeControlName) |
|
433 { |
|
434 return static_cast< CMMAVolumeControl* >(control); |
|
435 } |
|
436 } |
|
437 return 0; |
393 } |
438 } |
394 |
439 |
395 void CAMMSAudioOutputControl::CreateNativeAudioOutputControlL() |
440 void CAMMSAudioOutputControl::CreateNativeAudioOutputControlL() |
396 { |
441 { |
397 if (iAudioOutput) |
442 if (iAudioOutput) |