Fix for 37272 37208 37254
[apps/osp/Call.git] / src / CallSoundManager.cpp
index c66928a..e3ca156 100644 (file)
@@ -41,6 +41,10 @@ SoundManager::SoundManager(void)
        , __pVibrator(null)
        , __pPlayer(null)
        , __lastEndedConferenceCall(false)
+       , __pConnectPlayer(null)
+       , __pDisconnectPlayer(null)
+       , __pReminderPlayer(null)
+       , __pWaitingTonePlayer(null)
 {
        __timer.Construct(*this);
        __isSoundStatusOn = false;
@@ -56,10 +60,32 @@ SoundManager::~SoundManager(void)
        if (__pVibrator != null)
        {
                delete __pVibrator;
+               __pVibrator = null;
        }
        if (__pPlayer != null)
        {
                delete __pPlayer;
+               __pPlayer = null;
+       }
+       if(__pConnectPlayer != null)
+       {
+               delete __pConnectPlayer;
+               __pConnectPlayer = null;
+       }
+       if(__pDisconnectPlayer != null)
+       {
+               delete __pDisconnectPlayer;
+               __pDisconnectPlayer = null;
+       }
+       if(__pReminderPlayer != null)
+       {
+               delete __pReminderPlayer;
+               __pReminderPlayer = null;
+       }
+       if(__pWaitingTonePlayer != null)
+       {
+               delete __pWaitingTonePlayer;
+               __pWaitingTonePlayer = null;
        }
 
 }
@@ -201,49 +227,51 @@ SoundManager::OnTimerExpired(Timer& timer)
        vconf_get_bool(VCONFKEY_CISSAPPL_MINUTE_MINDER_BOOL, &unknownRejectStatus);
        bool ReminderToneSetStatus = unknownRejectStatus;
        result res = E_FAILURE;
