devsound/a3fdevsound/src/devsoundadaptor/cdevcommoncontrol.cpp
branchRCL_3
changeset 8 bc06d8566074
parent 7 94dbab0a2133
child 11 d5f04de580b7
equal deleted inserted replaced
7:94dbab0a2133 8:bc06d8566074
   175 
   175 
   176 
   176 
   177 void CDevCommonControl::ContextEvent(TUid aEvent, TInt aError) 
   177 void CDevCommonControl::ContextEvent(TUid aEvent, TInt aError) 
   178     {
   178     {
   179     DP_CONTEXT(CDevCommonControl::ContextEvent, CtxDevSound, DPLOCAL);
   179     DP_CONTEXT(CDevCommonControl::ContextEvent, CtxDevSound, DPLOCAL);
   180     DP_IN();
   180     DP3_IN("ContextEvent aEvent=%x iActiveState=%d aError=%d",aEvent, iDevAudio->iActiveState, aError);
   181 
   181 
   182     // Can't "switch {...}" on UIDs unfortunately:
   182     // Can't "switch {...}" on UIDs unfortunately:
   183 
       
   184     if (aEvent == KUidA3FContextUpdateComplete)
   183     if (aEvent == KUidA3FContextUpdateComplete)
   185         {
   184         {
   186         //use a sub state pattern to make premtion cycles like other cycles.
   185         if(iBeingPreempted && iStateEventReceived)
   187         if(iBeingPreempted)
   186             {
   188             {
   187             //use a sub state pattern to make premtion cycles like other cycles.
   189             DP1(DLERR,"Preemption error=%d", aError);
   188             DP1(DLERR,"Preemption error=%d", aError);
   190             CDevAudioControl::ContextEvent(aEvent, aError);
       
   191             iDevAudio->iActiveState = EDevSoundAdaptorBeingPreempted;
   189             iDevAudio->iActiveState = EDevSoundAdaptorBeingPreempted;
   192             iBeingPreempted=EFalse;
   190             iBeingPreempted=EFalse;
   193             }
   191             }
   194         ContextEventUpdateComplete(aError);
   192 		ContextEventUpdateComplete(aError);
       
   193         }
       
   194 
       
   195     else if ((aEvent == KUidA3FContextCommitUpdate))
       
   196         {
       
   197         iBeingPreempted=EFalse; // clear being preempted
       
   198         TBool adaptorControlsContext = iAdaptationObserver->AdaptorControlsContext();
       
   199         iIgnoreAsyncOpComplete = !adaptorControlsContext;
       
   200             // if we don't control context, always send a PreemptionFinishedCallbackReceived()
       
   201 		iStateEventReceived=EFalse;
   195         }
   202         }
   196 
   203 
   197     else if ((aEvent == KUidA3FContextPreEmption) or (aEvent == KUidA3FContextPreEmptedCommit))
   204     else if ((aEvent == KUidA3FContextPreEmption) or (aEvent == KUidA3FContextPreEmptedCommit))
   198         {
   205         {
   199         //we are not being preemptied
   206         // clear iBeingPreepted - will be set in ContextEventPreEmption if req
   200         iBeingPreempted=EFalse;
   207         iBeingPreempted=EFalse;
       
   208         TBool adaptorControlsContext = iAdaptationObserver->AdaptorControlsContext();
       
   209 		iStateEventReceived=EFalse;
       
   210         iIgnoreAsyncOpComplete=EFalse; // clear being iIgnoreAsyncOpComplete
   201         ContextEventPreEmption(aEvent, aError);
   211         ContextEventPreEmption(aEvent, aError);
       
   212         if (!adaptorControlsContext)
       
   213             {
       
   214             iIgnoreAsyncOpComplete = ETrue; // if we don't control context never do AsyncOpComplete
       
   215             }
   202         }
   216         }
   203 
   217 
   204     else if (aEvent == KUidA3FContextAbort)
   218     else if (aEvent == KUidA3FContextAbort)
   205         {
   219         {
   206         ContextEventAbort(aError);
   220         ContextEventAbort(aError);
   210     }
   224     }
   211 
   225 
   212 
   226 
   213 void CDevCommonControl::ContextEventAsynchronousPlayCompletion(TInt aError) // from CDevCommonControl
   227 void CDevCommonControl::ContextEventAsynchronousPlayCompletion(TInt aError) // from CDevCommonControl
   214     {
   228     {
   215     DP_CONTEXT(CDevCommonControl::ContextEvent, CtxDevSound, DPLOCAL);
   229     DP_CONTEXT(CDevCommonControl::ContextEventAsynchronousPlayCompletion, CtxDevSound, DPLOCAL);
   216     DP_IN();
   230     DP_IN();
   217     
   231     
   218 	iAdaptationObserver->AsynchronousOperationComplete(aError, ETrue);
   232 	iAdaptationObserver->AsynchronousOperationComplete(aError, ETrue);
   219 		
   233 		
   220     if (aError)
   234     if (aError)
   226     }
   240     }
   227 
   241 
   228 
   242 
   229 void CDevCommonControl::ContextEventAsynchronousInitializeComplete(TInt aError) // from CDevCommonControl
   243 void CDevCommonControl::ContextEventAsynchronousInitializeComplete(TInt aError) // from CDevCommonControl
   230     {
   244     {
   231     DP_CONTEXT(CDevCommonControl::ContextEvent, CtxDevSound, DPLOCAL);
   245     DP_CONTEXT(CDevCommonControl::ContextEventAsynchronousInitializeComplete, CtxDevSound, DPLOCAL);
   232     DP_IN();
   246     DP_IN();
   233     
   247     
   234     iAdaptationObserver->AsynchronousOperationComplete(aError, ETrue);
   248     iAdaptationObserver->AsynchronousOperationComplete(aError, ETrue);
   235     iAdaptationObserver->InitializeComplete(aError);
   249     iAdaptationObserver->InitializeComplete(aError);
   236     
   250     
   238     }
   252     }
   239 
   253 
   240 
   254 
   241 void CDevCommonControl::ContextEventUpdateComplete(TInt aError) // from CDevCommonControl
   255 void CDevCommonControl::ContextEventUpdateComplete(TInt aError) // from CDevCommonControl
   242     {
   256     {
   243     DP_CONTEXT(CDevCommonControl::ContextEvent, CtxDevSound, DPLOCAL);
   257     DP_CONTEXT(CDevCommonControl::ContextEventUpdateComplete, CtxDevSound, DPLOCAL);
   244     DP_IN();
   258     DP_IN();
   245     
   259     
   246     if (iStateEventReceived)
   260     if (iStateEventReceived)
   247         {
   261         {
   248         iStateEventReceived = EFalse;
   262         iStateEventReceived = EFalse;
   275     }
   289     }
   276 
   290 
   277 
   291 
   278 void CDevCommonControl::ContextEventPreEmption(TUid aEvent, TInt aError) // from CDevCommonControl
   292 void CDevCommonControl::ContextEventPreEmption(TUid aEvent, TInt aError) // from CDevCommonControl
   279     {
   293     {
   280     DP_CONTEXT(CDevCommonControl::ContextEvent, CtxDevSound, DPLOCAL);
   294     DP_CONTEXT(CDevCommonControl::ContextEventPreEmption, CtxDevSound, DPLOCAL);
   281     DP_IN();
   295     DP_IN();
   282     
   296     
   283     DP1(DLERR,"Preemption error=%d", aError);
   297     DP1(DLERR,"Preemption error=%d", aError);
   284     CDevAudioControl::ContextEvent(aEvent, aError);
   298     CDevAudioControl::ContextEvent(aEvent, aError);
   285     iBeingPreempted=ETrue;
   299     iBeingPreempted=ETrue;
   288     }
   302     }
   289 
   303 
   290 
   304 
   291 void CDevCommonControl::ContextEventAbort(TInt aError) // from CDevCommonControl
   305 void CDevCommonControl::ContextEventAbort(TInt aError) // from CDevCommonControl
   292     {
   306     {
   293     DP_CONTEXT(CDevCommonControl::ContextEvent, CtxDevSound, DPLOCAL);
   307     DP_CONTEXT(CDevCommonControl::ContextEventAbort, CtxDevSound, DPLOCAL);
   294     DP_IN();
   308     DP_IN();
   295     
   309     
   296     DP1(DLERR,"Abort error=%d", aError);
   310     DP1(DLERR,"Abort error=%d", aError);
   297     FinishWithError(aError==KErrAbort ? KErrDied:aError);
   311     FinishWithError(aError==KErrAbort ? KErrDied:aError);
   298     
   312     
   300     }
   314     }
   301 
   315 
   302 
   316 
   303 void CDevCommonControl::ContextEventStopDevSoundNotifications() // from CDevCommonControl
   317 void CDevCommonControl::ContextEventStopDevSoundNotifications() // from CDevCommonControl
   304     {
   318     {
   305     DP_CONTEXT(CDevCommonControl::ContextEvent, CtxDevSound, DPLOCAL);
   319     DP_CONTEXT(CDevCommonControl::ContextEventStopDevSoundNotifications, CtxDevSound, DPLOCAL);
   306     DP_IN();
   320     DP_IN();
   307     
   321     
   308     iDevAudio->iAudioStream->UnregisterAudioStreamObserver(*this);
   322     iDevAudio->iAudioStream->UnregisterAudioStreamObserver(*this);
   309     iGainControl->UnregisterAudioGainControlObserver(*this);
   323     iGainControl->UnregisterAudioGainControlObserver(*this);
   310     iAudioCodecIf->UnregisterAudioCodecObserver(*this);
   324     iAudioCodecIf->UnregisterAudioCodecObserver(*this);
   314     }
   328     }
   315 
   329 
   316 
   330 
   317 void CDevCommonControl::ContextEventPauseResumeSequenceDueToEmptyBuffers(TBool aFlush) // from CDevCommonControl
   331 void CDevCommonControl::ContextEventPauseResumeSequenceDueToEmptyBuffers(TBool aFlush) // from CDevCommonControl
   318     {
   332     {
   319     DP_CONTEXT(CDevCommonControl::ContextEvent, CtxDevSound, DPLOCAL);
   333     DP_CONTEXT(CDevCommonControl::ContextEventPauseResumeSequenceDueToEmptyBuffers, CtxDevSound, DPLOCAL);
   320     DP_IN();
   334     DP_IN();
   321     
   335     
   322     TInt err(KErrNone);
   336     TInt err(KErrNone);
   323 
   337 
   324     if (iPauseResumeSequenceDueToEmptyBuffers)
   338     if (iPauseResumeSequenceDueToEmptyBuffers)
   343     }
   357     }
   344 
   358 
   345 
   359 
   346 void CDevCommonControl::ContextEventStateDevSoundAdaptorUnloading() // from CDevCommonControl
   360 void CDevCommonControl::ContextEventStateDevSoundAdaptorUnloading() // from CDevCommonControl
   347     {
   361     {
   348     DP_CONTEXT(CDevCommonControl::ContextEvent, CtxDevSound, DPLOCAL);
   362     DP_CONTEXT(CDevCommonControl::ContextEventStateDevSoundAdaptorUnloading, CtxDevSound, DPLOCAL);
   349     DP_IN();
   363     DP_IN();
   350     
   364     
   351     // Due destruction sequence or reinitialization
   365     // Due destruction sequence or reinitialization
   352     if (iDevAudio->iClosing or iDevAudio->iReinitializing)
   366     if (iDevAudio->iClosing or iDevAudio->iReinitializing)
   353         {
   367         {
   398     }
   412     }
   399 
   413 
   400 
   414 
   401 void CDevCommonControl::ContextEventStateDevSoundAdaptorLoading() // from CDevCommonControl
   415 void CDevCommonControl::ContextEventStateDevSoundAdaptorLoading() // from CDevCommonControl
   402     {
   416     {
   403     DP_CONTEXT(CDevCommonControl::ContextEvent, CtxDevSound, DPLOCAL);
   417     DP_CONTEXT(CDevCommonControl::ContextEventStateDevSoundAdaptorLoading, CtxDevSound, DPLOCAL);
   404     DP_IN();
   418     DP_IN();
   405     
   419     
   406     iDevAudio->RequestGainAndBalance(this); // TODO handle error
   420     iDevAudio->RequestGainAndBalance(this); // TODO handle error
   407 
   421 
   408     TInt err = iDevAudio->iAudioStream->Activate();
   422     TInt err = iDevAudio->iAudioStream->Activate();
   427     }
   441     }
   428 
   442 
   429 
   443 
   430 void CDevCommonControl::ContextEventStateDevSoundAdaptorStopping() // from CDevCommonControl
   444 void CDevCommonControl::ContextEventStateDevSoundAdaptorStopping() // from CDevCommonControl
   431     {   
   445     {   
   432     DP_CONTEXT(CDevCommonControl::ContextEvent, CtxDevSound, DPLOCAL);
   446     DP_CONTEXT(CDevCommonControl::ContextEventStateDevSoundAdaptorStopping, CtxDevSound, DPLOCAL);
   433     DP_IN();
   447     DP_IN();
   434     
   448     
   435     TInt err = Unload();
   449     TInt err = Unload();
   436     if (err)
   450     if (err)
   437         {
   451         {
   445     }
   459     }
   446 
   460 
   447 
   461 
   448 void CDevCommonControl::ContextEventStateDevSoundAdaptorBeingPreempted() // from CDevCommonControl
   462 void CDevCommonControl::ContextEventStateDevSoundAdaptorBeingPreempted() // from CDevCommonControl
   449     {
   463     {
   450     DP_CONTEXT(CDevCommonControl::ContextEvent, CtxDevSound, DPLOCAL);
   464     DP_CONTEXT(CDevCommonControl::ContextEventStateDevSoundAdaptorBeingPreempted, CtxDevSound, DPLOCAL);
   451     DP_IN();
   465     DP_IN();
   452     
   466     
   453     __ASSERT_DEBUG(iDevAudio->iActiveStreamState == EInitialized, Panic(EStreamBeingDemotedToEIdle));
   467     __ASSERT_DEBUG(iDevAudio->iActiveStreamState == EInitialized, Panic(EStreamBeingDemotedToEIdle));
   454     FinishWithError(KErrInUse);
   468     FinishWithError(KErrInUse);
   455     if (iIgnoreAsyncOpComplete)
   469     if (iIgnoreAsyncOpComplete)
   466     }
   480     }
   467 
   481 
   468 
   482 
   469 void CDevCommonControl::ContextEventStateDevSoundAdaptorUninitializing() // from CDevCommonControl
   483 void CDevCommonControl::ContextEventStateDevSoundAdaptorUninitializing() // from CDevCommonControl
   470     {
   484     {
   471     DP_CONTEXT(CDevCommonControl::ContextEvent, CtxDevSound, DPLOCAL);
   485     DP_CONTEXT(CDevCommonControl::ContextEventStateDevSoundAdaptorUninitializing, CtxDevSound, DPLOCAL);
   472     DP_IN();
   486     DP_IN();
   473     TInt err = RemoveProcessingUnits();
   487     TInt err = RemoveProcessingUnits();
   474 
   488 
   475     if (err == KErrNone)
   489     if (err == KErrNone)
   476         {
   490         {
   485     }
   499     }
   486 
   500 
   487 
   501 
   488 void CDevCommonControl::ContextEventErrorStateDevSoundAdaptorActivating(TInt aError) // from CDevCommonControl
   502 void CDevCommonControl::ContextEventErrorStateDevSoundAdaptorActivating(TInt aError) // from CDevCommonControl
   489     {
   503     {
   490     DP_CONTEXT(CDevCommonControl::ContextEvent, CtxDevSound, DPLOCAL);
   504     DP_CONTEXT(CDevCommonControl::ContextEventErrorStateDevSoundAdaptorActivating, CtxDevSound, DPLOCAL);
   491     DP_IN();
   505     DP_IN();
   492 
   506 
   493     // If the resume operation fails as result of EmptyBuffers
   507     // If the resume operation fails as result of EmptyBuffers
   494     // Notify about operation complete through CallbackFromAdaptorReceived
   508     // Notify about operation complete through CallbackFromAdaptorReceived
   495     // and continue to allow client to receive PlayError()
   509     // and continue to allow client to receive PlayError()
   513     }
   527     }
   514 
   528 
   515 
   529 
   516 void CDevCommonControl::ContextEventErrorStateDevSoundAdaptorBeingPreempted() // from CDevCommonControl
   530 void CDevCommonControl::ContextEventErrorStateDevSoundAdaptorBeingPreempted() // from CDevCommonControl
   517     {
   531     {
   518     DP_CONTEXT(CDevCommonControl::ContextEvent, CtxDevSound, DPLOCAL);
   532     DP_CONTEXT(CDevCommonControl::ContextEventErrorStateDevSoundAdaptorBeingPreempted, CtxDevSound, DPLOCAL);
   519     DP_IN();
   533     DP_IN();
   520     
   534     
   521 __ASSERT_DEBUG(iDevAudio->iActiveStreamState == EInitialized, Panic(EStreamBeingDemotedToEIdle));
   535 __ASSERT_DEBUG(iDevAudio->iActiveStreamState == EInitialized, Panic(EStreamBeingDemotedToEIdle));
   522     FinishWithError(KErrInUse);
   536     FinishWithError(KErrInUse);
   523 
   537 
   530     }
   544     }
   531 
   545 
   532 
   546 
   533 void CDevCommonControl::ContextEventUpdateWithoutStateEventNoError() // from CDevCommonControl
   547 void CDevCommonControl::ContextEventUpdateWithoutStateEventNoError() // from CDevCommonControl
   534     {
   548     {
   535     DP_CONTEXT(CDevCommonControl::ContextEvent, CtxDevSound, DPLOCAL);
   549     DP_CONTEXT(CDevCommonControl::ContextEventUpdateWithoutStateEventNoError, CtxDevSound, DPLOCAL);
   536     DP_IN();
   550     DP2_IN("iActiveState=%d iIgnoreAsyncOpComplete=%d",iDevAudio->iActiveState, iIgnoreAsyncOpComplete);
   537     
   551     
   538     if (iDevAudio->iActiveState != EDevSoundAdaptorRemovingProcessingUnits)
   552     if (iDevAudio->iActiveState != EDevSoundAdaptorRemovingProcessingUnits)
   539         {
   553         {
   540         iAdaptationObserver->AsynchronousOperationComplete(KErrNone, ETrue);
   554 	    if (iIgnoreAsyncOpComplete)
       
   555 	      {
       
   556 	      iAdaptationObserver->PreemptionFinishedCallbackReceived(ETrue);
       
   557 	      iIgnoreAsyncOpComplete = EFalse;
       
   558 	      }
       
   559 	    else
       
   560 	      {
       
   561 	      iAdaptationObserver->AsynchronousOperationComplete(KErrNone, ETrue);
       
   562 	      }
   541         DP_OUT();
   563         DP_OUT();
   542         return;
   564         return;
   543         }
   565         }
   544 
   566 
   545     iDevAudio->iActiveState = EDevSoundAdaptorCreated_Uninitialised;
   567     iDevAudio->iActiveState = EDevSoundAdaptorCreated_Uninitialised;
   566     }
   588     }
   567 
   589 
   568 
   590 
   569 void CDevCommonControl::ContextEventUpdateWithoutStateEventButWithError(TInt aError) // from CDevCommonControl
   591 void CDevCommonControl::ContextEventUpdateWithoutStateEventButWithError(TInt aError) // from CDevCommonControl
   570     {
   592     {
   571     DP_CONTEXT(CDevCommonControl::ContextEvent, CtxDevSound, DPLOCAL);
   593     DP_CONTEXT(CDevCommonControl::ContextEventUpdateWithoutStateEventButWithError, CtxDevSound, DPLOCAL);
   572     DP_IN();
   594     DP_IN();
   573     
   595     
   574 	// NOTE: If no state change then do NOT complete the event.
       
   575 	
       
   576     // NOTE: We shouldn't actually be in any of the states below when calling this function.
   596     // NOTE: We shouldn't actually be in any of the states below when calling this function.
   577     //       But just in case we are we will rewind the state before dealing with the error. 
   597     //       But just in case we are we will rewind the state before dealing with the error. 
   578     switch (iDevAudio->iActiveState)
   598     switch (iDevAudio->iActiveState)
   579         {
   599         {
   580     case EDevSoundAdaptorInitialising:
   600     case EDevSoundAdaptorInitialising:
   600     }
   620     }
   601 
   621 
   602 
   622 
   603 void CDevCommonControl::ContextEventUpdateWithStateEventNoError() // from CDevCommonControl 
   623 void CDevCommonControl::ContextEventUpdateWithStateEventNoError() // from CDevCommonControl 
   604     {
   624     {
   605     DP_CONTEXT(CDevCommonControl::ContextEvent, CtxDevSound, DPLOCAL);
   625     DP_CONTEXT(CDevCommonControl::ContextEventUpdateWithStateEventNoError, CtxDevSound, DPLOCAL);
   606     DP_IN();
   626     DP_IN();
   607 
   627 
   608     switch (iDevAudio->iActiveState)
   628     switch (iDevAudio->iActiveState)
   609         {
   629         {
   610     case EDevSoundAdaptorUninitialising:
   630     case EDevSoundAdaptorUninitialising:
   655     }
   675     }
   656 
   676 
   657 
   677 
   658 void CDevCommonControl::ContextEventUpdateWithStateEventAndError(TInt aError) // from CDevCommonControl
   678 void CDevCommonControl::ContextEventUpdateWithStateEventAndError(TInt aError) // from CDevCommonControl
   659     {
   679     {
   660     DP_CONTEXT(CDevCommonControl::ContextEvent, CtxDevSound, DPLOCAL);
   680     DP_CONTEXT(CDevCommonControl::ContextEventUpdateWithStateEventAndError, CtxDevSound, DPLOCAL);
   661     DP_IN();
   681     DP_IN();
   662 
   682 
   663     DP1(DLERR,"ContextEvent error=%d", aError);
   683     DP1(DLERR,"ContextEventUpdateWithStateEventAndError error=%d", aError);
   664     
   684     
   665     switch(iDevAudio->iActiveState)
   685     switch(iDevAudio->iActiveState)
   666         {
   686         {
   667     case EDevSoundAdaptorInitialising:
   687     case EDevSoundAdaptorInitialising:
   668         iDevAudio->iActiveState = EDevSoundAdaptorCreated_Uninitialised;
   688         iDevAudio->iActiveState = EDevSoundAdaptorCreated_Uninitialised;