multimediacommsengine/mmcecli/src/mcefactory.cpp
changeset 0 1bce908db942
child 49 64c62431ac08
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     1 /*
       
     2 * Copyright (c) 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:    
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 
       
    21 #include <s32buf.h>
       
    22 
       
    23 #include "mceinsession.h"
       
    24 #include "mceoutsession.h"
       
    25 #include "mceaudiostream.h"
       
    26 #include "mcevideostream.h"
       
    27 #include "mcertpsource.h"
       
    28 #include "mcemicsource.h"
       
    29 #include "mcecamerasource.h"
       
    30 #include "mcefilesource.h"
       
    31 #include "mcefilesink.h"
       
    32 #include "mcertpsink.h"
       
    33 #include "mcespeakersink.h"
       
    34 #include "mcedisplaysink.h"
       
    35 #include "mceamrcodec.h"
       
    36 #include "mceamrwbcodec.h"
       
    37 #include "mceg711codec.h"
       
    38 #include "mceg729codec.h"
       
    39 #include "mceilbccodec.h"
       
    40 #include "mcedtmfcodec.h"
       
    41 #include "mcecncodec.h"
       
    42 #include "mceredcodec.h"
       
    43 #include "mceh263codec.h"
       
    44 #include "mcefactory.h"
       
    45 #include "mceserial.h"
       
    46 #include "mcedefs.h"
       
    47 #include "mcevideocodec.h"
       
    48 #include "mcestreambundle.h"
       
    49 #include "mceavsink.h"
       
    50 #include "mceavccodec.h"
       
    51 
       
    52 // ============================ MEMBER FUNCTIONS ===============================
       
    53 
       
    54 
       
    55 // -----------------------------------------------------------------------------
       
    56 // TMceFactory::CreateLC
       
    57 // -----------------------------------------------------------------------------
       
    58 //
       
    59 CMceSession* TMceFactory::CreateLC( CMceComSession::TType aType )
       
    60 	{
       
    61     CMceSession* session = NULL;
       
    62     switch ( aType )
       
    63         {
       
    64         case CMceComSession::EInSession:
       
    65             {
       
    66             session = CMceInSession::NewL();
       
    67             CleanupStack::PushL( session );
       
    68             break;
       
    69             }
       
    70         case CMceComSession::EOutSession:
       
    71             {
       
    72             session = CMceOutSession::NewL();
       
    73             CleanupStack::PushL( session );
       
    74             break;
       
    75             }
       
    76         default:
       
    77             {
       
    78             break;
       
    79             }
       
    80         }
       
    81 
       
    82     if ( !session )
       
    83         {
       
    84         User::Leave( KErrNotSupported );
       
    85         }
       
    86         
       
    87     return session;    
       
    88 	}
       
    89 
       
    90 // -----------------------------------------------------------------------------
       
    91 // TMceFactory::CreateLC
       
    92 // -----------------------------------------------------------------------------
       
    93 //
       
    94 CMceSession* TMceFactory::CreateLC( MMceComSerializationContext& aSerCtx )
       
    95     {
       
    96     RReadStream& readStream = aSerCtx.ReadStream();
       
    97     
       
    98     MStreamBuf* streamBuf = readStream.Source();
       
    99     TStreamPos pos = streamBuf->TellL( MStreamBuf::ERead );
       
   100     CMceComSession::TType type =
       
   101     	static_cast<CMceComSession::TType>( readStream.ReadUint8L() );
       
   102     streamBuf->SeekL( MStreamBuf::ERead, pos );
       
   103     
       
   104     CMceSession* session = CreateLC( type );
       
   105     session->InternalizeL( aSerCtx );
       
   106     return session;    
       
   107     }
       
   108 
       
   109 
       
   110 // -----------------------------------------------------------------------------
       
   111 // TMceFactory::CreateL
       
   112 // -----------------------------------------------------------------------------
       
   113 //
       
   114 CMceMsgBase* TMceFactory::CreateL( TMceItcDataType aType,
       
   115                                    RReadStream& aReadStream )
       
   116     {
       
   117     MMceComSerializationContext serCtx( aReadStream );
       
   118     CleanupClosePushL( serCtx );
       
   119     
       
   120     CMceMsgBase* object = CreateL( aType, serCtx );
       
   121     
       
   122     CleanupStack::PopAndDestroy();//serCtx
       
   123     
       
   124     return object;
       
   125     
       
   126     }
       
   127 
       
   128 
       
   129 // -----------------------------------------------------------------------------
       
   130 // TMceFactory::CreateL
       
   131 // -----------------------------------------------------------------------------
       
   132 //
       
   133 CMceMsgBase* TMceFactory::CreateL( TMceItcDataType aType,
       
   134                                    MMceComSerializationContext& aSerCtx )
       
   135     {
       
   136     
       
   137     CMceMsgBase* message = NULL;
       
   138     switch ( aType )
       
   139         {
       
   140         case EMceItcMsgTypeSession:
       
   141             {
       
   142             message = new (ELeave) CMceMsgObject<CMceSession>();
       
   143         	break;
       
   144             }
       
   145         case EMceItcMsgTypeStream:
       
   146             {
       
   147             message = new (ELeave) CMceMsgObject<CMceMediaStream>();
       
   148         	break;
       
   149             }
       
   150         case EMceItcMsgTypeCodec:
       
   151             {
       
   152             message = new (ELeave) CMceMsgObject<CMceAudioCodec>();
       
   153         	break;
       
   154             }
       
   155         case EMceItcMsgTypeSink:
       
   156             {
       
   157             message = new (ELeave) CMceMsgObject<CMceMediaSink>();
       
   158         	break;
       
   159             }
       
   160         case EMceItcMsgTypeSource:
       
   161             {
       
   162             message = new (ELeave) CMceMsgObject<CMceMediaSource>();
       
   163         	break;
       
   164             }
       
   165         case EMceItcMsgTypeSIPData:
       
   166             {
       
   167             message = new (ELeave) CMceMsgSIPData();
       
   168         	break;
       
   169             }
       
   170         case EMceItcMsgTypeSIPReply:
       
   171             {
       
   172             message = new (ELeave) CMceMsgSIPReply();
       
   173         	break;
       
   174             }
       
   175         
       
   176         case EMceItcMsgTypeSIPRequest:
       
   177             {
       
   178             message = new (ELeave) CMceMsgSIPRequest();
       
   179         	break;
       
   180             }    
       
   181         case EMceItcMsgTypeEvent:
       
   182             {
       
   183             message = new (ELeave) CMceMsgSIPEvent();
       
   184         	break;
       
   185             }
       
   186         case EMceItcMsgTypeTextArray:
       
   187             {
       
   188             message = new (ELeave) CMceMsgTextArray();
       
   189         	break;
       
   190             }
       
   191         case EMceItcMsgTypeMessageArray:
       
   192             {
       
   193             message = new (ELeave) CMceMsgArray<TMceFactory>( *this );
       
   194         	break;
       
   195             }
       
   196 	    default:
       
   197 	        {
       
   198 	        }
       
   199         }
       
   200         
       
   201     if ( message )
       
   202         {
       
   203     	CleanupStack::PushL( message );
       
   204     	message->PushL();
       
   205         message->DoDecodeL( aSerCtx );
       
   206         message->Pop();
       
   207         CleanupStack::Pop( message );
       
   208         }
       
   209 
       
   210     return message;
       
   211             
       
   212     }
       
   213 
       
   214 // -----------------------------------------------------------------------------
       
   215 // TMceFactory::CreateL
       
   216 // -----------------------------------------------------------------------------
       
   217 //
       
   218 CMceStreamBundle* TMceFactory::CreateBundleLC( CMceSession& aSession, 
       
   219                                                MMceComSerializationContext& aSerCtx )
       
   220     {
       
   221     RReadStream& readStream = aSerCtx.ReadStream();
       
   222     
       
   223     MStreamBuf* streamBuf = readStream.Source();
       
   224     TStreamPos pos = streamBuf->TellL( MStreamBuf::ERead );
       
   225     CMceStreamBundle::TMceStreamBundleType type =
       
   226     	static_cast<CMceStreamBundle::TMceStreamBundleType>( readStream.ReadUint8L() );
       
   227     streamBuf->SeekL( MStreamBuf::ERead, pos );
       
   228     
       
   229     CMceStreamBundle* bundle = CMceStreamBundle::NewLC( type );
       
   230     bundle->InitializeL( aSession );
       
   231     bundle->InternalizeL( aSerCtx );
       
   232     
       
   233     return bundle;
       
   234     
       
   235     }
       
   236 
       
   237 
       
   238 // -----------------------------------------------------------------------------
       
   239 // TMceMediaStreamFactory::CreateLC
       
   240 // -----------------------------------------------------------------------------
       
   241 //
       
   242 CMceMediaStream* TMceMediaStreamFactory::CreateLC( TMceMediaType aType )
       
   243 	{
       
   244 	
       
   245     CMceMediaStream* stream = NULL;
       
   246     switch ( aType )
       
   247         {
       
   248         case KMceAudio:
       
   249             {
       
   250             stream = CMceAudioStream::NewLC();
       
   251             break;
       
   252             }
       
   253         case KMceVideo:
       
   254             {
       
   255             stream = CMceVideoStream::NewLC();
       
   256             break;
       
   257             }            
       
   258         default:
       
   259             {
       
   260             break;
       
   261             }
       
   262         }
       
   263 
       
   264     if ( !stream )
       
   265         {
       
   266         User::Leave( KErrNotSupported );
       
   267         }
       
   268         
       
   269     return stream;
       
   270     
       
   271 	}
       
   272 	
       
   273 
       
   274 // -----------------------------------------------------------------------------
       
   275 // TMceMediaStreamFactory::CreateLC
       
   276 // -----------------------------------------------------------------------------
       
   277 //
       
   278 CMceMediaStream* TMceMediaStreamFactory::CreateLC(
       
   279                                         MMceComSerializationContext& aSerCtx )
       
   280     {
       
   281     RReadStream& readStream = aSerCtx.ReadStream();
       
   282     
       
   283     MStreamBuf* streamBuf = readStream.Source();
       
   284     TStreamPos pos = streamBuf->TellL( MStreamBuf::ERead );
       
   285     TMceMediaType type = static_cast<TMceMediaType>( readStream.ReadUint8L() );
       
   286     streamBuf->SeekL( MStreamBuf::ERead, pos );
       
   287     
       
   288     CMceMediaStream* stream = CreateLC( type );
       
   289     stream->InternalizeL( aSerCtx );
       
   290     return stream;
       
   291     
       
   292     }
       
   293 
       
   294 
       
   295 
       
   296 	
       
   297 // -----------------------------------------------------------------------------
       
   298 // TMceSourceFactory::CreateLC
       
   299 // -----------------------------------------------------------------------------
       
   300 //
       
   301 CMceMediaSource* TMceSourceFactory::CreateLC( TMceSourceType aType )
       
   302     {
       
   303     CMceMediaSource* source = NULL;
       
   304 
       
   305     switch ( aType )
       
   306         {
       
   307         case KMceRTPSource:
       
   308             {
       
   309             source = CMceRtpSource::NewLC();
       
   310             break;
       
   311             }
       
   312         case KMceMicSource:
       
   313             {
       
   314             source = CMceMicSource::NewLC();
       
   315             break;
       
   316             }
       
   317         case KMceCameraSource:
       
   318             {
       
   319             source = CMceCameraSource::NewLC();
       
   320             break;
       
   321             }
       
   322         case KMceFileSource:
       
   323             {
       
   324             source = CMceFileSource::NewLC();
       
   325             break;
       
   326             }
       
   327         default:
       
   328             {
       
   329             break;
       
   330             }
       
   331         }
       
   332 
       
   333     if ( !source )
       
   334         {
       
   335         User::Leave( KErrNotSupported );
       
   336         }
       
   337         
       
   338     return source;
       
   339     
       
   340     }
       
   341 
       
   342 
       
   343 // -----------------------------------------------------------------------------
       
   344 // TMceSourceFactory::CreateLC
       
   345 // -----------------------------------------------------------------------------
       
   346 //
       
   347 CMceMediaSource* TMceSourceFactory::CreateLC( MMceComSerializationContext& aSerCtx )
       
   348     {
       
   349     RReadStream& readStream = aSerCtx.ReadStream();
       
   350     
       
   351     MStreamBuf* streamBuf = readStream.Source();
       
   352     TStreamPos pos = streamBuf->TellL( MStreamBuf::ERead );
       
   353     TMceSourceType type = static_cast<TMceSourceType>( readStream.ReadUint8L() );
       
   354     streamBuf->SeekL( MStreamBuf::ERead, pos );
       
   355 
       
   356     CMceMediaSource* source = CreateLC( type );
       
   357     source->InternalizeL( aSerCtx );
       
   358     return source;
       
   359     
       
   360     }
       
   361 
       
   362 // -----------------------------------------------------------------------------
       
   363 // TMceSinkFactory::CreateLC
       
   364 // -----------------------------------------------------------------------------
       
   365 //
       
   366 CMceMediaSink* TMceSinkFactory::CreateLC( TMceSinkType aType )
       
   367     {
       
   368     CMceMediaSink* sink = NULL;
       
   369     switch ( aType )
       
   370         {
       
   371         case KMceRTPSink:
       
   372             {
       
   373             sink = CMceRtpSink::NewLC();
       
   374             break;
       
   375             }
       
   376         case KMceSpeakerSink:
       
   377             {
       
   378             sink = CMceSpeakerSink::NewLC();
       
   379             break;
       
   380             }
       
   381         case KMceDisplaySink:
       
   382             {
       
   383             sink = CMceDisplaySink::NewLC();
       
   384             break;
       
   385             }
       
   386         case KMceFileSink:
       
   387             {
       
   388             sink = CMceFileSink::NewLC();
       
   389             break;
       
   390             }
       
   391         default:
       
   392             {
       
   393             break;
       
   394             }
       
   395         }
       
   396 
       
   397     if ( !sink )
       
   398         {
       
   399         User::Leave( KErrNotSupported );
       
   400         }
       
   401         
       
   402     return sink;
       
   403     
       
   404     }
       
   405 
       
   406 // -----------------------------------------------------------------------------
       
   407 // TMceSinkFactory::CreateLC
       
   408 // -----------------------------------------------------------------------------
       
   409 //
       
   410 CMceMediaSink* TMceSinkFactory::CreateLC( MMceComSerializationContext& aSerCtx )
       
   411     {
       
   412     RReadStream& readStream = aSerCtx.ReadStream();
       
   413     
       
   414     MStreamBuf* streamBuf = readStream.Source();
       
   415     TStreamPos pos = streamBuf->TellL( MStreamBuf::ERead );
       
   416     TMceSinkType type = static_cast<TMceSinkType>( readStream.ReadUint8L() );
       
   417     streamBuf->SeekL( MStreamBuf::ERead, pos );
       
   418     
       
   419     CMceMediaSink* sink = CreateLC( type );
       
   420     sink->InternalizeL( aSerCtx );
       
   421     return sink;
       
   422     
       
   423     }
       
   424     
       
   425 // -----------------------------------------------------------------------------
       
   426 // TMceSinkFactory::CreateLC
       
   427 // -----------------------------------------------------------------------------
       
   428 //
       
   429 void TMceSinkFactory::CreateLC( MMceComSerializable*& aSink, MMceComSerializationContext& aSerCtx )
       
   430     {
       
   431 
       
   432     RReadStream& readStream = aSerCtx.ReadStream();
       
   433     
       
   434     MStreamBuf* streamBuf = readStream.Source();
       
   435     TStreamPos pos = streamBuf->TellL( MStreamBuf::ERead );
       
   436     TMceSinkType type = static_cast<TMceSinkType>( readStream.ReadUint8L() );
       
   437     streamBuf->SeekL( MStreamBuf::ERead, pos );
       
   438     
       
   439     switch ( type )
       
   440         {
       
   441         case KMceAvSink:
       
   442             {
       
   443             aSink = CMceAvSink::NewLC();
       
   444             break;
       
   445             }
       
   446         default:
       
   447             {
       
   448             break;
       
   449             }
       
   450         }
       
   451     
       
   452     if ( !aSink )
       
   453         {
       
   454         User::Leave( KErrNotSupported );
       
   455         }
       
   456         
       
   457     aSink->InternalizeL( aSerCtx );
       
   458     
       
   459     }
       
   460 
       
   461     
       
   462 
       
   463 // -----------------------------------------------------------------------------
       
   464 // TMceAudioCodecFactory::CreateLC
       
   465 // -----------------------------------------------------------------------------
       
   466 //
       
   467 CMceAudioCodec* TMceAudioCodecFactory::CreateLC( TBuf8<KMceMaxSdpNameLength> aSdpName )
       
   468     {
       
   469     CMceAudioCodec* codec = CreateL( aSdpName );
       
   470     CleanupStack::PushL( codec );
       
   471 	return codec;     
       
   472     }
       
   473     
       
   474 // -----------------------------------------------------------------------------
       
   475 // TMceAudioCodecFactory::CreateL
       
   476 // -----------------------------------------------------------------------------
       
   477 //
       
   478 CMceAudioCodec* TMceAudioCodecFactory::CreateL( TBuf8<KMceMaxSdpNameLength> aSdpName )
       
   479     {
       
   480     CMceAudioCodec* codec = NULL;
       
   481     if( !aSdpName.CompareF( KMceSDPNameAMR ) )
       
   482         {
       
   483         codec = CMceAmrCodec::NewL( aSdpName );
       
   484         }
       
   485     else if ( !aSdpName.CompareF( KMceSDPNameAMRWB ) )
       
   486     	{
       
   487 		codec = CMceAmrWbCodec::NewL( aSdpName );
       
   488     	}
       
   489     else if ( !aSdpName.CompareF( KMceSDPNamePCMU ) ||
       
   490               !aSdpName.CompareF( KMceSDPNamePCMA ) )
       
   491         {
       
   492         codec = CMceG711Codec::NewL( aSdpName );
       
   493         }
       
   494     else if ( !aSdpName.CompareF( KMceSDPNameG729 ) )        
       
   495         {
       
   496         codec = CMceG729Codec::NewL( aSdpName );   
       
   497         }     
       
   498     else if ( !aSdpName.CompareF( KMceSDPNameiLBC ) )        
       
   499         {
       
   500         codec = CMceiLBCCodec::NewL( aSdpName );
       
   501         }
       
   502     else if ( !aSdpName.CompareF( KMceSDPNameDtmf ) )
       
   503         {
       
   504         codec = CMceDtmfCodec::NewL( aSdpName );
       
   505         }
       
   506     else if ( !aSdpName.CompareF( KMceSDPNameCn ) )
       
   507         {
       
   508         codec = CMceCnCodec::NewL( aSdpName );
       
   509         }
       
   510     else if ( !aSdpName.CompareF( KMceSDPNameRed ) )
       
   511         {
       
   512         codec = CMceRedCodec::NewL( aSdpName );
       
   513         }
       
   514     else
       
   515         {
       
   516         User::Leave( KErrNotSupported );
       
   517         }
       
   518 	return codec;
       
   519     }
       
   520 
       
   521 // -----------------------------------------------------------------------------
       
   522 // TMceAudioCodecFactory::CreateLC
       
   523 // -----------------------------------------------------------------------------
       
   524 //
       
   525 CMceAudioCodec* TMceAudioCodecFactory::CreateLC( MMceComSerializationContext& aSerCtx )
       
   526     {
       
   527     RReadStream& readStream = aSerCtx.ReadStream();
       
   528     
       
   529     MStreamBuf* streamBuf = readStream.Source();
       
   530     TStreamPos pos = streamBuf->TellL( MStreamBuf::ERead );
       
   531     TBuf8<KMceMaxSdpNameLength> sdpName;
       
   532     MceSerial::DecodeL( sdpName, readStream );
       
   533     
       
   534     streamBuf->SeekL( MStreamBuf::ERead, pos );
       
   535     
       
   536     CMceAudioCodec* codec = CreateL( sdpName );
       
   537     CleanupStack::PushL( codec );
       
   538     codec->InternalizeL( aSerCtx );
       
   539     return codec;    
       
   540     }
       
   541 
       
   542 
       
   543 // -----------------------------------------------------------------------------
       
   544 // TMceVideoCodecFactory::CreateLC
       
   545 // -----------------------------------------------------------------------------
       
   546 //
       
   547 CMceVideoCodec* TMceVideoCodecFactory::CreateLC( TBuf8<KMceMaxSdpNameLength> aSdpName )
       
   548     {
       
   549     CMceVideoCodec* codec = CreateL( aSdpName );
       
   550     CleanupStack::PushL( codec );
       
   551     return codec;       
       
   552     }
       
   553     
       
   554 // -----------------------------------------------------------------------------
       
   555 // TMceVideoCodecFactory::CreateL
       
   556 // -----------------------------------------------------------------------------
       
   557 //
       
   558 CMceVideoCodec* TMceVideoCodecFactory::CreateL( TBuf8<KMceMaxSdpNameLength> aSdpName )
       
   559     {
       
   560     CMceVideoCodec* codec = NULL;
       
   561     
       
   562     if( aSdpName.CompareF(KMceSDPNameH263) == 0 || 
       
   563         aSdpName.CompareF(KMceSDPNameH2632000) == 0 ||
       
   564         aSdpName.CompareF(KMceSDPNameH2631998) == 0)
       
   565         {
       
   566         codec = CMceH263Codec::NewL( aSdpName );
       
   567         }
       
   568     else if ( aSdpName.CompareF(KMceSDPNameH264) == 0 )
       
   569         {
       
   570         codec = CMceAvcCodec::NewL( aSdpName );
       
   571         }
       
   572     else
       
   573         {
       
   574         User::Leave( KErrNotSupported );
       
   575         }
       
   576 	return codec;
       
   577 	        
       
   578     }
       
   579 
       
   580 // -----------------------------------------------------------------------------
       
   581 // TMceVideoCodecFactory::CreateLC
       
   582 // -----------------------------------------------------------------------------
       
   583 //
       
   584 CMceVideoCodec* TMceVideoCodecFactory::CreateLC( MMceComSerializationContext& aSerCtx )
       
   585     {
       
   586     RReadStream& readStream = aSerCtx.ReadStream();
       
   587     
       
   588     MStreamBuf* streamBuf = readStream.Source();
       
   589     TStreamPos pos = streamBuf->TellL( MStreamBuf::ERead );
       
   590     TBuf8<KMceMaxSdpNameLength> sdpName;
       
   591     MceSerial::DecodeL( sdpName, readStream );
       
   592     
       
   593     streamBuf->SeekL( MStreamBuf::ERead, pos );
       
   594     
       
   595     CMceVideoCodec* codec = CreateL( sdpName );
       
   596     CleanupStack::PushL( codec );
       
   597     codec->InternalizeL( aSerCtx );
       
   598     return codec;    
       
   599     }
       
   600