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