multimediacommsengine/mmceshared/src/mcecommessagestream.cpp
branchrcs
changeset 49 64c62431ac08
child 50 1d8943dd8be6
equal deleted inserted replaced
44:fb024d5e35fa 49:64c62431ac08
       
     1 /*
       
     2 * Copyright (c) 2005 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 "mcemessagestream.h"
       
    22 #include "mcecommessagestream.h"
       
    23 #include "mcecommessagecodec.h"
       
    24 #include "mcecommediasource.h"
       
    25 #include "mcecommediasink.h"
       
    26 #include "mceserial.h"
       
    27 #include "mceevents.h"
       
    28 #include "cleanupresetanddestroy.h"
       
    29 
       
    30 #ifdef MCE_COMMON_SERVER_SIDE
       
    31 
       
    32 #include <MmccCodecInformationFactory.h>
       
    33 #include <MmccCodecInformation.h>
       
    34 
       
    35     
       
    36 #endif//MCE_COMMON_SERVER_SIDE
       
    37 
       
    38 
       
    39 // ============================ MEMBER FUNCTIONS ===============================
       
    40 
       
    41 
       
    42 // -----------------------------------------------------------------------------
       
    43 // CMceComMessageStream::NewL
       
    44 // -----------------------------------------------------------------------------
       
    45 //
       
    46 CMceComMessageStream* CMceComMessageStream::NewL()
       
    47     {
       
    48     CMceComMessageStream* self = NewLC();
       
    49     CleanupStack::Pop( self );
       
    50     return self;
       
    51     }
       
    52 
       
    53 // -----------------------------------------------------------------------------
       
    54 // CMceComMessageStream::NewLC
       
    55 // -----------------------------------------------------------------------------
       
    56 //
       
    57 CMceComMessageStream* CMceComMessageStream::NewLC()
       
    58     {
       
    59     CMceComMessageStream* self = new (ELeave) CMceComMessageStream();
       
    60     CleanupStack::PushL( self );
       
    61     self->ConstructL();
       
    62     return self;
       
    63     }
       
    64 
       
    65 
       
    66 
       
    67 // -----------------------------------------------------------------------------
       
    68 // CMceComMessageStream::~CMceComMessageStream
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 CMceComMessageStream::~CMceComMessageStream()
       
    72     {
       
    73     iCodecs.ResetAndDestroy();
       
    74     }
       
    75 
       
    76 
       
    77 
       
    78 // -----------------------------------------------------------------------------
       
    79 // CMceComMessageStream::CMceComMessageStream
       
    80 // -----------------------------------------------------------------------------
       
    81 //
       
    82 CMceComMessageStream::CMceComMessageStream()
       
    83     :CMceComMediaStream( KMceMessage ),
       
    84     iUseMsrpPathAttrForHostAddrAndPort(ETrue),
       
    85     iMsrpConnUsage(EFalse)
       
    86     {
       
    87     }
       
    88 
       
    89 
       
    90 
       
    91 
       
    92 // -----------------------------------------------------------------------------
       
    93 // CMceComMessageStream::AddCodecL
       
    94 // -----------------------------------------------------------------------------
       
    95 //
       
    96 void CMceComMessageStream::AddCodecL( CMceComCodec* aCodec)
       
    97     {
       
    98     iCodecs.AppendL( static_cast<CMceComMessageCodec*>(aCodec) );
       
    99     }
       
   100 
       
   101 // -----------------------------------------------------------------------------
       
   102 // CMceComMessageStream::RemoveCodecL
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 void CMceComMessageStream::RemoveCodecL( CMceComCodec* aCodec )
       
   106     {
       
   107     CMceComMessageCodec* codec = static_cast<CMceComMessageCodec*>( aCodec );
       
   108     TInt index = Codecs().Find( codec );
       
   109     User::LeaveIfError( index );
       
   110     
       
   111     Codecs().Remove( index );
       
   112     delete aCodec;
       
   113     
       
   114     }
       
   115 
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 // CMceComMessageStream::RemoveCodecL
       
   119 // -----------------------------------------------------------------------------
       
   120 //
       
   121 void CMceComMessageStream::DestroyCodecs( )
       
   122     {
       
   123     iCodecs.ResetAndDestroy();
       
   124     } 
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CMceComAudioStream::CodecL
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 CMceComMessageCodec* CMceComMessageStream::CodecL( TInt aIndex ) const
       
   131     {
       
   132     __ASSERT_ALWAYS( aIndex >= 0 && aIndex < iCodecs.Count(),
       
   133         User::Leave( KErrArgument ) );
       
   134     
       
   135     return iCodecs[aIndex];
       
   136     }
       
   137 
       
   138 // -----------------------------------------------------------------------------
       
   139 // CMceComMessageStream::CodecCount
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 TInt CMceComMessageStream::CodecCount() const
       
   143     {
       
   144     return iCodecs.Count();
       
   145     }
       
   146 
       
   147 // -----------------------------------------------------------------------------
       
   148 // CMceComMessageStream::FindCodec
       
   149 // -----------------------------------------------------------------------------
       
   150 //
       
   151 
       
   152 CMceComCodec* CMceComMessageStream::FindCodecL( CMceComCodec& aCodec )
       
   153     {
       
   154     CMceComCodec* foundCodec = NULL;
       
   155     CMceComMessageCodec* codec = static_cast<CMceComMessageCodec*>( &aCodec );
       
   156     TInt index = Codecs().Find( codec );
       
   157     if ( index == KErrNotFound )
       
   158         {
       
   159         for ( TInt i = 0; i < Codecs().Count() && !foundCodec; i++ )
       
   160             {
       
   161             if ( Codecs()[ i ]->iSdpName.CompareF( aCodec.iSdpName ) == 0 )
       
   162                 {
       
   163                 foundCodec = Codecs()[ i ];
       
   164                 }     
       
   165             }
       
   166         }
       
   167     else
       
   168         {
       
   169         foundCodec = Codecs()[ index ];
       
   170         }
       
   171     return foundCodec;
       
   172     }
       
   173     
       
   174 
       
   175 // -----------------------------------------------------------------------------
       
   176 // CMceComMessageStream::Codecs
       
   177 // -----------------------------------------------------------------------------
       
   178 //
       
   179 RPointerArray<CMceComMessageCodec>& CMceComMessageStream::Codecs()
       
   180     {
       
   181     return iCodecs;
       
   182     }
       
   183 
       
   184 
       
   185 // -----------------------------------------------------------------------------
       
   186 // CMceComMessageStream::InternalizeFlatL
       
   187 // -----------------------------------------------------------------------------
       
   188 //
       
   189 void CMceComMessageStream::InternalizeFlatL( RReadStream& aReadStream )
       
   190     {
       
   191     CMceComMediaStream::InternalizeFlatL( aReadStream );
       
   192     this->iUseMsrpPathAttrForHostAddrAndPort = aReadStream.ReadInt8L();
       
   193     this->iMsrpConnUsage = aReadStream.ReadInt8L();
       
   194     }
       
   195 
       
   196 
       
   197 
       
   198 // -----------------------------------------------------------------------------
       
   199 // CMceComMessageStream::ExternalizeFlatL
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 void CMceComMessageStream::ExternalizeFlatL( RWriteStream& aWriteStream )
       
   203     {
       
   204     CMceComMediaStream::ExternalizeFlatL( aWriteStream );
       
   205     aWriteStream.WriteInt8L(this->iUseMsrpPathAttrForHostAddrAndPort);
       
   206     aWriteStream.WriteInt8L(this->iMsrpConnUsage);
       
   207     }
       
   208 
       
   209   
       
   210 // -----------------------------------------------------------------------------
       
   211 // CMceComMessageStream::InternalizeL
       
   212 // -----------------------------------------------------------------------------
       
   213 //
       
   214 void CMceComMessageStream::InternalizeL( MMceComSerializationContext& aSerCtx )
       
   215     {
       
   216     CMceComMediaStream::InternalizeL( aSerCtx );
       
   217     
       
   218     TMceMessageStreamSerializer<CMceComMessageStream> serial( *this );
       
   219     serial.InternalizeL( aSerCtx );
       
   220         
       
   221     }
       
   222     
       
   223 // -----------------------------------------------------------------------------
       
   224 // CMceComMessageStream::ExternalizeL
       
   225 // -----------------------------------------------------------------------------
       
   226 //
       
   227 void CMceComMessageStream::ExternalizeL( MMceComSerializationContext& aSerCtx )
       
   228     {
       
   229     CMceComMediaStream::ExternalizeL( aSerCtx );
       
   230     
       
   231     TMceMessageStreamSerializer<CMceComMessageStream> serial( *this );
       
   232     serial.ExternalizeL( aSerCtx );
       
   233     
       
   234     }
       
   235 
       
   236 // -----------------------------------------------------------------------------
       
   237 // CMceComMessageStream::CloneL
       
   238 // -----------------------------------------------------------------------------
       
   239 //
       
   240 CMceComMediaStream* CMceComMessageStream::CloneL()
       
   241     {
       
   242     CMceComMessageStream* copy = new (ELeave) CMceComMessageStream();
       
   243     CleanupStack::PushL( copy );
       
   244     copy->ConstructL( *this );
       
   245     CleanupStack::Pop( copy );
       
   246     return copy;
       
   247     }
       
   248 
       
   249 // -----------------------------------------------------------------------------
       
   250 // CMceComMessageStream::ConstructL
       
   251 // -----------------------------------------------------------------------------
       
   252 //
       
   253 void CMceComMessageStream::ConstructL()
       
   254     {
       
   255     
       
   256     CMceComMediaStream::ConstructL();
       
   257     
       
   258     }
       
   259 
       
   260 
       
   261 // -----------------------------------------------------------------------------
       
   262 // CMceComMessageStream::ConstructL
       
   263 // -----------------------------------------------------------------------------
       
   264 //
       
   265 void CMceComMessageStream::ConstructL( CMceComMessageStream& aStream )
       
   266     {
       
   267     CMceComMediaStream::ConstructL( aStream );
       
   268     for (int i = 0; i<aStream.Codecs().Count();i++)
       
   269         {
       
   270         CMceComMessageCodec* codec = aStream.Codecs()[ i ]->CloneL();
       
   271         CleanupStack::PushL( codec );
       
   272         AddCodecL( codec );
       
   273         CleanupStack::Pop( codec );
       
   274         }
       
   275     
       
   276     }
       
   277 
       
   278 
       
   279 // -----------------------------------------------------------------------------
       
   280 // CMceComMessageStream::ConstructL
       
   281 // -----------------------------------------------------------------------------
       
   282 //
       
   283 void CMceComMessageStream::InitializeL( CMceComSession& aParent )
       
   284     {
       
   285     CMceComMediaStream::InitializeL( aParent );
       
   286 
       
   287     for (int i = 0; i<Codecs().Count();i++)
       
   288         {
       
   289         Codecs()[i]->InitializeL( *this );
       
   290         }
       
   291     }
       
   292 
       
   293 
       
   294 // -----------------------------------------------------------------------------
       
   295 // CMceComMessageStream::UpdateL
       
   296 // -----------------------------------------------------------------------------
       
   297 //
       
   298 void CMceComMessageStream::UpdateL( CMceComMediaStream& aStream )
       
   299     {  
       
   300     CMceComMediaStream::UpdateL( aStream );
       
   301 
       
   302     CMceComMessageStream* stream = static_cast<CMceComMessageStream*>( &aStream );
       
   303 	
       
   304 	
       
   305     if (iUseMsrpPathAttrForHostAddrAndPort != stream->iUseMsrpPathAttrForHostAddrAndPort)
       
   306     {
       
   307     iUseMsrpPathAttrForHostAddrAndPort = stream->iUseMsrpPathAttrForHostAddrAndPort;
       
   308     }
       
   309     this->iMsrpConnUsage = stream->iMsrpConnUsage ;
       
   310     
       
   311     RPointerArray<CMceComMessageCodec> updated;
       
   312     
       
   313     MceCleanupResetAndDestroyPushL( updated );
       
   314     
       
   315     for( TInt i = 0; i < stream->Codecs().Count(); i++ )
       
   316         {
       
   317         CMceComMessageCodec* update = stream->Codecs()[i];
       
   318         TBool isUpdated = EFalse;
       
   319         TInt j = 0;
       
   320         while( !isUpdated && j < Codecs().Count() )
       
   321             {
       
   322             CMceComMessageCodec* codec = Codecs()[j];
       
   323             if ( codec->Id() == update->Id() )
       
   324                 {
       
   325                 codec->UpdateL( *update );
       
   326                 stream->Codecs().Remove( i );
       
   327                 delete update;
       
   328                 updated.AppendL( codec );
       
   329                 Codecs().Remove( j );
       
   330                 i--;
       
   331                 isUpdated = ETrue;
       
   332                 }
       
   333             j++;                
       
   334             }
       
   335         }
       
   336 	this->iMsrpConnUsage = stream->iMsrpConnUsage ;        
       
   337     if ( Codecs().Count() > 0 )//codecs have been removed
       
   338         {
       
   339         Session()->IsStructureChanged() = ETrue;
       
   340         }
       
   341         
       
   342     iCodecs.ResetAndDestroy();
       
   343     while( updated.Count() > 0 )
       
   344         {
       
   345         iCodecs.AppendL( updated[0] );
       
   346         updated.Remove( 0 );
       
   347         }
       
   348         
       
   349     CleanupStack::PopAndDestroy();//updated
       
   350             
       
   351     if ( stream->Codecs().Count() > 0 )//streams have been added
       
   352         {
       
   353         Session()->IsStructureChanged() = ETrue;
       
   354             
       
   355         while( stream->Codecs().Count() > 0 )
       
   356             {
       
   357             CMceComMessageCodec* add = stream->Codecs()[0];
       
   358             iCodecs.AppendL( add );
       
   359             stream->Codecs().Remove( 0 );
       
   360             }
       
   361         }
       
   362     }
       
   363 
       
   364 
       
   365 
       
   366 // -----------------------------------------------------------------------------
       
   367 // CMceComMessageStream::ReorderCodecs
       
   368 // -----------------------------------------------------------------------------
       
   369 //
       
   370 void CMceComMessageStream::ReorderCodecs()
       
   371     {
       
   372     // The data path will not be handled in MCC for message type streams hence no codecs.
       
   373     TLinearOrder<CMceComMessageCodec> order( CMceComMessageCodec::CompareSdpIndex );
       
   374     
       
   375     iCodecs.Sort( order );
       
   376     }
       
   377 
       
   378 
       
   379 
       
   380 #ifdef MCE_COMMON_SERVER_SIDE
       
   381 
       
   382 
       
   383 // -----------------------------------------------------------------------------
       
   384 // CMceComMessageStream::SynchronizeL
       
   385 // -----------------------------------------------------------------------------
       
   386 //
       
   387 void CMceComMessageStream::SynchronizeL( TBool aRoleAnswerer )
       
   388     {
       
   389     TInt codecIndex( 0 );
       
   390 // Presently there is no codecs support in MCE/MCC for message type streams
       
   391     while ( codecIndex < Codecs().Count() )
       
   392         {
       
   393         CMceComCodec& codec = *Codecs()[ codecIndex ];
       
   394         
       
   395         //When role is offerer stream cannot remove codecs. 
       
   396         //It will be done by mediamanager together with mcc
       
   397         //if there is session update decoded there might be codecs
       
   398         //which are not valid anymore, and thus, needed to be removed.
       
   399         TBool remove( !codec.iIsNegotiated && aRoleAnswerer );
       
   400         
       
   401         if ( BoundStream() )
       
   402             {
       
   403             CMceComCodec* sync = BoundStreamL().FindCodecL( codec );
       
   404             
       
   405             if ( remove )
       
   406                 {
       
   407                 BoundStreamL().RemoveCodecL( sync );
       
   408                 }
       
   409             else if ( sync )
       
   410                 {
       
   411                 sync->SynchronizeL( codec, aRoleAnswerer );
       
   412                 }
       
   413             else if ( aRoleAnswerer )
       
   414                 {
       
   415                 //MCE_DEFINE_TEXT_CODEC( textCodec, codec );
       
   416                 CMceComMessageCodec& textCodec = static_cast<CMceComMessageCodec&>( codec );
       
   417                 CMceComMessageCodec* copy = textCodec.CloneL();
       
   418                 CleanupStack::PushL( copy );
       
   419                 copy->InitializeL( BoundStreamL() );
       
   420                 //MCE_TEXT( BoundStreamL() ).AddCodecL( copy );
       
   421                 (static_cast<CMceComMessageStream&>( BoundStreamL() )).AddCodecL( copy );
       
   422                 CleanupStack::Pop( copy );
       
   423                 }
       
   424             else
       
   425                 {
       
   426                 //NOP
       
   427                 }
       
   428             }
       
   429             
       
   430         if ( remove )
       
   431             {
       
   432             RemoveCodecL( &codec );
       
   433             }
       
   434         else
       
   435             {
       
   436             codecIndex++;
       
   437             }
       
   438         }
       
   439 
       
   440     }
       
   441 
       
   442 // -----------------------------------------------------------------------------
       
   443 // CMceComMessageStream::UpdateDefaultCodecL
       
   444 // -----------------------------------------------------------------------------
       
   445 //
       
   446 void CMceComMessageStream::UpdateDefaultCodecL()
       
   447     {
       
   448     RPointerArray<CMceComMessageCodec>& messageCodecs = Codecs();
       
   449     
       
   450     if ( messageCodecs.Count() > 0 )
       
   451         {
       
   452         CMceComCodec& highestPriorityCodec = *messageCodecs[ 0 ];
       
   453         
       
   454         TBool defaultRemoved( highestPriorityCodec.iIsEnabled &&
       
   455                               !highestPriorityCodec.iIsNegotiated );
       
   456                               
       
   457         TBool priorityChanged( !highestPriorityCodec.iIsEnabled && 
       
   458                                highestPriorityCodec.iIsNegotiated );                
       
   459         if ( defaultRemoved || priorityChanged )
       
   460             {
       
   461             TBool newDefaultCodecSet( EFalse );
       
   462             for ( TInt i = 0; i < messageCodecs.Count(); i++ )
       
   463                 {
       
   464                 CMceComCodec& codec = *messageCodecs[ i ];
       
   465                 if ( codec.iIsNegotiated )
       
   466                     {
       
   467                     if ( newDefaultCodecSet )
       
   468                         {
       
   469                         codec.iIsEnabled = EFalse;
       
   470                         }
       
   471                     else
       
   472                         {
       
   473                         codec.iIsEnabled = ETrue;
       
   474                         newDefaultCodecSet = ETrue;
       
   475                         }
       
   476                     }
       
   477                 }
       
   478             }
       
   479         }
       
   480     }
       
   481     
       
   482 // -----------------------------------------------------------------------------
       
   483 // CMceComMessageStream::PrepareL
       
   484 // -----------------------------------------------------------------------------
       
   485 //
       
   486 void CMceComMessageStream::PrepareL()
       
   487     {
       
   488 // Data path will not be handled for Message type streams in MCE/MCC
       
   489     //Hence not required to prepare the streams
       
   490     RPointerArray<CMceComMessageCodec>& codecs = Codecs();
       
   491     __ASSERT_ALWAYS ( codecs.Count() > 0, User::Leave( KErrArgument ) );
       
   492 
       
   493     if ( BoundStream() )
       
   494         {
       
   495         CMceComMessageStream& boundStream = static_cast<CMceComMessageStream&>( BoundStreamL() );
       
   496         __ASSERT_ALWAYS ( boundStream.Codecs().Count() > 0, User::Leave( KErrArgument ) );
       
   497         }
       
   498 
       
   499     }
       
   500 
       
   501 
       
   502 
       
   503 // -----------------------------------------------------------------------------
       
   504 // CMceComMessageStream::MccStreamType
       
   505 // -----------------------------------------------------------------------------
       
   506 //
       
   507 TInt CMceComMessageStream::MccStreamType() const
       
   508     {
       
   509     
       
   510     // The data path will not be handled in MCC for message type streams
       
   511     TInt type = KMccMessageLocalStream;
       
   512     
       
   513     if ( iStreamType == EReceiveStream || 
       
   514          iStreamType == EReceiveOnlyStream )
       
   515         {
       
   516         type = KMccMessageDownlinkStream;
       
   517         }
       
   518     else if ( iStreamType == ESendStream || 
       
   519               iStreamType == ESendOnlyStream )
       
   520         {
       
   521         type = KMccMessageUplinkStream;
       
   522         }
       
   523     else
       
   524         {
       
   525         type = KMccMessageLocalStream;
       
   526         }
       
   527         
       
   528     return type;
       
   529     }
       
   530 
       
   531 
       
   532 // -----------------------------------------------------------------------------
       
   533 // CMceComMessageStream::MccStreamType
       
   534 // -----------------------------------------------------------------------------
       
   535 //
       
   536 TInt CMceComMessageStream::MccLinkType() const
       
   537     {
       
   538 // The data path will not be handled in MCC for message type streams
       
   539     TInt type = KMccLinkMessage;
       
   540     
       
   541     if ( iStreamType == ELocalStream )
       
   542         {
       
   543         type = KMccLinkLocal;
       
   544         }
       
   545     if (iSession->iClientCryptoSuites.Count()>0)
       
   546         {
       
   547         type =KMccLinkSecure;
       
   548         }
       
   549     return type; 
       
   550     }
       
   551 
       
   552 #endif//MCE_COMMON_SERVER_SIDE