mmserv/tms/tmscallserver/src/ipcalldownlinkds.cpp
changeset 14 80975da52420
parent 12 5a06f39ad45b
child 16 43d09473c595
child 19 4a629bc82c5e
equal deleted inserted replaced
12:5a06f39ad45b 14:80975da52420
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description: Telephony Multimedia Service
       
    15  *
       
    16  */
       
    17 
       
    18 #include <AudioPreference.h>
       
    19 #include <AudioOutput.h>
       
    20 #include <mmcccodecinformation.h>
       
    21 #include <IlbcDecoderIntfc.h>
       
    22 #include <G711DecoderIntfc.h>
       
    23 #include <G729DecoderIntfc.h>
       
    24 #include <ErrorConcealmentIntfc.h>
       
    25 #include "tmsutility.h"
       
    26 #include "ipcallstream.h"
       
    27 
       
    28 using namespace TMS;
       
    29 
       
    30 // -----------------------------------------------------------------------------
       
    31 // TMSIPDownlink::TMSIPDownlink
       
    32 // Standard Constructor
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 TMSIPDownlink::TMSIPDownlink()
       
    36     {
       
    37     }
       
    38 
       
    39 // -----------------------------------------------------------------------------
       
    40 // TMSIPDownlink::~TMSIPDownlink
       
    41 // Standard Constructor
       
    42 // -----------------------------------------------------------------------------
       
    43 //
       
    44 TMSIPDownlink::~TMSIPDownlink()
       
    45     {
       
    46     TRACE_PRN_FN_ENT;
       
    47 
       
    48     Stop();
       
    49 
       
    50     delete iAudioOutput;
       
    51     delete iErrConcealmentIntfc;
       
    52     delete iG711DecoderIntfc;
       
    53     delete iG729DecoderIntfc;
       
    54     delete iIlbcDecoderIntfc;
       
    55 
       
    56     TRACE_PRN_FN_EXT;
       
    57     }
       
    58 
       
    59 // -----------------------------------------------------------------------------
       
    60 // TMSIPDownlink::NewL
       
    61 // Symbian two-phase constructor
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 TMSIPDownlink* TMSIPDownlink::NewL(const guint32 codecID,
       
    65         const TMMFPrioritySettings priority)
       
    66     {
       
    67     TMSIPDownlink* self = new (ELeave) TMSIPDownlink();
       
    68     CleanupStack::PushL(self);
       
    69     self->ConstructL(codecID, priority);
       
    70     CleanupStack::Pop(self);
       
    71     return self;
       
    72     }
       
    73 
       
    74 // -----------------------------------------------------------------------------
       
    75 // TMSIPDownlink::ConstructL
       
    76 // Part two of Symbian two phase construction
       
    77 // -----------------------------------------------------------------------------
       
    78 //
       
    79 void TMSIPDownlink::ConstructL(const guint32 codecID,
       
    80         const TMMFPrioritySettings priority)
       
    81     {
       
    82     TRACE_PRN_FN_ENT;
       
    83 
       
    84     iCodecID = codecID;
       
    85     iPriority = priority;
       
    86 
       
    87     // Client must set these before querying!
       
    88     iG711DecodeMode = TMS_G711_CODEC_MODE_ALAW;
       
    89     iILBCDecodeMode = TMS_ILBC_CODEC_MODE_20MS_FRAME;
       
    90 
       
    91     TRAPD(err, InitDevSoundL(EMMFStatePlaying, priority));
       
    92     if (err != TMS_RESULT_SUCCESS)
       
    93         {
       
    94         User::Leave(err);
       
    95         }
       
    96 
       
    97     iMaxBufLen = ConfigureMedia(iCodecID);
       
    98 
       
    99     TRACE_PRN_FN_EXT;
       
   100     }
       
   101 
       
   102 // -----------------------------------------------------------------------------
       
   103 // TMSIPDownlink::Start
       
   104 //
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 void TMSIPDownlink::Start()
       
   108     {
       
   109     TRACE_PRN_FN_ENT;
       
   110 
       
   111     gint err = TMS_RESULT_ILLEGAL_OPERATION;
       
   112 
       
   113     if (iStatus == EReady && iDevSound)
       
   114         {
       
   115         TRAP(err, iDevSound->PlayInitL());
       
   116         TRACE_PRN_IF_ERR(err);
       
   117 
       
   118 #ifdef _DEBUG
       
   119         iSamplesPlayedCount = 0;
       
   120 #endif
       
   121         if (err != TMS_RESULT_SUCCESS)
       
   122             {
       
   123             iStatus = EReady;
       
   124             }
       
   125         }
       
   126 
       
   127     TRACE_PRN_FN_EXT;
       
   128     }
       
   129 
       
   130 // -----------------------------------------------------------------------------
       
   131 // TMSIPDownlink::Stop
       
   132 //
       
   133 // -----------------------------------------------------------------------------
       
   134 //
       
   135 void TMSIPDownlink::Stop()
       
   136     {
       
   137     TRACE_PRN_FN_ENT;
       
   138 
       
   139     if (iStatus == EStreaming && iDevSound)
       
   140         {
       
   141         iDevSound->Stop();
       
   142         iStatus = EReady;
       
   143         }
       
   144 
       
   145     TRACE_PRN_FN_EXT;
       
   146     }
       
   147 
       
   148 // -----------------------------------------------------------------------------
       
   149 // TMSIPDownlink::BufferToBeFilled
       
   150 // A reference to the buffer delivered from the DevSound is stored locally
       
   151 // for later use. It will be filled with the data passed from the client
       
   152 // when it calls BufferFilled.
       
   153 //
       
   154 // -----------------------------------------------------------------------------
       
   155 //
       
   156 void TMSIPDownlink::BufferToBeFilled(CMMFBuffer* aBuffer)
       
   157     {
       
   158     // Store pointer to the received buffer
       
   159     iDevSoundBufPtr = static_cast<CMMFDataBuffer*> (aBuffer);
       
   160     iBufLen = iDevSoundBufPtr->RequestSize();
       
   161     TRACE_PRN_N1(_L("TMS->DNL->BTBF: LEN[%d]"), iBufLen);
       
   162 
       
   163 #ifndef __WINSCW__
       
   164     //TODO: revisit this!
       
   165     // The first AMR buffer returns 1 for no data frame.
       
   166     /*if (iCodecID == KMccFourCCIdAMRNB)
       
   167      {
       
   168      iBufLen = iMaxBufLen;
       
   169      }*/
       
   170 #endif //__WINSCW__
       
   171     // Create or adjust the chunk
       
   172     gint err = DoChunk(iBufLen, iMsgBuffer);
       
   173 
       
   174     if (err != TMS_RESULT_SUCCESS)
       
   175         {
       
   176         Stop();
       
   177         iMsgBuffer.iStatus = err;
       
   178         }
       
   179     else
       
   180         {
       
   181         // Notify client there is buffer ready to be filled
       
   182         iMsgBuffer.iStatus = err;
       
   183         iMsgBuffer.iInt = iBufLen;
       
   184         iStatus = EStreaming;
       
   185         // If chunk is opened, we will expect a call from the client to
       
   186         // get chunk handle. When we get a call to copy chunk handle,
       
   187         // check these variables and see if they match. This is not
       
   188         // completely secure, but will provide some level of security
       
   189         if (iMsgBuffer.iBool == TRUE)
       
   190             {
       
   191             iWriteDataXferHndlToClient = TRUE;
       
   192             iKey = iMsgBuffer.iUint32;
       
   193             }
       
   194         }
       
   195 
       
   196     iMsgBuffer.iRequest = ECmdFillBuffer;
       
   197     err = iMsgQueue.Send(iMsgBuffer);
       
   198 
       
   199     TRACE_PRN_IF_ERR(err);
       
   200     }
       
   201 
       
   202 // -----------------------------------------------------------------------------
       
   203 // TMSIPDownlink::BufferFilled
       
   204 //
       
   205 // -----------------------------------------------------------------------------
       
   206 //
       
   207 void TMSIPDownlink::BufferFilled(const guint buflen)
       
   208     {
       
   209     TRACE_PRN_N1(_L("TMS->DNL->BF: LEN[%d]"), buflen);
       
   210 
       
   211     // Copy data over from chunk
       
   212     TPtr8 dataPtr(iChunk.Base(), buflen, iMaxBufLen);
       
   213     //    RDebug::RawPrint(dataPtr);
       
   214 
       
   215     if (iStatus == EStreaming && iDevSound && iDevSoundBufPtr)
       
   216         {
       
   217         // Fill D/S buffer and send it for playback
       
   218         iDevSoundBufPtr->Data() = dataPtr;
       
   219         TRAPD(ignore, iDevSoundBufPtr->SetRequestSizeL(buflen));
       
   220         if (ignore) //makes compiler happy
       
   221             {
       
   222             //try playing anyway
       
   223             iDevSound->PlayData();
       
   224             }
       
   225         else
       
   226             {
       
   227             iDevSound->PlayData();
       
   228             }
       
   229         }
       
   230     }
       
   231 
       
   232 // -----------------------------------------------------------------------------
       
   233 // TMSIPDownlink::SetCodecCi
       
   234 //
       
   235 // -----------------------------------------------------------------------------
       
   236 //
       
   237 gint TMSIPDownlink::SetCodecCi()
       
   238     {
       
   239     TRAPD(err, SetCodecCiL());
       
   240     return err;
       
   241     }
       
   242 
       
   243 // -----------------------------------------------------------------------------
       
   244 // TMSIPDownlink::SetCodecCiL
       
   245 //
       
   246 // -----------------------------------------------------------------------------
       
   247 //
       
   248 void TMSIPDownlink::SetCodecCiL()
       
   249     {
       
   250     TRACE_PRN_FN_ENT;
       
   251 
       
   252     switch (iCodecID)
       
   253         {
       
   254         case KMccFourCCIdG711:
       
   255             {
       
   256             if (!iG711DecoderIntfc)
       
   257                 {
       
   258                 iG711DecoderIntfc = CG711DecoderIntfc::NewL(*iDevSound);
       
   259                 }
       
   260             break;
       
   261             }
       
   262         case KMccFourCCIdG729:
       
   263             {
       
   264             if (!iG729DecoderIntfc)
       
   265                 {
       
   266                 iG729DecoderIntfc = CG729DecoderIntfc::NewL(*iDevSound);
       
   267                 }
       
   268             break;
       
   269             }
       
   270         case KMccFourCCIdILBC:
       
   271             {
       
   272             if (!iIlbcDecoderIntfc)
       
   273                 {
       
   274                 iIlbcDecoderIntfc = CIlbcDecoderIntfc::NewL(*iDevSound);
       
   275                 }
       
   276             break;
       
   277             }
       
   278         case KMccFourCCIdAMRNB:
       
   279         case KMMFFourCCCodePCM16:
       
   280             {
       
   281             break;
       
   282             }
       
   283         default:
       
   284             {
       
   285             User::Leave(TMS_RESULT_INVALID_ARGUMENT);
       
   286             break;
       
   287             }
       
   288         }
       
   289 
       
   290     if (!iErrConcealmentIntfc && iCodecID != KMMFFourCCCodePCM16)
       
   291         {
       
   292         iErrConcealmentIntfc = CErrorConcealmentIntfc::NewL(*iDevSound);
       
   293         }
       
   294 
       
   295     TRACE_PRN_FN_EXT;
       
   296     }
       
   297 
       
   298 // -----------------------------------------------------------------------------
       
   299 // TMSIPDownlink::SetVolume
       
   300 //
       
   301 // -----------------------------------------------------------------------------
       
   302 //
       
   303 gint TMSIPDownlink::SetVolume(const guint volume)
       
   304     {
       
   305     gint ret(TMS_RESULT_UNINITIALIZED_OBJECT);
       
   306     if (iDevSound)
       
   307         {
       
   308         iDevSound->SetVolume(volume);
       
   309         ret = TMS_RESULT_SUCCESS;
       
   310         }
       
   311     TRACE_PRN_N1(_L("TMS->DNL: SetVolume [%d]"), volume);
       
   312     return ret;
       
   313     }
       
   314 
       
   315 // -----------------------------------------------------------------------------
       
   316 // TMSIPDownlink::GetVolume
       
   317 //
       
   318 // -----------------------------------------------------------------------------
       
   319 //
       
   320 gint TMSIPDownlink::GetVolume(guint& volume)
       
   321     {
       
   322     gint ret(TMS_RESULT_UNINITIALIZED_OBJECT);
       
   323     if (iDevSound)
       
   324         {
       
   325         volume = iDevSound->Volume();
       
   326         ret = TMS_RESULT_SUCCESS;
       
   327         }
       
   328     TRACE_PRN_N1(_L("TMS->DNL: GetVolume [%d]"), volume);
       
   329     return ret;
       
   330     }
       
   331 
       
   332 // -----------------------------------------------------------------------------
       
   333 // TMSIPDownlink::GetMaxVolume
       
   334 //
       
   335 // -----------------------------------------------------------------------------
       
   336 //
       
   337 gint TMSIPDownlink::GetMaxVolume(guint& volume)
       
   338     {
       
   339     gint ret(TMS_RESULT_UNINITIALIZED_OBJECT);
       
   340     if (iDevSound)
       
   341         {
       
   342         volume = iDevSound->MaxVolume();
       
   343         ret = TMS_RESULT_SUCCESS;
       
   344         }
       
   345     TRACE_PRN_N1(_L("TMS->DNL: MaxVolume [%d]"), volume);
       
   346     return ret;
       
   347     }
       
   348 
       
   349 // -----------------------------------------------------------------------------
       
   350 // TMSIPDownlink::GetDataXferChunkHndl
       
   351 //
       
   352 // -----------------------------------------------------------------------------
       
   353 //
       
   354 gint TMSIPDownlink::GetDataXferChunkHndl(const TUint32 key, RChunk& chunk)
       
   355     {
       
   356     gint status = TMS_RESULT_DOES_NOT_EXIST;
       
   357 
       
   358     if (iChunk.Handle())
       
   359         {
       
   360         if (iWriteDataXferHndlToClient && (iKey == key))
       
   361             {
       
   362             chunk = iChunk;
       
   363             iWriteDataXferHndlToClient = FALSE;
       
   364             iKey = 0;
       
   365             status = TMS_RESULT_SUCCESS;
       
   366             }
       
   367         else
       
   368             {
       
   369             status = TMS_RESULT_ILLEGAL_OPERATION;
       
   370             }
       
   371         }
       
   372 
       
   373     TRACE_PRN_IF_ERR(status);
       
   374     return status;
       
   375     }
       
   376 
       
   377 // -----------------------------------------------------------------------------
       
   378 // TMSIPDownlink::SetIlbcCodecMode
       
   379 //
       
   380 // -----------------------------------------------------------------------------
       
   381 //
       
   382 gint TMSIPDownlink::SetIlbcCodecMode(gint mode)
       
   383     {
       
   384     gint err = TMS_RESULT_DOES_NOT_EXIST;
       
   385 
       
   386     if (iStatus == EReady)
       
   387         {
       
   388         iILBCDecodeMode = mode;
       
   389 
       
   390         if (iIlbcDecoderIntfc && iCodecID == KMccFourCCIdILBC)
       
   391             {
       
   392             if (mode == TMS_ILBC_CODEC_MODE_20MS_FRAME)
       
   393                 {
       
   394                 err = iIlbcDecoderIntfc->SetDecoderMode(
       
   395                         CIlbcDecoderIntfc::E20msFrame);
       
   396                 TRACE_PRN_N(_L("TMS->DNL: iLBC Mode Set [20ms]"));
       
   397                 }
       
   398             else if (mode == TMS_ILBC_CODEC_MODE_30MS_FRAME)
       
   399                 {
       
   400                 err = iIlbcDecoderIntfc->SetDecoderMode(
       
   401                         CIlbcDecoderIntfc::E30msFrame);
       
   402                 TRACE_PRN_N(_L("TMS->DNL: iLBC Mode Set [30ms]"));
       
   403                 }
       
   404             }
       
   405         }
       
   406 
       
   407     TRACE_PRN_IF_ERR(err);
       
   408     return err;
       
   409     }
       
   410 
       
   411 // -----------------------------------------------------------------------------
       
   412 // TMSIPDownlink::GetIlbcCodecMode
       
   413 //
       
   414 // -----------------------------------------------------------------------------
       
   415 //
       
   416 gint TMSIPDownlink::GetIlbcCodecMode(gint& mode)
       
   417     {
       
   418     // not available through CIs -> return cashed value
       
   419     mode = iILBCDecodeMode;
       
   420     TRACE_PRN_N1(_L("TMS->DNL: GetIlbcCodecMode [%d]"), mode);
       
   421     return TMS_RESULT_SUCCESS;
       
   422     }
       
   423 
       
   424 // -----------------------------------------------------------------------------
       
   425 // TMSIPDownlink::SetG711CodecMode
       
   426 //
       
   427 // -----------------------------------------------------------------------------
       
   428 //
       
   429 gint TMSIPDownlink::SetG711CodecMode(gint mode)
       
   430     {
       
   431     gint err = TMS_RESULT_DOES_NOT_EXIST;
       
   432 
       
   433     if (iStatus == EReady)
       
   434         {
       
   435         iG711DecodeMode = mode;
       
   436 
       
   437         if (iG711DecoderIntfc && iCodecID == KMccFourCCIdG711)
       
   438             {
       
   439             if (mode == TMS_G711_CODEC_MODE_ALAW)
       
   440                 {
       
   441                 err = iG711DecoderIntfc->SetDecoderMode(
       
   442                         CG711DecoderIntfc::EDecALaw);
       
   443                 TRACE_PRN_N(_L("TMS->DNL: G711 Mode Set [ALaw]"));
       
   444                 }
       
   445             else if (mode == TMS_G711_CODEC_MODE_MULAW)
       
   446                 {
       
   447                 err = iG711DecoderIntfc->SetDecoderMode(
       
   448                         CG711DecoderIntfc::EDecULaw);
       
   449                 TRACE_PRN_N(_L("TMS->DNL: G711 Mode Set [uLaw]"));
       
   450                 }
       
   451             }
       
   452         }
       
   453 
       
   454     TRACE_PRN_IF_ERR(err);
       
   455     return err;
       
   456     }
       
   457 
       
   458 // -----------------------------------------------------------------------------
       
   459 // TMSIPDownlink::GetG711CodecMode
       
   460 //
       
   461 // -----------------------------------------------------------------------------
       
   462 //
       
   463 gint TMSIPDownlink::GetG711CodecMode(gint& mode)
       
   464     {
       
   465     // not available through CIs -> return cached value
       
   466     mode = iG711DecodeMode;
       
   467     TRACE_PRN_N1(_L("TMS->DNL: GetG711CodecMode [%d]"), mode);
       
   468     return TMS_RESULT_SUCCESS;
       
   469     }
       
   470 
       
   471 // -----------------------------------------------------------------------------
       
   472 // TMSIPDownlink::FrameModeRqrdForEC
       
   473 //
       
   474 // -----------------------------------------------------------------------------
       
   475 //
       
   476 gint TMSIPDownlink::FrameModeRqrdForEC(gboolean& frmodereq)
       
   477     {
       
   478     gint err = TMS_RESULT_DOES_NOT_EXIST;
       
   479 
       
   480     if (iStatus == EReady)
       
   481         {
       
   482         if (iErrConcealmentIntfc)
       
   483             {
       
   484             err = iErrConcealmentIntfc->FrameModeRqrdForEC(frmodereq);
       
   485             TRACE_PRN_N1(_L("TMS->DNL: FrameModeRqrdForEC [%d]"), frmodereq);
       
   486             }
       
   487         }
       
   488 
       
   489     TRACE_PRN_IF_ERR(err);
       
   490     return err;
       
   491     }
       
   492 
       
   493 // -----------------------------------------------------------------------------
       
   494 // TMSIPDownlink::SetFrameMode
       
   495 //
       
   496 // -----------------------------------------------------------------------------
       
   497 //
       
   498 gint TMSIPDownlink::SetFrameMode(const gboolean frmode)
       
   499     {
       
   500     gint err = TMS_RESULT_DOES_NOT_EXIST;
       
   501 
       
   502     if (iStatus == EReady)
       
   503         {
       
   504         iFrameMode = frmode;
       
   505 
       
   506         if (iErrConcealmentIntfc)
       
   507             {
       
   508             err = iErrConcealmentIntfc->SetFrameMode(frmode);
       
   509             TRACE_PRN_N1(_L("TMS->DNL: SetFrameMode [%d]"), frmode);
       
   510             }
       
   511         }
       
   512 
       
   513     TRACE_PRN_IF_ERR(err);
       
   514     return err;
       
   515     }
       
   516 
       
   517 // -----------------------------------------------------------------------------
       
   518 // TMSIPDownlink::GetFrameMode
       
   519 //
       
   520 // -----------------------------------------------------------------------------
       
   521 //
       
   522 gint TMSIPDownlink::GetFrameMode(gboolean& frmode)
       
   523     {
       
   524     gint err = TMS_RESULT_DOES_NOT_EXIST;
       
   525 
       
   526     if (iErrConcealmentIntfc)
       
   527         {
       
   528         // not available through CIs -> return cached value
       
   529         frmode = iFrameMode;
       
   530         TRACE_PRN_N1(_L("TMS->DNL: GetFrameMode [%d]"), frmode);
       
   531         err = TMS_RESULT_SUCCESS;
       
   532         }
       
   533 
       
   534     TRACE_PRN_IF_ERR(err);
       
   535     return err;
       
   536     }
       
   537 
       
   538 // -----------------------------------------------------------------------------
       
   539 // TMSIPDownlink::ConcealErrorForNextBuffer
       
   540 //
       
   541 // -----------------------------------------------------------------------------
       
   542 //
       
   543 gint TMSIPDownlink::ConcealErrorForNextBuffer()
       
   544     {
       
   545     gint err = TMS_RESULT_DOES_NOT_EXIST;
       
   546 
       
   547     if (iErrConcealmentIntfc)
       
   548         {
       
   549         err = iErrConcealmentIntfc->ConcealErrorForNextBuffer();
       
   550         TRACE_PRN_N(_L("TMS->DNL: ConcealErrorForNextBuffer"));
       
   551         }
       
   552 
       
   553     TRACE_PRN_IF_ERR(err);
       
   554     return err;
       
   555     }
       
   556 
       
   557 // -----------------------------------------------------------------------------
       
   558 // TMSIPDownlink::SetCng
       
   559 //
       
   560 // -----------------------------------------------------------------------------
       
   561 //
       
   562 gint TMSIPDownlink::SetCng(const TMSFormatType fmttype, const gboolean cng)
       
   563     {
       
   564     gint err = TMS_RESULT_DOES_NOT_EXIST;
       
   565 
       
   566     if (iStatus == EReady)
       
   567         {
       
   568         if (fmttype == TMS_FORMAT_G711 && iG711DecoderIntfc)
       
   569             {
       
   570             err = iG711DecoderIntfc->SetCng(cng);
       
   571             TRACE_PRN_N1(_L("TMS->DNL: SetCng [%d]"), cng);
       
   572             }
       
   573         else if (fmttype == TMS_FORMAT_ILBC && iIlbcDecoderIntfc)
       
   574             {
       
   575             err = iIlbcDecoderIntfc->SetCng(cng);
       
   576             TRACE_PRN_N1(_L("TMS->DNL: SetCng [%d]"), cng);
       
   577             }
       
   578         }
       
   579 
       
   580     TRACE_PRN_IF_ERR(err);
       
   581     return err;
       
   582     }
       
   583 
       
   584 // -----------------------------------------------------------------------------
       
   585 // TMSIPDownlink::GetCng
       
   586 //
       
   587 // -----------------------------------------------------------------------------
       
   588 //
       
   589 gint TMSIPDownlink::GetCng(const TMSFormatType fmttype, gboolean& cng)
       
   590     {
       
   591     gint err = TMS_RESULT_DOES_NOT_EXIST;
       
   592 
       
   593     if (iStatus == EReady)
       
   594         {
       
   595         if (fmttype == TMS_FORMAT_G711 && iG711DecoderIntfc)
       
   596             {
       
   597             err = iG711DecoderIntfc->GetCng(cng);
       
   598             TRACE_PRN_N1(_L("TMS->DNL: GetCng [%d]"), cng);
       
   599             }
       
   600         else if (fmttype == TMS_FORMAT_ILBC && iIlbcDecoderIntfc)
       
   601             {
       
   602             err = iIlbcDecoderIntfc->GetCng(cng);
       
   603             TRACE_PRN_N1(_L("TMS->DNL: GetCng [%d]"), cng);
       
   604             }
       
   605         }
       
   606 
       
   607     TRACE_PRN_IF_ERR(err);
       
   608     return err;
       
   609     }
       
   610 
       
   611 // -----------------------------------------------------------------------------
       
   612 // TMSIPDownlink::SetPlc
       
   613 //
       
   614 // -----------------------------------------------------------------------------
       
   615 //
       
   616 gint TMSIPDownlink::SetPlc(const TMSFormatType fmttype, const gboolean plc)
       
   617     {
       
   618     gint err = TMS_RESULT_DOES_NOT_EXIST;
       
   619 
       
   620     if (iStatus == EReady)
       
   621         {
       
   622         if (fmttype == TMS_FORMAT_G711 && iG711DecoderIntfc)
       
   623             {
       
   624             iPlc = plc;
       
   625             err = iG711DecoderIntfc->SetPlc(iPlc);
       
   626             TRACE_PRN_N1(_L("TMS->DNL: SetPlc [%d]"), plc);
       
   627             }
       
   628         }
       
   629 
       
   630     TRACE_PRN_IF_ERR(err);
       
   631     return err;
       
   632     }
       
   633 
       
   634 // -----------------------------------------------------------------------------
       
   635 // TMSIPDownlink::GetPlc
       
   636 //
       
   637 // -----------------------------------------------------------------------------
       
   638 //
       
   639 gint TMSIPDownlink::GetPlc(const TMSFormatType fmttype, gboolean& plc)
       
   640     {
       
   641     gint err = TMS_RESULT_DOES_NOT_EXIST;
       
   642 
       
   643     if (fmttype == TMS_FORMAT_G711 && iG711DecoderIntfc)
       
   644         {
       
   645         // not available through CIs -> return cached value
       
   646         plc = iPlc;
       
   647         err = TMS_RESULT_SUCCESS;
       
   648         TRACE_PRN_N1(_L("TMS->DNL: GetPlc [%d]"), plc);
       
   649         }
       
   650 
       
   651     TRACE_PRN_IF_ERR(err);
       
   652     return err;
       
   653     }
       
   654 
       
   655 // -----------------------------------------------------------------------------
       
   656 // TMSIPDownlink::BadLsfNextBuffer
       
   657 //
       
   658 // -----------------------------------------------------------------------------
       
   659 //
       
   660 gint TMSIPDownlink::BadLsfNextBuffer()
       
   661     {
       
   662     gint err = TMS_RESULT_DOES_NOT_EXIST;
       
   663 
       
   664     if (iStatus == EStreaming)
       
   665         {
       
   666         if (iCodecID == KMccFourCCIdG729 && iG729DecoderIntfc)
       
   667             {
       
   668             err = iG729DecoderIntfc->BadLsfNextBuffer();
       
   669             TRACE_PRN_N(_L("TMS->DNL: BadLsfNextBuffer"));
       
   670             }
       
   671         }
       
   672 
       
   673     TRACE_PRN_IF_ERR(err);
       
   674     return err;
       
   675     }
       
   676 
       
   677 // -----------------------------------------------------------------------------
       
   678 // TMSIPDownlink::SetAudioDeviceL
       
   679 //
       
   680 // -----------------------------------------------------------------------------
       
   681 void TMSIPDownlink::SetAudioDeviceL(TMSAudioOutput output)
       
   682     {
       
   683     TRACE_PRN_FN_ENT;
       
   684 
       
   685     if (!iAudioOutput)
       
   686         {
       
   687         iAudioOutput = CAudioOutput::NewL(*iDevSound);
       
   688         }
       
   689 
       
   690     if (iAudioOutput)
       
   691         {
       
   692         // ENoPreference=0, EAll=1, ENoOutput=2, EPrivate=3, EPublic=4
       
   693         CAudioOutput::TAudioOutputPreference outputDev;
       
   694 
       
   695         switch (output)
       
   696             {
       
   697             case TMS_AUDIO_OUTPUT_PRIVATE:
       
   698             case TMS_AUDIO_OUTPUT_HANDSET:
       
   699                 outputDev = CAudioOutput::EPrivate;
       
   700                 break;
       
   701             case TMS_AUDIO_OUTPUT_PUBLIC:
       
   702             case TMS_AUDIO_OUTPUT_LOUDSPEAKER:
       
   703                 outputDev = CAudioOutput::EPublic;
       
   704                 break;
       
   705             default: // Use default device routing
       
   706                 outputDev = CAudioOutput::ENoPreference;
       
   707                 break;
       
   708             }
       
   709 
       
   710         iAudioOutput->SetAudioOutputL(outputDev);
       
   711         TRACE_PRN_N1(_L("TMS->DNL: SetAudioDeviceL [%d]"), outputDev);
       
   712         }
       
   713 
       
   714     TRACE_PRN_FN_EXT;
       
   715     }
       
   716 
       
   717 // -----------------------------------------------------------------------------
       
   718 // TMSIPDownlink::GetAudioDeviceL
       
   719 //
       
   720 // -----------------------------------------------------------------------------
       
   721 //
       
   722 void TMSIPDownlink::GetAudioDeviceL(TMSAudioOutput& output)
       
   723     {
       
   724     TRACE_PRN_FN_ENT;
       
   725 
       
   726     if (!iAudioOutput)
       
   727         {
       
   728         iAudioOutput = CAudioOutput::NewL(*iDevSound);
       
   729         }
       
   730 
       
   731     if (iAudioOutput)
       
   732         {
       
   733         CAudioOutput::TAudioOutputPreference outputDev =
       
   734                 iAudioOutput->AudioOutput();
       
   735 
       
   736         switch (outputDev)
       
   737             {
       
   738             case CAudioOutput::ENoPreference:
       
   739             case CAudioOutput::EAll:
       
   740             case CAudioOutput::ENoOutput:
       
   741             case CAudioOutput::EPrivate:
       
   742                 output = TMS_AUDIO_OUTPUT_PRIVATE;
       
   743                 break;
       
   744             case CAudioOutput::EPublic:
       
   745                 output = TMS_AUDIO_OUTPUT_PUBLIC;
       
   746                 break;
       
   747             default:
       
   748                 output = TMS_AUDIO_OUTPUT_PRIVATE;
       
   749                 break;
       
   750             }
       
   751         }
       
   752 
       
   753     TRACE_PRN_FN_EXT;
       
   754     }
       
   755 
       
   756 // CALLBACKS
       
   757 
       
   758 // -----------------------------------------------------------------------------
       
   759 // TMSIPDownlink::InitializeComplete
       
   760 // A callback from the DevSound indicating completion of the initialization.
       
   761 // It will send config data to the D/S and configure the encoder via CI.
       
   762 // If everything goes well, the state of the thread is set EReady.
       
   763 // The initialization completion message is sent back to the main thread.
       
   764 // -----------------------------------------------------------------------------
       
   765 //
       
   766 void TMSIPDownlink::InitializeComplete(TInt aError)
       
   767     {
       
   768     TRACE_PRN_FN_ENT;
       
   769 
       
   770     gint err = aError;
       
   771 
       
   772     if (err == TMS_RESULT_SUCCESS && iDevSound)
       
   773         {
       
   774         TMMFCapabilities conf;
       
   775         conf = iDevSound->Config();
       
   776         conf.iRate = EMMFSampleRate8000Hz;
       
   777         conf.iChannels = EMMFMono;
       
   778         TRAP(err, iDevSound->SetConfigL(conf));
       
   779         if (err == TMS_RESULT_SUCCESS)
       
   780             {
       
   781             // We are ready to stream even in case of later CI setting failure
       
   782             iStatus = EReady;
       
   783             iMaxVolume = iDevSound->MaxVolume();
       
   784             }
       
   785 
       
   786         // Init Custom Interface API to the decoder
       
   787         err = SetCodecCi();
       
   788         if (err != TMS_RESULT_SUCCESS)
       
   789             {
       
   790             // DEBUG only
       
   791             // Can ignore error - although decoder is not fully configured but
       
   792             // it can still run in the default mode.
       
   793             TRACE_PRN_IF_ERR(err);
       
   794             }
       
   795         }
       
   796 
       
   797     // TODO: Notify client
       
   798 
       
   799     TRACE_PRN_IF_ERR(err);
       
   800     TRACE_PRN_FN_EXT;
       
   801     }
       
   802 
       
   803 // -----------------------------------------------------------------------------
       
   804 // TMSIPDownlink::PlayError
       
   805 // From MDevSoundObserver
       
   806 // Record error is send to client over comm channel.
       
   807 // The state of recorder is rolled back to EReady.
       
   808 // -----------------------------------------------------------------------------
       
   809 //
       
   810 void TMSIPDownlink::PlayError(TInt /*aError*/)
       
   811     {
       
   812     //TRACE_PRN_IF_ERR(aError);
       
   813 
       
   814 #ifdef _DEBUG
       
   815     iSamplesPlayedCount = 0;
       
   816 #endif
       
   817     iStatus = EReady;
       
   818 
       
   819     // TODO: Notify client
       
   820     }
       
   821 
       
   822 // End of file