mmsharing/mmshengine/tsrc/ut_engine/src/ut_musengclipsession.cpp
changeset 0 f0cf47e981f9
child 18 0da2e08216b6
equal deleted inserted replaced
-1:000000000000 0:f0cf47e981f9
       
     1 /*
       
     2 * Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 //  INTERNAL INCLUDES
       
    20 #include "ut_musengClipsession.h"
       
    21 #include "musengstubs.h"
       
    22 #include "musengtestdefs.h"
       
    23 #include "musengclipsession.h"
       
    24 #include "mussipprofilehandler.h"
       
    25 #include "musengmceutils.h"
       
    26 
       
    27 
       
    28 //  SYSTEM INCLUDES
       
    29 #include <digia/eunit/eunitmacros.h>
       
    30 #include <mceoutsession.h>
       
    31 #include <mcestreambundle.h>
       
    32 #include <mcevideostream.h>
       
    33 #include <mceaudiostream.h>
       
    34 #include <mcefilesource.h>
       
    35 #include <mcertpsink.h>
       
    36 #include <mcedisplaysink.h>
       
    37 #include <mcespeakersink.h>
       
    38 #include <mcertpsource.h>
       
    39 #include <mcevideocodec.h>
       
    40 #include <mceamrcodec.h>
       
    41 #include <drmcommon.h>
       
    42 #include <sipprofile.h>
       
    43 #include <sipstrings.h>
       
    44 
       
    45 
       
    46 // -----------------------------------------------------------------------------
       
    47 //
       
    48 // -----------------------------------------------------------------------------
       
    49 //
       
    50 UT_CMusEngClipSession* UT_CMusEngClipSession::NewL()
       
    51     {
       
    52     UT_CMusEngClipSession* self = UT_CMusEngClipSession::NewLC();
       
    53     CleanupStack::Pop( self );
       
    54     return self;
       
    55     }
       
    56 
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 //
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 UT_CMusEngClipSession* UT_CMusEngClipSession::NewLC()
       
    63     {
       
    64     UT_CMusEngClipSession* self = new( ELeave ) UT_CMusEngClipSession();
       
    65     CleanupStack::PushL( self );
       
    66     self->ConstructL();
       
    67     return self;
       
    68     }
       
    69 
       
    70 
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 // -----------------------------------------------------------------------------
       
    74 //
       
    75 UT_CMusEngClipSession::~UT_CMusEngClipSession()
       
    76     {
       
    77     // NOP
       
    78     }
       
    79 
       
    80 
       
    81 // -----------------------------------------------------------------------------
       
    82 // Default constructor
       
    83 // -----------------------------------------------------------------------------
       
    84 //
       
    85 UT_CMusEngClipSession::UT_CMusEngClipSession()
       
    86     {
       
    87     // NOP
       
    88     }
       
    89 
       
    90 
       
    91 // -----------------------------------------------------------------------------
       
    92 // Second phase construct
       
    93 // -----------------------------------------------------------------------------
       
    94 //
       
    95 void UT_CMusEngClipSession::ConstructL()
       
    96     {
       
    97     // The ConstructL from the base class CEUnitTestSuiteClass must be called.
       
    98     // It generates the test case table.
       
    99     CEUnitTestSuiteClass::ConstructL();
       
   100     }
       
   101     
       
   102 
       
   103 // -----------------------------------------------------------------------------
       
   104 //
       
   105 // -----------------------------------------------------------------------------
       
   106 //
       
   107 void UT_CMusEngClipSession::SetupL()
       
   108     {
       
   109     iObserver = new( ELeave ) CMusEngObserverStub;
       
   110     iClipSession = CMusEngClipSession::NewL( TRect(0,0, 100,100),
       
   111                                              *iObserver,
       
   112                                              *iObserver,
       
   113                                              *iObserver );
       
   114     iClipSession->SetClipL( KTestVideoFileName );
       
   115     iClipSession->iVideoCodecList = KMceSDPNameH264().AllocL();
       
   116 
       
   117     SIPStrings::OpenL();
       
   118     }
       
   119 
       
   120 // -----------------------------------------------------------------------------
       
   121 //
       
   122 // -----------------------------------------------------------------------------
       
   123 //
       
   124 void UT_CMusEngClipSession::Setup2L()
       
   125     {
       
   126     iObserver = new( ELeave ) CMusEngObserverStub;
       
   127     iClipSession = CMusEngClipSession::NewL( TRect(0,0, 100,100),
       
   128                                              *iObserver,
       
   129                                              *iObserver,
       
   130                                              *iObserver );
       
   131     iClipSession->SetClipL( KTestVideoFileName );
       
   132     iClipSession->iVideoCodecList = KMceSDPNameH263().AllocL();
       
   133 
       
   134     SIPStrings::OpenL();
       
   135     }
       
   136     
       
   137 // -----------------------------------------------------------------------------
       
   138 //
       
   139 // -----------------------------------------------------------------------------
       
   140 //
       
   141 void UT_CMusEngClipSession::Teardown()
       
   142     {
       
   143     SIPStrings::Close();
       
   144     delete iClipSession;
       
   145     delete iObserver;
       
   146     }
       
   147 
       
   148 
       
   149 
       
   150 // TEST CASES
       
   151 
       
   152 
       
   153 // -----------------------------------------------------------------------------
       
   154 //
       
   155 // -----------------------------------------------------------------------------
       
   156 //
       
   157 void UT_CMusEngClipSession::UT_NewLL()
       
   158     {
       
   159     EUNIT_ASSERT( iClipSession )
       
   160     EUNIT_ASSERT( iClipSession->iFileName != KNullDesC() )
       
   161     EUNIT_ASSERT( !iClipSession->iSession )
       
   162     }
       
   163 
       
   164 
       
   165 // -----------------------------------------------------------------------------
       
   166 //
       
   167 // -----------------------------------------------------------------------------
       
   168 //
       
   169 void UT_CMusEngClipSession::UT_SetClipLL()
       
   170     {
       
   171     // Try with protected file, cannot use EUNIT_ASSERT_SPECIFIC_LEAVE
       
   172     TRAPD( error, iClipSession->SetClipL( KMusDrmProtectedFileName() ) )
       
   173     MUS_TEST_FORWARD_ALLOC_FAILURE( error );
       
   174     EUNIT_ASSERT( error == KErrPermissionDenied )
       
   175     EUNIT_ASSERT_EQUALS( iClipSession->iFileName, KTestVideoFileName() )
       
   176 
       
   177     // Change the file before session is established
       
   178     iClipSession->SetClipL( KTestAvcVideoFileName() );
       
   179     EUNIT_ASSERT_EQUALS( iClipSession->iFileName, KTestAvcVideoFileName() )
       
   180     EUNIT_ASSERT( !iClipSession->iSession )
       
   181     
       
   182     // simulate session establishment
       
   183     ESTABLISH_OUT_SESSION( iClipSession );
       
   184     
       
   185     // Now test with established session
       
   186     iClipSession->SetClipL( KTestVideoFileName() );
       
   187     
       
   188     CMceFileSource* file = 
       
   189                     MusEngMceUtils::GetFileSourceL( *iClipSession->iSession );
       
   190     
       
   191     EUNIT_ASSERT_EQUALS( iClipSession->iFileName, KTestVideoFileName() )
       
   192     EUNIT_ASSERT_EQUALS( file->iFileName, KTestVideoFileName() )
       
   193     
       
   194     
       
   195     }
       
   196 
       
   197 
       
   198 // -----------------------------------------------------------------------------
       
   199 //
       
   200 // -----------------------------------------------------------------------------
       
   201 //
       
   202 void UT_CMusEngClipSession::UT_FastForwardLL()
       
   203     {
       
   204     // Try before establishment
       
   205     EUNIT_ASSERT_SPECIFIC_LEAVE( iClipSession->FastForwardL( ETrue ),
       
   206                                  KErrNotReady )
       
   207     
       
   208     // Establish session, simulate position and duration and try again   
       
   209     ESTABLISH_OUT_SESSION( iClipSession );
       
   210     
       
   211     CMceFileSource* file = 
       
   212                     MusEngMceUtils::GetFileSourceL( *iClipSession->iSession );
       
   213                     
       
   214     file->iDuration = KMusEngTestFileDuration;
       
   215     file->iPosition = KMusEngTestFilePosition; 
       
   216     
       
   217     iClipSession->FastForwardL( ETrue );
       
   218 
       
   219     EUNIT_ASSERT( !file->iIsEnabled )
       
   220     EUNIT_ASSERT( iClipSession->iFFWDStartTime.Int64() > 0 )
       
   221     EUNIT_ASSERT( iClipSession->iFRWDStartTime.Int64() == 0 )
       
   222     
       
   223     // Simulate fastforwarding for a while
       
   224     User::After( 1000 );
       
   225 
       
   226     // Try to fastforward when already fastforwarding, will be ignored
       
   227     iClipSession->FastForwardL( ETrue );
       
   228     EUNIT_ASSERT( !file->iIsEnabled )
       
   229     EUNIT_ASSERT( iClipSession->iFFWDStartTime.Int64() > 0 )
       
   230     EUNIT_ASSERT( iClipSession->iFRWDStartTime.Int64() == 0 )
       
   231     
       
   232     // Stop fastforwarding
       
   233     iClipSession->FastForwardL( EFalse );
       
   234     EUNIT_ASSERT( file->iPosition > KMusEngTestFilePosition )
       
   235     EUNIT_ASSERT( file->iPosition != file->iDuration )
       
   236     EUNIT_ASSERT( !file->iIsEnabled )
       
   237     EUNIT_ASSERT( iClipSession->iFFWDStartTime.Int64() == 0 )
       
   238     EUNIT_ASSERT( iClipSession->iFRWDStartTime.Int64() == 0 )
       
   239     
       
   240     // Try to stop fastforwarding again, leaves 
       
   241     EUNIT_ASSERT_SPECIFIC_LEAVE( iClipSession->FastForwardL( EFalse ),
       
   242                                  KErrAlreadyExists )
       
   243     
       
   244     // Start fastrewinding
       
   245     iClipSession->FastRewindL( ETrue );
       
   246     EUNIT_ASSERT( !file->iIsEnabled )
       
   247     EUNIT_ASSERT( iClipSession->iFFWDStartTime.Int64() == 0 )
       
   248     EUNIT_ASSERT( iClipSession->iFRWDStartTime.Int64() > 0 )
       
   249     
       
   250     // Start fastforwarding, rewinding should be stopped and FFWD started
       
   251     iClipSession->FastForwardL( ETrue );
       
   252     EUNIT_ASSERT( !file->iIsEnabled )
       
   253     EUNIT_ASSERT( iClipSession->iFFWDStartTime.Int64() > 0 )
       
   254     EUNIT_ASSERT( iClipSession->iFRWDStartTime.Int64() == 0 )
       
   255     
       
   256     // Simulate fastforwarding for a while
       
   257     User::After( 1000 );
       
   258     
       
   259     // Simulate that clip is almost in end and fastforwarding would have 
       
   260     // continued over end, position should be set to duration.
       
   261     
       
   262     file->iPosition = TTimeIntervalMicroSeconds( file->iDuration.Int64() - 1 );
       
   263     
       
   264     iClipSession->FastForwardL( EFalse );
       
   265     EUNIT_ASSERT( file->iPosition == file->iDuration )
       
   266     EUNIT_ASSERT( !file->iIsEnabled )
       
   267     EUNIT_ASSERT( iClipSession->iFFWDStartTime.Int64() == 0 )
       
   268     EUNIT_ASSERT( iClipSession->iFRWDStartTime.Int64() == 0 )
       
   269     
       
   270     }
       
   271 
       
   272 
       
   273 // -----------------------------------------------------------------------------
       
   274 //
       
   275 // -----------------------------------------------------------------------------
       
   276 //
       
   277 void UT_CMusEngClipSession::UT_FastRewindLL()
       
   278     {
       
   279     // Try before establishment
       
   280     EUNIT_ASSERT_SPECIFIC_LEAVE( iClipSession->FastRewindL( ETrue ),
       
   281                                  KErrNotReady )
       
   282     
       
   283     // Establish session, simulate position and duration and try again   
       
   284     ESTABLISH_OUT_SESSION( iClipSession );
       
   285     
       
   286     CMceFileSource* file = 
       
   287                     MusEngMceUtils::GetFileSourceL( *iClipSession->iSession );
       
   288                     
       
   289     file->iDuration = KMusEngTestFileDuration;
       
   290     file->iPosition = KMusEngTestFilePosition; 
       
   291     
       
   292     iClipSession->FastRewindL( ETrue );
       
   293 
       
   294     EUNIT_ASSERT( !file->iIsEnabled )
       
   295     EUNIT_ASSERT( iClipSession->iFFWDStartTime.Int64() == 0 )
       
   296     EUNIT_ASSERT( iClipSession->iFRWDStartTime.Int64() > 0 )
       
   297     
       
   298     // Simulate fastrewinding for a while
       
   299     User::After( 1000 );
       
   300     
       
   301     // Try to fastrewind when already fastrewinding, will be ignored
       
   302     iClipSession->FastRewindL( ETrue );
       
   303     EUNIT_ASSERT( !file->iIsEnabled )
       
   304     EUNIT_ASSERT( iClipSession->iFFWDStartTime.Int64() == 0 )
       
   305     EUNIT_ASSERT( iClipSession->iFRWDStartTime.Int64() > 0 )
       
   306     
       
   307     // Stop fastrewinding
       
   308     iClipSession->FastRewindL( EFalse );
       
   309     EUNIT_ASSERT( file->iPosition < KMusEngTestFilePosition )
       
   310     EUNIT_ASSERT( file->iPosition != TTimeIntervalMicroSeconds( 0 ) )
       
   311     EUNIT_ASSERT( !file->iIsEnabled )
       
   312     EUNIT_ASSERT( iClipSession->iFFWDStartTime.Int64() == 0 )
       
   313     EUNIT_ASSERT( iClipSession->iFRWDStartTime.Int64() == 0 )
       
   314     
       
   315     // Try to stop fastrewinding again, leaves 
       
   316     EUNIT_ASSERT_SPECIFIC_LEAVE( iClipSession->FastRewindL( EFalse ),
       
   317                                  KErrAlreadyExists )
       
   318     
       
   319     // Start fastforwarding
       
   320     iClipSession->FastForwardL( ETrue );
       
   321     EUNIT_ASSERT( !file->iIsEnabled )
       
   322     EUNIT_ASSERT( iClipSession->iFFWDStartTime.Int64() >= 0 )
       
   323     EUNIT_ASSERT( iClipSession->iFRWDStartTime.Int64() == 0 )
       
   324     
       
   325     // Start fastrewinding, forwarding should be stopped and FFWD started
       
   326     iClipSession->FastRewindL( ETrue );
       
   327     EUNIT_ASSERT( !file->iIsEnabled );
       
   328     EUNIT_ASSERT( iClipSession->iFFWDStartTime.Int64() == 0 )
       
   329     EUNIT_ASSERT( iClipSession->iFRWDStartTime.Int64() >= 0 )
       
   330     
       
   331     // Simulate that clip has just begun and fastrewinding would have 
       
   332     // continued over beginning, position should be set to zero.
       
   333     
       
   334     file->iPosition = TTimeIntervalMicroSeconds( 1 );
       
   335     
       
   336     // Simulate fastrewinding for a while
       
   337     User::After( 1000 );
       
   338     
       
   339     iClipSession->FastRewindL( EFalse );
       
   340     EUNIT_ASSERT( file->iPosition == TTimeIntervalMicroSeconds( 0 ) )
       
   341     EUNIT_ASSERT( !file->iIsEnabled )
       
   342     EUNIT_ASSERT( iClipSession->iFFWDStartTime.Int64() == 0 )
       
   343     EUNIT_ASSERT( iClipSession->iFRWDStartTime.Int64() == 0 ) 
       
   344     }
       
   345 
       
   346 
       
   347 // -----------------------------------------------------------------------------
       
   348 //
       
   349 // -----------------------------------------------------------------------------
       
   350 //
       
   351 void UT_CMusEngClipSession::UT_PositionLL()
       
   352     {
       
   353     // Try before establishment
       
   354     EUNIT_ASSERT_SPECIFIC_LEAVE( iClipSession->PositionL(), KErrNotReady )
       
   355     
       
   356     // Establish session and try again
       
   357     ESTABLISH_OUT_SESSION( iClipSession );
       
   358     
       
   359     CMceFileSource* file = 
       
   360                     MusEngMceUtils::GetFileSourceL( *iClipSession->iSession );
       
   361     file->iPosition = 2000000;
       
   362     
       
   363     EUNIT_ASSERT( iClipSession->PositionL().Int() * 1000000 == 
       
   364                   file->iPosition.Int64() )
       
   365     
       
   366     // Ask position while fastforwarding, it should be bigger than real position
       
   367     iClipSession->FastForwardL( ETrue );
       
   368     
       
   369     User::After( 1000000 ); // We have to wait since dividing in PositionL and 
       
   370                             // multiplying before comparison loses difference 
       
   371     
       
   372     EUNIT_ASSERT( iClipSession->PositionL().Int() * 1000000 >
       
   373                   file->iPosition.Int64() )
       
   374     
       
   375     // Ask position while fastforwarding beyond end of clip, clip duration is
       
   376     // returned
       
   377     file->iPosition = file->iDuration;
       
   378     
       
   379     EUNIT_ASSERT( iClipSession->PositionL().Int() * 1000000 ==
       
   380                   file->iDuration.Int64() )
       
   381     
       
   382     // Stop fastforwarding, start fastrewinding, position is set to the end clip
       
   383     iClipSession->FastForwardL( EFalse );
       
   384     iClipSession->FastRewindL( ETrue );
       
   385     
       
   386     User::After( 1000000 ); // We have to wait since dividing in PositionL and 
       
   387                             // multiplying before comparison loses difference 
       
   388     
       
   389     // Ask position while fastrewinding, it should be smaller than real 
       
   390     // position
       
   391     EUNIT_ASSERT( iClipSession->PositionL().Int() * 1000000 <
       
   392                   file->iPosition.Int64() )
       
   393     
       
   394     // Ask position while fastrewinding beyond the beginning of clip, zero 
       
   395     // returned
       
   396     file->iPosition = 0;
       
   397     
       
   398     EUNIT_ASSERT( iClipSession->PositionL().Int() * 1000000 == 0 )
       
   399     
       
   400     // Asking position when rewinded to beginning but rewinding has ended 
       
   401     // and clip has not ended (position should not be altered in that case)
       
   402     iClipSession->iRewindedToBeginning = ETrue;
       
   403     file->iPosition = 0;
       
   404     iClipSession->iFRWDStartTime = TTime( 0 );
       
   405     
       
   406     EUNIT_ASSERT( iClipSession->PositionL().Int() * 1000000 == 0 )
       
   407     
       
   408     // Position has proceeded from beginning, rewinding to beginning info
       
   409     // is cleared.
       
   410     file->iPosition = 10000000;
       
   411     iClipSession->iFRWDStartTime = TTime( 0 );
       
   412     
       
   413     EUNIT_ASSERT( iClipSession->PositionL().Int() * 1000000 == 10000000 )
       
   414     EUNIT_ASSERT( iClipSession->iRewindedToBeginning == EFalse )
       
   415     }
       
   416     
       
   417     
       
   418 // -----------------------------------------------------------------------------
       
   419 //
       
   420 // -----------------------------------------------------------------------------
       
   421 //
       
   422 void UT_CMusEngClipSession::UT_DurationLL()
       
   423     {
       
   424     // Try before establishment
       
   425     EUNIT_ASSERT_SPECIFIC_LEAVE( iClipSession->DurationL(), KErrNotReady )
       
   426     
       
   427     // Establish session and try again
       
   428     ESTABLISH_OUT_SESSION( iClipSession );
       
   429     
       
   430     CMceFileSource* file = 
       
   431                     MusEngMceUtils::GetFileSourceL( *iClipSession->iSession );
       
   432     file->iDuration = 2000000;
       
   433     
       
   434     EUNIT_ASSERT( iClipSession->DurationL().Int() * 1000000 == 
       
   435                   file->iDuration.Int64() )
       
   436     }
       
   437 
       
   438 
       
   439 // -----------------------------------------------------------------------------
       
   440 //
       
   441 // -----------------------------------------------------------------------------
       
   442 //
       
   443 void UT_CMusEngClipSession::UT_SetPositionLL()
       
   444     {
       
   445     TTimeIntervalSeconds time( 20 );
       
   446     
       
   447     // Try before establishment
       
   448     EUNIT_ASSERT_SPECIFIC_LEAVE( iClipSession->SetPositionL( time ),
       
   449                                  KErrNotReady )
       
   450     
       
   451     // Normal case with already disabled file source
       
   452     ESTABLISH_OUT_SESSION( iClipSession );
       
   453     
       
   454     CMceFileSource* file = 
       
   455                 MusEngMceUtils::GetFileSourceL( *iClipSession->iSession ); 
       
   456     file->iIsEnabled = EFalse;
       
   457     
       
   458     iClipSession->SetPositionL( time );
       
   459     
       
   460     EUNIT_ASSERT( file->iPosition.Int64() == 
       
   461                   static_cast<TInt64>(time.Int()) * 1000000 )
       
   462     EUNIT_ASSERT( !file->iIsEnabled )
       
   463     
       
   464     // Normal case with enabled file source
       
   465     TTimeIntervalSeconds anotherTime( 30 );
       
   466 
       
   467     file->iIsEnabled = ETrue;
       
   468     iClipSession->SetPositionL( anotherTime );
       
   469     
       
   470     EUNIT_ASSERT( file->iPosition.Int64() == 
       
   471                   static_cast<TInt64>(anotherTime.Int()) * 1000000 )
       
   472     EUNIT_ASSERT( file->iIsEnabled )
       
   473     }
       
   474 
       
   475 
       
   476 // -----------------------------------------------------------------------------
       
   477 //
       
   478 // -----------------------------------------------------------------------------
       
   479 //
       
   480 void UT_CMusEngClipSession::UT_TranscodeLToAvcL()
       
   481     {
       
   482     // Check that transcoding is not possible before invite
       
   483     EUNIT_ASSERT_SPECIFIC_LEAVE( 
       
   484                     iClipSession->TranscodeL( KTestVideoFileName() ),
       
   485                     KErrNotReady )
       
   486     
       
   487     // Construct session with video and audio streams that must transcoded 
       
   488     
       
   489     CSIPProfile* profile = iClipSession->iSipProfileHandler->Profile();
       
   490   
       
   491     iClipSession->iSession = CMceOutSession::NewL( 
       
   492                                     *(iClipSession->iManager),
       
   493                                     *profile,
       
   494                                     KTestRecipientSipUri8() );
       
   495                              
       
   496     CMceVideoStream* videoStream = CMceVideoStream::NewLC();
       
   497 
       
   498     CMceRtpSink* rtpsink = CMceRtpSink::NewLC();
       
   499     videoStream->AddSinkL( rtpsink );
       
   500     CleanupStack::Pop( rtpsink );
       
   501 
       
   502     CMceFileSource* fileSource = 
       
   503         CMceFileSource::NewLC( *iClipSession->iManager, KTestAvcVideoFileName() );
       
   504     videoStream->SetSourceL( fileSource );                            
       
   505     CleanupStack::Pop( fileSource );
       
   506 
       
   507     iClipSession->iSession->AddStreamL( videoStream );
       
   508     CleanupStack::Pop( videoStream );
       
   509     
       
   510     CMceAudioStream* audioStream = CMceAudioStream::NewLC();
       
   511         
       
   512     audioStream->AddSinkL( CMceRtpSink::NewLC() );
       
   513     CleanupStack::Pop();
       
   514     
       
   515     audioStream->SetSourceL( fileSource );
       
   516     
       
   517     iClipSession->iSession->AddStreamL( audioStream );
       
   518     CleanupStack::Pop( audioStream );
       
   519     
       
   520     videoStream->iState = CMceMediaStream::ETranscodingRequired;
       
   521     audioStream->iState = CMceMediaStream::ETranscodingRequired; 
       
   522     
       
   523     // Remove all codecs (file has some unknown codec type)
       
   524     RPointerArray<CMceVideoCodec> videoCodecs = videoStream->Codecs();
       
   525     for ( TInt i = 0; i < videoCodecs.Count(); i++ )
       
   526         {
       
   527         videoStream->RemoveCodecL( *videoCodecs[ i ] );
       
   528         }
       
   529     RPointerArray<CMceVideoCodec> videoCodecs2 = videoStream->Codecs();
       
   530     EUNIT_ASSERT_EQUALS( videoCodecs2.Count(), 0 )
       
   531     EUNIT_ASSERT( audioStream->Codecs().Count() > 1 )  
       
   532     
       
   533     // Add some stream which must not be transcoded
       
   534     
       
   535     CMceAudioStream* inStream = CMceAudioStream::NewLC();
       
   536         
       
   537     inStream->AddSinkL( CMceSpeakerSink::NewLC() );
       
   538     CleanupStack::Pop();
       
   539     
       
   540     inStream->SetSourceL( CMceRtpSource::NewLC() );
       
   541     CleanupStack::Pop();
       
   542     
       
   543     iClipSession->iSession->AddStreamL( inStream );
       
   544     CleanupStack::Pop( inStream );
       
   545 
       
   546     // Transcode
       
   547     iClipSession->TranscodeL( KTestAvcVideoFileName() );
       
   548     
       
   549     // Check that transcoding has begun (transcoding to AVC as we know
       
   550     // that other end supports it
       
   551     EUNIT_ASSERT( iClipSession->iTranscodingOngoing )
       
   552     EUNIT_ASSERT( videoStream->State() == CMceMediaStream::ETranscoding )
       
   553     EUNIT_ASSERT( audioStream->State() == CMceMediaStream::ETranscoding )
       
   554     EUNIT_ASSERT( inStream->State() != CMceMediaStream::ETranscoding )
       
   555     
       
   556     // Check that codecs have been replaced
       
   557     const RPointerArray<CMceVideoCodec> videoCodecs3 = videoStream->Codecs();
       
   558     EUNIT_ASSERT_EQUALS( videoCodecs3.Count(), 1 )
       
   559     EUNIT_ASSERT( videoCodecs3[0]->SdpName().FindF( KMceSDPNameH264() ) >= 0 )
       
   560     EUNIT_ASSERT( audioStream->Codecs().Count() == 1 )  
       
   561     EUNIT_ASSERT( audioStream->Codecs()[0]->AllowedBitrates() == 
       
   562                   KMceAllowedAmrNbBitrate475 )
       
   563     }
       
   564 
       
   565 // -----------------------------------------------------------------------------
       
   566 //
       
   567 // -----------------------------------------------------------------------------
       
   568 //
       
   569 void UT_CMusEngClipSession::UT_TranscodeLToH263L()
       
   570     {
       
   571     // Check that transcoding is not possible before invite
       
   572     EUNIT_ASSERT_SPECIFIC_LEAVE( 
       
   573                     iClipSession->TranscodeL( KTestVideoFileName() ),
       
   574                     KErrNotReady )
       
   575     
       
   576     // Construct session with video and audio streams that must transcoded 
       
   577     
       
   578     CSIPProfile* profile = iClipSession->iSipProfileHandler->Profile();
       
   579   
       
   580     iClipSession->iSession = CMceOutSession::NewL( 
       
   581                                     *(iClipSession->iManager),
       
   582                                     *profile,
       
   583                                     KTestRecipientSipUri8() );
       
   584                              
       
   585     CMceVideoStream* videoStream = CMceVideoStream::NewLC();
       
   586 
       
   587     CMceRtpSink* rtpsink = CMceRtpSink::NewLC();
       
   588     videoStream->AddSinkL( rtpsink );
       
   589     CleanupStack::Pop( rtpsink );
       
   590 
       
   591     CMceFileSource* fileSource = 
       
   592         CMceFileSource::NewLC( *iClipSession->iManager, KTestAvcVideoFileName() );
       
   593     videoStream->SetSourceL( fileSource );                            
       
   594     CleanupStack::Pop( fileSource );
       
   595 
       
   596     iClipSession->iSession->AddStreamL( videoStream );
       
   597     CleanupStack::Pop( videoStream );
       
   598     
       
   599     CMceAudioStream* audioStream = CMceAudioStream::NewLC();
       
   600         
       
   601     audioStream->AddSinkL( CMceRtpSink::NewLC() );
       
   602     CleanupStack::Pop();
       
   603     
       
   604     audioStream->SetSourceL( fileSource );
       
   605     
       
   606     iClipSession->iSession->AddStreamL( audioStream );
       
   607     CleanupStack::Pop( audioStream );
       
   608     
       
   609     videoStream->iState = CMceMediaStream::ETranscodingRequired;
       
   610     audioStream->iState = CMceMediaStream::ETranscodingRequired; 
       
   611     
       
   612     const RPointerArray<CMceVideoCodec> videoCodecs = videoStream->Codecs();
       
   613     EUNIT_ASSERT_EQUALS( videoCodecs.Count(), 1 )
       
   614     EUNIT_ASSERT( videoCodecs[0]->SdpName().FindF( KMceSDPNameH264() ) >= 0 )
       
   615     EUNIT_ASSERT( audioStream->Codecs().Count() > 1 )  
       
   616     
       
   617     TSize resolution(200,200); // Some value
       
   618     videoStream->Codecs()[0]->SetResolutionL( resolution );
       
   619     audioStream->Codecs()[0]->SetBitrate( KMceAllowedAmrNbBitrateAll );
       
   620     
       
   621     // Add some stream which must not be transcoded
       
   622     
       
   623     CMceAudioStream* inStream = CMceAudioStream::NewLC();
       
   624         
       
   625     inStream->AddSinkL( CMceSpeakerSink::NewLC() );
       
   626     CleanupStack::Pop();
       
   627     
       
   628     inStream->SetSourceL( CMceRtpSource::NewLC() );
       
   629     CleanupStack::Pop();
       
   630     
       
   631     iClipSession->iSession->AddStreamL( inStream );
       
   632     CleanupStack::Pop( inStream );
       
   633 
       
   634     // Transcode
       
   635     iClipSession->TranscodeL( KTestAvcVideoFileName() );
       
   636     
       
   637     // Check that transcoding has begun (transcoding to H263 as we don't
       
   638     // know whether other end supports H264)    EUNIT_ASSERT( iClipSession->iTranscodingOngoing )
       
   639     EUNIT_ASSERT( videoStream->State() == CMceMediaStream::ETranscoding )
       
   640     EUNIT_ASSERT( audioStream->State() == CMceMediaStream::ETranscoding )
       
   641     EUNIT_ASSERT( inStream->State() != CMceMediaStream::ETranscoding )
       
   642     
       
   643     // Check that codecs have been replaced
       
   644     const RPointerArray<CMceVideoCodec> videoCodecs2 = videoStream->Codecs();
       
   645     EUNIT_ASSERT_EQUALS( videoCodecs2.Count(), 1 )
       
   646     EUNIT_ASSERT( videoCodecs2[0]->SdpName().FindF( KMceSDPNameH263() ) >= 0 )
       
   647     EUNIT_ASSERT( audioStream->Codecs().Count() == 1 )  
       
   648     
       
   649     EUNIT_ASSERT( videoStream->Codecs()[0]->Resolution() != resolution )
       
   650     EUNIT_ASSERT( audioStream->Codecs()[0]->AllowedBitrates() == 
       
   651                   KMceAllowedAmrNbBitrate475 )
       
   652     }
       
   653     
       
   654 // -----------------------------------------------------------------------------
       
   655 //
       
   656 // -----------------------------------------------------------------------------
       
   657 //
       
   658 void UT_CMusEngClipSession::UT_CancelTranscodeLL()
       
   659     {
       
   660     // Check that canceling transcoding is not possible before actual
       
   661     // transcoding
       
   662     EUNIT_ASSERT_SPECIFIC_LEAVE( iClipSession->CancelTranscodeL(),
       
   663                                  KErrNotReady )
       
   664     
       
   665     // Construct session structure
       
   666     
       
   667     CSIPProfile* profile = iClipSession->iSipProfileHandler->Profile();
       
   668   
       
   669     iClipSession->iSession = CMceOutSession::NewL( 
       
   670                                     *(iClipSession->iManager),
       
   671                                     *profile,
       
   672                                     KTestRecipientSipUri8() );
       
   673                              
       
   674     CMceVideoStream* videoStream = CMceVideoStream::NewLC();
       
   675 
       
   676     CMceRtpSink* rtpsink = CMceRtpSink::NewLC();
       
   677     videoStream->AddSinkL( rtpsink );
       
   678     CleanupStack::Pop( rtpsink );
       
   679 
       
   680     CMceFileSource* fileSource = 
       
   681         CMceFileSource::NewLC( *iClipSession->iManager, KTestVideoFileName() );
       
   682     videoStream->SetSourceL( fileSource );                            
       
   683     CleanupStack::Pop( fileSource );
       
   684 
       
   685     iClipSession->iSession->AddStreamL( videoStream );
       
   686     CleanupStack::Pop( videoStream );
       
   687     
       
   688     CMceAudioStream* audioStream = CMceAudioStream::NewLC();
       
   689         
       
   690     audioStream->AddSinkL( CMceRtpSink::NewLC() );
       
   691     CleanupStack::Pop();
       
   692     
       
   693     audioStream->SetSourceL( fileSource );
       
   694     
       
   695     iClipSession->iSession->AddStreamL( audioStream );
       
   696     CleanupStack::Pop( audioStream );
       
   697     
       
   698     // Set need for transcoding
       
   699     videoStream->iState = CMceMediaStream::ETranscodingRequired;
       
   700     audioStream->iState = CMceMediaStream::ETranscodingRequired; 
       
   701 
       
   702     // Transcode
       
   703     iClipSession->TranscodeL( KTestAvcVideoFileName() );
       
   704 
       
   705     EUNIT_ASSERT( videoStream->State() == CMceMediaStream::ETranscoding )
       
   706     EUNIT_ASSERT( audioStream->State() == CMceMediaStream::ETranscoding )
       
   707         
       
   708     // Cancel
       
   709     iClipSession->CancelTranscodeL();
       
   710     
       
   711     EUNIT_ASSERT( videoStream->State() == 
       
   712                   CMceMediaStream::ETranscodingRequired )
       
   713     EUNIT_ASSERT( audioStream->State() == 
       
   714                   CMceMediaStream::ETranscodingRequired )
       
   715     }
       
   716     
       
   717     
       
   718 // -----------------------------------------------------------------------------
       
   719 //
       
   720 // -----------------------------------------------------------------------------
       
   721 //    
       
   722 void UT_CMusEngClipSession::UT_PlayLL()
       
   723     {
       
   724     // Check that resuming is not possible before invite
       
   725     EUNIT_ASSERT_SPECIFIC_LEAVE( iClipSession->PlayL(), KErrNotReady )
       
   726     
       
   727     ESTABLISH_OUT_SESSION( iClipSession );
       
   728 
       
   729     // Check that playing is not possible during FFWD
       
   730     iClipSession->iFFWDStartTime = TTime( 10 );
       
   731     EUNIT_ASSERT_SPECIFIC_LEAVE( iClipSession->PlayL(), KErrNotReady )
       
   732     iClipSession->iFFWDStartTime = TTime( 0 );
       
   733  
       
   734     // Check that playing is not possible during FRWD
       
   735     iClipSession->iFRWDStartTime = TTime( 10 );
       
   736     EUNIT_ASSERT_SPECIFIC_LEAVE( iClipSession->PlayL(), KErrNotReady )
       
   737     iClipSession->iFRWDStartTime = TTime( 0 );
       
   738 
       
   739     // Successful case
       
   740     CMceFileSource* file = 
       
   741             MusEngMceUtils::GetFileSourceL( *(iClipSession->iSession) );
       
   742 
       
   743     file->iIsEnabled = EFalse;
       
   744 
       
   745     iClipSession->PlayL();
       
   746 
       
   747     EUNIT_ASSERT( file->IsEnabled() )
       
   748     
       
   749     // Try to play again, request should be ignored
       
   750     
       
   751     iClipSession->PlayL();
       
   752 
       
   753     EUNIT_ASSERT( file->IsEnabled() )
       
   754 
       
   755     }
       
   756     
       
   757 
       
   758 // -----------------------------------------------------------------------------
       
   759 //
       
   760 // -----------------------------------------------------------------------------
       
   761 //    
       
   762 void UT_CMusEngClipSession::UT_PauseLL()
       
   763     {
       
   764     // Check that pausing is not possible before invite
       
   765     EUNIT_ASSERT_SPECIFIC_LEAVE( iClipSession->PauseL(), KErrNotReady )
       
   766     
       
   767     ESTABLISH_OUT_SESSION( iClipSession );
       
   768 
       
   769     // Check that pausing is not possible during FFWD
       
   770     iClipSession->iFFWDStartTime = TTime( 10 );
       
   771     EUNIT_ASSERT_SPECIFIC_LEAVE( iClipSession->PauseL(), KErrNotReady )
       
   772     iClipSession->iFFWDStartTime = TTime( 0 );
       
   773  
       
   774     // Check that pausing is not possible during FRWD
       
   775     iClipSession->iFRWDStartTime = TTime( 10 );
       
   776     EUNIT_ASSERT_SPECIFIC_LEAVE( iClipSession->PauseL(), KErrNotReady )
       
   777     iClipSession->iFRWDStartTime = TTime( 0 );
       
   778 
       
   779     // Successful case
       
   780     
       
   781     CMceFileSource* file = 
       
   782             MusEngMceUtils::GetFileSourceL( *(iClipSession->iSession) );
       
   783 
       
   784     file->iIsEnabled = ETrue;
       
   785     
       
   786     iClipSession->PauseL();
       
   787 
       
   788     EUNIT_ASSERT( !file->IsEnabled() )
       
   789     
       
   790     // Try to pause again, request should be ignored
       
   791     
       
   792     iClipSession->PauseL();
       
   793 
       
   794     EUNIT_ASSERT( !file->IsEnabled() )
       
   795 
       
   796     }
       
   797 
       
   798 
       
   799 // -----------------------------------------------------------------------------
       
   800 //
       
   801 // -----------------------------------------------------------------------------
       
   802 //    
       
   803 void UT_CMusEngClipSession::UT_IsPlayingLL()
       
   804     {
       
   805     // Try without a session 
       
   806     EUNIT_ASSERT_SPECIFIC_LEAVE( iClipSession->IsPlayingL(), KErrNotReady );
       
   807     
       
   808     // Normal cases
       
   809     ESTABLISH_OUT_SESSION( iClipSession );
       
   810     
       
   811     iClipSession->PlayL();
       
   812     EUNIT_ASSERT( iClipSession->IsPlayingL() )
       
   813     
       
   814     iClipSession->PauseL();
       
   815     EUNIT_ASSERT( !iClipSession->IsPlayingL() )
       
   816     }
       
   817         
       
   818 
       
   819 // -----------------------------------------------------------------------------
       
   820 //
       
   821 // -----------------------------------------------------------------------------
       
   822 //
       
   823 void UT_CMusEngClipSession::UT_CompleteSessionStructureLL()
       
   824     {
       
   825     
       
   826     CMceStreamBundle* localBundle = 
       
   827                             CMceStreamBundle::NewLC( CMceStreamBundle::ELS );
       
   828     
       
   829     // Check that structure cannot be completed before creating the session
       
   830     EUNIT_ASSERT_SPECIFIC_LEAVE( 
       
   831                 iClipSession->CompleteSessionStructureL( *localBundle ),
       
   832                 KErrNotReady )
       
   833     
       
   834     // Check that structure cannot be completed before setting the file name
       
   835     iClipSession->iFileName = KNullDesC();          
       
   836     CSIPProfile* profile = iClipSession->iSipProfileHandler->Profile();
       
   837   
       
   838     iClipSession->iSession = CMceOutSession::NewL( 
       
   839                                     *(iClipSession->iManager),
       
   840                                     *profile,
       
   841                                     KTestRecipientSipUri8() );
       
   842 
       
   843     EUNIT_ASSERT_SPECIFIC_LEAVE( 
       
   844                 iClipSession->CompleteSessionStructureL( *localBundle ),
       
   845                 KErrNotReady )
       
   846     
       
   847     // Normal case
       
   848     iClipSession->iFileName = KTestVideoFileName();                     
       
   849     iClipSession->CompleteSessionStructureL( *localBundle );
       
   850     
       
   851     EUNIT_ASSERT( iClipSession->iSession->Streams().Count() == 3 )
       
   852     EUNIT_ASSERT( iClipSession->iSession->Streams()[0]->Type() == KMceVideo )
       
   853     EUNIT_ASSERT( iClipSession->iSession->Streams()[0]->Source() )
       
   854     EUNIT_ASSERT( iClipSession->iSession->Streams()[0]->Source()->Type() ==
       
   855                   KMceFileSource )
       
   856     EUNIT_ASSERT( !iClipSession->IsPlayingL() )              
       
   857     EUNIT_ASSERT( iClipSession->iSession->Streams()[0]->Sinks().Count() == 1 )
       
   858     EUNIT_ASSERT( iClipSession->iSession->Streams()[0]->Sinks()[0]->Type() ==
       
   859                   KMceRTPSink )
       
   860     
       
   861     // Check that only stream with speaker has been added to a bundle
       
   862     EUNIT_ASSERT( localBundle->Streams().Count() == 1 )
       
   863     EUNIT_ASSERT( localBundle->Streams()[0]->Type() == KMceAudio )
       
   864     EUNIT_ASSERT( localBundle->Streams()[0]->Sinks().Count() > 0 )
       
   865     EUNIT_ASSERT( localBundle->Streams()[0]->Sinks()[0]->Type() == 
       
   866                   KMceSpeakerSink )
       
   867     
       
   868     CleanupStack::PopAndDestroy( localBundle );
       
   869     }
       
   870 
       
   871 
       
   872 // -----------------------------------------------------------------------------
       
   873 // Although all states are not meaningfull for LiveSession, all states are
       
   874 // tested in order to force the updating of unit tests when behavior is changed 
       
   875 // -----------------------------------------------------------------------------
       
   876 //
       
   877 void UT_CMusEngClipSession::UT_StreamStateChangedL()
       
   878     {
       
   879     // Try without a session, nothing happens
       
   880     CMceVideoStream* videoStream = CMceVideoStream::NewLC();
       
   881     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
       
   882                                                             *videoStream );
       
   883     CleanupStack::PopAndDestroy( videoStream );
       
   884     
       
   885     // Simulate sending invite
       
   886     iClipSession->InviteL( KTestRecipientSipUri() );
       
   887    
       
   888     // Try all the stream states
       
   889     CMceMediaStream* changedStream = iClipSession->iSession->Streams()[0];
       
   890     
       
   891     // EUninitialized, stream is created, unexpected change, nothing happens
       
   892     changedStream->iState = CMceMediaStream::EUninitialized;
       
   893     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
       
   894                                                             *changedStream );
       
   895     EUNIT_ASSERT( iObserver->IsReseted() )
       
   896     
       
   897     // EInitialized, stream is initialized
       
   898     changedStream->iState = CMceMediaStream::EInitialized;
       
   899     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
       
   900                                                             *changedStream );
       
   901     EUNIT_ASSERT( iObserver->IsReseted() )
       
   902     
       
   903     // EBuffering, stream is buffering
       
   904     changedStream->iState = CMceMediaStream::EBuffering;
       
   905     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
       
   906                                                             *changedStream );
       
   907     EUNIT_ASSERT( iObserver->IsReseted() )
       
   908     
       
   909     // EIdle, stream is not receiving RTP
       
   910     changedStream->iState = CMceMediaStream::EIdle;
       
   911     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
       
   912                                                             *changedStream );
       
   913     EUNIT_ASSERT( iObserver->IsReseted() )
       
   914     
       
   915     // EStreaming, stream is streaming
       
   916     changedStream->iState = CMceMediaStream::EStreaming;
       
   917     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
       
   918                                                             *changedStream );
       
   919     EUNIT_ASSERT( iObserver->iStreamStreamingCalled )
       
   920     iObserver->Reset();
       
   921     
       
   922     // EDisabled, stream is explicitly disabled
       
   923     changedStream->iState = CMceMediaStream::EDisabled;
       
   924     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
       
   925                                                             *changedStream );
       
   926     EUNIT_ASSERT( iObserver->IsReseted() )
       
   927     
       
   928     // ENoResources, stream has no needed resources to stream
       
   929     changedStream->iState = CMceMediaStream::ENoResources;
       
   930     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
       
   931                                                             *changedStream );
       
   932     EUNIT_ASSERT( iObserver->IsReseted() )
       
   933     
       
   934     // ETranscodingRequired, stream requires non-realtime transcoding
       
   935     changedStream->iState = CMceMediaStream::ETranscodingRequired;
       
   936     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
       
   937                                                             *changedStream );
       
   938     EUNIT_ASSERT( iObserver->IsReseted() )
       
   939     
       
   940     // ETranscoding, stream is transcoding in non-realtime
       
   941     changedStream->iState = CMceMediaStream::ETranscoding;
       
   942     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
       
   943                                                             *changedStream );
       
   944     EUNIT_ASSERT( iObserver->IsReseted() )
       
   945     }
       
   946     
       
   947 
       
   948 // -----------------------------------------------------------------------------
       
   949 // Although all states are not meaningfull for ClipSession, all states are
       
   950 // tested in order to force the updating of unit tests when behavior is changed 
       
   951 // -----------------------------------------------------------------------------
       
   952 //
       
   953 void UT_CMusEngClipSession::UT_StreamStateChangedWithSourceL()
       
   954     {
       
   955     // Try without a session, nothing happens
       
   956     CMceVideoStream* videoStream = CMceVideoStream::NewLC();
       
   957     CMceRtpSource* rtpSource = CMceRtpSource::NewLC();
       
   958     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
       
   959                     *videoStream,
       
   960                     *rtpSource );     
       
   961     CleanupStack::PopAndDestroy( rtpSource );         
       
   962     CleanupStack::PopAndDestroy( videoStream );
       
   963     
       
   964     // Simulate sending invite
       
   965     iClipSession->InviteL( KTestRecipientSipUri() );
       
   966     
       
   967     // Try all the non-default stream states
       
   968     CMceMediaStream* changedStream = iClipSession->iSession->Streams()[0];
       
   969     CMceMediaSource* changedSource = changedStream->Source();
       
   970     
       
   971     // EDisabled, end of clip
       
   972     changedStream->iState = CMceMediaStream::EDisabled;
       
   973     changedSource->iIsEnabled = EFalse;
       
   974     iClipSession->StreamStateChanged( *changedStream, *changedSource );
       
   975     
       
   976     EUNIT_ASSERT( iObserver->iEndOfClipCalled == ETrue )
       
   977     changedSource->iIsEnabled = ETrue;
       
   978     iObserver->Reset();
       
   979     
       
   980     // ETranscodingRequired, transcoding has failed
       
   981     iClipSession->iSession->iState = CMceSession::EIdle;
       
   982     iClipSession->iTranscodingOngoing = ETrue;
       
   983     changedStream->iState = CMceMediaStream::ETranscodingRequired;
       
   984     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
       
   985                             *changedStream, *changedSource );
       
   986     EUNIT_ASSERT( iObserver->iTranscodingFailedCalled )
       
   987     EUNIT_ASSERT( !iClipSession->iTranscodingOngoing )
       
   988     iObserver->Reset();
       
   989     
       
   990     // ETranscoding, transcoding has progresssed
       
   991     iClipSession->iSession->iState = CMceSession::EIdle;
       
   992     changedStream->iState = CMceMediaStream::ETranscoding;
       
   993     static_cast<CMceFileSource*>(changedSource)->iTranscodingPercentage = 20;
       
   994     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
       
   995                             *changedStream, *changedSource );
       
   996     EUNIT_ASSERT( iObserver->iTranscodingProgressedPercentage == 20 )
       
   997     iObserver->Reset();
       
   998     
       
   999     // ETranscoding, transcoding has progresssed, querying percentage fails
       
  1000     iClipSession->iSession->iState = CMceSession::EIdle;
       
  1001     changedStream->iState = CMceMediaStream::ETranscoding;
       
  1002     iObserver->iTranscodingProgressedPercentage = -1; // make assertion possible
       
  1003     static_cast<CMceFileSource*>(changedSource)->iFailWithCode = KErrNotReady;
       
  1004     static_cast<CMceFileSource*>(changedSource)->iTranscodingPercentage = 30;
       
  1005     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
       
  1006                             *changedStream, *changedSource );
       
  1007     EUNIT_ASSERT( iObserver->iTranscodingProgressedPercentage == 0 )
       
  1008     iObserver->Reset();
       
  1009 
       
  1010     // EInitialized, transcoding has completed, establishment fails
       
  1011     iClipSession->iSession->iState = CMceSession::EIdle;
       
  1012     iClipSession->iSession->iFailWithCode = KErrCorrupt; // != KErrNone
       
  1013     iClipSession->iTranscodingOngoing = ETrue;
       
  1014     changedStream->iState = CMceMediaStream::EInitialized;
       
  1015     static_cast<CMceFileSource*>(changedSource)->iTranscodingPercentage = 100;
       
  1016     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
       
  1017                             *changedStream, *changedSource );
       
  1018     EUNIT_ASSERT( iObserver->iTranscodingCompletedInitCalled )
       
  1019     EUNIT_ASSERT( iObserver->iTranscodingCompletedFinalizeCalled )
       
  1020     EUNIT_ASSERT( iObserver->iSessionFailedCalled )
       
  1021     EUNIT_ASSERT( !iClipSession->iTranscodingOngoing )
       
  1022     iObserver->Reset();
       
  1023     
       
  1024     // EInitialized, transcoding has completed, establishment succeeds
       
  1025     iClipSession->iSession->iState = CMceSession::EIdle;
       
  1026     iClipSession->iTranscodingOngoing = ETrue;
       
  1027     changedStream->iState = CMceMediaStream::EInitialized;
       
  1028     static_cast<CMceFileSource*>(changedSource)->iTranscodingPercentage = 100;
       
  1029     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
       
  1030                             *changedStream, *changedSource );
       
  1031     EUNIT_ASSERT( iObserver->iTranscodingCompletedInitCalled )
       
  1032     EUNIT_ASSERT( iObserver->iTranscodingCompletedFinalizeCalled )    
       
  1033     // Next cannot be asserted since it is not true with alloc decoration
       
  1034     // EUNIT_ASSERT( !iObserver->iSessionFailedCalled )  
       
  1035     EUNIT_ASSERT( !iClipSession->iTranscodingOngoing )
       
  1036     iObserver->Reset();
       
  1037     
       
  1038     
       
  1039     // Test default stream state change behavior, remove or change when
       
  1040     // behavior changes
       
  1041     
       
  1042     
       
  1043     // EUninitialized, stream is created, unexpected change, nothing happens
       
  1044     changedStream->iState = CMceMediaStream::EUninitialized;
       
  1045     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
       
  1046                             *changedStream, *changedSource );
       
  1047     EUNIT_ASSERT( iObserver->IsReseted() )
       
  1048     
       
  1049     // EInitialized, stream is initialized
       
  1050     changedStream->iState = CMceMediaStream::EInitialized;
       
  1051     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
       
  1052                             *changedStream, *changedSource );
       
  1053     EUNIT_ASSERT( iObserver->IsReseted() )
       
  1054 
       
  1055     // Special meaning (Transcoding ready), tested separately
       
  1056     
       
  1057     // EBuffering, stream is buffering
       
  1058     changedStream->iState = CMceMediaStream::EBuffering;
       
  1059     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
       
  1060                             *changedStream, *changedSource );
       
  1061     EUNIT_ASSERT( iObserver->IsReseted() )
       
  1062     
       
  1063     // EIdle, stream is not receiving RTP
       
  1064     changedStream->iState = CMceMediaStream::EIdle;
       
  1065     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
       
  1066                             *changedStream, *changedSource );
       
  1067     EUNIT_ASSERT( iObserver->IsReseted() )
       
  1068     
       
  1069     // EStreaming, stream is streaming
       
  1070     changedStream->iState = CMceMediaStream::EStreaming;
       
  1071     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
       
  1072                             *changedStream, *changedSource );
       
  1073     EUNIT_ASSERT( iObserver->iStreamStreamingCalled )
       
  1074     iObserver->Reset();
       
  1075     
       
  1076     // EDisabled, stream is explicitly disabled
       
  1077     // This state has non-default meaning, tested before defaults
       
  1078     
       
  1079     // ENoResources, stream has no needed resources to stream
       
  1080     changedStream->iState = CMceMediaStream::ENoResources;
       
  1081     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
       
  1082                             *changedStream, *changedSource );
       
  1083     EUNIT_ASSERT( iObserver->IsReseted() )
       
  1084 
       
  1085     
       
  1086     }
       
  1087 
       
  1088 
       
  1089 // -----------------------------------------------------------------------------
       
  1090 // Although all states are not meaningfull for LiveSession, all states are
       
  1091 // tested in order to force the updating of unit tests when behavior is changed 
       
  1092 // -----------------------------------------------------------------------------
       
  1093 //
       
  1094 void UT_CMusEngClipSession::UT_StreamStateChangedWithSinkL()
       
  1095     {
       
  1096     // Try without a session, nothing happens
       
  1097     CMceVideoStream* videoStream = CMceVideoStream::NewLC();
       
  1098     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
       
  1099                                                         *videoStream,
       
  1100                                                         *CMceRtpSink::NewLC() );
       
  1101     CleanupStack::PopAndDestroy(); // rtp
       
  1102     CleanupStack::PopAndDestroy( videoStream );
       
  1103     
       
  1104     // Simulate sending invite
       
  1105     iClipSession->InviteL( KTestRecipientSipUri() );
       
  1106                                      
       
  1107     // Test default stream state change behavior
       
  1108     CMceMediaStream* changedStream = iClipSession->iSession->Streams()[0];
       
  1109     CMceMediaSink* changedSink = changedStream->Sinks()[0];
       
  1110 
       
  1111     // EUninitialized, stream is created, unexpected change, nothing happens
       
  1112     changedStream->iState = CMceMediaStream::EUninitialized;
       
  1113     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
       
  1114                                                             *changedStream,
       
  1115                                                             *changedSink );
       
  1116     EUNIT_ASSERT( iObserver->IsReseted() )
       
  1117     
       
  1118     // EInitialized, stream is initialized
       
  1119     changedStream->iState = CMceMediaStream::EInitialized;
       
  1120     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
       
  1121                                                             *changedStream,
       
  1122                                                             *changedSink );
       
  1123     EUNIT_ASSERT( iObserver->IsReseted() )
       
  1124     
       
  1125     // EBuffering, stream is buffering
       
  1126     changedStream->iState = CMceMediaStream::EBuffering;
       
  1127     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
       
  1128                                                             *changedStream,
       
  1129                                                             *changedSink );
       
  1130     EUNIT_ASSERT( iObserver->IsReseted() )
       
  1131     
       
  1132     // EIdle, stream is not receiving RTP
       
  1133     changedStream->iState = CMceMediaStream::EIdle;
       
  1134     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
       
  1135                                                             *changedStream,
       
  1136                                                             *changedSink );
       
  1137     EUNIT_ASSERT( iObserver->IsReseted() )
       
  1138     
       
  1139     // EStreaming, stream is streaming
       
  1140     changedStream->iState = CMceMediaStream::EStreaming;
       
  1141     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
       
  1142                                                             *changedStream,
       
  1143                                                             *changedSink );
       
  1144     EUNIT_ASSERT( iObserver->iStreamStreamingCalled )
       
  1145     iObserver->Reset();
       
  1146     
       
  1147     // EDisabled, stream is explicitly disabled
       
  1148     changedStream->iState = CMceMediaStream::EDisabled;
       
  1149     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
       
  1150                                                             *changedStream,
       
  1151                                                             *changedSink );
       
  1152     EUNIT_ASSERT( iObserver->IsReseted() )
       
  1153     
       
  1154     // ENoResources, stream has no needed resources to stream
       
  1155     changedStream->iState = CMceMediaStream::ENoResources;
       
  1156     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
       
  1157                                                             *changedStream,
       
  1158                                                             *changedSink );
       
  1159     EUNIT_ASSERT( iObserver->IsReseted() )
       
  1160                                                             
       
  1161     // ETranscodingRequired, stream requires non-realtime transcoding
       
  1162     changedStream->iState = CMceMediaStream::ETranscodingRequired;
       
  1163     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
       
  1164                                                             *changedStream,
       
  1165                                                             *changedSink );
       
  1166     EUNIT_ASSERT( iObserver->IsReseted() )
       
  1167     
       
  1168     // ETranscoding, stream is transcoding in non-realtime
       
  1169     changedStream->iState = CMceMediaStream::ETranscoding;
       
  1170     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
       
  1171                                                             *changedStream,
       
  1172                                                             *changedSink );
       
  1173     EUNIT_ASSERT( iObserver->IsReseted() )
       
  1174     
       
  1175     }
       
  1176 
       
  1177 
       
  1178 // -----------------------------------------------------------------------------
       
  1179 //
       
  1180 // -----------------------------------------------------------------------------
       
  1181 //
       
  1182 void UT_CMusEngClipSession::UT_AddAmrCodecLL()
       
  1183     {
       
  1184     // Check that all the codecs are replaced with AMR codec
       
  1185     CMceAudioStream* audioStream = CMceAudioStream::NewLC();
       
  1186     
       
  1187     audioStream->InitializeL( iClipSession->iManager );
       
  1188     
       
  1189     EUNIT_ASSERT( audioStream->Codecs().Count() == 2 )
       
  1190     
       
  1191     iClipSession->AddAmrCodecL( *audioStream );
       
  1192     
       
  1193     EUNIT_ASSERT( audioStream->Codecs().Count() == 1 )
       
  1194     EUNIT_ASSERT( audioStream->Codecs()[0]->SdpName() == KMceSDPNameAMR() )
       
  1195     EUNIT_ASSERT( audioStream->Codecs()[0]->AllowedBitrates() == 
       
  1196                   KMceAllowedAmrNbBitrate475 )
       
  1197     EUNIT_ASSERT( audioStream->Codecs()[0]->Bitrate() == 
       
  1198                   KMceAmrNbBitrate475 )
       
  1199     
       
  1200     // Check that function leaves  if there is no AMR codec
       
  1201     
       
  1202     iClipSession->iManager->iSupportedAudioCodecs.ResetAndDestroy();
       
  1203     
       
  1204     EUNIT_ASSERT_SPECIFIC_LEAVE( iClipSession->AddAmrCodecL( *audioStream ),
       
  1205                                  KErrNotFound )
       
  1206     
       
  1207     CleanupStack::PopAndDestroy( audioStream );
       
  1208     }
       
  1209     
       
  1210 
       
  1211 // -----------------------------------------------------------------------------
       
  1212 //
       
  1213 // -----------------------------------------------------------------------------
       
  1214 //
       
  1215 void UT_CMusEngClipSession::UT_AddVideoCodecLL()
       
  1216     {
       
  1217     // Check that all the codecs are replaced with H263 codec if other end
       
  1218     // does not support H264
       
  1219     //
       
  1220     delete iClipSession->iVideoCodecList;
       
  1221     iClipSession->iVideoCodecList = NULL;
       
  1222     iClipSession->iVideoCodecList = KMceSDPNameH263().AllocL();
       
  1223     
       
  1224     CMceVideoStream* videoStream = CMceVideoStream::NewLC();
       
  1225     
       
  1226     videoStream->InitializeL( iClipSession->iManager );
       
  1227     
       
  1228     EUNIT_ASSERT( videoStream->Codecs().Count() > 1 )
       
  1229     
       
  1230     iClipSession->AddVideoCodecL( *videoStream );
       
  1231     
       
  1232     EUNIT_ASSERT( videoStream->Codecs().Count() == 1 )
       
  1233     EUNIT_ASSERT( videoStream->Codecs()[0]->SdpName() == KMceSDPNameH2632000() )
       
  1234     
       
  1235     // Check that all codecs are replaced with H264 codec if other end
       
  1236     // supports it
       
  1237     //
       
  1238     _LIT8( KMusTestCodecListDelim, ";" );
       
  1239     delete iClipSession->iVideoCodecList;
       
  1240     iClipSession->iVideoCodecList = NULL;
       
  1241     iClipSession->iVideoCodecList = 
       
  1242         HBufC8::NewL( KMceSDPNameH263().Length() + 
       
  1243                       KMceSDPNameH264().Length() + 
       
  1244                       KMusTestCodecListDelim().Length() );
       
  1245     iClipSession->iVideoCodecList->Des().Copy( KMceSDPNameH263() );
       
  1246     iClipSession->iVideoCodecList->Des().Append( KMusTestCodecListDelim() );
       
  1247     iClipSession->iVideoCodecList->Des().Append( KMceSDPNameH264() );
       
  1248     iClipSession->AddVideoCodecL( *videoStream );
       
  1249     
       
  1250     EUNIT_ASSERT( videoStream->Codecs().Count() == 1 )
       
  1251     EUNIT_ASSERT( videoStream->Codecs()[0]->SdpName() == KMceSDPNameH264() )
       
  1252     
       
  1253     // Check that function leaves  if there is no H264 codec
       
  1254     //
       
  1255     iClipSession->iManager->iSupportedVideoCodecs.ResetAndDestroy();
       
  1256     
       
  1257     EUNIT_ASSERT_SPECIFIC_LEAVE( iClipSession->AddVideoCodecL( *videoStream ),
       
  1258                                  KErrNotFound )
       
  1259     
       
  1260     CleanupStack::PopAndDestroy( videoStream );
       
  1261     }
       
  1262     
       
  1263 
       
  1264 // -----------------------------------------------------------------------------
       
  1265 //
       
  1266 // -----------------------------------------------------------------------------
       
  1267 //
       
  1268 void UT_CMusEngClipSession::UT_HasClipEndedL()
       
  1269     {
       
  1270     // Try before establishing the session
       
  1271     EUNIT_ASSERT( !iClipSession->HasClipEnded() )
       
  1272     
       
  1273     // Try with session, but without video out stream 
       
  1274     
       
  1275     CSIPProfile* profile = iClipSession->iSipProfileHandler->Profile();
       
  1276   
       
  1277     iClipSession->iSession = CMceOutSession::NewL( 
       
  1278                                     *(iClipSession->iManager),
       
  1279                                     *profile,
       
  1280                                     KTestRecipientSipUri8() ); 
       
  1281     
       
  1282     EUNIT_ASSERT( !iClipSession->HasClipEnded() )
       
  1283     
       
  1284     // Try with video out stream without source...
       
  1285     CMceVideoStream* videoOut = CMceVideoStream::NewLC();
       
  1286     
       
  1287     videoOut->AddSinkL( CMceRtpSink::NewLC() );
       
  1288     CleanupStack::Pop();
       
  1289      
       
  1290     iClipSession->iSession->AddStreamL( videoOut );
       
  1291     CleanupStack::Pop( videoOut );
       
  1292     
       
  1293     EUNIT_ASSERT( !iClipSession->HasClipEnded() )
       
  1294     
       
  1295     // And with enabled source and stream     
       
  1296     videoOut->SetSourceL( CMceFileSource::NewLC( *iClipSession->iManager,
       
  1297                                                  iClipSession->iFileName ) );
       
  1298     CleanupStack::Pop();
       
  1299     
       
  1300     EUNIT_ASSERT( !iClipSession->HasClipEnded() )
       
  1301     
       
  1302     // try with different position and duration
       
  1303     (static_cast<CMceFileSource*> (videoOut->Source()))->iPosition = 90;
       
  1304     (static_cast<CMceFileSource*> (videoOut->Source()))->iDuration = 111;
       
  1305     EUNIT_ASSERT( !iClipSession->HasClipEnded() )
       
  1306     
       
  1307     // Disapling source
       
  1308     (static_cast<CMceFileSource*> (videoOut->Source()))->DisableL();
       
  1309     EUNIT_ASSERT( !iClipSession->HasClipEnded() )
       
  1310 
       
  1311     // Disapling stream
       
  1312     videoOut->iState = CMceMediaStream::EDisabled;
       
  1313     EUNIT_ASSERT( !iClipSession->HasClipEnded() )
       
  1314        
       
  1315     // and finaly try with "real" end of clip 
       
  1316     (static_cast<CMceFileSource*> (videoOut->Source()))->iPosition = 0;
       
  1317     (static_cast<CMceFileSource*> (videoOut->Source()))->iDuration = 111;
       
  1318     
       
  1319     EUNIT_ASSERT( iClipSession->HasClipEnded() )
       
  1320     }
       
  1321     
       
  1322 
       
  1323 // -----------------------------------------------------------------------------
       
  1324 //
       
  1325 // -----------------------------------------------------------------------------
       
  1326 //
       
  1327 void UT_CMusEngClipSession::UT_ConstructAudioStructureLL()
       
  1328     {
       
  1329     
       
  1330     CMceStreamBundle* localBundle = 
       
  1331                             CMceStreamBundle::NewLC( CMceStreamBundle::ELS );
       
  1332    
       
  1333     // Check that audio structure cannot be constructed before 
       
  1334     // creating the session
       
  1335     EUNIT_ASSERT_SPECIFIC_LEAVE( 
       
  1336                 iClipSession->ConstructAudioStructureL( *localBundle ),
       
  1337                 KErrNotReady )
       
  1338     
       
  1339     // Try without a file source
       
  1340     
       
  1341     CSIPProfile* profile = iClipSession->iSipProfileHandler->Profile();
       
  1342   
       
  1343     iClipSession->iSession = CMceOutSession::NewL( 
       
  1344                                     *(iClipSession->iManager),
       
  1345                                     *profile,
       
  1346                                     KTestRecipientSipUri8() );
       
  1347     
       
  1348     EUNIT_ASSERT_SPECIFIC_LEAVE( 
       
  1349                 iClipSession->ConstructAudioStructureL( *localBundle ),
       
  1350                 KErrNotFound )
       
  1351     
       
  1352     // Normal case
       
  1353     
       
  1354     CMceVideoStream* videoOut = CMceVideoStream::NewLC();
       
  1355     
       
  1356     videoOut->AddSinkL( CMceRtpSink::NewLC() );
       
  1357     CleanupStack::Pop();
       
  1358     
       
  1359     videoOut->SetSourceL( CMceFileSource::NewLC( *iClipSession->iManager,
       
  1360                                                  iClipSession->iFileName ) );
       
  1361     CleanupStack::Pop();                                             
       
  1362      
       
  1363     iClipSession->iSession->AddStreamL( videoOut );
       
  1364     CleanupStack::Pop( videoOut );
       
  1365       
       
  1366     iClipSession->ConstructAudioStructureL( *localBundle );
       
  1367     
       
  1368     EUNIT_ASSERT( iClipSession->iSession->Streams().Count() == 3 )
       
  1369     EUNIT_ASSERT( iClipSession->iSession->Streams()[1]->Type() == KMceAudio )  
       
  1370     EUNIT_ASSERT( iClipSession->iSession->Streams()[2]->Type() == KMceAudio ) 
       
  1371     EUNIT_ASSERT( iClipSession->iSession->Streams()[1]->Source() == 
       
  1372                   videoOut->Source() )  
       
  1373     EUNIT_ASSERT( iClipSession->iSession->Streams()[2]->Source() == 
       
  1374                   videoOut->Source() )
       
  1375     EUNIT_ASSERT( iClipSession->iSession->Streams()[1]->Sinks().Count() == 1 )
       
  1376     EUNIT_ASSERT( iClipSession->iSession->Streams()[2]->Sinks().Count() == 1 )
       
  1377     EUNIT_ASSERT( iClipSession->iSession->Streams()[1]->Sinks()[0]->Type() ==
       
  1378                   KMceRTPSink )
       
  1379     EUNIT_ASSERT( iClipSession->iSession->Streams()[2]->Sinks()[0]->Type() ==
       
  1380                   KMceSpeakerSink )                         
       
  1381     
       
  1382     // Check that only stream with speaker has been added to a bundle
       
  1383     EUNIT_ASSERT( localBundle->Streams().Count() == 1 )
       
  1384     EUNIT_ASSERT( localBundle->Streams()[0]->Type() == KMceAudio )
       
  1385     EUNIT_ASSERT( localBundle->Streams()[0]->Sinks().Count() == 1 )
       
  1386     EUNIT_ASSERT( localBundle->Streams()[0]->Sinks()[0]->Type() == 
       
  1387                   KMceSpeakerSink )
       
  1388     
       
  1389     CleanupStack::PopAndDestroy( localBundle );
       
  1390     }
       
  1391 
       
  1392 
       
  1393 // -----------------------------------------------------------------------------
       
  1394 // Check that audio is not constructed in operator variant
       
  1395 // -----------------------------------------------------------------------------
       
  1396 //
       
  1397 void UT_CMusEngClipSession::UT_ConstructAudioStructureL_OperatorVariantL()
       
  1398     { 
       
  1399     iClipSession->iOperatorVariant = ETrue;
       
  1400    	CSIPProfile* profile = iClipSession->iSipProfileHandler->Profile();
       
  1401     delete profile->iArray;
       
  1402     profile->iArray = NULL;
       
  1403     profile->iArray = new ( ELeave ) CDesC8ArrayFlat( 1 );
       
  1404     profile->iArray->AppendL( KMusSipUri );
       
  1405   
       
  1406     // Establish session, ConstructAudioStructureL gets called
       
  1407     ESTABLISH_OUT_SESSION( iClipSession );
       
  1408     
       
  1409     // Check that only two video streams has been constructed
       
  1410     EUNIT_ASSERT_EQUALS( iClipSession->iSession->Streams().Count(), 2 )
       
  1411     EUNIT_ASSERT_EQUALS( iClipSession->iSession->Streams()[0]->Type(), 
       
  1412                          KMceVideo )  
       
  1413     EUNIT_ASSERT_EQUALS( iClipSession->iSession->Streams()[1]->Type(),
       
  1414                          KMceVideo ) 
       
  1415     
       
  1416     // Check that no bundles has been constructed
       
  1417     EUNIT_ASSERT_EQUALS( iClipSession->iSession->Bundles().Count(), 0 )
       
  1418     }
       
  1419 
       
  1420 
       
  1421 // -----------------------------------------------------------------------------
       
  1422 // 
       
  1423 // -----------------------------------------------------------------------------
       
  1424 //
       
  1425 void UT_CMusEngClipSession::UT_EstablishSessionLL()
       
  1426     {
       
  1427     iClipSession->SetClipL( KTestAvcVideoFileName() );
       
  1428 
       
  1429     // Try to establish, must fail, because of missing session
       
  1430     TRAPD( error, iClipSession->EstablishSessionL() );
       
  1431     MUS_TEST_FORWARD_ALLOC_FAILURE( error );
       
  1432     EUNIT_ASSERT( error == KErrNotReady );
       
  1433     
       
  1434     EUNIT_ASSERT( iClipSession->iVideoCodecList );
       
  1435 
       
  1436     ///////
       
  1437     // 1.Test that in case the peer party supports H264, no transcoding is needed
       
  1438     
       
  1439     // Call to CMusEngOutMceSession::InviteL leads to call to EstablishL
       
  1440     iClipSession->InviteL( KTestRecipientSipUri );
       
  1441     
       
  1442     const RPointerArray<CMceMediaStream>& streams = iClipSession->iSession->Streams();
       
  1443 
       
  1444     for ( TInt i = 0; i < streams.Count(); ++i )
       
  1445          {
       
  1446          if ( streams[i]->Type() == KMceVideo )
       
  1447              {
       
  1448              
       
  1449              CMceVideoStream* videoStream = static_cast<CMceVideoStream*>( streams[i] );
       
  1450              const RPointerArray<CMceVideoCodec> codecs = videoStream->Codecs();
       
  1451              EUNIT_ASSERT_EQUALS( codecs.Count(), 1 )
       
  1452              EUNIT_ASSERT( codecs[0]->SdpName().FindF( KMceSDPNameH264() ) >= 0 )
       
  1453              
       
  1454              }
       
  1455          }
       
  1456 
       
  1457     EUNIT_ASSERT( !iObserver->iTranscodingNeededCalled )             
       
  1458     
       
  1459     ///////
       
  1460     // 2.Test the case when we don't know whether peer supports H264, 
       
  1461     // transcoding is needed, H264 codec has to be removed from the codec list
       
  1462 
       
  1463     delete iClipSession->iSession;
       
  1464     iClipSession->iSession = NULL;
       
  1465     
       
  1466     delete iClipSession->iVideoCodecList;
       
  1467     iClipSession->iVideoCodecList = NULL;
       
  1468     
       
  1469     // Call to CMusEngOutMceSession::InviteL leads to call to EstablishL
       
  1470     iClipSession->InviteL( KTestRecipientSipUri );
       
  1471 
       
  1472     const RPointerArray<CMceMediaStream>& streams2 = iClipSession->iSession->Streams();
       
  1473 
       
  1474     for ( TInt i = 0; i < streams2.Count(); ++i )
       
  1475          {
       
  1476          if ( streams2[i]->Type() == KMceVideo )
       
  1477              {
       
  1478              CMceVideoStream* videoStream = static_cast<CMceVideoStream*>( streams2[i] );
       
  1479              const RPointerArray<CMceVideoCodec> codecs = videoStream->Codecs();
       
  1480              EUNIT_ASSERT_EQUALS( codecs.Count(), 1 )
       
  1481              EUNIT_ASSERT( codecs[0]->SdpName().FindF( KMceSDPNameH263() ) >= 0 )
       
  1482              }
       
  1483          }
       
  1484  
       
  1485     EUNIT_ASSERT( iObserver->iTranscodingNeededCalled )
       
  1486     
       
  1487     
       
  1488     ///////
       
  1489     // 3.Test that if peer doesn't supports H264, transcoding is needed
       
  1490     // H264 codec has to be removed from the codec list
       
  1491 
       
  1492     iObserver->iTranscodingNeededCalled = EFalse;
       
  1493     
       
  1494     delete iClipSession->iSession;
       
  1495     iClipSession->iSession = NULL;
       
  1496      
       
  1497     iClipSession->iVideoCodecList = KMceSDPNameH263().AllocL();
       
  1498     
       
  1499     // Call to CMusEngOutMceSession::InviteL leads to call to EstablishL
       
  1500     iClipSession->InviteL( KTestRecipientSipUri );
       
  1501 
       
  1502     const RPointerArray<CMceMediaStream>& streams3 = iClipSession->iSession->Streams();
       
  1503 
       
  1504     for ( TInt i = 0; i < streams3.Count(); ++i )
       
  1505          {
       
  1506          if ( streams2[i]->Type() == KMceVideo )
       
  1507              {
       
  1508              CMceVideoStream* videoStream = static_cast<CMceVideoStream*>( streams3[i] );
       
  1509              const RPointerArray<CMceVideoCodec> codecs = videoStream->Codecs();
       
  1510              EUNIT_ASSERT_EQUALS( codecs.Count(), 1 )
       
  1511              EUNIT_ASSERT( codecs[0]->SdpName().FindF( KMceSDPNameH263() ) >= 0 )
       
  1512              }
       
  1513          }
       
  1514   
       
  1515     EUNIT_ASSERT( iObserver->iTranscodingNeededCalled )
       
  1516           
       
  1517     }
       
  1518 
       
  1519 
       
  1520 //  TEST TABLE
       
  1521 
       
  1522 EUNIT_BEGIN_TEST_TABLE(
       
  1523     UT_CMusEngClipSession,
       
  1524     "UT_CMusEngClipSesssion",
       
  1525     "UNIT" )
       
  1526 
       
  1527 EUNIT_TEST(
       
  1528     "NewL - test ",
       
  1529     "CMusEngClipSession",
       
  1530     "NewL",
       
  1531     "FUNCTIONALITY",
       
  1532     SetupL, UT_NewLL, Teardown)
       
  1533 
       
  1534 EUNIT_TEST(
       
  1535     "SetClipL - test ",
       
  1536     "CMusEngClipSession",
       
  1537     "AetClipL",
       
  1538     "FUNCTIONALITY",
       
  1539     SetupL, UT_SetClipLL, Teardown)
       
  1540 
       
  1541 EUNIT_TEST(
       
  1542     "FastForwardL - test ",
       
  1543     "CMusEngClipSession",
       
  1544     "FastForwardL",
       
  1545     "FUNCTIONALITY",
       
  1546     SetupL, UT_FastForwardLL, Teardown)
       
  1547 
       
  1548 EUNIT_TEST(
       
  1549     "FastRewindL - test ",
       
  1550     "CMusEngClipSession",
       
  1551     "FastRewindL",
       
  1552     "FUNCTIONALITY",
       
  1553     SetupL, UT_FastRewindLL, Teardown)
       
  1554 
       
  1555 EUNIT_TEST(
       
  1556     "PositionL - test ",
       
  1557     "CMusEngClipSession",
       
  1558     "PositionL",
       
  1559     "FUNCTIONALITY",
       
  1560     SetupL, UT_PositionLL, Teardown)
       
  1561 
       
  1562 EUNIT_TEST(
       
  1563     "DurationL - test ",
       
  1564     "CMusEngClipSession",
       
  1565     "DurationL",
       
  1566     "FUNCTIONALITY",
       
  1567     SetupL, UT_DurationLL, Teardown)
       
  1568 
       
  1569 EUNIT_TEST(
       
  1570     "SetPositionL - test ",
       
  1571     "CMusEngClipSession",
       
  1572     "SetPositionL",
       
  1573     "FUNCTIONALITY",
       
  1574     SetupL, UT_SetPositionLL, Teardown)
       
  1575     
       
  1576 EUNIT_TEST(
       
  1577     "TranscodeL - To AVC test ",
       
  1578     "CMusEngClipSession",
       
  1579     "TranscodeL",
       
  1580     "FUNCTIONALITY",
       
  1581     SetupL, UT_TranscodeLToAvcL, Teardown)
       
  1582 
       
  1583 EUNIT_TEST(
       
  1584     "TranscodeL - To H263 test ",
       
  1585     "CMusEngClipSession",
       
  1586     "TranscodeL",
       
  1587     "FUNCTIONALITY",
       
  1588     Setup2L, UT_TranscodeLToH263L, Teardown)
       
  1589     
       
  1590 EUNIT_TEST(
       
  1591     "CancelTranscodeL - test ",
       
  1592     "CMusEngClipSession",
       
  1593     "CancelTranscodeL",
       
  1594     "FUNCTIONALITY",
       
  1595     SetupL, UT_CancelTranscodeLL, Teardown)
       
  1596     
       
  1597 EUNIT_TEST(
       
  1598     "PlayL - test ",
       
  1599     "CMusEngClipSession",
       
  1600     "PlayL",
       
  1601     "FUNCTIONALITY",
       
  1602     SetupL, UT_PlayLL, Teardown)
       
  1603 
       
  1604 EUNIT_TEST(
       
  1605     "PauseL - test ",
       
  1606     "CMusEngClipSession",
       
  1607     "PauseL",
       
  1608     "FUNCTIONALITY",
       
  1609     SetupL, UT_PauseLL, Teardown)
       
  1610 
       
  1611 EUNIT_TEST(
       
  1612     "IsPlayingL - test ",
       
  1613     "CMusEngClipSession",
       
  1614     "IsPlayingL",
       
  1615     "FUNCTIONALITY",
       
  1616     SetupL, UT_IsPlayingLL, Teardown)
       
  1617 
       
  1618 EUNIT_TEST(
       
  1619     "CompleteSessionStructureL - test ",
       
  1620     "CMusEngClipSession",
       
  1621     "CompleteSessionStructureL",
       
  1622     "FUNCTIONALITY",
       
  1623     SetupL, UT_CompleteSessionStructureLL, Teardown)
       
  1624 
       
  1625 EUNIT_TEST(
       
  1626     "StreamStateChangedL() - test ",
       
  1627     "CMusEngClipSession",
       
  1628     "StreamStateChangedL()",
       
  1629     "FUNCTIONALITY",
       
  1630     SetupL, UT_StreamStateChangedL, Teardown)
       
  1631     
       
  1632 EUNIT_TEST(
       
  1633     "StreamStateChangedL( source ) - test ",
       
  1634     "CMusEngClipSession",
       
  1635     "StreamStateChangedL( source )",
       
  1636     "FUNCTIONALITY",
       
  1637     SetupL, UT_StreamStateChangedWithSourceL, Teardown)
       
  1638 
       
  1639 EUNIT_TEST(
       
  1640     "StreamStateChangedL( sink ) - test ",
       
  1641     "CMusEngClipSession",
       
  1642     "StreamStateChangedL( sink )",
       
  1643     "FUNCTIONALITY",
       
  1644     SetupL, UT_StreamStateChangedWithSinkL, Teardown)
       
  1645         
       
  1646 EUNIT_TEST(
       
  1647     "AddAmrCodecL - test ",
       
  1648     "CMusEngClipSession",
       
  1649     "AddAmrCodecL",
       
  1650     "FUNCTIONALITY",
       
  1651     SetupL, UT_AddAmrCodecLL, Teardown)
       
  1652 
       
  1653 EUNIT_TEST(
       
  1654     "AddVideoCodecL - test ",
       
  1655     "CMusEngClipSession",
       
  1656     "AddVideoCodecL",
       
  1657     "FUNCTIONALITY",
       
  1658     SetupL, UT_AddVideoCodecLL, Teardown)
       
  1659     
       
  1660 EUNIT_TEST(
       
  1661     "HasClipEnded - test ",
       
  1662     "CMusEngClipSession",
       
  1663     "HasClipEnded",
       
  1664     "FUNCTIONALITY",
       
  1665     SetupL, UT_HasClipEndedL, Teardown)
       
  1666 
       
  1667 EUNIT_TEST(
       
  1668     "ConstructAudioStructureL - test ",
       
  1669     "CMusEngClipSession",
       
  1670     "ConstructAudioStructureL",
       
  1671     "FUNCTIONALITY",
       
  1672     SetupL, UT_ConstructAudioStructureLL, Teardown)
       
  1673 
       
  1674 EUNIT_TEST(
       
  1675     "ConstructAudioStructureL - test operator specific behavior ",
       
  1676     "CMusEngClipSession",
       
  1677     "ConstructAudioStructureL",
       
  1678     "FUNCTIONALITY",
       
  1679     SetupL, UT_ConstructAudioStructureL_OperatorVariantL, Teardown)    
       
  1680 
       
  1681 EUNIT_TEST(
       
  1682     "EstablishSessionL - test ",
       
  1683     "CMusEngClipSession",
       
  1684     "EstablishSessionL",
       
  1685     "FUNCTIONALITY",
       
  1686     SetupL, UT_EstablishSessionLL, Teardown)    
       
  1687 
       
  1688         
       
  1689 EUNIT_END_TEST_TABLE
       
  1690 
       
  1691 //  END OF FILE
       
  1692 
       
  1693