phoneplugins/csplugin/src/tmshandler.cpp
changeset 65 2a5d4ab426d3
parent 27 2f8f8080a020
child 76 cfea66083b62
equal deleted inserted replaced
60:1eef62f5c541 65:2a5d4ab426d3
     9  * Initial Contributors:
     9  * Initial Contributors:
    10  * Nokia Corporation - initial contribution.
    10  * Nokia Corporation - initial contribution.
    11  *
    11  *
    12  * Contributors:
    12  * Contributors:
    13  *
    13  *
    14  * Description:  Starts and stops audio streams.
    14  * Description: Activates TMS call audio control streams.
    15  *
    15  *
    16  */
    16  */
    17 
    17 
    18 #include <tmsfactory.h>
    18 #include <tmsfactory.h>
    19 #include <tmscall.h>
    19 #include <tmscall.h>
    20 #include <tmsstream.h>
    20 #include <tmsstream.h>
    21 #include "tmshandler.h"
    21 #include "tmshandler.h"
    22 #include "csplogger.h"
    22 #include "csplogger.h"
    23 #include "csptimer.h"
       
    24 #include "csppanic.pan"
    23 #include "csppanic.pan"
    25 
    24 #include "mtmshandlerobserver.h"
    26 /**
    25 
    27  * Timeout initial value.
    26 const TInt KStreamInitRetry = 1000000; //1 sec
    28  */
    27 const TInt KRetryForever = -1;
    29 const TInt KTimeoutInitial = 200000; // 0.2s
       
    30 
       
    31 /**
       
    32  * Double the timeout for every retry.
       
    33  */
       
    34 const TInt KTimeoutMultiplier = 2;
       
    35 
       
    36 // ======== MEMBER FUNCTIONS ========
       
    37 
    28 
    38 // ---------------------------------------------------------------------------
    29 // ---------------------------------------------------------------------------
    39 // Static constructor
    30 // Static constructor
    40 // ---------------------------------------------------------------------------
    31 // ---------------------------------------------------------------------------
    41 //
    32 //
    42 TmsHandler* TmsHandler::NewL()
    33 TmsHandler* TmsHandler::NewL(MTmsHandlerObserver& aObserver)
    43     {
    34     {
    44     TmsHandler* self = TmsHandler::NewLC();
    35     TmsHandler* self = TmsHandler::NewLC(aObserver);
    45     CleanupStack::Pop(self);
    36     CleanupStack::Pop(self);
    46     return self;
    37     return self;
    47     }
    38     }
    48 
    39 
    49 // ---------------------------------------------------------------------------
    40 // ---------------------------------------------------------------------------
    50 // Static constructor
    41 // Static constructor
    51 // ---------------------------------------------------------------------------
    42 // ---------------------------------------------------------------------------
    52 //
    43 //
    53 TmsHandler* TmsHandler::NewLC()
    44 TmsHandler* TmsHandler::NewLC(MTmsHandlerObserver& aObserver)
    54     {
    45     {
    55     TmsHandler* self = new (ELeave) TmsHandler();
    46     TmsHandler* self = new (ELeave) TmsHandler();
    56     CleanupStack::PushL(self);
    47     CleanupStack::PushL(self);
    57     self->ConstructL();
    48     self->ConstructL(aObserver);
    58     return self;
    49     return self;
    59     }
    50     }
    60 
    51 
    61 // ---------------------------------------------------------------------------
    52 // ---------------------------------------------------------------------------
    62 // Destructor
    53 // Destructor
    63 // ---------------------------------------------------------------------------
    54 // ---------------------------------------------------------------------------
    64 //
    55 //
    65 TmsHandler::~TmsHandler()
    56 TmsHandler::~TmsHandler()
    66     {
    57     {
    67     if (iTimer)
       
    68         {
       
    69         iTimer->CancelNotify();
       
    70         delete iTimer;
       
    71         }
       
    72     if (iTmsUplink && iTmsCall)
    58     if (iTmsUplink && iTmsCall)
    73         {
    59         {
    74         // CloseUplink();
       
    75         iTmsCall->DeleteStream(iTmsUplink);
    60         iTmsCall->DeleteStream(iTmsUplink);
    76         }
    61         }
    77     if (iTmsDnlink && iTmsCall)
    62     if (iTmsDnlink && iTmsCall)
    78         {
    63         {
    79         // CloseDownlink();
       
    80         iTmsCall->DeleteStream(iTmsDnlink);
    64         iTmsCall->DeleteStream(iTmsDnlink);
    81         }
    65         }
    82     if (iFactory && iTmsCall)
    66     if (iFactory && iTmsCall)
    83         {
    67         {
    84         iFactory->DeleteCall(iTmsCall);
    68         iFactory->DeleteCall(iTmsCall);
    97         }
    81         }
    98     if (iFactory && iTmsModemSink)
    82     if (iFactory && iTmsModemSink)
    99         {
    83         {
   100         iFactory->DeleteSink(iTmsModemSink);
    84         iFactory->DeleteSink(iTmsModemSink);
   101         }
    85         }
   102 
       
   103     delete iFactory;
    86     delete iFactory;
   104 
    87     }
   105     }
    88 
   106 
    89 // ---------------------------------------------------------------------------
   107 // ---------------------------------------------------------------------------
    90 // TmsHandler::StartStreams
   108 // From class MCSPAudioStream
    91 // Activates TMS call audio control streams. If called in the middle of an
   109 // Activates mic and speaker.
    92 // ongoing stream initialization, the request is cashed in until both streams
   110 // ---------------------------------------------------------------------------
    93 // transition to initialized state.
   111 //
    94 // ---------------------------------------------------------------------------
   112 void TmsHandler::StartStreams()
    95 //
       
    96 TInt TmsHandler::StartStreams()
   113     {
    97     {
   114     CSPLOGSTRING(CSPINT, "TmsHandler::StartStreams");
    98     CSPLOGSTRING(CSPINT, "TmsHandler::StartStreams");
   115 
    99     TInt status(TMS_RESULT_SUCCESS);
   116     StartMicAndSpeaker();
   100 
   117     }
   101     if (iTmsUplink)
   118 
   102         {
   119 // ---------------------------------------------------------------------------
   103         if (iTmsUplink->GetState() == TMS_STREAM_INITIALIZED)
   120 // From class MCSPAudioStream
   104             {
   121 // Deactivates mic and speaker if the streams are active or they are
   105             status = iTmsUplink->Start(KRetryForever);
   122 // activating.
   106             }
       
   107         else if (iUplInitializing)
       
   108             {
       
   109             iStartAfterInitComplete = ETrue;
       
   110             }
       
   111         }
       
   112 
       
   113     if (iTmsDnlink && status == TMS_RESULT_SUCCESS)
       
   114         {
       
   115         if (iTmsDnlink->GetState() == TMS_STREAM_INITIALIZED)
       
   116             {
       
   117             status = iTmsDnlink->Start(KRetryForever);
       
   118             }
       
   119         else if (iDnlInitializing)
       
   120             {
       
   121             iStartAfterInitComplete = ETrue;
       
   122             }
       
   123         }
       
   124 
       
   125     CSPLOGSTRING2(CSPINT, "TmsHandler::StartStreams status %d", status);
       
   126 
       
   127     if (status != TMS_RESULT_SUCCESS)
       
   128         {
       
   129         // Cancel any pending retry and cancel.
       
   130         StopStreams();
       
   131         status = KErrCancel;
       
   132         }
       
   133     return status;
       
   134     }
       
   135 
       
   136 // ---------------------------------------------------------------------------
       
   137 // TmsHandler::StopStreams
       
   138 // Deactivates TMS call audio control streams. If streams are not started yet,
       
   139 // any pending request on TMS streams will be canceled.
   123 // ---------------------------------------------------------------------------
   140 // ---------------------------------------------------------------------------
   124 //
   141 //
   125 void TmsHandler::StopStreams()
   142 void TmsHandler::StopStreams()
   126     {
   143     {
   127     CSPLOGSTRING(CSPINT, "TmsHandler::StopStreams");
   144     CSPLOGSTRING(CSPINT, "TmsHandler::StopStreams");
   128     gint status(TMS_RESULT_SUCCESS);
   145 
   129     if (iTimer && IsMicAndSpeakerStarted())
   146     if (iTmsUplink)
   130         {
   147         {
   131         CSPLOGSTRING(CSPINT, "TmsHandler::StopStreams Stopping");
   148         iTmsUplink->Stop();
   132         iTimer->CancelNotify();
   149         }
   133         iTimeout = KTimeoutInitial;
   150     if (iTmsDnlink)
   134         status = iTmsUplink->Stop();
   151         {
   135         iUplinkStarted = FALSE;
   152         iTmsDnlink->Stop();
   136         status |= iTmsDnlink->Stop();
   153         }
   137         iDnlinkStarted = FALSE;
   154     iUplInitializing = EFalse;
   138 
   155     iDnlInitializing = EFalse;
   139         if (status != TMS_RESULT_SUCCESS)
   156     iStartAfterInitComplete = EFalse;
   140             {
   157     }
   141             status = TMS_RESULT_GENERAL_ERROR;
   158 
   142             }
   159 // ---------------------------------------------------------------------------
   143         }
   160 // TmsHandler::AreStreamsStarted
   144     CSPLOGSTRING2(CSPINT, "TmsHandler::StopStreams status %d", status);
   161 // Indicates whether both audio control streams have been started.
   145     }
   162 // ---------------------------------------------------------------------------
   146 
   163 //
   147 // ---------------------------------------------------------------------------
   164 TBool TmsHandler::AreStreamsStarted()
   148 // From class MCSPTimerObserver
   165     {
   149 // Notify from CSPTimer that timeout passed. Try to start mic and
   166     TBool status(EFalse);
   150 // speaker again.
   167 
   151 // ---------------------------------------------------------------------------
   168     if (iTmsUplink && iTmsDnlink)
   152 //
   169         {
   153 void TmsHandler::TimerEvent()
   170         if (iTmsUplink->GetState() == TMS_STREAM_STARTED &&
   154     {
   171                 iTmsDnlink->GetState() == TMS_STREAM_STARTED)
   155     CSPLOGSTRING(CSPINT, "TmsHandler.TimerEvent" );
   172             {
   156     iTimeout *= KTimeoutMultiplier;
   173             status = ETrue;
   157     StartMicAndSpeaker();
   174             }
       
   175         }
       
   176     return status;
   158     }
   177     }
   159 
   178 
   160 // ---------------------------------------------------------------------------
   179 // ---------------------------------------------------------------------------
   161 // Constructor
   180 // Constructor
   162 // ---------------------------------------------------------------------------
   181 // ---------------------------------------------------------------------------
   163 //
   182 //
   164 TmsHandler::TmsHandler() :
   183 TmsHandler::TmsHandler()
   165     iTimeout(KTimeoutInitial)
       
   166     {
   184     {
   167     }
   185     }
   168 
   186 
   169 // ---------------------------------------------------------------------------
   187 // ---------------------------------------------------------------------------
   170 // Second phase constructor
   188 // Second phase constructor
   171 // ---------------------------------------------------------------------------
   189 // ---------------------------------------------------------------------------
   172 //
   190 //
   173 void TmsHandler::ConstructL()
   191 void TmsHandler::ConstructL(MTmsHandlerObserver& aObserver)
   174     {
   192     {
   175     CSPLOGSTRING(CSPINT, "TmsHandler::ConstructL");
   193     CSPLOGSTRING(CSPINT, "TmsHandler::ConstructL");
   176     iTimer = CSPTimer::NewL();
   194     iObserver = &aObserver;
   177 
   195     User::LeaveIfError(CreateTMSCallControl());
   178     if (CreateTMSCallControl())
       
   179         {
       
   180         User::LeaveIfError(TMS_RESULT_UNINITIALIZED_OBJECT);
       
   181         }
       
   182     }
   196     }
   183 
   197 
   184 // ---------------------------------------------------------------------------
   198 // ---------------------------------------------------------------------------
   185 // TmsHandler::CreateTMSCallControl()
   199 // TmsHandler::CreateTMSCallControl()
   186 // ---------------------------------------------------------------------------
   200 // Allocates and initializes all TMS resources needed for call audio control.
   187 //
   201 // ---------------------------------------------------------------------------
   188 gint TmsHandler::CreateTMSCallControl()
   202 //
   189     {
   203 TInt TmsHandler::CreateTMSCallControl()
       
   204     {
       
   205     CSPLOGSTRING(CSPINT, "TmsHandler::CreateTMSCallControl");
   190     TMSVer* v = NULL;
   206     TMSVer* v = NULL;
   191     TInt status;
   207     TInt status;
   192     status = TMSFactory::CreateFactory(iFactory, *v);
   208     status = TMSFactory::CreateFactory(iFactory, *v);
   193 
   209 
   194     __ASSERT_ALWAYS(iFactory, Panic( ECSPPanicBadHandle));
   210     __ASSERT_ALWAYS(iFactory, Panic(ECSPPanicBadHandle));
   195 
   211 
   196     status = iFactory->CreateCall(TMS_CALL_CS, iTmsCall, 0);
   212     status = iFactory->CreateCall(TMS_CALL_CS, iTmsCall, 0);
   197 
   213 
   198     status |= CreateUplink();
   214     if (iTmsCall && status == TMS_RESULT_SUCCESS)
   199     status |= CreateDownlink();
   215         {
   200     status |= CreateMicSource();
   216         status = iTmsCall->CreateStream(TMS_STREAM_UPLINK, iTmsUplink);
   201     status |= AddMicSourceToStream();
   217         status |= iTmsCall->CreateStream(TMS_STREAM_DOWNLINK, iTmsDnlink);
   202     status |= CreateModemSink();
   218         status |= iFactory->CreateSource(TMS_SOURCE_MIC, iTmsMicSource);
   203     status |= AddModemSinkToStream();
   219         status |= iFactory->CreateSink(TMS_SINK_MODEM, iTmsModemSink);
   204     status |= CreateModemSource();
   220         status |= iFactory->CreateSource(TMS_SOURCE_MODEM, iTmsModemSource);
   205     status |= AddModemSourceToStream();
   221         status |= iFactory->CreateSink(TMS_SINK_SPEAKER, iTmsSpeakerSink);
   206     status |= CreateSpeakerSink();
   222         }
   207     status |= AddSpeakerSinkToStream();
   223     if (iTmsUplink && iTmsMicSource && iTmsModemSink &&
   208     status |= OpenDownlink();
   224             status == TMS_RESULT_SUCCESS)
   209 
   225         {
       
   226         status = iTmsUplink->AddSource(iTmsMicSource);
       
   227         status |= iTmsUplink->AddSink(iTmsModemSink);
       
   228         status |= iTmsUplink->AddObserver(*this, NULL);
       
   229         status |= iTmsUplink->Init(KStreamInitRetry);
       
   230         }
       
   231     if (iTmsDnlink && iTmsModemSource && iTmsSpeakerSink &&
       
   232             status == TMS_RESULT_SUCCESS)
       
   233         {
       
   234         status = iTmsDnlink->AddSource(iTmsModemSource);
       
   235         status |= iTmsDnlink->AddSink(iTmsSpeakerSink);
       
   236         status |= iTmsDnlink->AddObserver(*this, NULL);
       
   237         status |= iTmsDnlink->Init(KStreamInitRetry);
       
   238         }
       
   239     if (status == TMS_RESULT_SUCCESS)
       
   240         {
       
   241         iUplInitializing = ETrue;
       
   242         iDnlInitializing = ETrue;
       
   243         }
       
   244     else
       
   245         {
       
   246         status = KErrCancel; // Convert to Symbian error and cancel
       
   247         }
   210     return status;
   248     return status;
   211     }
   249     }
   212 
   250 
   213 // ---------------------------------------------------------------------------
   251 // ----------------------------------------------------------------------------
   214 // Resets timer
   252 // TmsHandler::ProcessUplinkStreamChangeEvent
   215 // ---------------------------------------------------------------------------
   253 // Processes Uplink stream state change events.
   216 //
   254 // ----------------------------------------------------------------------------
   217 void TmsHandler::AudioStreamsStarted()
   255 //
   218     {
   256 void TmsHandler::ProcessUplinkStreamChangeEvent(TInt aState)
   219     CSPLOGSTRING(CSPINT, "TmsHandler::AudioStreamsStarted" );
   257     {
   220     iTimeout = KTimeoutInitial;
   258     CSPLOGSTRING(CSPINT, "TmsHandler::ProcessUplinkStreamChangeEvent");
   221     iTimer->CancelNotify();
   259     switch (aState)
   222     }
   260         {
   223 
   261         case TMS_STREAM_INITIALIZED:
   224 // ---------------------------------------------------------------------------
   262             iUplInitializing = EFalse;
   225 // Starts timer
   263             if (iStartAfterInitComplete)
   226 // ---------------------------------------------------------------------------
   264                 {
   227 //
   265                 iStartAfterInitComplete = EFalse;
   228 void TmsHandler::StartTimer()
   266                 TInt status = StartStreams();
   229     {
   267                 if (status != TMS_RESULT_SUCCESS)
   230     CSPLOGSTRING(CSPINT, "TmsHandler::StartTimer" );
   268                     {
   231     iTimer->NotifyAfter(iTimeout, *this);
   269                     iObserver->AudioStreamsError(status);
   232     }
   270                     }
   233 
   271                 }
   234 // ---------------------------------------------------------------------------
   272             break;
   235 // Starts mic and speaker
   273         case TMS_STREAM_UNINITIALIZED:
   236 // ---------------------------------------------------------------------------
   274             // As result of Deinit() or error
   237 //
   275             iUplInitializing = EFalse;
   238 void TmsHandler::StartMicAndSpeaker()
   276             iStartAfterInitComplete = EFalse;
   239     {
   277             break;
   240     // if speaker and mic is active then activation does not cause any actions.
   278         case TMS_STREAM_PAUSED:
   241     gint status(TMS_RESULT_SUCCESS);
   279             break;
   242 
   280         case TMS_STREAM_STARTED:
   243     if (iTmsUplink)
   281             if (AreStreamsStarted())
   244         {
   282                 {
   245         status = iTmsUplink->Start();
   283                 iObserver->AudioStreamsStarted();
   246         }
   284                 }
   247     CSPLOGSTRING2( CSPINT, "TmsHandler::StartMicAndSpeaker status %d", status );
   285             break;
   248     }
   286         default:
   249 
   287             break;
   250 // ---------------------------------------------------------------------------
   288         }
   251 // Indicated if mic and speaker are started or starting up.
   289     }
   252 // ---------------------------------------------------------------------------
   290 
   253 //
   291 // ----------------------------------------------------------------------------
   254 TBool TmsHandler::IsMicAndSpeakerStarted()
   292 // TmsHandler::ProcessDownlinkStreamChangeEvent
   255     {
   293 // Processes Downlink stream state change events.
   256     return (iUplinkStarted || iDnlinkStarted);
   294 // ----------------------------------------------------------------------------
   257     }
   295 //
   258 
   296 void TmsHandler::ProcessDownlinkStreamChangeEvent(TInt aState)
   259 // ----------------------------------------------------------------------------
   297     {
   260 // CreateUplink
   298     CSPLOGSTRING(CSPINT, "TmsHandler::ProcessDownlinkStreamChangeEvent");
   261 // ----------------------------------------------------------------------------
   299     switch (aState)
   262 //
   300         {
   263 gint TmsHandler::CreateUplink()
   301         case TMS_STREAM_INITIALIZED:
   264     {
   302             iDnlInitializing = EFalse;
   265     CSPLOGSTRING(CSPINT, "TmsHandler::CreateUplink");
   303             if (iStartAfterInitComplete)
   266     gint status(TMS_RESULT_SUCCESS);
   304                 {
   267     if (iTmsCall)
   305                 iStartAfterInitComplete = EFalse;
   268         {
   306                 TInt status = StartStreams();
   269         status = iTmsCall->CreateStream(TMS_STREAM_UPLINK, iTmsUplink);
   307                 if (status != TMS_RESULT_SUCCESS)
   270         }
   308                     {
   271     return status;
   309                     iObserver->AudioStreamsError(status);
   272     }
   310                     }
   273 
   311                 }
   274 // ----------------------------------------------------------------------------
   312             break;
   275 // CreateDownlink
   313         case TMS_STREAM_UNINITIALIZED:
   276 // ----------------------------------------------------------------------------
   314             // As result of Deinit() or error
   277 //
   315             iDnlInitializing = EFalse;
   278 gint TmsHandler::CreateDownlink()
   316             iStartAfterInitComplete = EFalse;
   279     {
   317             break;
   280     CSPLOGSTRING(CSPINT, "TmsHandler::CreateDownlink");
   318         case TMS_STREAM_PAUSED:
   281     gint status(TMS_RESULT_SUCCESS);
   319             break;
   282 
   320         case TMS_STREAM_STARTED:
   283     if (iTmsCall)
   321             if (AreStreamsStarted())
   284         {
   322                 {
   285         status = iTmsCall->CreateStream(TMS_STREAM_DOWNLINK, iTmsDnlink);
   323                 iObserver->AudioStreamsStarted();
   286         }
   324                 }
   287     return status;
   325             break;
   288     }
   326         default:
   289 
   327             break;
   290 // ----------------------------------------------------------------------------
   328         }
   291 // OpenUplink
       
   292 // ----------------------------------------------------------------------------
       
   293 //
       
   294 gint TmsHandler::OpenUplink()
       
   295     {
       
   296     CSPLOGSTRING(CSPINT, "TmsHandler::OpenUplink");
       
   297     gint status = TMS_RESULT_SUCCESS;
       
   298 
       
   299     if (iTmsUplink)
       
   300         {
       
   301         status = iTmsUplink->AddObserver(*this, NULL);
       
   302         if (status == TMS_RESULT_SUCCESS)
       
   303             {
       
   304             status = iTmsUplink->Init();
       
   305             }
       
   306         }
       
   307     return status;
       
   308     }
       
   309 
       
   310 // ----------------------------------------------------------------------------
       
   311 // OpenDownlink
       
   312 // ----------------------------------------------------------------------------
       
   313 //
       
   314 gint TmsHandler::OpenDownlink()
       
   315     {
       
   316     CSPLOGSTRING(CSPINT, "TmsHandler::OpenDownlink");
       
   317     gint status = TMS_RESULT_SUCCESS;
       
   318 
       
   319     if (iTmsDnlink)
       
   320         {
       
   321         status = iTmsDnlink->AddObserver(*this, NULL);
       
   322         if (status == TMS_RESULT_SUCCESS)
       
   323             {
       
   324             status = iTmsDnlink->Init();
       
   325             }
       
   326         }
       
   327     return status;
       
   328     }
       
   329 
       
   330 // ----------------------------------------------------------------------------
       
   331 // CreateModemSource
       
   332 // ----------------------------------------------------------------------------
       
   333 //
       
   334 gint TmsHandler::CreateModemSource()
       
   335     {
       
   336     gint status(TMS_RESULT_SUCCESS);
       
   337 
       
   338     if (iFactory && !iTmsModemSource)
       
   339         {
       
   340         status = iFactory->CreateSource(TMS_SOURCE_MODEM, iTmsModemSource);
       
   341         }
       
   342     return status;
       
   343     }
       
   344 
       
   345 // ----------------------------------------------------------------------------
       
   346 // AddModemSourceToStream
       
   347 // ----------------------------------------------------------------------------
       
   348 //
       
   349 gint TmsHandler::AddModemSourceToStream()
       
   350     {
       
   351     gint status(TMS_RESULT_SUCCESS);
       
   352     if (iTmsDnlink && iTmsModemSource)
       
   353         {
       
   354         status = iTmsDnlink->AddSource(iTmsModemSource);
       
   355         }
       
   356     return status;
       
   357     }
       
   358 
       
   359 // ----------------------------------------------------------------------------
       
   360 // CreateModemSink
       
   361 // ----------------------------------------------------------------------------
       
   362 //
       
   363 gint TmsHandler::CreateModemSink()
       
   364     {
       
   365     gint status(TMS_RESULT_SUCCESS);
       
   366 
       
   367     if (iFactory && !iTmsModemSink)
       
   368         {
       
   369         status = iFactory->CreateSink(TMS_SINK_MODEM, iTmsModemSink);
       
   370         }
       
   371     return status;
       
   372     }
       
   373 
       
   374 // ----------------------------------------------------------------------------
       
   375 // AddModemSinkToStream
       
   376 // ----------------------------------------------------------------------------
       
   377 //
       
   378 gint TmsHandler::AddModemSinkToStream()
       
   379     {
       
   380     gint status(TMS_RESULT_SUCCESS);
       
   381     if (iTmsUplink && iTmsModemSink)
       
   382         {
       
   383         status = iTmsUplink->AddSink(iTmsModemSink);
       
   384         }
       
   385     return status;
       
   386     }
       
   387 
       
   388 // ----------------------------------------------------------------------------
       
   389 // CreateMicSource
       
   390 // ----------------------------------------------------------------------------
       
   391 //
       
   392 gint TmsHandler::CreateMicSource()
       
   393     {
       
   394     gint status(TMS_RESULT_SUCCESS);
       
   395 
       
   396     if (iFactory && !iTmsMicSource)
       
   397         {
       
   398         status = iFactory->CreateSource(TMS_SOURCE_MIC, iTmsMicSource);
       
   399         }
       
   400     return status;
       
   401     }
       
   402 
       
   403 // ----------------------------------------------------------------------------
       
   404 // AddMicSourceToStream
       
   405 // ----------------------------------------------------------------------------
       
   406 //
       
   407 gint TmsHandler::AddMicSourceToStream()
       
   408     {
       
   409     gint status(TMS_RESULT_SUCCESS);
       
   410     if (iTmsUplink && iTmsMicSource)
       
   411         {
       
   412         status = iTmsUplink->AddSource(iTmsMicSource);
       
   413         }
       
   414     return status;
       
   415     }
       
   416 
       
   417 // ----------------------------------------------------------------------------
       
   418 // CreateSpeakerSink
       
   419 // ----------------------------------------------------------------------------
       
   420 //
       
   421 gint TmsHandler::CreateSpeakerSink()
       
   422     {
       
   423     gint status(TMS_RESULT_SUCCESS);
       
   424 
       
   425     if (iFactory && !iTmsSpeakerSink)
       
   426         {
       
   427         status = iFactory->CreateSink(TMS_SINK_SPEAKER, iTmsSpeakerSink);
       
   428         }
       
   429     return status;
       
   430     }
       
   431 
       
   432 // ----------------------------------------------------------------------------
       
   433 // AddSpeakerSinkToStream
       
   434 // ----------------------------------------------------------------------------
       
   435 //
       
   436 gint TmsHandler::AddSpeakerSinkToStream()
       
   437     {
       
   438     gint status(TMS_RESULT_SUCCESS);
       
   439     if (iTmsDnlink && iTmsSpeakerSink)
       
   440         {
       
   441         status = iTmsDnlink->AddSink(iTmsSpeakerSink);
       
   442         }
       
   443     return status;
       
   444     }
   329     }
   445 
   330 
   446 // TMS CALLBACKS
   331 // TMS CALLBACKS
   447 
   332 
   448 // ----------------------------------------------------------------------------
   333 // ----------------------------------------------------------------------------
   449 // TmsHandler::TMSStreamEvent
   334 // TmsHandler::TMSStreamEvent
       
   335 // From TMSStreamObserver
       
   336 // TMS call audio stream control event handler.
   450 // ----------------------------------------------------------------------------
   337 // ----------------------------------------------------------------------------
   451 //
   338 //
   452 void TmsHandler::TMSStreamEvent(const TMSStream& stream, TMSSignalEvent event)
   339 void TmsHandler::TMSStreamEvent(const TMSStream& stream, TMSSignalEvent event)
   453     {
   340     {
   454     CSPLOGSTRING2(CSPINT, "TmsHandler::TMSStreamEvent status %d", event.reason);
   341     CSPLOGSTRING2(CSPINT, "TmsHandler::TMSStreamEvent status %d", event.reason);
   455 
   342 
   456     TMSStreamType strmType = const_cast<TMSStream&>(stream).GetStreamType();
   343     TMSStreamType strmType = const_cast<TMSStream&> (stream).GetStreamType();
   457 
   344 
   458     if (strmType == TMS_STREAM_UPLINK &&
   345     if (strmType == TMS_STREAM_UPLINK)
   459             event.type == TMS_EVENT_STREAM_STATE_CHANGED)
   346         {
   460         {
   347         if (event.type == TMS_EVENT_STREAM_STATE_CHANGED)
   461         switch (event.curr_state)
   348             {
   462             {
   349             ProcessUplinkStreamChangeEvent(event.curr_state);
   463             case TMS_STREAM_INITIALIZED:
   350             }
   464                 //notify stream ready state
   351         else if (event.type == TMS_EVENT_STREAM_STATE_CHANGE_ERROR)
   465                 break;
   352             {
   466             case TMS_STREAM_UNINITIALIZED:
   353 #ifndef __WINS__
   467                 //notify initialization error
   354             Panic( ECSPPanicAudioStreamInitFailure );
   468                 break;
   355 #endif
   469             case TMS_STREAM_PAUSED:
   356             }
   470                 break;
   357         }
   471             case TMS_STREAM_STARTED:
   358     else if (strmType == TMS_STREAM_DOWNLINK)
   472                 iUplinkStarted = TRUE;
   359         {
   473                 iTmsDnlink->Start();
   360         if (event.type == TMS_EVENT_STREAM_STATE_CHANGED)
   474                 break;
   361             {
   475             default:
   362             ProcessDownlinkStreamChangeEvent(event.curr_state);
   476                 break;
   363             }
   477             }
   364         else if (event.type == TMS_EVENT_STREAM_STATE_CHANGE_ERROR)
   478         }
   365             {
   479     else if (strmType == TMS_STREAM_DOWNLINK &&
   366 #ifndef __WINS__
   480             event.type == TMS_EVENT_STREAM_STATE_CHANGED)
   367             Panic( ECSPPanicAudioStreamInitFailure );
   481         {
   368 #endif
   482         switch (event.curr_state)
       
   483             {
       
   484             case TMS_STREAM_INITIALIZED:
       
   485                 {
       
   486                 if ((iTmsCall->GetCallType() == TMS_CALL_CS)
       
   487                         && (!iUplinkStarted))
       
   488                     {
       
   489                     OpenUplink();
       
   490                     }
       
   491                 //notify stream ready state
       
   492                 }
       
   493                 break;
       
   494             case TMS_STREAM_UNINITIALIZED:
       
   495                 //notify initialization error
       
   496                 break;
       
   497             case TMS_STREAM_PAUSED:
       
   498                 break;
       
   499             case TMS_STREAM_STARTED:
       
   500                 iDnlinkStarted = TRUE;
       
   501                 break;
       
   502             default:
       
   503                 break;
       
   504             }
   369             }
   505         }
   370         }
   506     }
   371     }
   507 
   372 
   508 //  End of File
   373 //  End of File