multimediacommsengine/mmcecli/src/mcestreambundle.cpp
changeset 0 1bce908db942
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 "mcestreambundle.h"
       
    22 #include "mcesession.h"
       
    23 #include "mcecomstreambundle.h"
       
    24 #include "mcefactory.h"
       
    25 #include "mceserial.h"
       
    26 #include "mceendpointproxy.h"
       
    27 
       
    28 #define _FLAT_DATA static_cast<CMceComStreamBundle*>( iFlatData )
       
    29 #define FLAT_DATA( data ) _FLAT_DATA->data
       
    30 
       
    31 // ============================ MEMBER FUNCTIONS ===============================
       
    32 
       
    33 // -----------------------------------------------------------------------------
       
    34 // CMceStreamBundle::NewL
       
    35 // -----------------------------------------------------------------------------
       
    36 //
       
    37 EXPORT_C CMceStreamBundle* CMceStreamBundle::NewL( TMceStreamBundleType aType )
       
    38     {
       
    39     CMceStreamBundle* self = NewLC( aType );
       
    40     CleanupStack::Pop( self );
       
    41     return self;   
       
    42     
       
    43     }
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 // CMceStreamBundle::NewLC
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 EXPORT_C CMceStreamBundle* CMceStreamBundle::NewLC( TMceStreamBundleType aType )
       
    50     {
       
    51     CMceStreamBundle* self = new (ELeave) CMceStreamBundle();
       
    52     CleanupStack::PushL( self );
       
    53     self->ConstructL( aType );
       
    54     return self;
       
    55     }
       
    56      
       
    57 // -----------------------------------------------------------------------------
       
    58 // CMceStreamBundle::~CMceStreamBundle
       
    59 // -----------------------------------------------------------------------------
       
    60 //
       
    61 EXPORT_C CMceStreamBundle::~CMceStreamBundle()
       
    62     {
       
    63     delete iFlatData;
       
    64     iStreams.Close();
       
    65     iTempStreams.Close();
       
    66     }
       
    67 
       
    68 // -----------------------------------------------------------------------------
       
    69 // CMceStreamBundle::Type
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 EXPORT_C CMceStreamBundle::TMceStreamBundleType CMceStreamBundle::Type() const
       
    73     {
       
    74     return FLAT_DATA( Type() );
       
    75     }
       
    76     
       
    77 // -----------------------------------------------------------------------------
       
    78 // CMceStreamBundle::AddStreamL
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 EXPORT_C void CMceStreamBundle::AddStreamL( CMceMediaStream& aStream )
       
    82     {
       
    83     iStreams.AppendL( &aStream );
       
    84     }
       
    85         
       
    86 // -----------------------------------------------------------------------------
       
    87 // CMceStreamBundle::RemoveStreamL
       
    88 // -----------------------------------------------------------------------------
       
    89 //
       
    90 EXPORT_C void CMceStreamBundle::RemoveStreamL( CMceMediaStream& aStream )
       
    91     {
       
    92     TInt index = iStreams.Find( &aStream );
       
    93     User::LeaveIfError( index );
       
    94     iStreams.Remove( index );
       
    95     }
       
    96         
       
    97 // -----------------------------------------------------------------------------
       
    98 // CMceStreamBundle::Streams
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 EXPORT_C const RPointerArray< CMceMediaStream >& CMceStreamBundle::Streams()
       
   102     {
       
   103     return iStreams;
       
   104     }
       
   105      
       
   106 // -----------------------------------------------------------------------------
       
   107 // CMceStreamBundle::SerializationId
       
   108 // -----------------------------------------------------------------------------
       
   109 //
       
   110 TUint64 CMceStreamBundle::SerializationId() const
       
   111     {
       
   112     return FLAT_DATA( SerializationId() );
       
   113     }
       
   114      
       
   115 // -----------------------------------------------------------------------------
       
   116 // CMceStreamBundle::InternalizeFlatL
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 void CMceStreamBundle::InternalizeFlatL( RReadStream& aReadStream )
       
   120     {
       
   121     __ASSERT_ALWAYS( iFlatData , User::Leave( KErrNotReady ) );
       
   122     _FLAT_DATA->InternalizeFlatL( aReadStream );
       
   123     
       
   124     }
       
   125 
       
   126 // -----------------------------------------------------------------------------
       
   127 // CMceStreamBundle::ExternalizeFlatL
       
   128 // -----------------------------------------------------------------------------
       
   129 //
       
   130 void CMceStreamBundle::ExternalizeFlatL( RWriteStream& aWriteStream )
       
   131     {
       
   132     __ASSERT_ALWAYS( iFlatData , User::Leave( KErrNotReady ) );
       
   133     _FLAT_DATA->ExternalizeFlatL( aWriteStream );
       
   134     }
       
   135      
       
   136 
       
   137 // -----------------------------------------------------------------------------
       
   138 // CMceStreamBundle::InternalizeL
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 void CMceStreamBundle::InternalizeL( MMceComSerializationContext& aSerCtx )
       
   142     {
       
   143     __ASSERT_ALWAYS( iSession, User::Leave( KErrArgument ) );
       
   144     
       
   145     RReadStream& readStream = aSerCtx.ReadStream();
       
   146 
       
   147     InternalizeFlatL( readStream );
       
   148 
       
   149     TUint32 i = 0;
       
   150     TInt j = 0;
       
   151     TMceMediaId streamId;
       
   152 
       
   153     TUint32 streamCount = readStream.ReadUint32L();
       
   154     for( i = 0; i<streamCount; i++)
       
   155         {
       
   156         MceSerial::DecodeL( streamId, readStream );
       
   157         for( j = 0; j < iSession->Streams().Count();j++ )
       
   158             {
       
   159             CMceMediaStream* stream = iSession->Streams()[ j ];
       
   160             if ( stream->Id() == streamId )
       
   161                 {
       
   162                 AddStreamL( *stream );
       
   163                 }
       
   164             }
       
   165         }
       
   166 
       
   167     }
       
   168 
       
   169 // -----------------------------------------------------------------------------
       
   170 // CMceStreamBundle::ExternalizeL
       
   171 // -----------------------------------------------------------------------------
       
   172 //
       
   173 void CMceStreamBundle::ExternalizeL( MMceComSerializationContext& aSerCtx )
       
   174     {
       
   175     RWriteStream& writeStream = aSerCtx.WriteStream();
       
   176     
       
   177     ExternalizeFlatL( writeStream );
       
   178     
       
   179 	writeStream.WriteUint32L( iStreams.Count() );
       
   180 	for( TInt i = 0;i<iStreams.Count();i++)
       
   181 	    {
       
   182         MceSerial::EncodeL( iStreams[ i ]->Id(), writeStream );
       
   183     	}
       
   184 
       
   185     }
       
   186         
       
   187 
       
   188 // -----------------------------------------------------------------------------
       
   189 // CMceStreamBundle::AddedL
       
   190 // -----------------------------------------------------------------------------
       
   191 //
       
   192 void CMceStreamBundle::AddedL()
       
   193     {
       
   194     MMceEndPointProxy* proxy = NULL;
       
   195     CMceMediaSink* endpoint = NULL;
       
   196     TInt i = 0;
       
   197 
       
   198     //sinks
       
   199     for( i = 0; i< iStreams.Count(); i++ )
       
   200         {
       
   201         
       
   202         CMceMediaStream* stream = iStreams[ i ];
       
   203         AddedSinkL( *stream, endpoint, proxy );
       
   204         if ( stream->BoundStream() )
       
   205             {
       
   206             AddedSinkL( stream->BoundStreamL(), endpoint, proxy );
       
   207             }
       
   208         }
       
   209 
       
   210     }
       
   211 
       
   212 
       
   213 // -----------------------------------------------------------------------------
       
   214 // CMceStreamBundle::AddedSinkL
       
   215 // -----------------------------------------------------------------------------
       
   216 //
       
   217 void CMceStreamBundle::AddedSinkL( CMceMediaStream& aStream,
       
   218                                    CMceMediaSink*& aCurrentSink,
       
   219                                    MMceEndPointProxy*& aProxy )
       
   220 
       
   221     {
       
   222     
       
   223     for( TInt j=0; j < aStream.Sinks().Count(); j++ )
       
   224         {
       
   225         aProxy = aCurrentSink ? aCurrentSink->EndpointProxy() : aProxy;
       
   226         aCurrentSink = aStream.Sinks()[ j ];
       
   227         aCurrentSink->SetupEndpointProxyL( aProxy );
       
   228         }
       
   229     }
       
   230 
       
   231  
       
   232  
       
   233 // -----------------------------------------------------------------------------
       
   234 // CMceStreamBundle::InitializeL
       
   235 // -----------------------------------------------------------------------------
       
   236 //
       
   237 void CMceStreamBundle::InitializeL( CMceSession& aParent )
       
   238     {
       
   239     iSession = &aParent;
       
   240     }
       
   241     
       
   242 // -----------------------------------------------------------------------------
       
   243 // CMceStreamBundle::CMceStreamBundle
       
   244 // -----------------------------------------------------------------------------
       
   245 //
       
   246 CMceStreamBundle::CMceStreamBundle()
       
   247     {
       
   248     }
       
   249 
       
   250 // -----------------------------------------------------------------------------
       
   251 // CMceStreamBundle::ConstructL
       
   252 // -----------------------------------------------------------------------------
       
   253 //
       
   254 void CMceStreamBundle::ConstructL( CMceStreamBundle::TMceStreamBundleType aType )
       
   255     {
       
   256     
       
   257     iFlatData = CMceComStreamBundle::NewL( aType );
       
   258     
       
   259     }
       
   260