mmserv/voipaudioservices/VoIPClient/src/VoIPAudioSession.cpp
changeset 0 71ca22bcf22a
child 28 ebf79c79991a
equal deleted inserted replaced
-1:000000000000 0:71ca22bcf22a
       
     1 /*
       
     2  * Copyright (c) 2007-2008 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:  Implements RVoIPAudioSession object.
       
    15  *
       
    16  */
       
    17 
       
    18 #include <s32mem.h>
       
    19 #include "debugtracemacros.h"
       
    20 #include "VoIPAudioClientServer.h"
       
    21 #include "VoIPAudioSession.h"
       
    22 
       
    23 // CONSTANTS
       
    24 const TUint KServerConnectRetries = 2;
       
    25 const TUint KSessionMessageSlots = 10;
       
    26 
       
    27 // -----------------------------------------------------------------------------
       
    28 // StartServer
       
    29 // Static function to start the server process thread.
       
    30 // Start the server process/thread which lives in an EPOCEXE object.
       
    31 // Returns: TInt: KErrNone (0) if no error
       
    32 // -----------------------------------------------------------------------------
       
    33 //
       
    34 static TInt StartServer()
       
    35     {
       
    36     const TUidType serverUid(KNullUid, KNullUid, KVoIPServerUid3);
       
    37 
       
    38     // Only one instance of the server is allowed. Attempt of launching
       
    39     // second instance of the server will fail with KErrAlreadyExists.
       
    40     RProcess server;
       
    41     TInt r = server.Create(KVoIPServerName, KNullDesC, serverUid);
       
    42 
       
    43     if (r != KErrNone)
       
    44         {
       
    45         return r;
       
    46         }
       
    47 
       
    48     TRequestStatus stat;
       
    49     server.Rendezvous(stat);
       
    50 
       
    51     if (stat != KRequestPending)
       
    52         {
       
    53         server.Kill(0); // abort startup
       
    54         }
       
    55     else
       
    56         {
       
    57         server.Resume(); // logon OK - start the server
       
    58         }
       
    59 
       
    60     User::WaitForRequest(stat); // wait for start or death
       
    61 
       
    62     // Panic reason cannot be '0' as it would conflict with KErrNone
       
    63     r = (server.ExitType() == EExitPanic) ? KErrGeneral : stat.Int();
       
    64     server.Close();
       
    65     return r;
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // RVoIPAudioSession::Connect
       
    70 // Create a client-side session. Start the server if not started already.
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 EXPORT_C TInt RVoIPAudioSession::Connect()
       
    74     {
       
    75     TRACE_PRN_FN_ENT;
       
    76 
       
    77     TInt retry = KServerConnectRetries;
       
    78     TInt err = KErrGeneral;
       
    79     TInt numMessageSlots = KSessionMessageSlots;
       
    80 
       
    81     for (;;)
       
    82         {
       
    83         // Try to create a new session with the server
       
    84         err = CreateSession(KVoIPServerName, Version(), numMessageSlots);
       
    85 
       
    86         if ((err != KErrNotFound) && (err != KErrServerTerminated))
       
    87             {
       
    88             TRACE_PRN_N1(_L("[VAS session created; err==%d]"), err);
       
    89             break; // Connected to existing server - ok
       
    90             }
       
    91 
       
    92         if (--retry == 0)
       
    93             {
       
    94             break; // Failed.
       
    95             }
       
    96 
       
    97         // Server not running, try to start it.
       
    98         err = StartServer();
       
    99         TRACE_PRN_N1(_L("[VAS server started; err==%d]"), err);
       
   100 
       
   101         if ((err != KErrNone) && (err != KErrAlreadyExists))
       
   102             {
       
   103             break; // Server not launched - propagate error
       
   104             }
       
   105         }
       
   106 
       
   107     TRACE_PRN_FN_EXT;
       
   108     return err;
       
   109     }
       
   110 
       
   111 // -----------------------------------------------------------------------------
       
   112 // RVoIPAudioSession::Version
       
   113 // -----------------------------------------------------------------------------
       
   114 //
       
   115 EXPORT_C TVersion RVoIPAudioSession::Version() const
       
   116     {
       
   117     return (TVersion(KVoIPServMajorVersionNumber,
       
   118             KVoIPServMinorVersionNumber, KVoIPServBuildVersionNumber));
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // RVoIPAudioSession::Close
       
   123 // -----------------------------------------------------------------------------
       
   124 //
       
   125 EXPORT_C void RVoIPAudioSession::Close()
       
   126     {
       
   127     TRACE_PRN_FN_ENT;
       
   128 
       
   129     SendClientRequest(EVoIPSessionClose, TIpcArgs(TIpcArgs::ENothing));
       
   130     RSessionBase::Close();
       
   131 
       
   132     TRACE_PRN_FN_EXT;
       
   133     }
       
   134 
       
   135 // -----------------------------------------------------------------------------
       
   136 // RVoIPAudioSession::OpenDownlink
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 EXPORT_C TInt RVoIPAudioSession::OpenDownlink(
       
   140         const TMMFPrioritySettings aPriority)
       
   141     {
       
   142     TMMFPrioritySettingsPckg pckg;
       
   143     pckg() = aPriority;
       
   144     TIpcArgs args(&pckg);
       
   145     TInt err = SendClientRequest(EVoIPOpenDownlink, args);
       
   146     return err;
       
   147     }
       
   148 
       
   149 // -----------------------------------------------------------------------------
       
   150 // RVoIPAudioSession::GetMaxVolume
       
   151 // -----------------------------------------------------------------------------
       
   152 //
       
   153 EXPORT_C TInt RVoIPAudioSession::GetMaxVolume()
       
   154     {
       
   155     TInt maxVol = 0;
       
   156     TPckgBuf<TInt> pckg;
       
   157     TIpcArgs args(&pckg);
       
   158     SendClientRequest(EVoIPGetMaxVolume, args);
       
   159     maxVol = pckg();
       
   160     return maxVol;
       
   161     }
       
   162 
       
   163 // -----------------------------------------------------------------------------
       
   164 // RVoIPAudioSession::SetVolume
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 EXPORT_C TInt RVoIPAudioSession::SetVolume(const TInt aVolume)
       
   168     {
       
   169     TInt err = SendClientRequest(EVoIPSetVolume, TIpcArgs(aVolume));
       
   170     return err;
       
   171     }
       
   172 
       
   173 // -----------------------------------------------------------------------------
       
   174 // RVoIPAudioSession::GetVolume
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 EXPORT_C TInt RVoIPAudioSession::GetVolume()
       
   178     {
       
   179     TInt vol = 0;
       
   180     TVoIPMsgBufPckg pckg;
       
   181     TIpcArgs args(&pckg);
       
   182     TInt err = SendClientRequest(EVoIPGetVolume, args);
       
   183     if (err == KErrNone)
       
   184         {
       
   185         vol = pckg().iInt;
       
   186         err = pckg().iStatus;
       
   187         }
       
   188 
       
   189     return (err == KErrNone) ? vol : err;
       
   190     }
       
   191 
       
   192 // ---------------------------------------------------------------------------
       
   193 // RVoIPAudioSession::GetSupportedDecoders
       
   194 // ---------------------------------------------------------------------------
       
   195 //
       
   196 EXPORT_C TInt RVoIPAudioSession::GetSupportedDecoders(
       
   197         const TMMFPrioritySettings aPriority, RArray<TUint32>& aDecoders,
       
   198         TInt& aFrameSize)
       
   199     {
       
   200     TRACE_PRN_FN_ENT;
       
   201 
       
   202     TMMFPrioritySettingsPckg pckg;
       
   203     pckg() = aPriority;
       
   204     TIpcArgs args(&pckg);
       
   205     TInt err = SendClientRequest(EVoIPSetDecoderPriority, args);
       
   206 
       
   207     TVoIPMsgBufPckg pckg1;
       
   208     TIpcArgs args1(&pckg1);
       
   209     err = SendClientRequest(EVoIPGetSupportedDecodersCount, args1);
       
   210     TInt count = 0;
       
   211     aFrameSize = 0;
       
   212 
       
   213     if (err == KErrNone)
       
   214         {
       
   215         count = pckg1().iInt;
       
   216         aFrameSize = pckg1().iUint; //for 10/20ms frame detection
       
   217         err = pckg1().iStatus;
       
   218         }
       
   219 
       
   220     if (count > 0 && err == KErrNone)
       
   221         {
       
   222         TRAP(err, PopulateArrayL(EVoIPGetSupportedDecoders, aDecoders, count));
       
   223         }
       
   224 
       
   225     TRACE_PRN_FN_EXT;
       
   226     return err;
       
   227     }
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // RVoIPAudioSession::SetDecoder
       
   231 // -----------------------------------------------------------------------------
       
   232 //
       
   233 EXPORT_C TInt RVoIPAudioSession::SetDecoder(const TUint32 aDecoder)
       
   234     {
       
   235     TPckgBuf<TUint32> pckg;
       
   236     pckg() = aDecoder;
       
   237     TIpcArgs args(&pckg);
       
   238     TInt err = SendClientRequest(EVoIPSetDecoder, args);
       
   239     return err;
       
   240     }
       
   241 
       
   242 // -----------------------------------------------------------------------------
       
   243 // RVoIPAudioSession::SetAudioDevice
       
   244 // -----------------------------------------------------------------------------
       
   245 //
       
   246 EXPORT_C TInt RVoIPAudioSession::SetAudioDevice(
       
   247         const CVoIPAudioDownlinkStream::TVoIPOutputDevice aDevice)
       
   248     {
       
   249     TPckgBuf<TUint> pckg;
       
   250     pckg() = TUint(aDevice);
       
   251     TIpcArgs args(&pckg);
       
   252     TInt err = SendClientRequest(EVoIPSetAudioDevice, args);
       
   253     return err;
       
   254     }
       
   255 
       
   256 // -----------------------------------------------------------------------------
       
   257 // RVoIPAudioSession::GetAudioDevice
       
   258 // -----------------------------------------------------------------------------
       
   259 //
       
   260 EXPORT_C TInt RVoIPAudioSession::GetAudioDevice(
       
   261         CVoIPAudioDownlinkStream::TVoIPOutputDevice& aDevice)
       
   262     {
       
   263     TVoIPMsgBufPckg pckg;
       
   264     TIpcArgs args(&pckg);
       
   265     TInt err = SendClientRequest(EVoIPGetAudioDevice, args);
       
   266     if (err == KErrNone)
       
   267         {
       
   268         aDevice = (CVoIPAudioDownlinkStream::TVoIPOutputDevice) pckg().iUint;
       
   269         err = pckg().iStatus;
       
   270         }
       
   271 
       
   272     return err;
       
   273     }
       
   274 
       
   275 // -----------------------------------------------------------------------------
       
   276 // RVoIPAudioSession::StartDownlink
       
   277 // -----------------------------------------------------------------------------
       
   278 //
       
   279 EXPORT_C TInt RVoIPAudioSession::StartDownlink()
       
   280     {
       
   281     TInt err = SendClientRequest(EVoIPStartDownlink, TIpcArgs(TIpcArgs::ENothing));
       
   282     return err;
       
   283     }
       
   284 
       
   285 // -----------------------------------------------------------------------------
       
   286 // RVoIPAudioSession::StopDownlink
       
   287 // -----------------------------------------------------------------------------
       
   288 //
       
   289 EXPORT_C TInt RVoIPAudioSession::StopDownlink()
       
   290     {
       
   291     TInt err = SendClientRequest(EVoIPStopDownlink, TIpcArgs(TIpcArgs::ENothing));
       
   292     return err;
       
   293     }
       
   294 
       
   295 // -----------------------------------------------------------------------------
       
   296 // RVoIPAudioSession::CloseDownlink
       
   297 // -----------------------------------------------------------------------------
       
   298 //
       
   299 EXPORT_C void RVoIPAudioSession::CloseDownlink()
       
   300     {
       
   301     SendClientRequest(EVoIPCloseDownlink, TIpcArgs(TIpcArgs::ENothing));
       
   302     }
       
   303 
       
   304 // -----------------------------------------------------------------------------
       
   305 // RVoIPAudioSession::BufferFilled
       
   306 // -----------------------------------------------------------------------------
       
   307 //
       
   308 EXPORT_C TInt RVoIPAudioSession::BufferFilled(TPtr8 aBuffer,
       
   309         const TUint aBufferSequence)
       
   310     {
       
   311     TVoIPMsgBufPckg pckg;
       
   312     pckg().iInt = aBuffer.Size();
       
   313     pckg().iUint = aBufferSequence;
       
   314     TIpcArgs args(&pckg);
       
   315     TInt err = SendClientRequest(EVoIPBufferFilled, args);
       
   316     return err;
       
   317     }
       
   318 
       
   319 // For uplink stream
       
   320 
       
   321 // -----------------------------------------------------------------------------
       
   322 // RVoIPAudioSession::OpenUplink
       
   323 // -----------------------------------------------------------------------------
       
   324 //
       
   325 EXPORT_C TInt RVoIPAudioSession::OpenUplink(
       
   326         const TMMFPrioritySettings aPriority)
       
   327     {
       
   328     TMMFPrioritySettingsPckg pckg;
       
   329     pckg() = aPriority;
       
   330     TIpcArgs args(&pckg);
       
   331     TInt err = SendClientRequest(EVoIPOpenUplink, args);
       
   332     return err;
       
   333     }
       
   334 
       
   335 // -----------------------------------------------------------------------------
       
   336 // RVoIPAudioSession::GetMaxGain
       
   337 // -----------------------------------------------------------------------------
       
   338 //
       
   339 EXPORT_C TInt RVoIPAudioSession::GetMaxGain()
       
   340     {
       
   341     TInt maxGain = 0;
       
   342     TPckgBuf<TInt> pckg;
       
   343     TIpcArgs args(&pckg);
       
   344     SendClientRequest(EVoIPGetMaxGain, args);
       
   345     maxGain = pckg();
       
   346     return maxGain;
       
   347     }
       
   348 
       
   349 // -----------------------------------------------------------------------------
       
   350 // RVoIPAudioSession::SetGain
       
   351 // -----------------------------------------------------------------------------
       
   352 //
       
   353 EXPORT_C TInt RVoIPAudioSession::SetGain(const TInt aGain)
       
   354     {
       
   355     TInt err = SendClientRequest(EVoIPSetGain, TIpcArgs(aGain));
       
   356     return err;
       
   357     }
       
   358 
       
   359 // -----------------------------------------------------------------------------
       
   360 // RVoIPAudioSession::GetGain
       
   361 // -----------------------------------------------------------------------------
       
   362 //
       
   363 EXPORT_C TInt RVoIPAudioSession::GetGain()
       
   364     {
       
   365     TInt gain = 0;
       
   366     TVoIPMsgBufPckg pckg;
       
   367     TIpcArgs args(&pckg);
       
   368     TInt err = SendClientRequest(EVoIPGetGain, args);
       
   369     if (err == KErrNone)
       
   370         {
       
   371         gain = pckg().iInt;
       
   372         err = pckg().iStatus;
       
   373         }
       
   374 
       
   375     return (err == KErrNone) ? gain : err;
       
   376     }
       
   377 
       
   378 // ---------------------------------------------------------------------------
       
   379 // RVoIPAudioSession::GetSupportedEncodersL
       
   380 // ---------------------------------------------------------------------------
       
   381 //
       
   382 EXPORT_C TInt RVoIPAudioSession::GetSupportedEncoders(
       
   383         const TMMFPrioritySettings aPriority, RArray<TUint32>& aEncoders,
       
   384         TInt& aFrameSize)
       
   385     {
       
   386     TRACE_PRN_FN_ENT;
       
   387 
       
   388     TMMFPrioritySettingsPckg pckg;
       
   389     pckg() = aPriority;
       
   390     TIpcArgs args(&pckg);
       
   391     TInt err = SendClientRequest(EVoIPSetEncoderPriority, args);
       
   392 
       
   393     TVoIPMsgBufPckg pckg1;
       
   394     TIpcArgs args1(&pckg1);
       
   395     err = SendClientRequest(EVoIPGetSupportedEncodersCount, args1);
       
   396     TInt count = 0;
       
   397     aFrameSize = 0;
       
   398 
       
   399     if (err == KErrNone)
       
   400         {
       
   401         count = pckg1().iInt;
       
   402         aFrameSize = pckg1().iUint; //for 10/20ms frame detection
       
   403         err = pckg1().iStatus;
       
   404         }
       
   405 
       
   406     if (count > 0 && err == KErrNone)
       
   407         {
       
   408         TRAP(err, PopulateArrayL(EVoIPGetSupportedEncoders, aEncoders, count));
       
   409         }
       
   410 
       
   411     TRACE_PRN_FN_EXT;
       
   412     return err;
       
   413     }
       
   414 
       
   415 // -----------------------------------------------------------------------------
       
   416 // RVoIPAudioSession::SetEncoder
       
   417 // -----------------------------------------------------------------------------
       
   418 //
       
   419 EXPORT_C TInt RVoIPAudioSession::SetEncoder(const TUint32 aEncoder)
       
   420     {
       
   421     TPckgBuf<TUint32> pckg;
       
   422     pckg() = aEncoder;
       
   423     TIpcArgs args(&pckg);
       
   424     TInt err = SendClientRequest(EVoIPSetEncoder, args);
       
   425     return err;
       
   426     }
       
   427 
       
   428 // -----------------------------------------------------------------------------
       
   429 // RVoIPAudioSession::StartUplink
       
   430 // -----------------------------------------------------------------------------
       
   431 //
       
   432 EXPORT_C TInt RVoIPAudioSession::StartUplink()
       
   433     {
       
   434     TInt err = SendClientRequest(EVoIPStartUplink, TIpcArgs(TIpcArgs::ENothing));
       
   435     return err;
       
   436     }
       
   437 
       
   438 // -----------------------------------------------------------------------------
       
   439 // RVoIPAudioSession::StopUplink
       
   440 // -----------------------------------------------------------------------------
       
   441 //
       
   442 EXPORT_C TInt RVoIPAudioSession::StopUplink()
       
   443     {
       
   444     TInt err = SendClientRequest(EVoIPStopUplink, TIpcArgs(TIpcArgs::ENothing));
       
   445     return err;
       
   446     }
       
   447 
       
   448 // -----------------------------------------------------------------------------
       
   449 // RVoIPAudioSession::CloseUplink
       
   450 // -----------------------------------------------------------------------------
       
   451 //
       
   452 EXPORT_C void RVoIPAudioSession::CloseUplink()
       
   453     {
       
   454     SendClientRequest(EVoIPCloseUplink, TIpcArgs(TIpcArgs::ENothing));
       
   455     }
       
   456 
       
   457 // -----------------------------------------------------------------------------
       
   458 // RVoIPAudioSession::BufferEmptied
       
   459 // -----------------------------------------------------------------------------
       
   460 //
       
   461 EXPORT_C TInt RVoIPAudioSession::BufferEmptied(TPtr8 aBuffer)
       
   462     {
       
   463     TVoIPMsgBufPckg pckg;
       
   464     pckg().iInt = aBuffer.Size();
       
   465     TIpcArgs args(&pckg);
       
   466     TInt err = SendClientRequest(EVoIPBufferEmptied, args);
       
   467     return err;
       
   468     }
       
   469 
       
   470 // For codec CIs
       
   471 
       
   472 // -----------------------------------------------------------------------------
       
   473 // RVoIPAudioSession::GetSupportedBitRatesL
       
   474 // -----------------------------------------------------------------------------
       
   475 //
       
   476 EXPORT_C void RVoIPAudioSession::GetSupportedBitRatesL(RArray<TUint>& aArray)
       
   477     {
       
   478     TRACE_PRN_FN_ENT;
       
   479 
       
   480     TInt brCount = 0;
       
   481     TVoIPMsgBufPckg pckg;
       
   482     TIpcArgs args(&pckg);
       
   483     TInt err = SendClientRequest(EVoIPGetSupportedBitratesCount, args);
       
   484     if (err == KErrNone)
       
   485         {
       
   486         brCount = pckg().iInt;
       
   487         err = pckg().iStatus;
       
   488         }
       
   489 
       
   490     TRACE_PRN_N1(_L("BRCount [%d]"), brCount);
       
   491 
       
   492     if (brCount > 0 && err == KErrNone)
       
   493         {
       
   494         HBufC8* buf = HBufC8::NewLC(brCount * sizeof(TUint));
       
   495         TPtr8 ptr = buf->Des();
       
   496         TIpcArgs args1;
       
   497         args1.Set(0, &ptr);
       
   498         err = SendClientRequest(EVoIPGetSupportedBitrates, args1);
       
   499         if (err == KErrNone)
       
   500             {
       
   501             RDesReadStream stream(ptr);
       
   502             CleanupClosePushL(stream); // stream on cleanup
       
   503             aArray.Reset();
       
   504 
       
   505             for (TInt i = 0; i < brCount; i++)
       
   506                 {
       
   507                 aArray.Append(stream.ReadUint32L());
       
   508                 }
       
   509 
       
   510             CleanupStack::PopAndDestroy(&stream);
       
   511             }
       
   512 
       
   513         CleanupStack::PopAndDestroy(buf);
       
   514         }
       
   515 
       
   516     TRACE_PRN_FN_EXT;
       
   517     }
       
   518 
       
   519 // -----------------------------------------------------------------------------
       
   520 // RVoIPAudioSession::SetBitRate
       
   521 // -----------------------------------------------------------------------------
       
   522 //
       
   523 EXPORT_C TInt RVoIPAudioSession::SetBitRate(const TUint aBitrate)
       
   524     {
       
   525     TInt err = SendClientRequest(EVoIPSetBitrate, TIpcArgs(aBitrate));
       
   526     return err;
       
   527     }
       
   528 
       
   529 // -----------------------------------------------------------------------------
       
   530 // RVoIPAudioSession::GetBitRate
       
   531 // -----------------------------------------------------------------------------
       
   532 //
       
   533 EXPORT_C TInt RVoIPAudioSession::GetBitRate(TUint& aBitrate)
       
   534     {
       
   535     TVoIPMsgBufPckg pckg;
       
   536     TIpcArgs args(&pckg);
       
   537     TInt err = SendClientRequest(EVoIPGetBitrate, args);
       
   538     if (err == KErrNone)
       
   539         {
       
   540         aBitrate = pckg().iUint;
       
   541         err = pckg().iStatus;
       
   542         }
       
   543 
       
   544     return err;
       
   545     }
       
   546 
       
   547 // -----------------------------------------------------------------------------
       
   548 // RVoIPAudioSession::SetVAD
       
   549 // -----------------------------------------------------------------------------
       
   550 //
       
   551 EXPORT_C TInt RVoIPAudioSession::SetVAD(const TBool aVad)
       
   552     {
       
   553     TInt err = SendClientRequest(EVoIPSetVad, TIpcArgs(aVad));
       
   554     return err;
       
   555     }
       
   556 
       
   557 // -----------------------------------------------------------------------------
       
   558 // RVoIPAudioSession::GetVAD
       
   559 // -----------------------------------------------------------------------------
       
   560 //
       
   561 EXPORT_C TInt RVoIPAudioSession::GetVAD(TBool& aVad)
       
   562     {
       
   563     TVoIPMsgBufPckg pckg;
       
   564     TIpcArgs args(&pckg);
       
   565     TInt err = SendClientRequest(EVoIPGetVad, args);
       
   566     if (err == KErrNone)
       
   567         {
       
   568         aVad = pckg().iBool;
       
   569         err = pckg().iStatus;
       
   570         }
       
   571     return err;
       
   572     }
       
   573 
       
   574 // -----------------------------------------------------------------------------
       
   575 // RVoIPAudioSession::FrameModeRequiredForErrorConcealment
       
   576 // -----------------------------------------------------------------------------
       
   577 //
       
   578 EXPORT_C TInt RVoIPAudioSession::FrameModeRequiredForEC(TBool& aMode)
       
   579     {
       
   580     TVoIPMsgBufPckg pckg;
       
   581     TIpcArgs args(&pckg);
       
   582     TInt err = SendClientRequest(EVoIPFrameModeRqrdForEC, args);
       
   583     if (err == KErrNone)
       
   584         {
       
   585         aMode = pckg().iBool;
       
   586         err = pckg().iStatus;
       
   587         }
       
   588     return err;
       
   589     }
       
   590 
       
   591 // -----------------------------------------------------------------------------
       
   592 // RVoIPAudioSession::SetFrameMode
       
   593 // -----------------------------------------------------------------------------
       
   594 //
       
   595 EXPORT_C TInt RVoIPAudioSession::SetFrameMode(const TBool aMode)
       
   596     {
       
   597     TInt err = SendClientRequest(EVoIPSetFrameMode, TIpcArgs(aMode));
       
   598     return err;
       
   599     }
       
   600 
       
   601 // -----------------------------------------------------------------------------
       
   602 // RVoIPAudioSession::GetFrameMode
       
   603 // -----------------------------------------------------------------------------
       
   604 //
       
   605 EXPORT_C TInt RVoIPAudioSession::GetFrameMode(TBool& aMode)
       
   606     {
       
   607     TVoIPMsgBufPckg pckg;
       
   608     TIpcArgs args(&pckg);
       
   609     TInt err = SendClientRequest(EVoIPGetFrameMode, args);
       
   610     if (err == KErrNone)
       
   611         {
       
   612         aMode = pckg().iBool;
       
   613         err = pckg().iStatus;
       
   614         }
       
   615     return err;
       
   616     }
       
   617 
       
   618 // -----------------------------------------------------------------------------
       
   619 // RVoIPAudioSession::ConcealErrorForNextBuffer
       
   620 // -----------------------------------------------------------------------------
       
   621 //
       
   622 EXPORT_C TInt RVoIPAudioSession::ConcealErrorForNextBuffer()
       
   623     {
       
   624     TInt err = SendClientRequest(EVoIPConcealErrForNextBuf, TIpcArgs(TIpcArgs::ENothing));
       
   625     return err;
       
   626     }
       
   627 
       
   628 // -----------------------------------------------------------------------------
       
   629 // RVoIPAudioSession::SetMode
       
   630 // -----------------------------------------------------------------------------
       
   631 //
       
   632 EXPORT_C TInt RVoIPAudioSession::SetMode(
       
   633         const CVoIPFormatIntfc::TG711CodecMode aMode)
       
   634     {
       
   635     TPckgBuf<CVoIPFormatIntfc::TG711CodecMode> pckg;
       
   636     pckg() = aMode;
       
   637     TIpcArgs args(&pckg);
       
   638     TInt err = SendClientRequest(EVoIPSetG711CodecMode, args);
       
   639     return err;
       
   640     }
       
   641 
       
   642 // -----------------------------------------------------------------------------
       
   643 // RVoIPAudioSession::GetMode
       
   644 // -----------------------------------------------------------------------------
       
   645 //
       
   646 EXPORT_C TInt RVoIPAudioSession::GetMode(
       
   647         CVoIPFormatIntfc::TG711CodecMode& aMode)
       
   648     {
       
   649     TVoIPMsgBufPckg pckg;
       
   650     TIpcArgs args(&pckg);
       
   651     TInt err = SendClientRequest(EVoIPGetG711CodecMode, args);
       
   652     if (err == KErrNone)
       
   653         {
       
   654         aMode = (CVoIPFormatIntfc::TG711CodecMode) pckg().iUint;
       
   655         err = pckg().iStatus;
       
   656         }
       
   657     return err;
       
   658     }
       
   659 
       
   660 // -----------------------------------------------------------------------------
       
   661 // RVoIPAudioSession::SetMode
       
   662 // -----------------------------------------------------------------------------
       
   663 //
       
   664 EXPORT_C TInt RVoIPAudioSession::SetMode(
       
   665         const CVoIPFormatIntfc::TILBCCodecMode aMode)
       
   666     {
       
   667     TPckgBuf<CVoIPFormatIntfc::TILBCCodecMode> pckg;
       
   668     pckg() = aMode;
       
   669     TIpcArgs args(&pckg);
       
   670     TInt err = SendClientRequest(EVoIPSetIlbcCodecMode, args);
       
   671     return err;
       
   672     }
       
   673 
       
   674 // -----------------------------------------------------------------------------
       
   675 // RVoIPAudioSession::GetMode
       
   676 // -----------------------------------------------------------------------------
       
   677 //
       
   678 EXPORT_C TInt RVoIPAudioSession::GetMode(
       
   679         CVoIPFormatIntfc::TILBCCodecMode& aMode)
       
   680     {
       
   681     TVoIPMsgBufPckg pckg;
       
   682     TIpcArgs args(&pckg);
       
   683     TInt err = SendClientRequest(EVoIPGetIlbcCodecMode, args);
       
   684     if (err == KErrNone)
       
   685         {
       
   686         aMode = (CVoIPFormatIntfc::TILBCCodecMode) pckg().iUint;
       
   687         err = pckg().iStatus;
       
   688         }
       
   689 
       
   690     return err;
       
   691     }
       
   692 
       
   693 // -----------------------------------------------------------------------------
       
   694 // RVoIPAudioSession::SetCNG
       
   695 // -----------------------------------------------------------------------------
       
   696 //
       
   697 EXPORT_C TInt RVoIPAudioSession::SetCNG(const TBool aCng)
       
   698     {
       
   699     TInt err = SendClientRequest(EVoIPSetCng, TIpcArgs(aCng));
       
   700     return err;
       
   701     }
       
   702 
       
   703 // -----------------------------------------------------------------------------
       
   704 // RVoIPAudioSession::GetCNG
       
   705 // -----------------------------------------------------------------------------
       
   706 //
       
   707 EXPORT_C TInt RVoIPAudioSession::GetCNG(TBool& aCng)
       
   708     {
       
   709     TVoIPMsgBufPckg pckg;
       
   710     TIpcArgs args(&pckg);
       
   711     TInt err = SendClientRequest(EVoIPGetCng, args);
       
   712     if (err == KErrNone)
       
   713         {
       
   714         aCng = pckg().iBool;
       
   715         err = pckg().iStatus;
       
   716         }
       
   717 
       
   718     return err;
       
   719     }
       
   720 
       
   721 // -----------------------------------------------------------------------------
       
   722 // RVoIPAudioSession::SetPLC
       
   723 // -----------------------------------------------------------------------------
       
   724 //
       
   725 EXPORT_C TInt RVoIPAudioSession::SetPLC(const TBool aPlc)
       
   726     {
       
   727     TInt err = SendClientRequest(EVoIPSetPlc, TIpcArgs(aPlc));
       
   728     return err;
       
   729     }
       
   730 
       
   731 // -----------------------------------------------------------------------------
       
   732 // RVoIPAudioSession::GetPLC
       
   733 // -----------------------------------------------------------------------------
       
   734 //
       
   735 EXPORT_C TInt RVoIPAudioSession::GetPLC(TBool& aPlc)
       
   736     {
       
   737     TVoIPMsgBufPckg pckg;
       
   738     TIpcArgs args(&pckg);
       
   739     TInt err = SendClientRequest(EVoIPGetPlc, args);
       
   740     if (err == KErrNone)
       
   741         {
       
   742         aPlc = pckg().iBool;
       
   743         err = pckg().iStatus;
       
   744         }
       
   745     return err;
       
   746     }
       
   747 
       
   748 // -----------------------------------------------------------------------------
       
   749 // RVoIPAudioSession::BadLsfNextBuffer
       
   750 // -----------------------------------------------------------------------------
       
   751 //
       
   752 EXPORT_C TInt RVoIPAudioSession::BadLsfNextBuffer()
       
   753     {
       
   754     TInt err = SendClientRequest(EVoIPBadLsfNextBuffer, TIpcArgs(TIpcArgs::ENothing));
       
   755     return err;
       
   756     }
       
   757 
       
   758 // -----------------------------------------------------------------------------
       
   759 // RVoIPAudioSession::Open
       
   760 // -----------------------------------------------------------------------------
       
   761 //
       
   762 EXPORT_C TInt RVoIPAudioSession::OpenDTMFTonePlayer()
       
   763     {
       
   764     TInt err = SendClientRequest(EVoIPOpenDTMFTonePlayer, TIpcArgs(TIpcArgs::ENothing));
       
   765     return err;
       
   766     }
       
   767 
       
   768 // ---------------------------------------------------------------------------
       
   769 // RVoIPAudioSession::Play
       
   770 // ---------------------------------------------------------------------------
       
   771 //
       
   772 EXPORT_C TInt RVoIPAudioSession::PlayDTMFTone(const TDesC& aTones)
       
   773     {
       
   774     TTonesMsgBufPckg pckg;
       
   775     pckg().iFileName = aTones;
       
   776     TIpcArgs args(&pckg);
       
   777     TInt err = SendClientRequest(EVoIPPlayDTMFTone, args);
       
   778     return err;
       
   779     }
       
   780 
       
   781 // ---------------------------------------------------------------------------
       
   782 // RVoIPAudioSession::Stop
       
   783 // ---------------------------------------------------------------------------
       
   784 //
       
   785 EXPORT_C TInt RVoIPAudioSession::StopDTMFTonePlay()
       
   786     {
       
   787     TInt err = SendClientRequest(EVoIPStopDTMFTone, TIpcArgs(TIpcArgs::ENothing));
       
   788     return err;
       
   789     }
       
   790 
       
   791 // ---------------------------------------------------------------------------
       
   792 // RVoIPAudioSession::Close
       
   793 // ---------------------------------------------------------------------------
       
   794 //
       
   795 EXPORT_C void RVoIPAudioSession::CloseDTMFTonePlayer()
       
   796     {
       
   797     SendClientRequest(EVoIPCloseDTMFTonePlayer, TIpcArgs(TIpcArgs::ENothing));
       
   798     }
       
   799 
       
   800 // -----------------------------------------------------------------------------
       
   801 // RVoIPAudioSession::OpenRingTonePlayer
       
   802 // -----------------------------------------------------------------------------
       
   803 //
       
   804 EXPORT_C TInt RVoIPAudioSession::OpenRingTonePlayer()
       
   805     {
       
   806     TInt err = SendClientRequest(EVoIPOpenRingTonePlayerFromProfile, TIpcArgs(TIpcArgs::ENothing));
       
   807     return err;
       
   808     }
       
   809 
       
   810 // -----------------------------------------------------------------------------
       
   811 // RVoIPAudioSession::OpenRingTonePlayer
       
   812 // -----------------------------------------------------------------------------
       
   813 //
       
   814 EXPORT_C TInt RVoIPAudioSession::OpenRingTonePlayer(const TDesC& aFileName)
       
   815     {
       
   816     TTonesMsgBufPckg pckg;
       
   817     pckg().iFileName = aFileName;
       
   818     TIpcArgs args(&pckg);
       
   819     TInt err = SendClientRequest(EVoIPOpenRingTonePlayerFromFile, args);
       
   820     return err;
       
   821     }
       
   822 
       
   823 // -----------------------------------------------------------------------------
       
   824 // RVoIPAudioSession::OpenRingTonePlayer
       
   825 // -----------------------------------------------------------------------------
       
   826 //
       
   827 EXPORT_C TInt RVoIPAudioSession::OpenRingTonePlayer(const RFile& aFileHandle)
       
   828     {
       
   829     TIpcArgs args;
       
   830     aFileHandle.TransferToServer(args, 0, 1); //0=Fs, 1==file handle
       
   831     TInt err = SendClientRequest(EVoIPOpenRingTonePlayerFromRFile, args);
       
   832     return err;
       
   833     }
       
   834 
       
   835 // -----------------------------------------------------------------------------
       
   836 // RVoIPAudioSession::OpenRingTonePlayer
       
   837 // -----------------------------------------------------------------------------
       
   838 //
       
   839 EXPORT_C TInt RVoIPAudioSession::OpenRingTonePlayer(const TDesC8& aDesData)
       
   840     {
       
   841     TPtrC8 ptr(aDesData);
       
   842     TIpcArgs args;
       
   843     args.Set(0, &ptr);
       
   844     TInt err = SendClientRequest(EVoIPOpenRingTonePlayerFromDes, args);
       
   845     return err;
       
   846     }
       
   847 
       
   848 // -----------------------------------------------------------------------------
       
   849 // RVoIPAudioSession::PlayRingTone
       
   850 // -----------------------------------------------------------------------------
       
   851 //
       
   852 EXPORT_C TInt RVoIPAudioSession::PlayRingTone()
       
   853     {
       
   854     TInt err = SendClientRequest(EVoIPPlayRingTone, TIpcArgs(TIpcArgs::ENothing));
       
   855     return err;
       
   856     }
       
   857 
       
   858 // -----------------------------------------------------------------------------
       
   859 // RVoIPAudioSession::PauseRingTone
       
   860 // -----------------------------------------------------------------------------
       
   861 //
       
   862 EXPORT_C TInt RVoIPAudioSession::PauseRingTone()
       
   863     {
       
   864     TInt err = SendClientRequest(EVoIPPauseRingTone, TIpcArgs(TIpcArgs::ENothing));
       
   865     return err;
       
   866     }
       
   867 
       
   868 // -----------------------------------------------------------------------------
       
   869 // RVoIPAudioSession::ResumeRingTone
       
   870 // -----------------------------------------------------------------------------
       
   871 //
       
   872 EXPORT_C TInt RVoIPAudioSession::ResumeRingTone()
       
   873     {
       
   874     TInt err = SendClientRequest(EVoIPResumeRingTone, TIpcArgs(TIpcArgs::ENothing));
       
   875     return err;
       
   876     }
       
   877 
       
   878 // -----------------------------------------------------------------------------
       
   879 // RVoIPAudioSession::StopRingTone
       
   880 // -----------------------------------------------------------------------------
       
   881 //
       
   882 EXPORT_C TInt RVoIPAudioSession::StopRingTone()
       
   883     {
       
   884     TInt err = SendClientRequest(EVoIPStopRingTone, TIpcArgs(TIpcArgs::ENothing));
       
   885     return err;
       
   886     }
       
   887 
       
   888 // -----------------------------------------------------------------------------
       
   889 // RVoIPAudioSession::CloseRingTonePlayer
       
   890 // -----------------------------------------------------------------------------
       
   891 //
       
   892 EXPORT_C void RVoIPAudioSession::CloseRingTonePlayer()
       
   893     {
       
   894     SendClientRequest(EVoIPCloseRingTonePlayer, TIpcArgs(TIpcArgs::ENothing));
       
   895     }
       
   896 
       
   897 // -----------------------------------------------------------------------------
       
   898 // RVoIPAudioSession::ConfigureJitterBuffer
       
   899 // -----------------------------------------------------------------------------
       
   900 //
       
   901 EXPORT_C TInt RVoIPAudioSession::ConfigureJitterBuffer(
       
   902         const TVoIPJBConfig& aJbConfig)
       
   903     {
       
   904     TPckgBuf<TVoIPJBConfig> pckg;
       
   905     pckg() = aJbConfig;
       
   906     TIpcArgs args(&pckg);
       
   907     TInt err = SendClientRequest(EVoIPConfigJitterBuffer, args);
       
   908     return err;
       
   909     }
       
   910 
       
   911 // -----------------------------------------------------------------------------
       
   912 // RVoIPAudioSession::ResetJitterBuffer
       
   913 // -----------------------------------------------------------------------------
       
   914 //
       
   915 EXPORT_C TInt RVoIPAudioSession::ResetJitterBuffer(const TBool aPlayTone)
       
   916     {
       
   917     TInt err = SendClientRequest(EVoIPResetJitterBuffer, TIpcArgs(aPlayTone));
       
   918     return err;
       
   919     }
       
   920 
       
   921 // -----------------------------------------------------------------------------
       
   922 // RVoIPAudioSession::DelayDown
       
   923 // -----------------------------------------------------------------------------
       
   924 //
       
   925 EXPORT_C TInt RVoIPAudioSession::DelayDown()
       
   926     {
       
   927     TInt err = SendClientRequest(EVoIPJBDelayDown, TIpcArgs(TIpcArgs::ENothing));
       
   928     return err;
       
   929     }
       
   930 
       
   931 // -----------------------------------------------------------------------------
       
   932 // RVoIPAudioSession::DelayUp
       
   933 // -----------------------------------------------------------------------------
       
   934 //
       
   935 EXPORT_C TInt RVoIPAudioSession::DelayUp()
       
   936     {
       
   937     TInt err = SendClientRequest(EVoIPJBDelayUp, TIpcArgs(TIpcArgs::ENothing));
       
   938     return err;
       
   939     }
       
   940 
       
   941 // -----------------------------------------------------------------------------
       
   942 // RVoIPAudioSession::PopulateArrayL
       
   943 // -----------------------------------------------------------------------------
       
   944 //
       
   945 void RVoIPAudioSession::PopulateArrayL(
       
   946         TVoIPAudioClientServerRequest aRequest, RArray<TUint32>& aDecoders,
       
   947         TInt aCount)
       
   948     {
       
   949     HBufC8* buf = HBufC8::NewLC(aCount * sizeof(TUint32));
       
   950     TPtr8 ptr = buf->Des();
       
   951     TIpcArgs args;
       
   952     args.Set(0, &ptr);
       
   953     TInt err = SendClientRequest(aRequest, args);
       
   954 
       
   955     if (err == KErrNone)
       
   956         {
       
   957         RDesReadStream stream(ptr);
       
   958         CleanupClosePushL(stream);
       
   959         aDecoders.Reset();
       
   960 
       
   961         for (TInt i = 0; i < aCount; i++)
       
   962             {
       
   963             aDecoders.Append(stream.ReadUint32L());
       
   964             }
       
   965 
       
   966         CleanupStack::PopAndDestroy(&stream);
       
   967         }
       
   968 
       
   969     CleanupStack::PopAndDestroy(buf);
       
   970     }
       
   971 
       
   972 
       
   973 // -----------------------------------------------------------------------------
       
   974 // RVoIPAudioSession::SendClientRequest
       
   975 // -----------------------------------------------------------------------------
       
   976 //
       
   977 TInt RVoIPAudioSession::SendClientRequest(
       
   978         TVoIPAudioClientServerRequest aRequest, const TIpcArgs& aArgs) const
       
   979     {
       
   980     TInt status = KErrBadHandle;
       
   981     if (Handle())
       
   982         {
       
   983        // if (&aArgs == TIpcArgs::ENothing)
       
   984         status = SendReceive(aRequest, aArgs);
       
   985         }
       
   986     return status;
       
   987     }
       
   988 
       
   989 // End of file