multimediacommsengine/mmceshared/src/mcecommediastream.cpp
changeset 0 1bce908db942
child 49 64c62431ac08
equal deleted inserted replaced
-1:000000000000 0:1bce908db942
       
     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 "mcecommediastream.h"
       
    22 #include "mceserial.h"
       
    23 #include "mceevents.h"
       
    24 #include "mcecommediasource.h"
       
    25 #include "mcecommediasink.h"
       
    26 #include "mcertpsource.h"
       
    27 #include "mcertpsink.h"
       
    28 #include "mcecomcodec.h"
       
    29 #include "cleanupresetanddestroy.h"
       
    30 #include "mceclient.pan"
       
    31 
       
    32 #ifdef MCE_COMMON_SERVER_SIDE
       
    33 
       
    34 #include <sdpcodecstringconstants.h>
       
    35 #include "mcesrvstream.h"
       
    36 #include "mcemediaobserver.h"
       
    37 #include "mcepreconditions.h"
       
    38 #include "mcesdpsession.h"
       
    39 
       
    40 #endif
       
    41 
       
    42 
       
    43 
       
    44 // ============================ MEMBER FUNCTIONS ===============================
       
    45 
       
    46 
       
    47 // -----------------------------------------------------------------------------
       
    48 // CMceComMediaStream::~CMceMediaStream
       
    49 // -----------------------------------------------------------------------------
       
    50 //
       
    51 CMceComMediaStream::~CMceComMediaStream()
       
    52     {
       
    53     
       
    54     if ( iSource )
       
    55         {
       
    56         DeleteSource();
       
    57         }
       
    58     
       
    59     if ( iLinkOwner )
       
    60 	    {
       
    61     	delete iLinkedStream;
       
    62     	iLinkedStream = NULL;
       
    63 	    }
       
    64 
       
    65 	while( iSinks.Count() > 0 )
       
    66 	    {
       
    67 	    DeleteSink( 0 );
       
    68 	    }
       
    69 	    
       
    70     iSinks.Reset();
       
    71     iSinks.Close();
       
    72     
       
    73     if ( iEmptySink )
       
    74     	{
       
    75     	delete iEmptySink;
       
    76     	iEmptySink = NULL;
       
    77     	}
       
    78     if ( iEmptySource )
       
    79     	{
       
    80     	delete iEmptySource;
       
    81     	iEmptySource = NULL;
       
    82     	}
       
    83     if	( iLocalMediaSDPLines )
       
    84     	{
       
    85     	delete iLocalMediaSDPLines;
       
    86     	iLocalMediaSDPLines = NULL;
       
    87     	}
       
    88     if ( iRemoteMediaSDPLines )
       
    89     	{
       
    90     	delete iRemoteMediaSDPLines;
       
    91     	iRemoteMediaSDPLines = NULL;
       
    92     	}
       
    93     
       
    94 #ifdef MCE_COMMON_SERVER_SIDE
       
    95     
       
    96     iPreconditions.ResetAndDestroy();
       
    97     
       
    98 #endif// MCE_COMMON_SERVER_SIDE
       
    99     
       
   100     }
       
   101 
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 // CMceComMediaStream::SetSourceL
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 void CMceComMediaStream::SetSourceL( CMceComMediaSource* aSource )
       
   108     {
       
   109     if ( aSource )
       
   110         {
       
   111         aSource->ReferenceCount()++;
       
   112         }
       
   113     
       
   114     if ( iSource )
       
   115         {
       
   116         DeleteSource();            
       
   117         }
       
   118     iSource = aSource;
       
   119     }
       
   120 
       
   121 
       
   122 // -----------------------------------------------------------------------------
       
   123 // CMceComMediaStream::AddSinkL
       
   124 // -----------------------------------------------------------------------------
       
   125 //
       
   126 void CMceComMediaStream::AddSinkL( CMceComMediaSink* aSink )
       
   127     {
       
   128     iSinks.AppendL( aSink );
       
   129     aSink->ReferenceCount()++;
       
   130     }
       
   131 
       
   132 
       
   133 // -----------------------------------------------------------------------------
       
   134 // CMceComMediaStream::DeleteSink
       
   135 // -----------------------------------------------------------------------------
       
   136 //
       
   137 void CMceComMediaStream::DeleteSink( TInt aIndex )
       
   138     {
       
   139     
       
   140     iSinks[ aIndex ]->ReferenceCount()--;
       
   141     if ( iSinks[ aIndex ]->ReferenceCount() == 0 )
       
   142         {
       
   143         delete iSinks[ aIndex ];
       
   144         }
       
   145     else
       
   146         {
       
   147         iSinks[ aIndex ]->UnInitialize( *this );
       
   148         }
       
   149         
       
   150     iSinks.Remove( aIndex );
       
   151     
       
   152     }
       
   153     
       
   154 // -----------------------------------------------------------------------------
       
   155 // CMceComMediaStream::DeleteSource
       
   156 // -----------------------------------------------------------------------------
       
   157 //
       
   158 void CMceComMediaStream::DeleteSource()
       
   159     {
       
   160     iSource->ReferenceCount()--;
       
   161     if ( iSource->ReferenceCount() == 0 )
       
   162         {
       
   163         delete iSource;
       
   164         }
       
   165     else
       
   166         {
       
   167         iSource->UnInitialize( *this );
       
   168         }
       
   169         
       
   170     iSource = NULL;
       
   171     }
       
   172 
       
   173 // -----------------------------------------------------------------------------
       
   174 // CMceComMediaStream::Source
       
   175 // -----------------------------------------------------------------------------
       
   176 //
       
   177 CMceComMediaSource* CMceComMediaStream::Source()
       
   178     {
       
   179     return iSource;
       
   180     }
       
   181 
       
   182 
       
   183 // -----------------------------------------------------------------------------
       
   184 // CMceComMediaStream::Sinks
       
   185 // -----------------------------------------------------------------------------
       
   186 //
       
   187 RPointerArray<CMceComMediaSink>& CMceComMediaStream::Sinks()
       
   188     {
       
   189     return iSinks;
       
   190     }    
       
   191 
       
   192 
       
   193 // -----------------------------------------------------------------------------
       
   194 // CMceComMediaStream::BindL
       
   195 // -----------------------------------------------------------------------------
       
   196 //
       
   197 void CMceComMediaStream::BindL( CMceComMediaStream* aStream )
       
   198     {
       
   199     __ASSERT_ALWAYS( !(!iLinkOwner && iLinkedStream ) , User::Leave( KErrArgument ) );
       
   200     
       
   201     if ( aStream )
       
   202         {
       
   203         iLinkOwner = ETrue;
       
   204         aStream->DoBind( this );
       
   205         DoBind( aStream );
       
   206         }
       
   207     else
       
   208         {
       
   209         iLinkOwner = EFalse;
       
   210     	delete iLinkedStream;
       
   211     	iLinkedStream = NULL;
       
   212     	if ( iSession )
       
   213     		{
       
   214 			InitializeL( *iSession );
       
   215     		}
       
   216     	
       
   217         }
       
   218         
       
   219     }
       
   220 
       
   221 
       
   222 // -----------------------------------------------------------------------------
       
   223 // CMceComMediaStream::DoBind
       
   224 // -----------------------------------------------------------------------------
       
   225 //
       
   226 void CMceComMediaStream::DoBind( CMceComMediaStream* aStream )
       
   227     {
       
   228     if ( iLinkedStream )
       
   229         {
       
   230         delete iLinkedStream;
       
   231         iLinkedStream = NULL;
       
   232         }
       
   233         
       
   234     iLinkedStream = aStream;
       
   235     
       
   236     }
       
   237 
       
   238 
       
   239 // -----------------------------------------------------------------------------
       
   240 // CMceComMediaStream::BoundStreamL
       
   241 // -----------------------------------------------------------------------------
       
   242 //
       
   243 CMceComMediaStream& CMceComMediaStream::BoundStreamL()
       
   244     {
       
   245     return *iLinkedStream;
       
   246     }
       
   247 
       
   248 
       
   249 // -----------------------------------------------------------------------------
       
   250 // CMceComMediaStream::BoundStream
       
   251 // -----------------------------------------------------------------------------
       
   252 //
       
   253 TBool CMceComMediaStream::BoundStream() const
       
   254     {
       
   255     return iLinkedStream != NULL;
       
   256     }
       
   257 
       
   258 
       
   259 // -----------------------------------------------------------------------------
       
   260 // CMceComMediaStream::Binder
       
   261 // -----------------------------------------------------------------------------
       
   262 //
       
   263 TBool CMceComMediaStream::Binder() const
       
   264     {
       
   265     return iLinkOwner;
       
   266     }
       
   267 
       
   268 // -----------------------------------------------------------------------------
       
   269 // CMceComMediaStream::operator()
       
   270 // -----------------------------------------------------------------------------
       
   271 //
       
   272 CMceComMediaStream& CMceComMediaStream::operator()()
       
   273     {
       
   274     CMceComMediaStream* owner = this;
       
   275     
       
   276     if ( BoundStream() && !Binder() )
       
   277         {
       
   278         owner = iLinkedStream;
       
   279         }
       
   280 
       
   281     return *owner;
       
   282     
       
   283     }
       
   284        
       
   285 // -----------------------------------------------------------------------------
       
   286 // CMceComMediaStream::operator()
       
   287 // -----------------------------------------------------------------------------
       
   288 //
       
   289 const CMceComMediaStream& CMceComMediaStream::operator()() const
       
   290     {
       
   291     const CMceComMediaStream* owner = this;
       
   292     
       
   293     if ( BoundStream() && !Binder() )
       
   294         {
       
   295         owner = iLinkedStream;
       
   296         }
       
   297 
       
   298     return *owner;
       
   299     
       
   300     }
       
   301 
       
   302 // -----------------------------------------------------------------------------
       
   303 // CMceComMediaStream::SerializationId
       
   304 // -----------------------------------------------------------------------------
       
   305 //
       
   306 TUint64 CMceComMediaStream::SerializationId() const
       
   307     {
       
   308     return iID.Uint64();
       
   309     }
       
   310     
       
   311 // -----------------------------------------------------------------------------
       
   312 // CMceComMediaStream::InternalizeFlatL
       
   313 // -----------------------------------------------------------------------------
       
   314 //
       
   315 void CMceComMediaStream::InternalizeFlatL( RReadStream& aReadStream )
       
   316     {
       
   317     
       
   318     //iType
       
   319     iType = static_cast<TMceMediaType>( aReadStream.ReadUint8L() );
       
   320     //iID
       
   321     MceSerial::DecodeL( iID, aReadStream );
       
   322     //iState
       
   323     iIsEnabled = static_cast< TBool >( aReadStream.ReadUint8L() );
       
   324     //iLocalMediaPort
       
   325     iLocalMediaPort = aReadStream.ReadUint16L();
       
   326     //iRemoteMediaPort
       
   327 	iRemoteMediaPort = aReadStream.ReadUint16L();
       
   328     //iLocalMediaSDPLines
       
   329     MceSerial::DecodeL( iLocalMediaSDPLines, aReadStream ); 
       
   330     //iRemoteMediaSDPLines
       
   331     MceSerial::DecodeL( iRemoteMediaSDPLines, aReadStream ); 
       
   332     //iLinkOwner
       
   333     iLinkOwner = static_cast<TBool>( aReadStream.ReadUint8L() );
       
   334     //iState
       
   335     iState = static_cast<CMceMediaStream::TState>( aReadStream.ReadUint8L() );
       
   336     //iIgnoreRemotePort
       
   337     iIgnoreRemotePort = static_cast<TBool>( aReadStream.ReadUint8L() );    
       
   338     }
       
   339     
       
   340 // -----------------------------------------------------------------------------
       
   341 // CMceComMediaStream::ExternalizeFlatL
       
   342 // -----------------------------------------------------------------------------
       
   343 //
       
   344 void CMceComMediaStream::ExternalizeFlatL( RWriteStream& aWriteStream )
       
   345     {
       
   346     
       
   347 	aWriteStream.WriteUint8L( iType );
       
   348     MceSerial::EncodeL( iID, aWriteStream );
       
   349 	aWriteStream.WriteUint8L( iIsEnabled );
       
   350 	aWriteStream.WriteUint16L( iLocalMediaPort );
       
   351     aWriteStream.WriteUint16L( iRemoteMediaPort );
       
   352 	MceSerial::EncodeL( iLocalMediaSDPLines, aWriteStream );
       
   353 	MceSerial::EncodeL( iRemoteMediaSDPLines, aWriteStream );
       
   354 	aWriteStream.WriteUint8L( iLinkOwner );
       
   355 	aWriteStream.WriteUint8L( iState );
       
   356 	aWriteStream.WriteUint8L( iIgnoreRemotePort );
       
   357     }
       
   358 
       
   359 
       
   360 // -----------------------------------------------------------------------------
       
   361 // CMceComMediaStream::InternalizeL
       
   362 // -----------------------------------------------------------------------------
       
   363 //
       
   364 void CMceComMediaStream::InternalizeL( MMceComSerializationContext& aSerCtx )
       
   365     {
       
   366     
       
   367     TMceMediaStreamSerializer<CMceComMediaStream> serial( *this );
       
   368     serial.InternalizeL( aSerCtx );
       
   369     }
       
   370 
       
   371 // -----------------------------------------------------------------------------
       
   372 // CMceComMediaStream::ExternalizeL
       
   373 // -----------------------------------------------------------------------------
       
   374 //
       
   375 void CMceComMediaStream::ExternalizeL( MMceComSerializationContext& aSerCtx )
       
   376     {
       
   377     
       
   378     TMceMediaStreamSerializer<CMceComMediaStream> serial( *this );
       
   379     serial.ExternalizeL( aSerCtx );
       
   380     
       
   381     }
       
   382 
       
   383 
       
   384 // -----------------------------------------------------------------------------
       
   385 // CMceComMediaStream::CMceComMediaStream
       
   386 // -----------------------------------------------------------------------------
       
   387 //
       
   388 CMceComMediaStream::CMceComMediaStream( TMceMediaType aType )
       
   389   : iID( TMceMediaId( (TUint32)&iID ) ),
       
   390     iType( aType ),
       
   391     iIsEnabled( ETrue ),
       
   392     iLocalMediaPort (5000),
       
   393     iRemoteRtcpAddress ( KInetAddrAny ),
       
   394     iRemoteRtcpPort( 0 ),
       
   395     iStreamType( ELocalStream ),
       
   396     iState( CMceMediaStream::EUninitialized ),
       
   397     iLinkOwner( EFalse ),
       
   398     iLinkedStream( NULL ),
       
   399     iSource( NULL ),
       
   400     iSdpIndex( KErrNotFound ),
       
   401     iLinkId( KMceNotAssigned ),
       
   402     iDowngradedEnpoints( EFalse )
       
   403     {
       
   404     }
       
   405 
       
   406 
       
   407 // -----------------------------------------------------------------------------
       
   408 // CMceComMediaStream::ConstructL
       
   409 // -----------------------------------------------------------------------------
       
   410 //
       
   411 void CMceComMediaStream::ConstructL()
       
   412     {
       
   413     
       
   414     iLocalMediaSDPLines = new (ELeave) CDesC8ArrayFlat( KMceArrayGranularity );
       
   415     iRemoteMediaSDPLines = new (ELeave) CDesC8ArrayFlat( KMceArrayGranularity );
       
   416     
       
   417     }
       
   418 
       
   419 
       
   420 // -----------------------------------------------------------------------------
       
   421 // CMceComMediaStream::ConstructL
       
   422 // -----------------------------------------------------------------------------
       
   423 //
       
   424 void CMceComMediaStream::ConstructL( CMceComMediaStream& aStream )
       
   425     {
       
   426     
       
   427     iID = aStream.iID;
       
   428     iType = aStream.iType;
       
   429     iIsEnabled = aStream.iIsEnabled;
       
   430     iState = aStream.iState;
       
   431     iLocalMediaPort = aStream.iLocalMediaPort;
       
   432     iRemoteMediaPort = aStream.iRemoteMediaPort;
       
   433     iIgnoreRemotePort = aStream.iIgnoreRemotePort;
       
   434     iRemoteRtcpAddress = aStream.iRemoteRtcpAddress;
       
   435     iRemoteRtcpPort = aStream.iRemoteRtcpPort;
       
   436     iLocalMediaSDPLines = new (ELeave) CDesC8ArrayFlat( KMceArrayGranularity );
       
   437     iRemoteMediaSDPLines = new (ELeave) CDesC8ArrayFlat( KMceArrayGranularity );
       
   438     
       
   439     iSdpIndex = aStream.iSdpIndex;
       
   440     iDowngradedEnpoints = aStream.iDowngradedEnpoints;
       
   441     
       
   442     TInt i = 0;
       
   443     for( i = 0;i<aStream.iLocalMediaSDPLines->MdcaCount();i++ )
       
   444         {
       
   445         iLocalMediaSDPLines->AppendL( aStream.iLocalMediaSDPLines->MdcaPoint( i ) );
       
   446         }
       
   447         
       
   448     for( i = 0;i<aStream.iRemoteMediaSDPLines->MdcaCount();i++ )
       
   449         {
       
   450         iRemoteMediaSDPLines->AppendL( aStream.iRemoteMediaSDPLines->MdcaPoint( i ) );
       
   451         }
       
   452         
       
   453     iLinkOwner = aStream.iLinkOwner;
       
   454     
       
   455     if ( aStream.Binder() && aStream.BoundStream() )
       
   456         {
       
   457         iLinkedStream = static_cast<CMceComMediaStream*>( aStream.iLinkedStream->CloneL() );
       
   458         iLinkedStream->iLinkedStream = this;
       
   459         }
       
   460         
       
   461     if ( aStream.iSource )
       
   462         {
       
   463         CMceComMediaSource* source = aStream.iSource->CloneL();
       
   464         CleanupStack::PushL( source );
       
   465         SetSourceL( source );
       
   466         CleanupStack::Pop( source );
       
   467         }
       
   468         
       
   469     for( i = 0; i < aStream.iSinks.Count();i++)
       
   470         {
       
   471         CMceComMediaSink* sink = aStream.iSinks[ i ]->CloneL();
       
   472         CleanupStack::PushL( sink );
       
   473         AddSinkL( sink );
       
   474         CleanupStack::Pop( sink );
       
   475         }
       
   476         
       
   477     if ( aStream.iEmptySource )
       
   478         {
       
   479         iEmptySource = aStream.iEmptySource->CloneL();
       
   480         }
       
   481         
       
   482     if ( aStream.iEmptySink )
       
   483         {
       
   484         iEmptySink = aStream.iEmptySink->CloneL();
       
   485         }
       
   486         
       
   487 #ifdef MCE_COMMON_SERVER_SIDE
       
   488     
       
   489     if ( aStream.iPreconditions.Count() )
       
   490         {
       
   491         for ( int j = 0; j < aStream.iPreconditions.Count(); j++ )
       
   492         	{
       
   493         	TMcePreconditions* precondition = 
       
   494         				static_cast < TMcePreconditions* > ( aStream.iPreconditions[j] );
       
   495         	TMcePreconditions* clone = precondition->CloneL( *this );
       
   496         	CleanupStack::PushL( clone );
       
   497         	iPreconditions.AppendL( clone );
       
   498         	CleanupStack::Pop( clone );
       
   499         	}
       
   500         }
       
   501     else	
       
   502         {
       
   503         iPreconditions.Reset();
       
   504         }
       
   505     
       
   506 #endif// MCE_COMMON_SERVER_SIDE
       
   507         
       
   508     }
       
   509 
       
   510 
       
   511 
       
   512 // -----------------------------------------------------------------------------
       
   513 // CMceComMediaStream::BaseFactory
       
   514 // -----------------------------------------------------------------------------
       
   515 //
       
   516 TMceComFactory CMceComMediaStream::BaseFactory()
       
   517     {
       
   518     return TMceComFactory();
       
   519     }
       
   520 
       
   521 // -----------------------------------------------------------------------------
       
   522 // CMceComMediaStream::Factory
       
   523 // -----------------------------------------------------------------------------
       
   524 //
       
   525 TMceComMediaStreamFactory CMceComMediaStream::Factory()
       
   526     {
       
   527     return TMceComMediaStreamFactory();
       
   528     }
       
   529 
       
   530 
       
   531 // -----------------------------------------------------------------------------
       
   532 // CMceComMediaStream::SetSourceL
       
   533 // -----------------------------------------------------------------------------
       
   534 //
       
   535 void CMceComMediaStream::SetSourceL( MMceComSerializationContext& aSerCtx )
       
   536     {
       
   537 
       
   538     RReadStream& readStream = aSerCtx.ReadStream();
       
   539 
       
   540     TBool externalizedReference = readStream.ReadUint8L();
       
   541     
       
   542     if ( externalizedReference )
       
   543         {
       
   544         TMceMediaId id;
       
   545         MceSerial::DecodeL( id, readStream );
       
   546         CMceComMediaSource* source = NULL;
       
   547         TInt index = 0;
       
   548         while( !source && index < aSerCtx.SourceCache().Count() )
       
   549             {
       
   550             source = static_cast<CMceComMediaSource*>( 
       
   551                                             aSerCtx.SourceCache()[ index++ ] );
       
   552             source = source->SerializationId() == id.Uint64() ? source : NULL;
       
   553             }
       
   554         __ASSERT_ALWAYS( source, User::Leave( KErrNotFound ) );
       
   555         SetSourceL( source );
       
   556         }
       
   557     else
       
   558         {
       
   559         CMceComMediaSource* source = 
       
   560             BaseFactory().SourceFactory().CreateLC( aSerCtx );
       
   561         SetSourceL( source );
       
   562         CleanupStack::Pop( source );
       
   563         aSerCtx.SourceCache().AppendL( source );
       
   564         
       
   565         }
       
   566     }
       
   567 
       
   568 // -----------------------------------------------------------------------------
       
   569 // CMceComMediaStream::AddSinkL
       
   570 // -----------------------------------------------------------------------------
       
   571 //
       
   572 void CMceComMediaStream::AddSinkL( MMceComSerializationContext& aSerCtx )
       
   573     {
       
   574 
       
   575     RReadStream& readStream = aSerCtx.ReadStream();
       
   576 
       
   577     TBool externalizedReference = readStream.ReadUint8L();
       
   578     
       
   579     if ( externalizedReference )
       
   580         {
       
   581         TMceMediaId id;
       
   582         MceSerial::DecodeL( id, readStream );
       
   583         CMceComMediaSink* sink = NULL;
       
   584         TInt index = 0;
       
   585         while( !sink && index < aSerCtx.SinkCache().Count() )
       
   586             {
       
   587             sink = static_cast<CMceComMediaSink*>( aSerCtx.SinkCache()[ index++ ] );
       
   588             sink = sink->SerializationId() == id.Uint64() ? sink : NULL;
       
   589             }
       
   590         __ASSERT_ALWAYS( sink, User::Leave( KErrNotFound ) );
       
   591         AddSinkL( sink );
       
   592         }
       
   593     else
       
   594         {
       
   595         CMceComMediaSink* sink = 
       
   596             BaseFactory().SinkFactory().CreateLC( aSerCtx );
       
   597         AddSinkL( sink );
       
   598         CleanupStack::Pop( sink );
       
   599         aSerCtx.SinkCache().AppendL( sink );
       
   600         
       
   601         }
       
   602     
       
   603     }
       
   604 
       
   605 // -----------------------------------------------------------------------------
       
   606 // CMceComMediaStream::Id
       
   607 // -----------------------------------------------------------------------------
       
   608 //
       
   609 TMceMediaId CMceComMediaStream::Id() const
       
   610     {
       
   611     return iID;
       
   612     }
       
   613 
       
   614 
       
   615 // -----------------------------------------------------------------------------
       
   616 // CMceComMediaStream::InitializeL
       
   617 // -----------------------------------------------------------------------------
       
   618 //
       
   619 void CMceComMediaStream::InitializeL( CMceComSession& aParent )
       
   620     {
       
   621     iSession = &aParent;
       
   622     
       
   623     iStreamType = ELocalStream;
       
   624     
       
   625     if ( Binder() && BoundStream() )
       
   626         {
       
   627         iLinkedStream->InitializeL( aParent );
       
   628         }
       
   629         
       
   630     if ( iSource )
       
   631         {
       
   632         iSource->InitializeL( *this );
       
   633         if ( iSource->iType == KMceRTPSource )
       
   634             {
       
   635             iStreamType = BoundStream() ? EReceiveStream : EReceiveOnlyStream;
       
   636             }
       
   637         }
       
   638         
       
   639         
       
   640     for( int i = 0; i < iSinks.Count();i++)
       
   641         {
       
   642         iSinks[i]->InitializeL( *this );
       
   643         if ( iStreamType == ELocalStream && 
       
   644              iSinks[i]->iType == KMceRTPSink )
       
   645             {
       
   646             iStreamType = BoundStream() ? ESendStream : ESendOnlyStream;
       
   647             }
       
   648         }
       
   649         
       
   650     if ( iEmptySource )
       
   651         {
       
   652         iEmptySource->InitializeL( *this );
       
   653         }
       
   654         
       
   655     if ( iEmptySink )
       
   656         {
       
   657         iEmptySink->InitializeL( *this );
       
   658         }
       
   659     }
       
   660 
       
   661 // -----------------------------------------------------------------------------
       
   662 // CMceComMediaStream::Session
       
   663 // -----------------------------------------------------------------------------
       
   664 //
       
   665 CMceComSession* CMceComMediaStream::Session() const
       
   666     {
       
   667     return iSession;
       
   668     }
       
   669 
       
   670 
       
   671 // -----------------------------------------------------------------------------
       
   672 // CMceComMediaStream::SetRemoteMediaPort
       
   673 // -----------------------------------------------------------------------------
       
   674 //
       
   675 void CMceComMediaStream::SetRemoteMediaPort( TUint aPort )
       
   676     {
       
   677     
       
   678     iRemoteMediaPort = aPort;
       
   679     
       
   680     if ( BoundStream() )
       
   681         {
       
   682         iLinkedStream->iRemoteMediaPort = aPort;
       
   683         }
       
   684         
       
   685     }    
       
   686 
       
   687 // -----------------------------------------------------------------------------
       
   688 // CMceComMediaStream::SetRemoteRtcpMediaPort
       
   689 // -----------------------------------------------------------------------------
       
   690 //
       
   691 void CMceComMediaStream::SetRemoteRtcpMediaAddrL( TDesC16& aAddr )
       
   692     {
       
   693     User::LeaveIfError ( 
       
   694                     iRemoteRtcpAddress.Input( aAddr ) );
       
   695     
       
   696     if ( BoundStream() )
       
   697         {
       
   698         iLinkedStream->iRemoteRtcpAddress = iRemoteRtcpAddress;
       
   699         }
       
   700         
       
   701     }
       
   702 // -----------------------------------------------------------------------------
       
   703 // CMceComMediaStream::SetRemoteRtcpMediaPort
       
   704 // -----------------------------------------------------------------------------
       
   705 //
       
   706 void CMceComMediaStream::SetRemoteRtcpMediaPort( TUint aPort )
       
   707     {
       
   708     
       
   709     iRemoteRtcpPort = aPort;
       
   710     
       
   711     if ( BoundStream() )
       
   712         {
       
   713         iLinkedStream->iRemoteRtcpPort = aPort;
       
   714         }
       
   715         
       
   716     }    
       
   717 
       
   718 // -----------------------------------------------------------------------------
       
   719 // CMceComMediaStream::SetLocalMediaPort
       
   720 // -----------------------------------------------------------------------------
       
   721 //
       
   722 void CMceComMediaStream::SetLocalMediaPort( TUint aPort )
       
   723     {
       
   724     
       
   725     iLocalMediaPort = aPort;
       
   726     
       
   727     if ( BoundStream() )
       
   728         {
       
   729         iLinkedStream->iLocalMediaPort = aPort;
       
   730         }
       
   731         
       
   732     }    
       
   733 	
       
   734 	
       
   735 // -----------------------------------------------------------------------------
       
   736 // CMceComMediaStream::RemoteMediaPort
       
   737 // -----------------------------------------------------------------------------
       
   738 //
       
   739 TUint CMceComMediaStream::RemoteMediaPort() const
       
   740 	{
       
   741 	return iRemoteMediaPort;
       
   742 	}
       
   743 
       
   744 // -----------------------------------------------------------------------------
       
   745 // CMceComMediaStream::LocalMediaPort
       
   746 // -----------------------------------------------------------------------------
       
   747 //
       
   748 TUint CMceComMediaStream::LocalMediaPort() const
       
   749 	{
       
   750 	return iLocalMediaPort;
       
   751 	}
       
   752 
       
   753 // -----------------------------------------------------------------------------
       
   754 // CMceComMediaStream::RemoteMediaPortChanged
       
   755 // -----------------------------------------------------------------------------
       
   756 //
       
   757 TBool CMceComMediaStream::RemoteMediaPortChanged( TUint aNewPort )
       
   758     {
       
   759     return ( aNewPort != iRemoteMediaPort && !iIgnoreRemotePort );
       
   760     }
       
   761     
       
   762     
       
   763 // -----------------------------------------------------------------------------
       
   764 // CMceComMediaStream::RemoteRTCPAddressChanged
       
   765 // -----------------------------------------------------------------------------
       
   766 //
       
   767 TBool CMceComMediaStream::RemoteRTCPAddressChanged( TUint aNewPort, TInetAddr aAddr )
       
   768     {
       
   769     return ( (aNewPort != iRemoteRtcpPort && !iIgnoreRemotePort) ||
       
   770     		(aAddr != iRemoteRtcpAddress && !iIgnoreRemotePort ));
       
   771     }
       
   772 
       
   773 // -----------------------------------------------------------------------------
       
   774 // CMceComMediaStream::SetIgnoreRemotePort
       
   775 // -----------------------------------------------------------------------------
       
   776 //
       
   777 void CMceComMediaStream::SetIgnoreRemotePort( TBool aIgnore )
       
   778     {
       
   779     // Remote port comparison can be turned on/off. For example nat session might
       
   780     // change remote port to be different than defined in sdp (remote port is
       
   781     // actually in own loopback address) and in such case comparison is not 
       
   782     // valid.
       
   783     iIgnoreRemotePort = aIgnore;
       
   784     }
       
   785     
       
   786 // -----------------------------------------------------------------------------
       
   787 // CMceComMediaStream::EventReceivedL
       
   788 // -----------------------------------------------------------------------------
       
   789 //
       
   790 TInt CMceComMediaStream::EventReceivedL( TMceComEvent& aEvent )
       
   791     {
       
   792     TInt status = aEvent.Id().iMediaID == iID ? KMceEventNotConsumed : KMceEventNotOwner;
       
   793 
       
   794     //try binded
       
   795     if ( status == KMceEventNotOwner )
       
   796         {
       
   797         if ( Binder() && BoundStream() )
       
   798             {
       
   799             status = iLinkedStream->EventReceivedL( aEvent );
       
   800             }
       
   801         return status;
       
   802         }
       
   803         
       
   804     //try source
       
   805     if ( aEvent.Id().IsSourceId() )
       
   806         {
       
   807         if ( iSource )
       
   808             {
       
   809             status = iSource->EventReceivedL( aEvent );
       
   810             status = status == KMceEventNotOwner ? KMceEventNotConsumed : status;
       
   811             }
       
   812         return status;
       
   813         }
       
   814         
       
   815     //try sinks
       
   816     if ( aEvent.Id().IsSinkId() )
       
   817         {
       
   818         TInt sinkStatus = status;
       
   819         TInt j = 0;
       
   820         while ( sinkStatus != KMceEventConsumed && j < iSinks.Count() )
       
   821             {
       
   822             CMceComMediaSink* sink = iSinks[j]; 
       
   823             sinkStatus = sink->EventReceivedL( aEvent );
       
   824             j++;                
       
   825             }
       
   826         status = sinkStatus == KMceEventNotOwner ? KMceEventNotConsumed : sinkStatus;    
       
   827         return status;            
       
   828         }
       
   829 
       
   830     return status;
       
   831     }
       
   832 
       
   833 
       
   834 
       
   835 
       
   836 // -----------------------------------------------------------------------------
       
   837 // CMceComMediaStream::UpdateL
       
   838 // -----------------------------------------------------------------------------
       
   839 //
       
   840 void CMceComMediaStream::UpdateL( CMceComMediaStream& aStream )
       
   841     {
       
   842     
       
   843     iType = aStream.iType;
       
   844     iID = aStream.iID;
       
   845     iIsEnabled = aStream.iIsEnabled;
       
   846     iLocalMediaPort = aStream.iLocalMediaPort;
       
   847     // If stream is in ignoring mode, remote port is not updated
       
   848     if ( !iIgnoreRemotePort )
       
   849         {
       
   850         iRemoteMediaPort = aStream.iRemoteMediaPort;
       
   851         }
       
   852     iIgnoreRemotePort = aStream.iIgnoreRemotePort;
       
   853     iState = aStream.iState;
       
   854     
       
   855     delete iLocalMediaSDPLines;
       
   856     iLocalMediaSDPLines = aStream.iLocalMediaSDPLines;
       
   857     aStream.iLocalMediaSDPLines = NULL;
       
   858     
       
   859     delete iRemoteMediaSDPLines;
       
   860     iRemoteMediaSDPLines = aStream.iRemoteMediaSDPLines;
       
   861     aStream.iRemoteMediaSDPLines = NULL;
       
   862     
       
   863     
       
   864     if ( aStream.BoundStream() )
       
   865         {
       
   866         if ( BoundStream() ) 
       
   867             {
       
   868             if ( Binder() )
       
   869                 {
       
   870                 iLinkedStream->UpdateL( *aStream.iLinkedStream );
       
   871                 }
       
   872             }
       
   873         else 
       
   874             {
       
   875             Session()->IsStructureChanged() = ETrue;
       
   876             CMceComMediaStream* newStream = aStream.iLinkedStream;
       
   877             newStream->iLinkedStream = NULL;
       
   878             newStream->iLinkOwner = EFalse;
       
   879             aStream.iLinkedStream = NULL;
       
   880             aStream.iLinkOwner = EFalse;
       
   881             CleanupStack::PushL( newStream );
       
   882             BindL( newStream );
       
   883             CleanupStack::Pop( newStream );
       
   884             }
       
   885         }
       
   886     else if ( !aStream.BoundStream() && BoundStream() )
       
   887         {
       
   888         Session()->IsStructureChanged() = ETrue;
       
   889         BindL( NULL );
       
   890         }
       
   891     else
       
   892         {
       
   893         //NOP
       
   894         }
       
   895         
       
   896     if ( Source() && aStream.Source() )
       
   897         {
       
   898         if ( Source()->Id() == aStream.Source()->Id() )
       
   899             {
       
   900             iSource->UpdateL( *aStream.Source() );
       
   901             }
       
   902         else
       
   903             {
       
   904             SetSourceL( aStream.Source() );
       
   905             }
       
   906         }
       
   907     else if ( !Source() && aStream.Source() )
       
   908         {
       
   909         SetSourceL( aStream.Source() );
       
   910         }
       
   911     else 
       
   912         {
       
   913         Session()->IsStructureChanged() = ETrue;
       
   914         SetSourceL( NULL );
       
   915         }
       
   916      
       
   917     
       
   918     RPointerArray<CMceComMediaSink> updated;
       
   919     CleanupClosePushL( updated );
       
   920     
       
   921     //updated sinks
       
   922     TInt i = 0;
       
   923     TInt j = 0;
       
   924     CMceComMediaSink* sink = NULL;
       
   925     CMceComMediaSink* update = NULL;
       
   926     for( i = 0; i < aStream.Sinks().Count(); i++ )
       
   927         {
       
   928         update = aStream.Sinks()[i];
       
   929         TBool isUpdated = EFalse;
       
   930         TInt k = 0;
       
   931         while( !isUpdated && k < Sinks().Count() )
       
   932             {
       
   933             sink = Sinks()[k];
       
   934             if ( sink->Id() == update->Id() )
       
   935                 {
       
   936                 sink->UpdateL( *update );
       
   937                 updated.AppendL( sink );
       
   938                 isUpdated = ETrue;
       
   939                 }
       
   940             k++;                
       
   941             }
       
   942         }
       
   943 
       
   944     //removed sinks
       
   945     sink = NULL;
       
   946     update = NULL;
       
   947     for( i = 0; i < Sinks().Count(); i++ )
       
   948         {
       
   949         sink = Sinks()[ i ];
       
   950         update = NULL;
       
   951         j = 0;
       
   952         while( !update && j < updated.Count() )
       
   953             {
       
   954             update = updated[ j++ ];
       
   955             update = update->Id() == sink->Id() ? update : NULL;
       
   956             }
       
   957         if ( !update )
       
   958             {
       
   959             Session()->IsStructureChanged() = ETrue;
       
   960             DeleteSink( i );
       
   961             i--;
       
   962             }
       
   963         }
       
   964 
       
   965     //added sinks    
       
   966     sink = NULL;
       
   967     update = NULL;
       
   968     for( i = 0; i < aStream.Sinks().Count(); i++ )
       
   969         {
       
   970         sink = aStream.Sinks()[ i ];
       
   971         update = NULL;
       
   972         j = 0;
       
   973         while( !update && j < updated.Count() )
       
   974             {
       
   975             update = updated[ j++ ];
       
   976             update = update->Id() == sink->Id() ? update : NULL;
       
   977             }
       
   978         if ( !update )
       
   979             {
       
   980             Session()->IsStructureChanged() = ETrue;
       
   981             AddSinkL( sink );//'reference counted'
       
   982             }
       
   983         }
       
   984     
       
   985     CleanupStack::PopAndDestroy();//updated
       
   986     
       
   987     }
       
   988     
       
   989     
       
   990 // -----------------------------------------------------------------------------
       
   991 // CMceComMediaStream::IsEnabled
       
   992 // -----------------------------------------------------------------------------
       
   993 //
       
   994 TBool CMceComMediaStream::IsEnabled()
       
   995     {
       
   996     return iIsEnabled;
       
   997     }
       
   998     
       
   999 
       
  1000 // -----------------------------------------------------------------------------
       
  1001 // CMceComMediaStream::SendStream
       
  1002 // -----------------------------------------------------------------------------
       
  1003 //
       
  1004 CMceComMediaStream* CMceComMediaStream::SendStream()
       
  1005     {
       
  1006     CMceComMediaStream* sendStream = NULL;
       
  1007     
       
  1008     if ( IS_SENDSTREAM( this ) )
       
  1009         {
       
  1010         sendStream = this;
       
  1011         }
       
  1012     else if ( BoundStream() )
       
  1013         {
       
  1014         if ( IS_SENDSTREAM( iLinkedStream ) )
       
  1015             {
       
  1016             //The bound stream is uplink
       
  1017             sendStream = iLinkedStream;
       
  1018             }
       
  1019         }
       
  1020     else
       
  1021         {
       
  1022         //NOP
       
  1023         }
       
  1024         
       
  1025     return sendStream;
       
  1026     
       
  1027     }
       
  1028 
       
  1029 // -----------------------------------------------------------------------------
       
  1030 // CMceComMediaStream::ReceiveStream
       
  1031 // -----------------------------------------------------------------------------
       
  1032 //
       
  1033 CMceComMediaStream* CMceComMediaStream::ReceiveStream()
       
  1034     {
       
  1035     CMceComMediaStream* receiveStream = NULL;
       
  1036     
       
  1037     if ( IS_RECEIVESTREAM( this ) )
       
  1038         {
       
  1039         receiveStream = this;
       
  1040         }
       
  1041     else if ( BoundStream() )
       
  1042         {
       
  1043         if ( IS_RECEIVESTREAM( iLinkedStream ) )
       
  1044             {
       
  1045             //The bound stream is uplink
       
  1046             receiveStream = iLinkedStream;
       
  1047             }
       
  1048         }
       
  1049     else
       
  1050         {
       
  1051         //NOP
       
  1052         }
       
  1053         
       
  1054     return receiveStream;
       
  1055     
       
  1056     }
       
  1057 
       
  1058 
       
  1059 // -----------------------------------------------------------------------------
       
  1060 // CMceComMediaStream::OfferStream
       
  1061 // -----------------------------------------------------------------------------
       
  1062 //
       
  1063 CMceComMediaStream* CMceComMediaStream::OfferStream()
       
  1064     {
       
  1065     CMceComMediaStream* offerStream = NULL;
       
  1066     
       
  1067     offerStream = ReceiveStream();
       
  1068     if ( !offerStream )
       
  1069         {
       
  1070         //try send only
       
  1071         offerStream = SendStream();
       
  1072         __ASSERT_ALWAYS( !offerStream ||
       
  1073                          offerStream->iStreamType == ESendOnlyStream,
       
  1074                          User::Panic( KMceServerPanic, KErrGeneral ) );
       
  1075         }
       
  1076 
       
  1077     return offerStream;
       
  1078     
       
  1079     }
       
  1080 
       
  1081 
       
  1082 // -----------------------------------------------------------------------------
       
  1083 // CMceComMediaStream::AnswerStream
       
  1084 // -----------------------------------------------------------------------------
       
  1085 //
       
  1086 CMceComMediaStream* CMceComMediaStream::AnswerStream()
       
  1087     {
       
  1088     CMceComMediaStream* answerStream = NULL;
       
  1089     
       
  1090     answerStream = SendStream();
       
  1091     if ( !answerStream )
       
  1092         {
       
  1093         //try receive only
       
  1094         answerStream = ReceiveStream();
       
  1095         __ASSERT_ALWAYS( !answerStream ||
       
  1096                          answerStream->iStreamType == EReceiveOnlyStream,
       
  1097                          User::Panic( KMceServerPanic, KErrGeneral ) );
       
  1098         }
       
  1099 
       
  1100     return answerStream;
       
  1101     
       
  1102     }
       
  1103 
       
  1104 // -----------------------------------------------------------------------------
       
  1105 // CMceComMediaStream::SdpIndex
       
  1106 // -----------------------------------------------------------------------------
       
  1107 //
       
  1108 TInt& CMceComMediaStream::SdpIndex()
       
  1109     {
       
  1110     CMceComMediaStream& main = (*this)();
       
  1111 
       
  1112     return main.iSdpIndex;
       
  1113     
       
  1114     }
       
  1115     
       
  1116 // -----------------------------------------------------------------------------
       
  1117 // CMceComMediaStream::UseRtcp
       
  1118 // -----------------------------------------------------------------------------
       
  1119 //
       
  1120 TBool CMceComMediaStream::UseRtcp() const
       
  1121     {
       
  1122     TBool useRtcp = DoUseRtcp();
       
  1123     if ( useRtcp && BoundStream() )
       
  1124 	    {
       
  1125 	    useRtcp = iLinkedStream->DoUseRtcp();	
       
  1126 	    }
       
  1127     return useRtcp;
       
  1128     }
       
  1129 
       
  1130 // -----------------------------------------------------------------------------
       
  1131 // CMceComMediaStream::DoUseRtcp
       
  1132 // -----------------------------------------------------------------------------
       
  1133 //
       
  1134 TBool CMceComMediaStream::DoUseRtcp() const
       
  1135     {
       
  1136     TBool useRtcp( ETrue );
       
  1137     if ( iSource )
       
  1138         {
       
  1139         useRtcp = iSource->UseRTCP();
       
  1140         }
       
  1141     for( TInt i=0; i < iSinks.Count() && useRtcp; i++ )
       
  1142         {
       
  1143         useRtcp = iSinks[i]->UseRTCP();
       
  1144         }
       
  1145     return useRtcp;
       
  1146     }    
       
  1147     
       
  1148 #ifdef MCE_COMMON_SERVER_SIDE      
       
  1149 
       
  1150 // -----------------------------------------------------------------------------
       
  1151 // CMceComMediaStream::DecodedL
       
  1152 // -----------------------------------------------------------------------------
       
  1153 //
       
  1154 void CMceComMediaStream::DecodedL( TBool aRoleAnswerer )
       
  1155     {    
       
  1156     SynchronizeL( aRoleAnswerer );
       
  1157     
       
  1158     ReorderCodecs();
       
  1159         
       
  1160     if ( BoundStream() )
       
  1161         {
       
  1162         BoundStreamL().ReorderCodecs();
       
  1163         }
       
  1164     }
       
  1165 
       
  1166 
       
  1167 // -----------------------------------------------------------------------------
       
  1168 // CMceComMediaStream::EmptySinkL
       
  1169 // -----------------------------------------------------------------------------
       
  1170 //
       
  1171 CMceComMediaSink& CMceComMediaStream::EmptySinkL()
       
  1172     {
       
  1173     if ( !iEmptySink )
       
  1174         {
       
  1175         iEmptySink = CMceComMediaSink::NewL();
       
  1176         iEmptySink->InitializeL( *this );
       
  1177         }
       
  1178     return *iEmptySink;
       
  1179     }
       
  1180 
       
  1181 // -----------------------------------------------------------------------------
       
  1182 // CMceComMediaStream::EmptySourceL
       
  1183 // -----------------------------------------------------------------------------
       
  1184 //    
       
  1185 CMceComMediaSource& CMceComMediaStream::EmptySourceL()
       
  1186     {
       
  1187     if ( !iEmptySource )
       
  1188         {
       
  1189         iEmptySource = CMceComMediaSource::NewL();
       
  1190         iEmptySource->InitializeL( *this );
       
  1191         }
       
  1192     return *iEmptySource;
       
  1193     }
       
  1194 
       
  1195 // -----------------------------------------------------------------------------
       
  1196 // CMceComMediaStream::EventReceived
       
  1197 // -----------------------------------------------------------------------------
       
  1198 //
       
  1199 void CMceComMediaStream::EventReceived( TMceMccComEvent& aEvent )
       
  1200     {
       
  1201     
       
  1202     //TBD: handle situation where there are multiple codecs and sinks
       
  1203 //    if ( Codecs().Count() == 1 && Sinks().Count() == 1 )
       
  1204 //        {
       
  1205 
       
  1206         aEvent.iStream = this;
       
  1207                     
       
  1208         if ( aEvent.iSource )
       
  1209             {
       
  1210             aEvent.iSource->EventReceived( aEvent );
       
  1211             }
       
  1212         else if ( aEvent.iSink )
       
  1213             {
       
  1214             aEvent.iSink->EventReceived( aEvent );
       
  1215             }
       
  1216         //state event with endpointid 0
       
  1217         else 
       
  1218             {
       
  1219             if ( aEvent.iEvent == KMccStreamPaused ||
       
  1220                  aEvent.iEvent == KMccStreamResumed )
       
  1221                 {
       
  1222                 Source()->EventReceived( aEvent );
       
  1223                 for( TInt i = 0;i<Sinks().Count();i++)
       
  1224                     {
       
  1225                     Sinks()[i]->EventReceived( aEvent );
       
  1226                     }
       
  1227                 }
       
  1228             else
       
  1229                 {
       
  1230                 
       
  1231                 CMceComSession* session = Session();
       
  1232                 
       
  1233                 switch( aEvent.iEvent )
       
  1234                     {
       
  1235                     case KMccInactivityEvent:
       
  1236                         {
       
  1237                         aEvent.iItcEvent = EMceItcInactivityTimeout;
       
  1238                         aEvent.iItcData = iState;
       
  1239                         session->MediaObserver().EventReceived( aEvent );
       
  1240                         break;
       
  1241                         }
       
  1242                     case KMccStreamError:
       
  1243                         {
       
  1244                         aEvent.iItcEvent = EMceItcInProgress;
       
  1245                         aEvent.iItcData = iState;
       
  1246                         session->MediaObserver().MediaError( aEvent );
       
  1247                         break;
       
  1248                         }
       
  1249                     case KMccRtcpReceived:
       
  1250                         {
       
  1251                         aEvent.iItcEvent = EMceItcNotAssigned;
       
  1252                         switch( aEvent.iEventSubType )
       
  1253                             {
       
  1254                             case KRtcpSrPacket:
       
  1255                                 {
       
  1256                                 aEvent.iItcEvent = EMceItcSRReceived;
       
  1257                                 break;
       
  1258                                 }
       
  1259                             case KRtcpRrPacket:
       
  1260                                 {
       
  1261                                 aEvent.iItcEvent = EMceItcRRReceived;
       
  1262                                 break;
       
  1263                                 }
       
  1264                             case KRtcpPacketUndefined:
       
  1265                                 {
       
  1266                                 aEvent.iItcEvent = EMceItcFCMsgReceived;
       
  1267                                 break;
       
  1268                                 }
       
  1269                             default:
       
  1270                                 {
       
  1271                                 //NOP
       
  1272                                 break;
       
  1273                                 }
       
  1274                             
       
  1275                             }
       
  1276                         if ( aEvent.iItcEvent != EMceItcNotAssigned )
       
  1277                             {
       
  1278                             aEvent.iItcData = iState;
       
  1279                             session->MediaObserver().EventReceived( aEvent );
       
  1280                             }
       
  1281                         break;
       
  1282                         }
       
  1283                     case KMccStreamIdle:
       
  1284                     case KMccStreamPlaying:
       
  1285                     case KMccStreamStarted:
       
  1286                     case KMccStreamBuffering:
       
  1287                     case KMccStreamClosed:
       
  1288                     case KMccStreamStopped:
       
  1289                     case KMccResourceNotAvailable:
       
  1290                     case KMccActivityEvent:
       
  1291                     case KMccResourceReserved:
       
  1292                     case KMccResourceReleased:
       
  1293                         {
       
  1294                         aEvent.iItcEvent = EMceItcInProgress;
       
  1295                         aEvent.iItcData = iState;
       
  1296                         session->MediaObserver().EventReceived( aEvent );
       
  1297                         break;
       
  1298                         }
       
  1299                     case KMccLinkCreated:
       
  1300                         {
       
  1301                         aEvent.iItcEvent = EMceItcLinkCreated;
       
  1302                         aEvent.iItcData = LocalMediaPort();
       
  1303                         session->MediaObserver().EventReceived( aEvent );
       
  1304                         break;
       
  1305                         }
       
  1306                     default:
       
  1307                         {
       
  1308                         //NOP
       
  1309                         break;
       
  1310                         }
       
  1311                     }
       
  1312                 }
       
  1313             }
       
  1314             
       
  1315          //}
       
  1316         
       
  1317     }
       
  1318 
       
  1319 
       
  1320 // -----------------------------------------------------------------------------
       
  1321 // CMceComMediaStream::Merge
       
  1322 // -----------------------------------------------------------------------------
       
  1323 //
       
  1324 void CMceComMediaStream::Merge( CMceComMediaStream& aMergeWith )
       
  1325     {
       
  1326     iState = aMergeWith.iState;
       
  1327     }
       
  1328 
       
  1329 // -----------------------------------------------------------------------------
       
  1330 // CMceComMediaStream::SetState
       
  1331 // -----------------------------------------------------------------------------
       
  1332 //
       
  1333 void CMceComMediaStream::SetState( TMceMccComEvent& aEvent )
       
  1334     {
       
  1335     //update stream state
       
  1336     switch( aEvent.iEvent )
       
  1337         {
       
  1338         case KMccStreamResumed:
       
  1339         case KMccStreamPlaying:
       
  1340         case KMccStreamStarted:
       
  1341             {
       
  1342             iState = CMceMediaStream::EStreaming;
       
  1343             break;
       
  1344             }
       
  1345         case KMccStreamBuffering:
       
  1346             {
       
  1347             iState = CMceMediaStream::EBuffering;
       
  1348             break;
       
  1349             }
       
  1350         case KMccStreamIdle:
       
  1351             {
       
  1352             iState = CMceMediaStream::EIdle;
       
  1353             break;
       
  1354             }
       
  1355         case KMccStreamPaused:
       
  1356         case KMccStreamStopped:
       
  1357         case KMccStreamClosed:
       
  1358         case KMccStreamError:
       
  1359             {
       
  1360             iState = CMceMediaStream::EDisabled;
       
  1361             break;
       
  1362             }
       
  1363         case KMccResourceNotAvailable:
       
  1364             {
       
  1365             iState = CMceMediaStream::ENoResources;
       
  1366             break;
       
  1367             }
       
  1368         case KMccActivityEvent:
       
  1369             {
       
  1370             if ( iState == CMceMediaStream::EInitialized )
       
  1371                 {
       
  1372                 iState = CMceMediaStream::EIdle;
       
  1373                 }
       
  1374             break;
       
  1375             }
       
  1376         case KMccInactivityEvent:
       
  1377         case KMccResourceReserved:
       
  1378         case KMccResourceReleased:
       
  1379         case KMccRtcpReceived:
       
  1380         default:
       
  1381             {
       
  1382             //NOP
       
  1383             break;
       
  1384             }
       
  1385         }
       
  1386         
       
  1387     if ( aEvent.iSource )
       
  1388         {
       
  1389         aEvent.iSource->SetState( aEvent );
       
  1390         }
       
  1391     else if ( aEvent.iSink )
       
  1392         {
       
  1393         aEvent.iSink->SetState( aEvent );
       
  1394         }
       
  1395     else
       
  1396         {
       
  1397         // Codec state changes not used at the moment (enabled flag
       
  1398         // should not be switched by events).
       
  1399         //aEvent.iCodec->SetState( aEvent );
       
  1400         Source()->SetState( aEvent );
       
  1401         for( TInt i = 0;i<Sinks().Count();i++)
       
  1402             {
       
  1403             Sinks()[i]->SetState( aEvent );
       
  1404             }
       
  1405         }
       
  1406     }
       
  1407     
       
  1408 
       
  1409 // -----------------------------------------------------------------------------
       
  1410 // CMceComMediaStream::SetLinkId
       
  1411 // -----------------------------------------------------------------------------
       
  1412 //
       
  1413 void CMceComMediaStream::SetLinkId( TUint32 aLinkId )
       
  1414     {
       
  1415     
       
  1416     iLinkId = aLinkId;
       
  1417     
       
  1418     if ( BoundStream() )
       
  1419         {
       
  1420         iLinkedStream->iLinkId = aLinkId;
       
  1421         }
       
  1422         
       
  1423     }
       
  1424 
       
  1425 // -----------------------------------------------------------------------------
       
  1426 // CMceComMediaStream::Direction
       
  1427 // -----------------------------------------------------------------------------
       
  1428 //
       
  1429 TInt CMceComMediaStream::Direction()
       
  1430     {
       
  1431     TInt sdpType = SdpStreamType();
       
  1432     
       
  1433     switch( sdpType  )
       
  1434         {
       
  1435         case SdpCodecStringConstants::EAttributeSendrecv:
       
  1436             {
       
  1437             if ( !IsEnabled() && !iLinkedStream->IsEnabled() )
       
  1438                 {
       
  1439                 sdpType = SdpCodecStringConstants::EAttributeInactive;
       
  1440                 }
       
  1441             else if ( !IsEnabled() && iLinkedStream->IsEnabled() )
       
  1442                 {
       
  1443                 sdpType = iLinkedStream->iStreamType == EReceiveStream ? 
       
  1444                             SdpCodecStringConstants::EAttributeRecvonly :
       
  1445                             SdpCodecStringConstants::EAttributeSendonly;
       
  1446                 }
       
  1447             else if ( IsEnabled() && !iLinkedStream->IsEnabled() )
       
  1448                 {
       
  1449                 sdpType = iStreamType == EReceiveStream ? 
       
  1450                             SdpCodecStringConstants::EAttributeRecvonly :
       
  1451                             SdpCodecStringConstants::EAttributeSendonly;
       
  1452                 }
       
  1453             else 
       
  1454                 {
       
  1455                 //NOP
       
  1456                 }
       
  1457             break;
       
  1458             }
       
  1459         case SdpCodecStringConstants::EAttributeRecvonly: 
       
  1460         case SdpCodecStringConstants::EAttributeSendonly:
       
  1461             {
       
  1462             sdpType = IsEnabled() ? sdpType : SdpCodecStringConstants::EAttributeInactive;
       
  1463             break;
       
  1464             }
       
  1465         default:
       
  1466             {
       
  1467             break;
       
  1468             }
       
  1469     
       
  1470         }
       
  1471     
       
  1472     return sdpType;
       
  1473     }
       
  1474 
       
  1475 // -----------------------------------------------------------------------------
       
  1476 // CMceComMediaStream::SetDirectionL
       
  1477 // -----------------------------------------------------------------------------
       
  1478 //
       
  1479 void CMceComMediaStream::SetDirectionL( TInt aDirection )
       
  1480     {
       
  1481     TInt streamDirection = Direction();
       
  1482     TBool valid = aDirection == SdpCodecStringConstants::EAttributeInactive;
       
  1483 
       
  1484     if ( !valid )
       
  1485         {
       
  1486         if ( streamDirection == SdpCodecStringConstants::EAttributeRecvonly )
       
  1487             {
       
  1488             valid = aDirection == SdpCodecStringConstants::EAttributeSendonly;
       
  1489             }
       
  1490         else if ( streamDirection == SdpCodecStringConstants::EAttributeSendonly )
       
  1491             {
       
  1492             valid = aDirection == SdpCodecStringConstants::EAttributeRecvonly;
       
  1493             }
       
  1494         else
       
  1495             {
       
  1496             valid = ETrue;
       
  1497             }
       
  1498         }
       
  1499     
       
  1500     CMceSdpSession& sSession = Session()->SdpSession();       
       
  1501     if ( sSession.iOOldSchool == 0 &&  
       
  1502     	 !valid && 
       
  1503     	 ( Session()->Modifier( KMceMediaDirection ) == KMceMediaDirectionWithAddress ) )
       
  1504         {
       
  1505         sSession.iOOldSchool = 1;    
       
  1506 	    User::Leave( KMceErrOldSchool );
       
  1507         }
       
  1508         
       
  1509 	User::LeaveIfError( !valid ? KErrArgument : KErrNone );
       
  1510 		
       
  1511     SetDirection( aDirection, KMceNoEndpointAdjustment );
       
  1512         
       
  1513     }
       
  1514 
       
  1515 // -----------------------------------------------------------------------------
       
  1516 // CMceComMediaStream::DowngradedEndpoints
       
  1517 // -----------------------------------------------------------------------------
       
  1518 //
       
  1519 TBool& CMceComMediaStream::DowngradedEndpoints()
       
  1520     {
       
  1521     return iDowngradedEnpoints;
       
  1522     }
       
  1523 
       
  1524 // -----------------------------------------------------------------------------
       
  1525 // CMceComMediaStream::Enable
       
  1526 // -----------------------------------------------------------------------------
       
  1527 //
       
  1528 void CMceComMediaStream::Enable( TBool aEnable, TBool aEndpointAdjustment )
       
  1529     {
       
  1530     DowngradedEndpoints() = EFalse;
       
  1531     
       
  1532     iIsEnabled = aEnable;
       
  1533     if ( aEndpointAdjustment )
       
  1534         {
       
  1535         DowngradedEndpoints() = !aEnable;
       
  1536         if ( iSource )
       
  1537             {
       
  1538             iSource->Enabled( aEnable );
       
  1539             }
       
  1540         for( TInt i = 0;i<iSinks.Count();i++)
       
  1541             {
       
  1542             iSinks[ i ]->Enabled( aEnable );
       
  1543             }
       
  1544         }
       
  1545     }
       
  1546         
       
  1547 // -----------------------------------------------------------------------------
       
  1548 // CMceComMediaStream::SetDirection
       
  1549 // -----------------------------------------------------------------------------
       
  1550 //
       
  1551 void CMceComMediaStream::SetDirection( TInt aDirection, TBool aEndpointAdjustment )
       
  1552     { 
       
  1553 	if ( !aEndpointAdjustment && Direction() != aDirection &&
       
  1554 	     !(Direction() == SdpCodecStringConstants::EAttributeSendonly 
       
  1555 	       && aDirection == SdpCodecStringConstants::EAttributeRecvonly) &&
       
  1556 	     ! (Direction() == SdpCodecStringConstants::EAttributeRecvonly 
       
  1557 	       && aDirection == SdpCodecStringConstants::EAttributeSendonly) )//direction has changed
       
  1558 		{
       
  1559 		aEndpointAdjustment = KMceEndpointAdjustment;
       
  1560 		}
       
  1561    
       
  1562     switch( aDirection )
       
  1563         {
       
  1564         case SdpCodecStringConstants::EAttributeSendonly:
       
  1565             {
       
  1566             if ( iStreamType == EReceiveStream && 
       
  1567                  iLinkedStream->iStreamType == ESendStream )
       
  1568                 {
       
  1569                 Enable( ETrue, aEndpointAdjustment );
       
  1570                 iLinkedStream->Enable( EFalse, aEndpointAdjustment );
       
  1571                 }
       
  1572             else if ( iStreamType == ESendStream && 
       
  1573                       iLinkedStream->iStreamType == EReceiveStream )
       
  1574                 {
       
  1575                 Enable( EFalse, aEndpointAdjustment );
       
  1576                 iLinkedStream->Enable( ETrue, EFalse );
       
  1577                 }
       
  1578             else if ( iStreamType == ESendOnlyStream )
       
  1579                 {
       
  1580                 Enable( EFalse, aEndpointAdjustment );
       
  1581                 }
       
  1582             else if ( iStreamType == EReceiveOnlyStream )
       
  1583                 {
       
  1584                 Enable( ETrue, aEndpointAdjustment );
       
  1585                 }
       
  1586             break;
       
  1587             }
       
  1588         case SdpCodecStringConstants::EAttributeRecvonly:
       
  1589             {
       
  1590             if ( iStreamType == EReceiveStream && 
       
  1591                  iLinkedStream->iStreamType == ESendStream )
       
  1592                 {
       
  1593                 Enable( EFalse, aEndpointAdjustment );
       
  1594                 iLinkedStream->Enable( ETrue, aEndpointAdjustment );
       
  1595                 }
       
  1596             else if ( iStreamType == ESendStream && 
       
  1597                       iLinkedStream->iStreamType == EReceiveStream )
       
  1598                 {
       
  1599                 Enable( ETrue, EFalse );
       
  1600                 iLinkedStream->Enable( EFalse, aEndpointAdjustment );
       
  1601                 }
       
  1602             else if ( iStreamType == EReceiveOnlyStream )
       
  1603                 {
       
  1604                 Enable( EFalse, aEndpointAdjustment );
       
  1605                 }
       
  1606             else if ( iStreamType == ESendOnlyStream )
       
  1607                 {
       
  1608                 Enable( ETrue, aEndpointAdjustment );
       
  1609                 }
       
  1610             break;
       
  1611             }
       
  1612         case SdpCodecStringConstants::EAttributeSendrecv:
       
  1613         case KErrNotFound:
       
  1614             {
       
  1615             if ( !IsEnabled() && iLinkedStream && iLinkedStream->IsEnabled() )
       
  1616                 {
       
  1617                 iLinkedStream->Enable( ETrue, EFalse );
       
  1618                 Enable( ETrue, aEndpointAdjustment ); 
       
  1619                 }
       
  1620             else if ( IsEnabled() && iLinkedStream && !iLinkedStream->IsEnabled() )
       
  1621                 {
       
  1622                 Enable( ETrue, EFalse ); 
       
  1623                 iLinkedStream->Enable( ETrue, aEndpointAdjustment ); 
       
  1624                 }
       
  1625             else if ( !IsEnabled() && iLinkedStream && !iLinkedStream->IsEnabled() ) 
       
  1626                 {
       
  1627                 Enable( ETrue, aEndpointAdjustment );   
       
  1628                 iLinkedStream->Enable( ETrue, aEndpointAdjustment );   
       
  1629                 }
       
  1630             else if ( !iLinkedStream )
       
  1631                 {
       
  1632                 Enable( ETrue, EFalse ); 
       
  1633                 }
       
  1634             else
       
  1635                 {
       
  1636                 iLinkedStream->Enable( ETrue, EFalse );
       
  1637                 Enable( ETrue, EFalse );    
       
  1638                 }
       
  1639             
       
  1640             break;
       
  1641             }
       
  1642         case SdpCodecStringConstants::EAttributeInactive:
       
  1643             {
       
  1644             Enable( EFalse, KMceEndpointAdjustment );
       
  1645             if ( iLinkedStream )
       
  1646                 {
       
  1647                 iLinkedStream->Enable( EFalse, KMceEndpointAdjustment );
       
  1648                 }
       
  1649             break;
       
  1650             }
       
  1651         default:
       
  1652             {
       
  1653             //NOP
       
  1654             break;
       
  1655             }
       
  1656         }
       
  1657     }
       
  1658     
       
  1659     
       
  1660 // -----------------------------------------------------------------------------
       
  1661 // CMceComMediaStream::SdpStreamType
       
  1662 // -----------------------------------------------------------------------------
       
  1663 //
       
  1664 TInt CMceComMediaStream::SdpStreamType()
       
  1665     {
       
  1666     TInt sdpType = KErrNotFound;
       
  1667     
       
  1668     switch( iStreamType  )
       
  1669         {
       
  1670         case EReceiveStream:
       
  1671         case ESendStream:
       
  1672             {
       
  1673             sdpType = SdpCodecStringConstants::EAttributeSendrecv;
       
  1674             break;
       
  1675             }
       
  1676         case EReceiveOnlyStream: 
       
  1677             {
       
  1678             sdpType = SdpCodecStringConstants::EAttributeRecvonly;
       
  1679             break;
       
  1680             }
       
  1681         case ESendOnlyStream:
       
  1682             {
       
  1683             sdpType = SdpCodecStringConstants::EAttributeSendonly;
       
  1684             break;
       
  1685             }
       
  1686         default:
       
  1687             {
       
  1688             break;
       
  1689             }
       
  1690     
       
  1691         }
       
  1692     
       
  1693     return sdpType;
       
  1694     
       
  1695     }
       
  1696 
       
  1697 
       
  1698 // -----------------------------------------------------------------------------
       
  1699 // CMceComMediaStream::PreconditionsL
       
  1700 // -----------------------------------------------------------------------------
       
  1701 //
       
  1702 TMcePreconditions* CMceComMediaStream::PreconditionsL( TMceSessionModifier aModifier,
       
  1703 														CSdpMediaField* aMediaLine )
       
  1704     {
       
  1705     CMceComMediaStream& main = (*this)();
       
  1706     TInt count = main.iPreconditions.Count();
       
  1707     TMcePreconditions* precondition = NULL;
       
  1708     
       
  1709     for ( TInt n = 0; n < count; n++ )
       
  1710  		{
       
  1711  		TMcePreconditions* search = main.iPreconditions[ n ];
       
  1712  		if ( aModifier == KMceSecPreconditions &&
       
  1713  		search->Type() == TMcePreconditions :: ESecPreconds )
       
  1714  			{
       
  1715  			precondition = search;
       
  1716  			}
       
  1717  		if ( aModifier == KMcePreconditions &&
       
  1718  		search->Type() == TMcePreconditions :: EQosPreconds )
       
  1719  			{
       
  1720  			precondition = search;
       
  1721  			}
       
  1722  		}
       
  1723     
       
  1724     if ( !precondition ) 
       
  1725     	{
       
  1726     	
       
  1727     	TMcePreconditionsFactory factory;	
       
  1728         
       
  1729         if ( aModifier == KMceSecPreconditions ) 
       
  1730         	{
       
  1731         	//only create sec precondition 
       
  1732         	precondition = factory.CreateL( *this, *aMediaLine );
       
  1733         	}
       
  1734 		else
       
  1735 			{
       
  1736 			//create qos precondition
       
  1737         	precondition = factory.CreateL( *this );
       
  1738 			}
       
  1739 			
       
  1740 	    if ( precondition )
       
  1741 	    	{
       
  1742 	    	CleanupStack::PushL( precondition );
       
  1743         	main.iPreconditions.AppendL( precondition );
       
  1744 	    	CleanupStack::Pop( precondition );
       
  1745 	    	}
       
  1746 	   
       
  1747         }
       
  1748     
       
  1749         
       
  1750     
       
  1751     return precondition;
       
  1752     
       
  1753     }
       
  1754 
       
  1755 
       
  1756 // -----------------------------------------------------------------------------
       
  1757 // CMceComMediaStream::Preconditions
       
  1758 // -----------------------------------------------------------------------------
       
  1759 //
       
  1760 const RPointerArray<TMcePreconditions>& CMceComMediaStream::Preconditions() const
       
  1761     {
       
  1762     
       
  1763     const CMceComMediaStream& main = (*this)();
       
  1764     return main.iPreconditions;
       
  1765     }
       
  1766 
       
  1767 
       
  1768     
       
  1769 #endif//MCE_COMMON_SERVER_SIDE
       
  1770