diff -r 0b192a3a05a4 -r 00f9ee97d895 bluetoothengine/btmac/src/BTMonoCmdHandler/btmcvolume.cpp --- a/bluetoothengine/btmac/src/BTMonoCmdHandler/btmcvolume.cpp Tue Feb 02 00:20:42 2010 +0200 +++ b/bluetoothengine/btmac/src/BTMonoCmdHandler/btmcvolume.cpp Fri Apr 16 15:08:36 2010 +0300 @@ -60,11 +60,13 @@ void CBtmcVolume::SetSpeakerVolumeL(TInt aHfVol) { TRACE_FUNC - TRACE_INFO((_L("phone vol %d, acc vol %d"), iPhnSpkrVol, iAccSpkrVol)) + TRACE_INFO((_L("current vols phone %d, acc %d"), iPhnSpkrVol, iAccSpkrVol)) + // Store the new volume setting of headset regardless of + // whether volume control is active or not currently iAccSpkrVol = HfToPhoneVolScale(aHfVol); - if (iVolCtrlActivated) + TRACE_INFO((_L("new acc vol %d"), iAccSpkrVol)) + if ( IsActiveRemoteVolumeControl() ) { - TRACE_INFO((_L("to new vol %d"), iAccSpkrVol)) TInt vol = GetNewPhoneVol(); if (vol != KNoAudioStreaming) { @@ -73,10 +75,6 @@ DoSetSpeakerVolL( prevPhVol ); } } - else - { - TRACE_INFO((_L("volume control inactive!"))) - } } void CBtmcVolume::SetMicrophoneVolumeL(TInt /*aHfVol*/) @@ -86,13 +84,11 @@ void CBtmcVolume::ActivateRemoteVolumeControl() { - if (!iVolCtrlActivated) + TRACE_FUNC + if (!IsActiveRemoteVolumeControl() ) { - TRACE_FUNC iVolLevelProperty.Subscribe(iActive->iStatus); iActive->GoActive(); - - iVolCtrlActivated = ETrue; TInt vol = GetNewPhoneVol(); TRACE_INFO((_L("current phone vol %d, acc vol %d"), vol, iAccSpkrVol)) if (vol != KNoAudioStreaming) @@ -109,11 +105,7 @@ void CBtmcVolume::DeActivateRemoteVolumeControl() { - if (iVolCtrlActivated) - { - iVolCtrlActivated = EFalse; - iActive->Cancel(); - } + iActive->Cancel(); TRACE_FUNC } @@ -211,11 +203,15 @@ diff1 = Abs( aPrevPhVol - iAccSpkrVol ); diff2 = Abs( iPhnSpkrVol - iAccSpkrVol ); - if( diff2 >= diff1 ) + if (diff2 > diff1) { // the previous phone volume is closer to current headset volume setting volClick = ( aPrevPhVol < iPhnSpkrVol ) ? KPSVolumeDownClicked : KPSVolumeUpClicked; } + else if ( (diff2 == diff1) && (diff1 !=0) ) + { + volClick = ( aPrevPhVol < iPhnSpkrVol ) ? KPSVolumeDownClicked : KPSVolumeUpClicked; + } // otherwise we have roughly synchronized vol in both ends. } else if( iAccSpkrVol != iPhnSpkrVol ) @@ -242,21 +238,15 @@ volClick = (iAccSpkrVol > iPhnSpkrVol) ? KPSVolumeUpClicked : KPSVolumeDownClicked; } } - + TInt err( KErrNotFound ); if( volClick ) { - iAction = ESpeakerVolSet; - TInt err = iVolKeyEventProperty.Set( volClick ); - if( err ) - { - iAction = ESpeakerVolSubscribe; - TRACE_ERROR((_L("Set KMediaKeysVolumeKeyEvent err %d"), err)); - } + err = iVolKeyEventProperty.Set( volClick ); + TRACE_INFO((_L("Set KMediaKeysVolumeKeyEvent click %d err %d"), volClick, err)); } - else - { - iAction = ESpeakerVolSubscribe; - } + + iAction = err ? ESpeakerVolSubscribe : ESpeakerVolSet; + TRACE_FUNC_EXIT } @@ -313,4 +303,9 @@ return iPhnSpkrVol; } +TBool CBtmcVolume::IsActiveRemoteVolumeControl() + { + return iActive->IsActive(); + } + // End of file