videoplayback/videohelix/src/mpxvideoplaybackcontroller.cpp
changeset 0 96612d01cf9f
child 1 6711b85517b7
equal deleted inserted replaced
-1:000000000000 0:96612d01cf9f
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:  This class plays local video file
       
    15  *
       
    16 */
       
    17 
       
    18 // Version : %version: 39 %
       
    19 
       
    20 
       
    21 //
       
    22 //  INCLUDE FILES
       
    23 //
       
    24 #include <eikenv.h>
       
    25 #include <mpxcenrepobserver.h>
       
    26 #include <mpxcenrepwatcher.h>
       
    27 #include <mpxmediageneraldefs.h>
       
    28 #include <mpxcommandgeneraldefs.h>
       
    29 #include <mpxmessagegeneraldefs.h>
       
    30 #include <mpxmediageneralextdefs.h>
       
    31 #include <mpxplaybackcommanddefs.h>
       
    32 #include <mpxplaybackpluginobserver.h>
       
    33 #include <mpxplaybackplugin.h>
       
    34 #include <AudioPreference.h>
       
    35 #include <mpxplaybackplugin.h>
       
    36 
       
    37 #include <coreapplicationuisdomainpskeys.h>
       
    38 #include <ctsydomainpskeys.h>
       
    39 #include <mmf/common/mmferrors.h>
       
    40 
       
    41 #include <hal.h>
       
    42 #include <hal_data.h>
       
    43 #include <e32std.h>
       
    44 #include <devsoundif.h>
       
    45 
       
    46 #include "mpxvideoregion.h"
       
    47 #include "mpxvideoplaybackcontroller.h"
       
    48 #include "mpxvideoplaybackstate.h"
       
    49 #include "mpxvideoprivatecrkeys.h"
       
    50 #include "mpxvideohelixplayback.h"
       
    51 #include "mpxvideoseeker.h"
       
    52 #include "mpxvideoplayerutility.h"
       
    53 #include "mpxvideodrmhelper.h"
       
    54 #include <mpxvideoplaybackdefs.h>
       
    55 #include "mpxmediavideodefs.h"
       
    56 
       
    57 //
       
    58 //  CONSTANTS
       
    59 //
       
    60 #define KMAXMIMETYPELENGTH 256
       
    61 
       
    62 //
       
    63 //  Backlight Timeout in Micro Seconds
       
    64 //
       
    65 #define KMPXBackLightTimeOut 3500000
       
    66 
       
    67 #define KOneKilobyte 1024
       
    68 
       
    69 _LIT( KTitle, "Title" );
       
    70 _LIT( KLiveStream, "LiveStream" );
       
    71 _LIT( KSeekable, "Seekable" );
       
    72 _LIT( KArtist, "Artist" );
       
    73 _LIT( KAuthor, "Author" );
       
    74 _LIT( KFormat, "MimeType" );
       
    75 _LIT( KTrue, "1" );
       
    76 _LIT( KFalse, "0" );
       
    77 _LIT (KMPStreamingPauseSupported, "StreamingPauseSupported");
       
    78 
       
    79 
       
    80 // ============================ MEMBER FUNCTIONS ===================================================
       
    81 
       
    82 //  ------------------------------------------------------------------------------------------------
       
    83 //  CMPXVideoPlaybackController::NewL()
       
    84 //  ------------------------------------------------------------------------------------------------
       
    85 //
       
    86 CMPXVideoPlaybackController* CMPXVideoPlaybackController::NewL( MMPXPlaybackPluginObserver& aObs )
       
    87 {
       
    88    CMPXVideoPlaybackController* self = new( ELeave ) CMPXVideoPlaybackController();
       
    89    CleanupStack::PushL( self );
       
    90    self->ConstructL( aObs );
       
    91    CleanupStack::Pop();
       
    92    return self;
       
    93 }
       
    94 
       
    95 //  ----------------------------------------------------------------------------
       
    96 //  CMPXVideoPlaybackController::CreatePreInitStatesL()
       
    97 //  ----------------------------------------------------------------------------
       
    98 //
       
    99 void CMPXVideoPlaybackController::CreatePreInitStatesL()
       
   100 {
       
   101     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::CreatePreInitStatesL()"));
       
   102 
       
   103     iNotIntialisedState = CMPXNotInitialisedState::NewL(this);
       
   104     iInitialisingState  = CMPXInitialisingState::NewL(this);
       
   105 
       
   106     // Set the default state to non initialised
       
   107     iState              = iNotIntialisedState;
       
   108 }
       
   109 
       
   110 //  ----------------------------------------------------------------------------
       
   111 //  CMPXVideoPlaybackController::CreatePostInitStatesL()
       
   112 //  ----------------------------------------------------------------------------
       
   113 //
       
   114 void CMPXVideoPlaybackController::CreatePostInitStatesL()
       
   115 {
       
   116     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::CreatePostInitStatesL()"));
       
   117 
       
   118     //
       
   119     //  Check if the post init states have been created
       
   120     //
       
   121     if ( ! iInitialisedState )
       
   122     {
       
   123         iInitialisedState   = CMPXInitialisedState::NewL(this);
       
   124         iPlayingState       = CMPXPlayingState::NewL(this);
       
   125         iBufferingState     = CMPXBufferingState::NewL(this);
       
   126         iPausedState        = CMPXPausedState::NewL(this);
       
   127         iSeekingState       = CMPXSeekingState::NewL(this);
       
   128         iStoppedState       = CMPXStoppedState::NewL(this);
       
   129     }
       
   130 }
       
   131 
       
   132 //  ----------------------------------------------------------------------------
       
   133 //  CMPXVideoPlaybackController::ConstructL
       
   134 //  Symbian 2nd phase constructor can leave.
       
   135 //  ----------------------------------------------------------------------------
       
   136 //
       
   137 void CMPXVideoPlaybackController::ConstructL( MMPXPlaybackPluginObserver& aObs )
       
   138 {
       
   139     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::ConstructL()"));
       
   140 
       
   141     iMPXPluginObs = &aObs;
       
   142     iAccessPointId = -1;
       
   143     iVideoSeeker = CMPXVideoSeeker::NewL( this );
       
   144 
       
   145     // Initiliaze to True
       
   146     iSeekable = ETrue;
       
   147 
       
   148     InitVolumeWatchers();
       
   149 
       
   150     CreatePreInitStatesL();
       
   151 
       
   152     iPlayer = CMpxVideoPlayerUtility::NewL( this );
       
   153 
       
   154     iBackLightTimer = CPeriodic::NewL( CActive::EPriorityStandard );
       
   155 
       
   156     iDrmHelper = CMpxVideoDrmHelper::NewL();
       
   157 }
       
   158 
       
   159 //  ----------------------------------------------------------------------------
       
   160 //  CMPXVideoPlaybackController::CloseController()
       
   161 //  ----------------------------------------------------------------------------
       
   162 //
       
   163 void CMPXVideoPlaybackController::CloseController()
       
   164 {
       
   165     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::CloseController()"));
       
   166 
       
   167     ChangeState( EMPXVideoNotInitialized );
       
   168 }
       
   169 
       
   170 //  ------------------------------------------------------------------------------------------------
       
   171 //    CMPXVideoPlaybackController::OpenFileL()
       
   172 //  ------------------------------------------------------------------------------------------------
       
   173 //
       
   174 void CMPXVideoPlaybackController::OpenFileL( const TDesC& aMediaFile,
       
   175                                              RFile& aFile,
       
   176                                              TInt aAccessPointId )
       
   177 {
       
   178     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::OpenFileL()"),
       
   179                    _L("file = %S"), &aMediaFile );
       
   180 
       
   181     TBool fileExists = EFalse;
       
   182 
       
   183     ChangeState( EMPXVideoInitializing );
       
   184 
       
   185     iClipName = aMediaFile.AllocL();
       
   186     iAccessPointId = aAccessPointId;
       
   187 
       
   188     //
       
   189     //  If file handle exists, duplicate it to the controller
       
   190     //
       
   191     if ( aFile.SubSessionHandle() )
       
   192     {
       
   193         if ( iFileHandle.SubSessionHandle() )
       
   194         {
       
   195             iFileHandle.Close();
       
   196         }
       
   197 
       
   198         User::LeaveIfError( iFileHandle.Duplicate( aFile ) );
       
   199 
       
   200         fileExists = ETrue;
       
   201     }
       
   202 
       
   203     DetermineMediaTypeL();
       
   204     SetPlaybackModeL();
       
   205 
       
   206     //
       
   207     //  Create accessory monitor to search for TV-Out events
       
   208     //
       
   209     if ( ! iAccessoryMonitor )
       
   210     {
       
   211         iAccessoryMonitor = CMPXVideoAccessoryObserver::NewL( this );
       
   212     }
       
   213 
       
   214     if ( iAccessoryMonitor->IsTvOutPlaybackAllowed() )
       
   215     {
       
   216         if ( fileExists )
       
   217         {
       
   218             //
       
   219             //  Ensure there are rights for protected clips
       
   220             //
       
   221             TInt drmError = iDrmHelper->GetDrmRightsStatus( iFileHandle );
       
   222 
       
   223             if ( drmError )
       
   224             {
       
   225                 //
       
   226                 //  Send error to observer for handling
       
   227                 //
       
   228                 HandleError( drmError );
       
   229             }
       
   230             else
       
   231             {
       
   232                 iState->OpenFileL( iFileHandle );
       
   233             }
       
   234         }
       
   235         else
       
   236         {
       
   237             iState->OpenFileL( iClipName->Des() );
       
   238         }
       
   239     }
       
   240     else
       
   241     {
       
   242         HandleError( KMPXVideoTvOutPlaybackNotAllowedClose );
       
   243     }
       
   244 }
       
   245 
       
   246 //  ----------------------------------------------------------------------------
       
   247 //    C++ constructor
       
   248 //  ----------------------------------------------------------------------------
       
   249 //
       
   250 CMPXVideoPlaybackController::CMPXVideoPlaybackController()
       
   251     : iAppInForeground(ETrue)
       
   252     , iForegroundPause(EFalse)
       
   253     , iAllowAutoPlay(ETrue)
       
   254     , iHelixLoadingStarted(EFalse)
       
   255 {
       
   256 }
       
   257 
       
   258 //  ----------------------------------------------------------------------------
       
   259 //    Destructor
       
   260 //  ----------------------------------------------------------------------------
       
   261 //
       
   262 CMPXVideoPlaybackController::~CMPXVideoPlaybackController()
       
   263 {
       
   264     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::~CMPXVideoPlaybackController"));
       
   265 
       
   266     delete iDrmHelper;
       
   267     delete iAccessoryMonitor;
       
   268 
       
   269     delete iNotIntialisedState;
       
   270     delete iInitialisingState;
       
   271     delete iInitialisedState;
       
   272     delete iPlayingState;
       
   273     delete iBufferingState;
       
   274     delete iPausedState;
       
   275     delete iSeekingState;
       
   276     delete iStoppedState;
       
   277 
       
   278     if ( iPlaybackMode )
       
   279     {
       
   280         delete iPlaybackMode;
       
   281         iPlaybackMode = NULL;
       
   282     }
       
   283 
       
   284     if ( iVolumeWatcher )
       
   285     {
       
   286         delete iVolumeWatcher;
       
   287         iVolumeWatcher = NULL;
       
   288     }
       
   289 
       
   290     if ( iMuteWatcher )
       
   291     {
       
   292         delete iMuteWatcher;
       
   293         iMuteWatcher = NULL;
       
   294     }
       
   295 
       
   296     if ( iFileDetails )
       
   297     {
       
   298         delete iFileDetails;
       
   299         iFileDetails = NULL;
       
   300     }
       
   301 
       
   302     if ( iClipName )
       
   303     {
       
   304         delete iClipName;
       
   305         iClipName = NULL;
       
   306     }
       
   307 
       
   308     if ( iRecognizedMimeType )
       
   309     {
       
   310         delete iRecognizedMimeType;
       
   311         iRecognizedMimeType = NULL;
       
   312     }
       
   313 
       
   314     if ( iVideoSeeker )
       
   315     {
       
   316         delete iVideoSeeker;
       
   317         iVideoSeeker = NULL;
       
   318     }
       
   319 
       
   320     if ( iFileHandle.SubSessionHandle() )
       
   321     {
       
   322         iFileHandle.Close();
       
   323     }
       
   324 
       
   325     if ( iBackLightTimer )
       
   326     {
       
   327         iBackLightTimer->Cancel();
       
   328         delete iBackLightTimer;
       
   329         iBackLightTimer = NULL;
       
   330     }
       
   331 
       
   332     if ( iPlayer )
       
   333     {
       
   334         delete iPlayer;
       
   335         iPlayer = NULL;
       
   336     }
       
   337 
       
   338 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
   339 
       
   340     if ( iFileHandle64.SubSessionHandle() )
       
   341     {
       
   342         iFileHandle64.Close();
       
   343     }
       
   344 
       
   345 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
   346 
       
   347 }
       
   348 
       
   349 //  ----------------------------------------------------------------------------
       
   350 //    Executes general playback commands supported by the playback FW
       
   351 //    CMPXVideoPlaybackController::HandleGeneralPlaybackCommandL()
       
   352 //  ----------------------------------------------------------------------------
       
   353 //
       
   354 void
       
   355 CMPXVideoPlaybackController::HandleGeneralPlaybackCommandL( CMPXCommand& aCmd )
       
   356 {
       
   357     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::HandleGeneralPlaybackTypeL()"));
       
   358 
       
   359     if ( aCmd.IsSupported( KMPXCommandPlaybackGeneralType ) )
       
   360     {
       
   361         TMPXPlaybackCommand cmd = static_cast<TMPXPlaybackCommand>
       
   362                                       (aCmd.ValueTObjectL<TInt>(KMPXCommandPlaybackGeneralType ));
       
   363 
       
   364         MPX_DEBUG(_L("CMPXVideoPlaybackController::HandleGeneralPlaybackCommandL() id = %d"), cmd );
       
   365 
       
   366         DoHandleCommandL( cmd );
       
   367     }
       
   368 }
       
   369 
       
   370 //  ----------------------------------------------------------------------------
       
   371 //    Executes general playback commands supported by the playback FW
       
   372 //    CMPXVideoPlaybackController::HandleCustomPlaybackCommandL()
       
   373 //  ----------------------------------------------------------------------------
       
   374 //
       
   375 void
       
   376 CMPXVideoPlaybackController::HandleCustomPlaybackCommandL( CMPXCommand& aCmd )
       
   377 {
       
   378     MPX_ENTER_EXIT(
       
   379         _L("CMPXVideoPlaybackController::HandleCustomPlaybackCommandL()") );
       
   380 
       
   381     if ( aCmd.IsSupported( KMPXMediaVideoPlaybackCommand ) )
       
   382     {
       
   383         TMPXVideoPlaybackCommand cmd = static_cast<TMPXVideoPlaybackCommand>
       
   384                             (aCmd.ValueTObjectL<TInt>(KMPXMediaVideoPlaybackCommand));
       
   385 
       
   386         MPX_DEBUG(_L("CMPXVideoPlaybackController::HandleCustomPlaybackCommandL() cmd = %d"), cmd );
       
   387 
       
   388         switch ( cmd )
       
   389         {
       
   390             case EPbCmdInitView:
       
   391             {
       
   392                 if ( iState != iNotIntialisedState)
       
   393                 {
       
   394                     aCmd.SetTextValueL( KMPXMediaVideoPlaybackFileName, *iClipName );
       
   395                     aCmd.SetTObjectValueL<TInt>( KMPXMediaVideoMode, iPlaybackMode->GetMode() );
       
   396 
       
   397                     aCmd.SetTObjectValueL<TInt>( KMPXMediaVideoTvOutConnected,
       
   398                                                  iAccessoryMonitor->IsTvOutConnected() );
       
   399 
       
   400                     aCmd.SetTObjectValueL<TInt>( KMPXMediaVideoTvOutPlayAllowed,
       
   401                                                  iAccessoryMonitor->IsTvOutPlaybackAllowed() );
       
   402 
       
   403                     if ( iRecognizedMimeType )
       
   404                     {
       
   405                         aCmd.SetTextValueL( KMPXMediaVideoRecognizedMimeType, *iRecognizedMimeType );
       
   406                     }
       
   407                 }
       
   408 
       
   409                 break;
       
   410             }
       
   411             case EPbCmdSetDisplayWindow:
       
   412             {
       
   413                 SetDisplayWindowL( aCmd );
       
   414                 break;
       
   415             }
       
   416             case EPbCmdAbortDSA:
       
   417             {
       
   418                 AbortDSA();
       
   419                 break;
       
   420             }
       
   421             case EPbCmdRestartDSA:
       
   422             {
       
   423                 RestartDSA( aCmd );
       
   424                 break;
       
   425             }
       
   426             case EPbCmdStartVideoSeekingForward:
       
   427             {
       
   428                 iState->HandleStartSeekL( ETrue );
       
   429                 break;
       
   430             }
       
   431             case EPbCmdStartVideoSeekingBackward:
       
   432             {
       
   433                 iState->HandleStartSeekL( EFalse );
       
   434                 break;
       
   435             }
       
   436             case EPbCmdStopVideoSeeking:
       
   437             {
       
   438                 iState->HandleStopSeekL();
       
   439                 break;
       
   440             }
       
   441             case EPbCmdHandleForeground:
       
   442             {
       
   443                 iAppInForeground = ETrue;
       
   444                 iState->HandleForeground();
       
   445                 break;
       
   446             }
       
   447             case EPbCmdHandleBackground:
       
   448             {
       
   449                 iAppInForeground = static_cast<TBool>(aCmd.ValueTObjectL<TBool>(KMPXMediaVideoAppForeground));
       
   450                 iState->HandleBackground();
       
   451                 break;
       
   452             }
       
   453             case EPbCmdNaturalAspectRatio:
       
   454             {
       
   455                 iState->SetAspectRatioL( aCmd, EMMFNatural );
       
   456                 break;
       
   457             }
       
   458             case EPbCmdZoomAspectRatio:
       
   459             {
       
   460                 iState->SetAspectRatioL( aCmd, EMMFZoom );
       
   461                 break;
       
   462             }
       
   463             case EPbCmdStretchAspectRatio:
       
   464             {
       
   465                 iState->SetAspectRatioL( aCmd, EMMFStretch );
       
   466                 break;
       
   467             }
       
   468             case EPbCmdUpdateSeekable:
       
   469             {
       
   470                 iSeekable = aCmd.ValueTObjectL<TBool>(KMPXMediaGeneralExtVideoSeekable);
       
   471 
       
   472                 if( iFileDetails )
       
   473                 {
       
   474                     iFileDetails->iSeekable &= iSeekable;
       
   475                 }
       
   476 
       
   477                 break;
       
   478             }
       
   479             case EPbCmdEndofClipReached:
       
   480             {
       
   481                 iState->HandleEndOfClip();
       
   482                 break;
       
   483             }
       
   484             case EPbCmdHandleIncreaseVolume:
       
   485             {
       
   486                 HandleVolumeL( ETrue );
       
   487                 break;
       
   488             }
       
   489             case EPbCmdHandleDecreaseVolume:
       
   490             {
       
   491                 HandleVolumeL( EFalse );
       
   492                 break;
       
   493             }
       
   494             case EPbCmdCustomPause:
       
   495             {
       
   496                 iState->HandleCustomPause();
       
   497                 break;
       
   498             }
       
   499             case EPbCmdCustomPlay:
       
   500             {
       
   501                 iState->HandleCustomPlay();
       
   502                 break;
       
   503             }
       
   504             case EPbCmdRetrieveBufferingPercentage:
       
   505             {
       
   506                 TInt bufferingPercentage = 100;
       
   507 
       
   508                 //
       
   509                 //  Check if Helix is in the loading state.  If not, return 100 since
       
   510                 //  Helix believes they are fully loaded
       
   511                 //
       
   512                 if ( iHelixLoadingStarted )
       
   513                 {
       
   514                     bufferingPercentage = iState->RetrieveBufferingPercentage();
       
   515                 }
       
   516 
       
   517                 aCmd.SetTObjectValueL<TInt>( KMPXMediaVideoBufferingPercentage,
       
   518                                              bufferingPercentage );
       
   519 
       
   520                 break;
       
   521             }
       
   522             default:
       
   523             {
       
   524                 break;
       
   525             }
       
   526         }
       
   527     }
       
   528 }
       
   529 
       
   530 //  ------------------------------------------------------------------------------------------------
       
   531 //    CMPXVideoPlaybackController::HandlePdlCommandL()
       
   532 //  ------------------------------------------------------------------------------------------------
       
   533 //
       
   534 void
       
   535 CMPXVideoPlaybackController::HandlePdlCommandL( CMPXCommand& aCmd )
       
   536 {
       
   537     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::HandlePdlCommandL()"));
       
   538 
       
   539     TMPXPlaybackPdCommand cmd =
       
   540         static_cast<TMPXPlaybackPdCommand>(*aCmd.Value<TInt>(KMPXCommandPlaybackGeneralType));
       
   541 
       
   542     switch ( cmd )
       
   543     {
       
   544         case EPbCmdStartPd:
       
   545         {
       
   546             //
       
   547             //  Set the media type to PDL so the PDL mode will be created
       
   548             //
       
   549             iMediaType = CMediaRecognizer::EProgressiveDownload;
       
   550             SetPlaybackModeL();
       
   551             iPlaybackMode->ConnectToDownloadL( aCmd );
       
   552 
       
   553             break;
       
   554         }
       
   555         case EPbCmdGetPdStatus:
       
   556         {
       
   557             if ( iPlaybackMode )
       
   558             {
       
   559                 iPlaybackMode->GetPdlStatusL( aCmd );
       
   560             }
       
   561             else
       
   562             {
       
   563                 //
       
   564                 //  There must be an error since the playback mode does not exist
       
   565                 //  Return a state of not downloading since the error will be handled
       
   566                 //  during the MediaL() call.
       
   567                 //
       
   568                 aCmd.SetTObjectValueL<TMPXPlaybackPdDownloadState>( KMPXCommandPlaybackPDState,
       
   569                                                                     EPbDlStateNotDownloading );
       
   570                 aCmd.SetTObjectValueL<TInt>( KMPXCommandPlaybackPDDownloadedBytes, KOneKilobyte );
       
   571                 aCmd.SetTObjectValueL<TInt>( KMPXCommandPlaybackPDTotalBytes, KOneKilobyte );
       
   572             }
       
   573 
       
   574             break;
       
   575         }
       
   576         default:
       
   577         {
       
   578             break;
       
   579         }
       
   580     }
       
   581 }
       
   582 
       
   583 //  ----------------------------------------------------------------------------
       
   584 //    Set the DataSource and DataSink to the IMMFController
       
   585 //
       
   586 //  ----------------------------------------------------------------------------
       
   587 //
       
   588 void CMPXVideoPlaybackController::HandleCommandL( CMPXCommand& aCmd )
       
   589 {
       
   590     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::HandleCommandL() - CMPXCommand"));
       
   591 
       
   592     if ( aCmd.IsSupported( KMPXCommandGeneralId ) )
       
   593     {
       
   594         TInt cmdId = *aCmd.Value<TInt>(KMPXCommandGeneralId);
       
   595 
       
   596         MPX_DEBUG(_L("CMPXVideoPlaybackController::HandleCommandL() id = 0x%08x"), cmdId );
       
   597 
       
   598         switch ( cmdId )
       
   599         {
       
   600             case KMPXCommandIdPlaybackGeneral:
       
   601             {
       
   602                 HandleGeneralPlaybackCommandL( aCmd );
       
   603                 break;
       
   604             }
       
   605             case KMPXMediaIdVideoPlayback:
       
   606             {
       
   607                 HandleCustomPlaybackCommandL( aCmd );
       
   608                 break;
       
   609             }
       
   610             case KMPXCommandIdPlaybackPD:
       
   611             {
       
   612                 HandlePdlCommandL( aCmd );
       
   613                 break;
       
   614             }
       
   615         }
       
   616     }
       
   617 }
       
   618 
       
   619 //  ----------------------------------------------------------------------------
       
   620 //    CMPXVideoPlaybackController::HandleCommandL
       
   621 //
       
   622 //  ----------------------------------------------------------------------------
       
   623 //
       
   624 void CMPXVideoPlaybackController::HandleCommandL(TMPXPlaybackCommand aCmd, TInt /*aData*/)
       
   625 {
       
   626     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::HandleCommandL() - TMPXPlaybackCommand"));
       
   627 
       
   628     DoHandleCommandL( aCmd );
       
   629 }
       
   630 
       
   631 //  ----------------------------------------------------------------------------
       
   632 //    CMPXVideoPlaybackController::DoHandleCommandL
       
   633 //  ----------------------------------------------------------------------------
       
   634 void CMPXVideoPlaybackController::DoHandleCommandL(TInt aCmd)
       
   635 {
       
   636     MPX_ENTER_EXIT(
       
   637         _L("CMPXVideoPlaybackController::DoHandleCommandL()"),
       
   638         _L("Command = %d"), aCmd );
       
   639 
       
   640     switch (aCmd)
       
   641     {
       
   642         case EPbCmdPlay:
       
   643         {
       
   644             iState->HandlePlay();
       
   645             break;
       
   646         }
       
   647         case EPbCmdPause:
       
   648         {
       
   649             iState->HandlePause();
       
   650             break;
       
   651         }
       
   652         case EPbCmdPlayPause:
       
   653         {
       
   654             iState->HandlePlayPause();
       
   655             break;
       
   656         }
       
   657         case EPbCmdStartSeekForward:
       
   658         {
       
   659             iState->HandleStartSeekL( ETrue );
       
   660             break;
       
   661         }
       
   662         case EPbCmdStartSeekBackward:
       
   663         {
       
   664             iState->HandleStartSeekL( EFalse );
       
   665             break;
       
   666         }
       
   667         case EPbCmdStopSeeking:
       
   668         {
       
   669             iState->HandleStopSeekL();
       
   670             break;
       
   671         }
       
   672         case EPbCmdClose:
       
   673         {
       
   674             iState->HandleClose();
       
   675             break;
       
   676         }
       
   677         case EPbCmdStop:
       
   678         {
       
   679             iState->HandleStop();
       
   680             break;
       
   681         }
       
   682         default:
       
   683         {
       
   684             break;
       
   685         }
       
   686     }
       
   687 }
       
   688 
       
   689 //  ----------------------------------------------------------------------------
       
   690 //    CMPXVideoPlaybackController::HandleMMFEvent
       
   691 //  ----------------------------------------------------------------------------
       
   692 //
       
   693 void CMPXVideoPlaybackController::HandleMMFEvent( const TMMFEvent& aEvent )
       
   694 {
       
   695     MPX_ENTER_EXIT(
       
   696         _L("CMPXVideoPlaybackController::HandleMMFEvent()"),
       
   697         _L("EventType = 0x%08x, ErrorCode = %d"), aEvent.iEventType, aEvent.iErrorCode );
       
   698 
       
   699     if ( aEvent.iEventType == KMMFEventCategoryVideoOpenComplete )
       
   700     {
       
   701         iState->HandleOpenComplete( aEvent.iErrorCode );
       
   702     }
       
   703     else if ( aEvent.iEventType == KMMFEventCategoryVideoPrepareComplete )
       
   704     {
       
   705         iState->HandlePrepareComplete( aEvent.iErrorCode );
       
   706     }
       
   707     else if ( aEvent.iEventType == KMMFEventCategoryPlaybackComplete )
       
   708     {
       
   709         iState->HandlePlaybackComplete( aEvent.iErrorCode );
       
   710     }
       
   711     else if ( aEvent.iEventType == KMMFEventCategoryVideoLoadingStarted )
       
   712     {
       
   713         //
       
   714         //  Set the flag to retrieve the Buffering percentage from Helix
       
   715         //
       
   716         iHelixLoadingStarted = ETrue;
       
   717 
       
   718         iState->HandleLoadingStarted();
       
   719     }
       
   720     else if ( aEvent.iEventType == KMMFEventCategoryVideoLoadingComplete )
       
   721     {
       
   722         //
       
   723         //  Set the flag to retrieve the Buffering percentage from Helix
       
   724         //
       
   725         iHelixLoadingStarted = EFalse;
       
   726 
       
   727         iState->HandleLoadingComplete( aEvent.iErrorCode );
       
   728     }
       
   729 #ifdef SYMBIAN_BUILD_GCE
       
   730     else if ( aEvent.iEventType == KMMFEventCategoryVideoSurfaceCreated )
       
   731     {
       
   732         TInt error = iPlayer->VideoSurfaceCreated();
       
   733 
       
   734         if ( error != KErrNone )
       
   735         {
       
   736             MPX_TRAPD( err, iState->SendErrorToViewL( error ) );
       
   737         }
       
   738     }
       
   739     else if ( aEvent.iEventType == KMMFEventCategoryVideoSurfaceParametersChanged )
       
   740     {
       
   741         TInt error = iPlayer->SurfaceParametersChanged();
       
   742 
       
   743         if ( error != KErrNone )
       
   744         {
       
   745             MPX_TRAPD( err, iState->SendErrorToViewL( error ) );
       
   746         }
       
   747     }
       
   748     else if ( aEvent.iEventType == KMMFEventCategoryVideoRemoveSurface )
       
   749     {
       
   750         TInt error = iPlayer->RemoveSurface();
       
   751 
       
   752         if ( error != KErrNone )
       
   753         {
       
   754             MPX_TRAPD( err, iState->SendErrorToViewL( error ) );
       
   755         }
       
   756     }
       
   757 #endif // SYMBIAN_BUILD_GCE
       
   758     else if ( aEvent.iEventType == KMMFEventCategoryVideoPlayerGeneralError )
       
   759     {
       
   760         switch ( aEvent.iErrorCode )
       
   761         {
       
   762             case KErrDisconnected:
       
   763             case KErrTimedOut:
       
   764             {
       
   765                 iState->ResolveTimeoutError(aEvent.iErrorCode);
       
   766                 break;
       
   767             }
       
   768             case KErrHardwareNotAvailable:
       
   769             case KErrMMAudioDevice:
       
   770             case KErrMMVideoDevice:
       
   771             {
       
   772                 // Resource lost; go to pause state
       
   773                 iState->HandlePause();
       
   774                 break;
       
   775             }
       
   776             default:
       
   777             {
       
   778                 iState->HandleUnexpectedError( aEvent.iErrorCode );
       
   779                 break;
       
   780             }
       
   781         }
       
   782     }
       
   783     else if ( aEvent.iEventType == KMMFEventCategoryAudioResourceAvailable )
       
   784     {
       
   785       // ?????
       
   786     }
       
   787     else
       
   788     {
       
   789         //
       
   790         //  unexpected MMF event
       
   791         //
       
   792     }
       
   793 }
       
   794 
       
   795 //  ----------------------------------------------------------------------------
       
   796 //    CMPXVideoHelixPlayback::RestartDSA()
       
   797 //
       
   798 //    This is not state dependent so the ctlr can handle this
       
   799 //  ----------------------------------------------------------------------------
       
   800 void CMPXVideoPlaybackController::RestartDSA( CMPXCommand& aCmd )
       
   801 {
       
   802     MPX_ENTER_EXIT(_L("CMPXVideoHelixPlayback::RestartDSA()"));
       
   803 
       
   804     CMPXVideoRegion* videoRegion =
       
   805         aCmd.ValueCObjectL<CMPXVideoRegion>(KMPXMediaVideoPlaybackDSARegion);
       
   806 
       
   807     iPlayer->RestartDsa( videoRegion->GetRegion() );
       
   808 
       
   809     delete videoRegion;
       
   810 }
       
   811 
       
   812 //  ----------------------------------------------------------------------------
       
   813 //    CMPXVideoPlaybackController::SetDisplayWindowL()
       
   814 //
       
   815 //    This is not state dependent .
       
   816 //    Note: The view can control the when it sends this command
       
   817 //  ----------------------------------------------------------------------------
       
   818 void CMPXVideoPlaybackController::SetDisplayWindowL( CMPXCommand& aCmd )
       
   819 {
       
   820     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::SetDisplayWindowL()"));
       
   821 
       
   822     TRect rect =
       
   823         static_cast<TRect>( aCmd.ValueTObjectL<TRect>(KMPXMediaVideoPlaybackTRect) );
       
   824 
       
   825     MPX_DEBUG(_L("CMPXVideoHelixPlayback::SetDisplayWindowL() region sent"));
       
   826 
       
   827     CMPXVideoRegion* videoRegion =
       
   828         aCmd.ValueCObjectL<CMPXVideoRegion>(KMPXMediaVideoPlaybackDSARegion);
       
   829 
       
   830     CleanupStack::PushL( videoRegion );
       
   831 
       
   832     iPlayer->SetDisplayWindowL( rect, rect, videoRegion->GetRegion() );
       
   833 
       
   834     CleanupStack::PopAndDestroy( videoRegion );
       
   835 }
       
   836 
       
   837 //  ------------------------------------------------------------------------------------------------
       
   838 //  CMPXVideoPlaybackController::SetVolumeCenRepL
       
   839 //  Sets the volume level in Central Repository
       
   840 //  ------------------------------------------------------------------------------------------------
       
   841 //
       
   842 void CMPXVideoPlaybackController::SetVolumeCenRepL( TInt aVolume )
       
   843 {
       
   844     MPX_ENTER_EXIT(
       
   845         _L("CMPXVideoPlaybackController::SetVolumeCenRepL()"),
       
   846         _L("aVolume = %d"), aVolume );
       
   847 
       
   848     if ( iFileDetails && iFileDetails->iAudioEnabled )
       
   849     {
       
   850         TInt volume( 0 );
       
   851 
       
   852         if ( aVolume > KPbPlaybackVolumeLevelMax )
       
   853         {
       
   854             volume = KPbPlaybackVolumeLevelMax;
       
   855         }
       
   856         else if ( aVolume < KPbPlaybackVolumeLevelMin )
       
   857         {
       
   858             volume = KPbPlaybackVolumeLevelMin;
       
   859         }
       
   860         else
       
   861         {
       
   862             volume = aVolume;
       
   863         }
       
   864 
       
   865         MPX_DEBUG(
       
   866             _L("CMPXVideoPlaybackController::SetVolumeCenRepL(): Setting volume = %d"), volume );
       
   867 
       
   868         if ( volume > 0 )
       
   869         {
       
   870             //
       
   871             // Media player's CenRep volume range : 0 - number of volume steps
       
   872             // MPX framework volume range : 0-100
       
   873             //
       
   874             iVolumeWatcher->SetValueL( volume / iVolumeNormalizer );
       
   875             SetMuteCenRepL( EFalse );
       
   876         }
       
   877         else
       
   878         {
       
   879             //
       
   880             // save both mute and current volume values in CenRep
       
   881             //
       
   882             iVolumeWatcher->SetValueL( 0 );
       
   883             SetMuteCenRepL( ETrue );
       
   884         }
       
   885     }
       
   886     else
       
   887     {
       
   888         MPX_DEBUG(_L("CMPXVideoPlaybackController::SetVolumeCenRepL(): Audio isn't enabled"));
       
   889     }
       
   890 }
       
   891 
       
   892 //  ------------------------------------------------------------------------------------------------
       
   893 //  CMPXVideoPlaybackController::SetMuteCenRepL
       
   894 //  ------------------------------------------------------------------------------------------------
       
   895 void CMPXVideoPlaybackController::SetMuteCenRepL( TBool aMute )
       
   896 {
       
   897     if ( iFileDetails && iFileDetails->iAudioEnabled )
       
   898     {
       
   899         iMuteWatcher->SetValueL( aMute );
       
   900 
       
   901         MPX_DEBUG(_L("CMPXVideoPlaybackController::SetMuteCenRepL(): Mute = %d"), aMute );
       
   902     }
       
   903     else
       
   904     {
       
   905         MPX_DEBUG(_L("CMPXVideoPlaybackController::SetMuteCenRepL() : Audio isn't enabled"));
       
   906     }
       
   907 }
       
   908 
       
   909 //  ------------------------------------------------------------------------------------------------
       
   910 //  CMPXVideoPlaybackController::SetVolumeMMFL
       
   911 //
       
   912 //  Sets the volume level in MMF
       
   913 //
       
   914 //  NOTE: This is done only after the HandleSettingChange callback from CenRep
       
   915 //        has been received as a result of a prior iVolumeWatcher->SetValueL call
       
   916 //  ------------------------------------------------------------------------------------------------
       
   917 //
       
   918 void CMPXVideoPlaybackController::SetVolumeMMFL()
       
   919 {
       
   920     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::SetVolumeMMFL()"));
       
   921 
       
   922     TInt volume = iVolumeWatcher->CurrentValueL();
       
   923     TBool mute = iMuteWatcher->CurrentValueL();
       
   924 
       
   925     MPX_DEBUG(_L("CMPXVideoPlaybackController::SetVolumeMMFL() volume = %d, mute = %d")
       
   926             , volume, mute );
       
   927 
       
   928     TInt newVolume = 0;
       
   929 
       
   930     if ( ! mute )
       
   931     {
       
   932         //
       
   933         // If it was muted and previous volume level was 0, set the volume to 1
       
   934         //
       
   935         if ( volume == 0 )
       
   936         {
       
   937             volume++;
       
   938         }
       
   939 
       
   940         newVolume =
       
   941             volume  * iVolumeNormalizer * iFileDetails->iMaxVolume / KPbPlaybackVolumeLevelMax;
       
   942     }
       
   943 
       
   944     MPX_DEBUG(_L("CMPXVideoPlaybackController::SetVolumeMMFL() new volume = %d"), newVolume );
       
   945 
       
   946     //  Change MMF Audio player's volume
       
   947     iPlayer->SetVolumeL( newVolume );
       
   948 
       
   949     if ( ! mute )
       
   950     {
       
   951         iMPXPluginObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPVolumeChanged,
       
   952                                           newVolume,
       
   953                                           KErrNone );
       
   954     }
       
   955 }
       
   956 
       
   957 //  ------------------------------------------------------------------------------------------------
       
   958 //    Handle a change in a setting value.
       
   959 //  ------------------------------------------------------------------------------------------------
       
   960 //
       
   961 void CMPXVideoPlaybackController::HandleSettingChange( const TUid& aRepositoryUid,
       
   962                                                        TUint32 aSettingId )
       
   963 {
       
   964     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::HandleSettingChange()"));
       
   965 
       
   966     if ( aRepositoryUid == KCRUidMPXVideoSettings )
       
   967     {
       
   968         switch ( aSettingId )
       
   969         {
       
   970             case KMPXVideoPlaybackMute:
       
   971             {
       
   972                 iMPXPluginObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPMuteChanged,
       
   973                                                   iMuteWatcher->CurrentValueL(),
       
   974                                                   KErrNone );
       
   975                 // fall through
       
   976             }
       
   977             case KMPXVideoPlaybackVolume:
       
   978             {
       
   979                 //
       
   980                 //  this is the callback from cen-rep
       
   981                 //  let the state decide if it needs to do something
       
   982                 //
       
   983                 iState->HandleVolumeChange();
       
   984                 break;
       
   985             }
       
   986             default:
       
   987             {
       
   988                 break;
       
   989             }
       
   990         }
       
   991     }
       
   992 }
       
   993 
       
   994 //  ----------------------------------------------------------------------------
       
   995 //  CMPXVideoPlaybackController::SetPropertyL()
       
   996 //
       
   997 //  Sets the property of the plugin
       
   998 //  ----------------------------------------------------------------------------
       
   999 //
       
  1000 void CMPXVideoPlaybackController::SetPropertyL( TMPXPlaybackProperty aProperty, TInt aValue )
       
  1001 {
       
  1002     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::SetPropertyL()"),
       
  1003                    _L("prop %d, val %d"), aProperty, aValue );
       
  1004 
       
  1005     switch ( aProperty )
       
  1006     {
       
  1007         case EPbPropertyPosition:
       
  1008         {
       
  1009             iState->HandleSetPositionL( aValue );
       
  1010 
       
  1011             //
       
  1012             // Set Position is a synchronous call. It needs not wait for any callback
       
  1013             // so HandlePluginEvent can be issued at this time.
       
  1014             //
       
  1015             iMPXPluginObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPSetComplete,
       
  1016                                               aProperty,
       
  1017                                               KErrNone );
       
  1018             break;
       
  1019         }
       
  1020         case EPbPropertyVolume:
       
  1021         {
       
  1022             //
       
  1023             // Volume is an asynchronous call. After a new volume value is saved
       
  1024             // in CenRep, it needs to wait for a callback. At that time, HandlePluginEvent
       
  1025             // for volume will be issued.
       
  1026             //
       
  1027             SetVolumeCenRepL( aValue );
       
  1028             break;
       
  1029         }
       
  1030         case EPbPropertyMute:
       
  1031         {
       
  1032             //
       
  1033             // Mute is an asynchronous call. After a new mute value is saved
       
  1034             // in CenRep, it needs to wait for a callback. At that time, HandlePluginEvent
       
  1035             // for mute will be issued.
       
  1036             //
       
  1037             SetMuteCenRepL( aValue );
       
  1038             break;
       
  1039         }
       
  1040         default:
       
  1041         {
       
  1042             User::Leave( KErrNotSupported );
       
  1043         }
       
  1044     }
       
  1045 
       
  1046 }
       
  1047 
       
  1048 //  ----------------------------------------------------------------------------
       
  1049 //  CMPXVideoPlaybackController::GetPropertyL
       
  1050 //
       
  1051 //    Gets a property of the plugin (async)
       
  1052 //  ----------------------------------------------------------------------------
       
  1053 
       
  1054 void CMPXVideoPlaybackController::GetPropertyL( TMPXPlaybackProperty aProperty ) const
       
  1055 {
       
  1056     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::GetPropertyL()"),
       
  1057                    _L("aProperty = %d"), aProperty );
       
  1058 
       
  1059     TInt value = 0;
       
  1060     TInt err = KErrNone;
       
  1061 
       
  1062     switch( aProperty )
       
  1063     {
       
  1064         case EPbPropertyPosition:
       
  1065         {
       
  1066             TTimeIntervalMicroSeconds pos = iPlayer->PositionL();
       
  1067 
       
  1068             value = pos.Int64() / KPbMilliMultiplier;
       
  1069 
       
  1070             break;
       
  1071         }
       
  1072         case EPbPropertyDuration:
       
  1073         {
       
  1074             if ( iFileDetails )
       
  1075             {
       
  1076                 value = iFileDetails->iDuration.Int64() / KPbMilliMultiplier;
       
  1077             }
       
  1078 
       
  1079             break;
       
  1080         }
       
  1081         case EPbPropertyVolume:
       
  1082         {
       
  1083             TInt volume = 0;
       
  1084 
       
  1085             if ( ! iMuteWatcher->CurrentValueL() )
       
  1086             {
       
  1087                 volume = iVolumeWatcher->CurrentValueL() * iVolumeNormalizer;
       
  1088             }
       
  1089 
       
  1090             value = volume;
       
  1091 
       
  1092             break;
       
  1093         }
       
  1094         case EPbPropertyMaxVolume:
       
  1095         {
       
  1096             if ( iFileDetails )
       
  1097             {
       
  1098                 value = iFileDetails->iMaxVolume;
       
  1099             }
       
  1100             break;
       
  1101         }
       
  1102         case EPbPropertyMute:
       
  1103         {
       
  1104             TInt volume = iPlayer->Volume();
       
  1105 
       
  1106             value = volume ? 0 : 1;
       
  1107 
       
  1108             break;
       
  1109         }
       
  1110         case EPbPropertySupportedFeatures:
       
  1111         {
       
  1112             value = 0;
       
  1113             break;
       
  1114         }
       
  1115         default:
       
  1116         {
       
  1117             User::Leave( KErrNotSupported );
       
  1118         }
       
  1119     }
       
  1120 
       
  1121     if ( iMPXPluginObs )
       
  1122     {
       
  1123         MPX_DEBUG(_L("CMPXVideoPlaybackController::GetPropertyL() value = %d"), value);
       
  1124 
       
  1125         iMPXPluginObs->HandleProperty( aProperty, value, err );
       
  1126     }
       
  1127 }
       
  1128 
       
  1129 //
       
  1130 //  ----------------------------------------------------------------------------
       
  1131 //    Sends the media properties
       
  1132 //  ----------------------------------------------------------------------------
       
  1133 //
       
  1134 void CMPXVideoPlaybackController::SendMediaL( const TArray<TMPXAttribute>& aAttrs )
       
  1135 {
       
  1136     MPX_ENTER_EXIT( _L("CMPXVideoPlaybackController::SendMediaL()"));
       
  1137 
       
  1138     TInt retError = KErrNone;
       
  1139 
       
  1140     RArray<TInt> suppIds;
       
  1141     CleanupClosePushL( suppIds );
       
  1142 
       
  1143     suppIds.AppendL( KMPXMediaIdGeneral );
       
  1144     suppIds.AppendL( KMPXMediaIdVideo );
       
  1145 
       
  1146     CMPXMedia* media = CMPXMedia::NewL( suppIds.Array() );
       
  1147 
       
  1148     CleanupStack::PopAndDestroy( &suppIds );
       
  1149     CleanupStack::PushL( media );
       
  1150 
       
  1151     retError = iState->RetrieveFileDetailsL( aAttrs, media );
       
  1152 
       
  1153     iMPXPluginObs->HandleMedia( *media, retError );
       
  1154 
       
  1155     CleanupStack::PopAndDestroy( media );
       
  1156 }
       
  1157 
       
  1158 //
       
  1159 //  ----------------------------------------------------------------------------
       
  1160 //  CMPXVideoPlaybackController::ChangeState
       
  1161 //  ----------------------------------------------------------------------------
       
  1162 //
       
  1163 void CMPXVideoPlaybackController::ChangeState(TMPXVideoPlaybackState aChangeToState)
       
  1164 {
       
  1165     MPX_ENTER_EXIT( _L("CMPXVideoPlaybackController::ChangeState()"),
       
  1166                     _L("newState = %d"), aChangeToState );
       
  1167 
       
  1168     if ( aChangeToState != iState->GetState() )
       
  1169     {
       
  1170         switch ( aChangeToState )
       
  1171         {
       
  1172             case EMPXVideoPlaying:
       
  1173                 iState = iPlayingState;
       
  1174                 //
       
  1175                 //  If clip is audio only, stop the backlight timer and break switch
       
  1176                 //  If clip has audio and video, proceed to the next case which will
       
  1177                 //  start the backlight timer if needed
       
  1178                 //
       
  1179                 if ( iFileDetails->iVideoEnabled )
       
  1180                 {
       
  1181                     StartBackLightTimer();
       
  1182                 }
       
  1183                 else
       
  1184                 {
       
  1185                     CancelBackLightTimer();
       
  1186                 }
       
  1187                 break;
       
  1188             case EMPXVideoPaused:
       
  1189                 iState = iPausedState;
       
  1190                 CancelBackLightTimer();
       
  1191                 break;
       
  1192             case EMPXVideoInitializing:
       
  1193                 iState = iInitialisingState;
       
  1194                 StartBackLightTimer();
       
  1195                 break;
       
  1196             case EMPXVideoInitialized:
       
  1197                 iState = iInitialisedState;
       
  1198                 break;
       
  1199             case EMPXVideoBuffering:
       
  1200                 iState = iBufferingState;
       
  1201                 StartBackLightTimer();
       
  1202                 break;
       
  1203             case EMPXVideoSeeking:
       
  1204                 iState = iSeekingState;
       
  1205                 break;
       
  1206             case EMPXVideoStopped:
       
  1207                 iState = iStoppedState;
       
  1208                 CancelBackLightTimer();
       
  1209                 break;
       
  1210             case EMPXVideoNotInitialized:
       
  1211                 ResetMemberVariables();
       
  1212                 iState = iNotIntialisedState;
       
  1213                 CancelBackLightTimer();
       
  1214                 break;
       
  1215         }
       
  1216     }
       
  1217 }
       
  1218 
       
  1219 //  ------------------------------------------------------------------------------------------------
       
  1220 //    Reads the file details from the media properties
       
  1221 //  ------------------------------------------------------------------------------------------------
       
  1222 //
       
  1223 void CMPXVideoPlaybackController::ReadFileDetailsL()
       
  1224 {
       
  1225     MPX_ENTER_EXIT( _L("CMPXVideoPlaybackController::ReadFileDetailsL()"));
       
  1226 
       
  1227     CMPXVideoFileDetails* temp = iFileDetails;
       
  1228 
       
  1229     //
       
  1230     //  Create the file details class and delete old data
       
  1231     //
       
  1232     iFileDetails = CMPXVideoFileDetails::NewL();
       
  1233     delete temp;
       
  1234 
       
  1235     iFileDetails->iClipName = iClipName->AllocL();
       
  1236 
       
  1237     //
       
  1238     //  Resolution
       
  1239     //
       
  1240     TSize size;
       
  1241     iPlayer->VideoFrameSizeL( size );
       
  1242     iFileDetails->iResolutionHeight = size.iHeight;
       
  1243     iFileDetails->iResolutionWidth = size.iWidth;
       
  1244 
       
  1245     //
       
  1246     //  Video Track
       
  1247     //
       
  1248     TInt videoBitRate = iPlayer->VideoBitRateL();
       
  1249     iFileDetails->iVideoEnabled = ( videoBitRate != 0 );
       
  1250 
       
  1251     iFileDetails->iBitRate = videoBitRate + iPlayer->AudioBitRateL();
       
  1252 
       
  1253     //
       
  1254     // Drm Protected
       
  1255     //
       
  1256     if ( iFileHandle.SubSessionHandle() )
       
  1257     {
       
  1258         iFileDetails->iDrmProtected = iDrmHelper->IsProtected( iFileHandle );
       
  1259     }
       
  1260 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
  1261     else if ( iFileHandle64.SubSessionHandle() )
       
  1262     {
       
  1263         iFileDetails->iDrmProtected = iDrmHelper->IsProtected64( iFileHandle64 );
       
  1264     }
       
  1265 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
  1266 
       
  1267 
       
  1268     //
       
  1269     //  Audio Track
       
  1270     //
       
  1271     iFileDetails->iAudioEnabled = iPlayer->AudioEnabledL();
       
  1272 
       
  1273     //
       
  1274     //  Duration
       
  1275     //
       
  1276     iFileDetails->iDuration = iPlayer->DurationL();
       
  1277 
       
  1278     //
       
  1279     //  Max Volume
       
  1280     //
       
  1281     iFileDetails->iMaxVolume = iPlayer->MaxVolume();
       
  1282 
       
  1283     // 
       
  1284     //  FourCC Code
       
  1285     //
       
  1286     iFileDetails->iFourCCCode  = iPlayer->FourCCCode();    
       
  1287     
       
  1288     //
       
  1289     //  Mime Type
       
  1290     //
       
  1291     HBufC8* mimeType = HBufC8::NewL( KMAXMIMETYPELENGTH );
       
  1292     CleanupStack::PushL( mimeType );
       
  1293 
       
  1294     TPtr8 des = mimeType->Des();
       
  1295 
       
  1296     TInt err = iPlayer->VideoFormatMimeType( des );
       
  1297 
       
  1298     if ( ! err )
       
  1299     {
       
  1300         HBufC* mimeType16 = HBufC::NewLC( des.Length() );
       
  1301         TPtr des16( mimeType16->Des() );
       
  1302 
       
  1303         des16.Copy( des );
       
  1304         iFileDetails->iMimeType = des16.AllocL();
       
  1305 
       
  1306         CleanupStack::PopAndDestroy( mimeType16 );
       
  1307     }
       
  1308 
       
  1309     CleanupStack::PopAndDestroy( mimeType );
       
  1310 
       
  1311     //
       
  1312     //  Loop through the meta data entries
       
  1313     //
       
  1314     TInt metaCount = 0;
       
  1315 
       
  1316     MPX_TRAPD( error, metaCount = iPlayer->NumberOfMetaDataEntriesL() );
       
  1317 
       
  1318     if ( ! error )
       
  1319     {
       
  1320         CMMFMetaDataEntry* metaData = NULL;
       
  1321 
       
  1322         for ( TInt i = 0 ; i < metaCount ; ++i )
       
  1323         {
       
  1324             metaData = iPlayer->MetaDataEntryL(i);
       
  1325 
       
  1326             CleanupStack::PushL( metaData );
       
  1327 
       
  1328             if ( ! metaData->Name().CompareF( KSeekable ) )
       
  1329             {
       
  1330                 if ( ! metaData->Value().CompareF( KTrue ) )
       
  1331                 {
       
  1332                     iFileDetails->iSeekable = ETrue;
       
  1333                 }
       
  1334             }
       
  1335             else if ( ! metaData->Name().CompareF( KLiveStream ) )
       
  1336             {
       
  1337                 if ( ! metaData->Value().CompareF( KTrue ) )
       
  1338                 {
       
  1339                     iFileDetails->iLiveStream = ETrue;
       
  1340                 }
       
  1341             }
       
  1342             else if ( ! metaData->Name().CompareF( KTitle ) )
       
  1343             {
       
  1344                 iFileDetails->iTitle = metaData->Value().AllocL();
       
  1345             }
       
  1346             else if ( ( ! metaData->Name().CompareF( KArtist ) ) ||
       
  1347                       ( ! metaData->Name().CompareF( KAuthor ) ) )
       
  1348             {
       
  1349                 iFileDetails->iArtist = metaData->Value().AllocL();
       
  1350             }
       
  1351             else if ( ! metaData->Name().CompareF( KFormat ) )
       
  1352             {
       
  1353                 //
       
  1354                 //  Do not overwrite the mime type
       
  1355                 //
       
  1356                 if ( ! iFileDetails->iMimeType )
       
  1357                 {
       
  1358                     iFileDetails->iMimeType = metaData->Value().AllocL();
       
  1359                 }
       
  1360             }
       
  1361             else if ( !metaData->Name().CompareF(KMPStreamingPauseSupported) )
       
  1362             {
       
  1363                 if ( ! metaData->Value().CompareF( KFalse ) )
       
  1364                 {
       
  1365                     // Streaming Pause is not supported by server
       
  1366                     iFileDetails->iPausableStream = EFalse;
       
  1367                 }
       
  1368             }
       
  1369 
       
  1370             CleanupStack::PopAndDestroy( metaData );
       
  1371         }
       
  1372 
       
  1373         // Update the seek value for asx clips with the value
       
  1374         // received from the engine ( single item )
       
  1375         iFileDetails->iSeekable &= iSeekable;
       
  1376 
       
  1377         //
       
  1378         // If it is live streaming, seekable and PausableStream should be EFalse
       
  1379         // Helix sends ETrue for "Seekable" and "PausableStream" in case of live streaming
       
  1380         //
       
  1381         if ( iFileDetails->iLiveStream || !iFileDetails->iPausableStream )
       
  1382         {
       
  1383             iFileDetails->iSeekable = EFalse;
       
  1384             iFileDetails->iPausableStream = EFalse;
       
  1385         }
       
  1386     }
       
  1387 }
       
  1388 
       
  1389 //  ------------------------------------------------------------------------------------------------
       
  1390 //  CMPXVideoPlaybackController::GetModeToSet
       
  1391 //  ------------------------------------------------------------------------------------------------
       
  1392 //
       
  1393 TMPXVideoMode CMPXVideoPlaybackController::GetModeToSet()
       
  1394 {
       
  1395     MPX_DEBUG(_L("CMPXVideoPlaybackController::GetModeToSet()"));
       
  1396 
       
  1397     TMPXVideoMode changeToMode = EMPXVideoLocal;   // default
       
  1398 
       
  1399     //
       
  1400     //  CMediaRecognizer can not recognize live media - as there isn't
       
  1401     //  sufficient info available from file name or file handle to make that
       
  1402     //  determination - so first check the file details for LIVE
       
  1403     //
       
  1404     if ( iFileDetails && iFileDetails->iLiveStream )
       
  1405     {
       
  1406         changeToMode = EMPXVideoLiveStreaming;
       
  1407     }
       
  1408     else
       
  1409     {
       
  1410         switch ( iMediaType )
       
  1411         {
       
  1412             case CMediaRecognizer::ELocalVideoFile: //intentional fall through
       
  1413             case CMediaRecognizer::ELocalAudioFile: //intentional fall through
       
  1414             case CMediaRecognizer::ELocalAudioPlaylist:
       
  1415             {
       
  1416                 // changeToMode initialized to EMPXVideoLocal
       
  1417                 // re-assignment not needed
       
  1418                 break;
       
  1419             }
       
  1420             case CMediaRecognizer::EProgressiveDownload:
       
  1421             {
       
  1422                 changeToMode = EMPXVideoProgressiveDownload;
       
  1423                 break;
       
  1424             }
       
  1425             case CMediaRecognizer::ELocalAsxFile:    //intentional fall through
       
  1426             case CMediaRecognizer::ELocalRamFile:    //intentional fall through
       
  1427             case CMediaRecognizer::ELocalSdpFile:    //intentional fall through
       
  1428             case CMediaRecognizer::EUrl:
       
  1429             {
       
  1430                 changeToMode = EMPXVideoStreaming;
       
  1431                 break;
       
  1432             }
       
  1433             case CMediaRecognizer::EUnidentified:   //intentional fall through
       
  1434             default:
       
  1435             {
       
  1436                 changeToMode = EMPXVideoLocal;
       
  1437                 break;
       
  1438             }
       
  1439         }
       
  1440     }
       
  1441 
       
  1442     MPX_DEBUG(_L("CMPXVideoPlaybackController::GetModeToSet() mode = %d"), changeToMode);
       
  1443 
       
  1444     return changeToMode;
       
  1445 }
       
  1446 
       
  1447 
       
  1448 //  ------------------------------------------------------------------------------------------------
       
  1449 //  CMPXVideoPlaybackController::SetPlaybackModeL
       
  1450 //  ------------------------------------------------------------------------------------------------
       
  1451 //
       
  1452 void CMPXVideoPlaybackController::SetPlaybackModeL()
       
  1453 {
       
  1454     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::SetPlaybackModeL()"));
       
  1455 
       
  1456     //
       
  1457     //  Do not allow the mode to be switched from PDL once it is set
       
  1458     //
       
  1459     if ( ! iPlaybackMode || iPlaybackMode->GetMode() != EMPXVideoProgressiveDownload )
       
  1460     {
       
  1461         //
       
  1462         //  determine what mode the controller needs to be in
       
  1463         //
       
  1464         TMPXVideoMode mode = GetModeToSet();
       
  1465 
       
  1466         //
       
  1467         //  Set new mode when no mode has been set or this is a new mode
       
  1468         //
       
  1469         if ( ! iPlaybackMode || mode != iPlaybackMode->GetMode() )
       
  1470         {
       
  1471             CMPXVideoPlaybackMode* temp = iPlaybackMode;
       
  1472 
       
  1473             switch ( mode )
       
  1474             {
       
  1475                 case EMPXVideoLocal:
       
  1476                     iPlaybackMode = CMPXLocalPlaybackMode::NewL( this );
       
  1477                     break;
       
  1478                 case EMPXVideoProgressiveDownload:
       
  1479                     iPlaybackMode = CMPXProgressiveDLPlaybackMode::NewL( this );
       
  1480                     break;
       
  1481                 case EMPXVideoStreaming:
       
  1482                     iPlaybackMode = CMPXStreamingPlaybackMode::NewL( this );
       
  1483                     break;
       
  1484                 case EMPXVideoLiveStreaming:
       
  1485                     iPlaybackMode = CMPXLiveStreamingPlaybackMode::NewL( this );
       
  1486                     break;
       
  1487                 default:
       
  1488                     iPlaybackMode = CMPXLocalPlaybackMode::NewL( this );
       
  1489                     break;
       
  1490             }
       
  1491 
       
  1492             delete temp;
       
  1493         }
       
  1494     }
       
  1495 }
       
  1496 
       
  1497 // -------------------------------------------------------------------------------------------------
       
  1498 //    CMPXVideoPlaybackController::DetermineMediaTypeL()
       
  1499 // -------------------------------------------------------------------------------------------------
       
  1500 //
       
  1501 void CMPXVideoPlaybackController::DetermineMediaTypeL()
       
  1502 {
       
  1503     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::DetermineMediaTypeL()"));
       
  1504 
       
  1505     CMediaRecognizer::TMediaType mediaType = CMediaRecognizer::EUnidentified;
       
  1506 
       
  1507     CMediaRecognizer* recognizer = CMediaRecognizer::NewL();
       
  1508     CleanupStack::PushL(recognizer);
       
  1509 
       
  1510     if ( iFileHandle.SubSessionHandle() )
       
  1511     {
       
  1512         TInt size(0);
       
  1513         iFileHandle.Size( size );
       
  1514 
       
  1515         if ( size > 0 )
       
  1516         {
       
  1517             mediaType = recognizer->IdentifyMediaTypeL( iClipName->Des(), iFileHandle, ETrue );
       
  1518 
       
  1519             iRecognizedMimeType = recognizer->MimeTypeL( iFileHandle ).AllocL();
       
  1520         }
       
  1521     }
       
  1522 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
  1523     else if ( iFileHandle64.SubSessionHandle() )
       
  1524     {
       
  1525         TInt64 size(0);
       
  1526         iFileHandle64.Size( size );
       
  1527 
       
  1528         if ( size > 0 )
       
  1529         {
       
  1530             mediaType = recognizer->IdentifyMediaTypeL( iClipName->Des(), iFileHandle64, ETrue );
       
  1531 
       
  1532             iRecognizedMimeType = recognizer->MimeTypeL( iFileHandle64 ).AllocL();
       
  1533         }
       
  1534     }
       
  1535 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
  1536     else
       
  1537     {
       
  1538         if ( recognizer->IsValidStreamingPrefix( iClipName->Des() ) )
       
  1539         {
       
  1540             //
       
  1541             //   check the descriptor to determine if it has a valid streaming prefix
       
  1542             //
       
  1543             mediaType = CMediaRecognizer::EUrl;
       
  1544         }
       
  1545     }
       
  1546 
       
  1547     CleanupStack::PopAndDestroy( recognizer );
       
  1548 
       
  1549     iMediaType = mediaType;
       
  1550 }
       
  1551 
       
  1552 // -----------------------------------------------------------------------------
       
  1553 // CMPXVideoPlaybackController::IsPhoneCall
       
  1554 // -----------------------------------------------------------------------------
       
  1555 //
       
  1556 TBool CMPXVideoPlaybackController::IsPhoneCall()
       
  1557 {
       
  1558     TInt state = 0;
       
  1559     TBool call;
       
  1560     RProperty SystemState;
       
  1561 
       
  1562     SystemState.Attach( KPSUidCtsyCallInformation, KCTsyCallState );
       
  1563 
       
  1564     TInt error = SystemState.Get( state );
       
  1565 
       
  1566     if ( error || ( state == EPSCTsyCallStateNone || state == EPSCTsyCallStateUninitialized ) )
       
  1567     {
       
  1568         call = EFalse;
       
  1569     }
       
  1570     else
       
  1571     {
       
  1572         call = ETrue;
       
  1573     }
       
  1574 
       
  1575     MPX_DEBUG(_L("CMPXVideoPlaybackController::IsPhoneCall(%d)"), call);
       
  1576 
       
  1577     SystemState.Close();
       
  1578     return call;
       
  1579 }
       
  1580 
       
  1581 // -----------------------------------------------------------------------------
       
  1582 // CMPXVideoPlaybackController::IsActivePhoneCall
       
  1583 // -----------------------------------------------------------------------------
       
  1584 //
       
  1585 TBool CMPXVideoPlaybackController::IsActivePhoneCall()
       
  1586 {
       
  1587     TBool retVal = EFalse;
       
  1588     TInt state = 0;
       
  1589     RProperty SystemState;
       
  1590 
       
  1591     SystemState.Attach( KPSUidCtsyCallInformation, KCTsyCallState );
       
  1592 
       
  1593     if ( !SystemState.Get( state ) && state == EPSCTsyCallStateConnected )
       
  1594     {
       
  1595         retVal = ETrue;
       
  1596     }
       
  1597 
       
  1598     MPX_DEBUG(_L("CMPXVideoPlaybackController::IsActivePhoneCall(%d)"), retVal);
       
  1599 
       
  1600     SystemState.Close();
       
  1601 
       
  1602     return retVal;
       
  1603 }
       
  1604 
       
  1605 // -----------------------------------------------------------------------------
       
  1606 // CMPXVideoPlaybackController::IsVideoCall
       
  1607 // -----------------------------------------------------------------------------
       
  1608 //
       
  1609 TBool CMPXVideoPlaybackController::IsVideoCall()
       
  1610 {
       
  1611     TInt callType;
       
  1612 
       
  1613     RProperty::Get( KPSUidCtsyCallInformation,
       
  1614                     KCTsyCallType,
       
  1615                     callType );// Ignore errors
       
  1616 
       
  1617     TBool videoCall = ( callType == EPSCTsyCallTypeH324Multimedia );
       
  1618 
       
  1619     MPX_DEBUG(_L("CMPXVideoPlaybackController::IsVideoCall(%d)"), videoCall );
       
  1620 
       
  1621     return videoCall;
       
  1622 }
       
  1623 
       
  1624 // -----------------------------------------------------------------------------
       
  1625 // CMPXVideoPlaybackController::IsVoiceCall
       
  1626 // -----------------------------------------------------------------------------
       
  1627 //
       
  1628 TBool CMPXVideoPlaybackController::IsVoiceCall()
       
  1629 {
       
  1630     TBool call;
       
  1631     TInt type = 0;
       
  1632     RProperty SystemState;
       
  1633 
       
  1634     SystemState.Attach( KPSUidCtsyCallInformation, KCTsyCallState );
       
  1635 
       
  1636     TInt error = SystemState.Get( KPSUidCtsyCallInformation, KCTsyCallType, type );
       
  1637 
       
  1638     if ( ! error && ( (type == EPSCTsyCallTypeCSVoice) || (type == EPSCTsyCallTypeVoIP) ) )
       
  1639     {
       
  1640         call = ETrue;
       
  1641     }
       
  1642     else
       
  1643     {
       
  1644         call = EFalse;
       
  1645     }
       
  1646 
       
  1647     MPX_DEBUG(_L("CMPXVideoPlaybackController::IsVoiceCall(%d)"), call);
       
  1648 
       
  1649     SystemState.Close();
       
  1650     return call;
       
  1651 }
       
  1652 
       
  1653 // -----------------------------------------------------------------------------
       
  1654 // CMPXVideoPlaybackController::IsAlarm
       
  1655 // -----------------------------------------------------------------------------
       
  1656 //
       
  1657 TBool CMPXVideoPlaybackController::IsAlarm()
       
  1658 {
       
  1659     TBool alarm( EFalse );
       
  1660 
       
  1661     RProperty::Get( KPSUidCoreApplicationUIs, KLightsAlarmLightActive, alarm );
       
  1662 
       
  1663     alarm = ( alarm == ELightsBlinking ) ? ETrue : EFalse; // Ignore errors
       
  1664 
       
  1665     MPX_DEBUG(_L("CMPXVideoPlaybackController::IsAlarm(%d)"), alarm);
       
  1666 
       
  1667     return alarm;
       
  1668 }
       
  1669 
       
  1670 // -----------------------------------------------------------------------------
       
  1671 // CMPXVideoPlaybackController::IsDisplayOff
       
  1672 // -----------------------------------------------------------------------------
       
  1673 //
       
  1674 TBool CMPXVideoPlaybackController::IsDisplayOff()
       
  1675 {
       
  1676     TBool displayState;
       
  1677     HAL::Get( HALData::EDisplayState, displayState );
       
  1678 
       
  1679     MPX_DEBUG(_L("CMPXVideoPlaybackController::IsDisplayOff(%d)"), !displayState);
       
  1680 
       
  1681     return !displayState;
       
  1682 }
       
  1683 
       
  1684 //  ------------------------------------------------------------------------------------------------
       
  1685 //    CMPXVideoPlaybackController::HandleTvOutEventL()
       
  1686 //  ------------------------------------------------------------------------------------------------
       
  1687 //
       
  1688 void CMPXVideoPlaybackController::HandleTvOutEventL( TBool aConnected )
       
  1689 {
       
  1690     MPX_ENTER_EXIT( _L("CMPXVideoPlaybackController::HandleTvOutEventL()"),
       
  1691                     _L("aConnected = %d"), aConnected );
       
  1692 
       
  1693     TBool playbackAllowed = ETrue;
       
  1694 
       
  1695     if ( aConnected )
       
  1696     {
       
  1697         //
       
  1698         //  TV-Out accessory connected
       
  1699         //
       
  1700         if ( ! iAccessoryMonitor->IsTvOutPlaybackAllowed() )
       
  1701         {
       
  1702             //
       
  1703             //  Clip has DRM protection and TV-Out is connected
       
  1704             //  Pause playback and display info note
       
  1705             //
       
  1706             DoHandleCommandL( EPbCmdPause );
       
  1707 
       
  1708             playbackAllowed = EFalse;
       
  1709 
       
  1710             iState->SendErrorToViewL( KMPXVideoTvOutPlaybackNotAllowed );
       
  1711         }
       
  1712     }
       
  1713     else
       
  1714     {
       
  1715         //
       
  1716         //  Pause playback since TV-Out accessory has been disconnected.
       
  1717         //
       
  1718         DoHandleCommandL( EPbCmdPause );
       
  1719     }
       
  1720 
       
  1721     //
       
  1722     //  Send notice to the playback view with TV-Out connection status
       
  1723     //  and TV-Out playback allowed flag
       
  1724     //
       
  1725     CMPXMessage* message = CMPXMessage::NewL();
       
  1726     CleanupStack::PushL( message );
       
  1727 
       
  1728     message->SetTObjectValueL<TMPXMessageId>( KMPXMessageGeneralId, KMPXMediaIdVideoPlayback );
       
  1729     message->SetTObjectValueL<TMPXVideoPlaybackCommand>
       
  1730         ( KMPXMediaVideoPlaybackCommand, EPbCmdTvOutEvent );
       
  1731     message->SetTObjectValueL<TInt>( KMPXMediaVideoTvOutConnected, aConnected );
       
  1732     message->SetTObjectValueL<TInt>( KMPXMediaVideoTvOutPlayAllowed, playbackAllowed );
       
  1733 
       
  1734     iMPXPluginObs->HandlePlaybackMessage( message, KErrNone );
       
  1735 
       
  1736     CleanupStack::PopAndDestroy( message );
       
  1737 }
       
  1738 
       
  1739 //  ------------------------------------------------------------------------------------------------
       
  1740 //    CMPXVideoPlaybackController::CancelBackLightTimer
       
  1741 //  ------------------------------------------------------------------------------------------------
       
  1742 void  CMPXVideoPlaybackController::CancelBackLightTimer()
       
  1743 {
       
  1744     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::CancelBackLightTimer()"));
       
  1745 
       
  1746     if ( iBackLightTimer->IsActive() )
       
  1747     {
       
  1748         iBackLightTimer->Cancel();
       
  1749     }
       
  1750 }
       
  1751 
       
  1752 //  ------------------------------------------------------------------------------------------------
       
  1753 //    CMPXVideoPlaybackState::StartBackLightTimer
       
  1754 //  ------------------------------------------------------------------------------------------------
       
  1755 void  CMPXVideoPlaybackController::StartBackLightTimer()
       
  1756 {
       
  1757     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::StartBackLightTimer()"));
       
  1758 
       
  1759     if ( !iBackLightTimer->IsActive() )
       
  1760     {
       
  1761         iBackLightTimer->Start(
       
  1762             0,
       
  1763             KMPXBackLightTimeOut,
       
  1764             TCallBack( CMPXVideoPlaybackController::HandleBackLightTimout, this ));
       
  1765     }
       
  1766 }
       
  1767 
       
  1768 // -------------------------------------------------------------------------------------------------
       
  1769 // Handle back light timer timeout callback
       
  1770 // -------------------------------------------------------------------------------------------------
       
  1771 //
       
  1772 TInt CMPXVideoPlaybackController::HandleBackLightTimout( TAny* aPtr )
       
  1773 {
       
  1774     static_cast<CMPXVideoPlaybackController*>(aPtr)->DoHandleBackLightTimout();
       
  1775     return KErrNone;
       
  1776 }
       
  1777 
       
  1778 // -------------------------------------------------------------------------------------------------
       
  1779 // Handle back light timer timeout
       
  1780 // -------------------------------------------------------------------------------------------------
       
  1781 //
       
  1782 void CMPXVideoPlaybackController::DoHandleBackLightTimout()
       
  1783 {
       
  1784     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::DoHandleBackLightTimout()"));
       
  1785 
       
  1786     User::ResetInactivityTime();
       
  1787 }
       
  1788 
       
  1789 // -------------------------------------------------------------------------------------------------
       
  1790 // CMPXVideoPlaybackController::InitVolumeWatchers()
       
  1791 // -------------------------------------------------------------------------------------------------
       
  1792 //
       
  1793 void CMPXVideoPlaybackController::InitVolumeWatchers()
       
  1794 {
       
  1795     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::InitVolumeWatchers()"));
       
  1796 
       
  1797     if ( ! iVolumeWatcher )
       
  1798     {
       
  1799         MPX_TRAPD( err,
       
  1800                 iVolumeWatcher = CMPXCenRepWatcher::NewL( KCRUidMPXVideoSettings,
       
  1801                                                           KMPXVideoPlaybackVolume,
       
  1802                                                           this ) );
       
  1803     }
       
  1804 
       
  1805     if ( ! iMuteWatcher )
       
  1806     {
       
  1807         MPX_TRAPD( err,
       
  1808                 iMuteWatcher = CMPXCenRepWatcher::NewL( KCRUidMPXVideoSettings,
       
  1809                                                         KMPXVideoPlaybackMute,
       
  1810                                                         this ) );
       
  1811     }
       
  1812 
       
  1813     //
       
  1814     // MPX framework volume range : 0-100
       
  1815     // Media player volume range : 0-10
       
  1816     // MPX video player volume range : 0 - volume steps (defined in PlaybackHelper)
       
  1817     // For IAD, need to manipulate volume to save in cenrep
       
  1818     // MPX Framework volume / iVolumeNormalizer => CenRep
       
  1819     //
       
  1820     CDevSoundIf* devSoundIf = CDevSoundIf::NewL();
       
  1821     TInt volumeSteps =  devSoundIf->GetNumberOfVolumeSteps();
       
  1822     delete devSoundIf;
       
  1823 
       
  1824     //
       
  1825     // MPX issues GetPropertyL(EPbPropertyVolume) before MMF gets called.
       
  1826     // Hence, set iVolumeNormalizer value during construction time.
       
  1827     //
       
  1828     SetVolumeSteps( volumeSteps );
       
  1829 }
       
  1830 
       
  1831 //  ------------------------------------------------------------------------------------------------
       
  1832 //  CMPXVideoPlaybackController::HandleError
       
  1833 //  ------------------------------------------------------------------------------------------------
       
  1834 //
       
  1835 void CMPXVideoPlaybackController::HandleError( TInt error )
       
  1836 {
       
  1837     MPX_ENTER_EXIT( _L("CMPXVideoPlaybackController::HandleError()"),
       
  1838                     _L("error = %d"), error );
       
  1839 
       
  1840     ChangeState( EMPXVideoNotInitialized );
       
  1841 
       
  1842     //
       
  1843     // Move the FW state to Initialized so that it can request for Media
       
  1844     //
       
  1845     iMPXPluginObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPInitialised, 0, KErrNone );
       
  1846 
       
  1847     iPBPluginError = error;
       
  1848 }
       
  1849 
       
  1850 //  ------------------------------------------------------------------------------------------------
       
  1851 //    CMPXVideoPlaybackController::ResetMemberVariables
       
  1852 //  ------------------------------------------------------------------------------------------------
       
  1853 //
       
  1854 void CMPXVideoPlaybackController::ResetMemberVariables()
       
  1855 {
       
  1856     MPX_ENTER_EXIT( _L("CMPXVideoPlaybackController::ResetMemberVariables()"));
       
  1857 
       
  1858     iPlayer->Reset();
       
  1859 
       
  1860     if ( iFileDetails )
       
  1861     {
       
  1862         delete iFileDetails;
       
  1863         iFileDetails = NULL;
       
  1864     }
       
  1865 
       
  1866     if ( iClipName )
       
  1867     {
       
  1868         delete iClipName;
       
  1869         iClipName = NULL;
       
  1870     }
       
  1871 
       
  1872     if ( iRecognizedMimeType )
       
  1873     {
       
  1874         delete iRecognizedMimeType;
       
  1875         iRecognizedMimeType = NULL;
       
  1876     }
       
  1877 
       
  1878     if ( iFileHandle.SubSessionHandle() )
       
  1879     {
       
  1880         iFileHandle.Close();
       
  1881     }
       
  1882 
       
  1883 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
  1884     if ( iFileHandle64.SubSessionHandle() )
       
  1885     {
       
  1886         iFileHandle64.Close();
       
  1887     }
       
  1888 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
  1889     
       
  1890     // reset to True
       
  1891     iSeekable = ETrue;
       
  1892 
       
  1893     //
       
  1894     //  Needs to be last thing destroyed since PDL requires the
       
  1895     //  controller to be unloaded to move clip
       
  1896     //
       
  1897     delete iPlaybackMode;
       
  1898     iPlaybackMode = NULL;
       
  1899 
       
  1900     //
       
  1901     //  Reset the flag to retrieve the Buffering percentage from Helix
       
  1902     //
       
  1903     iHelixLoadingStarted = EFalse;
       
  1904 }
       
  1905 
       
  1906 //  ------------------------------------------------------------------------------------------------
       
  1907 //  CMPXVideoPlaybackController::HandleVolumeL
       
  1908 //  ------------------------------------------------------------------------------------------------
       
  1909 //
       
  1910 void CMPXVideoPlaybackController::HandleVolumeL( TBool aIncrease )
       
  1911 {
       
  1912     MPX_ENTER_EXIT( _L("CMPXVideoPlaybackController::HandleVolumeL()"),
       
  1913                     _L("aIncrease = %d"), aIncrease );
       
  1914 
       
  1915     //
       
  1916     // Media player's CenRep volume range : 0 - number of volume steps
       
  1917     // MPX framework volume range : 0-100
       
  1918     //
       
  1919     TInt volume = iVolumeWatcher->CurrentValueL();
       
  1920 
       
  1921     if ( aIncrease )
       
  1922     {
       
  1923         //
       
  1924         // increase the current volume
       
  1925         //
       
  1926         volume++;
       
  1927     }
       
  1928     else if ( volume > 0 )
       
  1929     {
       
  1930         //
       
  1931         // decrease the current volume
       
  1932         //
       
  1933         volume--;
       
  1934     }
       
  1935 
       
  1936     //
       
  1937     // save the current volume level in CenRep
       
  1938     //
       
  1939     SetVolumeCenRepL( volume * iVolumeNormalizer );
       
  1940 }
       
  1941 
       
  1942 //  ------------------------------------------------------------------------------------------------
       
  1943 //  CMPXVideoPlaybackController::SetVolumeSteps
       
  1944 //  ------------------------------------------------------------------------------------------------
       
  1945 //
       
  1946 void CMPXVideoPlaybackController::SetVolumeSteps( TInt aVolumeSteps )
       
  1947 {
       
  1948     MPX_DEBUG(_L("CMPXVideoPlaybackController::SetVolumeSteps(%d)"), aVolumeSteps );
       
  1949 
       
  1950     iVolumeNormalizer = KPbPlaybackVolumeLevelMax / aVolumeSteps;
       
  1951 }
       
  1952 
       
  1953 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
  1954 
       
  1955 //  ------------------------------------------------------------------------------------------------
       
  1956 //    CMPXVideoPlaybackController::OpenFile64L()
       
  1957 //  ------------------------------------------------------------------------------------------------
       
  1958 //
       
  1959 void CMPXVideoPlaybackController::OpenFile64L( const TDesC& aMediaFile,
       
  1960                                                RFile64& aFile,
       
  1961                                                TInt aAccessPointId )
       
  1962 {
       
  1963     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::OpenFile64L( RFile64 )"),
       
  1964                    _L("file = %S"), &aMediaFile );
       
  1965 
       
  1966     TBool fileExists = EFalse;
       
  1967 
       
  1968     ChangeState( EMPXVideoInitializing );
       
  1969 
       
  1970     iClipName = aMediaFile.AllocL();
       
  1971     iAccessPointId = aAccessPointId;
       
  1972 
       
  1973     //
       
  1974     //  If file handle exists, duplicate it to the controller
       
  1975     //
       
  1976     if ( aFile.SubSessionHandle() )
       
  1977     {
       
  1978         if ( iFileHandle64.SubSessionHandle() )
       
  1979         {
       
  1980             iFileHandle64.Close();
       
  1981         }
       
  1982 
       
  1983         User::LeaveIfError( iFileHandle64.Duplicate( aFile ) );
       
  1984 
       
  1985         fileExists = ETrue;
       
  1986     }
       
  1987 
       
  1988     DetermineMediaTypeL();
       
  1989     SetPlaybackModeL();
       
  1990 
       
  1991     //
       
  1992     //  Create accessory monitor to search for TV-Out events
       
  1993     //
       
  1994     if ( ! iAccessoryMonitor )
       
  1995     {
       
  1996         iAccessoryMonitor = CMPXVideoAccessoryObserver::NewL( this );
       
  1997     }
       
  1998 
       
  1999     if ( iAccessoryMonitor->IsTvOutPlaybackAllowed() )
       
  2000     {
       
  2001         if ( fileExists )
       
  2002         {
       
  2003             //
       
  2004             //  Ensure there are rights for protected clips
       
  2005             //
       
  2006             TInt drmError = iDrmHelper->GetDrmRightsStatus64( iFileHandle64 );
       
  2007 
       
  2008             if ( drmError )
       
  2009             {
       
  2010                 //
       
  2011                 //  Send error to observer for handling
       
  2012                 //
       
  2013                 HandleError( drmError );
       
  2014             }
       
  2015             else
       
  2016             {
       
  2017                 iState->OpenFile64L( iFileHandle64 );
       
  2018             }
       
  2019         }
       
  2020         else
       
  2021         {
       
  2022             iState->OpenFileL( iClipName->Des() );
       
  2023         }
       
  2024     }
       
  2025     else
       
  2026     {
       
  2027         HandleError( KMPXVideoTvOutPlaybackNotAllowedClose );
       
  2028     }
       
  2029 }
       
  2030 
       
  2031 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
       
  2032 
       
  2033 // End of file