mpx/playbackframework/playbackengine/src/mpxautoresumehandler.cpp
branchRCL_3
changeset 17 780c925249c1
parent 0 a2952bb97e68
child 55 6c1dfe4da5dd
equal deleted inserted replaced
15:d240f0a77280 17:780c925249c1
    23 #include "mpxplaybackengine.h"
    23 #include "mpxplaybackengine.h"
    24 #include "mpxautoresumehandler.h"
    24 #include "mpxautoresumehandler.h"
    25 
    25 
    26 // CONSTANTS
    26 // CONSTANTS
    27 const TInt KMPXErrDiedTimeout = 2000000;
    27 const TInt KMPXErrDiedTimeout = 2000000;
    28 
       
    29 // Time to wait before resume after call has ended.
    28 // Time to wait before resume after call has ended.
    30 const TInt KMPXResumeWaitTime = 3000000; // 3.0s
    29 const TInt KMPXResumeWaitTime = 3000000; // 3.0s
    31 
    30 
       
    31 // TODO: the following constants and definitions are copied from nssvascoreconstant.h, which is not
       
    32 // included directly because it is an App layer API. Way to fix this is to ask Speechsrv to move the header file to MW layer.
       
    33 const TUid KSINDUID = {KUidSystemCategoryValue};
       
    34 const TInt ERecognitionState=0;
       
    35 
       
    36 // Recognition state values for the P&S key ERecognitionState
       
    37 enum TRecognitionStateValues
       
    38     {
       
    39     ERecognitionStarted = 0, 
       
    40     ERecognitionSpeechEnd, 
       
    41     ERecognitionSuccess, 
       
    42     ERecognitionFail
       
    43     };
       
    44 // End TODO
    32 
    45 
    33 
    46 
    34 // ================= MEMBER FUNCTIONS =======================
    47 // ================= MEMBER FUNCTIONS =======================
    35 
    48 
    36 
    49 
    58                                             KCTsyCallState,this);
    71                                             KCTsyCallState,this);
    59 
    72 
    60     // Listen to call type changes
    73     // Listen to call type changes
    61     iTypeObserver = CMPXPSKeyWatcher::NewL(KPSUidCtsyCallInformation,
    74     iTypeObserver = CMPXPSKeyWatcher::NewL(KPSUidCtsyCallInformation,
    62                                            KCTsyCallType,this);
    75                                            KCTsyCallType,this);
       
    76     
       
    77     iVoiceCmdObserver = CMPXPSKeyWatcher::NewL( KSINDUID, ERecognitionState, this );
       
    78     
    63     iResumeTimer = CPeriodic::NewL(CActive::EPriorityStandard);
    79     iResumeTimer = CPeriodic::NewL(CActive::EPriorityStandard);
    64     }
    80     }
    65 
    81 
    66 // -----------------------------------------------------------------------------
    82 // -----------------------------------------------------------------------------
    67 // Constructs a new entry with given values.
    83 // Constructs a new entry with given values.
    86 // Destructor
   102 // Destructor
    87 // -----------------------------------------------------------------------------
   103 // -----------------------------------------------------------------------------
    88 //
   104 //
    89 CMPXAutoResumeHandler::~CMPXAutoResumeHandler()
   105 CMPXAutoResumeHandler::~CMPXAutoResumeHandler()
    90     {
   106     {
       
   107     delete iVoiceCmdObserver;
    91     delete iStateObserver;
   108     delete iStateObserver;
    92     delete iTypeObserver;
   109     delete iTypeObserver;
    93     if ( iResumeTimer )
   110     if ( iResumeTimer )
    94         {
   111         {
    95         CancelResumeTimer();
   112         CancelResumeTimer();
   133 void CMPXAutoResumeHandler::HandlePlaybackComplete(TInt aError)
   150 void CMPXAutoResumeHandler::HandlePlaybackComplete(TInt aError)
   134     {
   151     {
   135     MPX_DEBUG2("CMPXAutoResumeHandler::HandlePlaybackComplete(%d) entering", aError);
   152     MPX_DEBUG2("CMPXAutoResumeHandler::HandlePlaybackComplete(%d) entering", aError);
   136     iPausedForCall = EFalse;
   153     iPausedForCall = EFalse;
   137     if ( KErrDied == aError ||
   154     if ( KErrDied == aError ||
   138          KErrAccessDenied == aError )
   155          KErrAccessDenied == aError || 
       
   156          KErrInUse == aError )
   139         {
   157         {
   140         iKErrDiedTime.HomeTime();
   158         iKErrDiedTime.HomeTime();
   141 
   159 
   142         TInt callType = EPSCTsyCallTypeNone;
   160         TInt callType = EPSCTsyCallTypeNone;
   143         TInt callState = EPSCTsyCallStateNone;
   161         TInt callState = EPSCTsyCallStateNone;
   144 
   162         TInt voiceCmdState(0);
       
   163         
   145         if (!iTypeObserver->GetValue(callType) &&
   164         if (!iTypeObserver->GetValue(callType) &&
   146             !iStateObserver->GetValue(callState))
   165             !iStateObserver->GetValue(callState))
   147             {
   166             {
   148             if ((callState == EPSCTsyCallStateRinging && iMixerSupport) ||
   167             if ((callState == EPSCTsyCallStateRinging && iMixerSupport) ||
   149                  ShouldPause())
   168                  ShouldPause())
   153                 // due to phone call being connected. Enable
   172                 // due to phone call being connected. Enable
   154                 // autoresume.
   173                 // autoresume.
   155                 iPausedForCall = ETrue;
   174                 iPausedForCall = ETrue;
   156                 }
   175                 }
   157             }
   176             }
   158         }
   177         
   159     MPX_DEBUG1("CMPXAutoResumeHandler::HandlePlaybackComplete() exiting");
   178         if ( !iPausedForCall && !iVoiceCmdObserver->GetValue( voiceCmdState ) ) // key exist if voice commanding is in progress
       
   179             {
       
   180             // Paused due voice command activity
       
   181             iPausedForVoiceCmd = ETrue;
       
   182             }
       
   183         }
       
   184     
       
   185     MPX_DEBUG3("CMPXAutoResumeHandler::HandlePlaybackComplete() exiting: iPausedForCall=%d, iPausedForVoiceCmd=%d",
       
   186                iPausedForCall, iPausedForVoiceCmd);
   160     }
   187     }
   161 
   188 
   162 // -----------------------------------------------------------------------------
   189 // -----------------------------------------------------------------------------
   163 // CMPXAutoResumeHandler::CancelResumeTimer
   190 // CMPXAutoResumeHandler::CancelResumeTimer
   164 // -----------------------------------------------------------------------------
   191 // -----------------------------------------------------------------------------
   173 
   200 
   174 // -----------------------------------------------------------------------------
   201 // -----------------------------------------------------------------------------
   175 // CMPXAutoResumeHandler::HandlePSEvent
   202 // CMPXAutoResumeHandler::HandlePSEvent
   176 // -----------------------------------------------------------------------------
   203 // -----------------------------------------------------------------------------
   177 //
   204 //
   178 void CMPXAutoResumeHandler::HandlePSEvent(TUid /*aUid*/, TInt /*aKey*/)
   205 void CMPXAutoResumeHandler::HandlePSEvent(TUid aUid, TInt /*aKey*/)
   179     {
   206     {
   180     MPX_FUNC("CMPXAutoResumeHandler::HandlePSEvent()");
   207     MPX_FUNC("CMPXAutoResumeHandler::HandlePSEvent()");
   181     TRAP_IGNORE(DoHandleStateChangeL());
   208     
       
   209     if ( aUid == KSINDUID )
       
   210         {
       
   211         DoHandleVoiceCmdChange();
       
   212         }
       
   213     else
       
   214         {
       
   215         TRAP_IGNORE(DoHandleStateChangeL());
       
   216         }
   182     }
   217     }
   183 
   218 
   184 // -----------------------------------------------------------------------------
   219 // -----------------------------------------------------------------------------
   185 // CMPXAutoResumeHandler::DoHandleStateChangeL
   220 // CMPXAutoResumeHandler::DoHandleStateChangeL
   186 // -----------------------------------------------------------------------------
   221 // -----------------------------------------------------------------------------
   244             {
   279             {
   245             iResumeTimer->Cancel();
   280             iResumeTimer->Cancel();
   246             iPausedForCall = ETrue;
   281             iPausedForCall = ETrue;
   247             }
   282             }
   248         }
   283         }
       
   284     
       
   285     if ( shouldPause && iVoiceCmdResumeOngoing )
       
   286         {
       
   287         // Resume timer has been started after a voice command, cancel it now
       
   288         // so that playback is not resumed while calling
       
   289         if ( iResumeTimer->IsActive() )
       
   290             {
       
   291             iResumeTimer->Cancel();
       
   292             }
       
   293         iVoiceCmdResumeOngoing = EFalse;
       
   294         iPausedForCall = ETrue; // resume playback once call has been ended
       
   295         }
       
   296     
   249     MPX_DEBUG2("CMPXAutoResumeHandler::DoHandleStateChangeL(): iPausedForCall = %d", iPausedForCall);
   297     MPX_DEBUG2("CMPXAutoResumeHandler::DoHandleStateChangeL(): iPausedForCall = %d", iPausedForCall);
   250     }
   298     }
   251 
   299 
   252 // -----------------------------------------------------------------------------
   300 // -----------------------------------------------------------------------------
   253 // CMPXAutoResumeHandler::ShouldPause
   301 // CMPXAutoResumeHandler::ShouldPause
   315 //
   363 //
   316 void CMPXAutoResumeHandler::HandleResumeTimerCallback()
   364 void CMPXAutoResumeHandler::HandleResumeTimerCallback()
   317     {
   365     {
   318     MPX_FUNC("CMPXAutoResumeHandler::HandleResumeTimerCallback() entering");
   366     MPX_FUNC("CMPXAutoResumeHandler::HandleResumeTimerCallback() entering");
   319 
   367 
       
   368     iVoiceCmdResumeOngoing = EFalse;
       
   369     
   320     CancelResumeTimer();
   370     CancelResumeTimer();
   321     TRAP_IGNORE( iEngine.HandleCommandL( EPbCmdPlayWithFadeIn ));
   371     TRAP_IGNORE( iEngine.HandleCommandL( EPbCmdPlayWithFadeIn ));
   322     }
   372     }
   323 
   373 
   324 // -----------------------------------------------------------------------------
   374 // -----------------------------------------------------------------------------
   372     {
   422     {
   373     MPX_DEBUG2("CMPXAutoResumeHandler::SetAutoResume(): AutoResume = %d", aAutoResume);
   423     MPX_DEBUG2("CMPXAutoResumeHandler::SetAutoResume(): AutoResume = %d", aAutoResume);
   374     iAutoResume = aAutoResume;
   424     iAutoResume = aAutoResume;
   375     }
   425     }
   376 
   426 
       
   427 // -----------------------------------------------------------------------------
       
   428 // CMPXAutoResumeHandler::DoHandleVoiceCmdChange
       
   429 // -----------------------------------------------------------------------------
       
   430 //
       
   431 void CMPXAutoResumeHandler::DoHandleVoiceCmdChange()
       
   432     {
       
   433     MPX_FUNC("CMPXAutoResumeHandler::DoHandleVoiceCmdChange()");
       
   434     
       
   435     TInt voiceCmdState( 0 );
       
   436     TInt err( iVoiceCmdObserver->GetValue( voiceCmdState ) );
       
   437     
       
   438     MPX_DEBUG4("CMPXAutoResumeHandler::DoHandleVoiceCmdChange(): iPausedForVoiceCmd = %d, err=%d, state=%d", 
       
   439                     iPausedForVoiceCmd, err, voiceCmdState);
       
   440     
       
   441     if ( iPausedForVoiceCmd && !iPausedForCall )
       
   442         {
       
   443         if ( err == KErrNotFound ) // voice command has been finished once the P&S key is deleted 
       
   444             {
       
   445             if ( iResumeTimer->IsActive() )
       
   446                   iResumeTimer->Cancel();
       
   447             
       
   448             iResumeTimer->Start( KMPXResumeWaitTime, KMPXResumeWaitTime, TCallBack(ResumeTimerCallback, this) );
       
   449             
       
   450             iPausedForVoiceCmd = EFalse;
       
   451             
       
   452             iVoiceCmdResumeOngoing = ETrue; // flag for cancelling resume timer due to a call
       
   453             }
       
   454         }
       
   455     
       
   456     if ( iPausedForCall ) // ensure that not interfering with call handling in any circumstances
       
   457         {
       
   458         iPausedForVoiceCmd = EFalse;
       
   459         }
       
   460     }
       
   461 
   377 //  End of File
   462 //  End of File