mmserv/tms/tmscallserver/src/tmsipcalldownlinkds.cpp
branchRCL_3
changeset 40 60e492b28869
parent 17 3570217d8c21
child 45 095bea5f582e
equal deleted inserted replaced
30:ab526b8cacfb 40:60e492b28869
    30 // -----------------------------------------------------------------------------
    30 // -----------------------------------------------------------------------------
    31 // TMSIPDownlink::TMSIPDownlink
    31 // TMSIPDownlink::TMSIPDownlink
    32 // Standard Constructor
    32 // Standard Constructor
    33 // -----------------------------------------------------------------------------
    33 // -----------------------------------------------------------------------------
    34 //
    34 //
    35 TMSIPDownlink::TMSIPDownlink()
    35 TMSIPDownlink::TMSIPDownlink(TMSIPDevSoundObserver& observer) :
       
    36     TMSIPCallStreamBase(observer)
    36     {
    37     {
    37     }
    38     }
    38 
    39 
    39 // -----------------------------------------------------------------------------
    40 // -----------------------------------------------------------------------------
    40 // TMSIPDownlink::~TMSIPDownlink
    41 // TMSIPDownlink::~TMSIPDownlink
    59 // -----------------------------------------------------------------------------
    60 // -----------------------------------------------------------------------------
    60 // TMSIPDownlink::NewL
    61 // TMSIPDownlink::NewL
    61 // Symbian two-phase constructor
    62 // Symbian two-phase constructor
    62 // -----------------------------------------------------------------------------
    63 // -----------------------------------------------------------------------------
    63 //
    64 //
    64 TMSIPDownlink* TMSIPDownlink::NewL(const guint32 codecID,
    65 TMSIPDownlink* TMSIPDownlink::NewL(TMSIPDevSoundObserver& observer,
    65         const TMMFPrioritySettings priority)
    66         const guint32 codecID, const TMMFPrioritySettings priority)
    66     {
    67     {
    67     TMSIPDownlink* self = new (ELeave) TMSIPDownlink();
    68     TMSIPDownlink* self = new (ELeave) TMSIPDownlink(observer);
    68     CleanupStack::PushL(self);
    69     CleanupStack::PushL(self);
    69     self->ConstructL(codecID, priority);
    70     self->ConstructL(codecID, priority);
    70     CleanupStack::Pop(self);
    71     CleanupStack::Pop(self);
    71     return self;
    72     return self;
    72     }
    73     }
    78 //
    79 //
    79 void TMSIPDownlink::ConstructL(const guint32 codecID,
    80 void TMSIPDownlink::ConstructL(const guint32 codecID,
    80         const TMMFPrioritySettings priority)
    81         const TMMFPrioritySettings priority)
    81     {
    82     {
    82     TRACE_PRN_FN_ENT;
    83     TRACE_PRN_FN_ENT;
    83 
       
    84     iCodecID = codecID;
    84     iCodecID = codecID;
    85     iPriority = priority;
    85     iPriority = priority;
    86 
    86 
    87     // Client must set these before querying!
    87     // Client must set these before querying!
    88     iG711DecodeMode = TMS_G711_CODEC_MODE_ALAW;
    88     iG711DecodeMode = TMS_G711_CODEC_MODE_ALAW;
    89     iILBCDecodeMode = TMS_ILBC_CODEC_MODE_20MS_FRAME;
    89     iILBCDecodeMode = TMS_ILBC_CODEC_MODE_20MS_FRAME;
    90 
       
    91     TRAPD(err, InitDevSoundL(EMMFStatePlaying, priority));
    90     TRAPD(err, InitDevSoundL(EMMFStatePlaying, priority));
    92     if (err != TMS_RESULT_SUCCESS)
    91     if (err != TMS_RESULT_SUCCESS)
    93         {
    92         {
    94         User::Leave(err);
    93         User::Leave(err);
    95         }
    94         }
    96 
    95 
    97     iMaxBufLen = ConfigureMedia(iCodecID);
    96     iMaxBufLen = ConfigureMedia(iCodecID);
    98 
       
    99     TRACE_PRN_FN_EXT;
    97     TRACE_PRN_FN_EXT;
   100     }
    98     }
   101 
    99 
   102 // -----------------------------------------------------------------------------
   100 // -----------------------------------------------------------------------------
   103 // TMSIPDownlink::Start
   101 // TMSIPDownlink::Start
   105 // -----------------------------------------------------------------------------
   103 // -----------------------------------------------------------------------------
   106 //
   104 //
   107 void TMSIPDownlink::Start()
   105 void TMSIPDownlink::Start()
   108     {
   106     {
   109     TRACE_PRN_FN_ENT;
   107     TRACE_PRN_FN_ENT;
   110 
       
   111     gint err = TMS_RESULT_ILLEGAL_OPERATION;
   108     gint err = TMS_RESULT_ILLEGAL_OPERATION;
   112 
   109 
   113     if (iStatus == EReady && iDevSound)
   110     if (iStatus == EReady && iDevSound)
   114         {
   111         {
   115         TRAP(err, iDevSound->PlayInitL());
   112         TRAP(err, iDevSound->PlayInitL());
   116         TRACE_PRN_IF_ERR(err);
   113         TRACE_PRN_IF_ERR(err);
   117 
       
   118 #ifdef _DEBUG
       
   119         iSamplesPlayedCount = 0;
       
   120 #endif
       
   121         if (err != TMS_RESULT_SUCCESS)
   114         if (err != TMS_RESULT_SUCCESS)
   122             {
   115             {
   123             iStatus = EReady;
   116             iStatus = EReady;
   124             }
   117             iObserver.DownlinkStarted(err);
   125         }
   118             }
   126 
   119         }
   127     TRACE_PRN_FN_EXT;
   120     TRACE_PRN_FN_EXT;
   128     }
   121     }
   129 
   122 
   130 // -----------------------------------------------------------------------------
   123 // -----------------------------------------------------------------------------
   131 // TMSIPDownlink::Stop
   124 // TMSIPDownlink::Stop
   139     if (iStatus == EStreaming && iDevSound)
   132     if (iStatus == EStreaming && iDevSound)
   140         {
   133         {
   141         iDevSound->Stop();
   134         iDevSound->Stop();
   142         iStatus = EReady;
   135         iStatus = EReady;
   143         }
   136         }
   144 
       
   145     TRACE_PRN_FN_EXT;
   137     TRACE_PRN_FN_EXT;
   146     }
   138     }
   147 
   139 
   148 // -----------------------------------------------------------------------------
   140 // -----------------------------------------------------------------------------
   149 // TMSIPDownlink::BufferToBeFilled
   141 // TMSIPDownlink::BufferToBeFilled
   154 // -----------------------------------------------------------------------------
   146 // -----------------------------------------------------------------------------
   155 //
   147 //
   156 void TMSIPDownlink::BufferToBeFilled(CMMFBuffer* aBuffer)
   148 void TMSIPDownlink::BufferToBeFilled(CMMFBuffer* aBuffer)
   157     {
   149     {
   158     // Store pointer to the received buffer
   150     // Store pointer to the received buffer
   159     iDevSoundBufPtr = static_cast<CMMFDataBuffer*>(aBuffer);
   151     iDevSoundBufPtr = static_cast<CMMFDataBuffer*> (aBuffer);
   160     iBufLen = iDevSoundBufPtr->RequestSize();
   152     iBufLen = iDevSoundBufPtr->RequestSize();
   161     TRACE_PRN_N1(_L("TMS->DNL->BTBF: LEN[%d]"), iBufLen);
   153     TRACE_PRN_N1(_L("TMS->DNL->BTBF: LEN[%d]"), iBufLen);
   162 
   154 
   163 #ifndef __WINSCW__
   155 #ifndef __WINSCW__
   164     //TODO: revisit this!
   156     //TODO: Is this still true?
   165     // The first AMR buffer returns 1 for no data frame.
   157     // The first AMR buffer returns 1 for no data frame.
   166     /*if (iCodecID == KMccFourCCIdAMRNB)
   158     /*if (iCodecID == KMccFourCCIdAMRNB)
   167      {
   159      {
   168      iBufLen = iMaxBufLen;
   160      iBufLen = iMaxBufLen;
   169      }*/
   161      }*/
   170 #endif //__WINSCW__
   162 #endif //__WINSCW__
       
   163 
   171     // Create or adjust the chunk
   164     // Create or adjust the chunk
   172     gint err = DoChunk(iBufLen, iMsgBuffer);
   165     gint err = DoChunk(iBufLen, iMsgBuffer);
   173 
   166 
   174     if (err != TMS_RESULT_SUCCESS)
   167     if (err != TMS_RESULT_SUCCESS)
   175         {
   168         {
   180         {
   173         {
   181         // Notify client there is buffer ready to be filled
   174         // Notify client there is buffer ready to be filled
   182         iMsgBuffer.iStatus = err;
   175         iMsgBuffer.iStatus = err;
   183         iMsgBuffer.iInt = iBufLen;
   176         iMsgBuffer.iInt = iBufLen;
   184         iStatus = EStreaming;
   177         iStatus = EStreaming;
       
   178 
   185         // If chunk is opened, we will expect a call from the client to
   179         // 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,
   180         // get chunk handle. When we get a call to copy chunk handle,
   187         // check these variables and see if they match. This is not
   181         // check these variables and see if they match. This is not
   188         // completely secure, but will provide some level of security
   182         // completely secure, but will provide some level of security
   189         if (iMsgBuffer.iBool == TRUE)
   183         if (iMsgBuffer.iBool == TRUE)
   193             }
   187             }
   194         }
   188         }
   195 
   189 
   196     iMsgBuffer.iRequest = ECmdFillBuffer;
   190     iMsgBuffer.iRequest = ECmdFillBuffer;
   197     err = iMsgQueue.Send(iMsgBuffer);
   191     err = iMsgQueue.Send(iMsgBuffer);
   198 
       
   199     TRACE_PRN_IF_ERR(err);
   192     TRACE_PRN_IF_ERR(err);
   200     }
   193     }
   201 
   194 
   202 // -----------------------------------------------------------------------------
   195 // -----------------------------------------------------------------------------
   203 // TMSIPDownlink::BufferFilled
   196 // TMSIPDownlink::BufferFilled
   208     {
   201     {
   209     TRACE_PRN_N1(_L("TMS->DNL->BF: LEN[%d]"), buflen);
   202     TRACE_PRN_N1(_L("TMS->DNL->BF: LEN[%d]"), buflen);
   210 
   203 
   211     // Copy data over from chunk
   204     // Copy data over from chunk
   212     TPtr8 dataPtr(iChunk.Base(), buflen, iMaxBufLen);
   205     TPtr8 dataPtr(iChunk.Base(), buflen, iMaxBufLen);
   213     //    RDebug::RawPrint(dataPtr);
   206     //RDebug::RawPrint(dataPtr);
   214 
   207 
   215     if (iStatus == EStreaming && iDevSound && iDevSoundBufPtr)
   208     if (iStatus == EStreaming && iDevSound && iDevSoundBufPtr)
   216         {
   209         {
   217         // Fill D/S buffer and send it for playback
   210         // Fill D/S buffer and send it for playback
   218         iDevSoundBufPtr->Data() = dataPtr;
   211         iDevSoundBufPtr->Data() = dataPtr;
   360         else
   353         else
   361             {
   354             {
   362             status = TMS_RESULT_ILLEGAL_OPERATION;
   355             status = TMS_RESULT_ILLEGAL_OPERATION;
   363             }
   356             }
   364         }
   357         }
   365 
       
   366     TRACE_PRN_IF_ERR(status);
   358     TRACE_PRN_IF_ERR(status);
   367     return status;
   359     return status;
   368     }
   360     }
   369 
   361 
   370 // -----------------------------------------------------------------------------
   362 // -----------------------------------------------------------------------------
   394                         CIlbcDecoderIntfc::E30msFrame);
   386                         CIlbcDecoderIntfc::E30msFrame);
   395                 TRACE_PRN_N(_L("TMS->DNL: iLBC Mode Set [30ms]"));
   387                 TRACE_PRN_N(_L("TMS->DNL: iLBC Mode Set [30ms]"));
   396                 }
   388                 }
   397             }
   389             }
   398         }
   390         }
   399 
       
   400     TRACE_PRN_IF_ERR(err);
   391     TRACE_PRN_IF_ERR(err);
   401     return err;
   392     return err;
   402     }
   393     }
   403 
   394 
   404 // -----------------------------------------------------------------------------
   395 // -----------------------------------------------------------------------------
   441                         CG711DecoderIntfc::EDecULaw);
   432                         CG711DecoderIntfc::EDecULaw);
   442                 TRACE_PRN_N(_L("TMS->DNL: G711 Mode Set [uLaw]"));
   433                 TRACE_PRN_N(_L("TMS->DNL: G711 Mode Set [uLaw]"));
   443                 }
   434                 }
   444             }
   435             }
   445         }
   436         }
   446 
       
   447     TRACE_PRN_IF_ERR(err);
   437     TRACE_PRN_IF_ERR(err);
   448     return err;
   438     return err;
   449     }
   439     }
   450 
   440 
   451 // -----------------------------------------------------------------------------
   441 // -----------------------------------------------------------------------------
   476             {
   466             {
   477             err = iErrConcealmentIntfc->FrameModeRqrdForEC(frmodereq);
   467             err = iErrConcealmentIntfc->FrameModeRqrdForEC(frmodereq);
   478             TRACE_PRN_N1(_L("TMS->DNL: FrameModeRqrdForEC [%d]"), frmodereq);
   468             TRACE_PRN_N1(_L("TMS->DNL: FrameModeRqrdForEC [%d]"), frmodereq);
   479             }
   469             }
   480         }
   470         }
   481 
       
   482     TRACE_PRN_IF_ERR(err);
   471     TRACE_PRN_IF_ERR(err);
   483     return err;
   472     return err;
   484     }
   473     }
   485 
   474 
   486 // -----------------------------------------------------------------------------
   475 // -----------------------------------------------------------------------------
   500             {
   489             {
   501             err = iErrConcealmentIntfc->SetFrameMode(frmode);
   490             err = iErrConcealmentIntfc->SetFrameMode(frmode);
   502             TRACE_PRN_N1(_L("TMS->DNL: SetFrameMode [%d]"), frmode);
   491             TRACE_PRN_N1(_L("TMS->DNL: SetFrameMode [%d]"), frmode);
   503             }
   492             }
   504         }
   493         }
   505 
       
   506     TRACE_PRN_IF_ERR(err);
   494     TRACE_PRN_IF_ERR(err);
   507     return err;
   495     return err;
   508     }
   496     }
   509 
   497 
   510 // -----------------------------------------------------------------------------
   498 // -----------------------------------------------------------------------------
   521         // not available through CIs -> return cached value
   509         // not available through CIs -> return cached value
   522         frmode = iFrameMode;
   510         frmode = iFrameMode;
   523         TRACE_PRN_N1(_L("TMS->DNL: GetFrameMode [%d]"), frmode);
   511         TRACE_PRN_N1(_L("TMS->DNL: GetFrameMode [%d]"), frmode);
   524         err = TMS_RESULT_SUCCESS;
   512         err = TMS_RESULT_SUCCESS;
   525         }
   513         }
   526 
       
   527     TRACE_PRN_IF_ERR(err);
   514     TRACE_PRN_IF_ERR(err);
   528     return err;
   515     return err;
   529     }
   516     }
   530 
   517 
   531 // -----------------------------------------------------------------------------
   518 // -----------------------------------------------------------------------------
   540     if (iErrConcealmentIntfc)
   527     if (iErrConcealmentIntfc)
   541         {
   528         {
   542         err = iErrConcealmentIntfc->ConcealErrorForNextBuffer();
   529         err = iErrConcealmentIntfc->ConcealErrorForNextBuffer();
   543         TRACE_PRN_N(_L("TMS->DNL: ConcealErrorForNextBuffer"));
   530         TRACE_PRN_N(_L("TMS->DNL: ConcealErrorForNextBuffer"));
   544         }
   531         }
   545 
       
   546     TRACE_PRN_IF_ERR(err);
   532     TRACE_PRN_IF_ERR(err);
   547     return err;
   533     return err;
   548     }
   534     }
   549 
   535 
   550 // -----------------------------------------------------------------------------
   536 // -----------------------------------------------------------------------------
   567             {
   553             {
   568             err = iIlbcDecoderIntfc->SetCng(cng);
   554             err = iIlbcDecoderIntfc->SetCng(cng);
   569             TRACE_PRN_N1(_L("TMS->DNL: SetCng [%d]"), cng);
   555             TRACE_PRN_N1(_L("TMS->DNL: SetCng [%d]"), cng);
   570             }
   556             }
   571         }
   557         }
   572 
       
   573     TRACE_PRN_IF_ERR(err);
   558     TRACE_PRN_IF_ERR(err);
   574     return err;
   559     return err;
   575     }
   560     }
   576 
   561 
   577 // -----------------------------------------------------------------------------
   562 // -----------------------------------------------------------------------------
   594             {
   579             {
   595             err = iIlbcDecoderIntfc->GetCng(cng);
   580             err = iIlbcDecoderIntfc->GetCng(cng);
   596             TRACE_PRN_N1(_L("TMS->DNL: GetCng [%d]"), cng);
   581             TRACE_PRN_N1(_L("TMS->DNL: GetCng [%d]"), cng);
   597             }
   582             }
   598         }
   583         }
   599 
       
   600     TRACE_PRN_IF_ERR(err);
   584     TRACE_PRN_IF_ERR(err);
   601     return err;
   585     return err;
   602     }
   586     }
   603 
   587 
   604 // -----------------------------------------------------------------------------
   588 // -----------------------------------------------------------------------------
   617             iPlc = plc;
   601             iPlc = plc;
   618             err = iG711DecoderIntfc->SetPlc(iPlc);
   602             err = iG711DecoderIntfc->SetPlc(iPlc);
   619             TRACE_PRN_N1(_L("TMS->DNL: SetPlc [%d]"), plc);
   603             TRACE_PRN_N1(_L("TMS->DNL: SetPlc [%d]"), plc);
   620             }
   604             }
   621         }
   605         }
   622 
       
   623     TRACE_PRN_IF_ERR(err);
   606     TRACE_PRN_IF_ERR(err);
   624     return err;
   607     return err;
   625     }
   608     }
   626 
   609 
   627 // -----------------------------------------------------------------------------
   610 // -----------------------------------------------------------------------------
   638         // not available through CIs -> return cached value
   621         // not available through CIs -> return cached value
   639         plc = iPlc;
   622         plc = iPlc;
   640         err = TMS_RESULT_SUCCESS;
   623         err = TMS_RESULT_SUCCESS;
   641         TRACE_PRN_N1(_L("TMS->DNL: GetPlc [%d]"), plc);
   624         TRACE_PRN_N1(_L("TMS->DNL: GetPlc [%d]"), plc);
   642         }
   625         }
   643 
       
   644     TRACE_PRN_IF_ERR(err);
   626     TRACE_PRN_IF_ERR(err);
   645     return err;
   627     return err;
   646     }
   628     }
   647 
   629 
   648 // -----------------------------------------------------------------------------
   630 // -----------------------------------------------------------------------------
   660             {
   642             {
   661             err = iG729DecoderIntfc->BadLsfNextBuffer();
   643             err = iG729DecoderIntfc->BadLsfNextBuffer();
   662             TRACE_PRN_N(_L("TMS->DNL: BadLsfNextBuffer"));
   644             TRACE_PRN_N(_L("TMS->DNL: BadLsfNextBuffer"));
   663             }
   645             }
   664         }
   646         }
   665 
       
   666     TRACE_PRN_IF_ERR(err);
   647     TRACE_PRN_IF_ERR(err);
   667     return err;
   648     return err;
   668     }
   649     }
   669 
   650 
   670 // -----------------------------------------------------------------------------
   651 // -----------------------------------------------------------------------------
   757 // -----------------------------------------------------------------------------
   738 // -----------------------------------------------------------------------------
   758 //
   739 //
   759 void TMSIPDownlink::InitializeComplete(TInt aError)
   740 void TMSIPDownlink::InitializeComplete(TInt aError)
   760     {
   741     {
   761     TRACE_PRN_FN_ENT;
   742     TRACE_PRN_FN_ENT;
   762 
   743     gint status = aError;
   763     gint err = aError;
   744 
   764 
   745     if (status == TMS_RESULT_SUCCESS && iDevSound)
   765     if (err == TMS_RESULT_SUCCESS && iDevSound)
       
   766         {
   746         {
   767         TMMFCapabilities conf;
   747         TMMFCapabilities conf;
   768         conf = iDevSound->Config();
   748         conf = iDevSound->Config();
   769         conf.iRate = EMMFSampleRate8000Hz;
   749         conf.iRate = EMMFSampleRate8000Hz;
   770         conf.iChannels = EMMFMono;
   750         conf.iChannels = EMMFMono;
   771         TRAP(err, iDevSound->SetConfigL(conf));
   751         TRAP(status, iDevSound->SetConfigL(conf));
   772         if (err == TMS_RESULT_SUCCESS)
   752         if (status == TMS_RESULT_SUCCESS)
   773             {
   753             {
   774             // We are ready to stream even in case of later CI setting failure
   754             // We are ready to stream even in case of later CI setting failure
   775             iStatus = EReady;
   755             iStatus = EReady;
   776             iMaxVolume = iDevSound->MaxVolume();
   756             iMaxVolume = iDevSound->MaxVolume();
   777             }
   757             }
   778 
   758 
   779         // Init Custom Interface API to the decoder
   759         // Init Custom Interface API to the Decoder. Any return error can
   780         err = SetCodecCi();
   760         // be ignored as codec can still run in the default mode even if not
   781         if (err != TMS_RESULT_SUCCESS)
   761         // fully configured.
   782             {
   762         SetCodecCi();
   783             // DEBUG only
   763         }
   784             // Can ignore error - although decoder is not fully configured but
   764 
   785             // it can still run in the default mode.
   765     iObserver.DownlinkInitCompleted(status);
   786             TRACE_PRN_IF_ERR(err);
   766     TRACE_PRN_IF_ERR(status);
   787             }
       
   788         }
       
   789 
       
   790     // TODO: Notify client
       
   791 
       
   792     TRACE_PRN_IF_ERR(err);
       
   793     TRACE_PRN_FN_EXT;
   767     TRACE_PRN_FN_EXT;
   794     }
   768     }
   795 
   769 
   796 // -----------------------------------------------------------------------------
   770 // -----------------------------------------------------------------------------
   797 // TMSIPDownlink::PlayError
   771 // TMSIPDownlink::PlayError
   798 // From MDevSoundObserver
   772 // From MDevSoundObserver
   799 // Record error is send to client over comm channel.
   773 // Record error is send to client over comm channel.
   800 // The state of recorder is rolled back to EReady.
   774 // The state of recorder is rolled back to EReady.
   801 // -----------------------------------------------------------------------------
   775 // -----------------------------------------------------------------------------
   802 //
   776 //
   803 void TMSIPDownlink::PlayError(TInt /*aError*/)
   777 void TMSIPDownlink::PlayError(TInt aError)
   804     {
   778     {
   805     //TRACE_PRN_IF_ERR(aError);
       
   806 
       
   807 #ifdef _DEBUG
       
   808     iSamplesPlayedCount = 0;
       
   809 #endif
       
   810     iStatus = EReady;
   779     iStatus = EReady;
   811 
   780     iObserver.DownlinkStarted(aError);
   812     // TODO: Notify client
   781     TRACE_PRN_IF_ERR(aError);
   813     }
   782     }
   814 
   783 
   815 // End of file
   784 // End of file