mmserv/tms/tmscallserver/src/tmscsdevsound.cpp
branchRCL_3
changeset 19 095bea5f582e
parent 17 60e492b28869
child 20 0ac9a5310753
equal deleted inserted replaced
18:a36789189b53 19:095bea5f582e
    14  * Description: Telephony Multimedia Service
    14  * Description: Telephony Multimedia Service
    15  *
    15  *
    16  */
    16  */
    17 
    17 
    18 #include <AudioPreference.h>
    18 #include <AudioPreference.h>
       
    19 #include <tms.h>
    19 #include <S60FourCC.h>
    20 #include <S60FourCC.h>
    20 #include "tmsutility.h"
    21 #include "tmsutility.h"
    21 #include "tmscsdevsound.h"
    22 #include "tmscsdevsound.h"
    22 #include "tmscsdevsoundobserver.h"
    23 #include "tmscsdevsoundobserver.h"
    23 
    24 
    24 using namespace TMS;
    25 using namespace TMS;
    25 
    26 
    26 // -----------------------------------------------------------------------------
    27 // CONSTANTS
    27 // TMSCSPDevSound
    28 const gint KTimeoutInitial = 250000; // 250 ms initial timeout
       
    29 const gint KTimeoutMultiplier = 2;   // Double the timeout for each retry
       
    30 const gint KPeriodicTimeoutMax = 2000000; // 2 sec max periodic timeout
       
    31 const gint KMicroSecMultiply = 1000000;   // 1 sec
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // TMSCSDevSound
    28 // -----------------------------------------------------------------------------
    35 // -----------------------------------------------------------------------------
    29 //
    36 //
    30 TMSCSDevSound::TMSCSDevSound(TMSCSDevSoundObserver& observer) :
    37 TMSCSDevSound::TMSCSDevSound(TMSCSDevSoundObserver& observer) :
    31     iObserver(observer)
    38     iObserver(observer)
    32     {
    39     {
       
    40     iTimer = NULL;
       
    41     iPeriodic = KTimeoutInitial;
       
    42     iElapsedTime = 0;
       
    43     iInitRetryTime = 0;
       
    44     iStartRetryTime = 0;
    33     }
    45     }
    34 
    46 
    35 // -----------------------------------------------------------------------------
    47 // -----------------------------------------------------------------------------
    36 // ConstructL
    48 // ConstructL
    37 // -----------------------------------------------------------------------------
    49 // -----------------------------------------------------------------------------
    38 //
    50 //
    39 void TMSCSDevSound::ConstructL(const TMSStreamType strmtype)
    51 void TMSCSDevSound::ConstructL(const TMSStreamType strmtype,
    40     {
    52         const gint retrytime)
    41     TRACE_PRN_FN_ENT;
    53     {
       
    54     TRACE_PRN_FN_ENT;
       
    55     iInitRetryTime = retrytime;
    42     iStreamType = strmtype;
    56     iStreamType = strmtype;
    43 
    57 
    44     if (strmtype == TMS_STREAM_UPLINK)
    58     if (strmtype == TMS_STREAM_UPLINK)
    45         {
    59         {
    46         iMode = EMMFStateRecording;
    60         iMode = EMMFStateRecording;
    51         {
    65         {
    52         iMode = EMMFStatePlaying;
    66         iMode = EMMFStatePlaying;
    53         iPriority = KAudioPriorityCSCallDownlink;
    67         iPriority = KAudioPriorityCSCallDownlink;
    54         iPreference = KAudioPrefCSCallDownlink;
    68         iPreference = KAudioPrefCSCallDownlink;
    55         }
    69         }
       
    70 
       
    71     iTimer = TMSTimer::NewL();
    56     InitializeL();
    72     InitializeL();
    57     TRACE_PRN_FN_EXT;
    73     TRACE_PRN_FN_EXT;
    58     }
    74     }
    59 
    75 
    60 // -----------------------------------------------------------------------------
    76 // -----------------------------------------------------------------------------
    92 // Not implemented
   108 // Not implemented
    93 // -----------------------------------------------------------------------------
   109 // -----------------------------------------------------------------------------
    94 //
   110 //
    95 TMSCSDevSound::~TMSCSDevSound()
   111 TMSCSDevSound::~TMSCSDevSound()
    96     {
   112     {
       
   113     TRACE_PRN_FN_ENT;
       
   114     CancelTimer();
       
   115     delete iTimer;
    97     delete iDevSound;
   116     delete iDevSound;
       
   117     TRACE_PRN_FN_EXT;
    98     }
   118     }
    99 
   119 
   100 // -----------------------------------------------------------------------------
   120 // -----------------------------------------------------------------------------
   101 // Tries to activate the audio stream if not already active or activating
   121 // Tries to activate the audio stream if not already active or activating
   102 // -----------------------------------------------------------------------------
   122 // -----------------------------------------------------------------------------
   103 //
   123 //
   104 void TMSCSDevSound::Activate()
   124 void TMSCSDevSound::Activate(const gint retrytime)
   105     {
   125     {
       
   126     iStartRetryTime = retrytime;
       
   127 
   106     if (!iActive && !iActivationOngoing)
   128     if (!iActive && !iActivationOngoing)
   107         {
   129         {
   108         iActivationOngoing = ETrue;
   130         iActivationOngoing = ETrue;
   109         TRAP_IGNORE(DoActivateL());
   131         TRAP_IGNORE(DoActivateL());
   110         }
   132         }
   112 
   134 
   113 // -----------------------------------------------------------------------------
   135 // -----------------------------------------------------------------------------
   114 // Deactivates the audio device.
   136 // Deactivates the audio device.
   115 // -----------------------------------------------------------------------------
   137 // -----------------------------------------------------------------------------
   116 //
   138 //
   117 void TMSCSDevSound::Deactivate()
   139 void TMSCSDevSound::Deactivate(gboolean reset)
   118     {
   140     {
       
   141     TRACE_PRN_FN_ENT;
       
   142     if (reset)
       
   143         {
       
   144         iPeriodic = KTimeoutInitial;
       
   145         }
       
   146     CancelTimer();
   119     if (iDevSound && (iActive || iActivationOngoing))
   147     if (iDevSound && (iActive || iActivationOngoing))
   120         {
   148         {
   121         iDevSound->Stop();
   149         iDevSound->Stop();
   122         iActive = EFalse;
   150         iActive = EFalse;
   123         iActivationOngoing = EFalse;
   151         iActivationOngoing = EFalse;
   124         }
   152         }
       
   153     TRACE_PRN_FN_EXT;
   125     }
   154     }
   126 
   155 
   127 // -----------------------------------------------------------------------------
   156 // -----------------------------------------------------------------------------
   128 // DevSound
   157 // DevSound
   129 // -----------------------------------------------------------------------------
   158 // -----------------------------------------------------------------------------
   138 // -----------------------------------------------------------------------------
   167 // -----------------------------------------------------------------------------
   139 //
   168 //
   140 void TMSCSDevSound::InitializeComplete(TInt aError)
   169 void TMSCSDevSound::InitializeComplete(TInt aError)
   141     {
   170     {
   142     TRACE_PRN_FN_ENT;
   171     TRACE_PRN_FN_ENT;
   143     if (aError == TMS_RESULT_SUCCESS)
   172     if (aError != TMS_RESULT_SUCCESS && iInitRetryTime != 0)
   144         {
   173         {
       
   174         StartTimer();
       
   175         }
       
   176     else
       
   177         {
       
   178         iPeriodic = KTimeoutInitial;
       
   179         CancelTimer();
   145         NotifyEvent(aError);
   180         NotifyEvent(aError);
   146         }
   181         }
       
   182     TRACE_PRN_IF_ERR(aError);
   147     TRACE_PRN_FN_EXT;
   183     TRACE_PRN_FN_EXT;
   148     }
   184     }
   149 
   185 
   150 // -----------------------------------------------------------------------------
   186 // -----------------------------------------------------------------------------
   151 // TMSCSDevSound::NotifyEvent
   187 // TMSCSDevSound::NotifyEvent
   161         {
   197         {
   162         iObserver.UplinkInitCompleted(error);
   198         iObserver.UplinkInitCompleted(error);
   163         }
   199         }
   164     }
   200     }
   165 
   201 
       
   202 // -----------------------------------------------------------------------------
       
   203 // TMSCSDevSound::CancelTimer
       
   204 // Resets timer
       
   205 // -----------------------------------------------------------------------------
       
   206 //
       
   207 void TMSCSDevSound::CancelTimer()
       
   208     {
       
   209     iInitRetryTime = 0;
       
   210     iStartRetryTime = 0;
       
   211     iElapsedTime = 0;
       
   212 
       
   213     if (iTimer)
       
   214         {
       
   215         if (iTimer->IsRunning())
       
   216             {
       
   217             iTimer->CancelNotify();
       
   218             }
       
   219         }
       
   220     }
       
   221 
       
   222 // -----------------------------------------------------------------------------
       
   223 // TMSCSDevSound::StartTimer
       
   224 // Activates timer
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 void TMSCSDevSound::StartTimer()
       
   228     {
       
   229     if (iTimer && (iInitRetryTime != 0 || iStartRetryTime != 0))
       
   230         {
       
   231         iTimer->NotifyAfter(iPeriodic, *this);
       
   232         }
       
   233     }
       
   234 
       
   235 // -----------------------------------------------------------------------------
       
   236 // From TMSTimerObserver
       
   237 // Notification upon TMSTimer timeout.
       
   238 // -----------------------------------------------------------------------------
       
   239 //
       
   240 void TMSCSDevSound::TimerEvent()
       
   241     {
       
   242     if (iPeriodic < KPeriodicTimeoutMax)
       
   243         {
       
   244         iPeriodic *= KTimeoutMultiplier;
       
   245         }
       
   246     iElapsedTime += iPeriodic;
       
   247 
       
   248     if (!iActivationOngoing) //Initializing
       
   249         {
       
   250         if (iElapsedTime >= (iInitRetryTime * KMicroSecMultiply))
       
   251             {
       
   252             iInitRetryTime = 0; //timer will not start again
       
   253             }
       
   254         TRAPD(status, InitializeL());
       
   255         if (status != TMS_RESULT_SUCCESS)
       
   256             {
       
   257             NotifyEvent(status);
       
   258             }
       
   259         }
       
   260     else //Activating
       
   261         {
       
   262         if (iElapsedTime >= (iStartRetryTime * KMicroSecMultiply))
       
   263             {
       
   264             iStartRetryTime = 0; //timer will not start again
       
   265             }
       
   266         Deactivate(FALSE);
       
   267         Activate(iStartRetryTime);
       
   268         }
       
   269     }
       
   270 
   166 //  End of File
   271 //  End of File