vtengines/videoteleng/Src/Media/CVtEngLocalVideo.cpp
branchRCL_3
changeset 35 779871d1e4f4
parent 34 f15ac8e65a02
equal deleted inserted replaced
34:f15ac8e65a02 35:779871d1e4f4
    31 #include    <videotelephonydomainpskeys.h>
    31 #include    <videotelephonydomainpskeys.h>
    32 #include    <videotelephonyvariant.hrh>
    32 #include    <videotelephonyvariant.hrh>
    33 #include    <capivideosource.h>
    33 #include    <capivideosource.h>
    34 #include    <cvtlogger.h>
    34 #include    <cvtlogger.h>
    35 #include    <mvtprotocolhandler.h>
    35 #include    <mvtprotocolhandler.h>
    36 #include    <fbs.h> 
       
    37 #include    <w32std.h> 
       
    38 #include    <graphics/suerror.h>
       
    39 #include    <graphics/surfaceconfiguration.h> 
       
    40 
    36 
    41 #include    "CVtEngCameraPreferences.h"
    37 #include    "CVtEngCameraPreferences.h"
    42 
    38 
    43 // LOCAL CONSTANTS AND MACROS
    39 // LOCAL CONSTANTS AND MACROS
    44 
    40 
    95     {
    91     {
    96     __VTPRINTENTER( "LocVideo.ConstructL" )
    92     __VTPRINTENTER( "LocVideo.ConstructL" )
    97 
    93 
    98     iAsyncCallBack = new ( ELeave ) CAsyncCallBack(
    94     iAsyncCallBack = new ( ELeave ) CAsyncCallBack(
    99         TCallBack( CallBackFunc, this ), EPriorityStandard );
    95         TCallBack( CallBackFunc, this ), EPriorityStandard );
   100 
       
   101     iNGARender = CVtEngVFBitmapNGARender::NewL();
       
   102 
    96 
   103     TInt indexMobile( KErrNotFound );
    97     TInt indexMobile( KErrNotFound );
   104     iShareImage = CVtEngShareImage::NewL( *this );
    98     iShareImage = CVtEngShareImage::NewL( *this );
   105     iSourceController = CVSController::NewL( this );
    99     iSourceController = CVSController::NewL( this );
   106     iVideoProviders =
   100     iVideoProviders =
   372 
   366 
   373     delete iSource;
   367     delete iSource;
   374     delete iSourceController;
   368     delete iSourceController;
   375     DeleteAudioSource();
   369     DeleteAudioSource();
   376     delete iShareImage;
   370     delete iShareImage;
   377 
       
   378     delete iNGARender;
       
   379     
       
   380     __VTPRINTEXIT( "LocVid.~" )
   371     __VTPRINTEXIT( "LocVid.~" )
   381     }
   372     }
   382 
   373 
   383 // -----------------------------------------------------------------------------
   374 // -----------------------------------------------------------------------------
   384 // CVtEngLocalVideo::vsProviderError
   375 // CVtEngLocalVideo::vsProviderError
   840     {
   831     {
   841     __VTPRINTENTER( "LocVid.vsViewFinderFrameReady" )
   832     __VTPRINTENTER( "LocVid.vsViewFinderFrameReady" )
   842     if ( iActiveProvider &&
   833     if ( iActiveProvider &&
   843          iActiveProvider->iType != KVtEngProviderNone )
   834          iActiveProvider->iType != KVtEngProviderNone )
   844         {
   835         {
   845 #if 0
       
   846         TRAP_IGNORE( iOptions.iObserver->vtHandleFrameL(
   836         TRAP_IGNORE( iOptions.iObserver->vtHandleFrameL(
   847             MVtEngFrameObserver::ELocalVideoFrame, &aFrame ) );
   837             MVtEngFrameObserver::ELocalVideoFrame, &aFrame ) );
   848 #endif
       
   849         iNGARender->UpdateBitmapL( aFrame );
       
   850         }
   838         }
   851     __VTPRINTEXIT( "LocVid.vsViewFinderFrameReady" )
   839     __VTPRINTEXIT( "LocVid.vsViewFinderFrameReady" )
   852     }
   840     }
   853 
   841 
   854 // -----------------------------------------------------------------------------
   842 // -----------------------------------------------------------------------------
  1117     iDsaOptions.iRect = aDP.iRect;
  1105     iDsaOptions.iRect = aDP.iRect;
  1118     iDsaOptions.iWindow = &aDP.iWindow;
  1106     iDsaOptions.iWindow = &aDP.iWindow;
  1119     iDsaOptions.iWs = &aDP.iWs;
  1107     iDsaOptions.iWs = &aDP.iWs;
  1120     iDsaOptions.iWsSD = &aDP.iWsSD;
  1108     iDsaOptions.iWsSD = &aDP.iWsSD;
  1121     __VTPRINTEXIT( "LocVid.SetVFParamsDP" )
  1109     __VTPRINTEXIT( "LocVid.SetVFParamsDP" )
  1122     }
       
  1123 
       
  1124 // -----------------------------------------------------------------------------
       
  1125 // CVtEngLocalVideo::SetViewFinderParameters
       
  1126 // Configures parameters for rendering with NGA.
       
  1127 // -----------------------------------------------------------------------------
       
  1128 //
       
  1129 void CVtEngLocalVideo::SetViewFinderParameters(
       
  1130     const TVtEngRenderingOptionsNGA &aNGA )
       
  1131     {
       
  1132     __VTPRINTENTER( "LocVid.SetVFParamsNGA" )
       
  1133 
       
  1134     // Before setting the params, stop VF
       
  1135     if( ViewFinderStarted() )
       
  1136         {
       
  1137         StopViewFinder();
       
  1138         }
       
  1139 
       
  1140     iOptions.iSize.SetSize( KVtEngLocalVideoDefaultWidth, 
       
  1141                             KVtEngLocalVideoDefaultHeight );
       
  1142     
       
  1143     iWindow = &aNGA.iWindow;
       
  1144     iWs = &aNGA.iWs;
       
  1145     
       
  1146     iRenderingMethod = EWindowServer;
       
  1147 
       
  1148     iNGARender->AttachSurfaceL( iWs, iWindow );
       
  1149     __VTPRINTEXIT( "LocVid.SetVFParamsNGA" )
       
  1150     }
  1110     }
  1151 
  1111 
  1152 // -----------------------------------------------------------------------------
  1112 // -----------------------------------------------------------------------------
  1153 // CVtEngLocalVideo::SetDefaultStillImageL
  1113 // CVtEngLocalVideo::SetDefaultStillImageL
  1154 // Sets default still image.
  1114 // Sets default still image.
  1922     if ( iActiveProvider &&
  1882     if ( iActiveProvider &&
  1923          iViewFinderState != EVFNone &&
  1883          iViewFinderState != EVFNone &&
  1924          iActiveProvider->iProvider &&
  1884          iActiveProvider->iProvider &&
  1925          iActiveProvider->iProvider->ViewFinderActive() )
  1885          iActiveProvider->iProvider->ViewFinderActive() )
  1926         {
  1886         {
  1927 #if 0
       
  1928         TRAP_IGNORE( iOptions.iObserver->vtHandleFrameL(
  1887         TRAP_IGNORE( iOptions.iObserver->vtHandleFrameL(
  1929             MVtEngFrameObserver::ELocalVideoFrame, NULL ) );
  1888             MVtEngFrameObserver::ELocalVideoFrame, NULL ) );
  1930 #endif
       
  1931         iActiveProvider->iProvider->StopViewFinder();
  1889         iActiveProvider->iProvider->StopViewFinder();
  1932         __VTPRINT( DEBUG_MEDIA, "LocVideo.stopVF Stopped" )
  1890         __VTPRINT( DEBUG_MEDIA, "LocVideo.stopVF Stopped" )
  1933         if ( IsFlag( EFlagAutomaticSwitchCallback )  ||
  1891         if ( IsFlag( EFlagAutomaticSwitchCallback )  ||
  1934             IsFlag( EFlagUIBackground ) )
  1892             IsFlag( EFlagUIBackground ) )
  1935             {
  1893             {
  4540     __VTPRINTEXITR( "LocVid.LayoutCH.ProviderSwitchDone %d", handled )
  4498     __VTPRINTEXITR( "LocVid.LayoutCH.ProviderSwitchDone %d", handled )
  4541     return handled;
  4499     return handled;
  4542     }
  4500     }
  4543 
  4501 
  4544 // -----------------------------------------------------------------------------
  4502 // -----------------------------------------------------------------------------
  4545 // CVtEngLocalVideo::CVtEngVFBitmapNGARender::NewL
       
  4546 // -----------------------------------------------------------------------------
       
  4547 //
       
  4548 CVtEngLocalVideo::CVtEngVFBitmapNGARender * 
       
  4549 CVtEngLocalVideo::CVtEngVFBitmapNGARender::NewL()
       
  4550     {
       
  4551     CVtEngVFBitmapNGARender* self 
       
  4552         = new ( ELeave ) CVtEngVFBitmapNGARender();
       
  4553     CleanupStack::PushL( self );
       
  4554     self->ConstructL( );
       
  4555     CleanupStack::Pop();
       
  4556     return self;
       
  4557     }
       
  4558 
       
  4559 // -----------------------------------------------------------------------------
       
  4560 // CVtEngLocalVideo::CVtEngVFBitmapNGARender::~CVtEngVFBitmapNGARender
       
  4561 // -----------------------------------------------------------------------------
       
  4562 //
       
  4563 CVtEngLocalVideo::CVtEngVFBitmapNGARender::~CVtEngVFBitmapNGARender()
       
  4564     {
       
  4565     __VTPRINTENTER( "LocVid.NGARender.~" )
       
  4566     Cancel();
       
  4567     
       
  4568     if ( iSurfaceCreated )
       
  4569         {
       
  4570         iWindow->RemoveBackgroundSurface(ETrue);
       
  4571         iWs->UnregisterSurface(0, iSurfaceId);
       
  4572         
       
  4573         iSurfaceManager.CloseSurface(iSurfaceId);
       
  4574         iSurfaceChunk->Close();
       
  4575         delete iSurfaceChunk;
       
  4576         iSurfaceChunk = NULL;
       
  4577         
       
  4578         iSurfaceManager.Close();
       
  4579             
       
  4580         iSurfaceUpdateSession.CancelAllUpdateNotifications();
       
  4581         iSurfaceUpdateSession.Close();    
       
  4582         }
       
  4583     
       
  4584     __VTPRINTEXIT( "LocVid.NGARender.~" )
       
  4585     }
       
  4586 
       
  4587 // -----------------------------------------------------------------------------
       
  4588 // CVtEngLocalVideo::CVtEngVFBitmapNGARender::UpdateBitmap
       
  4589 // -----------------------------------------------------------------------------
       
  4590 //
       
  4591 TInt CVtEngLocalVideo::CVtEngVFBitmapNGARender::UpdateBitmapL( CFbsBitmap& aFrame )
       
  4592     {
       
  4593     __VTPRINTENTER( "LocVid.NGARender.UpdateBitmapL" )
       
  4594     // do nothing if we're already active, the newer bitmap will be ignored.
       
  4595     if ( IsActive() )
       
  4596         {
       
  4597         __VTPRINTEXIT( "LocVid.NGARender.UpdateBitmapL 0" )
       
  4598         return KErrNone;
       
  4599         }
       
  4600     else
       
  4601         {
       
  4602         if ( !iSurfaceCreated )
       
  4603             {
       
  4604             User::Leave( KErrNotReady );
       
  4605             }
       
  4606         aFrame.BeginDataAccess();
       
  4607         __VTPRINT2( DEBUG_MEDIA, "LocVid.NGARender.bitmap size = %d", aFrame.DataSize() );
       
  4608 #if 0
       
  4609         memcpy( iBuffer, aFrame.DataAddress(), aFrame.DataSize() );
       
  4610 #else
       
  4611         TInt size = aFrame.DataSize();
       
  4612         TPtr8 ptrBuffer( iBuffer, size );
       
  4613         ptrBuffer.Copy( reinterpret_cast<TUint8*>(aFrame.DataAddress()), size );
       
  4614 #endif
       
  4615         __VTPRINT( DEBUG_MEDIA, "LocVid.NGARender.bitmap step 1" );
       
  4616         aFrame.EndDataAccess();
       
  4617         __VTPRINT( DEBUG_MEDIA, "LocVid.NGARender.bitmap step 2" );
       
  4618         iStatus = KRequestPending;
       
  4619         SetActive();
       
  4620         __VTPRINT( DEBUG_MEDIA, "LocVid.NGARender.bitmap step 3" );
       
  4621         iSurfaceUpdateSession.NotifyWhenDisplayed( iStatus, iTimeStamp );
       
  4622         __VTPRINT( DEBUG_MEDIA, "LocVid.NGARender.bitmap step 4" );
       
  4623         iSurfaceUpdateSession.SubmitUpdate( KAllScreens, iSurfaceId, 0, NULL );
       
  4624         __VTPRINT( DEBUG_MEDIA, "LocVid.NGARender.bitmap step 5" );
       
  4625 
       
  4626         __VTPRINTEXIT( "LocVid.NGARender.UpdateBitmapL 1" )
       
  4627 
       
  4628         return KErrNone;
       
  4629         }
       
  4630     }
       
  4631 
       
  4632 // -----------------------------------------------------------------------------
       
  4633 // CVtEngLocalVideo::CVtEngVFBitmapNGARender::CreateSurfaceL
       
  4634 // -----------------------------------------------------------------------------
       
  4635 //
       
  4636 TInt CVtEngLocalVideo::CVtEngVFBitmapNGARender::AttachSurfaceL( 
       
  4637         RWsSession *aWs, 
       
  4638         RWindow *aWindow )
       
  4639     {
       
  4640     __VTPRINTENTER( "LocVid.NGARender.AttachSurfaceL" )
       
  4641     
       
  4642     if ( aWs == NULL || aWindow == NULL )
       
  4643         {
       
  4644         User::Leave( KErrArgument );
       
  4645         }
       
  4646         
       
  4647         if(iSurfaceCreated)
       
  4648         	return KErrNone;
       
  4649     
       
  4650     if ( !iSurfaceCreated )
       
  4651         {    
       
  4652         TInt err;
       
  4653             
       
  4654         err = iSurfaceUpdateSession.Connect();    
       
  4655         User::LeaveIfError(err);
       
  4656             
       
  4657         err = iSurfaceManager.Open();
       
  4658         User::LeaveIfError(err);
       
  4659         
       
  4660         RSurfaceManager::TSurfaceCreationAttributesBuf attributes;
       
  4661         attributes().iPixelFormat           = iSurfaceFormat; 
       
  4662         attributes().iSize.SetSize( KVtEngLocalVideoDefaultWidth, 
       
  4663                                     KVtEngLocalVideoDefaultHeight );
       
  4664         attributes().iBuffers               = EVtEngVFMaxBuffers;
       
  4665         attributes().iStride                = attributes().iSize.iWidth*4;
       
  4666         attributes().iOffsetToFirstBuffer   = 0;
       
  4667         attributes().iAlignment             = 4;
       
  4668         attributes().iContiguous            = EFalse;
       
  4669         attributes().iMappable              = ETrue;
       
  4670     
       
  4671         err = iSurfaceManager.CreateSurface( attributes, iSurfaceId );
       
  4672         User::LeaveIfError( err );  
       
  4673         
       
  4674         // Map to chunk
       
  4675         iSurfaceChunk = new RChunk();
       
  4676         User::LeaveIfNull( iSurfaceChunk );    
       
  4677         err = iSurfaceManager.MapSurface( iSurfaceId, *iSurfaceChunk );
       
  4678         User::LeaveIfError( err );    
       
  4679     
       
  4680         // Get the info from the surfaceManager
       
  4681         RSurfaceManager::TInfoBuf info;
       
  4682         err = iSurfaceManager.SurfaceInfo( iSurfaceId, info );
       
  4683         User::LeaveIfError( err );    
       
  4684     
       
  4685         TInt offset;
       
  4686         iSurfaceManager.GetBufferOffset( iSurfaceId, 0, offset );
       
  4687         iBuffer = iSurfaceChunk->Base() + offset;
       
  4688         
       
  4689         iSurfaceCreated = ETrue;
       
  4690         }
       
  4691     else
       
  4692         {
       
  4693         if ( iWs == NULL || iWindow == NULL )
       
  4694             {
       
  4695             User::Leave( KErrGeneral );
       
  4696             }
       
  4697         
       
  4698         iWindow->RemoveBackgroundSurface(ETrue);
       
  4699         iWs->UnregisterSurface(0, iSurfaceId);
       
  4700         
       
  4701         __VTPRINT( DEBUG_MEDIA, "LocVid.NGARender.Surface exists, detach first!" )
       
  4702         }
       
  4703 
       
  4704     iWs = aWs;
       
  4705     iWindow = aWindow;
       
  4706     iWs->RegisterSurface( 0, iSurfaceId );
       
  4707     
       
  4708     TSurfaceConfiguration surfaceConfig;
       
  4709     surfaceConfig.SetSurfaceId( iSurfaceId );
       
  4710     surfaceConfig.SetOrientation( CFbsBitGc::EGraphicsOrientationRotated270);
       
  4711     iWindow->SetBackgroundSurface( surfaceConfig, ETrue );
       
  4712     //iWindow->SetBackgroundSurface( iSurfaceId );
       
  4713     
       
  4714     __VTPRINTEXIT( "LocVid.NGARender.AttachSurfaceL" )
       
  4715     
       
  4716     return KErrNone;
       
  4717     }
       
  4718 
       
  4719 // -----------------------------------------------------------------------------
       
  4720 // CVtEngLocalVideo::CVtEngVFBitmapNGARender::~CVtEngVFBitmapNGARender
       
  4721 // -----------------------------------------------------------------------------
       
  4722 //
       
  4723 CVtEngLocalVideo::CVtEngVFBitmapNGARender::CVtEngVFBitmapNGARender()
       
  4724     : CActive( CActive::EPriorityStandard ),
       
  4725       iSurfaceFormat( EUidPixelFormatXRGB_8888 )
       
  4726     {
       
  4727     iSurfaceCreated = EFalse;
       
  4728 
       
  4729     CActiveScheduler::Add( this );        
       
  4730     }
       
  4731 
       
  4732 // -----------------------------------------------------------------------------
       
  4733 // CVtEngLocalVideo::CVtEngVFBitmapNGARender::ConstructL
       
  4734 // -----------------------------------------------------------------------------
       
  4735 //
       
  4736 void CVtEngLocalVideo::CVtEngVFBitmapNGARender::ConstructL( )
       
  4737     {
       
  4738     __VTPRINTENTER( "LocVid.NGARender.ConstructL" )  
       
  4739     __VTPRINTEXIT( "LocVid.NGARender.ConstructL" )
       
  4740     }
       
  4741 
       
  4742 // -----------------------------------------------------------------------------
       
  4743 // CVtEngLocalVideo::CVtEngVFBitmapNGARender::RunL
       
  4744 // -----------------------------------------------------------------------------
       
  4745 //
       
  4746 void CVtEngLocalVideo::CVtEngVFBitmapNGARender::RunL()
       
  4747     {
       
  4748     __VTPRINTENTER( "LocVid.NGARender.RunL" )  
       
  4749     __VTPRINTEXIT( "LocVid.NGARender.RunL" )
       
  4750     }
       
  4751 
       
  4752 // -----------------------------------------------------------------------------
       
  4753 // CVtEngLocalVideo::CVtEngVFBitmapNGARender::DoCancel
       
  4754 // -----------------------------------------------------------------------------
       
  4755 //
       
  4756 void CVtEngLocalVideo::CVtEngVFBitmapNGARender::DoCancel()
       
  4757     {
       
  4758     __VTPRINTENTER( "LocVid.NGARender.DoCancel" )  
       
  4759     __VTPRINTEXIT( "LocVid.NGARender.DoCancel" )
       
  4760     }
       
  4761 
       
  4762 // -----------------------------------------------------------------------------
       
  4763 // CVtEngLocalVideo::CreateCameraPreferencesL
  4503 // CVtEngLocalVideo::CreateCameraPreferencesL
  4764 // -----------------------------------------------------------------------------
  4504 // -----------------------------------------------------------------------------
  4765 //
  4505 //
  4766 CVtEngCameraPreferences* CVtEngLocalVideo::CreateCameraPreferencesL()
  4506 CVtEngCameraPreferences* CVtEngLocalVideo::CreateCameraPreferencesL()
  4767     {
  4507     {