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