khronosfws/openmax_al/src/mmf_adaptation/cmmfradiobackendengine.cpp
changeset 32 94fc26b6e006
parent 31 8dfd592727cb
child 33 5e8b14bae8c3
child 42 1fa3fb47b1e3
equal deleted inserted replaced
31:8dfd592727cb 32:94fc26b6e006
    29 CMMFRadioBackendEngine* CMMFRadioBackendEngine::Instance()
    29 CMMFRadioBackendEngine* CMMFRadioBackendEngine::Instance()
    30 {
    30 {
    31 	if (!s_instance)
    31 	if (!s_instance)
    32 	{	
    32 	{	
    33 		s_instance = new CMMFRadioBackendEngine();
    33 		s_instance = new CMMFRadioBackendEngine();
    34 		s_instance->ConstructL();
    34 		if (s_instance)
       
    35 		{
       
    36 			s_instance->ConstructL();
       
    37 		}
    35 	}
    38 	}
    36 	return s_instance;
    39 	return s_instance;
    37 }
    40 }
    38 
    41 
    39 void CMMFRadioBackendEngine::DeleteInstance()
    42 void CMMFRadioBackendEngine::DeleteInstance()
    41 	if (iFmTunerUtility)
    44 	if (iFmTunerUtility)
    42   {
    45   {
    43   	iFmTunerUtility->Close();
    46   	iFmTunerUtility->Close();
    44   	iFmTunerUtility = NULL;
    47   	iFmTunerUtility = NULL;
    45   }	
    48   }	
    46   if (iPlayerUtility)
    49   if (iRadioPlayerUtility)
    47   {
    50   {
    48   	iPlayerUtility->Close();
    51   	iRadioPlayerUtility->Close();
    49   	iPlayerUtility = NULL;
    52   	iRadioPlayerUtility = NULL;
    50   }
    53   }
    51   
    54   
    52   if (iRadioUtility)
    55   if (iRadioUtility)
    53   {
    56   {
    54 		delete iRadioUtility;
    57 		delete iRadioUtility;
    65 {
    68 {
    66 	
    69 	
    67 }
    70 }
    68 
    71 
    69 void CMMFRadioBackendEngine::ConstructL()
    72 void CMMFRadioBackendEngine::ConstructL()
    70 {
    73 {		
    71 	iAutoFlag = ETrue;
       
    72 		
       
    73  	iRadioUtility = CRadioUtility::NewL( ETrue );
    74  	iRadioUtility = CRadioUtility::NewL( ETrue );
    74  	iFmTunerUtility = &iRadioUtility->RadioFmTunerUtilityL( *this );
    75  	if (iRadioUtility)
    75  	iFmTunerUtility->EnableTunerInOfflineMode( ETrue );
    76  	{		
    76  	iFmTunerUtility->RequestTunerControl();   
    77  		iFmTunerUtility = &iRadioUtility->RadioFmTunerUtilityL( *this );
    77     
    78  	}
    78  	iPlayerUtility = &iRadioUtility->RadioPlayerUtilityL( *this );    
    79  	if (iFmTunerUtility)
       
    80  	{
       
    81  		iFmTunerUtility->EnableTunerInOfflineMode( ETrue );
       
    82  		iFmTunerUtility->RequestTunerControl();  
       
    83  	} 
       
    84   if (iRadioUtility)
       
    85   {  
       
    86  		iRadioPlayerUtility = &iRadioUtility->RadioPlayerUtilityL( *this ); 
       
    87  	}   
    79  	 
    88  	 
    80 }
    89 }
    81 void CMMFRadioBackendEngine::StationSeek(XAboolean aUpwards)
    90 void CMMFRadioBackendEngine::StationSeek(XAboolean aUpwards)
    82 {
    91 {
    83 	if (iFmTunerUtility)
    92 	if (iFmTunerUtility)
   173 }
   182 }
   174 TInt CMMFRadioBackendEngine::GetMaxVolume(TInt& aMaxVol)
   183 TInt CMMFRadioBackendEngine::GetMaxVolume(TInt& aMaxVol)
   175 {
   184 {
   176 	TInt ret = KErrNotFound;
   185 	TInt ret = KErrNotFound;
   177 
   186 
   178 	if (iPlayerUtility)
   187 	if (iRadioPlayerUtility)
   179 	{
   188 	{
   180 		ret = iPlayerUtility->GetMaxVolume(aMaxVol);
   189 		ret = iRadioPlayerUtility->GetMaxVolume(aMaxVol);
   181 	}		 
   190 	}		 
   182   return ret;
   191   return ret;
   183 }
   192 }
   184 
   193 
   185 TInt CMMFRadioBackendEngine::SetVolume(TInt aVol)
   194 TInt CMMFRadioBackendEngine::SetVolume(TInt aVol)
   186 {
   195 {
   187 	TInt ret = KErrNotFound; 
   196 	TInt ret = KErrNotFound; 
   188 
   197 
   189 	if (iPlayerUtility)
   198 	if (iRadioPlayerUtility)
   190 	{
   199 	{
   191 		ret = iPlayerUtility->SetVolume(aVol);
   200 		ret = iRadioPlayerUtility->SetVolume(aVol);
   192 	}		 
   201 	}		 
   193   return ret;
   202   return ret;
   194 }
   203 }
   195 
   204 
   196 TInt CMMFRadioBackendEngine::SetMute(XAboolean aMute)
   205 TInt CMMFRadioBackendEngine::SetMute(XAboolean aMute)
   197 {
   206 {
   198 	TInt ret = KErrNotFound;
   207 	TInt ret = KErrNotFound;
   199 
   208 
   200 	if (iPlayerUtility)
   209 	if (iRadioPlayerUtility)
   201 	{
   210 	{
   202 		ret = iPlayerUtility->Mute(aMute);
   211 		ret = iRadioPlayerUtility->Mute(aMute);
   203 	}		
   212 	}		
   204   return ret;
   213   return ret;
   205 }
   214 }
   206 
   215 
   207 TInt CMMFRadioBackendEngine::GetVolume(TInt& aVol)
   216 TInt CMMFRadioBackendEngine::GetVolume(TInt& aVol)
   208 {
   217 {
   209 	TInt ret = KErrNotFound;
   218 	TInt ret = KErrNotFound;
   210 
   219 
   211 	if (iPlayerUtility)
   220 	if (iRadioPlayerUtility)
   212 	{
   221 	{
   213 		ret = iPlayerUtility->GetVolume(aVol);
   222 		ret = iRadioPlayerUtility->GetVolume(aVol);
   214 	}		
   223 	}		
   215   return ret;
   224   return ret;
   216 }
   225 }
   217 
   226 
   218 TInt CMMFRadioBackendEngine::GetForcedMonoReception(XAuint32& aForcedMono) 
   227 TInt CMMFRadioBackendEngine::GetForcedMonoReception(XAuint32& aForcedMono) 
   219 {
   228 {
   220 	TInt ret = KErrNotFound;
   229 	TInt ret = KErrNotFound;
   221 	TBool forceMono = EFalse;
   230 	TBool forceMono;
   222 
   231 
   223 	if (iFmTunerUtility)
   232 	if (iFmTunerUtility)
   224 	{
   233 	{
   225 		ret = iFmTunerUtility->GetForcedMonoReception(forceMono);
   234 		ret = iFmTunerUtility->GetForcedMonoReception(forceMono);
   226 		if (ret != KErrNone)
       
   227 			return ret;			
       
   228 	}		 
   235 	}		 
   229 		
   236 		
   230 //  RDebug::Print(_L("CMMFRadioBackendEngine::GetForcedMonoReception RET: %d, aForcedMono = %d"), ret, aForcedMono);	 		
   237 //  RDebug::Print(_L("CMMFRadioBackendEngine::GetForcedMonoReception RET: %d, aForcedMono = %d"), ret, aForcedMono);	 		
   231 	if (forceMono)
   238 	if (forceMono)
   232 	{
   239 	{
   233 		aForcedMono = XA_STEREOMODE_MONO;
   240 		aForcedMono = XA_STEREOMODE_MONO;
   234 	}
   241 	}
   235 	else
   242 	else
   236 	{
   243 	{
   237 		if (iAutoFlag)			
   244 		if (iForceStereo)			
   238 			aForcedMono = XA_STEREOMODE_AUTO;
   245 			aForcedMono = XA_STEREOMODE_STEREO;		
   239 		else	
   246 		else	
   240 			aForcedMono = XA_STEREOMODE_STEREO;				
   247 			aForcedMono = XA_STEREOMODE_AUTO;					
   241 	}
   248 	}
   242   return ret;
   249   return ret;
   243 }
   250 }
   244 
   251 
   245 void CMMFRadioBackendEngine::PlayRadio()
   252 void CMMFRadioBackendEngine::PlayRadio()
   246 {
   253 {
   247 	if (iPlayerUtility)
   254 	if (iRadioPlayerUtility)
   248 	{
   255 	{
   249 		iPlayerUtility->Play();
   256 		iRadioPlayerUtility->Play();
   250 	}		
   257 	}		
   251 }
   258 }
   252 
   259 
   253 void CMMFRadioBackendEngine::StopRadio()
   260 void CMMFRadioBackendEngine::StopRadio()
   254 {
   261 {
   255 	if (iPlayerUtility)
   262 	if (iRadioPlayerUtility)
   256 	{
   263 	{
   257 		iPlayerUtility->Stop();
   264 		iRadioPlayerUtility->Stop();
   258 	}		
   265 	}		
   259 }
   266 }
   260 
   267 
   261 TInt CMMFRadioBackendEngine::ForceMonoReception(XAuint32 aForcedMono)
   268 TInt CMMFRadioBackendEngine::ForceMonoReception(XAuint32 aForcedMono)
   262 {
   269 {
   263 	TInt ret = KErrNotFound;
   270 	TInt ret = KErrNotFound;
   264 
   271 	TBool currentMode;
       
   272 	
       
   273 	ret = GetForcedMonoReception((XAuint32&)currentMode);
       
   274 	if (ret != XA_RESULT_SUCCESS)
       
   275 		return ret;
       
   276 		
   265 	if (iFmTunerUtility)
   277 	if (iFmTunerUtility)
   266 	{
   278 	{
   267 		if (aForcedMono == XA_STEREOMODE_MONO)
   279 		if (aForcedMono == XA_STEREOMODE_MONO)
   268 		{
   280 		{
   269 			iAutoFlag = EFalse;
   281 			iForceStereo = EFalse;
   270 			ret = iFmTunerUtility->ForceMonoReception(ETrue);
   282 			ret = iFmTunerUtility->ForceMonoReception(ETrue);
   271 		}
   283 		}
   272 		else if (aForcedMono == XA_STEREOMODE_STEREO)
   284 		else if (aForcedMono == XA_STEREOMODE_STEREO)
   273 		{
   285 		{
   274 			iAutoFlag = EFalse;
   286 			iForceStereo = ETrue;						
   275 			ret = iFmTunerUtility->ForceMonoReception(EFalse);
   287 			if (currentMode == XA_STEREOMODE_AUTO) // Transition from Auto to Stereo doesn't require Utility call:
       
   288 			{
       
   289 				MrftoForcedMonoChange(ETrue);
       
   290 			}	
       
   291 			else
       
   292 			{	
       
   293 				ret = iFmTunerUtility->ForceMonoReception(EFalse);
       
   294 			}
   276 		}	
   295 		}	
   277 		else // (aForcedMono == XA_STEREOMODE_AUTO)
   296 		else // (aForcedMono == XA_STEREOMODE_AUTO)
   278 		{
   297 		{
   279 			iAutoFlag = ETrue;
   298 			iForceStereo = EFalse;
   280 			ret = iFmTunerUtility->ForceMonoReception(EFalse);
   299 			if (currentMode == XA_STEREOMODE_STEREO) // Transition from Stereo to Auto doesn't require Utility call:	
       
   300 			{
       
   301 				MrftoForcedMonoChange(EFalse);
       
   302 			}	
       
   303 			else
       
   304 			{										
       
   305 				ret = iFmTunerUtility->ForceMonoReception(EFalse);
       
   306 			}
   281 		}							
   307 		}							
   282 	}	
   308 	}	
   283   DEBUG_API_A1("CMMFRadioBackendEngine::ForceMonoReception RET: %d", ret);	
   309   DEBUG_API_A1("CMMFRadioBackendEngine::ForceMonoReception RET: %d", ret);	
   284  // RDebug::Print(_L("CMMFRadioBackendEngine::ForceMonoReception RET: %d"), ret);	   		
   310  // RDebug::Print(_L("CMMFRadioBackendEngine::ForceMonoReception RET: %d"), ret);	   		
   285   return ret;
   311   return ret;
   295 {
   321 {
   296 	iPlayerAdaptContext = adaptcontext;
   322 	iPlayerAdaptContext = adaptcontext;
   297 	return XA_RESULT_SUCCESS;
   323 	return XA_RESULT_SUCCESS;
   298 } 
   324 } 
   299 
   325 
       
   326 XAresult TranslateError(TInt error)
       
   327     {
       
   328     XAresult status(XA_RESULT_SUCCESS);
       
   329     switch(error)
       
   330         {
       
   331         case KErrNone:
       
   332             status = XA_RESULT_SUCCESS;
       
   333             break;
       
   334         // to do: investigate and add other possible errors:
       
   335             
       
   336        /* case XA_RESULT_PRECONDITIONS_VIOLATED:
       
   337  
       
   338             break;
       
   339         case XA_RESULT_PARAMETER_INVALID:
       
   340 
       
   341             break;
       
   342         case XA_RESULT_MEMORY_FAILURE:
       
   343 
       
   344             break;
       
   345         case XA_RESULT_RESOURCE_ERROR:
       
   346 
       
   347             break;
       
   348         case XA_RESULT_RESOURCE_LOST:
       
   349  
       
   350             break;
       
   351         case XA_RESULT_IO_ERROR:
       
   352 
       
   353             break;
       
   354         case XA_RESULT_BUFFER_INSUFFICIENT:
       
   355 
       
   356             break;
       
   357         case XA_RESULT_CONTENT_CORRUPTED:
       
   358 
       
   359             break;
       
   360         case XA_RESULT_CONTENT_UNSUPPORTED:
       
   361  
       
   362             break;
       
   363         case XA_RESULT_CONTENT_NOT_FOUND:
       
   364 
       
   365             break;
       
   366         case XA_RESULT_PERMISSION_DENIED:
       
   367 
       
   368             break;
       
   369         case XA_RESULT_FEATURE_UNSUPPORTED:
       
   370 
       
   371             break;
       
   372         case XA_RESULT_INTERNAL_ERROR:
       
   373 
       
   374             break;
       
   375         case XA_RESULT_UNKNOWN_ERROR:
       
   376 
       
   377             break;
       
   378         case XA_RESULT_OPERATION_ABORTED:
       
   379 
       
   380             break;
       
   381         case XA_RESULT_CONTROL_LOST:
       
   382 
       
   383             break;
       
   384             */
       
   385         default:
       
   386         	break;
       
   387         } // end switch
       
   388     return status;
       
   389     }
   300 // -----------------------------------------------------------------------------
   390 // -----------------------------------------------------------------------------
   301 // CMMFRadioBackendEngine::MrpeoPresetChanged
   391 // CMMFRadioBackendEngine::MrpeoPresetChanged
   302 // Observer for Presets
   392 // Observer for Presets
   303 // -----------------------------------------------------------------------------
   393 // -----------------------------------------------------------------------------
   304 void CMMFRadioBackendEngine::MrpeoPresetChanged(
   394 void CMMFRadioBackendEngine::MrpeoPresetChanged(
   318 {
   408 {
   319 	
   409 	
   320 }    
   410 }    
   321 
   411 
   322 // ----------------------------------------------------
   412 // ----------------------------------------------------
   323 // CMMFRadioBackendEngine::MTsoForcedMonoChanged
   413 // CMMFRadioBackendEngine::MrftoForcedMonoChanged
   324 // Called when a client enables/disabled forced mono reception
   414 // Called when a client enables/disabled forced mono reception
   325 // ----------------------------------------------------
   415 // ----------------------------------------------------
   326 //
   416 //
   327 void CMMFRadioBackendEngine::MrftoForcedMonoChange(
   417 void CMMFRadioBackendEngine::MrftoForcedMonoChange(
   328     TBool aForcedMono )
   418     TBool aForcedMono )