+       reminderTonePath.Append(MINUTEREMINDERTONE_PATH);
 
        if(ReminderToneSetStatus == true)
        {
 
-               if(__pPlayer == null)
+               if(__pReminderPlayer == null)
                {
-                       __pPlayer =  new (std::nothrow) Player();
-                       res = __pPlayer->Construct(*this);
-                       if(res != E_SUCCESS)
+
+                       if(reminderTonePath.IsEmpty() == false)
                        {
-                               AppLogDebug("__pPlayer Construct failed with %d",res);
-                               return;
+                               __pReminderPlayer =  new (std::nothrow) Player();
+                               res = __pReminderPlayer->Construct(*this);
+                               if(res != E_SUCCESS)
+                               {
+                                       AppLogDebug("__pReminderPlayer Construct failed with %d",res);
+                                       return;
+                               }
+                               res = __pReminderPlayer->OpenFile(reminderTonePath,false);
+                               if(res != E_SUCCESS)
+                               {
+                                       AppLogDebug("__pReminderPlayer OpenFile failed with %d",res);
+                                       return;
+                               }
+                               res = __pReminderPlayer->SetLooping(false);
+                               if(res != E_SUCCESS)
+                               {
+                                       AppLogDebug("__pReminderPlayer SetLooping failed with %d",res);
+                                       return;
+                               }
+                               res = __pReminderPlayer->SetVolume(80);
+                               if(res != E_SUCCESS)
+                               {
+                                       AppLogDebug("__pReminderPlayer SetVolume failed with %d",res);
+                                       return;
+                               }
                        }
                }
 
-               reminderTonePath.Append(MINUTEREMINDERTONE_PATH);
-               if(reminderTonePath.IsEmpty() == false)
+               if(__pReminderPlayer != null)
                {
-                       __pPlayer->Stop();
-                       __pPlayer->Close();
-                       res = __pPlayer->OpenFile(reminderTonePath,false);
-                       if(res != E_SUCCESS)
-                       {
-                               AppLogDebug("__pPlayer OpenFile failed with %d",res);
-                               return;
-                       }
-                       res = __pPlayer->SetLooping(false);
-                       if(res != E_SUCCESS)
-                       {
-                               AppLogDebug("__pPlayer SetLooping failed with %d",res);
-                               return;
-                       }
-                       res = __pPlayer->SetVolume(80);
-                       if(res != E_SUCCESS)
-                       {
-                               AppLogDebug("__pPlayer SetVolume failed with %d",res);
-                               return;
-                       }
                        SetSoundMode(SOUND_MODE_MEDIA);
-                       res = __pPlayer->Play();
+                       res = __pReminderPlayer->Play();
                        if(res != E_SUCCESS)
                        {
-                               AppLogDebug("__pPlayer Play failed with %d",res);
+                               AppLogDebug("__pReminderPlayer Play failed with %d",res);
                                return;
                        }
                        SetSoundMode(SOUND_MODE_VOICE);
@@ -273,73 +301,75 @@ SoundManager::SetDisconnectTone(void)
        {
                AppLogDebug("disconnectToneSetStatus == true");
                disconnectTonePath.Append(CALLDISCONNECTTONE_PATH);
-               if(__pPlayer == null)
+               if(disconnectTonePath.IsEmpty() == false)
                {
-                       AppLogDebug("__pPlayer == null");
-                       __pPlayer =  new (std::nothrow) Player();
-                       res = __pPlayer->Construct(*this);
-                       if(res != E_SUCCESS)
+                       if(__pDisconnectPlayer == null)
                        {
-                               AppLogDebug("__pPlayer Construct failed with %d",res);
-                               return;
-                       }
+                               AppLogDebug("__pConnectPlayer == null");
+                               __pDisconnectPlayer =  new (std::nothrow) Player();
+                               res = __pDisconnectPlayer->Construct(*this);
+                               if(res != E_SUCCESS)
+                               {
+                                       AppLogDebug("__pDisconnectPlayer Construct failed with %d",res);
+                                       return;
+                               }
+                               res = __pDisconnectPlayer->OpenFile(disconnectTonePath,false);
+                               if(res != E_SUCCESS)
+                               {
+                                       AppLogDebug("__pDisconnectPlayer OpenFile failed with %d",res);
+                                       return;
+                               }
+                               res = __pDisconnectPlayer->SetLooping(false);
+                               if(res != E_SUCCESS)
+                               {
+                                       AppLogDebug("__pDisconnectPlayer SetLooping failed with %d",res);
+                                       return;
+                               }
+                               res = __pDisconnectPlayer->SetVolume(80);
+                               if(res != E_SUCCESS)
+                               {
+                                       AppLogDebug("__pDisconnectPlayer SetLooping SetVolume with %d",res);
+                                       return;
+                               }
 
+                       }
                }
-               if(disconnectTonePath.IsEmpty() == false)
+
+               if(__pDisconnectPlayer != null)
                {
-                       __pPlayer->Stop();
-                       __pPlayer->Close();
-                       AppLogDebug("__pPlayer OpenFile %ls",disconnectTonePath.GetPointer());
-                       res = __pPlayer->OpenFile(disconnectTonePath,false);
-                       if(res != E_SUCCESS)
-                       {
-                               AppLogDebug("__pPlayer OpenFile failed with %d",res);
-                               return;
-                       }
-                       res = __pPlayer->SetLooping(false);
-                       if(res != E_SUCCESS)
-                       {
-                               AppLogDebug("__pPlayer SetLooping failed with %d",res);
-                               return;
-                       }
-                       res = __pPlayer->SetVolume(80);
-                       if(res != E_SUCCESS)
+                       AppLogDebug("__pDisconnectPlayer OpenFile %ls",disconnectTonePath.GetPointer());
+                       SetSoundMode(SOUND_MODE_MEDIA);
+                       AppLogDebug("__pDisconnectPlayer SetVolume");
+                       if(__pDisconnectPlayer->GetState() == PLAYER_STATE_PLAYING)
                        {
-                               AppLogDebug("__pPlayer SetLooping SetVolume with %d",res);
-                               return;
+                               __pDisconnectPlayer->Stop();
                        }
-                       SetSoundMode(SOUND_MODE_MEDIA);
-                       AppLogDebug("__pPlayer SetVolume");
-                       res = __pPlayer->Play();
+                       res = __pDisconnectPlayer->Play();
                        if(res != E_SUCCESS)
                        {
-                               AppLogDebug("__pPlayer Play with %d",res);
+                               AppLogDebug("__pDisconnectPlayer Play with %d",res);
                                return;
                        }
                }
+
        }
+
+
+
+
        AppLogDebug("Exit");
 
 }
 
 void
-SoundManager::SetMinuteReminderTone()
+SoundManager::SetMinuteReminderTone(void)
 {
-
-       int unknownRejectStatus = -1;
-       vconf_get_bool(VCONFKEY_CISSAPPL_MINUTE_MINDER_BOOL, &unknownRejectStatus);
-       bool reminderToneSetStatus = unknownRejectStatus;
-
-       if(reminderToneSetStatus == true)
-       {
-               __timer.StartAsRepeatable(60000);
-       }
-
+       __timer.StartAsRepeatable(60000);
 }
 
 
 void
