mmserv/tms/tmsimpl/src/tmsstreambodyimpl.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 <stdio.h>
       
    19 #include <tms.h>
       
    20 #include <tmsstreamobsrvr.h>
       
    21 #include <tmsbuffer.h>
       
    22 #include <tmseffect.h>
       
    23 #include <tmsformat.h>
       
    24 #include "tmsutility.h"
       
    25 #include "tmscallproxy.h"
       
    26 #include "tmsclientserver.h"
       
    27 #include "tmsshared.h"
       
    28 #include "tmsstreambodyimpl.h"
       
    29 #include "tmsmembuffer.h"
       
    30 #include "tmsclientsourceimpl.h"
       
    31 #include "tmsclientsinkimpl.h"
       
    32 #include "tmsvolumeeffectimpl.h"
       
    33 #include "tmsgaineffectimpl.h"
       
    34 #include "tmsg711formatimpl.h"
       
    35 #include "tmsg729formatimpl.h"
       
    36 #include "tmsilbcformatimpl.h"
       
    37 #include "tmspcmformatimpl.h"
       
    38 #include "tmsamrformatimpl.h"
       
    39 
       
    40 using namespace TMS;
       
    41 
       
    42 TMSStreamBodyImpl::TMSStreamBodyImpl() :
       
    43     iProxy(NULL),
       
    44     iParent(NULL),
       
    45     iSource(NULL),
       
    46     iSink(NULL),
       
    47     iMsgQHandler(NULL),
       
    48     iObserver(NULL),
       
    49     iFormat(NULL),
       
    50     iStreamState(TMS_STREAM_UNINITIALIZED)
       
    51     {
       
    52     //TMSStream::Construct(this);
       
    53     }
       
    54 
       
    55 TMSStreamBodyImpl::~TMSStreamBodyImpl()
       
    56     {
       
    57     if (iMsgQHandler)
       
    58         {
       
    59         iMsgQHandler->Cancel();
       
    60         }
       
    61     delete iMsgQHandler;
       
    62     if (iMsgQueue.Handle() > 0)
       
    63         {
       
    64         iMsgQueue.Close();
       
    65         }
       
    66 
       
    67     iEffectsList.Reset();
       
    68 
       
    69     if (iContext.CallProxy && (iContext.StreamId != -1))
       
    70         {
       
    71         iContext.CallProxy->DeleteStream(iContext.CallType,
       
    72                 iContext.StreamType, iContext.StreamId);
       
    73         }
       
    74     }
       
    75 
       
    76 gint TMSStreamBodyImpl::Create(TMSCallType callType, TMSStreamType stype,
       
    77         TMSCallProxy* proxy, TMSStream& parent, TMSStreamBody*& bodyimpl)
       
    78     {
       
    79     gint ret(TMS_RESULT_INSUFFICIENT_MEMORY);
       
    80     TMSStreamBodyImpl* self = new TMSStreamBodyImpl;
       
    81     if (self)
       
    82         {
       
    83         ret = self->PostConstruct(callType, stype, proxy, parent);
       
    84         if (ret != TMS_RESULT_SUCCESS)
       
    85             {
       
    86             delete self;
       
    87             self = NULL;
       
    88             }
       
    89         }
       
    90     bodyimpl = self;
       
    91     return ret;
       
    92     }
       
    93 
       
    94 gint TMSStreamBodyImpl::PostConstruct(TMSCallType callType,
       
    95         TMSStreamType stype, TMSCallProxy* proxy, TMSStream& parent)
       
    96     {
       
    97     gint status(TMS_RESULT_SUCCESS);
       
    98     iContext.CallProxy = proxy;
       
    99     iParent = &parent;
       
   100     iContext.CallType = callType;
       
   101     iContext.StreamType = stype;
       
   102 
       
   103     status = CreateQueue(KTMSMsgQSlots);
       
   104 
       
   105     if (status == TMS_RESULT_SUCCESS)
       
   106         {
       
   107         if (iContext.CallProxy)
       
   108             {
       
   109             status = (iContext.CallProxy)->CreateStream(iContext.CallType,
       
   110                     iContext.StreamType, iContext.StreamId);
       
   111             }
       
   112         else
       
   113             {
       
   114             status = TMS_RESULT_UNINITIALIZED_OBJECT;
       
   115             }
       
   116         }
       
   117     return status;
       
   118     }
       
   119 
       
   120 gint TMSStreamBodyImpl::AddObserver(TMSStreamObserver& obsrvr,
       
   121         gpointer user_data)
       
   122     {
       
   123     gint ret(TMS_RESULT_SUCCESS);
       
   124     // TODO allow support for multiple observers
       
   125     if (!iObserver)
       
   126         {
       
   127         iObserver = &obsrvr;
       
   128         iUserData = user_data;
       
   129         }
       
   130     else
       
   131         {
       
   132         ret = TMS_RESULT_ALREADY_EXIST;
       
   133         }
       
   134     return ret;
       
   135     }
       
   136 
       
   137 gint TMSStreamBodyImpl::RemoveObserver(TMSStreamObserver& obsrvr)
       
   138     {
       
   139     gint ret(TMS_RESULT_SUCCESS);
       
   140     if (&obsrvr == iObserver)
       
   141         {
       
   142         iObserver = NULL;
       
   143         }
       
   144     else
       
   145         {
       
   146         ret = TMS_RESULT_DOES_NOT_EXIST;
       
   147         }
       
   148     return ret;
       
   149     }
       
   150 
       
   151 gint TMSStreamBodyImpl::AddSource(TMSSource* source)
       
   152     {
       
   153     gint ret(TMS_RESULT_SUCCESS);
       
   154 
       
   155     if (iStreamState == TMS_STREAM_UNINITIALIZED)
       
   156         {
       
   157         if (!iSource)
       
   158             {
       
   159             ret = ValidateSource(source);
       
   160             }
       
   161         else
       
   162             {
       
   163             ret = TMS_RESULT_ALREADY_EXIST;
       
   164             }
       
   165         }
       
   166     else
       
   167         {
       
   168         ret = TMS_RESULT_INVALID_STATE;
       
   169         }
       
   170     return ret;
       
   171     }
       
   172 
       
   173 gint TMSStreamBodyImpl::RemoveSource(TMSSource* source)
       
   174     {
       
   175     gint ret(TMS_RESULT_SUCCESS);
       
   176     if (iStreamState == TMS_STREAM_UNINITIALIZED)
       
   177         {
       
   178         if (source == iSource)
       
   179             {
       
   180             iSource = NULL;
       
   181             }
       
   182         else
       
   183             {
       
   184             ret = TMS_RESULT_DOES_NOT_EXIST;
       
   185             }
       
   186         }
       
   187     else
       
   188         {
       
   189         ret = TMS_RESULT_INVALID_STATE;
       
   190         }
       
   191     return ret;
       
   192     }
       
   193 
       
   194 gint TMSStreamBodyImpl::AddSink(TMSSink* sink)
       
   195     {
       
   196     gint ret(TMS_RESULT_SUCCESS);
       
   197 
       
   198     if (iStreamState == TMS_STREAM_UNINITIALIZED)
       
   199         {
       
   200         if (!iSink)
       
   201             {
       
   202             ret = ValidateSink(sink);
       
   203             }
       
   204         else
       
   205             {
       
   206             ret = TMS_RESULT_ALREADY_EXIST;
       
   207             }
       
   208         }
       
   209     else
       
   210         {
       
   211         ret = TMS_RESULT_INVALID_STATE;
       
   212         }
       
   213     return ret;
       
   214     }
       
   215 
       
   216 gint TMSStreamBodyImpl::RemoveSink(TMSSink* sink)
       
   217     {
       
   218     gint ret(TMS_RESULT_SUCCESS);
       
   219 
       
   220     if (iStreamState == TMS_STREAM_UNINITIALIZED)
       
   221         {
       
   222         if (sink == iSink)
       
   223             {
       
   224             iSink = NULL;
       
   225             }
       
   226         else
       
   227             {
       
   228             ret = TMS_RESULT_DOES_NOT_EXIST;
       
   229             }
       
   230         }
       
   231     else
       
   232         {
       
   233         ret = TMS_RESULT_INVALID_STATE;
       
   234         }
       
   235     return ret;
       
   236     }
       
   237 
       
   238 gint TMSStreamBodyImpl::SetFormat(TMSFormat* format)
       
   239     {
       
   240     gint ret(TMS_RESULT_SUCCESS);
       
   241     if (iStreamState == TMS_STREAM_UNINITIALIZED)
       
   242         {
       
   243         ret = ValidateFormat(format);
       
   244         }
       
   245     else
       
   246         {
       
   247         ret = TMS_RESULT_INVALID_STATE;
       
   248         }
       
   249     return ret;
       
   250     }
       
   251 
       
   252 gint TMSStreamBodyImpl::ResetFormat(TMSFormat* format)
       
   253     {
       
   254     gint ret(TMS_RESULT_SUCCESS);
       
   255     if (iStreamState == TMS_STREAM_UNINITIALIZED)
       
   256         {
       
   257         if (format == iFormat)
       
   258             {
       
   259             iFormat = NULL;
       
   260             }
       
   261         else
       
   262             {
       
   263             ret = TMS_RESULT_DOES_NOT_EXIST;
       
   264             }
       
   265         }
       
   266     else
       
   267         {
       
   268         ret = TMS_RESULT_INVALID_STATE;
       
   269         }
       
   270     return ret;
       
   271     }
       
   272 
       
   273 gint TMSStreamBodyImpl::AddEffect(TMSEffect* effect)
       
   274     {
       
   275     gint ret(TMS_RESULT_SUCCESS);
       
   276 
       
   277     if (iStreamState == TMS_STREAM_UNINITIALIZED)
       
   278         {
       
   279         // Add to list if effect is not already added
       
   280         ret = iEffectsList.Find(effect);
       
   281         if (ret == KErrNotFound)
       
   282             {
       
   283             ret = iEffectsList.Append(effect);
       
   284             }
       
   285         else
       
   286             {
       
   287             ret = TMS_RESULT_ALREADY_EXIST;
       
   288             }
       
   289         }
       
   290     else
       
   291         {
       
   292         ret = TMS_RESULT_INVALID_STATE;
       
   293         }
       
   294     return ret;
       
   295     }
       
   296 
       
   297 gint TMSStreamBodyImpl::RemoveEffect(TMSEffect* effect)
       
   298     {
       
   299     TInt status(TMS_RESULT_SUCCESS);
       
   300 
       
   301     if (iStreamState == TMS_STREAM_UNINITIALIZED)
       
   302         {
       
   303         TInt index = iEffectsList.Find(effect);
       
   304         // If found status has index to the effect in the array
       
   305         // else it would contain KErrNotFound
       
   306         if (index >= 0)
       
   307             {
       
   308             iEffectsList.Remove(index);
       
   309             }
       
   310         else
       
   311             {
       
   312             status = TMS_RESULT_DOES_NOT_EXIST;
       
   313             }
       
   314         }
       
   315     else
       
   316         {
       
   317         status = TMS_RESULT_INVALID_STATE;
       
   318         }
       
   319     return status;
       
   320     }
       
   321 
       
   322 TMSStreamState TMSStreamBodyImpl::GetState()
       
   323     {
       
   324     return iStreamState;
       
   325     }
       
   326 
       
   327 TMSStreamType TMSStreamBodyImpl::GetStreamType()
       
   328     {
       
   329     return iContext.StreamType;
       
   330     }
       
   331 
       
   332 gint TMSStreamBodyImpl::GetStreamId()
       
   333     {
       
   334     return iContext.StreamId;
       
   335     }
       
   336 
       
   337 gint TMSStreamBodyImpl::Init()
       
   338     {
       
   339     gint ret(TMS_RESULT_SUCCESS);
       
   340 
       
   341     ret = ValidateStream();
       
   342 
       
   343     RET_REASON_IF_ERR(ret);
       
   344 
       
   345     TMSFormatType fmttype;
       
   346     if (!iFormat && iContext.CallType == TMS_CALL_IP)
       
   347         {
       
   348         return TMS_RESULT_FORMAT_TYPE_UNSPECIFIED;
       
   349         }
       
   350     else if (iContext.CallType == TMS_CALL_IP)
       
   351         {
       
   352         iFormat->GetType(fmttype);
       
   353         }
       
   354 
       
   355     if (iContext.CallProxy)
       
   356         {
       
   357         ret = (iContext.CallProxy)->InitStream(iContext.CallType,
       
   358                 iContext.StreamType, iContext.StreamId, fmttype, &iMsgQueue);
       
   359         }
       
   360     else
       
   361         {
       
   362         ret = TMS_RESULT_UNINITIALIZED_OBJECT;
       
   363         }
       
   364 
       
   365     RET_REASON_IF_ERR(ret);
       
   366 
       
   367     if (iEffectsList.Count())
       
   368         {
       
   369         for (TInt i = 0; i < iEffectsList.Count(); i++)
       
   370             {
       
   371             TMSEffectType effecttype;
       
   372             iEffectsList[i]->GetType(effecttype);
       
   373             switch (effecttype)
       
   374                 {
       
   375                 case TMS_EFFECT_GAIN:
       
   376                     ((TMSGainEffectImpl*) iEffectsList[i])->SetProxy(
       
   377                             iContext.CallProxy, iMsgQHandler);
       
   378                     break;
       
   379                 case TMS_EFFECT_VOLUME:
       
   380                     ((TMSVolumeEffectImpl*) iEffectsList[i])->SetProxy(
       
   381                             iContext.CallProxy, iMsgQHandler);
       
   382                     break;
       
   383                 default:
       
   384                     ret = TMS_RESULT_INVALID_ARGUMENT;
       
   385                     break;
       
   386                 }
       
   387             }
       
   388         }
       
   389 
       
   390     if (iFormat)
       
   391         {
       
   392         TMSFormatType fmttype;
       
   393         iFormat->GetType(fmttype);
       
   394         switch (fmttype)
       
   395             {
       
   396             case TMS_FORMAT_PCM:
       
   397                 ((TMSPCMFormatImpl*) iFormat)->SetProxy(&iContext,
       
   398                         iMsgQHandler);
       
   399                 break;
       
   400             case TMS_FORMAT_AMR:
       
   401                 ((TMSAMRFormatImpl*) iFormat)->SetProxy(&iContext,
       
   402                         iMsgQHandler);
       
   403                 break;
       
   404             case TMS_FORMAT_G711:
       
   405                 ((TMSG711FormatImpl*) iFormat)->SetProxy(&iContext,
       
   406                         iMsgQHandler);
       
   407                 break;
       
   408             case TMS_FORMAT_G729:
       
   409                 ((TMSG729FormatImpl*) iFormat)->SetProxy(&iContext,
       
   410                         iMsgQHandler);
       
   411                 break;
       
   412             case TMS_FORMAT_ILBC:
       
   413                 ((TMSILBCFormatImpl*) iFormat)->SetProxy(&iContext,
       
   414                         iMsgQHandler);
       
   415                 break;
       
   416             default:
       
   417                 ret = TMS_RESULT_INVALID_ARGUMENT;
       
   418                 break;
       
   419             }
       
   420         }
       
   421 
       
   422     if (iContext.StreamType == TMS_STREAM_UPLINK)
       
   423         {
       
   424         if (iSink)
       
   425             {
       
   426             TMSSinkType sinkType;
       
   427             iSink->GetType(sinkType);
       
   428             switch (sinkType)
       
   429                 {
       
   430                 case TMS_SINK_CLIENT:
       
   431                     ((TMSClientSinkImpl*) iSink)->SetProxy(
       
   432                             iContext.CallProxy, iMsgQHandler);
       
   433                     break;
       
   434                 case TMS_SINK_MODEM:
       
   435                 case TMS_SINK_SPEAKER:
       
   436                     break;
       
   437                 default:
       
   438                     ret = TMS_RESULT_INVALID_ARGUMENT;
       
   439                     break;
       
   440                 }
       
   441             }
       
   442         else
       
   443             {
       
   444             ret = TMS_RESULT_UNINITIALIZED_OBJECT;
       
   445             }
       
   446         }
       
   447     else if (iContext.StreamType == TMS_STREAM_DOWNLINK)
       
   448         {
       
   449         if (iSource)
       
   450             {
       
   451             TMSSourceType sourceType;
       
   452             iSource->GetType(sourceType);
       
   453             switch (sourceType)
       
   454                 {
       
   455                 case TMS_SOURCE_CLIENT:
       
   456                     ((TMSClientSourceImpl*) iSource)->SetProxy(
       
   457                             iContext.CallProxy, iContext.StreamId,
       
   458                             iMsgQHandler);
       
   459                     break;
       
   460                 case TMS_SOURCE_MODEM:
       
   461                 case TMS_SOURCE_MIC:
       
   462                     break;
       
   463                 default:
       
   464                     ret = TMS_RESULT_INVALID_ARGUMENT;
       
   465                     break;
       
   466                 }
       
   467             }
       
   468         else
       
   469             {
       
   470             ret = TMS_RESULT_UNINITIALIZED_OBJECT;
       
   471             }
       
   472         }
       
   473 
       
   474     return ret;
       
   475     }
       
   476 
       
   477 gint TMSStreamBodyImpl::Pause()
       
   478     {
       
   479     gint ret(TMS_RESULT_SUCCESS);
       
   480     if (iContext.CallProxy)
       
   481         {
       
   482         ret = (iContext.CallProxy)->PauseStream(iContext.CallType,
       
   483                 iContext.StreamType, iContext.StreamId);
       
   484         }
       
   485     else
       
   486         {
       
   487         ret = TMS_RESULT_UNINITIALIZED_OBJECT;
       
   488         }
       
   489     return ret;
       
   490     }
       
   491 
       
   492 gint TMSStreamBodyImpl::Start()
       
   493     {
       
   494     gint ret(TMS_RESULT_SUCCESS);
       
   495     if (iContext.CallProxy)
       
   496         {
       
   497         ret = (iContext.CallProxy)->StartStream(iContext.CallType,
       
   498                 iContext.StreamType, iContext.StreamId);
       
   499         }
       
   500     else
       
   501         {
       
   502         ret = TMS_RESULT_UNINITIALIZED_OBJECT;
       
   503         }
       
   504     return ret;
       
   505     }
       
   506 
       
   507 gint TMSStreamBodyImpl::Stop()
       
   508     {
       
   509     gint ret(TMS_RESULT_SUCCESS);
       
   510     if (iContext.CallProxy)
       
   511         {
       
   512         ret = (iContext.CallProxy)->StopStream(iContext.CallType,
       
   513                 iContext.StreamType, iContext.StreamId);
       
   514         }
       
   515     else
       
   516         {
       
   517         ret = TMS_RESULT_UNINITIALIZED_OBJECT;
       
   518         }
       
   519     return ret;
       
   520     }
       
   521 
       
   522 void TMSStreamBodyImpl::Deinit()
       
   523     {
       
   524     if (iContext.CallProxy)
       
   525         {
       
   526         (iContext.CallProxy)->DeinitStream(iContext.CallType,
       
   527                 iContext.StreamType, iContext.StreamId);
       
   528         }
       
   529     }
       
   530 
       
   531 gint TMSStreamBodyImpl::ValidateSource(TMSSource* source)
       
   532     {
       
   533     gint ret(TMS_RESULT_NULL_ARGUMENT);
       
   534     TMSSourceType sourcetype;
       
   535 
       
   536     if (source)
       
   537         {
       
   538         source->GetType(sourcetype);
       
   539 
       
   540         switch (sourcetype)
       
   541             {
       
   542             case TMS_SOURCE_CLIENT:
       
   543                 {
       
   544                 if (iContext.CallType == TMS_CALL_IP &&
       
   545                         iContext.StreamType == TMS_STREAM_DOWNLINK)
       
   546                     {
       
   547                     iSource = source;
       
   548                     ret = TMS_RESULT_SUCCESS;
       
   549                     }
       
   550                 }
       
   551                 break;
       
   552             case TMS_SOURCE_MIC:
       
   553                 {
       
   554                 if (iContext.StreamType == TMS_STREAM_UPLINK)
       
   555                     {
       
   556                     iSource = source;
       
   557                     ret = TMS_RESULT_SUCCESS;
       
   558                     }
       
   559                 }
       
   560                 break;
       
   561             case TMS_SOURCE_MODEM:
       
   562                 {
       
   563                 if (iContext.CallType == TMS_CALL_CS &&
       
   564                         iContext.StreamType == TMS_STREAM_DOWNLINK)
       
   565                     {
       
   566                     iSource = source;
       
   567                     ret = TMS_RESULT_SUCCESS;
       
   568                     }
       
   569                 break;
       
   570                 }
       
   571             default:
       
   572                 break;
       
   573             }
       
   574         }
       
   575 
       
   576     return ret;
       
   577     }
       
   578 
       
   579 gint TMSStreamBodyImpl::ValidateSink(TMSSink* sink)
       
   580     {
       
   581     gint ret(TMS_RESULT_NULL_ARGUMENT);
       
   582     TMSSinkType sinktype;
       
   583 
       
   584     if (sink)
       
   585         {
       
   586         sink->GetType(sinktype);
       
   587 
       
   588         switch (sinktype)
       
   589             {
       
   590             case TMS_SINK_CLIENT:
       
   591                 {
       
   592                 if (iContext.CallType == TMS_CALL_IP &&
       
   593                         iContext.StreamType == TMS_STREAM_UPLINK)
       
   594                     {
       
   595                     iSink = sink;
       
   596                     ret = TMS_RESULT_SUCCESS;
       
   597                     }
       
   598                 }
       
   599                 break;
       
   600             case TMS_SINK_SPEAKER:
       
   601                 {
       
   602                 if (iContext.StreamType == TMS_STREAM_DOWNLINK)
       
   603                     {
       
   604                     iSink = sink;
       
   605                     ret = TMS_RESULT_SUCCESS;
       
   606                     }
       
   607                 }
       
   608                 break;
       
   609             case TMS_SINK_MODEM:
       
   610                 {
       
   611                 if (iContext.CallType == TMS_CALL_CS &&
       
   612                         iContext.StreamType == TMS_STREAM_UPLINK)
       
   613                     {
       
   614                     iSink = sink;
       
   615                     ret = TMS_RESULT_SUCCESS;
       
   616                     }
       
   617                 break;
       
   618                 }
       
   619             default:
       
   620                 break;
       
   621             }
       
   622         }
       
   623 
       
   624     return ret;
       
   625     }
       
   626 
       
   627 gint TMSStreamBodyImpl::ValidateFormat(TMSFormat* format)
       
   628     {
       
   629     gint ret(TMS_RESULT_NULL_ARGUMENT);
       
   630 
       
   631     if (format)
       
   632         {
       
   633         if (iContext.CallType == TMS_CALL_IP)
       
   634             {
       
   635             iFormat = format;
       
   636             ret = TMS_RESULT_SUCCESS;
       
   637             }
       
   638         else
       
   639             {
       
   640             ret = TMS_RESULT_INVALID_STATE;
       
   641             }
       
   642         }
       
   643     return ret;
       
   644     }
       
   645 
       
   646 gint TMSStreamBodyImpl::ValidateStream()
       
   647     {
       
   648     gint ret(TMS_RESULT_INVALID_STATE);
       
   649 
       
   650     if (iContext.StreamType == TMS_STREAM_UPLINK ||
       
   651             iContext.StreamType == TMS_STREAM_DOWNLINK)
       
   652         {
       
   653         if (iContext.CallType == TMS_CALL_IP)
       
   654             {
       
   655             if (ValidateSource(iSource) == TMS_RESULT_SUCCESS &&
       
   656                     ValidateSink(iSink) == TMS_RESULT_SUCCESS &&
       
   657                     ValidateFormat(iFormat) == TMS_RESULT_SUCCESS)
       
   658                 {
       
   659                 ret = TMS_RESULT_SUCCESS;
       
   660                 }
       
   661             }
       
   662         else if (iContext.CallType == TMS_CALL_CS)
       
   663             {
       
   664             if (ValidateSource(iSource) == TMS_RESULT_SUCCESS &&
       
   665                     ValidateSink(iSink) == TMS_RESULT_SUCCESS)
       
   666                 {
       
   667                 ret = TMS_RESULT_SUCCESS;
       
   668                 }
       
   669             }
       
   670         }
       
   671     return ret;
       
   672     }
       
   673 
       
   674 // ---------------------------------------------------------------------------
       
   675 // TMSStreamBodyImpl::CreateQueue
       
   676 // ---------------------------------------------------------------------------
       
   677 //
       
   678 gint TMSStreamBodyImpl::CreateQueue(const gint aNumSlots)
       
   679     {
       
   680     gint err = TMS_RESULT_INVALID_ARGUMENT;
       
   681 
       
   682     if (iMsgQueue.Handle() <= 0)
       
   683         {
       
   684         err = iMsgQueue.CreateGlobal(KNullDesC, aNumSlots);
       
   685         if (err == KErrNone)
       
   686             {
       
   687             TRAP(err, ReceiveMsgQHandlerEventsL());
       
   688             }
       
   689         }
       
   690 
       
   691     return err;
       
   692     }
       
   693 
       
   694 // ---------------------------------------------------------------------------
       
   695 // TMSStreamBodyImpl::ReceiveMsgQHandlerEventsL
       
   696 // Starts message queue handler (A/O) to monitor communication and transfer
       
   697 // buffer events between client and the server.
       
   698 // ---------------------------------------------------------------------------
       
   699 //
       
   700 void TMSStreamBodyImpl::ReceiveMsgQHandlerEventsL()
       
   701     {
       
   702     if (iMsgQHandler)
       
   703         {
       
   704         iMsgQHandler->Cancel();
       
   705         }
       
   706     else
       
   707         {
       
   708         iMsgQHandler = CQueueHandler::NewL(&iMsgQueue, &iContext);
       
   709         iMsgQHandler->AddObserver(*this, iContext.StreamType);
       
   710         }
       
   711 
       
   712     iMsgQHandler->Start();
       
   713     }
       
   714 
       
   715 // ======== CALLBACK FUNCTIONS ========
       
   716 
       
   717 void TMSStreamBodyImpl::QueueEvent(TInt aEventType, TInt aError,
       
   718         void* user_data)
       
   719     {
       
   720     TMSSignalEvent event;
       
   721     event.reason = aError;
       
   722     event.user_data = user_data;
       
   723     iStreamState = aEventType;
       
   724 
       
   725     switch (aEventType)
       
   726         {
       
   727         case TMS_STREAM_INITIALIZED:
       
   728         case TMS_STREAM_UNINITIALIZED:
       
   729         case TMS_STREAM_PAUSED:
       
   730         case TMS_STREAM_STARTED:
       
   731             {
       
   732             event.curr_state = aEventType;
       
   733             event.prev_state = iPrevState;
       
   734             if (iObserver)
       
   735                 {
       
   736                 event.type = TMS_EVENT_STREAM_STATE_CHANGED;
       
   737                 iObserver->TMSStreamEvent(iParent, event);
       
   738                 }
       
   739             break;
       
   740             }
       
   741         default:
       
   742             break;
       
   743         }
       
   744     iPrevState = aEventType;
       
   745     }
       
   746