mmserv/tms/tmsserver/src/tmsserversession.cpp
changeset 0 71ca22bcf22a
child 3 4f62049db6ac
equal deleted inserted replaced
-1:000000000000 0:71ca22bcf22a
       
     1 /*
       
     2  * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description: Telephony Multimedia Service
       
    15  *
       
    16  */
       
    17 
       
    18 #include <AudioPreference.h>
       
    19 #include "tmsutility.h"
       
    20 #include "tmsclientserver.h"
       
    21 #include "tmsshared.h"
       
    22 #include "tmsserversession.h"
       
    23 
       
    24 using namespace TMS;
       
    25 
       
    26 const TUint KArrayExpandSize = 8;
       
    27 
       
    28 // -----------------------------------------------------------------------------
       
    29 // TMSServerSession::NewL
       
    30 // Symbian constructor.
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 TMSServerSession* TMSServerSession::NewL(TMSServer &aServer)
       
    34     {
       
    35     TMSServerSession* self = new (ELeave) TMSServerSession(aServer);
       
    36     CleanupStack::PushL(self);
       
    37     self->ConstructL();
       
    38     CleanupStack::Pop(self);
       
    39     return self;
       
    40     }
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // TMSServerSession::~TMSServerSession
       
    44 // The destructor
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 TMSServerSession::~TMSServerSession()
       
    48     {
       
    49     TRACE_PRN_FN_ENT;
       
    50 
       
    51     iServer.DropSession(); // will start shutdown if no more sessions left
       
    52     delete iDevSound;
       
    53 
       
    54     if (iMsgQueue.Handle() > 0)
       
    55         {
       
    56         iMsgQueue.Close();
       
    57         }
       
    58 
       
    59     if (iTMSCallSessionHandle.Handle() > 0)
       
    60         {
       
    61         iTMSCallSessionHandle.Close();
       
    62         }
       
    63 
       
    64     // Release memory and close handles to unused plug-ins held by the DevSound
       
    65     REComSession::FinalClose();
       
    66 
       
    67     TRACE_PRN_FN_EXT;
       
    68     }
       
    69 
       
    70 // -----------------------------------------------------------------------------
       
    71 // TMSServerSession::ConstructL
       
    72 // 2-nd phase constructor.
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 void TMSServerSession::ConstructL()
       
    76     {
       
    77     TRACE_PRN_FN_ENT;
       
    78     TRACE_PRN_FN_EXT;
       
    79     }
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // TMSServerSession::TMSServerSession
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 TMSServerSession::TMSServerSession(TMSServer &aServer) :
       
    86     iServer(aServer)
       
    87     {
       
    88     TRACE_PRN_FN_ENT;
       
    89     iServer.AddSession();
       
    90     TRACE_PRN_FN_EXT;
       
    91     }
       
    92 
       
    93 // -----------------------------------------------------------------------------
       
    94 // TMSServerSession::ServiceL
       
    95 // Service request handler.
       
    96 // -----------------------------------------------------------------------------
       
    97 //
       
    98 void TMSServerSession::ServiceL(const RMessage2& aMessage)
       
    99     {
       
   100     TRAPD(err, DispatchMessageL(aMessage));
       
   101 
       
   102     if (err != KErrNone)
       
   103         {
       
   104         aMessage.Complete(err);
       
   105         }
       
   106     }
       
   107 
       
   108 // -----------------------------------------------------------------------------
       
   109 // TMSServerSession::DispatchMessageL
       
   110 // Service request handler.
       
   111 // -----------------------------------------------------------------------------
       
   112 //
       
   113 void TMSServerSession::DispatchMessageL(const RMessage2& aMessage)
       
   114     {
       
   115     switch (aMessage.Function())
       
   116         {
       
   117         case ETMSCallSessionHandle:
       
   118             GetTMSCallSessionHandleL(aMessage);
       
   119             break;
       
   120         case ETMSGetSupportedEncodersCount:
       
   121             GetCodecsCountL(aMessage, TMS_STREAM_UPLINK);
       
   122             break;
       
   123         case ETMSGetSupportedDecodersCount:
       
   124             GetCodecsCountL(aMessage, TMS_STREAM_DOWNLINK);
       
   125             break;
       
   126         case ETMSGetSupportedEncoders:
       
   127             GetSupportedCodecsL(aMessage, TMS_STREAM_UPLINK);
       
   128             break;
       
   129         case ETMSGetSupportedDecoders:
       
   130             GetSupportedCodecsL(aMessage, TMS_STREAM_DOWNLINK);
       
   131             break;
       
   132         case ETMSSetOutput:
       
   133             SetOutput(aMessage);
       
   134             break;
       
   135         case ETMSGetOutput:
       
   136             iServer.GetOutput(aMessage);
       
   137             break;
       
   138         case ETMSGetPreviousOutput:
       
   139             iServer.GetPreviousOutput(aMessage);
       
   140             break;
       
   141         case ETMSGetAvailableOutputs:
       
   142             iServer.GetAvailableOutputs(aMessage);
       
   143             break;
       
   144         case ETMSStartRoutingNotifier:
       
   145             iServer.StartRoutingNotifierL();
       
   146             aMessage.Complete(KErrNone);
       
   147             break;
       
   148         case ETMSCancelRoutingNotifier:
       
   149             iServer.CancelRoutingNotifier();
       
   150             aMessage.Complete(KErrNone);
       
   151             break;
       
   152         case ETMSStartGlobalEffectNotifier:
       
   153             iServer.StartCenRepHandlerL();
       
   154             aMessage.Complete(KErrNone);
       
   155             break;
       
   156         case ETMSCancelGlobalEffectNotifier:
       
   157             iServer.CancelCenRepHandler();
       
   158             aMessage.Complete(KErrNone);
       
   159             break;
       
   160         case ETMSSetMsgQueueHandle:
       
   161             SetMessageQueueHandleL(aMessage);
       
   162             break;
       
   163         case ETMSSetGlobalVol:
       
   164             SetVolLevel(aMessage);
       
   165             break;
       
   166         case ETMSGetGlobalVol:
       
   167             iServer.GetLevel(aMessage);
       
   168             break;
       
   169         case ETMSGetMaxGlobalVol:
       
   170             iServer.GetMaxLevel(aMessage);
       
   171             break;
       
   172         case ETMSSetGlobalGain:
       
   173             SetMicGain(aMessage);
       
   174             break;
       
   175         case ETMSGetGlobalGain:
       
   176             iServer.GetGain(aMessage);
       
   177             break;
       
   178         case ETMSGetMaxGlobalGain:
       
   179             iServer.GetMaxGain(aMessage);
       
   180             break;
       
   181         default:
       
   182             User::Leave(KErrNotSupported);
       
   183             break;
       
   184         }
       
   185     }
       
   186 
       
   187 // -----------------------------------------------------------------------------
       
   188 // TMSServerSession::SetMessageQueueHandleL
       
   189 //
       
   190 // Open message queue for handling server notifications back to the client.
       
   191 // -----------------------------------------------------------------------------
       
   192 //
       
   193 void TMSServerSession::SetMessageQueueHandleL(const RMessage2& aMessage)
       
   194     {
       
   195     gint status = KErrNone;
       
   196     if (iMsgQueue.Handle() <= 0)
       
   197         {
       
   198         status = iMsgQueue.Open(aMessage, 0);
       
   199         }
       
   200     if (status != KErrNone)
       
   201         {
       
   202         User::Leave(KErrArgument);
       
   203         }
       
   204     aMessage.Complete(KErrNone);
       
   205     }
       
   206 
       
   207 // -----------------------------------------------------------------------------
       
   208 // TMSServerSession::SetVolLevel
       
   209 // -----------------------------------------------------------------------------
       
   210 //
       
   211 void TMSServerSession::SetVolLevel(const RMessage2& aMessage)
       
   212     {
       
   213     TInt level = aMessage.Int0();
       
   214     iServer.SetLevel(this, TRUE, level);
       
   215     aMessage.Complete(KErrNone);
       
   216     }
       
   217 
       
   218 // -----------------------------------------------------------------------------
       
   219 // TMSServerSession::SetMicGain
       
   220 // -----------------------------------------------------------------------------
       
   221 //
       
   222 void TMSServerSession::SetMicGain(const RMessage2& aMessage)
       
   223     {
       
   224     TInt gain = aMessage.Int0();
       
   225     iServer.SetGain(this, gain);
       
   226     aMessage.Complete(KErrNone);
       
   227     }
       
   228 
       
   229 // -----------------------------------------------------------------------------
       
   230 // TMSServerSession::HandleGlobalEffectChange
       
   231 // -----------------------------------------------------------------------------
       
   232 //
       
   233 void TMSServerSession::HandleGlobalEffectChange(TInt globalevent)
       
   234     {
       
   235     TRACE_PRN_FN_ENT;
       
   236     iMsgBuffer.iRequest = ECmdGlobalEffectChange;
       
   237     iMsgBuffer.iStatus = KErrNone;
       
   238     iMsgBuffer.iInt = globalevent;
       
   239     NotifyClient();
       
   240     TRACE_PRN_FN_EXT;
       
   241     }
       
   242 
       
   243 // -----------------------------------------------------------------------------
       
   244 // TMSServerSession::HandleRoutingChange
       
   245 // -----------------------------------------------------------------------------
       
   246 //
       
   247 void TMSServerSession::HandleRoutingChange(TRoutingMsgBufPckg routinginfo)
       
   248     {
       
   249     TRACE_PRN_FN_ENT;
       
   250     iMsgBuffer.iRequest = ECmdGlobalRoutingChange;
       
   251     iMsgBuffer.iStatus = KErrNone;
       
   252     iMsgBuffer.iInt = routinginfo().iEvent;
       
   253     iMsgBuffer.iUint = routinginfo().iOutput;
       
   254     NotifyClient();
       
   255     TRACE_PRN_FN_EXT;
       
   256     }
       
   257 
       
   258 // -----------------------------------------------------------------------------
       
   259 // TMSServerSession::GetTMSCallSessionHandleL
       
   260 // -----------------------------------------------------------------------------
       
   261 //
       
   262 void TMSServerSession::GetTMSCallSessionHandleL(const RMessage2& aMessage)
       
   263     {
       
   264     TRACE_PRN_FN_ENT;
       
   265     if (iTMSCallSessionHandle.Handle() == 0)
       
   266         {
       
   267         iServer.GetNewTMSCallSessionHandleL(iTMSCallSessionHandle);
       
   268         }
       
   269     aMessage.Complete(iTMSCallSessionHandle);
       
   270     TRACE_PRN_FN_EXT;
       
   271     }
       
   272 
       
   273 // -----------------------------------------------------------------------------
       
   274 // TMSServerSession::GetCodecsCountL
       
   275 //
       
   276 // Note: Currently, no data persists as a new session is created each time
       
   277 //       before calling this method.
       
   278 // -----------------------------------------------------------------------------
       
   279 //
       
   280 void TMSServerSession::GetCodecsCountL(const RMessage2& aMessage,
       
   281         TMSStreamType strmType)
       
   282     {
       
   283     TInt err = KErrNone;
       
   284     TInt codecsCount = 0;
       
   285 
       
   286     RArray<TFourCC>* codecs;
       
   287     iServer.GetSupportedCodecs(strmType, codecs);
       
   288 
       
   289     if (codecs)
       
   290         {
       
   291         codecsCount = codecs->Count();
       
   292         }
       
   293 
       
   294     if (codecsCount <= 0)
       
   295         {
       
   296         delete iDevSound;
       
   297         iDevSound = NULL;
       
   298         iDevSound = CMMFDevSound::NewL();
       
   299 
       
   300         if (iDevSound)
       
   301             {
       
   302             codecs->Reset();
       
   303             TMMFPrioritySettings priority;
       
   304 
       
   305             if (strmType == TMS_STREAM_UPLINK)
       
   306                 {
       
   307                 iDevSound->GetSupportedInputDataTypesL(*codecs, priority);
       
   308                 }
       
   309             else if (strmType == TMS_STREAM_DOWNLINK)
       
   310                 {
       
   311                 iDevSound->GetSupportedOutputDataTypesL(*codecs, priority);
       
   312                 }
       
   313             else
       
   314                 {
       
   315                 err = KErrNotSupported;
       
   316                 }
       
   317 
       
   318 #ifdef __WINSCW__
       
   319             // Support for adaptation stubs
       
   320             codecs->Append(KMccFourCCIdG711);
       
   321             codecs->Append(KMccFourCCIdG729);
       
   322             codecs->Append(KMccFourCCIdILBC);
       
   323             codecs->Append(KMccFourCCIdAMRNB);
       
   324 #endif
       
   325             codecsCount = codecs->Count();
       
   326             }
       
   327 
       
   328         delete iDevSound;
       
   329         iDevSound = NULL;
       
   330         }
       
   331 
       
   332     TmsMsgBufPckg p;
       
   333     p().iInt = codecsCount;
       
   334 #ifndef __WINSCW__
       
   335     p().iUint = 0; // G711 frame size undetermined
       
   336     //TODO: query G.711 codec to find its correct frame size (10 or 20 ms)
       
   337 #else
       
   338     p().iUint = KTMSG711FrameLen20ms;
       
   339 #endif //__WINSCW__
       
   340     p().iStatus = err;
       
   341     aMessage.WriteL(0, p);
       
   342     aMessage.Complete(KErrNone);
       
   343     }
       
   344 
       
   345 // -----------------------------------------------------------------------------
       
   346 // TMSServerSession::GetSupportedEncodersL
       
   347 //
       
   348 // -----------------------------------------------------------------------------
       
   349 //
       
   350 void TMSServerSession::GetSupportedCodecsL(const RMessage2& aMessage,
       
   351         TMSStreamType strmType)
       
   352     {
       
   353     TRACE_PRN_FN_ENT;
       
   354 
       
   355     CBufFlat* dataCopyBuffer = CBufFlat::NewL(KArrayExpandSize);
       
   356     CleanupStack::PushL(dataCopyBuffer);
       
   357     RBufWriteStream stream;
       
   358     stream.Open(*dataCopyBuffer);
       
   359     CleanupClosePushL(stream);
       
   360 
       
   361     RArray<TFourCC>* codecs;
       
   362     iServer.GetSupportedCodecs(strmType, codecs);
       
   363     TInt codecsCount = 0;
       
   364     codecsCount = codecs->Count();
       
   365 
       
   366     for (TInt i = 0; i < codecsCount; i++)
       
   367         {
       
   368         TFourCC fcc = (codecs->Array())[i];
       
   369         stream.WriteUint32L(fcc.FourCC());
       
   370         TRACE_PRN_N2(_L("TMS->Codec[%d]==[0x%x]"), i+1, fcc.FourCC());
       
   371         }
       
   372 
       
   373     aMessage.WriteL(0, dataCopyBuffer->Ptr(0));
       
   374     CleanupStack::PopAndDestroy(&stream);
       
   375     CleanupStack::PopAndDestroy(dataCopyBuffer);
       
   376     aMessage.Complete(KErrNone);
       
   377 
       
   378     TRACE_PRN_FN_EXT;
       
   379     }
       
   380 
       
   381 // -----------------------------------------------------------------------------
       
   382 // TMSServerSession::SetOutput
       
   383 // -----------------------------------------------------------------------------
       
   384 //
       
   385 void TMSServerSession::SetOutput(const RMessage2& aMessage)
       
   386     {
       
   387     TInt output = aMessage.Int0();
       
   388     iServer.SetOutput(this, output);
       
   389     aMessage.Complete(KErrNone);
       
   390     }
       
   391 
       
   392 // -----------------------------------------------------------------------------
       
   393 // TMSServerSession::NotifyClient
       
   394 // -----------------------------------------------------------------------------
       
   395 //
       
   396 void TMSServerSession::NotifyClient()
       
   397     {
       
   398     if (iMsgQueue.Handle() > 0)
       
   399         {
       
   400         iMsgQueue.Send(iMsgBuffer);
       
   401         }
       
   402     }
       
   403 
       
   404 // End of file