mmsharing/livecommsui/lcui/tsrc/mustester/Stubs/mceclientstub/src/mcefilesource.cpp
branchRCL_3
changeset 33 bc78a40cd63c
parent 32 73a1feb507fb
child 35 6c57ef9392d2
equal deleted inserted replaced
32:73a1feb507fb 33:bc78a40cd63c
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 
       
    20 #include "mcefilesource.h"
       
    21 #include "mcevideostream.h"
       
    22 #include "mceaudiostream.h"
       
    23 #include "mcemanager.h"
       
    24 #include "mcesession.h"
       
    25 #include "utf.h"
       
    26 
       
    27 
       
    28 // ============================ MEMBER FUNCTIONS ===============================
       
    29 
       
    30 
       
    31 // -----------------------------------------------------------------------------
       
    32 //
       
    33 // -----------------------------------------------------------------------------
       
    34 //
       
    35 EXPORT_C CMceFileSource* CMceFileSource::NewL(
       
    36             CMceManager& aManager,
       
    37             const TFileName& aFileName )
       
    38     {
       
    39     CMceFileSource* self = CMceFileSource::NewLC( aManager, aFileName );
       
    40     CleanupStack::Pop( self );
       
    41     return self;
       
    42     }
       
    43 
       
    44 
       
    45 // -----------------------------------------------------------------------------
       
    46 //
       
    47 // -----------------------------------------------------------------------------
       
    48 //
       
    49 EXPORT_C CMceFileSource* CMceFileSource::NewLC(
       
    50             CMceManager& aManager,
       
    51             const TFileName& aFileName )
       
    52     {
       
    53     CMceFileSource* self = new (ELeave) CMceFileSource();
       
    54     CleanupStack::PushL( self );
       
    55     self->ConstructL( &aManager, aFileName );
       
    56     return self;
       
    57     }
       
    58 
       
    59 
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 // -----------------------------------------------------------------------------
       
    63 //
       
    64 EXPORT_C CMceFileSource::~CMceFileSource()
       
    65     {
       
    66     }
       
    67 
       
    68 
       
    69 // -----------------------------------------------------------------------------
       
    70 //
       
    71 // -----------------------------------------------------------------------------
       
    72 //
       
    73 EXPORT_C void CMceFileSource::EnableL()
       
    74     {
       
    75     CMceMediaSource::DoEnableL();
       
    76     }
       
    77 
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 //
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 EXPORT_C void CMceFileSource::DisableL()
       
    84     { 
       
    85     CMceMediaSource::DoDisableL();
       
    86     }
       
    87 
       
    88 
       
    89 // -----------------------------------------------------------------------------
       
    90 //
       
    91 // -----------------------------------------------------------------------------
       
    92 //
       
    93 EXPORT_C void CMceFileSource::UpdateL ( const TFileName& aFileName )
       
    94     {
       
    95     iFileName = aFileName;
       
    96     }
       
    97 
       
    98 
       
    99 // -----------------------------------------------------------------------------
       
   100 //
       
   101 // -----------------------------------------------------------------------------
       
   102 //    
       
   103 EXPORT_C TInt CMceFileSource::MediaElementCountL( TMceMediaType aType ) const
       
   104     {
       
   105     if ( aType == KMceAudio )
       
   106         {
       
   107         return iAudioElementCount;
       
   108         }
       
   109     else if ( aType == KMceVideo )
       
   110         {
       
   111         return iVideoElementCount;
       
   112         }
       
   113     return 0;
       
   114     }
       
   115 
       
   116 
       
   117 // -----------------------------------------------------------------------------
       
   118 //
       
   119 // -----------------------------------------------------------------------------
       
   120 //    
       
   121 EXPORT_C void CMceFileSource::SetCurrentMediaElementL( 
       
   122             TMceMediaType aType, 
       
   123             TInt aIndex )
       
   124     {
       
   125     __ASSERT_ALWAYS( aIndex >= 0 &&
       
   126                      aIndex < MediaElementCountL( aType ), 
       
   127                      User::Leave( KErrArgument ) );
       
   128                      
       
   129     if ( aType == KMceAudio )
       
   130         {
       
   131         iCurrentAudioElement = aIndex;
       
   132         }
       
   133     else if ( aType == KMceVideo )
       
   134         {
       
   135         iCurrentVideoElement = aIndex;
       
   136         }
       
   137     }
       
   138 
       
   139 
       
   140 // -----------------------------------------------------------------------------
       
   141 //
       
   142 // -----------------------------------------------------------------------------
       
   143 //      
       
   144 EXPORT_C TInt CMceFileSource::CurrentMediaElement( TMceMediaType aType )
       
   145     {
       
   146     if ( aType == KMceAudio )
       
   147         {
       
   148         return iCurrentAudioElement;
       
   149         }
       
   150     else if ( aType == KMceVideo )
       
   151         {
       
   152         return iCurrentVideoElement;
       
   153         }
       
   154     
       
   155     return 0;
       
   156     }
       
   157 
       
   158 
       
   159 // -----------------------------------------------------------------------------
       
   160 //
       
   161 // -----------------------------------------------------------------------------
       
   162 //      
       
   163 EXPORT_C void CMceFileSource::SetPositionL( 
       
   164             const TTimeIntervalMicroSeconds& aPosition )
       
   165     {
       
   166     __ASSERT_ALWAYS( aPosition <= DurationL() &&
       
   167                      aPosition >= TTimeIntervalMicroSeconds( 0 ), 
       
   168                      User::Leave( KErrArgument ) );
       
   169     
       
   170     iPosition = aPosition;
       
   171     }
       
   172 
       
   173 
       
   174 // -----------------------------------------------------------------------------
       
   175 //
       
   176 // -----------------------------------------------------------------------------
       
   177 //          
       
   178 EXPORT_C TTimeIntervalMicroSeconds CMceFileSource::PositionL() const
       
   179     {        
       
   180     return iPosition;
       
   181     }
       
   182 
       
   183 
       
   184 // -----------------------------------------------------------------------------
       
   185 //
       
   186 // -----------------------------------------------------------------------------
       
   187 //          
       
   188 EXPORT_C TTimeIntervalMicroSeconds CMceFileSource::DurationL() const
       
   189     {
       
   190     return iDuration;
       
   191     }
       
   192 
       
   193 
       
   194 // -----------------------------------------------------------------------------
       
   195 //
       
   196 // -----------------------------------------------------------------------------
       
   197 //  
       
   198 EXPORT_C void CMceFileSource::SetFastForwardL( TBool aUseFFWD )
       
   199     {
       
   200     __ASSERT_ALWAYS( this->MediaElementCountL( KMceVideo ) > 0, 
       
   201                      User::Leave( KErrNotSupported ) );
       
   202 
       
   203 
       
   204     iFastForward = aUseFFWD;
       
   205         
       
   206     
       
   207     if ( iFastForward )
       
   208         {
       
   209         iFastRewind = EFalse;
       
   210         }
       
   211     }
       
   212 
       
   213 
       
   214 // -----------------------------------------------------------------------------
       
   215 //
       
   216 // -----------------------------------------------------------------------------
       
   217 //  
       
   218 EXPORT_C void CMceFileSource::SetFastRewindL( TBool aUseFRWD )
       
   219     {
       
   220     __ASSERT_ALWAYS( this->MediaElementCountL( KMceVideo ) > 0, 
       
   221                      User::Leave( KErrNotSupported ) );
       
   222 
       
   223     iFastRewind = aUseFRWD;
       
   224         
       
   225     if ( iFastRewind )
       
   226         {
       
   227         iFastForward = EFalse;
       
   228         }
       
   229     }
       
   230 
       
   231 
       
   232 // -----------------------------------------------------------------------------
       
   233 //
       
   234 // -----------------------------------------------------------------------------
       
   235 //  
       
   236 EXPORT_C void CMceFileSource::TranscodeL( const TFileName& aFileName )
       
   237     {
       
   238     __ASSERT_ALWAYS( aFileName != KNullDesC, User::Leave( KErrArgument ) );
       
   239 
       
   240     TBool transcodingNeeded = EFalse;
       
   241     for ( TInt i = 0; i < iStreams.Count(); ++i )
       
   242         {
       
   243         if ( iStreams[i]->State() == CMceMediaStream::ETranscodingRequired )
       
   244             {
       
   245             transcodingNeeded = ETrue;
       
   246             if ( iStreams[i]->Type() == KMceAudio )
       
   247                 {
       
   248                 CMceAudioStream* audio = 
       
   249                                     static_cast<CMceAudioStream*>(iStreams[i]);
       
   250                 __ASSERT_ALWAYS( audio->Codecs().Count() > 0, 
       
   251                                  User::Leave( KErrNotReady ) );
       
   252                 }
       
   253             else
       
   254                 {
       
   255                 CMceVideoStream* video = 
       
   256                                     static_cast<CMceVideoStream*>(iStreams[i]);
       
   257                 __ASSERT_ALWAYS( video->Codecs().Count() > 0, 
       
   258                                  User::Leave( KErrNotReady ) );
       
   259                 }
       
   260                
       
   261             iStreams[i]->iState = CMceMediaStream::ETranscoding;
       
   262             }
       
   263         }
       
   264     
       
   265     __ASSERT_ALWAYS( transcodingNeeded, User::Leave( KErrNotReady ) );
       
   266         
       
   267     }
       
   268 
       
   269    
       
   270 // -----------------------------------------------------------------------------
       
   271 //
       
   272 // -----------------------------------------------------------------------------
       
   273 //  
       
   274 EXPORT_C void CMceFileSource::CancelTranscodeL()
       
   275     {
       
   276     TBool transcodingOngoing = EFalse;
       
   277     
       
   278     for ( TInt i = 0; i < iStreams.Count(); ++i )
       
   279         {
       
   280         if ( iStreams[i]->State() == CMceMediaStream::ETranscoding )
       
   281             {
       
   282             transcodingOngoing = ETrue;
       
   283             iStreams[i]->iState = CMceMediaStream::ETranscodingRequired;
       
   284             }
       
   285         }
       
   286     
       
   287     __ASSERT_ALWAYS( transcodingOngoing, User::Leave( KErrNotReady ) );
       
   288     
       
   289     }
       
   290 
       
   291 
       
   292 // -----------------------------------------------------------------------------
       
   293 //
       
   294 // -----------------------------------------------------------------------------
       
   295 //  
       
   296 EXPORT_C TInt CMceFileSource::TranscodingProgressL() const
       
   297     {
       
   298     TBool transcodingOngoing = EFalse;
       
   299     
       
   300     if ( iFailWithCode != KErrNone )
       
   301         {
       
   302         TInt failCode = iFailWithCode;
       
   303         iFailWithCode = KErrNone;
       
   304         User::Leave( failCode );
       
   305         }
       
   306     
       
   307     for ( TInt i = 0; i < iStreams.Count(); ++i )
       
   308         {
       
   309         if ( iStreams[i]->State() == CMceMediaStream::ETranscoding )
       
   310             {
       
   311             transcodingOngoing = ETrue;
       
   312             }
       
   313         }
       
   314     
       
   315     __ASSERT_ALWAYS( transcodingOngoing, User::Leave( KErrNotReady ) );
       
   316 
       
   317     return iTranscodingPercentage; 
       
   318     }
       
   319         
       
   320 
       
   321 // -----------------------------------------------------------------------------
       
   322 //
       
   323 // -----------------------------------------------------------------------------
       
   324 //
       
   325 void CMceFileSource::InitializeL( CMceManager* aManager )
       
   326     {
       
   327     iDuration = TTimeIntervalMicroSeconds( 100000000 );
       
   328     
       
   329     iAudioElementCount = 1;
       
   330     iVideoElementCount = 1;
       
   331         
       
   332     }
       
   333     
       
   334 // -----------------------------------------------------------------------------
       
   335 // Factory method for inner usage
       
   336 // -----------------------------------------------------------------------------
       
   337 //
       
   338 CMceFileSource* CMceFileSource::NewL()
       
   339     {
       
   340     CMceFileSource* self = CMceFileSource::NewLC();
       
   341     CleanupStack::Pop( self );
       
   342     return self;
       
   343     }
       
   344 
       
   345 
       
   346 // -----------------------------------------------------------------------------
       
   347 // Factory method for inner usage
       
   348 // -----------------------------------------------------------------------------
       
   349 //
       
   350 CMceFileSource* CMceFileSource::NewLC()
       
   351     {
       
   352     CMceFileSource* self = new (ELeave) CMceFileSource();
       
   353     CleanupStack::PushL( self );
       
   354     self->ConstructL( NULL, KNullDesC() );
       
   355     return self;
       
   356     }    
       
   357     
       
   358     
       
   359 // -----------------------------------------------------------------------------
       
   360 // 
       
   361 // -----------------------------------------------------------------------------
       
   362 //  
       
   363 CMceFileSource::CMceFileSource()
       
   364     {
       
   365     iType = KMceFileSource;    
       
   366     }
       
   367 
       
   368 
       
   369 // -----------------------------------------------------------------------------
       
   370 // 
       
   371 // -----------------------------------------------------------------------------
       
   372 //  
       
   373 void CMceFileSource::ConstructL( CMceManager* aManager, 
       
   374                                  const TFileName& aFileName )
       
   375     {
       
   376     
       
   377     iFileName = aFileName;
       
   378     
       
   379     if ( aManager )
       
   380         {        
       
   381         InitializeL( aManager );
       
   382         }
       
   383    
       
   384     }
       
   385 
       
   386 
       
   387