khronosfws/openmax_al/src/mmf_adaptation/cmmfradiobackendengine.cpp
changeset 21 2ed61feeead6
child 28 ebf79c79991a
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/khronosfws/openmax_al/src/mmf_adaptation/cmmfradiobackendengine.cpp	Fri May 28 19:26:28 2010 -0500
@@ -0,0 +1,616 @@
+/*
+* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
+* All rights reserved.
+* This component and the accompanying materials are made available
+* under the terms of "Eclipse Public License v1.0"
+* which accompanies this distribution, and is available
+* at the URL "http://www.eclipse.org/legal/epl-v10.html".
+*
+* Initial Contributors:
+* Nokia Corporation - initial contribution.
+*
+* Contributors:
+*
+* Description:
+*
+*/
+
+#include "cmmfradiobackendengine.h"
+
+extern "C" {
+#include "xaradioitfadaptation.h"
+#include "xanokiavolumeextitfadaptationmmf.h"
+#include "xanokialinearvolumeitfadaptationmmf.h"
+#include "xaplayitfadaptationmmf.h"
+}
+
+CMMFRadioBackendEngine *CMMFRadioBackendEngine::s_instance = 0;
+
+CMMFRadioBackendEngine* CMMFRadioBackendEngine::Instance()
+{
+	if (!s_instance)
+	{	
+		s_instance = new CMMFRadioBackendEngine();
+		s_instance->ConstructL();
+	}
+	return s_instance;
+}
+
+void CMMFRadioBackendEngine::DeleteInstance()
+{
+	if (iFmTunerUtility)
+  {
+  	iFmTunerUtility->Close();
+  	iFmTunerUtility = NULL;
+  }	
+  if (iPlayerUtility)
+  {
+  	iPlayerUtility->Close();
+  	iPlayerUtility = NULL;
+  }
+  
+  if (iRadioUtility)
+  {
+		delete iRadioUtility;
+		iRadioUtility = NULL;
+	}
+		
+}
+
+CMMFRadioBackendEngine::~CMMFRadioBackendEngine()
+{
+}
+    
+CMMFRadioBackendEngine::CMMFRadioBackendEngine()
+{
+	
+}
+
+void CMMFRadioBackendEngine::ConstructL()
+{
+	iAutoFlag = ETrue;
+		
+ 	iRadioUtility = CRadioUtility::NewL( ETrue );
+ 	iFmTunerUtility = &iRadioUtility->RadioFmTunerUtilityL( *this );
+ 	iFmTunerUtility->EnableTunerInOfflineMode( ETrue );
+ 	iFmTunerUtility->RequestTunerControl();   
+    
+ 	iPlayerUtility = &iRadioUtility->RadioPlayerUtilityL( *this );    
+ 	 
+}
+void CMMFRadioBackendEngine::StationSeek(XAboolean aUpwards)
+{
+	if (iFmTunerUtility)
+ 	{
+  	iFmTunerUtility->StationSeek(aUpwards);
+ 	}	
+}
+
+void CMMFRadioBackendEngine::SetFrequency(TInt aFreq)
+{
+  DEBUG_API_A1("CMMFRadioBackendEngine::SetFrequency: %d", aFreq);	
+	if (iFmTunerUtility)
+ 	{
+  	iFmTunerUtility->SetFrequency(aFreq);
+ 	}	
+}
+
+TInt CMMFRadioBackendEngine::GetFrequency(TInt& aFreq)
+{
+  DEBUG_API("CMMFRadioBackendEngine::GetFrequency");	
+	TInt ret = KErrNotFound;
+	if (iFmTunerUtility)
+	{
+  	ret = iFmTunerUtility->GetFrequency(aFreq);
+ 	}	
+  DEBUG_API_A1("CMMFRadioBackendEngine::GetFrequency RET: %d", ret);	 
+//  RDebug::Print(_L("CMMFRadioBackendEngine::GetFrequency RET: %d"), ret);	 
+ 	return ret; 	
+}
+
+TInt CMMFRadioBackendEngine::GetSignalStrength(TInt& aSignalStrength)
+{
+	TInt ret = KErrNotFound;
+ 	if (iFmTunerUtility)
+	{
+  	ret = iFmTunerUtility->GetSignalStrength(aSignalStrength);
+ 	}	
+  DEBUG_API_A1("CMMFRadioBackendEngine::GetSignalStrength RET: %d", ret);	
+//  RDebug::Print(_L("CMMFRadioBackendEngine::GetSignalStrength RET: %d"), ret);	    	
+	return ret;
+}
+
+void CMMFRadioBackendEngine::CancelSetFrequency()
+{
+	if (iFmTunerUtility)
+ 	{
+ 		iFmTunerUtility->CancelSetFrequency();
+ 	}	
+}
+
+void CMMFRadioBackendEngine::CancelStationSeek()
+{
+	if (iFmTunerUtility)
+ 	{
+ 		iFmTunerUtility->CancelStationSeek();
+ 	}	
+}
+
+void CMMFRadioBackendEngine::SetFreqRange(TFmRadioFrequencyRange aRange)
+{
+	if (iFmTunerUtility)
+ 	{
+ 		iFmTunerUtility->SetFrequencyRange(aRange);
+ 	}	
+}
+
+TInt CMMFRadioBackendEngine::GetFreqRange(TFmRadioFrequencyRange& aRange)
+{
+	TInt ret = KErrNotFound;
+	TInt minFreq = 0;
+	TInt maxFreq = 0;
+		
+ 	if (iFmTunerUtility)
+ 	{
+ 		ret = iFmTunerUtility->GetFrequencyRange((TFmRadioFrequencyRange&)aRange, (TInt&)minFreq, (TInt&)maxFreq);
+ 	}	
+  DEBUG_API_A1("CMMFRadioBackendEngine::GetFreqRange RET: %d", ret);	 
+//  RDebug::Print(_L("CMMFRadioBackendEngine::GetFreqRange RET: %d"), ret);	   	
+  return ret;
+}
+
+TInt CMMFRadioBackendEngine::GetFreqRangeProperties(TFmRadioFrequencyRange& aRange, TInt& aMinFreq, TInt& aMaxFreq)
+{
+	TInt ret = KErrNotFound;
+		
+	if (iFmTunerUtility)
+ 	{
+  	ret = iFmTunerUtility->GetFrequencyRange((TFmRadioFrequencyRange&)aRange, (TInt&)aMinFreq, (TInt&)aMaxFreq);
+ 	}	
+  DEBUG_API_A1("CMMFRadioBackendEngine::GetFreqRangeProperties RET: %d", ret);	 	
+//  RDebug::Print(_L("CMMFRadioBackendEngine::GetFreqRangeProperties RET: %d"), ret);	   
+  return ret;
+}
+TInt CMMFRadioBackendEngine::GetMaxVolume(TInt& aMaxVol)
+{
+	TInt ret = KErrNotFound;
+
+	if (iPlayerUtility)
+	{
+		ret = iPlayerUtility->GetMaxVolume(aMaxVol);
+	}		 
+  return ret;
+}
+
+TInt CMMFRadioBackendEngine::SetVolume(TInt aVol)
+{
+	TInt ret = KErrNotFound; 
+
+	if (iPlayerUtility)
+	{
+		ret = iPlayerUtility->SetVolume(aVol);
+	}		 
+  return ret;
+}
+
+TInt CMMFRadioBackendEngine::SetMute(XAboolean aMute)
+{
+	TInt ret = KErrNotFound;
+
+	if (iPlayerUtility)
+	{
+		ret = iPlayerUtility->Mute(aMute);
+	}		
+  return ret;
+}
+
+TInt CMMFRadioBackendEngine::GetVolume(TInt& aVol)
+{
+	TInt ret = KErrNotFound;
+
+	if (iPlayerUtility)
+	{
+		ret = iPlayerUtility->GetVolume(aVol);
+	}		
+  return ret;
+}
+
+TInt CMMFRadioBackendEngine::GetForcedMonoReception(XAuint32& aForcedMono) 
+{
+	TInt ret = KErrNotFound;
+	TBool forceMono = EFalse;
+
+	if (iFmTunerUtility)
+	{
+		ret = iFmTunerUtility->GetForcedMonoReception(forceMono);
+		if (ret != KErrNone)
+			return ret;			
+	}		 
+		
+//  RDebug::Print(_L("CMMFRadioBackendEngine::GetForcedMonoReception RET: %d, aForcedMono = %d"), ret, aForcedMono);	 		
+	if (forceMono)
+	{
+		aForcedMono = XA_STEREOMODE_MONO;
+	}
+	else
+	{
+		if (iAutoFlag)			
+			aForcedMono = XA_STEREOMODE_AUTO;
+		else	
+			aForcedMono = XA_STEREOMODE_STEREO;				
+	}
+  return ret;
+}
+
+void CMMFRadioBackendEngine::PlayRadio()
+{
+	if (iPlayerUtility)
+	{
+		iPlayerUtility->Play();
+	}		
+}
+
+void CMMFRadioBackendEngine::StopRadio()
+{
+	if (iPlayerUtility)
+	{
+		iPlayerUtility->Stop();
+	}		
+}
+
+TInt CMMFRadioBackendEngine::ForceMonoReception(XAuint32 aForcedMono)
+{
+	TInt ret = KErrNotFound;
+
+	if (iFmTunerUtility)
+	{
+		if (aForcedMono == XA_STEREOMODE_MONO)
+		{
+			iAutoFlag = EFalse;
+			ret = iFmTunerUtility->ForceMonoReception(ETrue);
+		}
+		else if (aForcedMono == XA_STEREOMODE_STEREO)
+		{
+			iAutoFlag = EFalse;
+			ret = iFmTunerUtility->ForceMonoReception(EFalse);
+		}	
+		else // (aForcedMono == XA_STEREOMODE_AUTO)
+		{
+			iAutoFlag = ETrue;
+			ret = iFmTunerUtility->ForceMonoReception(EFalse);
+		}							
+	}	
+  DEBUG_API_A1("CMMFRadioBackendEngine::ForceMonoReception RET: %d", ret);	
+ // RDebug::Print(_L("CMMFRadioBackendEngine::ForceMonoReception RET: %d"), ret);	   		
+  return ret;
+}
+
+XAresult CMMFRadioBackendEngine::SetRadioAdaptContext(void * adaptcontext)
+{
+	iRadioAdaptContext = adaptcontext;
+	return XA_RESULT_SUCCESS;
+} 
+
+XAresult CMMFRadioBackendEngine::SetPlayerAdaptContext(void * adaptcontext)
+{
+	iPlayerAdaptContext = adaptcontext;
+	return XA_RESULT_SUCCESS;
+} 
+
+// -----------------------------------------------------------------------------
+// CMMFRadioBackendEngine::MrpeoPresetChanged
+// Observer for Presets
+// -----------------------------------------------------------------------------
+void CMMFRadioBackendEngine::MrpeoPresetChanged(
+    TPresetChangeEvent /*aChange*/,
+    TInt /*aIndex*/ )
+{
+
+}
+
+// ----------------------------------------------------
+// CMMFRadioBackendEngine::MrftoSquelchChange
+//
+// ----------------------------------------------------
+//
+void CMMFRadioBackendEngine::MrftoSquelchChange(
+    TBool /*aSquelch*/ )
+{
+	
+}    
+
+// ----------------------------------------------------
+// CMMFRadioBackendEngine::MTsoForcedMonoChanged
+// Called when a client enables/disabled forced mono reception
+// ----------------------------------------------------
+//
+void CMMFRadioBackendEngine::MrftoForcedMonoChange(
+    TBool aForcedMono )
+{
+  DEBUG_API_A1("CMMFRadioBackendEngine::MrftoForcedMonoChange: aForcedMono =  %d", aForcedMono);	
+//  RDebug::Print(_L("CMMFRadioBackendEngine::MrftoForcedMonoChange: aForcedMono = %d"), aForcedMono);	   	
+	XARadioItfAdapt_StereoStatusChange((XAAdaptationBaseCtx*)iRadioAdaptContext, aForcedMono);    
+}  
+    
+ // ----------------------------------------------------
+// CMMFRadioBackendEngine::MrftoFrequencyChange
+// Called when the tuned frequency changes
+// ----------------------------------------------------
+//
+void CMMFRadioBackendEngine::MrftoFrequencyChange(
+    TInt aNewFrequency)
+{
+ 	DEBUG_API_A1("CMMFRadioBackendEngine::MrftoFrequencyChange: aNewFrequency =  %d", aNewFrequency);	
+ // RDebug::Print(_L("CMMFRadioBackendEngine::MrftoFrequencyChange aNewFrequency = %d"), aNewFrequency);	  			
+	XARadioItfAdapt_FrequencyChange((XAAdaptationBaseCtx*)iRadioAdaptContext, aNewFrequency);    
+}  
+    
+// ----------------------------------------------------
+// CMMFRadioBackendEngine::MrftoFrequencyRangeChange
+//
+// ----------------------------------------------------
+//
+void CMMFRadioBackendEngine::MrftoFrequencyRangeChange(
+    TFmRadioFrequencyRange aNewRange )
+{
+ 	DEBUG_API_A1("CMMFRadioBackendEngine::MrftoFrequencyRangeChange: aNewRange =  %d", aNewRange);		
+//  RDebug::Print(_L("CMMFRadioBackendEngine::MrftoFrequencyRangeChange: aNewRange = %d"), aNewRange);	  		
+	XARadioItfAdapt_FrequencyRangeChange((XAAdaptationBaseCtx*)iRadioAdaptContext, aNewRange);        
+} 
+ 
+// ----------------------------------------------------
+// CMMFRadioBackendEngine::MrftoOfflineModeStatusChange
+// Called when offline mode status changes
+// ----------------------------------------------------
+//
+void CMMFRadioBackendEngine::MrftoOfflineModeStatusChange(
+    TBool /*aOfflineMode*/ )
+{
+ 
+}  
+    
+// ----------------------------------------------------
+// CMMFRadioBackendEngine::MrftoAntennaStatusChange
+// Called when antenna status changes.
+// ----------------------------------------------------
+//
+void CMMFRadioBackendEngine::MrftoAntennaStatusChange(
+    TBool /*aAttached*/ )
+{
+
+}
+
+// ----------------------------------------------------
+// CMMFRadioBackendEngine::MrftoFmTransmitterStatusChange
+// The FM tuner is turned off when FM transmitter is on.
+// ----------------------------------------------------
+//
+void CMMFRadioBackendEngine::MrftoFmTransmitterStatusChange(
+    TBool /*aActive*/ )
+{
+ 
+}
+  
+// ----------------------------------------------------
+// CMMFRadioBackendEngine::MrftoStationSeekComplete
+//
+// ----------------------------------------------------
+//
+void CMMFRadioBackendEngine::MrftoStationSeekComplete(
+    TInt aError,
+    TInt aFrequency )
+{
+	XARadioItfAdapt_SeekComplete((XAAdaptationBaseCtx*)iRadioAdaptContext, aError, aFrequency);    
+}      	
+    
+// ----------------------------------------------------
+// CMMFRadioBackendEngine::MrftoSetFrequencyComplete
+// ----------------------------------------------------
+//
+void CMMFRadioBackendEngine::MrftoSetFrequencyComplete(
+    TInt aError )
+{
+ 	DEBUG_API_A1("CMMFRadioBackendEngine::MrftoSetFrequencyComplete: aError =  %d", aError);		
+//  RDebug::Print(_L("CMMFRadioBackendEngine::MrftoFrrequencyComplete: aError = %d"), aError);	  		
+	TInt freq = 0;
+  if (!aError) 
+ 	{
+ 		iFmTunerUtility->GetFrequency(freq);
+ 	}
+ 	DEBUG_API_A1("CMMFRadioBackendEngine::MrftoSetFrequencyComplete: new freq is: %d", freq);	 
+//  RDebug::Print(_L("CMMFRadioBackendEngine::MrftoSetFrequencyComplete: new freq is: %d"), freq);	  		
+	XARadioItfAdapt_SetFrequencyComplete((XAAdaptationBaseCtx*)iRadioAdaptContext, aError, freq);    
+}  
+    
+// ----------------------------------------------------
+// CMMFRadioBackendEngine::MrftoSetFrequencyRangeComplete
+//
+// ----------------------------------------------------
+//
+void CMMFRadioBackendEngine::MrftoSetFrequencyRangeComplete(
+    TInt aError )
+{
+ 	DEBUG_API_A1("CMMFRadioBackendEngine::MrftoSetFrequencyRangeComplete: aError =  %d", aError);		
+//  RDebug::Print(_L("CMMFRadioBackendEngine::MrftoSetFrequencyRangeComplete: aError = %d"), aError);	  	
+	XARadioItfAdapt_SetFrequencyRangeComplete((XAAdaptationBaseCtx*)iRadioAdaptContext, aError);       	  
+}
+
+// ----------------------------------------------------
+// CMMFRadioBackendEngine::MrftoRequestTunerControlComplete
+// ----------------------------------------------------
+//
+void CMMFRadioBackendEngine::MrftoRequestTunerControlComplete(
+    TInt aError)
+{
+//  RDebug::Print(_L("CMMFRadioBackendEngine::MrftoRequestTunerControlComplete: aError = %d"), aError);	  	  			 
+} 
+    
+// ----------------------------------------------------
+// CMMFRadioBackendEngine::MrpoBalanceChange
+//
+// ----------------------------------------------------
+//
+void CMMFRadioBackendEngine::MrpoBalanceChange(
+    TInt /*aLeftPercentage*/,
+    TInt /*aRightPercentage*/ )
+{
+	
+} 
+    
+// ----------------------------------------------------
+// CMMFRadioBackendEngine::MrpoMuteChange
+//
+// ----------------------------------------------------
+//
+void CMMFRadioBackendEngine::MrpoMuteChange(
+    TBool aMute )
+{
+	XANokiaVolumeExtItfAdapt_MuteChange((XAAdaptationBaseCtx*)iPlayerAdaptContext, aMute);   
+}  
+    
+// ----------------------------------------------------
+// CMMFRadioBackendEngine::MrpoVolumeChange
+//
+// ----------------------------------------------------
+//
+void CMMFRadioBackendEngine::MrpoVolumeChange(
+    TInt aVolume )
+{
+	XANokiaLinearVolumeItfAdapt_VolumeChange((XAAdaptationBaseCtx*)iPlayerAdaptContext, aVolume);      	
+}  
+    
+// ----------------------------------------------------
+// CMMFRadioBackendEngine::MrpoStateChange This is Tuner State
+// Called when the state of the tuner changes
+// ----------------------------------------------------
+//
+void CMMFRadioBackendEngine::MrpoStateChange(
+    TPlayerState aState,
+    TInt aError )
+{	    	
+	if ( aError )
+ 	{
+ 		DEBUG_API_A1("CMMFRadioBackendEngine::MrpoStateChange: aError =  %d", aError);
+ // 	RDebug::Print(_L("CMMFRadioBackendEngine::MrpoStateChange: aError = %d"), aError);	  	 			     	
+ 	}
+
+ 	DEBUG_API_A1("CMMFRadioBackendEngine::MrpoStateChange: new state =  %d", aState);	
+//  RDebug::Print(_L("CMMFRadioBackendEngine::MrpoStateChange: new state = %d"), aState);	  	 	   
+ 	      
+	if ( aState == ERadioPlayerPlaying )
+ 	{
+  	XAPlayItfAdaptMMF_StateChange((XAAdaptationBaseCtx*)iPlayerAdaptContext, ETrue);  
+	}  
+ 	else  // ERadioPlayerIdle
+ 	{
+  	XAPlayItfAdaptMMF_StateChange((XAAdaptationBaseCtx*)iPlayerAdaptContext, EFalse);  
+ 	}        	
+}                           
+               
+extern "C" {
+
+	void* cmmfradiobackendengine_init()
+	{ 
+		return CMMFRadioBackendEngine::Instance();
+	}
+    
+	void cmmfradiobackendengine_delete(void* context)
+	{ 
+		((CMMFRadioBackendEngine*)(context))->DeleteInstance();
+	}    
+                 
+	void  set_frequency(void* context, XAuint32 freq)
+	{
+		((CMMFRadioBackendEngine*)(context))->SetFrequency((TInt)freq); 			
+	}
+    
+	XAresult  get_frequency(void* context, XAuint32* freq)
+	{
+		return ((CMMFRadioBackendEngine*)(context))->GetFrequency((TInt&)*freq); 			
+	}  
+    
+	XAresult  get_signal_strength(void* context, XAuint32* signalStrength)
+	{
+		return ((CMMFRadioBackendEngine*)(context))->GetSignalStrength((TInt&)*signalStrength); 			
+	}      
+    
+	void station_seek(void* context, XAboolean upwards)      
+	{
+		((CMMFRadioBackendEngine*)(context))->StationSeek(upwards); 			
+	}
+		
+	void cancel_set_frequency(void* context)      
+	{
+		((CMMFRadioBackendEngine*)(context))->CancelSetFrequency(); 			
+	}		
+		
+	void cancel_station_seek(void* context)      
+	{
+		((CMMFRadioBackendEngine*)(context))->CancelStationSeek(); 			
+	}		
+		
+	void set_freq_range(void* context, XAuint8 range)      
+	{
+		((CMMFRadioBackendEngine*)(context))->SetFreqRange((TFmRadioFrequencyRange)range); 			
+	}	
+		
+	XAresult  get_freq_range(void* context, XAuint8* range)
+	{
+		return ((CMMFRadioBackendEngine*)(context))->GetFreqRange((TFmRadioFrequencyRange&)*range); 			
+	}
+    
+	XAresult  get_freq_range_properties(void* context, XAuint8 range, XAuint32* aMinFreq, XAuint32* aMaxFreq)
+	{
+		return ((CMMFRadioBackendEngine*)(context))->GetFreqRangeProperties((TFmRadioFrequencyRange&)range, (TInt&) *aMinFreq, (TInt&) *aMaxFreq); 		
+	}   
+    
+	XAresult  get_max_volume(void* context, XAmillibel* maxVol)
+	{
+		return  ((CMMFRadioBackendEngine*)(context))->GetMaxVolume((TInt&)*maxVol); 
+	}   
+
+	XAresult  set_volume(void* context, XAuint32 vol)
+	{
+		return ((CMMFRadioBackendEngine*)(context))->SetVolume((TInt)vol); 			
+	} 
+    
+	XAresult  get_volume(void* context, XAuint32* vol)
+	{
+		return ((CMMFRadioBackendEngine*)(context))->GetVolume((TInt&)*vol); 		
+	}  
+    
+	XAresult  set_mute(void* context, XAboolean mute)
+	{
+		return ((CMMFRadioBackendEngine*)(context))->SetMute(mute); 			
+	} 
+    
+	XAresult  get_stereo_mode(void* context, XAuint32* mode)
+	{
+		return ((CMMFRadioBackendEngine*)(context))->GetForcedMonoReception(*mode); 			
+	}     
+    
+	XAresult  set_stereo_mode(void* context, XAuint32 mode)
+	{
+		return ((CMMFRadioBackendEngine*)(context))->ForceMonoReception(mode); 		
+	}  
+     
+	void play_radio(void* context)
+	{
+		((CMMFRadioBackendEngine*)(context))->PlayRadio(); 			
+	} 
+    
+	void stop_radio(void* context)
+	{
+		((CMMFRadioBackendEngine*)(context))->StopRadio(); 	
+	}        
+    
+	XAresult mmf_set_radio_adapt_context(void * context, void * adaptcontext)
+	{
+		return ((CMMFRadioBackendEngine*)(context))->SetRadioAdaptContext(adaptcontext);
+	}   
+	
+	XAresult mmf_set_player_adapt_context(void * context, void * adaptcontext)
+	{
+		return ((CMMFRadioBackendEngine*)(context))->SetPlayerAdaptContext(adaptcontext);
+	}   	                       										
+}