-SoundManager::SetConnectTone()
+SoundManager::SetConnectTone(void)
 {
 
        String connectTonePath;
@@ -353,112 +383,126 @@ SoundManager::SetConnectTone()
        if(connectToneSetStatus == true)
        {
 
-               if(__pPlayer == null)
+               if(__pConnectPlayer == null)
                {
-                       __pPlayer =  new (std::nothrow) Player();
-                       res = __pPlayer->Construct(*this);
-                       if(res != E_SUCCESS)
+                       if (connectTonePath.IsEmpty() == false)
                        {
-                               AppLogDebug("__pPlayer Construct failed with %d",res);
-                               return;
+                               __pConnectPlayer =  new (std::nothrow) Player();
+                               res = __pConnectPlayer->Construct(*this);
+                               if(res != E_SUCCESS)
+                               {
+                                       AppLogDebug("__pConnectPlayer Construct failed with %d",res);
+                                       return;
+                               }
+                               res = __pConnectPlayer->OpenFile(connectTonePath,false);
+                               if(res != E_SUCCESS)
+                               {
+                                       AppLogDebug("__pConnectPlayer OpenFile failed with %d",res);
+                                       return;
+                               }
+                               res = __pConnectPlayer->SetLooping(false);
+                               if(res != E_SUCCESS)
+                               {
+                                       AppLogDebug("__pConnectPlayer SetLooping failed with %d",res);
+                                       return;
+                               }
+                               res = __pConnectPlayer->SetVolume(80);
+                               if(res != E_SUCCESS)
+                               {
+                                       AppLogDebug("__pConnectPlayer SetVolume failed with %d",res);
+                                       return;
+                               }
                        }
                }
-               if (connectTonePath.IsEmpty() == false)
-               {
 
-                       __pPlayer->Stop();
-                       __pPlayer->Close();
-                       res = __pPlayer->OpenFile(connectTonePath,false);
-                       if(res != E_SUCCESS)
-                       {
-                               AppLogDebug("__pPlayer OpenFile failed with %d",res);
-                               return;
-                       }
-                       res = __pPlayer->SetLooping(false);
-                       if(res != E_SUCCESS)
-                       {
-                               AppLogDebug("__pPlayer SetLooping failed with %d",res);
-                               return;
-                       }
-                       res = __pPlayer->SetVolume(80);
-                       if(res != E_SUCCESS)
-                       {
-                               AppLogDebug("__pPlayer SetVolume failed with %d",res);
-                               return;
-                       }
+               if(__pConnectPlayer != null)
+               {
                        res = SetSoundMode(SOUND_MODE_MEDIA);
-                       AppLogDebug("__pPlayer Playing connect tone");
-                       res = __pPlayer->Play();
+                       AppLogDebug("__pConnectPlayer Playing connect tone");
+                       res = __pConnectPlayer->Play();
                        if(res != E_SUCCESS)
                        {
-                               AppLogDebug("__pPlayer Play failed with %d",res);
+                               AppLogDebug("__pConnectPlayer Play failed with %d",res);
                                return;
                        }
                }
+
        }
+
+
 }
 
 void
-SoundManager::StartAlert(String& contactRingTone)
+SoundManager::SetWaitTone(void)
 {
+       CallAlertStatus status= CALL_ALERT_SOUND;
+       int alertStatus = -1;
        result res = E_FAILURE;
-       AppLogDebug("Enter");
-       if(__pSoundCallSession != null)
+       int retVal = vconf_get_int(VCONFKEY_CISSAPPL_ALERT_ON_CALL_INT, &alertStatus);
+       if (retVal == 0)
        {
-               CallAlertStatus status= CALL_ALERT_SOUND;
-               int alertStatus = -1;
-               int retVal = vconf_get_int(VCONFKEY_CISSAPPL_ALERT_ON_CALL_INT, &alertStatus);
-               if (retVal == 0)
-               {
-                       status = (CallAlertStatus) alertStatus;
-               }
-               AppLogDebug("No Alert already in call");
-               if(status == CALL_ALERT_SOUND)
+               status = (CallAlertStatus) alertStatus;
+       }
+       AppLogDebug("No Alert already in call");
+       if(status == CALL_ALERT_SOUND)
+       {
+               AppLogDebug("Playing alert tone");
+               String waitingTonePath;
+               waitingTonePath.Append(CALLWAITINGTONE_PATH);
+               if(__pWaitingTonePlayer == null)
                {
-                       AppLogDebug("Playing alert tone");
-                       String waitingTonePath;
-                       waitingTonePath.Append(CALLWAITINGTONE_PATH);
-                       if(__pPlayer == null)
-                       {
-                               __pPlayer =  new (std::nothrow) Player();
-                               res = __pPlayer->Construct(*this);
-                               if(res != E_SUCCESS)
-                               {
-                                       AppLogDebug("__pPlayer Construct failed with %d",res);
-                                       return;
-                               }
-                       }
                        if (waitingTonePath.IsEmpty() == false)
                        {
-                               __pPlayer->Stop();
-                               __pPlayer->Close();
-                               res = __pPlayer->OpenFile(waitingTonePath,false);
+                               __pWaitingTonePlayer =  new (std::nothrow) Player();
+                               res = __pWaitingTonePlayer->Construct(*this);
                                if(res != E_SUCCESS)
                                {
-                                       AppLogDebug("__pPlayer OpenFile failed with %d",res);
+                                       AppLogDebug("__pWaitingTonePlayer Construct failed with %d",res);
                                        return;
                                }
-                               res = __pPlayer->SetLooping(true);
+                               res = __pWaitingTonePlayer->OpenFile(waitingTonePath,false);
                                if(res != E_SUCCESS)
                                {
-                                       AppLogDebug("__pPlayer SetLooping failed with %d",res);
+                                       AppLogDebug("__pWaitingTonePlayer OpenFile failed with %d",res);
                                        return;
                                }
-                               res = __pPlayer->SetVolume(80);
+                               res = __pWaitingTonePlayer->SetLooping(true);
                                if(res != E_SUCCESS)
                                {
-                                       AppLogDebug("__pPlayer SetVolume failed with %d",res);
+                                       AppLogDebug("__pWaitingTonePlayer SetLooping failed with %d",res);
                                        return;
                                }
-                               SetSoundMode(SOUND_MODE_MEDIA);
-                               res = __pPlayer->Play();
+                               res = __pWaitingTonePlayer->SetVolume(80);
                                if(res != E_SUCCESS)
                                {
-                                       AppLogDebug("__pPlayer Play failed with %d",res);
+                                       AppLogDebug("__pWaitingTonePlayer SetVolume failed with %d",res);
                                        return;
                                }
                        }
                }
+
+               if( __pWaitingTonePlayer != null )
+               {
+                       SetSoundMode(SOUND_MODE_MEDIA);
+                       res = __pWaitingTonePlayer->Play();
+                       if(res != E_SUCCESS)
+                       {
+                               AppLogDebug("__pWaitingTonePlayer Play failed with %d",res);
+                               return;
+                       }
+               }
+
+       }
+}
+
+void
+SoundManager::StartAlert(String& contactRingTone)
+{
+       result res = E_FAILURE;
+       AppLogDebug("Enter");
+       if(__pSoundCallSession != null)
+       {
+               SetWaitTone();
                return;
        }
        else
@@ -515,7 +559,7 @@ SoundManager::StartAlert(String& contactRingTone)
                        ringTonePath.Clear();
                        ringTonePath.Append(RINGTONE_PATH);
                }
-               __pPlayer->Close();
+
                res = __pPlayer->OpenFile(ringTonePath,false);
                if(res != E_SUCCESS)
                {
@@ -560,7 +604,10 @@ SoundManager::StopAlert(void)
        {
                //todo: stop player
                AppLogDebug("Stopping ring tone");
-               res = __pPlayer->Stop();
+               if(__pPlayer->GetState() == PLAYER_STATE_PLAYING)
+               {
+                       res = __pPlayer->Stop();
+               }
                if(res != E_SUCCESS)
                {
                        AppLogDebug("__pPlayer Stop failed with %d",res);
@@ -581,6 +628,14 @@ SoundManager::StopAlert(void)
                __pVibrator->Stop();
                __isVibrateStatusOn = false;
        }
+       if(__pWaitingTonePlayer != null)
+       {
+               if(__pWaitingTonePlayer->GetState() == PLAYER_STATE_PLAYING)
+               {
+                       __pWaitingTonePlayer->Stop();
+               }
+       }
+
        AppLogDebug("Exit");
 }