mmsharing/mmshengine/tsrc/ut_engine/src/ut_musengclipsession.cpp
branchRCL_3
changeset 33 bc78a40cd63c
parent 32 73a1feb507fb
child 38 ac48f0cc9f9c
equal deleted inserted replaced
32:73a1feb507fb 33:bc78a40cd63c
    21 #include "musengstubs.h"
    21 #include "musengstubs.h"
    22 #include "musengtestdefs.h"
    22 #include "musengtestdefs.h"
    23 #include "musengclipsession.h"
    23 #include "musengclipsession.h"
    24 #include "mussipprofilehandler.h"
    24 #include "mussipprofilehandler.h"
    25 #include "musengmceutils.h"
    25 #include "musengmceutils.h"
    26 #include "mussessionproperties.h"
    26 
    27 
    27 
    28 //  SYSTEM INCLUDES
    28 //  SYSTEM INCLUDES
    29 #include <lcvideoplayer.h>
    29 #include <digia/eunit/eunitmacros.h>
    30 #include <lcsourcefilecontrol.h>
       
    31 #include <eunitmacros.h>
       
    32 #include <mceoutsession.h>
    30 #include <mceoutsession.h>
    33 #include <mcestreambundle.h>
    31 #include <mcestreambundle.h>
    34 #include <mcevideostream.h>
    32 #include <mcevideostream.h>
    35 #include <mceaudiostream.h>
    33 #include <mceaudiostream.h>
    36 #include <mcefilesource.h>
    34 #include <mcefilesource.h>
    41 #include <mcevideocodec.h>
    39 #include <mcevideocodec.h>
    42 #include <mceamrcodec.h>
    40 #include <mceamrcodec.h>
    43 #include <drmcommon.h>
    41 #include <drmcommon.h>
    44 #include <sipprofile.h>
    42 #include <sipprofile.h>
    45 #include <sipstrings.h>
    43 #include <sipstrings.h>
    46 #include <e32property.h>
       
    47 
    44 
    48 
    45 
    49 // -----------------------------------------------------------------------------
    46 // -----------------------------------------------------------------------------
    50 //
    47 //
    51 // -----------------------------------------------------------------------------
    48 // -----------------------------------------------------------------------------
   107 //
   104 //
   108 // -----------------------------------------------------------------------------
   105 // -----------------------------------------------------------------------------
   109 //
   106 //
   110 void UT_CMusEngClipSession::SetupL()
   107 void UT_CMusEngClipSession::SetupL()
   111     {
   108     {
   112     iLcSessionObserver = new( ELeave )CLcSessionObserverStub;
   109     iObserver = new( ELeave ) CMusEngObserverStub;
   113     iLcUiProvider = new( ELeave )CLcUiProviderStub;
   110     iClipSession = CMusEngClipSession::NewL( TRect(0,0, 100,100),
   114     iAudioRoutingObserver = new( ELeave )CMusEngObserverStub; 
   111                                              *iObserver,
   115     
   112                                              *iObserver,
   116     iClipSession = CMusEngClipSession::NewL();
   113                                              *iObserver );
   117     iClipSession->SetLcSessionObserver( iLcSessionObserver );
   114     iClipSession->SetClipL( KTestVideoFileName );
   118     iClipSession->SetLcUiProvider( iLcUiProvider );    
       
   119     iClipSession->LocalVideoPlayer()->LcSourceFileControl()->SetLcFileNameL(
       
   120         KTestVideoFileName() );
       
   121     delete iClipSession->iVideoCodecList;
       
   122     iClipSession->iVideoCodecList = NULL;
       
   123     iClipSession->iVideoCodecList = KMceSDPNameH264().AllocL();
   115     iClipSession->iVideoCodecList = KMceSDPNameH264().AllocL();
   124 
   116 
   125     SIPStrings::OpenL();
   117     SIPStrings::OpenL();
   126     
   118     }
   127     User::LeaveIfError( RProperty::Set( NMusSessionApi::KCategoryUid,
   119 
   128                                         NMusSessionApi::KRemoteSipAddress,
   120 // -----------------------------------------------------------------------------
   129                                         KTestRecipientSipUri ) );
   121 //
   130     }
   122 // -----------------------------------------------------------------------------
   131 
   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     }
   132     
   136     
   133 // -----------------------------------------------------------------------------
   137 // -----------------------------------------------------------------------------
   134 //
   138 //
   135 // -----------------------------------------------------------------------------
   139 // -----------------------------------------------------------------------------
   136 //
   140 //
   137 void UT_CMusEngClipSession::Teardown()
   141 void UT_CMusEngClipSession::Teardown()
   138     {
   142     {
   139     SIPStrings::Close();
   143     SIPStrings::Close();
   140     delete iClipSession;
   144     delete iClipSession;
   141     delete iLcSessionObserver;
   145     delete iObserver;
   142     delete iLcUiProvider;
       
   143     delete iAudioRoutingObserver;
       
   144     PropertyHelper::Close();
       
   145     }
   146     }
   146 
   147 
   147 
   148 
   148 
   149 
   149 // TEST CASES
   150 // TEST CASES
   150 
   151 
       
   152 
   151 // -----------------------------------------------------------------------------
   153 // -----------------------------------------------------------------------------
   152 //
   154 //
   153 // -----------------------------------------------------------------------------
   155 // -----------------------------------------------------------------------------
   154 //
   156 //
   155 void UT_CMusEngClipSession::UT_NewLL()
   157 void UT_CMusEngClipSession::UT_NewLL()
   156     {
   158     {
   157     EUNIT_ASSERT( iClipSession )
   159     EUNIT_ASSERT( iClipSession )
       
   160     EUNIT_ASSERT( iClipSession->iFileName != KNullDesC() )
   158     EUNIT_ASSERT( !iClipSession->iSession )
   161     EUNIT_ASSERT( !iClipSession->iSession )
   159     EUNIT_ASSERT( iClipSession->iMceManagerUid == TUid::Uid( KMusUiUid ) );
   162     }
   160     }
   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     iClipSession->iRewindedToBeginning = EFalse;
       
   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();
   161         
   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         
   162 
   818 
   163 // -----------------------------------------------------------------------------
   819 // -----------------------------------------------------------------------------
   164 //
   820 //
   165 // -----------------------------------------------------------------------------
   821 // -----------------------------------------------------------------------------
   166 //
   822 //
   167 void UT_CMusEngClipSession::UT_CompleteSessionStructureLL()
   823 void UT_CMusEngClipSession::UT_CompleteSessionStructureLL()
   168     {   
   824     {
       
   825     
   169     CMceStreamBundle* localBundle = 
   826     CMceStreamBundle* localBundle = 
   170         CMceStreamBundle::NewLC( CMceStreamBundle::ELS );
   827                             CMceStreamBundle::NewLC( CMceStreamBundle::ELS );
   171     
   828     
   172     // Check that structure cannot be completed before creating the session
   829     // Check that structure cannot be completed before creating the session
   173     EUNIT_ASSERT_SPECIFIC_LEAVE( 
   830     EUNIT_ASSERT_SPECIFIC_LEAVE( 
   174                 iClipSession->CompleteSessionStructureL( *localBundle ),
   831                 iClipSession->CompleteSessionStructureL( *localBundle ),
   175                 KErrNotReady )
   832                 KErrNotReady )
   176     
   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     
   177     // Normal case
   847     // Normal case
   178     CSIPProfile* profile = iClipSession->iSipProfileHandler->Profile();          
   848     iClipSession->iFileName = KTestVideoFileName();                     
   179     iClipSession->iSession = CMceOutSession::NewL( 
       
   180         *iClipSession->iManager, *profile, KTestRecipientSipUri8() );
       
   181     
       
   182     iClipSession->CompleteSessionStructureL( *localBundle );
   849     iClipSession->CompleteSessionStructureL( *localBundle );
       
   850     
   183     EUNIT_ASSERT( iClipSession->iSession->Streams().Count() == 3 )
   851     EUNIT_ASSERT( iClipSession->iSession->Streams().Count() == 3 )
   184     EUNIT_ASSERT( iClipSession->iSession->Streams()[0]->Type() == KMceVideo )
   852     EUNIT_ASSERT( iClipSession->iSession->Streams()[0]->Type() == KMceVideo )
   185     EUNIT_ASSERT( iClipSession->iSession->Streams()[0]->Source() )
   853     EUNIT_ASSERT( iClipSession->iSession->Streams()[0]->Source() )
   186     EUNIT_ASSERT( iClipSession->iSession->Streams()[0]->Source()->Type() ==
   854     EUNIT_ASSERT( iClipSession->iSession->Streams()[0]->Source()->Type() ==
   187                   KMceFileSource )             
   855                   KMceFileSource )
       
   856     EUNIT_ASSERT( !iClipSession->IsPlayingL() )              
   188     EUNIT_ASSERT( iClipSession->iSession->Streams()[0]->Sinks().Count() == 1 )
   857     EUNIT_ASSERT( iClipSession->iSession->Streams()[0]->Sinks().Count() == 1 )
   189     EUNIT_ASSERT( iClipSession->iSession->Streams()[0]->Sinks()[0]->Type() ==
   858     EUNIT_ASSERT( iClipSession->iSession->Streams()[0]->Sinks()[0]->Type() ==
   190                   KMceRTPSink )
   859                   KMceRTPSink )
   191     
   860     
   192     // Check that only stream with speaker has been added to a bundle
   861     // Check that only stream with speaker has been added to a bundle
   212     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   881     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   213                                                             *videoStream );
   882                                                             *videoStream );
   214     CleanupStack::PopAndDestroy( videoStream );
   883     CleanupStack::PopAndDestroy( videoStream );
   215     
   884     
   216     // Simulate sending invite
   885     // Simulate sending invite
   217     iClipSession->EstablishLcSessionL();
   886     iClipSession->InviteL( KTestRecipientSipUri() );
   218    
   887    
   219     // Try all the stream states
   888     // Try all the stream states
   220     CMceMediaStream* changedStream = iClipSession->iSession->Streams()[0];
   889     CMceMediaStream* changedStream = iClipSession->iSession->Streams()[0];
   221     
   890     
   222     // EUninitialized, stream is created, unexpected change, nothing happens
   891     // EUninitialized, stream is created, unexpected change, nothing happens
   223     changedStream->iState = CMceMediaStream::EUninitialized;
   892     changedStream->iState = CMceMediaStream::EUninitialized;
   224     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   893     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   225                                                             *changedStream );
   894                                                             *changedStream );
   226     EUNIT_ASSERT( iLcSessionObserver->IsReseted() )
   895     EUNIT_ASSERT( iObserver->IsReseted() )
   227     
   896     
   228     // EInitialized, stream is initialized
   897     // EInitialized, stream is initialized
   229     changedStream->iState = CMceMediaStream::EInitialized;
   898     changedStream->iState = CMceMediaStream::EInitialized;
   230     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   899     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   231                                                             *changedStream );
   900                                                             *changedStream );
   232     EUNIT_ASSERT( iLcSessionObserver->IsReseted() )
   901     EUNIT_ASSERT( iObserver->IsReseted() )
   233     
   902     
   234     // EBuffering, stream is buffering
   903     // EBuffering, stream is buffering
   235     changedStream->iState = CMceMediaStream::EBuffering;
   904     changedStream->iState = CMceMediaStream::EBuffering;
   236     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   905     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   237                                                             *changedStream );
   906                                                             *changedStream );
   238     EUNIT_ASSERT( iLcSessionObserver->IsReseted() )
   907     EUNIT_ASSERT( iObserver->IsReseted() )
   239     
   908     
   240     // EIdle, stream is not receiving RTP
   909     // EIdle, stream is not receiving RTP
   241     changedStream->iState = CMceMediaStream::EIdle;
   910     changedStream->iState = CMceMediaStream::EIdle;
   242     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   911     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   243                                                             *changedStream );
   912                                                             *changedStream );
   244     EUNIT_ASSERT( iLcSessionObserver->IsReseted() )
   913     EUNIT_ASSERT( iObserver->iStreamIdleCalled )
   245     
   914     
   246     // EStreaming, stream is streaming
   915     // EStreaming, stream is streaming
   247     changedStream->iState = CMceMediaStream::EStreaming;
   916     changedStream->iState = CMceMediaStream::EStreaming;
   248     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   917     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   249                                                             *changedStream );
   918                                                             *changedStream );
   250     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
   919     EUNIT_ASSERT( iObserver->iStreamStreamingCalled )
   251                          TInt( CLcSessionObserverStub::EPlayerStateChanged ) )
   920     iObserver->Reset();
   252     iLcSessionObserver->Reset();
       
   253     
   921     
   254     // EDisabled, stream is explicitly disabled
   922     // EDisabled, stream is explicitly disabled
   255     changedStream->iState = CMceMediaStream::EDisabled;
   923     changedStream->iState = CMceMediaStream::EDisabled;
   256     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   924     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   257                                                             *changedStream );
   925                                                             *changedStream );
   258     EUNIT_ASSERT( iLcSessionObserver->IsReseted() )
   926     EUNIT_ASSERT( iObserver->IsReseted() )
   259     
   927     
   260     // ENoResources, stream has no needed resources to stream
   928     // ENoResources, stream has no needed resources to stream
   261     changedStream->iState = CMceMediaStream::ENoResources;
   929     changedStream->iState = CMceMediaStream::ENoResources;
   262     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   930     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   263                                                             *changedStream );
   931                                                             *changedStream );
   264     EUNIT_ASSERT( iLcSessionObserver->IsReseted() )
   932     EUNIT_ASSERT( iObserver->IsReseted() )
   265     
   933     
   266     // ETranscodingRequired, stream requires non-realtime transcoding
   934     // ETranscodingRequired, stream requires non-realtime transcoding
   267     changedStream->iState = CMceMediaStream::ETranscodingRequired;
   935     changedStream->iState = CMceMediaStream::ETranscodingRequired;
   268     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   936     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   269                                                             *changedStream );
   937                                                             *changedStream );
   270     EUNIT_ASSERT( iLcSessionObserver->IsReseted() )
   938     EUNIT_ASSERT( iObserver->IsReseted() )
   271     
   939     
   272     // ETranscoding, stream is transcoding in non-realtime
   940     // ETranscoding, stream is transcoding in non-realtime
   273     changedStream->iState = CMceMediaStream::ETranscoding;
   941     changedStream->iState = CMceMediaStream::ETranscoding;
   274     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   942     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   275                                                             *changedStream );
   943                                                             *changedStream );
   276     EUNIT_ASSERT( iLcSessionObserver->IsReseted() )
   944     EUNIT_ASSERT( iObserver->IsReseted() )
   277     }
   945     }
   278     
   946     
   279 
   947 
   280 // -----------------------------------------------------------------------------
   948 // -----------------------------------------------------------------------------
   281 // Although all states are not meaningfull for ClipSession, all states are
   949 // Although all states are not meaningfull for ClipSession, all states are
   292                     *rtpSource );     
   960                     *rtpSource );     
   293     CleanupStack::PopAndDestroy( rtpSource );         
   961     CleanupStack::PopAndDestroy( rtpSource );         
   294     CleanupStack::PopAndDestroy( videoStream );
   962     CleanupStack::PopAndDestroy( videoStream );
   295     
   963     
   296     // Simulate sending invite
   964     // Simulate sending invite
   297     iClipSession->EstablishLcSessionL();
   965     iClipSession->InviteL( KTestRecipientSipUri() );
   298     
   966     
   299     // Try all the non-default stream states
   967     // Try all the non-default stream states
   300     CMceMediaStream* changedStream = iClipSession->iSession->Streams()[0];
   968     CMceMediaStream* changedStream = iClipSession->iSession->Streams()[0];
   301     CMceMediaSource* changedSource = changedStream->Source();
   969     CMceMediaSource* changedSource = changedStream->Source();
   302     
   970     
   303     // EDisabled, end of clip
   971     // EDisabled, end of clip
   304     changedStream->iState = CMceMediaStream::EDisabled;
   972     changedStream->iState = CMceMediaStream::EDisabled;
   305     changedSource->iIsEnabled = EFalse;
   973     changedSource->iIsEnabled = EFalse;
   306     iClipSession->StreamStateChanged( *changedStream, *changedSource );
   974     iClipSession->StreamStateChanged( *changedStream, *changedSource );
   307     
   975     
   308     // TODO: EUNIT_ASSERT( iLcSessionObserver->iEndOfClipCalled )
   976     EUNIT_ASSERT( iObserver->iEndOfClipCalled == ETrue )
   309     changedSource->iIsEnabled = ETrue;
   977     changedSource->iIsEnabled = ETrue;
   310     iLcSessionObserver->Reset();
   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     
   311     
  1038     
   312     // Test default stream state change behavior, remove or change when
  1039     // Test default stream state change behavior, remove or change when
   313     // behavior changes
  1040     // behavior changes
   314     
  1041     
   315     
  1042     
   316     // EUninitialized, stream is created, unexpected change, nothing happens
  1043     // EUninitialized, stream is created, unexpected change, nothing happens
   317     changedStream->iState = CMceMediaStream::EUninitialized;
  1044     changedStream->iState = CMceMediaStream::EUninitialized;
   318     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
  1045     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   319                             *changedStream, *changedSource );
  1046                             *changedStream, *changedSource );
   320     EUNIT_ASSERT( iLcSessionObserver->IsReseted() )
  1047     EUNIT_ASSERT( iObserver->IsReseted() )
   321     
  1048     
   322     // EInitialized, stream is initialized
  1049     // EInitialized, stream is initialized
   323     changedStream->iState = CMceMediaStream::EInitialized;
  1050     changedStream->iState = CMceMediaStream::EInitialized;
   324     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
  1051     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   325                             *changedStream, *changedSource );
  1052                             *changedStream, *changedSource );
   326     EUNIT_ASSERT( iLcSessionObserver->IsReseted() )
  1053     EUNIT_ASSERT( iObserver->IsReseted() )
   327 
  1054 
   328     // Special meaning (Transcoding ready), tested separately
  1055     // Special meaning (Transcoding ready), tested separately
   329     
  1056     
   330     // EBuffering, stream is buffering
  1057     // EBuffering, stream is buffering
   331     changedStream->iState = CMceMediaStream::EBuffering;
  1058     changedStream->iState = CMceMediaStream::EBuffering;
   332     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
  1059     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   333                             *changedStream, *changedSource );
  1060                             *changedStream, *changedSource );
   334     EUNIT_ASSERT( iLcSessionObserver->IsReseted() )
  1061     EUNIT_ASSERT( iObserver->IsReseted() )
   335     
  1062     
   336     // EIdle, stream is not receiving RTP
  1063     // EIdle, stream is not receiving RTP
   337     changedStream->iState = CMceMediaStream::EIdle;
  1064     changedStream->iState = CMceMediaStream::EIdle;
   338     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
  1065     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   339                             *changedStream, *changedSource );
  1066                             *changedStream, *changedSource );
   340     EUNIT_ASSERT( iLcSessionObserver->IsReseted() )
  1067     EUNIT_ASSERT( iObserver->iStreamIdleCalled )
   341     
  1068     
   342     // EStreaming, stream is streaming
  1069     // EStreaming, stream is streaming
   343     changedStream->iState = CMceMediaStream::EStreaming;
  1070     changedStream->iState = CMceMediaStream::EStreaming;
   344     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
  1071     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   345                             *changedStream, *changedSource );
  1072                             *changedStream, *changedSource );
   346     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
  1073     EUNIT_ASSERT( iObserver->iStreamStreamingCalled )
   347                          TInt( CLcSessionObserverStub::EPlayerStateChanged ) )
  1074     iObserver->Reset();
   348     iLcSessionObserver->Reset();
       
   349     
  1075     
   350     // EDisabled, stream is explicitly disabled
  1076     // EDisabled, stream is explicitly disabled
   351     // This state has non-default meaning, tested before defaults
  1077     // This state has non-default meaning, tested before defaults
   352     
  1078     
   353     // ENoResources, stream has no needed resources to stream
  1079     // ENoResources, stream has no needed resources to stream
   354     changedStream->iState = CMceMediaStream::ENoResources;
  1080     changedStream->iState = CMceMediaStream::ENoResources;
   355     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
  1081     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   356                             *changedStream, *changedSource );
  1082                             *changedStream, *changedSource );
   357     EUNIT_ASSERT( iLcSessionObserver->IsReseted() )
  1083     EUNIT_ASSERT( iObserver->IsReseted() )
       
  1084 
       
  1085     
   358     }
  1086     }
   359 
  1087 
   360 
  1088 
   361 // -----------------------------------------------------------------------------
  1089 // -----------------------------------------------------------------------------
   362 // Although all states are not meaningfull for LiveSession, all states are
  1090 // Although all states are not meaningfull for LiveSession, all states are
   372                                                         *CMceRtpSink::NewLC() );
  1100                                                         *CMceRtpSink::NewLC() );
   373     CleanupStack::PopAndDestroy(); // rtp
  1101     CleanupStack::PopAndDestroy(); // rtp
   374     CleanupStack::PopAndDestroy( videoStream );
  1102     CleanupStack::PopAndDestroy( videoStream );
   375     
  1103     
   376     // Simulate sending invite
  1104     // Simulate sending invite
   377     iClipSession->EstablishLcSessionL();
  1105     iClipSession->InviteL( KTestRecipientSipUri() );
   378                                      
  1106                                      
   379     // Test default stream state change behavior
  1107     // Test default stream state change behavior
   380     CMceMediaStream* changedStream = iClipSession->iSession->Streams()[0];
  1108     CMceMediaStream* changedStream = iClipSession->iSession->Streams()[0];
   381     CMceMediaSink* changedSink = changedStream->Sinks()[0];
  1109     CMceMediaSink* changedSink = changedStream->Sinks()[0];
   382 
  1110 
   383     // EUninitialized, stream is created, unexpected change, nothing happens
  1111     // EUninitialized, stream is created, unexpected change, nothing happens
   384     changedStream->iState = CMceMediaStream::EUninitialized;
  1112     changedStream->iState = CMceMediaStream::EUninitialized;
   385     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
  1113     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   386                                                             *changedStream,
  1114                                                             *changedStream,
   387                                                             *changedSink );
  1115                                                             *changedSink );
   388     EUNIT_ASSERT( iLcSessionObserver->IsReseted() )
  1116     EUNIT_ASSERT( iObserver->IsReseted() )
   389     
  1117     
   390     // EInitialized, stream is initialized
  1118     // EInitialized, stream is initialized
   391     changedStream->iState = CMceMediaStream::EInitialized;
  1119     changedStream->iState = CMceMediaStream::EInitialized;
   392     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
  1120     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   393                                                             *changedStream,
  1121                                                             *changedStream,
   394                                                             *changedSink );
  1122                                                             *changedSink );
   395     EUNIT_ASSERT( iLcSessionObserver->IsReseted() )
  1123     EUNIT_ASSERT( iObserver->IsReseted() )
   396     
  1124     
   397     // EBuffering, stream is buffering
  1125     // EBuffering, stream is buffering
   398     changedStream->iState = CMceMediaStream::EBuffering;
  1126     changedStream->iState = CMceMediaStream::EBuffering;
   399     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
  1127     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   400                                                             *changedStream,
  1128                                                             *changedStream,
   401                                                             *changedSink );
  1129                                                             *changedSink );
   402     EUNIT_ASSERT( iLcSessionObserver->IsReseted() )
  1130     EUNIT_ASSERT( iObserver->IsReseted() )
   403     
  1131     
   404     // EIdle, stream is not receiving RTP
  1132     // EIdle, stream is not receiving RTP
   405     changedStream->iState = CMceMediaStream::EIdle;
  1133     changedStream->iState = CMceMediaStream::EIdle;
   406     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
  1134     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   407                                                             *changedStream,
  1135                                                             *changedStream,
   408                                                             *changedSink );
  1136                                                             *changedSink );
   409     EUNIT_ASSERT( iLcSessionObserver->IsReseted() )
  1137     EUNIT_ASSERT( iObserver->iStreamIdleCalled );
   410     
  1138     
   411     // EStreaming, stream is streaming
  1139     // EStreaming, stream is streaming
   412     changedStream->iState = CMceMediaStream::EStreaming;
  1140     changedStream->iState = CMceMediaStream::EStreaming;
   413     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
  1141     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   414                                                             *changedStream,
  1142                                                             *changedStream,
   415                                                             *changedSink );
  1143                                                             *changedSink );
   416     EUNIT_ASSERT_EQUALS( TInt( iLcSessionObserver->iCalledFunction ),
  1144     EUNIT_ASSERT( iObserver->iStreamStreamingCalled )
   417                          TInt( CLcSessionObserverStub::EPlayerStateChanged ) )
  1145     iObserver->Reset();
   418     iLcSessionObserver->Reset();
       
   419     
  1146     
   420     // EDisabled, stream is explicitly disabled
  1147     // EDisabled, stream is explicitly disabled
   421     changedStream->iState = CMceMediaStream::EDisabled;
  1148     changedStream->iState = CMceMediaStream::EDisabled;
   422     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
  1149     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   423                                                             *changedStream,
  1150                                                             *changedStream,
   424                                                             *changedSink );
  1151                                                             *changedSink );
   425     EUNIT_ASSERT( iLcSessionObserver->IsReseted() )
  1152     EUNIT_ASSERT( iObserver->IsReseted() )
   426     
  1153     
   427     // ENoResources, stream has no needed resources to stream
  1154     // ENoResources, stream has no needed resources to stream
   428     changedStream->iState = CMceMediaStream::ENoResources;
  1155     changedStream->iState = CMceMediaStream::ENoResources;
   429     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
  1156     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   430                                                             *changedStream,
  1157                                                             *changedStream,
   431                                                             *changedSink );
  1158                                                             *changedSink );
   432     EUNIT_ASSERT( iLcSessionObserver->IsReseted() )
  1159     EUNIT_ASSERT( iObserver->IsReseted() )
   433                                                             
  1160                                                             
   434     // ETranscodingRequired, stream requires non-realtime transcoding
  1161     // ETranscodingRequired, stream requires non-realtime transcoding
   435     changedStream->iState = CMceMediaStream::ETranscodingRequired;
  1162     changedStream->iState = CMceMediaStream::ETranscodingRequired;
   436     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
  1163     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   437                                                             *changedStream,
  1164                                                             *changedStream,
   438                                                             *changedSink );
  1165                                                             *changedSink );
   439     EUNIT_ASSERT( iLcSessionObserver->IsReseted() )
  1166     EUNIT_ASSERT( iObserver->IsReseted() )
   440     
  1167     
   441     // ETranscoding, stream is transcoding in non-realtime
  1168     // ETranscoding, stream is transcoding in non-realtime
   442     changedStream->iState = CMceMediaStream::ETranscoding;
  1169     changedStream->iState = CMceMediaStream::ETranscoding;
   443     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
  1170     static_cast<MMceStreamObserver*>(iClipSession)->StreamStateChanged( 
   444                                                             *changedStream,
  1171                                                             *changedStream,
   445                                                             *changedSink );
  1172                                                             *changedSink );
   446     EUNIT_ASSERT( iLcSessionObserver->IsReseted() )
  1173     EUNIT_ASSERT( iObserver->IsReseted() )
       
  1174     
   447     }
  1175     }
   448 
  1176 
   449 
  1177 
   450 // -----------------------------------------------------------------------------
  1178 // -----------------------------------------------------------------------------
   451 //
  1179 //
   535 
  1263 
   536 // -----------------------------------------------------------------------------
  1264 // -----------------------------------------------------------------------------
   537 //
  1265 //
   538 // -----------------------------------------------------------------------------
  1266 // -----------------------------------------------------------------------------
   539 //
  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 //
   540 void UT_CMusEngClipSession::UT_ConstructAudioStructureLL()
  1327 void UT_CMusEngClipSession::UT_ConstructAudioStructureLL()
   541     {
  1328     {
   542     
  1329     
   543     CMceStreamBundle* localBundle = 
  1330     CMceStreamBundle* localBundle = 
   544                             CMceStreamBundle::NewLC( CMceStreamBundle::ELS );
  1331                             CMceStreamBundle::NewLC( CMceStreamBundle::ELS );
   567     CMceVideoStream* videoOut = CMceVideoStream::NewLC();
  1354     CMceVideoStream* videoOut = CMceVideoStream::NewLC();
   568     
  1355     
   569     videoOut->AddSinkL( CMceRtpSink::NewLC() );
  1356     videoOut->AddSinkL( CMceRtpSink::NewLC() );
   570     CleanupStack::Pop();
  1357     CleanupStack::Pop();
   571     
  1358     
   572     videoOut->SetSourceL( CMceFileSource::NewLC( 
  1359     videoOut->SetSourceL( CMceFileSource::NewLC( *iClipSession->iManager,
   573         *iClipSession->iManager,
  1360                                                  iClipSession->iFileName ) );
   574         iClipSession->LocalVideoPlayer()->LcSourceFileControl()->LcFileName() ) );
       
   575     CleanupStack::Pop();                                             
  1361     CleanupStack::Pop();                                             
   576      
  1362      
   577     iClipSession->iSession->AddStreamL( videoOut );
  1363     iClipSession->iSession->AddStreamL( videoOut );
   578     CleanupStack::Pop( videoOut );
  1364     CleanupStack::Pop( videoOut );
   579       
  1365       
   636 // 
  1422 // 
   637 // -----------------------------------------------------------------------------
  1423 // -----------------------------------------------------------------------------
   638 //
  1424 //
   639 void UT_CMusEngClipSession::UT_EstablishSessionLL()
  1425 void UT_CMusEngClipSession::UT_EstablishSessionLL()
   640     {
  1426     {
   641     iClipSession->LocalVideoPlayer()->LcSourceFileControl()->SetLcFileNameL(
  1427     iClipSession->SetClipL( KTestAvcVideoFileName() );
   642          KTestAvcVideoFileName() );
       
   643 
  1428 
   644     // Try to establish, must fail, because of missing session
  1429     // Try to establish, must fail, because of missing session
   645     TRAPD( error, iClipSession->EstablishSessionL() );
  1430     TRAPD( error, iClipSession->EstablishSessionL() );
   646     MUS_TEST_FORWARD_ALLOC_FAILURE( error );
  1431     MUS_TEST_FORWARD_ALLOC_FAILURE( error );
   647     EUNIT_ASSERT( error == KErrNotReady );
  1432     EUNIT_ASSERT( error == KErrNotReady );
   650 
  1435 
   651     ///////
  1436     ///////
   652     // 1.Test that in case the peer party supports H264, no transcoding is needed
  1437     // 1.Test that in case the peer party supports H264, no transcoding is needed
   653     
  1438     
   654     // Call to CMusEngOutMceSession::InviteL leads to call to EstablishL
  1439     // Call to CMusEngOutMceSession::InviteL leads to call to EstablishL
   655     iClipSession->EstablishLcSessionL();
  1440     iClipSession->InviteL( KTestRecipientSipUri );
   656     
  1441     
   657     const RPointerArray<CMceMediaStream>& streams = iClipSession->iSession->Streams();
  1442     const RPointerArray<CMceMediaStream>& streams = iClipSession->iSession->Streams();
   658 
  1443 
   659     for ( TInt i = 0; i < streams.Count(); ++i )
  1444     for ( TInt i = 0; i < streams.Count(); ++i )
   660          {
  1445          {
   666              EUNIT_ASSERT_EQUALS( codecs.Count(), 1 )
  1451              EUNIT_ASSERT_EQUALS( codecs.Count(), 1 )
   667              EUNIT_ASSERT( codecs[0]->SdpName().FindF( KMceSDPNameH264() ) >= 0 )
  1452              EUNIT_ASSERT( codecs[0]->SdpName().FindF( KMceSDPNameH264() ) >= 0 )
   668              
  1453              
   669              }
  1454              }
   670          }
  1455          }
       
  1456 
       
  1457     EUNIT_ASSERT( !iObserver->iTranscodingNeededCalled )    
       
  1458     EUNIT_ASSERT( !iClipSession->iTranscodingRequiredDueMissingOptions )
   671     
  1459     
   672     ///////
  1460     ///////
   673     // 2.Test the case when we don't know whether peer supports H264, 
  1461     // 2.Test the case when we don't know whether peer supports H264, 
   674     // transcoding is needed => function will leave with KErrNotSupported
  1462     // transcoding is needed, H264 codec has to be removed from the codec list
   675 
  1463 
   676     delete iClipSession->iSession;
  1464     delete iClipSession->iSession;
   677     iClipSession->iSession = NULL;
  1465     iClipSession->iSession = NULL;
   678     
  1466     
   679     delete iClipSession->iVideoCodecList;
  1467     delete iClipSession->iVideoCodecList;
   680     iClipSession->iVideoCodecList = NULL;
  1468     iClipSession->iVideoCodecList = NULL;
   681     
  1469     
   682     MUSENG_EUNIT_ASSERT_SPECIFIC_LEAVE( 
  1470     // Call to CMusEngOutMceSession::InviteL leads to call to EstablishL
   683                    iClipSession->EstablishLcSessionL(),
  1471     iClipSession->InviteL( KTestRecipientSipUri );
   684                    KErrNotSupported )
  1472 
   685     
  1473     const RPointerArray<CMceMediaStream>& streams2 = iClipSession->iSession->Streams();
       
  1474 
       
  1475     for ( TInt i = 0; i < streams2.Count(); ++i )
       
  1476          {
       
  1477          if ( streams2[i]->Type() == KMceVideo )
       
  1478              {
       
  1479              CMceVideoStream* videoStream = static_cast<CMceVideoStream*>( streams2[i] );
       
  1480              const RPointerArray<CMceVideoCodec> codecs = videoStream->Codecs();
       
  1481              EUNIT_ASSERT_EQUALS( codecs.Count(), 1 )
       
  1482              EUNIT_ASSERT( codecs[0]->SdpName().FindF( KMceSDPNameH263() ) >= 0 )
       
  1483              }
       
  1484          }
       
  1485  
       
  1486     EUNIT_ASSERT( iObserver->iTranscodingNeededCalled )
       
  1487     EUNIT_ASSERT( iObserver->iDueUnknowCapas )
       
  1488     EUNIT_ASSERT( iClipSession->iTranscodingRequiredDueMissingOptions )
   686     
  1489     
   687     ///////
  1490     ///////
   688     // 3.Test that if peer doesn't supports H264, transcoding is needed
  1491     // 3. Establish behaves differently at second round in case clip is AVC
   689     // => function will leave with KErrNotSupported
  1492     // and because remote party's capabilities were unknown. Use-case is such
       
  1493     // that AVC is tried to be transcoded first but if it fails, invite is retried
       
  1494     // by using AVC
       
  1495     iObserver->Reset();
       
  1496     iClipSession->InviteL( KTestRecipientSipUri );
       
  1497     const RPointerArray<CMceMediaStream>& testStreams = iClipSession->iSession->Streams();
       
  1498 
       
  1499     for ( TInt i = 0; i < testStreams.Count(); ++i )
       
  1500         {
       
  1501         if ( testStreams[i]->Type() == KMceVideo )
       
  1502             {
       
  1503             CMceVideoStream* videoStream = static_cast<CMceVideoStream*>( testStreams[i] );
       
  1504             const RPointerArray<CMceVideoCodec> codecs = videoStream->Codecs();
       
  1505             EUNIT_ASSERT_EQUALS( codecs.Count(), 1 )
       
  1506             EUNIT_ASSERT( codecs[0]->SdpName().FindF( KMceSDPNameH264() ) >= 0 )
       
  1507             }
       
  1508         }
       
  1509     
       
  1510     EUNIT_ASSERT( !iObserver->iTranscodingNeededCalled )
       
  1511     EUNIT_ASSERT( !iObserver->iDueUnknowCapas )
       
  1512     
       
  1513     ///////
       
  1514     // 4.Test that if peer doesn't supports H264, transcoding is needed
       
  1515     // H264 codec has to be removed from the codec list
       
  1516 
       
  1517     iObserver->iTranscodingNeededCalled = EFalse;
   690     
  1518     
   691     delete iClipSession->iSession;
  1519     delete iClipSession->iSession;
   692     iClipSession->iSession = NULL;
  1520     iClipSession->iSession = NULL;
   693      
  1521      
   694     iClipSession->iVideoCodecList = KMceSDPNameH263().AllocL();
  1522     iClipSession->iVideoCodecList = KMceSDPNameH263().AllocL();
   695     
  1523     
   696     MUSENG_EUNIT_ASSERT_SPECIFIC_LEAVE( 
  1524     // Call to CMusEngOutMceSession::InviteL leads to call to EstablishL
   697                     iClipSession->EstablishLcSessionL(),
  1525     iClipSession->InviteL( KTestRecipientSipUri );
   698                     KErrNotSupported )
  1526 
   699     }
  1527     const RPointerArray<CMceMediaStream>& streams3 = iClipSession->iSession->Streams();
   700 
  1528 
       
  1529     for ( TInt i = 0; i < streams3.Count(); ++i )
       
  1530          {
       
  1531          if ( streams3[i]->Type() == KMceVideo )
       
  1532              {
       
  1533              CMceVideoStream* videoStream = static_cast<CMceVideoStream*>( streams3[i] );
       
  1534              const RPointerArray<CMceVideoCodec> codecs = videoStream->Codecs();
       
  1535              EUNIT_ASSERT_EQUALS( codecs.Count(), 1 )
       
  1536              EUNIT_ASSERT( codecs[0]->SdpName().FindF( KMceSDPNameH263() ) >= 0 )
       
  1537              }
       
  1538          }
       
  1539   
       
  1540     EUNIT_ASSERT( iObserver->iTranscodingNeededCalled )
       
  1541     EUNIT_ASSERT( !iObserver->iDueUnknowCapas )
       
  1542           
       
  1543     }
       
  1544 
       
  1545 void UT_CMusEngClipSession::UT_IsRewindFromEndL()
       
  1546     {
       
  1547     // Try before establishing the session
       
  1548     EUNIT_ASSERT( !iClipSession->IsRewindFromEnd() )
       
  1549     
       
  1550     // Try with session, but without video out stream 
       
  1551     
       
  1552     CSIPProfile* profile = iClipSession->iSipProfileHandler->Profile();
       
  1553   
       
  1554     iClipSession->iSession = CMceOutSession::NewL( 
       
  1555                                     *(iClipSession->iManager),
       
  1556                                     *profile,
       
  1557                                     KTestRecipientSipUri8() ); 
       
  1558     
       
  1559     EUNIT_ASSERT( !iClipSession->IsRewindFromEnd() )
       
  1560     
       
  1561     // Try with video out stream without source...
       
  1562     CMceVideoStream* videoOut = CMceVideoStream::NewLC();
       
  1563     
       
  1564     videoOut->AddSinkL( CMceRtpSink::NewLC() );
       
  1565     CleanupStack::Pop();
       
  1566      
       
  1567     iClipSession->iSession->AddStreamL( videoOut );
       
  1568     CleanupStack::Pop( videoOut );
       
  1569     
       
  1570     EUNIT_ASSERT( !iClipSession->IsRewindFromEnd() )
       
  1571     
       
  1572     // And with enabled source and stream     
       
  1573     videoOut->SetSourceL( CMceFileSource::NewLC( *iClipSession->iManager,
       
  1574                                                  iClipSession->iFileName ) );
       
  1575     CleanupStack::Pop();
       
  1576     
       
  1577     EUNIT_ASSERT( !iClipSession->IsRewindFromEnd() )
       
  1578     
       
  1579     // try with different position and duration
       
  1580     (static_cast<CMceFileSource*> (videoOut->Source()))->iPosition = 90;
       
  1581     (static_cast<CMceFileSource*> (videoOut->Source()))->iDuration = 111;
       
  1582     EUNIT_ASSERT( !iClipSession->IsRewindFromEnd() )
       
  1583     
       
  1584     // Disapling source
       
  1585     (static_cast<CMceFileSource*> (videoOut->Source()))->DisableL();
       
  1586     EUNIT_ASSERT( !iClipSession->IsRewindFromEnd() )
       
  1587 
       
  1588     // Disapling stream
       
  1589     videoOut->iState = CMceMediaStream::EDisabled;
       
  1590     EUNIT_ASSERT( iClipSession->IsRewindFromEnd() )
       
  1591     
       
  1592     iClipSession->iPause = ETrue;
       
  1593     EUNIT_ASSERT( !iClipSession->IsRewindFromEnd() )
       
  1594     
       
  1595     iClipSession->iPause = EFalse;
       
  1596     EUNIT_ASSERT( iClipSession->IsRewindFromEnd() )
       
  1597        
       
  1598     // and finaly try with "real" end of clip 
       
  1599     (static_cast<CMceFileSource*> (videoOut->Source()))->iPosition = 0;
       
  1600     (static_cast<CMceFileSource*> (videoOut->Source()))->iDuration = 111;
       
  1601     
       
  1602     EUNIT_ASSERT( !iClipSession->IsRewindFromEnd() )
       
  1603     }
   701 
  1604 
   702 //  TEST TABLE
  1605 //  TEST TABLE
   703 
  1606 
   704 EUNIT_BEGIN_TEST_TABLE(
  1607 EUNIT_BEGIN_TEST_TABLE(
   705     UT_CMusEngClipSession,
  1608     UT_CMusEngClipSession,
   712     "NewL",
  1615     "NewL",
   713     "FUNCTIONALITY",
  1616     "FUNCTIONALITY",
   714     SetupL, UT_NewLL, Teardown)
  1617     SetupL, UT_NewLL, Teardown)
   715 
  1618 
   716 EUNIT_TEST(
  1619 EUNIT_TEST(
       
  1620     "SetClipL - test ",
       
  1621     "CMusEngClipSession",
       
  1622     "AetClipL",
       
  1623     "FUNCTIONALITY",
       
  1624     SetupL, UT_SetClipLL, Teardown)
       
  1625 
       
  1626 EUNIT_TEST(
       
  1627     "FastForwardL - test ",
       
  1628     "CMusEngClipSession",
       
  1629     "FastForwardL",
       
  1630     "FUNCTIONALITY",
       
  1631     SetupL, UT_FastForwardLL, Teardown)
       
  1632 
       
  1633 EUNIT_TEST(
       
  1634     "FastRewindL - test ",
       
  1635     "CMusEngClipSession",
       
  1636     "FastRewindL",
       
  1637     "FUNCTIONALITY",
       
  1638     SetupL, UT_FastRewindLL, Teardown)
       
  1639 
       
  1640 EUNIT_TEST(
       
  1641     "PositionL - test ",
       
  1642     "CMusEngClipSession",
       
  1643     "PositionL",
       
  1644     "FUNCTIONALITY",
       
  1645     SetupL, UT_PositionLL, Teardown)
       
  1646 
       
  1647 EUNIT_TEST(
       
  1648     "DurationL - test ",
       
  1649     "CMusEngClipSession",
       
  1650     "DurationL",
       
  1651     "FUNCTIONALITY",
       
  1652     SetupL, UT_DurationLL, Teardown)
       
  1653 
       
  1654 EUNIT_TEST(
       
  1655     "SetPositionL - test ",
       
  1656     "CMusEngClipSession",
       
  1657     "SetPositionL",
       
  1658     "FUNCTIONALITY",
       
  1659     SetupL, UT_SetPositionLL, Teardown)
       
  1660     
       
  1661 EUNIT_TEST(
       
  1662     "TranscodeL - To AVC test ",
       
  1663     "CMusEngClipSession",
       
  1664     "TranscodeL",
       
  1665     "FUNCTIONALITY",
       
  1666     SetupL, UT_TranscodeLToAvcL, Teardown)
       
  1667 
       
  1668 EUNIT_TEST(
       
  1669     "TranscodeL - To H263 test ",
       
  1670     "CMusEngClipSession",
       
  1671     "TranscodeL",
       
  1672     "FUNCTIONALITY",
       
  1673     Setup2L, UT_TranscodeLToH263L, Teardown)
       
  1674     
       
  1675 EUNIT_TEST(
       
  1676     "CancelTranscodeL - test ",
       
  1677     "CMusEngClipSession",
       
  1678     "CancelTranscodeL",
       
  1679     "FUNCTIONALITY",
       
  1680     SetupL, UT_CancelTranscodeLL, Teardown)
       
  1681     
       
  1682 EUNIT_TEST(
       
  1683     "PlayL - test ",
       
  1684     "CMusEngClipSession",
       
  1685     "PlayL",
       
  1686     "FUNCTIONALITY",
       
  1687     SetupL, UT_PlayLL, Teardown)
       
  1688 
       
  1689 EUNIT_TEST(
       
  1690     "PauseL - test ",
       
  1691     "CMusEngClipSession",
       
  1692     "PauseL",
       
  1693     "FUNCTIONALITY",
       
  1694     SetupL, UT_PauseLL, Teardown)
       
  1695 
       
  1696 EUNIT_TEST(
       
  1697     "IsPlayingL - test ",
       
  1698     "CMusEngClipSession",
       
  1699     "IsPlayingL",
       
  1700     "FUNCTIONALITY",
       
  1701     SetupL, UT_IsPlayingLL, Teardown)
       
  1702 
       
  1703 EUNIT_TEST(
   717     "CompleteSessionStructureL - test ",
  1704     "CompleteSessionStructureL - test ",
   718     "CMusEngClipSession",
  1705     "CMusEngClipSession",
   719     "CompleteSessionStructureL",
  1706     "CompleteSessionStructureL",
   720     "FUNCTIONALITY",
  1707     "FUNCTIONALITY",
   721     SetupL, UT_CompleteSessionStructureLL, Teardown)
  1708     SetupL, UT_CompleteSessionStructureLL, Teardown)
   752     "AddVideoCodecL - test ",
  1739     "AddVideoCodecL - test ",
   753     "CMusEngClipSession",
  1740     "CMusEngClipSession",
   754     "AddVideoCodecL",
  1741     "AddVideoCodecL",
   755     "FUNCTIONALITY",
  1742     "FUNCTIONALITY",
   756     SetupL, UT_AddVideoCodecLL, Teardown)
  1743     SetupL, UT_AddVideoCodecLL, Teardown)
       
  1744     
       
  1745 EUNIT_TEST(
       
  1746     "HasClipEnded - test ",
       
  1747     "CMusEngClipSession",
       
  1748     "HasClipEnded",
       
  1749     "FUNCTIONALITY",
       
  1750     SetupL, UT_HasClipEndedL, Teardown)
   757 
  1751 
   758 EUNIT_TEST(
  1752 EUNIT_TEST(
   759     "ConstructAudioStructureL - test ",
  1753     "ConstructAudioStructureL - test ",
   760     "CMusEngClipSession",
  1754     "CMusEngClipSession",
   761     "ConstructAudioStructureL",
  1755     "ConstructAudioStructureL",
   774     "CMusEngClipSession",
  1768     "CMusEngClipSession",
   775     "EstablishSessionL",
  1769     "EstablishSessionL",
   776     "FUNCTIONALITY",
  1770     "FUNCTIONALITY",
   777     SetupL, UT_EstablishSessionLL, Teardown)    
  1771     SetupL, UT_EstablishSessionLL, Teardown)    
   778 
  1772 
   779         
  1773 EUNIT_TEST(
       
  1774     "IsRewindFromEnd - test ",
       
  1775     "CMusEngClipSession",
       
  1776     "IsRewindFromEnd",
       
  1777     "FUNCTIONALITY",
       
  1778     SetupL, UT_IsRewindFromEndL, Teardown)
       
  1779     
   780 EUNIT_END_TEST_TABLE
  1780 EUNIT_END_TEST_TABLE
   781 
  1781 
   782 //  END OF FILE
  1782 //  END OF FILE
   783 
  1783 
   784 
  1784