vtengines/videoteleng/Src/Media/CVtEngDrawNGA.cpp
changeset 2 4a81900cd18b
parent 1 4fbbce2c82ba
child 8 07d1685f0cd4
equal deleted inserted replaced
1:4fbbce2c82ba 2:4a81900cd18b
   354 // -----------------------------------------------------------------------------
   354 // -----------------------------------------------------------------------------
   355 //
   355 //
   356 void CVtEngDrawNGA::BaseVideoFrameSizeChangedL( const TSize& /*aTo*/ )
   356 void CVtEngDrawNGA::BaseVideoFrameSizeChangedL( const TSize& /*aTo*/ )
   357     {
   357     {
   358     __VTPRINTENTER( "RVD(NGA).BaseVideoFrameSizeChangedL" )
   358     __VTPRINTENTER( "RVD(NGA).BaseVideoFrameSizeChangedL" )
       
   359     BaseConstructL();
       
   360     
       
   361     TInt err;
       
   362     
       
   363     iConfig.iRemoteWindow->RemoveBackgroundSurface(ETrue);
       
   364     iConfig.iWsSession->UnregisterSurface(0, iSurfaceId);
       
   365     
       
   366     iSurfaceChunk->Close();
       
   367     delete iSurfaceChunk;
       
   368     iSurfaceChunk = NULL;
       
   369     iSurfaceManager->CloseSurface(iSurfaceId);
       
   370     iSurfaceUpdateSession.CancelAllUpdateNotifications();
       
   371     iSurfaceUpdateSession.Close();
       
   372     
       
   373     /* Close the surface manager handle */
       
   374     iSurfaceManager->Close();
       
   375     delete iSurfaceManager;
       
   376     iSurfaceManager = 0;
       
   377     
       
   378     for ( TInt i = KVtEngMaxSurfaceBuffers-1; i >= 0 ; i-- )
       
   379         {
       
   380             if (iCallBackTable[i])
       
   381                 {
       
   382                 iCallBackTable[i]->Cancel();
       
   383                 delete iCallBackTable[i];
       
   384                 iCallBackTable[i] = NULL;
       
   385                 }
       
   386         }
       
   387     iSurfaceBuffers[ 0 ].UnSet();
       
   388     iSurfaceBuffers[ 1 ].UnSet();
       
   389     iSurfaceBuffer0.UnSet();
       
   390     iSurfaceBuffer1.UnSet();
       
   391     iWaitingBuffers.Reset();
       
   392     
       
   393     err = iSurfaceUpdateSession.Connect();    
       
   394     User::LeaveIfError(err);
       
   395     
       
   396     iSurfaceManager = new RSurfaceManager();
       
   397     
       
   398     User::LeaveIfNull(iSurfaceManager); 
       
   399     err = iSurfaceManager->Open();
       
   400     User::LeaveIfError(err);
       
   401     
       
   402     RSurfaceManager::TSurfaceCreationAttributesBuf attributes;
       
   403     attributes().iPixelFormat           = iSurfaceFormat; 
       
   404     attributes().iSize                  = iSourceSize;
       
   405     attributes().iBuffers               = KVtEngMaxSurfaceBuffers;
       
   406     
       
   407     //attributes().iStride                = iSourceSize.iWidth*2;
       
   408     attributes().iStride                = iSourceSize.iWidth*3/2;
       
   409     
       
   410     attributes().iOffsetToFirstBuffer   = 0;
       
   411     attributes().iAlignment             = 4;
       
   412     attributes().iContiguous            = EFalse;
       
   413     attributes().iMappable              = ETrue;
       
   414     
       
   415     err = iSurfaceManager->CreateSurface(attributes, iSurfaceId);
       
   416     User::LeaveIfError(err);  
       
   417     
       
   418     // Map to chunk
       
   419     iSurfaceChunk = new RChunk();
       
   420     User::LeaveIfNull(iSurfaceChunk);    
       
   421     err = iSurfaceManager->MapSurface(iSurfaceId, *iSurfaceChunk);
       
   422     User::LeaveIfError(err);    
       
   423     
       
   424     // Get the info from the surfaceManager
       
   425     RSurfaceManager::TInfoBuf info;
       
   426     err = iSurfaceManager->SurfaceInfo(iSurfaceId, info);
       
   427     User::LeaveIfError(err);    
       
   428     
       
   429     TInt offset;
       
   430     iSurfaceManager->GetBufferOffset(iSurfaceId, 0, offset);
       
   431     iSurfaceBuffer0.Set(iSurfaceChunk->Base() + offset, 0 );
       
   432     iSurfaceManager->GetBufferOffset(iSurfaceId, 1, offset);
       
   433     iSurfaceBuffer1.Set(iSurfaceChunk->Base() + offset, 1 );
       
   434     
       
   435     iConfig.iWsSession->RegisterSurface(0, iSurfaceId);   
       
   436     iConfig.iRemoteWindow->SetBackgroundSurface(iSurfaceId);
       
   437     
       
   438     iCallBackTable[0] = new(ELeave) CActiveCallBack(
       
   439             TCallBack(SurfaceBuffer0Ready, this), 
       
   440             CActive::EPriorityStandard-1);
       
   441     CActiveScheduler::Add(iCallBackTable[0]);
       
   442     
       
   443     iCallBackTable[1] = new(ELeave) CActiveCallBack(
       
   444             TCallBack(SurfaceBuffer1Ready, this), 
       
   445             CActive::EPriorityStandard-1);
       
   446     CActiveScheduler::Add(iCallBackTable[1]);
       
   447     
       
   448     iSurfaceCreated = ETrue;    
       
   449     
       
   450     ClearFlag( EInitializePostingSurfaceCalled );   
       
   451     
       
   452     // set the params for DS
       
   453     UpdateSinkParamsL();
       
   454     ClearFlag( EFirstFrameReceived );  
       
   455 
   359     __VTPRINTEXIT( "RVD(NGA).BaseVideoFrameSizeChangedL" )
   456     __VTPRINTEXIT( "RVD(NGA).BaseVideoFrameSizeChangedL" )
   360     }
   457     }
   361 
   458 
   362 // -----------------------------------------------------------------------------
   459 // -----------------------------------------------------------------------------
   363 // CVtEngDrawDSA::Config
   460 // CVtEngDrawDSA::Config
   551     if(iSurfaceCreated)
   648     if(iSurfaceCreated)
   552         {
   649         {
   553                 
   650                 
   554         if (iSurfaceManager)
   651         if (iSurfaceManager)
   555             {
   652             {
   556             return;
   653             /* Change log for recreate surface objects
   557             
   654              * Surface staffs should NOT be recreated once created,
   558             // Last return statement is for fixing an error causes
   655              * but unregister and register needs to be done since the 
   559             // green screen of remote video when swapping image after
   656              * bounding window change its position and size. At this
   560             // remote peer disabled video.
   657              * moment, reset the iWaitingBuffers and reset the callbacks
   561             // So we return here to prevent recreate the surface object
   658              * are recommended.
   562             // at this moment, codes below should NOT be removed due to
   659              */
   563             // potential future uses.
       
   564             iConfig.iRemoteWindow->RemoveBackgroundSurface(ETrue);
   660             iConfig.iRemoteWindow->RemoveBackgroundSurface(ETrue);
   565             iConfig.iWsSession->UnregisterSurface(0, iSurfaceId);
   661             iConfig.iWsSession->UnregisterSurface(0, iSurfaceId);
       
   662             
       
   663             /* Comment out below code to prevent delete the surface objects 
       
   664              * at this current stage, code below should NOT be removed due to
       
   665              * potential future uses.
       
   666              */
       
   667             /*
   566             iSurfaceChunk->Close();
   668             iSurfaceChunk->Close();
   567             delete iSurfaceChunk;
   669             delete iSurfaceChunk;
   568             iSurfaceChunk = NULL;
   670             iSurfaceChunk = NULL;
   569             iSurfaceManager->CloseSurface(iSurfaceId);
   671             iSurfaceManager->CloseSurface(iSurfaceId);
   570             iSurfaceUpdateSession.CancelAllUpdateNotifications();
   672             iSurfaceUpdateSession.CancelAllUpdateNotifications();
   571             iSurfaceUpdateSession.Close();
   673             iSurfaceUpdateSession.Close();
   572                               
   674             */
       
   675             
   573             /* Close the surface manager handle */
   676             /* Close the surface manager handle */
       
   677             /*
   574             iSurfaceManager->Close();
   678             iSurfaceManager->Close();
   575             delete iSurfaceManager;
   679             delete iSurfaceManager;
   576             iSurfaceManager = 0;
   680             iSurfaceManager = 0;
       
   681             */
   577             }
   682             }
   578         for ( TInt i = KVtEngMaxSurfaceBuffers-1; i >= 0 ; i-- )
   683         for ( TInt i = KVtEngMaxSurfaceBuffers-1; i >= 0 ; i-- )
   579             {
   684             {
   580                 if (iCallBackTable[i])
   685                 if (iCallBackTable[i])
   581                     {
   686                     {
   582                     iCallBackTable[i]->Cancel();
   687                     iCallBackTable[i]->Cancel();
   583                     delete iCallBackTable[i];
   688                     delete iCallBackTable[i];
   584                     iCallBackTable[i] = NULL;
   689                     iCallBackTable[i] = NULL;
   585                     }
   690                     }
   586             }
   691             }
       
   692         /* Comment out below code to prevent delete the surface buffers, 
       
   693          * otherwise the last buffer would not store the last frame. 
       
   694          * Code below should NOT be removed due to potential future uses.
       
   695          */
       
   696         /*
   587         iSurfaceBuffers[ 0 ].UnSet();
   697         iSurfaceBuffers[ 0 ].UnSet();
   588         iSurfaceBuffers[ 1 ].UnSet();
   698         iSurfaceBuffers[ 1 ].UnSet();
   589         iSurfaceBuffer0.UnSet();
   699         iSurfaceBuffer0.UnSet();
   590         iSurfaceBuffer1.UnSet();
   700         iSurfaceBuffer1.UnSet();
       
   701         */
   591         iWaitingBuffers.Reset();
   702         iWaitingBuffers.Reset();
   592         }
   703         }
   593     
   704     /* Add else branch to escape the recreate of the surface objects, 
   594     err = iSurfaceUpdateSession.Connect();    
   705      * it could be changed in future.
   595     User::LeaveIfError(err);
   706      */
   596     
   707     else
   597     iSurfaceManager = new RSurfaceManager();
   708         {
   598     
   709         err = iSurfaceUpdateSession.Connect();    
   599     User::LeaveIfNull(iSurfaceManager); 
   710         User::LeaveIfError(err);
   600     err = iSurfaceManager->Open();
   711         
   601     User::LeaveIfError(err);
   712         iSurfaceManager = new RSurfaceManager();
   602     
   713         
   603     RSurfaceManager::TSurfaceCreationAttributesBuf attributes;
   714         User::LeaveIfNull(iSurfaceManager); 
   604     attributes().iPixelFormat           = iSurfaceFormat; 
   715         err = iSurfaceManager->Open();
   605     attributes().iSize                  = iSourceSize;
   716         User::LeaveIfError(err);
   606     attributes().iBuffers               = KVtEngMaxSurfaceBuffers;
   717         
   607 
   718         RSurfaceManager::TSurfaceCreationAttributesBuf attributes;
   608     //attributes().iStride                = iSourceSize.iWidth*2;
   719         attributes().iPixelFormat           = iSurfaceFormat; 
   609     attributes().iStride                = iSourceSize.iWidth*3/2;
   720         attributes().iSize                  = iSourceSize;
   610 
   721         attributes().iBuffers               = KVtEngMaxSurfaceBuffers;
   611     attributes().iOffsetToFirstBuffer   = 0;
   722         
   612     attributes().iAlignment             = 4;
   723         //attributes().iStride                = iSourceSize.iWidth*2;
   613     attributes().iContiguous            = EFalse;
   724         attributes().iStride                = iSourceSize.iWidth*3/2;
   614     attributes().iMappable              = ETrue;
   725         
   615         
   726         attributes().iOffsetToFirstBuffer   = 0;
   616     err = iSurfaceManager->CreateSurface(attributes, iSurfaceId);
   727         attributes().iAlignment             = 4;
   617     User::LeaveIfError(err);  
   728         attributes().iContiguous            = EFalse;
   618     
   729         attributes().iMappable              = ETrue;
   619     // Map to chunk
   730         
   620     iSurfaceChunk = new RChunk();
   731         err = iSurfaceManager->CreateSurface(attributes, iSurfaceId);
   621     User::LeaveIfNull(iSurfaceChunk);    
   732         User::LeaveIfError(err);  
   622     err = iSurfaceManager->MapSurface(iSurfaceId, *iSurfaceChunk);
   733         
   623     User::LeaveIfError(err);    
   734         // Map to chunk
   624 
   735         iSurfaceChunk = new RChunk();
   625     // Get the info from the surfaceManager
   736         User::LeaveIfNull(iSurfaceChunk);    
   626     RSurfaceManager::TInfoBuf info;
   737         err = iSurfaceManager->MapSurface(iSurfaceId, *iSurfaceChunk);
   627     err = iSurfaceManager->SurfaceInfo(iSurfaceId, info);
   738         User::LeaveIfError(err);    
   628     User::LeaveIfError(err);    
   739         
   629 
   740         // Get the info from the surfaceManager
   630     TInt offset;
   741         RSurfaceManager::TInfoBuf info;
   631     iSurfaceManager->GetBufferOffset(iSurfaceId, 0, offset);
   742         err = iSurfaceManager->SurfaceInfo(iSurfaceId, info);
   632     iSurfaceBuffer0.Set(iSurfaceChunk->Base() + offset, 0 );
   743         User::LeaveIfError(err);    
   633     iSurfaceManager->GetBufferOffset(iSurfaceId, 1, offset);
   744         
   634     iSurfaceBuffer1.Set(iSurfaceChunk->Base() + offset, 1 );
   745         TInt offset;
   635         
   746         iSurfaceManager->GetBufferOffset(iSurfaceId, 0, offset);
       
   747         iSurfaceBuffer0.Set(iSurfaceChunk->Base() + offset, 0 );
       
   748         iSurfaceManager->GetBufferOffset(iSurfaceId, 1, offset);
       
   749         iSurfaceBuffer1.Set(iSurfaceChunk->Base() + offset, 1 );
       
   750         }
       
   751     
   636     iConfig.iWsSession->RegisterSurface(0, iSurfaceId);   
   752     iConfig.iWsSession->RegisterSurface(0, iSurfaceId);   
   637     iConfig.iRemoteWindow->SetBackgroundSurface(iSurfaceId);
   753     iConfig.iRemoteWindow->SetBackgroundSurface(iSurfaceId);
   638     
   754     
   639     iCallBackTable[0] = new(ELeave) CActiveCallBack(TCallBack(SurfaceBuffer0Ready, this), CActive::EPriorityStandard-1);
   755     iCallBackTable[0] = new(ELeave) CActiveCallBack(
       
   756             TCallBack(SurfaceBuffer0Ready, this), 
       
   757             CActive::EPriorityStandard-1);
   640     CActiveScheduler::Add(iCallBackTable[0]);
   758     CActiveScheduler::Add(iCallBackTable[0]);
   641     iCallBackTable[1] = new(ELeave) CActiveCallBack(TCallBack(SurfaceBuffer1Ready, this), CActive::EPriorityStandard-1);
   759     
       
   760     iCallBackTable[1] = new(ELeave) CActiveCallBack(
       
   761             TCallBack(SurfaceBuffer1Ready, this), 
       
   762             CActive::EPriorityStandard-1);
   642     CActiveScheduler::Add(iCallBackTable[1]);
   763     CActiveScheduler::Add(iCallBackTable[1]);
   643     
   764     
   644     iSurfaceCreated = ETrue;    
   765     iSurfaceCreated = ETrue;    
   645     
   766     
   646     ClearFlag( EInitializePostingSurfaceCalled );
   767     ClearFlag( EInitializePostingSurfaceCalled );