browserplugins/browseraudiovideoplugin/src/BavpControllerVideo.cpp
changeset 0 84ad3b177aa3
child 5 e45c3f40ea5f
equal deleted inserted replaced
-1:000000000000 0:84ad3b177aa3
       
     1 /*
       
     2 * Copyright (c) 2006 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of the License "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:  Controller class for handling browser requests to play video
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 // INCLUDE FILES
       
    20 #include <mmf/common/mmferrors.h>
       
    21 #include <aknclearer.h>
       
    22 #include <AknUtils.h>
       
    23 
       
    24 #include "BavpPlugin.h"
       
    25 #include "BavpLogger.h"
       
    26 #include "BavpControllerVideo.h"
       
    27 #include "BavpView.h"
       
    28 #include "BavpViewFullScreen.h"
       
    29 #include <mmf/common/mmfcontrollerframework.h> 
       
    30 #include <MMFScalingCustomCommandConstants.h>
       
    31 
       
    32 // CONSTANTS
       
    33 // One second represented in microseconds
       
    34 const TInt KBavpOneSecond = 1000000;
       
    35 
       
    36 // ============================ MEMBER FUNCTIONS ===============================
       
    37 
       
    38 // -----------------------------------------------------------------------------
       
    39 // CBavpControllerVideo::NewL
       
    40 // Two-phased constructor.
       
    41 // -----------------------------------------------------------------------------
       
    42 CBavpControllerVideo* CBavpControllerVideo::NewL( MBavpView* aView,
       
    43                                                   TUint aAccessPtId,
       
    44                                                   TBavpMediaType aMediaType,
       
    45                                                   const TDesC& aFileName )
       
    46     {
       
    47     CBavpControllerVideo* self = new( ELeave ) CBavpControllerVideo( aView, aAccessPtId );
       
    48 
       
    49     Log( EFalse, _L("CBavpControllerVideo::NewL this="), (TInt)self );
       
    50 
       
    51     CleanupStack::PushL( self );
       
    52     self->ConstructL( aMediaType, aFileName );
       
    53     CleanupStack::Pop( self );
       
    54     return self;
       
    55     }
       
    56 
       
    57 // -----------------------------------------------------------------------------
       
    58 // CBavpControllerVideo::~CBavpControllerVideo()
       
    59 // Destructor
       
    60 // -----------------------------------------------------------------------------
       
    61 CBavpControllerVideo::~CBavpControllerVideo()
       
    62     {
       
    63     Log( EFalse, _L("CBavpControllerVideo::~CBavpControllerVideo this="), (TInt)this );
       
    64 
       
    65     // If currently playing, call Stop before you close and delete
       
    66     if ( iCurrentState == EBavpPlaying && iVideoPlayer)
       
    67         {
       
    68         iVideoPlayer->Stop();
       
    69         }
       
    70 
       
    71     // Close the video plugin, and delete it
       
    72     if ( iVideoPlayer )
       
    73         {
       
    74         iVideoPlayer->Close();
       
    75         delete iVideoPlayer;
       
    76         }
       
    77 
       
    78     // CIdle AO used for display update
       
    79     if ( iDisplayUpdater )
       
    80         {
       
    81         delete iDisplayUpdater;
       
    82         }
       
    83 
       
    84   if ( iBackLightUpdater )
       
    85       {
       
    86       iBackLightUpdater->Cancel();
       
    87       delete iBackLightUpdater;
       
    88       }
       
    89     // Used for displaying content in full screen
       
    90     if ( iBavpViewFullScreen )
       
    91         {
       
    92         delete iBavpViewFullScreen;
       
    93         }
       
    94     }
       
    95 
       
    96 // -----------------------------------------------------------------------------
       
    97 // CBavpControllerVideo::CBavpControllerVideo
       
    98 // C++ default constructor can NOT contain any code, that
       
    99 // might leave.
       
   100 // -----------------------------------------------------------------------------
       
   101 CBavpControllerVideo::CBavpControllerVideo( MBavpView* aView, TUint aAccessPtId )
       
   102     : CBavpController( aView, aAccessPtId )
       
   103     {
       
   104     }
       
   105 
       
   106 // -----------------------------------------------------------------------------
       
   107 // CBavpControllerVideo::ConstructL
       
   108 // Symbian 2nd phase constructor can leave.
       
   109 // -----------------------------------------------------------------------------
       
   110 void CBavpControllerVideo::ConstructL( TBavpMediaType aMediaType,
       
   111                                        const TDesC& aFileName )
       
   112     {
       
   113     // Construct the BavpController base class
       
   114     BaseConstructL( aMediaType, aFileName );
       
   115 
       
   116     // Create CIdle (AO) to update the display
       
   117     iDisplayUpdater = CIdle::NewL( CActive::EPriorityIdle );
       
   118     iBackLightUpdater=CHeartbeat::NewL(CActive::EPriorityStandard);
       
   119     }
       
   120 
       
   121 // -----------------------------------------------------------------------------
       
   122 // CBavpControllerVideo::PrepareCompleteL
       
   123 // Handle the leaving methods needed by MvpuoPrepareComplete
       
   124 // -----------------------------------------------------------------------------
       
   125 void CBavpControllerVideo::PrepareCompleteL()
       
   126     {
       
   127     // Resolution
       
   128     TSize size;
       
   129     iVideoPlayer->VideoFrameSizeL(size);
       
   130     iClipInfo->iResolutionHeight = size.iHeight;
       
   131     iClipInfo->iResolutionWidth = size.iWidth;
       
   132 
       
   133     // Bitrate
       
   134     iClipInfo->iBitrate = iVideoPlayer->VideoBitRateL() +
       
   135                           iVideoPlayer->AudioBitRateL();
       
   136 
       
   137     TInt iMetaCount = iVideoPlayer->NumberOfMetaDataEntriesL();
       
   138     CMMFMetaDataEntry* metaData = NULL;
       
   139 
       
   140     for ( TInt i = 0; i < iMetaCount; i++ )
       
   141         {
       
   142         metaData = iVideoPlayer->MetaDataEntryL( i );
       
   143 
       
   144         Log( EFalse, _L("metaData index="), i );
       
   145         Log( EFalse, metaData->Name() );
       
   146         Log( EFalse, metaData->Value() );
       
   147 
       
   148         // Check if seekable
       
   149         if ( !metaData->Name().CompareF( KBavpSeekable ) )
       
   150             {
       
   151             if ( !metaData->Value().CompareF( KBavpFalse ) )
       
   152                 {
       
   153                 iClipInfo->iSeekable = EFalse;
       
   154                 }
       
   155             }
       
   156 
       
   157         // Check if live stream
       
   158         if ( !metaData->Name().CompareF( KBavpLiveStream ) )
       
   159             {
       
   160             if ( !metaData->Value().CompareF( KBavpTrue ) )
       
   161                 {
       
   162                 // Live stream is not seekable
       
   163                 iClipInfo->iLiveStream = ETrue;
       
   164                 iClipInfo->iSeekable = EFalse;
       
   165                 }
       
   166             }
       
   167 
       
   168         delete metaData;
       
   169         }   // end of for
       
   170 
       
   171     // Set up the max volume
       
   172     iClipInfo->iMaxVolume = iVideoPlayer->MaxVolume();
       
   173     iPlayerMaxVolume = iClipInfo->iMaxVolume;
       
   174 
       
   175     // Duration
       
   176     iClipInfo->iDurationInSeconds = iVideoPlayer->DurationL();
       
   177 
       
   178     // Audio track
       
   179     iClipInfo->iAudioTrack = iVideoPlayer->AudioEnabledL();
       
   180 
       
   181     // Video track
       
   182     iClipInfo->iVideoTrack = iVideoPlayer->VideoBitRateL();
       
   183 
       
   184     if ( IsClipSeekable() )
       
   185         {
       
   186         iVideoPlayer->SetPositionL( iClipInfo->iPosition );
       
   187         }
       
   188     }
       
   189 
       
   190 // -----------------------------------------------------------------------------
       
   191 // CBavpControllerVideo::InitVideoPlayer
       
   192 // The non-leaving version that calls the leaving version. Closes the current
       
   193 // player and prepares the MMF to play the video
       
   194 // -----------------------------------------------------------------------------
       
   195 void CBavpControllerVideo::InitVideoPlayer()
       
   196     {
       
   197     TRAP_IGNORE( InitVideoPlayerL() );
       
   198     }
       
   199 
       
   200 // -----------------------------------------------------------------------------
       
   201 // CBavpControllerVideo::InitVideoPlayerL
       
   202 // Closes the current player and prepares the MMF to play the video
       
   203 // -----------------------------------------------------------------------------
       
   204 void CBavpControllerVideo::InitVideoPlayerL()
       
   205     {
       
   206     Log( EFalse, _L("CBavpControllerVideo::InitVideoPlayerL()") );
       
   207 
       
   208     // If videoplayer is already opened, close and delete it
       
   209     if ( iVideoPlayer )
       
   210         {
       
   211         iVideoPlayer->Close();
       
   212         delete iVideoPlayer;
       
   213         iVideoPlayer = NULL;
       
   214         }
       
   215 
       
   216     // Get the rect to display
       
   217     TRect rect( iBavpView->CoeControl().Rect() );
       
   218     TPoint pt = iBavpView->WindowInst().AbsPosition();
       
   219     rect.Move( pt.iX, pt.iY );
       
   220 
       
   221     CEikonEnv* eikon = CEikonEnv::Static();
       
   222     RWsSession& ws = eikon->WsSession();
       
   223     CWsScreenDevice* screenDevice = eikon->ScreenDevice();
       
   224 
       
   225     // Clip rect manipulation.
       
   226     // Calculate the rect for display, including title and status pane
       
   227     TRect clipRect = GetClipRect( rect );
       
   228 
       
   229     Log( EFalse, _L("InitVideoPlayerL() - calling CVideoPlayerUtility::NewL") );
       
   230 
       
   231     // Initialize the videoplayer
       
   232     iVideoPlayer = CVideoPlayerUtility::NewL( *this, EMdaPriorityNormal,
       
   233                                               EMdaPriorityPreferenceNone,
       
   234                                               ws, *screenDevice,
       
   235                                               iBavpView->WindowInst(), rect,
       
   236                                               clipRect);
       
   237 
       
   238     // Register for loading notification
       
   239     iVideoPlayer->RegisterForVideoLoadingNotification( *this );
       
   240 
       
   241     switch ( iClipInfo->iMediaType )
       
   242         {
       
   243         case ELocalVideoFile:
       
   244             Log( EFalse, _L("InitVideoPlayerL() - calling OpenVideoFile") );
       
   245             OpenVideoFileL();
       
   246             break;
       
   247 
       
   248         case ELocalRamFile:
       
   249         case EUrl:
       
   250         case ELocalSdpFile:
       
   251 #if defined(BRDO_ASX_FILE)
       
   252 		case ELocalAsxFile:
       
   253 #endif // BRDO_ASX_FILE
       
   254             Log( EFalse, _L("InitVideoPlayerL() - calling OpenVideoUrlL") );
       
   255             OpenVideoUrlL();
       
   256             break;
       
   257 
       
   258         // Not supported
       
   259         case ELocalAudioPlaylist:
       
   260         default:
       
   261             User::Leave( KErrNotSupported );
       
   262             break;
       
   263         }
       
   264     }
       
   265 
       
   266 // -----------------------------------------------------------------------------
       
   267 // CBavpControllerVideo::UnInitVideoPlayer
       
   268 // Closes the player and delete the instance
       
   269 // -----------------------------------------------------------------------------
       
   270 void CBavpControllerVideo::UnInitVideoPlayer()
       
   271     {
       
   272     Log( EFalse, _L("CBavpControllerVideo::UnInitVideoPlayer()") );
       
   273 
       
   274     if ( iVideoPlayer )
       
   275         {
       
   276         iVideoPlayer->Close();
       
   277         delete iVideoPlayer;
       
   278         iVideoPlayer = NULL;
       
   279         }
       
   280 
       
   281     iCurrentState = EBavpNone;
       
   282     }
       
   283 
       
   284 // -----------------------------------------------------------------------------
       
   285 // CBavpControllerVideo::RotateScreen90
       
   286 // Rotate the screen if needed
       
   287 // -----------------------------------------------------------------------------
       
   288 void CBavpControllerVideo::RotateScreen90()
       
   289     {
       
   290     Log( EFalse, _L("CBavpControllerVideo::RotateScreen90()") );
       
   291 
       
   292     TRect screenRect;
       
   293     AknLayoutUtils::LayoutMetricsRect( AknLayoutUtils::EScreen, screenRect );
       
   294 
       
   295     // Rotate only if screen rect height is greater than its width
       
   296     if ( screenRect.Height() > screenRect.Width() )
       
   297         {
       
   298         TRAP_IGNORE( iVideoPlayer->SetRotationL( EVideoRotationClockwise90 ) );
       
   299         }
       
   300     }
       
   301 
       
   302 // -----------------------------------------------------------------------------
       
   303 // CBavpControllerVideo::RevertToFullScreenL
       
   304 // Set full screen display mode
       
   305 // -----------------------------------------------------------------------------
       
   306 void CBavpControllerVideo::RevertToFullScreenL()
       
   307     {
       
   308     Log( EFalse, _L("CBavpControllerVideo::RevertToFullScreenL()"));
       
   309     CBavpPluginEcomMain* npm = (CBavpPluginEcomMain*)Dll::Tls();
       
   310     bool fullscreen = true;
       
   311     
       
   312     iVideoPlayer->StopDirectScreenAccessL();
       
   313     iClipInfo->iInFullScreenMode = ETrue;
       
   314 
       
   315     npm->Funcs()->setvalue(iBavpView->bavPlugin()->getNPP(), 
       
   316                            NPPVpluginFullScreenBool, 
       
   317                            static_cast<void*>(&fullscreen));
       
   318     iBavpView->ControllerStateChangedL();
       
   319     
       
   320     CEikonEnv* eikon = CEikonEnv::Static();
       
   321     RWsSession& ws = eikon->WsSession();
       
   322     CWsScreenDevice* screenDevice = eikon->ScreenDevice();
       
   323     
       
   324     iNormalScreenRect = iBavpView->CoeControl().Rect();
       
   325     TPoint pt = iBavpView->WindowInst().AbsPosition();
       
   326     iNormalScreenRect.Move(pt.iX, pt.iY);
       
   327     TRect screenRect = eikon->EikAppUi()->ApplicationRect();
       
   328     
       
   329     CCoeControl* parentView = iBavpView->CoeControl().Parent();
       
   330     parentView->SetRect(screenRect);
       
   331     iBavpView->CoeControl().SetExtent(TPoint(0,0), screenRect.Size());
       
   332     
       
   333     iVideoPlayer->SetDisplayWindowL( ws, *screenDevice,
       
   334                                      iBavpView->WindowInst(),
       
   335                                      screenRect, screenRect );
       
   336                                          
       
   337     RotateScreen90();
       
   338     }
       
   339 
       
   340 // -----------------------------------------------------------------------------
       
   341 // CBavpControllerVideo::RevertToNormalScreenL
       
   342 // Set back to normal display mode
       
   343 // -----------------------------------------------------------------------------
       
   344 void CBavpControllerVideo::RevertToNormalScreenL()
       
   345     {
       
   346      Log( EFalse, _L("CBavpControllerVideo::RevertToNormalScreenL()") );
       
   347     CEikonEnv* eikon = CEikonEnv::Static();
       
   348     RWsSession& ws = eikon->WsSession();
       
   349     CWsScreenDevice* screenDevice = eikon->ScreenDevice();
       
   350     CBavpPluginEcomMain* npm = (CBavpPluginEcomMain*)Dll::Tls();
       
   351     bool fullscreen = false;
       
   352     
       
   353     iVideoPlayer->StopDirectScreenAccessL();
       
   354     
       
   355     npm->Funcs()->setvalue(iBavpView->bavPlugin()->getNPP(), 
       
   356                                NPPVpluginFullScreenBool, 
       
   357                                static_cast<void*>(&fullscreen));
       
   358 
       
   359     CCoeControl* parentView = iBavpView->CoeControl().Parent();
       
   360     parentView->SetRect(iNormalScreenRect);
       
   361     iBavpView->CoeControl().SetExtent(TPoint(0,0), iNormalScreenRect.Size());
       
   362 
       
   363     iClipInfo->iInFullScreenMode = EFalse;
       
   364     RefreshRectCoordinatesL();
       
   365     iVideoPlayer->SetRotationL( EVideoRotationNone );
       
   366     iBavpView->ControllerStateChangedL();
       
   367     }
       
   368 
       
   369 // -----------------------------------------------------------------------------
       
   370 // CBavpControllerVideo::ToggleScreen
       
   371 // Start a call back for the display screen switches (Full Screen to
       
   372 // Normal Screen)
       
   373 // -----------------------------------------------------------------------------
       
   374 void CBavpControllerVideo::ToggleScreen()
       
   375     {
       
   376     if ( iDisplayUpdater->IsActive() )
       
   377         {
       
   378         iDisplayUpdater->Cancel();
       
   379         }
       
   380 
       
   381     iDisplayUpdater->Start( TCallBack( CBavpControllerVideo::WaitForScreenSwitch,
       
   382                                        this ) );
       
   383     }
       
   384 
       
   385 // -----------------------------------------------------------------------------
       
   386 // CBavpControllerVideo::RefreshRectCoordinatesL
       
   387 // Refresh the coordinates of rect for display
       
   388 // -----------------------------------------------------------------------------
       
   389 void CBavpControllerVideo::RefreshRectCoordinatesL()
       
   390     {
       
   391     Log( EFalse, _L("CBavpControllerVideo::RefreshRectCoordinatesL()") );
       
   392 
       
   393     if ( IsClipFullScreen() ) {
       
   394         return;
       
   395     }
       
   396     if ( iVideoPlayer )
       
   397         {
       
   398         TRect rect( iBavpView->CoeControl().Rect() );
       
   399 
       
   400         TRect wr(iBavpView->WindowRect()); //can have negative coordinates 
       
   401                                            //if video scrolled out of viewport
       
   402         // Windows' absolute position, relative to the current screen
       
   403         TPoint pt = iBavpView->WindowInst().AbsPosition();
       
   404         rect.Move( pt.iX, pt.iY );
       
   405         wr.Move( pt.iX, pt.iY );
       
   406 
       
   407 
       
   408         CEikonEnv* eikon = CEikonEnv::Static();
       
   409         RWsSession& ws = eikon->WsSession();
       
   410         CWsScreenDevice* screenDevice = eikon->ScreenDevice();
       
   411 
       
   412         // Reset clipRect
       
   413         TRect clipRect = rect;
       
   414         clipRect = GetClipRect( rect );
       
   415 
       
   416         Log( EFalse, _L("\nPosition: == clipRect to DAS:  ==\n") );
       
   417         Log( EFalse, _L("\nPosition:: clipRect.x = \n"), clipRect.iTl.iX );
       
   418         Log( EFalse, _L("\nPosition:: clipRect.y = \n"), clipRect.iTl.iY );
       
   419         Log( EFalse, _L("\nPosition:2: clipRect.x = \n"), clipRect.iBr.iX );
       
   420         Log( EFalse, _L("\nPosition:2: clipRect.y = \n"), clipRect.iBr.iY );
       
   421 
       
   422 		TRAP_IGNORE
       
   423 		    (
       
   424               iVideoPlayer->SetDisplayWindowL( ws, *screenDevice,
       
   425             							     iBavpView->WindowInst(),
       
   426             							     wr, clipRect );
       
   427 		    );
       
   428     if( iCurrentState == EBavpPaused || iCurrentState == EBavpStopped || iCurrentState == EBavpPlayComplete )
       
   429         {
       
   430         iVideoPlayer->RefreshFrameL();
       
   431         }
       
   432         }
       
   433     }
       
   434 
       
   435 // -----------------------------------------------------------------------------
       
   436 // CBavpControllerVideo::WaitForScreenSwitch
       
   437 // Switches between normal screen and full screen
       
   438 // -----------------------------------------------------------------------------
       
   439 TInt CBavpControllerVideo::WaitForScreenSwitch( TAny* aThisData )
       
   440     {
       
   441     TRAP_IGNORE( WaitForScreenSwitchL( aThisData ) );
       
   442     return KErrNone;
       
   443     }
       
   444 
       
   445 // -----------------------------------------------------------------------------
       
   446 // CBavpControllerVideo::WaitForScreenSwitch
       
   447 // Switches between normal screen and full screen
       
   448 // -----------------------------------------------------------------------------
       
   449 void CBavpControllerVideo::WaitForScreenSwitchL( TAny* aThisData )
       
   450     {
       
   451     Log( EFalse, _L("CBavpControllerVideo::WaitForScreenSwitchL()") );
       
   452 
       
   453     // Use static cast
       
   454     CBavpControllerVideo* thisData = STATIC_CAST(CBavpControllerVideo*, aThisData);
       
   455 
       
   456     // Switch from Normal screen mode to Full Screen mode
       
   457     if ( !thisData->IsClipFullScreen() )
       
   458         {
       
   459         thisData->RevertToFullScreenL();
       
   460      
       
   461         }
       
   462     else if ( thisData->IsClipFullScreen() )
       
   463         {
       
   464         // Switch from Full Screen mode to Normal Screen mode
       
   465         thisData->RevertToNormalScreenL();
       
   466      
       
   467         }
       
   468     }
       
   469 
       
   470 // -----------------------------------------------------------------------------
       
   471 // CBavpControllerVideo::DoFastForwardL
       
   472 // Fast forwards the video
       
   473 // -----------------------------------------------------------------------------
       
   474 TInt CBavpControllerVideo::DoFastForwardL( TAny* aThisData )
       
   475     {
       
   476     CBavpControllerVideo* thisData = STATIC_CAST( CBavpControllerVideo*, aThisData );
       
   477     TTimeIntervalMicroSeconds skipPosition( 0 );
       
   478     TTimeIntervalMicroSeconds currentPosition( thisData->iVideoPlayer->PositionL() );
       
   479 
       
   480     Log( EFalse, _L("CBavpControllerVideo::DoFastForwardL() - currentPosition = "),
       
   481          currentPosition.Int64() );
       
   482 
       
   483     // If we're not at the end of clip, skip forward a few positions
       
   484     if ( currentPosition < thisData->iClipInfo->iDurationInSeconds )
       
   485         {
       
   486         skipPosition = currentPosition.Int64() + KSkipToPosition;
       
   487 
       
   488         // If skip pass end of clip, set to the end of clip
       
   489         if ( skipPosition > thisData->iClipInfo->iDurationInSeconds )
       
   490             {
       
   491             skipPosition = thisData->iClipInfo->iDurationInSeconds;
       
   492             }
       
   493 
       
   494         Log( EFalse, _L("CBavpControllerVideo::DoFastForwardL() - skipPosition = "),
       
   495              skipPosition.Int64() );
       
   496 
       
   497         // Set the position
       
   498         thisData->iVideoPlayer->SetPositionL( skipPosition );
       
   499 
       
   500         // Refresh the frame
       
   501         thisData->iVideoPlayer->RefreshFrameL();
       
   502         thisData->iClipInfo->iPosition = skipPosition;
       
   503         }
       
   504     else
       
   505         {
       
   506         // Fast Forward reached the end of the clip, cancel the fast forward
       
   507         thisData->iPositionUpdater->Cancel();
       
   508         thisData->iClipInfo->iPosition = thisData->iClipInfo->iDurationInSeconds;
       
   509         // Set the state to complete since it reached the end of the clip
       
   510         thisData->iCurrentState = EBavpFastForwardComplete;
       
   511         Log( EFalse, _L("CBavpControllerVideo::DoFastForwardL() - End of clip") );
       
   512         }
       
   513 
       
   514     return ETrue;
       
   515     }
       
   516 
       
   517 // -----------------------------------------------------------------------------
       
   518 // CBavpControllerVideo::DoRewindL
       
   519 // Rewinds the video
       
   520 // -----------------------------------------------------------------------------
       
   521 TInt CBavpControllerVideo::DoRewindL( TAny* aThisData )
       
   522     {
       
   523     CBavpControllerVideo* thisData = STATIC_CAST( CBavpControllerVideo*, aThisData );
       
   524     TTimeIntervalMicroSeconds skipPosition( 0 );
       
   525     TTimeIntervalMicroSeconds currentPosition( thisData->iVideoPlayer->PositionL() );
       
   526 
       
   527     Log( EFalse, _L("CBavpControllerVideo::DoFastForwardL() - currentPosition = "),
       
   528          currentPosition.Int64() );
       
   529 
       
   530     // We're not at the beginning of the clip, rewind a few positions
       
   531     if ( currentPosition > 0 )
       
   532         {
       
   533         skipPosition = currentPosition.Int64() - KSkipToPosition;
       
   534 
       
   535         // If skip pass beginning of clip, set to the beginning of clip
       
   536         if ( skipPosition < 0 )
       
   537             {
       
   538             skipPosition = 0;
       
   539             }
       
   540 
       
   541         Log( EFalse, _L("CBavpControllerVideo::RewindL() - skipPosition = "),
       
   542              skipPosition.Int64() );
       
   543 
       
   544         // Set the position
       
   545         thisData->iVideoPlayer->SetPositionL( skipPosition );
       
   546 
       
   547         // Refresh the frame
       
   548         thisData->iVideoPlayer->RefreshFrameL();
       
   549         thisData->iClipInfo->iPosition = skipPosition;
       
   550         }
       
   551     else
       
   552         {
       
   553         // Rewind reached the beginning of the clip, cancel the rewind
       
   554         thisData->iPositionUpdater->Cancel();
       
   555         thisData->iClipInfo->iPosition = 0;
       
   556         // Set the state to complete since it reached beginning of clip
       
   557         thisData->iCurrentState = EBavpRewindComplete;
       
   558         Log( EFalse, _L("CBavpControllerVideo::RewindL() - beginning of clip") );
       
   559         }
       
   560 
       
   561     return ETrue;
       
   562     }
       
   563 
       
   564 // --------------------------------------------------------------------------
       
   565 // CBavpControllerVideo::HandleError
       
   566 // Handle error codes. We can receive errors from the MMF Video Player
       
   567 // and its MMF callbacks (mvpuoPlayComplete, etc).
       
   568 // The MMF errors are for handling content issues, such as decoding content
       
   569 // and network access.
       
   570 // NOTES:
       
   571 // MMF errors start at -12000, see /epoc32/include/mmf/common/MMFErrors.h
       
   572 // MMF also returns -1 (KErrNotFound) and few other system-wide errors
       
   573 // -----------------------------------------------------------------------------
       
   574 void CBavpControllerVideo::HandleError( TInt aError )
       
   575     {
       
   576     Log( EFalse, _L("In CBavpControllerVideo::HandleError(): err="), aError );
       
   577 
       
   578     switch ( aError )
       
   579         {
       
   580         case KErrSessionClosed: // When we stop live streaming
       
   581             if ( iCurrentState == EBavpBuffering ||
       
   582                  iCurrentState == EBavpStopped )
       
   583                 {
       
   584                 Log( EFalse, _L("HandleError: iCurrentState=Buffering or Stopped and err=KErrSessionClosed") );
       
   585                 // Controller needs to be re-initialized, whenever
       
   586                 // live streaming is "Stopped"
       
   587                 // iCurrentState = EBavpNone, set by UnInitVideoPlayer
       
   588                 UnInitVideoPlayer();
       
   589                 // Set state to stopped, because we "stop" live content
       
   590                 iCurrentState = EBavpStopped;
       
   591                 }
       
   592             else if ( iCurrentState == EBavpPlaying ||
       
   593                       iCurrentState == EBavpPaused )
       
   594                 {
       
   595                 Log( EFalse, _L("HandleError:iCurrentState=Playing or Paused and err=KErrSessionClosed") );
       
   596                 // If the window is not on top, it might be a video or phone
       
   597                 // call interrupt
       
   598                 TRAP_IGNORE
       
   599                     (
       
   600                     if ( !iBavpView->IsTopWindowL() )
       
   601                         {
       
   602                         InitVideoPlayer();
       
   603                         }
       
   604                     )   // end of TRAP_IGNORE
       
   605                 }
       
   606             else
       
   607                 {
       
   608                 }
       
   609             break;
       
   610 
       
   611         case KErrDisconnected:
       
   612             // If the window is not on top, it might be a video or phone
       
   613             // call interrupt
       
   614             Log( EFalse, _L("HandleError: err=KErrDisconnected") );
       
   615             TRAP_IGNORE
       
   616                 (
       
   617                 if ( !iBavpView->IsTopWindowL() )
       
   618                     {
       
   619                     InitVideoPlayer();
       
   620                     }
       
   621                 )   // end of TRAP_IGNORE
       
   622             break;
       
   623 
       
   624         case KErrMMVideoDevice:
       
   625         case KErrMMAudioDevice:
       
   626             HandleMultiInstanceError();
       
   627             break;
       
   628 
       
   629         // Errors from MMF (i.e. MvpuoPrepareComplete, MvpuoPlayComplete...)
       
   630         case KErrNotFound:
       
   631         case KErrNotSupported:
       
   632         case KErrCorrupt:
       
   633         case KErrInUse:
       
   634         case KErrNoMemory:
       
   635         case KErrAbort:
       
   636         case KErrArgument:
       
   637         case KErrCouldNotConnect:
       
   638         case KErrTimedOut:
       
   639         case KErrHardwareNotAvailable:
       
   640         case KErrOverflow:
       
   641         case KErrMMNotEnoughBandwidth:
       
   642         case KErrMMNetworkRead:
       
   643         case KErrMMNetworkWrite:
       
   644         case KErrMMServerNotSupported:
       
   645         case KErrMMUDPReceive:
       
   646         case KErrMMInvalidProtocol:
       
   647         case KErrMMInvalidURL:
       
   648         case KErrMMProxyServer:
       
   649         case KErrMMDecoder:
       
   650         case KErrMMPartialPlayback:
       
   651             // Close the player and delete player instance.
       
   652             // iCurrentState = EBavpNone, set by UnInitVideoPlayer.
       
   653             UnInitVideoPlayer();
       
   654 
       
   655             // Display we have bad content
       
   656             Log( EFalse, _L("HandleError: state=BadContent") );
       
   657             iCurrentState = EBavpBadContent;
       
   658             iBavpView->UpdateView();
       
   659             break;
       
   660 
       
   661         default:
       
   662             // Do nothing
       
   663             break;
       
   664 
       
   665         }   // end of switch
       
   666 
       
   667     Log( EFalse, _L("Out CBavpControllerVideo::HandleError()") );
       
   668     }
       
   669 
       
   670 // -----------------------------------------------------------------------------
       
   671 // CBavpControllerVideo::HandleKeysL
       
   672 // Handles user key presses when we're Activated (aka Top of CCoeControl stack)
       
   673 // -----------------------------------------------------------------------------
       
   674 TKeyResponse CBavpControllerVideo::HandleKeysL( const TKeyEvent& aKeyEvent,
       
   675                                                 TEventCode aType )
       
   676     {
       
   677     TKeyResponse keyResponse( EKeyWasNotConsumed );
       
   678 
       
   679     // If we're in full screen mode, and any key is pressed, toggle to normal
       
   680     // screen. Consume all key presses (down, key, up) when in full screen mode.
       
   681     if ( IsClipFullScreen() )
       
   682         {
       
   683         if ( aType == EEventKeyDown )
       
   684             {
       
   685             ToggleScreen();
       
   686             }
       
   687         keyResponse = EKeyWasConsumed;
       
   688         }
       
   689     else
       
   690         {
       
   691         // Use the default HandleKeysL method
       
   692         keyResponse = CBavpController::HandleKeysL( aKeyEvent, aType );
       
   693         }
       
   694 
       
   695     return keyResponse;
       
   696     }
       
   697 
       
   698 // -----------------------------------------------------------------------------
       
   699 // CBavpControllerVideo::HandleCommandL
       
   700 // Default implementation, override as needed.
       
   701 // Handles the commands from the Option Menu defined in TBavpCommandIds
       
   702 // -----------------------------------------------------------------------------
       
   703 void CBavpControllerVideo::HandleCommandL( TBavpCommandIds aCommand )
       
   704     {
       
   705     Log( EFalse, _L("CBavpControllerVideo::HandleCommandL(): aCommand="), (TInt)aCommand );
       
   706 
       
   707     switch ( aCommand )
       
   708         {
       
   709         case EBavpCmdPlayFullScreen:
       
   710             ToggleScreen();
       
   711             break;
       
   712 
       
   713         default:
       
   714             // Use the default HandleCommandL method
       
   715             CBavpController::HandleCommandL( aCommand );
       
   716             break;
       
   717         }
       
   718     }
       
   719 
       
   720 // -----------------------------------------------------------------------------
       
   721 // CBavpControllerVideo::PlayAudioVideoL
       
   722 // Handles request to open and play an audio or video content
       
   723 // -----------------------------------------------------------------------------
       
   724 void CBavpControllerVideo::PlayAudioVideoL()
       
   725     {
       
   726     Log( EFalse, _L("CBavpControllerVideo::PlayAudioVideoL() ") );
       
   727 
       
   728     if ( iClipInfo->iMediaType == ELocalRamFile )
       
   729         {
       
   730         ParseRamFileL();
       
   731         }
       
   732 #if defined(BRDO_ASX_FILE)
       
   733     else if ( iClipInfo->iMediaType == ELocalAsxFile )
       
   734         {
       
   735         ParseAsxFileL();
       
   736         }
       
   737 #endif // BRDO_ASX_FILE
       
   738     // Check for the mediatype and open the file
       
   739     InitVideoPlayerL();
       
   740     }
       
   741 
       
   742 // -----------------------------------------------------------------------------
       
   743 // CBavpControllerVideo::Stop
       
   744 // Stops video from playing, if playing.
       
   745 // -----------------------------------------------------------------------------
       
   746 void CBavpControllerVideo::Stop()
       
   747     {
       
   748     Log( EFalse, _L("CBavpControllerVideo::Stop") );
       
   749 
       
   750     // If we are fast forwarding or rewind, stop the position updater
       
   751     iPositionUpdater->Cancel();
       
   752 
       
   753     if ( iVideoPlayer )
       
   754         {
       
   755         // Stop video and set the state to stop
       
   756         iVideoPlayer->Stop();
       
   757         iCurrentState = EBavpStopped;
       
   758 
       
   759         iClipInfo->iPosition = 0;
       
   760         TRAP_IGNORE
       
   761             (
       
   762             iVideoPlayer->SetPositionL( iClipInfo->iPosition );
       
   763             iVideoPlayer->RefreshFrameL();
       
   764             );
       
   765         }
       
   766 
       
   767     // The videoPlayer can play audio-only content, so we need to updateDisplay
       
   768     // to show the audio stop animation
       
   769     if ( !IsClipVideo() )
       
   770         {
       
   771         iBavpView->UpdateView();
       
   772         }
       
   773     }
       
   774 
       
   775 // -----------------------------------------------------------------------------
       
   776 // CBavpControllerVideo::PlayL
       
   777 // Plays video
       
   778 //
       
   779 // NOTE: The MMF throws an error when interrupted by a telephone call, so
       
   780 // iCurrentState=EBavpBadContent and PlayL called after call is done.
       
   781 // -----------------------------------------------------------------------------
       
   782 void CBavpControllerVideo::PlayL()
       
   783     {
       
   784     Log( EFalse, _L("CBavpControllerVideo::PlayL") );
       
   785 
       
   786     if ( !iVideoPlayer || !iPlayerInitialized )
       
   787         {
       
   788         // 1) Live-stream clip that was stopped will close the iVideoPlayer and
       
   789         // need buffering, because Play() will have to be reinitialized with
       
   790         // server.
       
   791         // 2) The initialization of multiple video instances and a single
       
   792         // playback hardware/software (ie Julie H/W) will cause the second plus
       
   793         // instances to return an error. HandleError() will display stop animation,
       
   794         // and if the user selects PlayL(), and the iVideoPlayer needs to be
       
   795         // reinitialized.
       
   796         //
       
   797         // The buffering animation will be stopped, when MvpuoPrepareComplete()
       
   798         // is called.
       
   799         iCurrentState = EBavpBuffering;
       
   800         iBavpView->UpdateView();
       
   801         Log( EFalse, _L("PlayL - Calling InitVideoPlayerL()") );
       
   802 
       
   803         // This calls OpenUrlL or OpenFileL, which will call iVideoPlayer->Play
       
   804         InitVideoPlayerL();
       
   805         return;
       
   806         }
       
   807 
       
   808     if ( iCurrentState == EBavpPaused ||
       
   809          iCurrentState == EBavpFastForwarding ||
       
   810          iCurrentState == EBavpRewinding )
       
   811         {
       
   812         // If we are fast forwarding or rewind, pause
       
   813         if ( iPositionUpdater->IsActive() )
       
   814             {
       
   815             // PauseL stops the PositionUpdater
       
   816             PauseL();
       
   817             }
       
   818 
       
   819         // We are resuming play and the clip is seekable, get the last
       
   820         // position and adjust the last position, if needed
       
   821         if ( iClipInfo->iPosition >=
       
   822              iClipInfo->iDurationInSeconds.Int64() - KBavpOneSecond )
       
   823             {
       
   824             // Take back one second if too near end of clip
       
   825             TTimeIntervalMicroSeconds adjustPosition =
       
   826                 iClipInfo->iPosition.Int64() - KBavpOneSecond;
       
   827 
       
   828             // Negative value is not allowed, use beginning of clip
       
   829             if ( adjustPosition.Int64() < 0 )
       
   830                 {
       
   831                 adjustPosition = 0;
       
   832                 }
       
   833 
       
   834             // Use the adjusted position
       
   835             iClipInfo->iPosition = adjustPosition;
       
   836             }
       
   837         }
       
   838     else
       
   839         {
       
   840         // Handle all other states, EBavpStopped, EBavpPlayComplete,
       
   841         // EBavpRewindComplete, EBavpFastForwardComplete, EBavpBadContent
       
   842         iClipInfo->iPosition = 0;
       
   843         }
       
   844 
       
   845     if ( IsClipOnDemand() && iCurrentState == EBavpStopped )
       
   846         {
       
   847         // On-demand that was stopped will need buffering,
       
   848         // because Play() will have to be reinitialized with server.
       
   849         // The buffering animation is stopped, for on-demand when
       
   850         // MvloLoadingComplete() is called
       
   851         iCurrentState = EBavpBuffering;
       
   852         Log( EFalse, _L("PlayL - Set EBavpBuffering") );
       
   853         }
       
   854     else
       
   855         {
       
   856         // Set state and update view to stop any animations running
       
   857         iCurrentState = EBavpPlaying;
       
   858         Log( EFalse, _L("PlayL - Set EBavpPlaying") );
       
   859         }
       
   860 
       
   861     iBavpView->UpdateView();
       
   862 
       
   863     iVideoPlayer->SetPositionL( iClipInfo->iPosition );
       
   864     iVideoPlayer->Play();
       
   865   // ETwelveOClock: Timer tick is on the second - from Symbian
       
   866   if (!iBackLightUpdater->IsActive())
       
   867     {
       
   868     iBackLightUpdater->Start( ETwelveOClock, this );
       
   869     }
       
   870     }
       
   871 
       
   872 // -----------------------------------------------------------------------------
       
   873 // CBavpControllerVideo::PauseL
       
   874 // Pauses video while playing. Saves the last position, if seekable content.
       
   875 // -----------------------------------------------------------------------------
       
   876 void CBavpControllerVideo::PauseL()
       
   877     {
       
   878     Log( EFalse, _L("CBavpControllerVideo::PauseL") );
       
   879 
       
   880     // If the position updater is running, stop it
       
   881     iPositionUpdater->Cancel();
       
   882 
       
   883     if ( iVideoPlayer )
       
   884         {
       
   885     //disable screensaver
       
   886     iBackLightUpdater->Cancel();
       
   887         if ( IsClipSeekable() )
       
   888             {
       
   889             // Seekable content, save position for possible resume
       
   890             iVideoPlayer->PauseL();
       
   891             iClipInfo->iPosition = iVideoPlayer->PositionL();
       
   892             iCurrentState = EBavpPaused;
       
   893             }
       
   894         else
       
   895             {
       
   896             // Not seekable content, i.e. Live stream
       
   897             iVideoPlayer->Stop();
       
   898             iClipInfo->iPosition = 0;
       
   899             iVideoPlayer->SetPositionL( iClipInfo->iPosition );
       
   900             iCurrentState = EBavpStopped;
       
   901             }
       
   902         }
       
   903     // The videoPlayer can play audio-only content, so we need to updateDisplay
       
   904     // to show the audio paused animation
       
   905     if ( !IsClipVideo() )
       
   906         {
       
   907         iBavpView->UpdateView();
       
   908         }
       
   909     }
       
   910 
       
   911 // -----------------------------------------------------------------------------
       
   912 // CBavpControllerAudio::FastForwardL
       
   913 // Fast forwards the video. This is only called on seekable and local file
       
   914 // content.
       
   915 // -----------------------------------------------------------------------------
       
   916 void CBavpControllerVideo::FastForwardL()
       
   917     {
       
   918     // Check that the content can be Fast Forwarded, this is used when media key
       
   919     // is pressed. We don't allow the user to select FF from Option Menu, if this
       
   920     // condition is not already meet.
       
   921     if ( !IsClipSeekable() && !IsClipLocalMedia() )
       
   922         {
       
   923         return;
       
   924         }
       
   925 
       
   926     // If playing, pause it (PauseL stops the PositionUpdater)
       
   927     if ( iCurrentState == EBavpPlaying )
       
   928         {
       
   929         PauseL();
       
   930         }
       
   931 
       
   932     iCurrentState = EBavpFastForwarding;
       
   933     iPositionUpdater->Start( KInitialDelay, KUpdateFrequency,
       
   934                              TCallBack( &DoFastForwardL, this ) );
       
   935   if (!iBackLightUpdater->IsActive())
       
   936     {
       
   937     iBackLightUpdater->Start( ETwelveOClock, this );
       
   938     }
       
   939     }
       
   940 
       
   941 // -----------------------------------------------------------------------------
       
   942 // CBavpControllerAudio::RewindL
       
   943 // Rewinds the video. This is only called on seekable and local file
       
   944 // content.
       
   945 // -----------------------------------------------------------------------------
       
   946 void CBavpControllerVideo::RewindL()
       
   947     {
       
   948     // Check that the content can be Rewound, this is used when media key
       
   949     // is pressed. We don't allow the user to select FF from Option Menu, if this
       
   950     // condition is not already meet.
       
   951     if ( !IsClipSeekable() && !IsClipLocalMedia() )
       
   952         {
       
   953         return;
       
   954         }
       
   955 
       
   956     // If playing, pause it (PauseL stops the PositionUpdater)
       
   957     if ( iCurrentState == EBavpPlaying )
       
   958         {
       
   959         PauseL();
       
   960         }
       
   961 
       
   962     iCurrentState = EBavpRewinding;
       
   963     iPositionUpdater->Start( KInitialDelay, KUpdateFrequency,
       
   964                              TCallBack( &DoRewindL, this ) );
       
   965   if (!iBackLightUpdater->IsActive())
       
   966     {
       
   967     iBackLightUpdater->Start( ETwelveOClock, this );
       
   968     }
       
   969 
       
   970     }
       
   971 // -----------------------------------------------------------------------------
       
   972 // CBavpControllerVideo::OpenVideoUrlL
       
   973 // Handles request to open the url link
       
   974 // -----------------------------------------------------------------------------
       
   975 void CBavpControllerVideo::OpenVideoUrlL()
       
   976     {
       
   977     Log( EFalse, _L("CBavpControllerVideo::OpenUrlL() entered") );
       
   978 
       
   979     // Note: Play() is called from MvpuoPrepareComplete()
       
   980     iVideoPlayer->OpenUrlL( *iClipInfo->iUrl, iAccessPtId,
       
   981                             KNullDesC8, KRopControllerUid );
       
   982     }
       
   983 
       
   984 // -----------------------------------------------------------------------------
       
   985 // CBavpControllerVideo::OpenVideoFileL
       
   986 // Open a video file
       
   987 // -----------------------------------------------------------------------------
       
   988 void CBavpControllerVideo::OpenVideoFileL()
       
   989     {
       
   990     Log( EFalse, _L("CBavpControllerVideo::OpenFileL() ") );
       
   991 
       
   992     // Note: Play() is called from MvpuoPrepareComplete()
       
   993     iVideoPlayer->OpenFileL( *iClipInfo->iFileName );
       
   994     }
       
   995 
       
   996 // -----------------------------------------------------------------------------
       
   997 // CBavpControllerVideo::SetPlayerVolume
       
   998 // -----------------------------------------------------------------------------
       
   999 void CBavpControllerVideo::SetPlayerVolume( TInt aVolume )
       
  1000     {
       
  1001     if ( iVideoPlayer && iPlayerInitialized )
       
  1002         {
       
  1003         // The CR volume is 0-10, convert to Video player volume 0-100
       
  1004         TInt playerVolume = ( aVolume * iPlayerMaxVolume ) / KCRVolumeMax;
       
  1005 
       
  1006         // Set Video player volume
       
  1007         TRAP_IGNORE( iVideoPlayer->SetVolumeL( playerVolume) );
       
  1008         }
       
  1009     }
       
  1010 
       
  1011 // -----------------------------------------------------------------------------
       
  1012 // CBavpControllerVideo::GetPlayerVolume
       
  1013 // -----------------------------------------------------------------------------
       
  1014 TInt CBavpControllerVideo::GetPlayerVolume()
       
  1015     {
       
  1016     TInt playerVolume( 0 );
       
  1017     TInt CRVolume( 0 );
       
  1018 
       
  1019     if ( iVideoPlayer && iPlayerInitialized )
       
  1020         {
       
  1021         // Video player returns 0-100
       
  1022         playerVolume = iVideoPlayer->Volume();
       
  1023 
       
  1024         // Convert to CR volume 0-10
       
  1025         CRVolume = ( playerVolume * KCRVolumeMax ) / iPlayerMaxVolume;
       
  1026         }
       
  1027 
       
  1028     return CRVolume;
       
  1029     }
       
  1030 
       
  1031 // -----------------------------------------------------------------------------
       
  1032 // CBavpControllerVideo::MvpuoOpenComplete
       
  1033 // Notification to the client that the opening of the video clip has completed,
       
  1034 // successfully, or otherwise.
       
  1035 // -----------------------------------------------------------------------------
       
  1036 void CBavpControllerVideo::MvpuoOpenComplete( TInt aError )
       
  1037     {
       
  1038     Log( EFalse, _L("MvpuoOpenComplete err="), aError );
       
  1039 
       
  1040     if ( aError != KErrNone )
       
  1041         {
       
  1042         // Got an error from the MMF callback
       
  1043         HandleError( aError );
       
  1044         }
       
  1045     else
       
  1046         {
       
  1047         // No error opening player, proceed with preparing player
       
  1048         iVideoPlayer->Prepare();
       
  1049         }
       
  1050     }
       
  1051 
       
  1052 // -----------------------------------------------------------------------------
       
  1053 // CBavpControllerVideo::MvpuoPrepareComplete
       
  1054 // Notification to the client that the opening of the video clip has been prepared
       
  1055 // successfully, or otherwise.
       
  1056 // This callback is called in response to a call to CVideoPlayerUtility::Prepare().
       
  1057 // -----------------------------------------------------------------------------
       
  1058 void CBavpControllerVideo::MvpuoPrepareComplete( TInt aError )
       
  1059     {
       
  1060     Log( EFalse, _L("MvpuoPrepareComplete err="), aError );
       
  1061 
       
  1062     if ( aError != KErrNone )
       
  1063         {
       
  1064         HandleError( aError );
       
  1065         }
       
  1066     else
       
  1067         {
       
  1068         // Proceed with initialization and playing content
       
  1069 
       
  1070         // Video player initialized and ready for interaction,
       
  1071         // volume, option menus, etc...
       
  1072         iPlayerInitialized = ETrue;
       
  1073 
       
  1074         // Cleanup clip info
       
  1075         iClipInfo->ReInit();
       
  1076 
       
  1077         // Handle all of the leaving methods of preparing the clip and
       
  1078         // controller. Reading meta data, max volume, ...
       
  1079         TRAP_IGNORE( PrepareCompleteL() );
       
  1080 
       
  1081         // Full screen display mode, rotate if necessary
       
  1082         if ( IsClipFullScreen() )
       
  1083             {
       
  1084             RotateScreen90();
       
  1085             }
       
  1086 
       
  1087         // Use the iCurrrentVolume, everytime we "set" the volume in the
       
  1088         // BavpController we check for Profile setting, so we can use it here
       
  1089         SetPlayerVolume( iCurrentVolume );
       
  1090 
       
  1091         // Start to play this media object
       
  1092         iVideoPlayer->Play();
       
  1093 
       
  1094         // Stop the buffering animation now, to avoid screen flicker
       
  1095         iCurrentState = EBavpPlaying;
       
  1096         iBavpView->UpdateView();
       
  1097         }
       
  1098     }
       
  1099 
       
  1100 // -----------------------------------------------------------------------------
       
  1101 // CBavpControllerVideo::MvpuoPlayComplete
       
  1102 // Notification that video playback has completed. This is not called if playback
       
  1103 // is explicitly stopped by calling Stop.
       
  1104 // -----------------------------------------------------------------------------
       
  1105 void CBavpControllerVideo::MvpuoPlayComplete( TInt aError )
       
  1106     {
       
  1107     Log( EFalse, _L("MvpuoPlayComplete err="), aError );
       
  1108 
       
  1109     if ( aError != KErrNone )
       
  1110         {
       
  1111         // Got an error from the MMF callback
       
  1112         HandleError( aError );
       
  1113         }
       
  1114     else
       
  1115         {
       
  1116         // No error, proceed with playing complete
       
  1117         iCurrentState = EBavpPlayComplete;
       
  1118         iClipInfo->iPosition = 0;
       
  1119 
       
  1120         // Set the previous call state to complete, this will ensure we
       
  1121         // don't try to replay the content if a call comes in
       
  1122         iPreCallState = EBavpPlayComplete;
       
  1123 
       
  1124         // Revert back to normal screen if it's full screen display
       
  1125         if ( IsClipFullScreen() )
       
  1126             {
       
  1127             TRAP_IGNORE
       
  1128                 (
       
  1129                 RevertToNormalScreenL();
       
  1130                 iBavpView->ControllerStateChangedL();
       
  1131                 );
       
  1132             }
       
  1133 
       
  1134         iBavpView->UpdateView();
       
  1135         }
       
  1136     }
       
  1137 
       
  1138 // -----------------------------------------------------------------------------
       
  1139 // CBavpControllerVideo::MvpuoEvent
       
  1140 // General event notification from controller. These events are specified by the
       
  1141 // supplier of the controller. Take the user initiaiated event, like selecting
       
  1142 // "pause" from the menu item, or another MMF event and convert into a
       
  1143 // "video plugin error", so we can process in HandleError().
       
  1144 // -----------------------------------------------------------------------------
       
  1145 void CBavpControllerVideo::MvpuoEvent( const TMMFEvent& aEvent )
       
  1146     {
       
  1147     Log( EFalse, _L("MvpuoEvent aEvent.iErrorCode="), aEvent.iErrorCode );
       
  1148 
       
  1149     if ( aEvent.iEventType == KMMFEventCategoryVideoPlayerGeneralError )
       
  1150         {
       
  1151         HandleError( aEvent.iErrorCode );
       
  1152         }
       
  1153     }
       
  1154 
       
  1155 // -----------------------------------------------------------------------------
       
  1156 // CBavpControllerVideo::MvloLoadingComplete
       
  1157 // Notification that video clip loading/rebuffering has started
       
  1158 // -----------------------------------------------------------------------------
       
  1159 void CBavpControllerVideo::MvloLoadingStarted()
       
  1160     {
       
  1161     Log( EFalse, _L("MvloLoadingStarted") );
       
  1162 
       
  1163     if ( iCurrentState !=  EBavpPlaying )
       
  1164         {
       
  1165         // Start the buffering animation
       
  1166         iCurrentState = EBavpBuffering;
       
  1167         iBavpView->UpdateView();
       
  1168         }
       
  1169     }
       
  1170 
       
  1171 // -----------------------------------------------------------------------------
       
  1172 // CBavpControllerVideo::MvloLoadingComplete
       
  1173 // Notification that video clip loading/rebuffering has completed
       
  1174 // and starting to play
       
  1175 // -----------------------------------------------------------------------------
       
  1176 void CBavpControllerVideo::MvloLoadingComplete()
       
  1177     {
       
  1178     Log( EFalse, _L("MvloLoadingComplete") );
       
  1179 
       
  1180   if ( !iBackLightUpdater->IsActive() )
       
  1181     {
       
  1182     iBackLightUpdater->Start( ETwelveOClock, this );
       
  1183     }
       
  1184     // Stop the buffering animation
       
  1185     iCurrentState = EBavpPlaying;
       
  1186     iBavpView->UpdateView();
       
  1187     }
       
  1188 
       
  1189  // -----------------------------------------------------------------------------
       
  1190 // CBavpControllerVideo::getPositionL
       
  1191 // To get the current position of the clip
       
  1192 // -----------------------------------------------------------------------------
       
  1193 
       
  1194  TTimeIntervalMicroSeconds CBavpControllerVideo::getPositionL()
       
  1195     {
       
  1196     if ( iVideoPlayer )
       
  1197     {
       
  1198         return iVideoPlayer->PositionL();
       
  1199     }
       
  1200     return NULL;
       
  1201     }
       
  1202 
       
  1203  // -----------------------------------------------------------------------------
       
  1204 // CBavpControllerVideo::setPositionL
       
  1205 // To set the position of the clip
       
  1206 // -----------------------------------------------------------------------------
       
  1207 
       
  1208   void CBavpControllerVideo::setPositionL(TTimeIntervalMicroSeconds val)
       
  1209     {
       
  1210         if ( iVideoPlayer )
       
  1211         {
       
  1212             if ( !IsClipSeekable() && !IsClipLocalMedia() )
       
  1213             {
       
  1214                 return;
       
  1215             }
       
  1216 
       
  1217             TBool didWePause = EFalse;
       
  1218             // If playing, pause it (PauseL stops the PositionUpdater)
       
  1219             if ( iCurrentState == EBavpPlaying )
       
  1220             {
       
  1221                 PauseL();
       
  1222                 didWePause = ETrue;
       
  1223             }
       
  1224 
       
  1225             if ( (val > iClipInfo->iDurationInSeconds ) || (val < 0) )
       
  1226             {
       
  1227                 val = 0;
       
  1228             }
       
  1229 
       
  1230             iVideoPlayer->SetPositionL(val);
       
  1231             iVideoPlayer->RefreshFrameL();
       
  1232             iClipInfo->iPosition = val;
       
  1233             if ( didWePause )
       
  1234             {
       
  1235                 PlayL();
       
  1236             }
       
  1237         }
       
  1238     }
       
  1239 
       
  1240 // -----------------------------------------------------------------------------
       
  1241 // CBavpControllerVideo::Beat
       
  1242 // Call HandleScreenSaver
       
  1243 // -----------------------------------------------------------------------------
       
  1244 //
       
  1245 void CBavpControllerVideo::Beat()
       
  1246   {
       
  1247   HandleScreenSaver();
       
  1248   }
       
  1249 
       
  1250 // -----------------------------------------------------------------------------
       
  1251 // CBavpControllerVideo::Synchronize
       
  1252 // Call HandleScreenSaver
       
  1253 // -----------------------------------------------------------------------------
       
  1254 //
       
  1255 void CBavpControllerVideo::Synchronize()
       
  1256   {
       
  1257   HandleScreenSaver();
       
  1258   }
       
  1259 
       
  1260 // -----------------------------------------------------------------------------
       
  1261 // CBavpControllerVideo::HandleScreenSaver
       
  1262 // To disable backlight for screensaver if needed
       
  1263 // -----------------------------------------------------------------------------
       
  1264 //
       
  1265 void CBavpControllerVideo::HandleScreenSaver()
       
  1266 {
       
  1267    Log( EFalse, _L("CBavpControllerVideo::HandleScreenSaver() entered" ));
       
  1268 
       
  1269     //disable screensaver when it's in playing|forwarding|backwarding mode
       
  1270     if ( NoScreenSaverMode() && iVideoPlayer )
       
  1271       {
       
  1272       User::ResetInactivityTime();
       
  1273       }
       
  1274 }
       
  1275 
       
  1276 TBool CBavpControllerVideo::NoScreenSaverMode()
       
  1277 {
       
  1278   return (iCurrentState == EBavpPlaying ||
       
  1279         iCurrentState == EBavpFastForwarding ||
       
  1280         iCurrentState == EBavpRewinding);
       
  1281 }
       
  1282 
       
  1283 
       
  1284 // -----------------------------------------------------------------------------
       
  1285 // CBavpControllerVideo::SetDefaultAspectRatioL
       
  1286 // Sets default aspect ratio (code is taken from mmplayer)
       
  1287 // -----------------------------------------------------------------------------
       
  1288 /*
       
  1289  * This function was added for consistency with mmplayer.
       
  1290  * Not used is 5.0 (tube) since we want to preserve correct 
       
  1291  * aspect ratio and this function will stretch the video to
       
  1292  * the full screen, which due to tube screen size doesn't match
       
  1293  * to correct ratio.
       
  1294  * If needed it should be called in  WaitForScreenSwitchL() after 
       
  1295  * screen mode changed.
       
  1296  */
       
  1297 void CBavpControllerVideo::SetDefaultAspectRatioL()
       
  1298 {
       
  1299   TSize frameSize;
       
  1300   TRect rect = iBavpView->CoeControl().Rect(); 
       
  1301   
       
  1302   if ( iVideoPlayer ) {
       
  1303 
       
  1304     iVideoPlayer->VideoFrameSizeL( frameSize );
       
  1305   }
       
  1306 
       
  1307   if ( frameSize.iWidth > 0 && frameSize.iHeight > 0) {
       
  1308  
       
  1309     TMMFScalingType scalingType = EMMFNatural;
       
  1310  
       
  1311     TReal32 videoAspectRatio = (TReal)frameSize.iWidth /
       
  1312                                 (TReal)frameSize.iHeight;
       
  1313     TReal32 dispAspectRatio = (TReal)rect.Width() / (TReal)rect.Height(); 
       
  1314  
       
  1315  // Choose the scaling type through the rule:
       
  1316  // videoAspectRatio - iDisplayAspectRatio > 0.1 ==> zoom
       
  1317  // videoAspectRatio - iDisplayAspectRatio < 0.1 ==> stretch
       
  1318  // videoAspectRatio = iDisplayAspectRatio ==> natural
       
  1319      if ( videoAspectRatio - dispAspectRatio > 0.1 ) {
       
  1320        scalingType = EMMFZoom;
       
  1321      }
       
  1322      else if ( videoAspectRatio != dispAspectRatio ) {
       
  1323        scalingType = EMMFStretch;
       
  1324      }
       
  1325 
       
  1326      TMMFMessageDestinationPckg destinationPckg(KUidInterfaceMMFControllerScalingMsg );
       
  1327       
       
  1328      TPckgBuf<TInt> scaleTypePckg( scalingType );
       
  1329      
       
  1330      iVideoPlayer->CustomCommandSync( destinationPckg,
       
  1331                                        EMMFSetScalingType,
       
  1332                                        scaleTypePckg,
       
  1333                                        KNullDesC8 );
       
  1334      iVideoPlayer->RefreshFrameL();
       
  1335 
       
  1336    }
       
  1337 }
       
  1338 
       
  1339 void CBavpControllerVideo::HandleInComingCallL()
       
  1340 
       
  1341 {
       
  1342 	if ( IsClipFullScreen() )
       
  1343       {
       
  1344       RevertToNormalScreenL();
       
  1345       }	
       
  1346 }
       
  1347 //  End of File