tsrc/consoleplayer/player/src/mmf/mmfplayerwindow.cpp
changeset 33 e1b6d78dfe6a
equal deleted inserted replaced
29:b818131c88a3 33:e1b6d78dfe6a
       
     1 /*
       
     2  * Copyright (c) 2010 Nokia Corporation and/or its subsidiary(-ies).
       
     3  * All rights reserved.
       
     4  * This component and the accompanying materials are made available
       
     5  * under the terms of "Eclipse Public License v1.0"
       
     6  * which accompanies this distribution, and is available
       
     7  * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8  *
       
     9  * Initial Contributors:
       
    10  * Nokia Corporation - initial contribution.
       
    11  *
       
    12  * Contributors:
       
    13  *
       
    14  * Description:
       
    15  * Source file for the MMF Player Window.
       
    16  * 
       
    17  */
       
    18 
       
    19 #include "mmfplayerwindow.h"
       
    20 
       
    21 bool IgnoreError( TInt aError )
       
    22     {
       
    23     bool ignore = false;
       
    24     // Some errors should be ignored.
       
    25     
       
    26     if( aError == -12017 )  
       
    27         {
       
    28         // partial playback - do not treat as an error
       
    29         ignore = true;
       
    30         RDebug::Printf( "CONSOLEPLAYER partial playback" );            
       
    31         }
       
    32     
       
    33     return ignore;
       
    34     }
       
    35 
       
    36 CMmfPlayerWindow* CMmfPlayerWindow::NewL( RFs& aFs, 
       
    37                                           RWsSession& aWs,
       
    38                                           CWsScreenDevice& aScreenDevice,
       
    39                                           const RWindowTreeNode &aParentWindow,
       
    40                                           TPoint aTopRight,
       
    41                                           TSize aSize,
       
    42                                           bool aTransparent,
       
    43                                           TRgb aBackgroundColor,
       
    44                                           bool aSuppressGraphicsContext,
       
    45                                           TUint32 aControllerUid )
       
    46     {
       
    47     CMmfPlayerWindow* self = new(ELeave) CMmfPlayerWindow( aFs, aWs, aScreenDevice, aSuppressGraphicsContext, aControllerUid );
       
    48     CleanupStack::PushL( self );
       
    49     self->ConstructL( aParentWindow, aTopRight, aSize, aTransparent, aBackgroundColor );
       
    50     CleanupStack::Pop();
       
    51     return self;   
       
    52     }
       
    53     
       
    54 CMmfPlayerWindow::CMmfPlayerWindow( RFs& aFs, RWsSession& aWs, CWsScreenDevice& aScreenDevice, bool aSuppressGraphicsContext, TUint32 aControllerUid ) :
       
    55     CPlayerWindow( aFs, aWs, aScreenDevice, aSuppressGraphicsContext ),
       
    56     iControllerUid( aControllerUid )
       
    57     {    
       
    58     }
       
    59 
       
    60 CMmfPlayerWindow::~CMmfPlayerWindow()
       
    61     {    
       
    62     delete iVideoPlayer;
       
    63     }
       
    64 
       
    65 void CMmfPlayerWindow::ConstructL( const RWindowTreeNode &aParentWindow, TPoint aTopRight, TSize aSize, bool aTransparent, TRgb aBackgroundColor )
       
    66     {
       
    67     BaseConstructL( aParentWindow, aTopRight, aSize, aTransparent, aBackgroundColor );
       
    68 
       
    69 #ifdef __USE_VIDEOPLAYER_1__
       
    70     iVideoPlayer = CVideoPlayerUtility::NewL(*this,
       
    71                                              EMdaPriorityNormal,
       
    72                                              EMdaPriorityPreferenceTimeAndQuality,
       
    73                                              iWs,
       
    74                                              iScreenDevice,
       
    75                                              iWindow,
       
    76                                              TRect(iScreenDevice.SizeInPixels()),
       
    77                                              TRect(iScreenDevice.SizeInPixels()));
       
    78 #else
       
    79     iVideoPlayer = CVideoPlayerUtility2::NewL(*this,EMdaPriorityNormal,EMdaPriorityPreferenceTimeAndQuality);
       
    80 #endif
       
    81     }
       
    82 
       
    83 
       
    84 void CMmfPlayerWindow::InitializeParameters( TSize& aVideoSize, 
       
    85                                              TTimeIntervalMicroSeconds& aDuration, 
       
    86                                              TInt& aMaxVolume, 
       
    87                                              TInt& aCurrentVolume,
       
    88                                              TInt& aBalanceCenter,
       
    89                                              TInt& aBalanceMaxLeft,
       
    90                                              TInt& aBalanceMaxRight,
       
    91                                              TInt& aDefaultBalance, 
       
    92                                              TInt& aCurrentBalance )
       
    93     {
       
    94     TRAPD( err, iVideoPlayer->VideoFrameSizeL(aVideoSize) );
       
    95     CheckError( err, "VideoFrameSizeL" );
       
    96     TRAP( err, aDuration = iVideoPlayer->DurationL() );
       
    97     CheckError( err, "DurationL" );
       
    98     aMaxVolume = iVideoPlayer->MaxVolume();
       
    99     aCurrentVolume = iVideoPlayer->Volume();
       
   100     aBalanceCenter = KMMFBalanceCenter;
       
   101     aBalanceMaxLeft = KMMFBalanceMaxLeft;
       
   102     aBalanceMaxRight = KMMFBalanceMaxRight;
       
   103     aDefaultBalance = iVideoPlayer->Balance();
       
   104     aCurrentBalance = aDefaultBalance;
       
   105     }
       
   106 
       
   107 void CMmfPlayerWindow::SetDefaultAutoscaleMode( TAutoscaleMode aDefaultAutoscale )
       
   108     {
       
   109     switch( aDefaultAutoscale )
       
   110         {
       
   111         case EDoNotAutoscale:
       
   112             iAutoScale = EAutoScaleNone;
       
   113             break;
       
   114         case EBestFit:
       
   115             iAutoScale = EAutoScaleBestFit;
       
   116             break;
       
   117         case EStretch:
       
   118             iAutoScale = EAutoScaleStretch;
       
   119             break;
       
   120         }
       
   121     iDefaultAutoScale = iAutoScale;
       
   122 #ifdef __USE_VIDEOPLAYER_1__
       
   123     TRAPD(err, iVideoPlayer->SetAutoScaleL(iAutoScale));
       
   124 #else
       
   125     TRAPD(err, iVideoPlayer->SetAutoScaleL(iWindow, iAutoScale));
       
   126 #endif
       
   127     if( err == KErrNotReady )
       
   128         {
       
   129         // Too soon to call this.  Will get called later, at the appropriate time.
       
   130         }
       
   131     else
       
   132         {
       
   133         CheckError( err, "SetDefaultAutoscaleMode" );
       
   134         }
       
   135     }    
       
   136 
       
   137 void CMmfPlayerWindow::PreparePlayerWithFile( RFile& aFile )
       
   138     {
       
   139     const TUid KUidController = { iControllerUid };
       
   140     TRAPD( err, iVideoPlayer->OpenFileL(aFile, KUidController) );
       
   141     CheckError( err, "OpenFileL" );
       
   142     
       
   143     // Now wait for MvpuoOpenComplete callback.            
       
   144     }
       
   145 
       
   146 void CMmfPlayerWindow::PreparePlayerWithUrl( const TDesC& aUrl )
       
   147     {
       
   148     TRAPD( err, iVideoPlayer->OpenUrlL(aUrl) );
       
   149     CheckError( err, "OpenUrlL" );
       
   150 
       
   151     // Now wait for MvpuoOpenComplete callback.                
       
   152     }
       
   153 
       
   154 TInt CMmfPlayerWindow::DoExecuteOperation( TInt /*aOperation*/ )
       
   155     {
       
   156     // Currently there are no MMF-specific commands.
       
   157     return KErrNotSupported;
       
   158     }
       
   159 
       
   160 TTimeIntervalMicroSeconds CMmfPlayerWindow::Position()
       
   161     {
       
   162     TTimeIntervalMicroSeconds position = 0;
       
   163     TRAPD( err, position = iVideoPlayer->PositionL() );
       
   164     CheckError( err, "PositionL" );
       
   165     return position;
       
   166     }
       
   167 
       
   168 TInt CMmfPlayerWindow::SetVolume( TInt aVolume )
       
   169     {
       
   170     TRAPD( err, iVideoPlayer->SetVolumeL( aVolume ) );
       
   171     if( err != KErrNone )
       
   172         {
       
   173         RDebug::Printf( "CONSOLEPLAYER SetVolumeL %i err=%i", aVolume, err );
       
   174         }
       
   175     return err;
       
   176     }
       
   177 
       
   178 TInt CMmfPlayerWindow::SetBalance( TInt aBalance )
       
   179     {
       
   180     TRAPD( err, iVideoPlayer->SetBalanceL( aBalance ) );
       
   181     if( err != KErrNone )
       
   182         {
       
   183         RDebug::Printf( "CONSOLEPLAYER SetBalanceL %i err=%i", aBalance, err );
       
   184         }
       
   185     return err;    
       
   186     }
       
   187 
       
   188 TInt CMmfPlayerWindow::RotationAngle()
       
   189     {
       
   190     switch( iRotation )
       
   191         {
       
   192         case EVideoRotationClockwise90:
       
   193             return 90;
       
   194         case EVideoRotationClockwise180:
       
   195             return 180;
       
   196         case EVideoRotationClockwise270:
       
   197             return 270;
       
   198         default:
       
   199             return 0;
       
   200         }        
       
   201     }
       
   202 
       
   203 TInt CMmfPlayerWindow::NextRotationAngle()
       
   204     {
       
   205     switch( iRotation )
       
   206         {
       
   207         case EVideoRotationNone:
       
   208             iRotation = EVideoRotationClockwise90;
       
   209             break;
       
   210         case EVideoRotationClockwise90:
       
   211             iRotation = EVideoRotationClockwise180;
       
   212             break;
       
   213         case EVideoRotationClockwise180:
       
   214             iRotation = EVideoRotationClockwise270;
       
   215             break;
       
   216         case EVideoRotationClockwise270:
       
   217             iRotation = EVideoRotationNone;
       
   218             break;
       
   219         }
       
   220 #ifdef __USE_VIDEOPLAYER_1__
       
   221     TRAPD( err, iVideoPlayer->SetRotationL(iRotation) );
       
   222 #else
       
   223     TRAPD( err, iVideoPlayer->SetRotationL(iWindow, iRotation) );
       
   224 #endif
       
   225     if( err != KErrNone )
       
   226         {
       
   227         RDebug::Printf( "CONSOLEPLAYER SetRotationL(%i) err=%i", iRotation, err );
       
   228         }    
       
   229     return err;
       
   230     }
       
   231 
       
   232 TInt CMmfPlayerWindow::ResetRotation()
       
   233     {
       
   234     iRotation = EVideoRotationNone;
       
   235 #ifdef __USE_VIDEOPLAYER_1__
       
   236     TRAPD( err, iVideoPlayer->SetRotationL(iRotation) );
       
   237 #else
       
   238     TRAPD( err, iVideoPlayer->SetRotationL(iWindow, iRotation) );
       
   239 #endif
       
   240     if( err != KErrNone )
       
   241         {
       
   242         RDebug::Printf( "CONSOLEPLAYER SetRotationL(reset) err=%i", err );
       
   243         }        
       
   244     return err;
       
   245     }
       
   246 
       
   247 TInt CMmfPlayerWindow::NextAutoscaleMode()
       
   248     {
       
   249     switch( iAutoScale )
       
   250         {
       
   251         case EAutoScaleNone:
       
   252             iAutoScale = EAutoScaleBestFit;
       
   253             break;
       
   254         case EAutoScaleBestFit:
       
   255             iAutoScale = EAutoScaleClip;
       
   256             break;
       
   257         case EAutoScaleClip:
       
   258             iAutoScale = EAutoScaleStretch;
       
   259             break;
       
   260         case EAutoScaleStretch:
       
   261             iAutoScale = EAutoScaleNone;
       
   262             break;
       
   263         }     
       
   264 #ifdef __USE_VIDEOPLAYER_1__
       
   265     TRAPD( err, iVideoPlayer->SetAutoScaleL(iAutoScale) );
       
   266 #else
       
   267     TRAPD( err, iVideoPlayer->SetAutoScaleL(iWindow, iAutoScale) );
       
   268 #endif
       
   269     if( err != KErrNone )
       
   270         {
       
   271         RDebug::Printf( "CONSOLEPLAYER SetAutoScaleL(%i) err=%i", iAutoScale, err );
       
   272         }    
       
   273     return err;
       
   274     }
       
   275 
       
   276 TInt CMmfPlayerWindow::ResetAutoscale()
       
   277     {
       
   278     iAutoScale = iDefaultAutoScale;
       
   279 #ifdef __USE_VIDEOPLAYER_1__
       
   280     TRAPD( err, iVideoPlayer->SetAutoScaleL(iAutoScale) );
       
   281 #else
       
   282     TRAPD( err, iVideoPlayer->SetAutoScaleL(iWindow, iAutoScale) );
       
   283 #endif
       
   284     if( err != KErrNone )
       
   285         {
       
   286         RDebug::Printf( "CONSOLEPLAYER SetAutoScaleL(%i) err=%i", iAutoScale, err );
       
   287         }    
       
   288     return err;
       
   289     }
       
   290 
       
   291 void CMmfPlayerWindow::AppendAutoscaleModeText( TDes& aString )
       
   292     {
       
   293     switch( iAutoScale )
       
   294         {
       
   295         case EAutoScaleNone:
       
   296             aString.Append(_L("None"));
       
   297             break;
       
   298         case EAutoScaleBestFit:
       
   299             aString.Append(_L("Best Fit"));
       
   300             break;
       
   301         case EAutoScaleClip:
       
   302             aString.Append(_L("Clip"));
       
   303             break;
       
   304         case EAutoScaleStretch:
       
   305             aString.Append(_L("Stretch"));
       
   306             break;
       
   307         } 
       
   308     }
       
   309 
       
   310 TInt CMmfPlayerWindow::SetClipRectangle( TRect aRect )
       
   311     {
       
   312 #ifdef __USE_VIDEOPLAYER_1__   
       
   313     TRAPD( err, iVideoPlayer->SetCropRegionL(aRect) );
       
   314     if( err != KErrNone )
       
   315         {
       
   316         RDebug::Printf( "CONSOLEPLAYER SetCropRegionL err=%i", err );
       
   317         }    
       
   318 #else
       
   319     TRAPD( err, iVideoPlayer->SetWindowClipRectL(iWindow, aRect) );
       
   320     if( err != KErrNone )
       
   321         {
       
   322         RDebug::Printf( "CONSOLEPLAYER SetCropRegionL err=%i", err );
       
   323         }    
       
   324 #endif
       
   325     return err;
       
   326     }
       
   327 
       
   328 TInt CMmfPlayerWindow::SetVideoExtent( TRect aExtent )
       
   329     {
       
   330 #ifdef __USE_VIDEOPLAYER_1__
       
   331     // TODO: HOW DO YOU DO THIS WITH OLD VIDEO PLAYER?
       
   332     TInt err = KErrNotSupported;
       
   333     RDebug::Printf( "CONSOLEPLAYER SetVideoExtent not supported with video player 1" );
       
   334 #else
       
   335     TRAPD( err, iVideoPlayer->SetVideoExtentL(iWindow, aExtent) );
       
   336     if( err != KErrNone )
       
   337         {
       
   338         RDebug::Printf( "CONSOLEPLAYER SetVideoExtentL err=%i", err );
       
   339         }    
       
   340 #endif
       
   341     return err;
       
   342     }
       
   343 
       
   344 TInt CMmfPlayerWindow::SetScaleFactor( TReal aWidthScaleFactor, TReal aHeightScaleFactor )
       
   345     {
       
   346 #ifdef __USE_VIDEOPLAYER_1__
       
   347     // TODO: WHAT VALUE SHOULD BE USED FOR aAntiAliasFiltering?    
       
   348     TRAPD( err, iVideoPlayer->SetScaleFactorL(aWidthScaleFactor, aHeightScaleFactor, ETrue) );
       
   349 #else
       
   350     TRAPD( err, iVideoPlayer->SetScaleFactorL(iWindow, aWidthScaleFactor, aHeightScaleFactor) );
       
   351 #endif
       
   352     if( err != KErrNone )
       
   353         {
       
   354         RDebug::Printf( "CONSOLEPLAYER SetScaleFactorL err=%i", err );
       
   355         }    
       
   356     return err;
       
   357     }
       
   358 
       
   359 TInt CMmfPlayerWindow::Play()
       
   360     {
       
   361     iVideoPlayer->Play();
       
   362     return KErrNone;
       
   363     }
       
   364 
       
   365 TInt CMmfPlayerWindow::Pause()
       
   366     {
       
   367     TRAPD(err, iVideoPlayer->PauseL());
       
   368     if( err != KErrNone )
       
   369         {
       
   370         RDebug::Printf( "CONSOLEPLAYER PauseL err=%i", err );
       
   371         }        
       
   372     return err;
       
   373     }
       
   374 
       
   375 TInt CMmfPlayerWindow::Stop()
       
   376     {
       
   377     TInt err = iVideoPlayer->Stop();
       
   378     if( err != KErrNone )
       
   379         {
       
   380         RDebug::Printf( "CONSOLEPLAYER Stop err=%i", err );
       
   381         }        
       
   382     return err;
       
   383     }
       
   384 
       
   385 TInt CMmfPlayerWindow::SetPosition( TTimeIntervalMicroSeconds aPositionInMs )
       
   386     {
       
   387     TRAPD( err, iVideoPlayer->SetPositionL( aPositionInMs ) );
       
   388     if( err != KErrNone )
       
   389         {
       
   390         RDebug::Printf( "CONSOLEPLAYER SetPositionL err=%i", err );
       
   391         }        
       
   392     return err;
       
   393     }
       
   394 
       
   395 TInt CMmfPlayerWindow::StepForward()
       
   396     {
       
   397     TRAPD( err, iVideoPlayer->StepFrameL(1) );
       
   398     if( err != KErrNone )
       
   399         {
       
   400         RDebug::Printf( "CONSOLEPLAYER StepFrameL(1) err=%i", err );
       
   401         }            
       
   402     return err;    
       
   403     }
       
   404 
       
   405 TInt CMmfPlayerWindow::StepBackward()
       
   406     {
       
   407     TRAPD( err, iVideoPlayer->StepFrameL(-1) );
       
   408     if( err != KErrNone )
       
   409         {
       
   410         RDebug::Printf( "CONSOLEPLAYER StepFrameL(-1) err=%i", err );
       
   411         }            
       
   412     return err;   
       
   413     }
       
   414 
       
   415 TInt CMmfPlayerWindow::SetPlayVelocity( TInt aVelocity )
       
   416     {
       
   417     TRAPD( err,iVideoPlayer->SetPlayVelocityL(aVelocity) );
       
   418     if( err != KErrNone )
       
   419         {
       
   420         RDebug::Printf( "CONSOLEPLAYER SetPlayVelocityL %i err=%i", aVelocity, err );
       
   421         }            
       
   422     return err;
       
   423     }
       
   424     
       
   425 // inherited from MVideoPlayerUtilityObserver
       
   426 
       
   427 void CMmfPlayerWindow::MvpuoOpenComplete(TInt aError)
       
   428     {
       
   429     RDebug::Printf( "CONSOLEPLAYER MvpuoOpenComplete(%i)", aError );
       
   430     
       
   431     if( aError == KErrNone )
       
   432         {
       
   433         iVideoPlayer->Prepare();
       
   434     
       
   435         // Now wait for MvpuoPrepareComplete callback.
       
   436         }
       
   437     else if( !IgnoreError( aError ) )
       
   438         {
       
   439         CheckError( aError, "MvpuOpenComplete" );
       
   440         }
       
   441     }
       
   442 
       
   443 void CMmfPlayerWindow::MvpuoPrepareComplete(TInt aError)
       
   444     {
       
   445     RDebug::Printf( "CONSOLEPLAYER MvpuoPrepareComplete(%i)", aError );
       
   446     
       
   447     if( aError == KErrNone )
       
   448         {
       
   449 #ifdef __USE_VIDEOPLAYER_1__   
       
   450         TRAPD( err, iVideoPlayer->SetDisplayWindowL( iWs, 
       
   451                                                      iScreenDevice, 
       
   452                                                      iWindow, 
       
   453                                                      TRect(iWindow.Position(), iWindow.Size()),
       
   454                                                      TRect(iWindow.Position(), iWindow.Size())) );
       
   455 #else
       
   456         TRAPD( err, iVideoPlayer->AddDisplayWindowL( iWs, iScreenDevice, iWindow ) );
       
   457 #endif
       
   458         if( err == KErrNone )
       
   459             {
       
   460             Play();
       
   461             ResetAutoscale();
       
   462             }
       
   463         else
       
   464             {
       
   465             RDebug::Printf("CONSOLEPLAYER AddDisplayWindowL failed, err=%i", err );
       
   466             }
       
   467         PlayInitiated();
       
   468         }
       
   469     else if( !IgnoreError( aError ) )
       
   470         {
       
   471         Error( aError );
       
   472         }
       
   473     }
       
   474 
       
   475 void CMmfPlayerWindow::MvpuoFrameReady(CFbsBitmap& /*aFrame*/,TInt aError)
       
   476     {
       
   477     RDebug::Printf( "CONSOLEPLAYER MvpuoFrameReady(%i)", aError );
       
   478     
       
   479     if( (aError != KErrNone) && !IgnoreError( aError ) )
       
   480         {
       
   481         Error( aError );
       
   482         }
       
   483     }
       
   484 
       
   485 void CMmfPlayerWindow::MvpuoPlayComplete(TInt aError)
       
   486     {
       
   487     RDebug::Printf( "CONSOLEPLAYER MvpuoPlayComplete(%i)", aError );
       
   488     
       
   489     if( aError == KErrNone )
       
   490         {
       
   491         PlayComplete();
       
   492         }
       
   493     else if( !IgnoreError( aError ) )
       
   494         {
       
   495         Error( aError );
       
   496         }
       
   497     }
       
   498 
       
   499 void CMmfPlayerWindow::MvpuoEvent(const TMMFEvent& aEvent)
       
   500     {   
       
   501     RDebug::Printf( "CONSOLEPLAYER MvpuoEvent event=%x error=%i", aEvent.iEventType.iUid, aEvent.iErrorCode );    
       
   502 
       
   503     if( aEvent.iErrorCode != KErrNone && !IgnoreError( aEvent.iErrorCode ) )
       
   504         {
       
   505         Error( aEvent.iErrorCode );
       
   506         }
       
   507     }