vtprotocolplugins/VideoSource/src/cmultiframeprovider.cpp
changeset 0 ed9695c8bcbe
child 3 b1602a5ab0a3
equal deleted inserted replaced
-1:000000000000 0:ed9695c8bcbe
       
     1 /*
       
     2 * Copyright (c) 2008 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:  Video Source subsystem.
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <imageconversion.h>
       
    21 #include <cvtimageconverter.h>
       
    22 #include <rphcltserver.h>
       
    23 #include <cphcltimagehandler.h>
       
    24 #include <bautils.h>
       
    25 
       
    26 #include "cmultiframeprovider.h"
       
    27 #include "cmultiframeloopao.h"
       
    28 #include "cmultiframedataao.h"
       
    29 
       
    30 #include "CVSStillImageDataProvider.h"
       
    31 #include "cvtimagebitmap.h"
       
    32 
       
    33 static const TInt KQcifWidth = 176;
       
    34 static const TInt KQcifHeight = 144;
       
    35 
       
    36 // Default bitmap size is VGA
       
    37 static const TInt KDefaultBitmapSizeWidth = 640;
       
    38 static const TInt KDefaultBitmapSizeHeight = 480;
       
    39 
       
    40 // MACROS
       
    41 
       
    42 #ifdef _DEBUG
       
    43 #    define __IF_DEBUG(t) {RDebug::t;}
       
    44 #else
       
    45 #    define __IF_DEBUG(t)
       
    46 #endif
       
    47 
       
    48 // ============================ TScalingMediator ===============================
       
    49 
       
    50 // -----------------------------------------------------------------------------
       
    51 // TScalingMediator::TScalingMediator( )
       
    52 // -----------------------------------------------------------------------------
       
    53 //
       
    54 TScalingMediator::TScalingMediator()
       
    55     {
       
    56     }
       
    57 
       
    58 // -----------------------------------------------------------------------------
       
    59 // TScalingMediator::ScalingFinished( )
       
    60 // -----------------------------------------------------------------------------
       
    61 //
       
    62 void TScalingMediator::ScalingFinished( TInt aError )
       
    63 		{
       
    64 		__IF_DEBUG(Print(_L("TScalingMediator::ScalingFinished() >>")));
       
    65     iWait->Signal( aError );
       
    66    	__IF_DEBUG(Print(_L("TScalingMediator::ScalingFinished() error %d <<"), aError));
       
    67 		}
       
    68 // -----------------------------------------------------------------------------
       
    69 // TScalingMediator::ScalingFinished( )
       
    70 // -----------------------------------------------------------------------------
       
    71 //
       
    72 void TScalingMediator::SetWaiter( CVSActiveWait< CMultiframeProvider >* aWait )
       
    73 			{
       
    74 			iWait = aWait;
       
    75 			}
       
    76 
       
    77 // ============================ CMultiframeProvider ===============================
       
    78 
       
    79 // -----------------------------------------------------------------------------
       
    80 // CMultiframeProvider::NewL( )
       
    81 // -----------------------------------------------------------------------------
       
    82 //
       
    83 CMultiframeProvider* CMultiframeProvider::NewL( MMultiframeprovider* aObserver, TDisplayMode aDisplayMode )
       
    84     {
       
    85     __IF_DEBUG(Print(_L("VideoSource: [%d] CMultiframeProvider::NewL() >>"), RThread().Id().operator TUint()));
       
    86     CMultiframeProvider* self =
       
    87     new (ELeave) CMultiframeProvider( aObserver, aDisplayMode );
       
    88     CleanupStack::PushL( self );
       
    89     self->ConstructL();
       
    90     CleanupStack::Pop( self );
       
    91     __IF_DEBUG(Print(_L("VideoSource: [%d] CMultiframeProvider::NewL() <<"), RThread().Id().operator TUint()));
       
    92     return self;
       
    93     }
       
    94 // -----------------------------------------------------------------------------
       
    95 // CMultiframeProvider::CMultiframeProvider(
       
    96 //  MVSDataProviderObserver* aObserver )
       
    97 // -----------------------------------------------------------------------------
       
    98 //
       
    99 CMultiframeProvider::CMultiframeProvider(
       
   100     MMultiframeprovider* aObserver , TDisplayMode aDisplayMode ): iDisplayMode( aDisplayMode ), iObserver( aObserver ), iBlank( EFalse ), iGSImage( EFalse )
       
   101     {
       
   102     __IF_DEBUG(Print(_L("VideoSource [%d]: CMultiframeProvider::CMultiframeProvider() >>"), RThread().Id().operator TUint()));
       
   103     //Set target VF size QCIF as default
       
   104     iTargetSize.SetSize( KQcifWidth , KQcifHeight );
       
   105     iVFSize.SetSize( KQcifWidth , KQcifHeight );
       
   106     __IF_DEBUG(Print(_L("VideoSource [%d]: CMultiframeProvider::CMultiframeProvider() <<"), RThread().Id().operator TUint()));
       
   107     }
       
   108 // -----------------------------------------------------------------------------
       
   109 // CMultiframeProvider::~CMultiframeProvider()
       
   110 // -----------------------------------------------------------------------------
       
   111 //
       
   112 CMultiframeProvider::~CMultiframeProvider()
       
   113     {
       
   114     __IF_DEBUG(Print(_L("VideoSource [%d]: CMultiframeProvider::~CMultiframeProvider() >>"), RThread().Id().operator TUint()));
       
   115     iFs.Close();
       
   116     iFreezeCS.Close();
       
   117     delete iImageDecoder; iImageDecoder = 0;
       
   118     delete iVtImageScalerInit;
       
   119     delete iVtImageScalerScale;
       
   120     delete iActiveWaitInit;
       
   121     delete iActiveWaitScale;
       
   122     delete iActiveWaitInitScale;
       
   123     delete iConverted;
       
   124     delete iMask;
       
   125     delete iTempBM;
       
   126     delete iDataTimer;
       
   127     delete iLoopAo;
       
   128     if ( iScaled != iBuffer1 && iScaled != iBuffer2 )
       
   129         {
       
   130     	  delete iScaled;
       
   131         }
       
   132     delete iGSBitmap;
       
   133     if ( !iBlank || !iGSImage )
       
   134     	  {
       
   135     	  delete iBuffer1;
       
   136 		    delete iBuffer2;
       
   137     	  }
       
   138     delete iFirstVfBuf;
       
   139     delete iSecondVfBuf;
       
   140     iFreeQueue.Close();
       
   141     iDefaultImageFile.Close();
       
   142     __IF_DEBUG(Print(_L("VideoSource [%d]: CMultiframeProvider::~CMultiframeProvider() <<"), RThread().Id().operator TUint()));
       
   143     }
       
   144 
       
   145 // -----------------------------------------------------------------------------
       
   146 // CMultiframeProvider::ConstructL()
       
   147 // -----------------------------------------------------------------------------
       
   148 //
       
   149 void CMultiframeProvider::ConstructL()
       
   150     {
       
   151     __IF_DEBUG(Print(_L("VideoSource [%d]: CMultiframeProvider::ConstructL() >>"), RThread().Id().operator TUint()));
       
   152     User::LeaveIfError( iFs.Connect() );
       
   153     User::LeaveIfError( iFreezeCS.CreateLocal() );
       
   154 
       
   155     // Create waiters and mediators for scaling purposes
       
   156     iActiveWaitInit = new (ELeave) CVSActiveWait< CMultiframeProvider >( this );
       
   157     iActiveWaitScale = new (ELeave) CVSActiveWait< CMultiframeProvider >( this );
       
   158     iActiveWaitInitScale = new (ELeave) CVSActiveWait< CMultiframeProvider >( this );
       
   159     iInitMediator.SetWaiter( iActiveWaitInitScale );
       
   160     iScalingMediator.SetWaiter( iActiveWaitScale );
       
   161     iVtImageScalerInit = CVtImageScaler::NewL( iInitMediator, CVtImageScaler::EBilinear );
       
   162     iVtImageScalerScale = CVtImageScaler::NewL( iScalingMediator, CVtImageScaler::EBilinear );
       
   163 		iDataTimer = new (ELeave) CMultiframeDataAO( this );
       
   164 		iDataTimer->SetObserver( iObserver );
       
   165     iLoopAo = new (ELeave) CMultiframeloopAO( this );
       
   166     iFirstVfBuf = CVtImageBitmap::NewL( TSize( KQcifWidth >> 2, KQcifHeight >> 2 ), iDisplayMode );
       
   167     iSecondVfBuf = CVtImageBitmap::NewL( TSize( KQcifWidth >> 2, KQcifHeight >> 2 ), iDisplayMode );
       
   168     iSecondVFBuffer = EFalse;
       
   169     iFirstVFBuffer = ETrue;
       
   170     iIsVfStopped = EFalse;
       
   171     iWaitForConverting = EFalse;
       
   172     __IF_DEBUG(Print(_L("VideoSource [%d]: CMultiframeProvider::ConstructL() <<"), RThread().Id().operator TUint()));
       
   173     }
       
   174 
       
   175 // -----------------------------------------------------------------------------
       
   176 // CMultiframeProvider::IniatializeGSL()
       
   177 //
       
   178 // -----------------------------------------------------------------------------
       
   179 //
       
   180 void CMultiframeProvider::IniatializeGSL( const TGeneralSettingsImageType aType )
       
   181     {
       
   182     __IF_DEBUG(Print(_L("VideoSource [%d]: CMultiframeProvider::IniatializeGSL() >>"), RThread().Id().operator TUint()));
       
   183 	  if ( aType == EGSStillImage )
       
   184         {
       
   185         // Open connection to phone server
       
   186         RPhCltServer phoneClient;
       
   187         User::LeaveIfError( phoneClient.Connect() );
       
   188         CleanupClosePushL( phoneClient );
       
   189     
       
   190     	  CPhCltImageHandler* stillH = CPhCltImageHandler::NewL();
       
   191         CleanupStack::PushL( stillH );
       
   192     
       
   193     	  // Load images
       
   194     	  CPhCltImageParams* imageParams;
       
   195         imageParams = stillH->CPhCltBaseImageParamsL( EPhCltTypeVTStill );
       
   196         CleanupStack::PushL( imageParams );
       
   197         User::LeaveIfError( stillH->LoadImages( imageParams ) );
       
   198     
       
   199         // Duplicate to image
       
   200     	  if( imageParams->Count() > 0 )
       
   201            {
       
   202            __IF_DEBUG(Print(_L("iImageCount > 0")));
       
   203            iGSBitmap = CVtImageBitmap::NewL( imageParams->GetImageL( 0 ) );
       
   204            }
       
   205         else
       
   206            {
       
   207            __IF_DEBUG(Print(_L("iImageCount <= 0 -> User::Leave( KErrNotFound )")));
       
   208            User::Leave( KErrNotFound );
       
   209            }
       
   210         // Cleanup
       
   211     	  CleanupStack::PopAndDestroy( 3 ); // phoneClient, stillH, imageParams
       
   212     	  iScaled = CVtImageBitmap::NewL( TSize( KQcifWidth, KQcifHeight ), iDisplayMode );
       
   213     		
       
   214         // If bitmap has different display mode than screen, then new bitmap
       
   215         // is created and image is converted to screen's display mode
       
   216         if ( iGSBitmap->Bitmap().DisplayMode() != iDisplayMode || 
       
   217                 iGSBitmap->Bitmap().ExtendedBitmapType() != KNullUid )
       
   218             {
       
   219             CVtImageBitmap* temp = CVtImageBitmap::NewL(
       
   220                 iGSBitmap->Bitmap().SizeInPixels(), iDisplayMode );
       
   221             CleanupStack::PushL( temp );
       
   222             // Color conversion is done by blitting it to other bitmap
       
   223             CFbsBitmapDevice* fbd = CFbsBitmapDevice::NewL( &temp->Bitmap() );
       
   224             CleanupStack::PushL( fbd );
       
   225             CFbsBitGc* fgc = NULL;
       
   226             User::LeaveIfError( fbd->CreateContext( fgc ) );
       
   227             CleanupStack::PushL( fgc );
       
   228             fgc->BitBlt( TPoint(), &iGSBitmap->Bitmap() );
       
   229             CleanupStack::PopAndDestroy( 2 ); // fbd, fgc
       
   230             CleanupStack::Pop(); // temp
       
   231             delete iGSBitmap; iGSBitmap = NULL;
       
   232             iGSBitmap = temp;
       
   233             }
       
   234         iGSImage = ETrue;
       
   235         iCount = 1;     
       
   236 		    iActiveWaitInit->InitializeWaiter( &ConversionFinished );
       
   237         iActiveWaitInit->Signal( KErrNone );
       
   238         }
       
   239     else
       
   240         { // default still image prepared by using file handle
       
   241         InitializeL( NULL );
       
   242         }
       
   243     iInitialization = ETrue;
       
   244     iDelay = 0;    
       
   245     __IF_DEBUG(Print(_L("VideoSource [%d]: CMultiframeProvider::IniatializeGSL() <<"), RThread().Id().operator TUint()));
       
   246 	}
       
   247 // -----------------------------------------------------------------------------
       
   248 // CMultiframeProvider::IniatializeBlank()
       
   249 //
       
   250 // -----------------------------------------------------------------------------
       
   251 //
       
   252 void CMultiframeProvider::IniatializeBlankL()
       
   253     {
       
   254     __IF_DEBUG(Print(_L("VideoSource [%d]: CMultiframeProvider::IniatializeBlank() >>"), RThread().Id().operator TUint()));
       
   255     iBlank = ETrue;
       
   256     iInitialization = ETrue;
       
   257     iDelay = 0;
       
   258     iCount = 1;
       
   259 
       
   260     CFbsBitmap* tempBitmap = 0;
       
   261 
       
   262     CreateBlankBitmapL(
       
   263         tempBitmap,
       
   264         TSize( KQcifWidth, KQcifHeight ),
       
   265         iDisplayMode,
       
   266 #ifdef _DEBUG
       
   267         KRgbYellow
       
   268 #else
       
   269         KRgbBlack
       
   270 #endif
       
   271         );
       
   272 
       
   273     CleanupStack::PushL( tempBitmap );
       
   274     iScaled = CVtImageBitmap::NewL( tempBitmap->Handle() );
       
   275     CleanupStack::PopAndDestroy(); // tempBitmap
       
   276     tempBitmap = 0;
       
   277 
       
   278     iActiveWaitInit->InitializeWaiter( &BMSScalingFinished );
       
   279     iActiveWaitInit->Signal( KErrNone );
       
   280     __IF_DEBUG(Print(_L("VideoSource [%d]: CMultiframeProvider::IniatializeBlank() <<"), RThread().Id().operator TUint()));
       
   281     }
       
   282  // -----------------------------------------------------------------------------
       
   283 // CVSStillImageDataProvider::CreateBlankBitmapL(
       
   284 //  CFbsBitmap*& aBitmap, const TSize& aSize, const TDisplayMode& aMode,
       
   285 //  const TRgb& aColor )
       
   286 // -----------------------------------------------------------------------------
       
   287 //
       
   288 void CMultiframeProvider::CreateBlankBitmapL(
       
   289     CFbsBitmap*& aBitmap,
       
   290     const TSize& aSize,
       
   291     const TDisplayMode& aMode,
       
   292     const TRgb& aColor )
       
   293     {
       
   294     __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::CreateBlankBitmapL() >>"), RThread().Id().operator TUint()));
       
   295     if( aBitmap )
       
   296        {
       
   297        delete aBitmap;
       
   298        aBitmap = 0;
       
   299        }
       
   300     aBitmap = new (ELeave) CFbsBitmap();
       
   301     User::LeaveIfError( aBitmap->Create( aSize, aMode ) );
       
   302     CFbsBitmapDevice* fbd = CFbsBitmapDevice::NewL( aBitmap );
       
   303     CleanupStack::PushL( fbd );
       
   304     CFbsBitGc* fgc = 0;
       
   305     User::LeaveIfError( fbd->CreateContext( fgc ) );
       
   306     CleanupStack::PushL( fgc );
       
   307 
       
   308     fgc->SetPenColor( aColor );
       
   309     fgc->SetBrushColor( aColor );
       
   310     fgc->SetBrushStyle( CGraphicsContext::ESolidBrush );
       
   311     fgc->DrawRect( TRect( aSize ) );
       
   312 
       
   313     CleanupStack::PopAndDestroy( 2 ); // fbd, fgc
       
   314     __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::CreateBlankBitmapL() <<"), RThread().Id().operator TUint()));
       
   315     }
       
   316 // -----------------------------------------------------------------------------
       
   317 // CMultiframeProvider::Iniatialize()
       
   318 //
       
   319 // -----------------------------------------------------------------------------
       
   320 //
       
   321 void CMultiframeProvider::InitializeL( const TFileName* aFileName )
       
   322     {
       
   323     __IF_DEBUG(Print(_L("VideoSource [%d]: CMultiframeProvider::InitializeL() >>"), RThread().Id().operator TUint()));
       
   324 		// Create bitmaps used for conversion and scaling  
       
   325 		iBuffer1 = CVtImageBitmap::NewL( TSize( KQcifWidth, KQcifHeight ), iDisplayMode );
       
   326 		iBuffer2 = CVtImageBitmap::NewL( TSize( KQcifWidth, KQcifHeight ), iDisplayMode );
       
   327     User::LeaveIfError( iFreeQueue.Append( iBuffer1 ) );
       
   328 		User::LeaveIfError( iFreeQueue.Append( iBuffer2 ) );
       
   329 		iLoopAo->SetFreeBitmaps( 2 );
       
   330 			
       
   331 		// Create ICL decoder in its own thread for current file  
       
   332 		TInt decodingoptions( 
       
   333 		CImageDecoder::TOptions( CImageDecoder::EOptionAlwaysThread | CImageDecoder::EAllowGeneratedMask ) );	
       
   334         
       
   335     if ( aFileName )
       
   336     		{
       
   337     		__IF_DEBUG(Print(_L(" file name exist, creating CImageDecoder")));
       
   338     		iImageDecoder = CImageDecoder::FileNewL( iFs, *aFileName, (CImageDecoder::TOptions )decodingoptions /*CImageDecoder::EOptionNone*/ );
       
   339     	  }
       
   340     else
       
   341         {
       
   342         __IF_DEBUG(Print(_L(" default vt image file => use phone server")));
       
   343         // default VT image file handle obtained from phone server
       
   344         RPhCltServer phoneClient;
       
   345         User::LeaveIfError( phoneClient.Connect() );
       
   346         __IF_DEBUG(Print(_L("  connected to phone server")));
       
   347         CleanupClosePushL( phoneClient );
       
   348         CPhCltImageHandler* handler = CPhCltImageHandler::NewL();
       
   349         CleanupStack::PushL( handler );                          
       
   350         __IF_DEBUG(Print(_L(" created image handler")));
       
   351         User::LeaveIfError( handler->OpenDefaultVtImage( iDefaultImageFile ) );
       
   352         decodingoptions &= ~CImageDecoder::EOptionAlwaysThread;
       
   353         __IF_DEBUG(Print(_L(" creating image decoder")));
       
   354         iImageDecoder = CImageDecoder::FileNewL( iDefaultImageFile, ContentAccess::EPlay, (CImageDecoder::TOptions )decodingoptions );
       
   355         __IF_DEBUG(Print(_L(" created image decoder")));
       
   356         CleanupStack::PopAndDestroy( 2 ); // handler, phoneClient
       
   357         }
       
   358     // Use ICL to calculate frame count 
       
   359 		iCount = iImageDecoder->FrameCount();
       
   360 		__IF_DEBUG(Print(_L(" frame count=%d"),iCount));
       
   361 		//If advanced flags are on show only first frame!
       
   362 		for ( TInt index = 0; index < iCount; ++index )
       
   363     		 {
       
   364     		 TFrameInfo frameInfo( iImageDecoder->FrameInfo( index ) );
       
   365     		 __IF_DEBUG(Print(_L("VideoSource [%d]: CMultiframeProvider::InitializeL() frameInfo.iFlags %b >>"), RThread().Id().operator TUint(), frameInfo.iFlags));
       
   366     		 if ( frameInfo.iFlags & TFrameInfo::ELeaveInPlace )
       
   367     		     {
       
   368     			   iDelay = 0;
       
   369     		     iCount = 1;	
       
   370     			   }
       
   371     		 }        	
       
   372 		//Set num of frames to viewer AO
       
   373 		iLoopAo->SetFrameCount( iCount );
       
   374 		//For default loopping frame sequence is disabled
       
   375 		iAnimation = EFalse;
       
   376 		iInitialization = ETrue;
       
   377 		//Start ICL image conversion (decoding) and local scaling 
       
   378 		ConvertAndScaleL( KFirstFrameIndx );	
       
   379     __IF_DEBUG(Print(_L("VideoSource [%d]: CMultiframeProvider::InitializeL() <<"), RThread().Id().operator TUint()));
       
   380     }
       
   381 
       
   382 // -----------------------------------------------------------------------------
       
   383 // CMultiframeProvider::SetVFScalingTargetSize()
       
   384 //
       
   385 // -----------------------------------------------------------------------------
       
   386 //
       
   387 void CMultiframeProvider::SetVFScalingTargetSize( TSize aSize )
       
   388 	  {
       
   389 	  __IF_DEBUG(Print(_L("VideoSource [%d]: CMultiframeProvider::SetVFScalingTargetSize() >>"), RThread().Id().operator TUint()));
       
   390   	iTargetSize = aSize;
       
   391 	  __IF_DEBUG(Print(_L("VideoSource [%d]: CMultiframeProvider::SetVFScalingTargetSize() W %d H %d <<"), RThread().Id().operator TUint(), aSize.iWidth , aSize.iHeight ));
       
   392   	}
       
   393 
       
   394 // -----------------------------------------------------------------------------
       
   395 // CMultiframeProvider::ConvertAndScaleL()
       
   396 // -----------------------------------------------------------------------------
       
   397 //
       
   398 void CMultiframeProvider::ConvertAndScaleL( TInt aFrameIndex )
       
   399 	  {
       
   400 	  // Variables related to Bitmap size
       
   401 	  // calculation
       
   402 	  __IF_DEBUG(Print(_L("VideoSource [%d]: CMultiframeProvider::ConvertAndScale()  aFrameIndex %d>>"), RThread().Id().operator TUint(),aFrameIndex));
       
   403 	  TSize convertedBitmapSize;
       
   404 	  TFrameInfo frameInfo( iImageDecoder->FrameInfo( aFrameIndex ) );
       
   405 	  if ( !iInitialization )
       
   406 		    {
       
   407 			  TInt delayindex;
       
   408 			  delayindex = aFrameIndex - 1;
       
   409 			  if ( delayindex <  KFirstFrameIndx )
       
   410 					  {
       
   411 						delayindex = ( iCount - 1 );
       
   412 					  }
       
   413 			  TFrameInfo delayframeInfo( iImageDecoder->FrameInfo( delayindex ) );
       
   414 			  iDelay = delayframeInfo.iDelay;
       
   415 		    }
       
   416 	  else
       
   417 		    {
       
   418 		    iDelay = 1;
       
   419 		    }
       
   420 	  __IF_DEBUG(Print(_L("VideoSource [%d]: CMultiframeProvider::ConvertAndScale()  iDelay %d>>"), RThread().Id().operator TUint(),iDelay.Int64() ));
       
   421 #ifdef _DEBUG
       
   422     TUint threadId( RThread().Id() );
       
   423     switch ( frameInfo.iFrameDisplayMode )
       
   424         {
       
   425         case EColor4K:
       
   426             RDebug::Print( _L( "VideoSource [%d]: FrameDPmode = EColor4K" ),
       
   427             	threadId );
       
   428             break;
       
   429         case EColor64K:
       
   430             RDebug::Print( _L( "VideoSource [%d]: FrameDPmode = EColor64K" ),
       
   431             	threadId );
       
   432             break;
       
   433         case EColor16M:
       
   434           	  RDebug::Print( _L( "VideoSource [%d]: FrameDPmode = EColor16M" ),
       
   435             	threadId );
       
   436             break;
       
   437         case EColor16MU:
       
   438           	  RDebug::Print( _L( "VideoSource [%d]: FrameDPmode = EColor16MU" ),
       
   439             	threadId );
       
   440            	 break;
       
   441         default:
       
   442            	 RDebug::Print( _L( "VideoSource [%d]: FrameDPmode = %d" ),
       
   443             	threadId, frameInfo.iFrameDisplayMode );
       
   444            	 break;
       
   445         }
       
   446 
       
   447     RDebug::Print( _L( "VideoSource [%d]: CMultiframeProvider:: frameInfo.iFlags %d" ),
       
   448         threadId,frameInfo.iFlags );
       
   449 #endif // _DEBUG
       
   450 
       
   451  	  // Use imagedecoder to calculate how many times source picture needs to be divided by 2
       
   452  	  // to fit in default (VGA) picture
       
   453 	  TInt reductionfactor = iImageDecoder->ReductionFactor( frameInfo.iOverallSizeInPixels,
       
   454 		    TSize( KDefaultBitmapSizeWidth, KDefaultBitmapSizeHeight ) );
       
   455  	  if ( iImageDecoder->ReducedSize( frameInfo.iOverallSizeInPixels, reductionfactor, convertedBitmapSize ) )
       
   456     	  {
       
   457     	  convertedBitmapSize = frameInfo.iOverallSizeInPixels;
       
   458     	  }
       
   459 
       
   460 #ifdef _DEBUG
       
   461 	   RDebug::Print( _L( "VideoSource [%d]: convertedBitmapSize Width = %d convertedBitmapSize Height = %d" ),
       
   462 		    threadId, convertedBitmapSize.iWidth, convertedBitmapSize.iHeight );
       
   463 #endif // _DEBUG
       
   464 	  __IF_DEBUG(Print(_L("VideoSource [%d]: CMultiframeProvider::ConvertAndScale() iConverted"), RThread().Id().operator TUint()));
       
   465 	      iConverted = CVtImageBitmap::NewL( convertedBitmapSize, iDisplayMode );
       
   466 	  __IF_DEBUG(Print(_L("VideoSource [%d]: CMultiframeProvider::ConvertAndScale() iConverted"), RThread().Id().operator TUint()));
       
   467 #ifdef _DEBUG
       
   468 	  RDebug::Print( _L( "VideoSource [%d]: convBitmap Width = %d convBitmap Height = %d" ),
       
   469 		    threadId, iConverted->Size().iWidth, iConverted->Size().iHeight );
       
   470 #endif // _DEBUG
       
   471 
       
   472 	  iStartTime.HomeTime();
       
   473 	  if ( iFreeQueue.Count() < 2 )
       
   474        	{
       
   475        	__IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::ConvertAndScale() iFreeQueue.Count() < 2 "), RThread().Id().operator TUint()));
       
   476        	iOldBM = ETrue;
       
   477        	iOldBitmap = iScaled;
       
   478        	}
       
   479     iScaled	= iFreeQueue[ 0 ];
       
   480 	  iFreeQueue.Remove( 0 );
       
   481 	  iLoopAo->RemoveFreeBitmaps( 1 );
       
   482 	  iActiveWaitInit->InitializeWaiter( &CMultiframeProvider::ConversionFinished );
       
   483 	  // Check if masking is supported
       
   484 	  if ( frameInfo.iFlags & TFrameInfo::ETransparencyPossible )
       
   485 		    {
       
   486 		    // Create mask for bitmap
       
   487 		    iMask = new ( ELeave )CFbsBitmap();
       
   488 		    User::LeaveIfError( iMask->Create( convertedBitmapSize, EGray256 ));
       
   489 		    iTempBM = CVtImageBitmap::NewL( convertedBitmapSize, iDisplayMode );
       
   490 		    iImageDecoder->Convert( iActiveWaitInit->RequestStatus(), iTempBM->Bitmap(), *iMask, aFrameIndex );
       
   491 		    }
       
   492 	  // No mask
       
   493 	  else
       
   494 		    {
       
   495 		    iImageDecoder->Convert( iActiveWaitInit->RequestStatus(), iConverted->Bitmap(), aFrameIndex );
       
   496 		    }
       
   497 	  __IF_DEBUG(Print(_L("VideoSource [%d]: CMultiframeProvider::ConvertAndScale() <<"), RThread().Id().operator TUint()));
       
   498 	}
       
   499 
       
   500 // -----------------------------------------------------------------------------
       
   501 // CMultiframeProvider::ConversionFinished( TInt aError )
       
   502 // -----------------------------------------------------------------------------
       
   503 //
       
   504 void CMultiframeProvider::ConversionFinished( TInt aError )
       
   505     {
       
   506     __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::ConversionFinished() >>"), RThread().Id().operator TUint()));
       
   507     if ( iCount == 1 || aError )
       
   508         {
       
   509         // delete decoder if not needed any more 
       
   510         // 1) single frame image, no further frames to convert
       
   511         // 2) error occured, decoder won't be used anyway
       
   512         __IF_DEBUG(Print(_L(" single frame image => destruct iImageDecoder, err %d"), aError ) );
       
   513         delete iImageDecoder;
       
   514         iImageDecoder = NULL;
       
   515         }
       
   516     // no harm done if other than this used, handle would already be 0
       
   517     iDefaultImageFile.Close(); 
       
   518     if ( aError == KErrNone )
       
   519         {
       
   520 				iActiveWaitInitScale->InitializeWaiter( &BMSScalingFinished );
       
   521       	if ( iGSImage )
       
   522        			{
       
   523        			__IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::ConversionFinished() scale GS "), RThread().Id().operator TUint()));
       
   524        			iVtImageScalerInit->Scale( *iGSBitmap, *iScaled );
       
   525       			}
       
   526       	else
       
   527       			{
       
   528        			__IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::ConversionFinished() scale "), RThread().Id().operator TUint()));
       
   529        			// Blit mask into a converted bitmap
       
   530        			if ( iMask )
       
   531        					{
       
   532        					CGraphicsContext* bitmapcontext = NULL;
       
   533        					CFbsBitmapDevice* bitmapdevice = NULL;
       
   534        					// Create bm device
       
   535        					TRAPD( error, bitmapdevice = CFbsBitmapDevice::NewL( &( iConverted->Bitmap() ) ) );
       
   536        					if ( error != KErrNone )
       
   537        							{
       
   538        							iObserver->NotifyImageHandlingError( aError );
       
   539        							delete bitmapdevice;
       
   540        							delete iTempBM;
       
   541        							delete iMask;
       
   542        							iMask = NULL;
       
   543        							iTempBM = NULL;
       
   544        							return;
       
   545        							}
       
   546        					// Create GC for bm
       
   547        					error = bitmapdevice->CreateContext( bitmapcontext );
       
   548        					if ( error != KErrNone )
       
   549        							{
       
   550        							iObserver->NotifyImageHandlingError( aError );
       
   551        							delete bitmapdevice;
       
   552        							delete bitmapcontext;
       
   553        							delete iTempBM;
       
   554        							delete iMask;
       
   555        							iMask = NULL;
       
   556        							iTempBM = NULL;
       
   557        							return;
       
   558        							}
       
   559        					// Fill destination bitmap with white color
       
   560        					TRect rect( iConverted->Size() );
       
   561        					bitmapcontext->SetBrushStyle( CGraphicsContext:: ESolidBrush );
       
   562        					bitmapcontext->SetPenStyle( CGraphicsContext::ESolidPen );
       
   563        					bitmapcontext->SetBrushColor( KRgbWhite );
       
   564        					bitmapcontext->SetPenColor( KRgbWhite);
       
   565        					bitmapcontext->DrawRect( rect );
       
   566 
       
   567        					// Draw mask and data bitmap into a same destination bm
       
   568        					bitmapcontext->DrawBitmapMasked( iConverted->Size(), &( iTempBM->Bitmap() ), iConverted->Size(), iMask, EFalse );
       
   569        					delete bitmapdevice;
       
   570        					delete bitmapcontext;
       
   571        					delete iTempBM;
       
   572        					delete iMask;
       
   573        					iMask = NULL;
       
   574        					iTempBM = NULL;
       
   575        				 	__IF_DEBUG(Print(_L("VideoSource [%d]: CMultiframeProvider::ConversionFinished() iMask"), RThread().Id().operator TUint()));
       
   576        					}
       
   577        			iVtImageScalerInit->Scale( *iConverted, *iScaled );
       
   578       			}
       
   579         	}
       
   580     // Allways inform Decoding problems
       
   581     else
       
   582        	{
       
   583         iObserver->NotifyImageHandlingError( aError );
       
   584         delete iTempBM;
       
   585        	delete iMask;
       
   586        	iMask = NULL;
       
   587        	iTempBM = NULL;
       
   588         }
       
   589     __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::ConversionFinished() error %d <<"), RThread().Id().operator TUint(), aError));
       
   590     }
       
   591 
       
   592 // -----------------------------------------------------------------------------
       
   593 // CMultiframeProvider::BMSScalingFinished( TInt aError )
       
   594 // -----------------------------------------------------------------------------
       
   595 //
       
   596 void CMultiframeProvider::BMSScalingFinished( TInt aError )
       
   597     {
       
   598     __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::BMSScalingFinished() >>"), RThread().Id().operator TUint()));
       
   599     if ( aError == KErrNone )
       
   600         {
       
   601         VFScalingReady();
       
   602         }
       
   603     else
       
   604         {
       
   605 #if 0
       
   606         if ( aError != KErrCancel ) // If KErrCancel, then ignore error!
       
   607             {
       
   608         	iObserver->NotifyImageHandlingError( aError );
       
   609         	}
       
   610         //Needs to be deleted also in cancel case
       
   611         delete iConverted; iConverted = NULL;
       
   612 #endif
       
   613         delete iConverted; iConverted = NULL;
       
   614         iObserver->NotifyImageHandlingError( aError );
       
   615         
       
   616         }
       
   617     __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::BMSScalingFinished() err %d <<"), RThread().Id().operator TUint(), aError));
       
   618     }
       
   619 
       
   620 // -----------------------------------------------------------------------------
       
   621 // CMultiframeProvider::AddBitmapToFreeQueue( CVtImageBitmap* aBitmap )
       
   622 // -----------------------------------------------------------------------------
       
   623 //
       
   624 void CMultiframeProvider::AddBitmapToFreeQueue()
       
   625     {
       
   626     __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::AddBitmapToFreeQueue() >>"), RThread().Id().operator TUint()));
       
   627     if ( iOldBM )
       
   628     	  {
       
   629     	  __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::AddBitmapToFreeQueue() OLD BM"), RThread().Id().operator TUint()));
       
   630     	  iOldBM = EFalse;
       
   631         iFreeQueue.Append( iOldBitmap );
       
   632     	  }
       
   633     else
       
   634     	  {
       
   635    	 	  iFreeQueue.Append( iScaled );
       
   636   		  }
       
   637     iLoopAo->SetFreeBitmaps( 1 );
       
   638     __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::AddBitmapToFreeQueue() <<"), RThread().Id().operator TUint()));
       
   639     }
       
   640     
       
   641 // -----------------------------------------------------------------------------
       
   642 // CMultiframeProvider::UseSecondVfBuffer()
       
   643 // -----------------------------------------------------------------------------
       
   644 //
       
   645 void CMultiframeProvider::UseSecondVfBuffer()
       
   646     {
       
   647     iSecondVFBuffer = ETrue;
       
   648     }
       
   649 
       
   650 // -----------------------------------------------------------------------------
       
   651 // CMultiframeProvider::VFScalingReady()
       
   652 // -----------------------------------------------------------------------------
       
   653 //
       
   654 void CMultiframeProvider::VFScalingReady()
       
   655     {
       
   656     __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::VFScalingReady() >>"), RThread().Id().operator TUint()));
       
   657     delete iConverted; iConverted = 0;
       
   658 
       
   659     // Calculate frame update delay here!
       
   660     TTime refpointtime;
       
   661     refpointtime.HomeTime();
       
   662     TTimeIntervalMicroSeconds deltaTime = refpointtime.MicroSecondsFrom( iStartTime );
       
   663     iFrameUpdateTime = iDelay.Int64() - deltaTime.Int64();
       
   664     if ( iFrameUpdateTime < 0 )
       
   665     		{
       
   666     		iFrameUpdateTime = 1;
       
   667     		}
       
   668     __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::VFScalingReady() iFrameUpdateTime %d>>"), RThread().Id().operator TUint(), iFrameUpdateTime.Int64()));
       
   669   	// Scale VF to fit in requested size
       
   670   	// size is as default QCIF
       
   671     if ( iIsVfStopped )
       
   672         {
       
   673         __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::VFScalingReady()VF Stop>>"), RThread().Id().operator TUint()));
       
   674         if ( iActiveWaitScale->IsActive() )
       
   675             {
       
   676             //ScaleCopy running
       
   677             //Waiting is OK
       
   678             __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::VFScalingReady()ScaleCopy running>>"), RThread().Id().operator TUint()));
       
   679             }
       
   680         else
       
   681             {
       
   682             //ScaleCopy is not running, Jump ScaleCopy
       
   683             __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::VFScalingReady()jump ScaleCopy>>"), RThread().Id().operator TUint()));
       
   684             iActiveWaitScale->InitializeWaiter( &VFRescalingFinished );
       
   685             iActiveWaitScale->Signal(KErrNone);
       
   686             }
       
   687         }
       
   688     else
       
   689         {
       
   690         __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::VFScalingReady()Normal run>>"), RThread().Id().operator TUint()));
       
   691         iVFUpdate = EFalse;
       
   692         ScaleCopy( iTargetSize );
       
   693         }
       
   694     __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::VFScalingReady() <<"), RThread().Id().operator TUint()));
       
   695     }
       
   696 
       
   697 // -----------------------------------------------------------------------------
       
   698 // CMultiframeProvider::ScaleCopy( TSize& aSize )
       
   699 // -----------------------------------------------------------------------------
       
   700 //
       
   701 void CMultiframeProvider::ScaleCopy( TSize& aSize,  TBool aVFUpdate  )
       
   702     {
       
   703     __IF_DEBUG(Print(_L("VideoSource [%d]: CMultiframeProvider::ScaleCopy() >>"), RThread().Id().operator TUint()));
       
   704 
       
   705     iVFUpdate = aVFUpdate;
       
   706     iVFSize = aSize;
       
   707     if ( iSecondVFBuffer && !iFirstVFBuffer )
       
   708         {
       
   709         iVFbitmap = iSecondVfBuf;
       
   710         iSecondVFBuffer = EFalse;
       
   711         iFirstVFBuffer = ETrue;
       
   712         }
       
   713     else
       
   714         {
       
   715         iVFbitmap = iFirstVfBuf;
       
   716         iFirstVFBuffer = EFalse;
       
   717         }
       
   718     //If Scaling is ongoing
       
   719     if ( iActiveWaitScale->IsActive() )
       
   720         {
       
   721         __IF_DEBUG(Print(_L("VideoSource [%d]: CMultiframeProvider::ScaleCopy(): active, storing size"), RThread().Id().operator TUint()));
       
   722         iWantedVFSize = aSize;
       
   723         }
       
   724     else
       
   725         {
       
   726         __IF_DEBUG(Print(_L("VideoSource [%d]: CMultiframeProvider::ScaleCopy(): scaling NOW"), RThread().Id().operator TUint()));
       
   727         iActiveWaitScale->InitializeWaiter( &VFRescalingFinished );
       
   728         TInt result( iVFbitmap->Bitmap().Resize( aSize ) );
       
   729         __IF_DEBUG(Print(_L("VideoSource [%d]: CMultiframeProvider::ScaleCopy() result %d <<"), RThread().Id().operator TUint(), result));
       
   730         if ( result != KErrNone )
       
   731             {
       
   732             iActiveWaitScale->Signal( result );
       
   733             }
       
   734         else
       
   735             {
       
   736             iVtImageScalerScale->Scale( *iScaled, *iVFbitmap );
       
   737             }
       
   738         }
       
   739     }
       
   740 // -----------------------------------------------------------------------------
       
   741 // CMultiframeProvider::NextFrame()
       
   742 // -----------------------------------------------------------------------------
       
   743 //
       
   744 void CMultiframeProvider::NextFrame()
       
   745     {
       
   746     iFreezeCS.Wait();
       
   747     iInitialization = EFalse;
       
   748     __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::NextFrame() >>"), RThread().Id().operator TUint()));
       
   749     
       
   750     if ( iNumOfConsumers < 1 )
       
   751         {
       
   752         __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::NextFrame() Consumer < 1>>"), RThread().Id().operator TUint()));
       
   753         iFreezeCS.Signal();
       
   754         return;
       
   755         }
       
   756     
       
   757     if (iCount > 1 && !iActiveWaitInit->IsActive() )
       
   758         {
       
   759         if (iWaitForConverting)
       
   760             {
       
   761             __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::NextFrame() Because CMultiframeloopAO::RunL is executing, so Signal is not needed"), RThread().Id().operator TUint()));
       
   762             }
       
   763         else
       
   764             {
       
   765             iLoopAo->Signal();
       
   766             }
       
   767         }
       
   768     __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::NextFrame() <<"), RThread().Id().operator TUint()));
       
   769     iFreezeCS.Signal();
       
   770     }
       
   771 
       
   772 // -----------------------------------------------------------------------------
       
   773 // CMultiframeProvider::IncreaseDataConsumer()
       
   774 // -----------------------------------------------------------------------------
       
   775 //
       
   776 void CMultiframeProvider::IncreaseDataConsumer()
       
   777     {
       
   778     iFreezeCS.Wait();
       
   779     __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::IncreaseDataConsumer() >>"), RThread().Id().operator TUint()));
       
   780     ++iNumOfConsumers;
       
   781     iFreezeCS.Signal();
       
   782     __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::IncreaseDataConsumer() <<"), RThread().Id().operator TUint()));
       
   783     }
       
   784 
       
   785 // -----------------------------------------------------------------------------
       
   786 // CMultiframeProvider::DecreaseDataConsumer()
       
   787 // -----------------------------------------------------------------------------
       
   788 //
       
   789 void CMultiframeProvider::DecreaseDataConsumer()
       
   790 	  {
       
   791 		iFreezeCS.Wait();
       
   792 		__IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::DecreaseDataConsumer() >>"), RThread().Id().operator TUint()));
       
   793 		--iNumOfConsumers;
       
   794 		if ( iNumOfConsumers < 1 )
       
   795     	  {
       
   796   		  iLoopAo->CancelDataLoop();
       
   797         iDataTimer->CancelTimeLoop();
       
   798   	  	}
       
   799   	__IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::DecreaseDataConsumer() <<"), RThread().Id().operator TUint()));  	
       
   800   	iFreezeCS.Signal();
       
   801 	  }
       
   802 // -----------------------------------------------------------------------------
       
   803 // CMultiframeProvider::ScaleVF( const TSize& aSize )
       
   804 // -----------------------------------------------------------------------------
       
   805 //
       
   806 void CMultiframeProvider::ScaleVF( const TSize& aSize )
       
   807     {
       
   808     __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::ScaleVF() >>"), RThread().Id().operator TUint()));
       
   809     iActiveWaitScale->InitializeWaiter( &VFRescalingFinished );
       
   810     TInt result( iVFbitmap->Bitmap().Resize( aSize ) );
       
   811     ClearVFScalingTargetSize();
       
   812     if ( result != KErrNone )
       
   813         {
       
   814         iActiveWaitScale->Signal( result );
       
   815         }
       
   816     else
       
   817         {
       
   818         iVtImageScalerScale->Scale( *iScaled, *iVFbitmap );
       
   819         }
       
   820     __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::ScaleVF() result %d <<"), RThread().Id().operator TUint(), result));
       
   821     }
       
   822 
       
   823 // -----------------------------------------------------------------------------
       
   824 // CMultiframeProvider::VFRescalingFinished( TInt aError )
       
   825 // -----------------------------------------------------------------------------
       
   826 //
       
   827 void CMultiframeProvider::VFRescalingFinished( TInt aError )
       
   828     {
       
   829     __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::VFRescalingFinished() >>"), RThread().Id().operator TUint()));
       
   830     if ( aError == KErrNone )
       
   831         {
       
   832         if ( iWantedVFSize != TSize() )
       
   833             {
       
   834             __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::VFRescalingFinished() REScaling needed"), RThread().Id().operator TUint()));
       
   835             ScaleVF( iWantedVFSize );
       
   836             ClearVFScalingTargetSize();
       
   837             }
       
   838         else
       
   839             {
       
   840             iDataTimer->CancelTimeLoop();
       
   841             
       
   842             if ( !iIsVfStopped && !iVFUpdate )
       
   843                 {
       
   844                 //Normally, VF and VS work
       
   845                 iVFCurrent = iVFbitmap;
       
   846                 iYUVBitMap = iScaled;
       
   847                 iDataTimer->LocalBuffer(iVFCurrent);
       
   848                 iDataTimer->RemoteBuffer(iYUVBitMap);
       
   849                 __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::ScalecopyRemoteAndUpdate() normal, iFrameUpdateTime %d>>"), RThread().Id().operator TUint(),
       
   850                         iFrameUpdateTime.Int64()));
       
   851                 iDataTimer->Activate(iFrameUpdateTime, iInitialization, iVFUpdate);
       
   852                 }
       
   853             else if ( iIsVfStopped && !iVFUpdate )
       
   854                 {
       
   855                 //VF doesn't work.
       
   856                 iYUVBitMap = iScaled;
       
   857                 iDataTimer->RemoteBuffer(iYUVBitMap);
       
   858                 __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::ScalecopyRemoteAndUpdate() VF Stop, iFrameUpdateTime %d>>"), RThread().Id().operator TUint(),
       
   859                         iFrameUpdateTime.Int64()));                
       
   860                 iDataTimer->Activate( iFrameUpdateTime, iInitialization, iVFUpdate);
       
   861                 }
       
   862             else if ( iIsVfStopped && iVFUpdate )
       
   863                 {
       
   864                 //VF restart 
       
   865                 iIsVfStopped = EFalse;
       
   866                 iVFUpdate = EFalse;
       
   867                 iVFCurrent = iVFbitmap;
       
   868                 iYUVBitMap = iScaled;
       
   869                 iDataTimer->LocalBuffer(iVFCurrent);
       
   870                 iDataTimer->RemoteBuffer(iYUVBitMap);
       
   871                 __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::ScalecopyRemoteAndUpdate() VF Restart iFrameUpdateTime 1>>"),
       
   872                         RThread().Id().operator TUint()));
       
   873                 iDataTimer->Activate(1, iInitialization, iVFUpdate);
       
   874                 }
       
   875             else
       
   876                 {
       
   877                 //maybe this condition never execute.
       
   878                 iVFCurrent = iVFbitmap;
       
   879                 iDataTimer->LocalBuffer(iVFCurrent);
       
   880                 __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::ScalecopyRemoteAndUpdate() last one, iFrameUpdateTime %d>>"), RThread().Id().operator TUint(),
       
   881                         iFrameUpdateTime.Int64()));                
       
   882                 iDataTimer->Activate( 1, iInitialization, iVFUpdate);
       
   883                 }
       
   884             }
       
   885         }
       
   886 #if 0
       
   887     else if ( ( aError == KErrCancel ) )
       
   888         {
       
   889         __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::VFRescalingFinished() CANCEL"), RThread().Id().operator TUint()));
       
   890         }
       
   891     else if( aError != KErrCancel ) // If KErrCancel, then ignore error!
       
   892         {
       
   893         iObserver->NotifyImageHandlingError( aError );
       
   894         }
       
   895 #endif
       
   896     else
       
   897         {
       
   898         iObserver->NotifyImageHandlingError( aError );
       
   899         }
       
   900     
       
   901     __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::VFRescalingFinished() err %d <<"), RThread().Id().operator TUint(), aError));
       
   902     }
       
   903 
       
   904 // -----------------------------------------------------------------------------
       
   905 // CMultiframeProvider::IsVFStopped()
       
   906 // -----------------------------------------------------------------------------
       
   907 //
       
   908 TBool CMultiframeProvider::IsVFStopped()
       
   909     {
       
   910     __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::IsVFStopped() >>"), RThread().Id().operator TUint()));
       
   911     __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::IsVFStopped() <<"), RThread().Id().operator TUint()));
       
   912     return iIsVfStopped;
       
   913     }
       
   914 
       
   915 // -----------------------------------------------------------------------------
       
   916 // CMultiframeProvider::SetVFStop()
       
   917 // -----------------------------------------------------------------------------
       
   918 //
       
   919 void CMultiframeProvider::SetVFStop()
       
   920     {
       
   921     __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::SetVFStop() >>"), RThread().Id().operator TUint()));
       
   922     iIsVfStopped = ETrue;
       
   923     __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::SetVFStop() <<"), RThread().Id().operator TUint()));
       
   924     }
       
   925 
       
   926 // -----------------------------------------------------------------------------
       
   927 // CMultiframeProvider::WaitForConverting()
       
   928 // -----------------------------------------------------------------------------
       
   929 //
       
   930 void CMultiframeProvider::WaitForConverting()
       
   931     {
       
   932     __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::WaitForConverting() >>"), RThread().Id().operator TUint()));
       
   933     iWaitForConverting = ETrue;
       
   934     __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::WaitForConverting() <<"), RThread().Id().operator TUint()));
       
   935     }
       
   936 
       
   937 // -----------------------------------------------------------------------------
       
   938 // CMultiframeProvider::WaitForConverting()
       
   939 // -----------------------------------------------------------------------------
       
   940 //
       
   941 void CMultiframeProvider::ReleaseForConverting()
       
   942     {
       
   943     __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::ReleaseForConverting() >>"), RThread().Id().operator TUint()));
       
   944     iWaitForConverting = EFalse;
       
   945     __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::ReleaseForConverting() <<"), RThread().Id().operator TUint()));
       
   946     }
       
   947 
       
   948 // -----------------------------------------------------------------------------
       
   949 // CMultiframeProvider::ClearVFScalingTargetSize()
       
   950 // -----------------------------------------------------------------------------
       
   951 //
       
   952 void CMultiframeProvider::ClearVFScalingTargetSize()
       
   953     {
       
   954     __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::ClearVFScalingTargetSize() >>"), RThread().Id().operator TUint()));
       
   955     iWantedVFSize = TSize();
       
   956     __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::ClearVFScalingTargetSize() <<"), RThread().Id().operator TUint()));
       
   957     }
       
   958 
       
   959 // -----------------------------------------------------------------------------
       
   960 // CMultiframeProvider::CancelInitializing()
       
   961 // -----------------------------------------------------------------------------
       
   962 //
       
   963 TBool CMultiframeProvider::CancelInitializing()
       
   964     {
       
   965     __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::CancelInitializing() >>"), RThread().Id().operator TUint()));
       
   966     TBool lResult = EFalse;
       
   967     
       
   968     if ( NULL == iImageDecoder )
       
   969         {
       
   970         __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::CancelInitializing() iImageDecoder is NULL ==="), RThread().Id().operator TUint()));
       
   971         // In this condition, Convert is already finished
       
   972         if ( iVtImageScalerInit->IsActive() )
       
   973             {
       
   974             __IF_DEBUG(Print(_L("VideoSource[%d] Line[%d]: CMultiframeProvider::CancelInitializing() iVtImageScalerInit->Cancel ==="), 
       
   975                     RThread().Id().operator TUint(), __LINE__));
       
   976             iVtImageScalerInit->Cancel();
       
   977             }
       
   978         else if ( iActiveWaitInitScale->IsActive() )
       
   979             {
       
   980             __IF_DEBUG(Print(_L("VideoSource[%d] Line[%d]: CMultiframeProvider::CancelInitializing() iActiveWaitInitScale->Cancel ==="), 
       
   981                     RThread().Id().operator TUint(), __LINE__));
       
   982             iActiveWaitInitScale->Cancel();
       
   983             }            
       
   984         else if ( iVtImageScalerScale->IsActive() )
       
   985             {
       
   986             __IF_DEBUG(Print(_L("VideoSource[%d] Line[%d]: CMultiframeProvider::CancelInitializing() iVtImageScalerScale->Cancel ==="), 
       
   987                     RThread().Id().operator TUint(), __LINE__));
       
   988             iVtImageScalerScale->Cancel();
       
   989             }
       
   990         else if ( iActiveWaitScale->IsActive() )
       
   991             {
       
   992             __IF_DEBUG(Print(_L("VideoSource[%d] Line[%d]: CMultiframeProvider::CancelInitializing() iActiveWaitScale->Cancel ==="), 
       
   993                     RThread().Id().operator TUint(), __LINE__));
       
   994             iActiveWaitScale->Cancel();
       
   995             }
       
   996         else
       
   997             {
       
   998             //In this condition, the convert,scale,copyScale were finished,
       
   999             //so do nothing, Waiting for InitializeReady()
       
  1000             __IF_DEBUG(Print(_L("VideoSource[%d] Line[%d]: CMultiframeProvider::CancelInitializing() Nothong to do,wait finish ==="), 
       
  1001                     RThread().Id().operator TUint(), __LINE__));
       
  1002             }
       
  1003         }
       
  1004     else
       
  1005         {
       
  1006         __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::CancelInitializing() cancel convert ==="), RThread().Id().operator TUint()));
       
  1007         //Convert is not finished, so we can cancel it, and return ETrue
       
  1008         iImageDecoder->Cancel();
       
  1009         lResult = ETrue;
       
  1010         }
       
  1011     
       
  1012     __IF_DEBUG(Print(_L("VideoSource[%d]: CMultiframeProvider::CancelInitializing() <<"), RThread().Id().operator TUint()));
       
  1013     return lResult;
       
  1014     }
       
  1015 
       
  1016 // ========================== OTHER EXPORTED FUNCTIONS =========================
       
  1017 
       
  1018 //  End of File
       
  1019