videoplayback/videohelix/src/mpxvideoplaybackcontroller.cpp
branchRCL_3
changeset 9 5294c000a26d
parent 8 ce5ada96ab30
child 10 112a725ff2c2
equal deleted inserted replaced
8:ce5ada96ab30 9:5294c000a26d
    13 *
    13 *
    14 * Description:  This class plays local video file
    14 * Description:  This class plays local video file
    15  *
    15  *
    16 */
    16 */
    17 
    17 
    18 // Version : %version: 47 %
    18 // Version : %version: ou1cpsw#49 %
    19 
    19 
    20 
    20 
    21 //
    21 //
    22 //  INCLUDE FILES
    22 //  INCLUDE FILES
    23 //
    23 //
    39 #include <mmf/common/mmferrors.h>
    39 #include <mmf/common/mmferrors.h>
    40 
    40 
    41 #include <e32std.h>
    41 #include <e32std.h>
    42 #include <devsoundif.h>
    42 #include <devsoundif.h>
    43 #include <avkondomainpskeys.h>
    43 #include <avkondomainpskeys.h>
       
    44 #include <hwrmlight.h>  
       
    45 #include <centralrepository.h>  // For display timeout setting
       
    46 #include <hwrmlightdomaincrkeys.h>
    44 
    47 
    45 #include "mpxvideoregion.h"
    48 #include "mpxvideoregion.h"
    46 #include "mpxvideoplaybackcontroller.h"
    49 #include "mpxvideoplaybackcontroller.h"
    47 #include "mpxvideoplaybackstate.h"
    50 #include "mpxvideoplaybackstate.h"
    48 #include "mpxvideoprivatecrkeys.h"
    51 #include "mpxvideoprivatecrkeys.h"
    59 #define KMAXMIMETYPELENGTH 256
    62 #define KMAXMIMETYPELENGTH 256
    60 
    63 
    61 //
    64 //
    62 //  Backlight Timeout in Micro Seconds
    65 //  Backlight Timeout in Micro Seconds
    63 //
    66 //
    64 #define KMPXBackLightTimeOut 3500000
    67 const TInt KMPXBackLightTimeOut = 3500000;
       
    68 const TInt KMPXInactivityTimeout  = 3 * KMPXBackLightTimeOut;
       
    69 const TInt KMPXMicroSecondsInASecond = 1000000;
    65 
    70 
    66 #define KOneKilobyte 1024
    71 #define KOneKilobyte 1024
    67 
    72 
    68 _LIT( KTitle, "Title" );
    73 _LIT( KTitle, "Title" );
    69 _LIT( KLiveStream, "LiveStream" );
    74 _LIT( KLiveStream, "LiveStream" );
   148     iVideoSeeker = CMPXVideoSeeker::NewL( this );
   153     iVideoSeeker = CMPXVideoSeeker::NewL( this );
   149 
   154 
   150     // Initiliaze to True
   155     // Initiliaze to True
   151     iSeekable = ETrue;
   156     iSeekable = ETrue;
   152 
   157 
   153     InitVolumeWatchers();
   158     InitVolumeWatchersL();
   154 
   159 
   155     CreatePreInitStatesL();
   160     CreatePreInitStatesL();
   156 
   161 
   157     iPlayer = CMpxVideoPlayerUtility::NewL( this );
   162     iPlayer = CMpxVideoPlayerUtility::NewL( this );
   158 
   163 
   159     iBackLightTimer = CPeriodic::NewL( CActive::EPriorityStandard );
   164     iBackLightTimer = CPeriodic::NewL( CActive::EPriorityStandard );
   160 
   165 
   161     iDrmHelper = CMpxVideoDrmHelper::NewL();
   166     iDrmHelper = CMpxVideoDrmHelper::NewL();
       
   167     
       
   168     iSavedPosition = 0;
   162 }
   169 }
   163 
   170 
   164 //  ----------------------------------------------------------------------------
   171 //  ----------------------------------------------------------------------------
   165 //  CMPXVideoPlaybackController::CloseController()
   172 //  CMPXVideoPlaybackController::CloseController()
   166 //  ----------------------------------------------------------------------------
   173 //  ----------------------------------------------------------------------------
   167 //
   174 //
   168 void CMPXVideoPlaybackController::CloseController()
   175 void CMPXVideoPlaybackController::CloseController()
   169 {
   176 {
   170     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::CloseController()"));
   177     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::CloseController()"));
   171 
       
   172     ChangeState( EMPXVideoNotInitialized );
   178     ChangeState( EMPXVideoNotInitialized );
   173 }
   179 }
   174 
   180 
   175 //  ------------------------------------------------------------------------------------------------
   181 //  ------------------------------------------------------------------------------------------------
   176 //    CMPXVideoPlaybackController::OpenFileL()
   182 //    CMPXVideoPlaybackController::OpenFileL()
   177 //  ------------------------------------------------------------------------------------------------
   183 //  ------------------------------------------------------------------------------------------------
   178 //
   184 //
   179 void CMPXVideoPlaybackController::OpenFileL( const TDesC& aMediaFile,
   185 void CMPXVideoPlaybackController::OpenFileL( const TDesC& aMediaFile,
   180                                              RFile& aFile,
   186                                              RFile& aFile,
   181                                              TInt aAccessPointId )
   187                                              TInt aPosition,
       
   188                                              TInt aAccessPointId ) 
   182 {
   189 {
   183     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::OpenFileL()"),
   190     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::OpenFileL()"),
   184                    _L("file = %S"), &aMediaFile );
   191                    _L("file = %S"), &aMediaFile );
   185 
   192 
   186     TBool fileExists = EFalse;
   193     TBool fileExists = EFalse;
   206     }
   213     }
   207 
   214 
   208     DetermineMediaTypeL();
   215     DetermineMediaTypeL();
   209     SetPlaybackModeL();
   216     SetPlaybackModeL();
   210 
   217 
       
   218     iSavedPosition = aPosition;
       
   219     
   211     //
   220     //
   212     //  Create accessory monitor to search for TV-Out events
   221     //  Create accessory monitor to search for TV-Out events
   213     //
   222     //
   214     if ( ! iAccessoryMonitor )
   223     if ( ! iAccessoryMonitor )
   215     {
   224     {
   255 CMPXVideoPlaybackController::CMPXVideoPlaybackController()
   264 CMPXVideoPlaybackController::CMPXVideoPlaybackController()
   256     : iAppInForeground(ETrue)
   265     : iAppInForeground(ETrue)
   257     , iForegroundPause(EFalse)
   266     , iForegroundPause(EFalse)
   258     , iAllowAutoPlay(ETrue)
   267     , iAllowAutoPlay(ETrue)
   259     , iHelixLoadingStarted(EFalse)
   268     , iHelixLoadingStarted(EFalse)
       
   269     , iLightStatus(CHWRMLight::ELightStatusUnknown)
   260 {
   270 {
   261 }
   271 }
   262 
   272 
   263 //  ----------------------------------------------------------------------------
   273 //  ----------------------------------------------------------------------------
   264 //    Destructor
   274 //    Destructor
   337     if ( iPlayer )
   347     if ( iPlayer )
   338     {
   348     {
   339         delete iPlayer;
   349         delete iPlayer;
   340         iPlayer = NULL;
   350         iPlayer = NULL;
   341     }
   351     }
       
   352    
       
   353     if ( iUserActivityTimer )
       
   354     {
       
   355         iUserActivityTimer->Cancel();
       
   356         delete iUserActivityTimer;
       
   357         iUserActivityTimer = NULL;
       
   358     }
       
   359     
       
   360     ReleaseLights();
       
   361     
       
   362     CancelDisplayTimer();
   342 
   363 
   343 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
   364 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
   344 
   365 
   345     if ( iFileHandle64.SubSessionHandle() )
   366     if ( iFileHandle64.SubSessionHandle() )
   346     {
   367     {
   977     {
   998     {
   978         switch ( aSettingId )
   999         switch ( aSettingId )
   979         {
  1000         {
   980             case KMPXVideoPlaybackMute:
  1001             case KMPXVideoPlaybackMute:
   981             {
  1002             {
       
  1003                 TInt muteValue( EFalse );
       
  1004 
       
  1005                 TRAP_IGNORE( muteValue = iMuteWatcher->CurrentValueL() );
       
  1006 
   982                 iMPXPluginObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPMuteChanged,
  1007                 iMPXPluginObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPMuteChanged,
   983                                                   iMuteWatcher->CurrentValueL(),
  1008                                                   muteValue,
   984                                                   KErrNone );
  1009                                                   KErrNone );
   985                 // fall through
  1010                 // fall through
   986             }
  1011             }
   987             case KMPXVideoPlaybackVolume:
  1012             case KMPXVideoPlaybackVolume:
   988             {
  1013             {
   989                 //
  1014                 //
   990                 //  this is the callback from cen-rep
  1015                 //  this is the callback from cen-rep
   991                 //  let the state decide if it needs to do something
  1016                 //  let the state decide if it needs to do something
   992                 //
  1017                 //
   993                 iState->HandleVolumeChange();
  1018                 iState->HandleVolumeChange();
   994                 break;
       
   995             }
       
   996             default:
       
   997             {
       
   998                 break;
  1019                 break;
   999             }
  1020             }
  1000         }
  1021         }
  1001     }
  1022     }
  1002 }
  1023 }
  1188                 //  If clip has audio and video, proceed to the next case which will
  1209                 //  If clip has audio and video, proceed to the next case which will
  1189                 //  start the backlight timer if needed
  1210                 //  start the backlight timer if needed
  1190                 //
  1211                 //
  1191                 if ( iFileDetails->iVideoEnabled )
  1212                 if ( iFileDetails->iVideoEnabled )
  1192                 {
  1213                 {
  1193                     StartBackLightTimer();
  1214                     StartLightsControl();
  1194                 }
  1215                 }
  1195                 else
  1216                 else
  1196                 {
  1217                 {
  1197                     CancelBackLightTimer();
  1218                     CancelLightsControl();
  1198                 }
  1219                 }
  1199                 
  1220                 
  1200                 break;
  1221                 break;
  1201             }
  1222             }
  1202             case EMPXVideoPaused:
  1223             case EMPXVideoPaused:
  1203             {
  1224             {
  1204                 iState = iPausedState;
  1225                 iState = iPausedState;
  1205                 CancelBackLightTimer();
  1226                 CancelLightsControl();
  1206                 break;
  1227                 break;
  1207             }
  1228             }
  1208             case EMPXVideoInitializing:
  1229             case EMPXVideoInitializing:
  1209             {
  1230             {
  1210                 iState = iInitialisingState;
  1231                 iState = iInitialisingState;
  1211                 StartBackLightTimer();
  1232                 StartLightsControl();
  1212                 break;
  1233                 break;
  1213             }
  1234             }
  1214             case EMPXVideoInitialized:
  1235             case EMPXVideoInitialized:
  1215             {
  1236             {
  1216                 iState = iInitialisedState;
  1237                 iState = iInitialisedState;
       
  1238                 StartLightsControl();
  1217                 break;
  1239                 break;
  1218             }
  1240             }
  1219             case EMPXVideoBuffering:
  1241             case EMPXVideoBuffering:
  1220             {
  1242             {
  1221                 iState = iBufferingState;
  1243                 iState = iBufferingState;
  1222                 StartBackLightTimer();
  1244                 StartLightsControl();
  1223                 break;
  1245                 break;
  1224             }
  1246             }
  1225             case EMPXVideoSeeking:
  1247             case EMPXVideoSeeking:
  1226             {
  1248             {
  1227                 iState = iSeekingState;
  1249                 iState = iSeekingState;
       
  1250                 StartLightsControl();
  1228                 break;
  1251                 break;
  1229             }
  1252             }
  1230             case EMPXVideoStopped:
  1253             case EMPXVideoStopped:
  1231             {
  1254             {
  1232                 iState = iStoppedState;
  1255                 iState = iStoppedState;
  1233                 CancelBackLightTimer();
  1256                 CancelLightsControl();
  1234                 break;
  1257                 break;
  1235             }
  1258             }
  1236             case EMPXVideoNotInitialized:
  1259             case EMPXVideoNotInitialized:
  1237             {
  1260             {
  1238                 ResetMemberVariables();
  1261                 ResetMemberVariables();
  1239                 iState = iNotIntialisedState;
  1262                 iState = iNotIntialisedState;
  1240                 CancelBackLightTimer();
  1263                 CancelLightsControl();
  1241                 break;
  1264                 break;
  1242             }
  1265             }
  1243         }
  1266         }
  1244     }
  1267     }
  1245 }
  1268 }
  1306     //
  1329     //
  1307     //  Max Volume
  1330     //  Max Volume
  1308     //
  1331     //
  1309     iFileDetails->iMaxVolume = iPlayer->MaxVolume();
  1332     iFileDetails->iMaxVolume = iPlayer->MaxVolume();
  1310 
  1333 
  1311     // 
  1334     //
  1312     //  FourCC Code
  1335     //  FourCC Code
  1313     //
  1336     //
  1314     iFileDetails->iFourCCCode  = iPlayer->FourCCCode();    
  1337     iFileDetails->iFourCCCode  = iPlayer->FourCCCode();
  1315     
  1338 
  1316     //
  1339     //
  1317     //  Mime Type
  1340     //  Mime Type
  1318     //
  1341     //
  1319     HBufC8* mimeType = HBufC8::NewL( KMAXMIMETYPELENGTH );
  1342     HBufC8* mimeType = HBufC8::NewL( KMAXMIMETYPELENGTH );
  1320     CleanupStack::PushL( mimeType );
  1343     CleanupStack::PushL( mimeType );
  1425             }
  1448             }
  1426             else if ( !metaData->Name().CompareF( KKeywords ) )
  1449             else if ( !metaData->Name().CompareF( KKeywords ) )
  1427             {
  1450             {
  1428                 iFileDetails->iKeywords = metaData->Value().AllocL();
  1451                 iFileDetails->iKeywords = metaData->Value().AllocL();
  1429             }
  1452             }
  1430             
  1453 
  1431             CleanupStack::PopAndDestroy( metaData );
  1454             CleanupStack::PopAndDestroy( metaData );
  1432         }
  1455         }
  1433 
  1456 
  1434         // Update the seek value for asx clips with the value
  1457         // Update the seek value for asx clips with the value
  1435         // received from the engine ( single item )
  1458         // received from the engine ( single item )
  1768 
  1791 
  1769             playbackAllowed = EFalse;
  1792             playbackAllowed = EFalse;
  1770 
  1793 
  1771             iState->SendErrorToViewL( KMPXVideoTvOutPlaybackNotAllowed );
  1794             iState->SendErrorToViewL( KMPXVideoTvOutPlaybackNotAllowed );
  1772         }
  1795         }
       
  1796         else
       
  1797         {
       
  1798             // If lights are being controlled enable display timer so that screen backlight will be turned
       
  1799             // of after timeout.
       
  1800             if ( iBackLightTimer->IsActive() )
       
  1801             {
       
  1802                 RestartDisplayTimer();
       
  1803             }
       
  1804          } 
       
  1805     }
       
  1806     else 
       
  1807     {
       
  1808         // TV out disconnected
       
  1809         CancelDisplayTimer();
       
  1810         // Ensure that lights are on after this 
       
  1811         ReleaseLights();
  1773     }
  1812     }
  1774 
  1813 
  1775     //
  1814     //
  1776     //  Send notice to the playback view with TV-Out connection status
  1815     //  Send notice to the playback view with TV-Out connection status
  1777     //  and TV-Out playback allowed flag
  1816     //  and TV-Out playback allowed flag
  1799 
  1838 
  1800     if ( iBackLightTimer->IsActive() )
  1839     if ( iBackLightTimer->IsActive() )
  1801     {
  1840     {
  1802         iBackLightTimer->Cancel();
  1841         iBackLightTimer->Cancel();
  1803     }
  1842     }
       
  1843     
  1804 }
  1844 }
  1805 
  1845 
  1806 //  ------------------------------------------------------------------------------------------------
  1846 //  ------------------------------------------------------------------------------------------------
  1807 //    CMPXVideoPlaybackState::StartBackLightTimer
  1847 //    CMPXVideoPlaybackState::StartBackLightTimer
  1808 //  ------------------------------------------------------------------------------------------------
  1848 //  ------------------------------------------------------------------------------------------------
  1813     if ( !iBackLightTimer->IsActive() )
  1853     if ( !iBackLightTimer->IsActive() )
  1814     {
  1854     {
  1815         iBackLightTimer->Start(
  1855         iBackLightTimer->Start(
  1816             0,
  1856             0,
  1817             KMPXBackLightTimeOut,
  1857             KMPXBackLightTimeOut,
  1818             TCallBack( CMPXVideoPlaybackController::HandleBackLightTimout, this ));
  1858             TCallBack( CMPXVideoPlaybackController::HandleBackLightTimeout, this ));
  1819     }
  1859     }
       
  1860     
  1820 }
  1861 }
  1821 
  1862 
  1822 // -------------------------------------------------------------------------------------------------
  1863 // -------------------------------------------------------------------------------------------------
  1823 // Handle back light timer timeout callback
  1864 // Handle back light timer timeout callback
  1824 // -------------------------------------------------------------------------------------------------
  1865 // -------------------------------------------------------------------------------------------------
  1825 //
  1866 //
  1826 TInt CMPXVideoPlaybackController::HandleBackLightTimout( TAny* aPtr )
  1867 TInt CMPXVideoPlaybackController::HandleBackLightTimeout( TAny* aPtr )
  1827 {
  1868 {
  1828     static_cast<CMPXVideoPlaybackController*>(aPtr)->DoHandleBackLightTimout();
  1869     static_cast<CMPXVideoPlaybackController*>(aPtr)->DoHandleBackLightTimeout();
  1829     return KErrNone;
  1870     return KErrNone;
  1830 }
  1871 }
  1831 
  1872 
  1832 // -------------------------------------------------------------------------------------------------
  1873 // -------------------------------------------------------------------------------------------------
  1833 // Handle back light timer timeout
  1874 // Handle back light timer timeout
  1834 // -------------------------------------------------------------------------------------------------
  1875 // -------------------------------------------------------------------------------------------------
  1835 //
  1876 //
  1836 void CMPXVideoPlaybackController::DoHandleBackLightTimout()
  1877 void CMPXVideoPlaybackController::DoHandleBackLightTimeout()
  1837 {
  1878 {
  1838     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::DoHandleBackLightTimout()"));
  1879     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::DoHandleBackLightTimeout()"));
  1839 
  1880     
       
  1881     TBool tvOutConnected( EFalse );
       
  1882     if ( iAccessoryMonitor )
       
  1883     {
       
  1884         tvOutConnected = iAccessoryMonitor->IsTvOutConnected();
       
  1885     }
       
  1886     
       
  1887     // User activity timer runs always when TV-out is connected
       
  1888     // it keeps resetting display timer and keeps lights on whenever there is user activity
       
  1889     if ( tvOutConnected )
       
  1890     {
       
  1891         MPX_DEBUG ( _L("CMPXVideoPlaybackController::DoHandleBackLightTimeout() inactivity time = %d"), User::InactivityTime().Int() );
       
  1892         // Cancel activity timer. Otherwise resetting inactivity time would fire user activity detection
       
  1893         CancelUserActivityTimer();
       
  1894     }
       
  1895         
  1840     User::ResetInactivityTime();
  1896     User::ResetInactivityTime();
       
  1897     
       
  1898     if ( tvOutConnected )
       
  1899     {
       
  1900         // Restart user activity timer. It must be running between backlight timer intervals so that backlight
       
  1901         // can be turned on if user activity is detected.
       
  1902         RestartUserActivityTimer();
       
  1903     }
       
  1904 }
       
  1905 
       
  1906 // -----------------------------------------------------------------------------
       
  1907 // CMPXVideoPlaybackController::StartLightsControl
       
  1908 // -----------------------------------------------------------------------------
       
  1909 //
       
  1910 void CMPXVideoPlaybackController::StartLightsControl()
       
  1911 {
       
  1912     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::StartLightsControl()"));
       
  1913 
       
  1914     StartBackLightTimer();
       
  1915              
       
  1916     if (iAccessoryMonitor )
       
  1917     {
       
  1918         if ( iAccessoryMonitor->IsTvOutConnected() )
       
  1919         {
       
  1920             RestartDisplayTimer();
       
  1921         }
       
  1922     }
       
  1923 }
       
  1924 
       
  1925 // -----------------------------------------------------------------------------
       
  1926 // CMPXVideoPlaybackController::CancelLightsControl
       
  1927 // -----------------------------------------------------------------------------
       
  1928 //
       
  1929 void CMPXVideoPlaybackController::CancelLightsControl()
       
  1930 {
       
  1931     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::CancelLightsControl()"));
       
  1932 	
       
  1933     // This is called whenever there is no need to keep screensaver of anymore
       
  1934     // This means that also displaytimer and activity monitoring can be stopped. 
       
  1935     // This method is not correct place for these calls
       
  1936     CancelBackLightTimer();
       
  1937    
       
  1938     CancelUserActivityTimer();
       
  1939     
       
  1940     CancelDisplayTimer();
       
  1941 	
       
  1942     // Ensure that lights are on
       
  1943     EnableDisplayBacklight();
       
  1944     
       
  1945 	// Release lights if releserved
       
  1946     ReleaseLights();  
       
  1947 }
       
  1948 
       
  1949 
       
  1950 // -----------------------------------------------------------------------------
       
  1951 // CMPXVideoPlaybackController::InitDisplayTimerL
       
  1952 // -----------------------------------------------------------------------------
       
  1953 //
       
  1954 TTimeIntervalMicroSeconds32 CMPXVideoPlaybackController::InitDisplayTimerL()
       
  1955 {
       
  1956     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::InitDisplayTimerL()"));
       
  1957 	
       
  1958     if ( !iDisplayTimer )
       
  1959     {
       
  1960         iDisplayTimer = CPeriodic::NewL( CPeriodic::EPriorityStandard );
       
  1961 		
       
  1962         MPX_DEBUG(_L("CMPXVideoPlaybackController::InitDisplayTimerL() - created") );	
       
  1963         
       
  1964     }
       
  1965    
       
  1966     if ( iDisplayTimerTimeout.Int() == 0 )
       
  1967     {
       
  1968         // Get the display light time-out value from CenRep
       
  1969         CRepository* repository = CRepository::NewLC( KCRUidLightSettings  );    
       
  1970         // What's the timeout value (in seconds ) for the display light?
       
  1971         TInt displayTimeOut ( 0 );
       
  1972         repository->Get( KDisplayLightsTimeout, displayTimeOut );
       
  1973         
       
  1974         if ( ( displayTimeOut * KMPXMicroSecondsInASecond ) > KMaxTInt )
       
  1975         {
       
  1976             iDisplayTimerTimeout = KMaxTInt;
       
  1977         }
       
  1978         else
       
  1979         {
       
  1980             iDisplayTimerTimeout = displayTimeOut * KMPXMicroSecondsInASecond;
       
  1981         }
       
  1982         
       
  1983         CleanupStack::PopAndDestroy( repository );
       
  1984     }     
       
  1985     
       
  1986     
       
  1987     MPX_DEBUG( _L("CMPXVideoPlaybackController::InitDisplayTimerL Timeout(%d)"), iDisplayTimerTimeout.Int() );
       
  1988 	
       
  1989     // Convert the timeout value to microseconds
       
  1990     return iDisplayTimerTimeout;   
       
  1991 }
       
  1992 
       
  1993 // -----------------------------------------------------------------------------
       
  1994 // CMPXVideoPlaybackController::RestartDisplayTimer
       
  1995 // -----------------------------------------------------------------------------
       
  1996 //
       
  1997 void CMPXVideoPlaybackController::RestartDisplayTimer()
       
  1998 {
       
  1999     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::RestartDisplayTimer"));
       
  2000 
       
  2001     TTimeIntervalMicroSeconds32 displayTimeOut(0);
       
  2002     // Leave system to safe state if following leaves. Lights stay on
       
  2003     MPX_TRAPD(err, displayTimeOut=InitDisplayTimerL(); )
       
  2004     if ( err == KErrNone )
       
  2005     {   
       
  2006         // check if the display timer is running and cancel it
       
  2007         if ( iDisplayTimer->IsActive() )
       
  2008         {
       
  2009             iDisplayTimer->Cancel();
       
  2010         }
       
  2011       
       
  2012         MPX_DEBUG( _L("CMPXVideoPlaybackController::RestartDisplayTimer() restarting displayTimer to=%d ms"), displayTimeOut.Int() );
       
  2013         
       
  2014         iDisplayTimer->Start( displayTimeOut, displayTimeOut,
       
  2015             TCallBack( CMPXVideoPlaybackController::HandleDisplayTimeout, this ) );
       
  2016     }
       
  2017     
       
  2018 }
       
  2019 
       
  2020 // -----------------------------------------------------------------------------
       
  2021 // CMPXVideoPlaybackController::CancelDisplayTimer
       
  2022 // -----------------------------------------------------------------------------
       
  2023 //
       
  2024 void CMPXVideoPlaybackController::CancelDisplayTimer() 
       
  2025 {
       
  2026     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::CancelDisplayTimer"));
       
  2027     
       
  2028     if ( iDisplayTimer )
       
  2029     {
       
  2030         if ( iDisplayTimer->IsActive() )
       
  2031         {
       
  2032             iDisplayTimer->Cancel();
       
  2033         }
       
  2034         delete iDisplayTimer;
       
  2035         iDisplayTimer = NULL;
       
  2036     }
       
  2037 }
       
  2038 
       
  2039 // -------------------------------------------------------------------------------------------------
       
  2040 //   CMPXVideoPlaybackUserInputHandler::HandleDisplayTimeout
       
  2041 // -------------------------------------------------------------------------------------------------
       
  2042 //
       
  2043 TInt CMPXVideoPlaybackController::HandleDisplayTimeout( TAny* aPtr )
       
  2044 {
       
  2045     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::HandleDisplayTimeout"));
       
  2046 
       
  2047     static_cast<CMPXVideoPlaybackController*>(aPtr)->DoHandleDisplayTimeout();
       
  2048 
       
  2049     return KErrNone;
       
  2050 }
       
  2051 
       
  2052 // -------------------------------------------------------------------------------------------------
       
  2053 //   CMPXVideoPlaybackUserInputHandler::DoHandleDisplayTimeout
       
  2054 // -------------------------------------------------------------------------------------------------
       
  2055 //
       
  2056 void CMPXVideoPlaybackController::DoHandleDisplayTimeout( )
       
  2057 {
       
  2058     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::DoHandleDisplayTimeout"));
       
  2059 
       
  2060     DisableDisplayBacklight();
       
  2061     // Avoid missing user activity immediately after lights are turned off
       
  2062     RestartUserActivityTimer();
       
  2063 }
       
  2064 
       
  2065 
       
  2066 
       
  2067 //  ------------------------------------------------------------------------------------------------
       
  2068 //  CMPXVideoPlaybackController::EnableDisplayBacklight
       
  2069 //  ------------------------------------------------------------------------------------------------
       
  2070 // 
       
  2071 void CMPXVideoPlaybackController::EnableDisplayBacklight()
       
  2072 {
       
  2073     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::EnableDisplayBacklight()"));
       
  2074     
       
  2075     // ELightStatusUnknown - We are not controlling lights and we don't care about lights
       
  2076     // ELightOn            - Ligths are certainly on 
       
  2077     MPX_DEBUG(_L("CMPXVideoPlaybackController::EnableDisplayBacklight() iLightStatus=%d"), iLightStatus );
       
  2078     
       
  2079     // We are responsible of turning lights on only if we have switched them off.
       
  2080     if ( iLightStatus == CHWRMLight::ELightOff )
       
  2081     {
       
  2082 
       
  2083         MPX_TRAPD( err,
       
  2084         {   
       
  2085             // Following GetLightsL() call will not leave.
       
  2086             // This call should not result to creation of CHWRMLight in this case
       
  2087             // because CHWRMLight was created when lights were turned off.
       
  2088             CHWRMLight* lights= GetLightsL();
       
  2089             if ( lights->LightStatus(CHWRMLight::EPrimaryDisplay) == CHWRMLight::ELightOff )
       
  2090             {
       
  2091                 MPX_DEBUG(_L("CMPXVideoPlaybackController::EnableDisplayBacklight() enabling") );
       
  2092 			
       
  2093                 lights->LightOnL( CHWRMLight::EPrimaryDisplay, 0  );
       
  2094                 iLightStatus = CHWRMLight::ELightOn;
       
  2095             }
       
  2096         } );
       
  2097         
       
  2098     }
       
  2099    
       
  2100 }
       
  2101 
       
  2102 //  ------------------------------------------------------------------------------------------------
       
  2103 //  CMPXVideoPlaybackController::DisableDisplayBacklight
       
  2104 //  ------------------------------------------------------------------------------------------------
       
  2105 // 
       
  2106 void CMPXVideoPlaybackController::DisableDisplayBacklight()
       
  2107 {
       
  2108     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::DisableDisplayBacklight()"));
       
  2109        
       
  2110     // No major harm done if following block leaves. Lights are left on
       
  2111     MPX_TRAPD( err,
       
  2112     {  
       
  2113         CHWRMLight* lights = GetLightsL();
       
  2114         if ( lights->LightStatus(CHWRMLight::EPrimaryDisplay) == CHWRMLight::ELightOn )
       
  2115         {
       
  2116            MPX_DEBUG(_L("CMPXVideoPlaybackController::DisableDisplayBacklight() disabling") );
       
  2117 		   
       
  2118            lights->LightOffL( CHWRMLight::EPrimaryDisplay, 0  );
       
  2119            iLightStatus = CHWRMLight::ELightOff;
       
  2120         }
       
  2121     } );
       
  2122    
       
  2123 }
       
  2124 
       
  2125 
       
  2126 //  ------------------------------------------------------------------------------------------------
       
  2127 //  CMPXVideoPlaybackController::InitUserActivityTimer
       
  2128 //  ------------------------------------------------------------------------------------------------
       
  2129 // 
       
  2130 void CMPXVideoPlaybackController::InitUserActivityTimerL()
       
  2131 {
       
  2132     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::InitUserActivityTimerL()"));
       
  2133     
       
  2134     iUserActivityTimer = CPeriodic::NewL( CActive::EPriorityStandard);
       
  2135     
       
  2136     // This timer will not run to the end. Timer will be canceled and reset at backlight timeout.    
       
  2137     iUserActivityTimer->Start(
       
  2138         0,
       
  2139         KMPXInactivityTimeout,
       
  2140         TCallBack( CMPXVideoPlaybackController::HandleUserActivityTimeout, this ));
       
  2141     
       
  2142 }
       
  2143 
       
  2144 //  ------------------------------------------------------------------------------------------------
       
  2145 //  CMPXVideoPlaybackController::RestartUserActivityTimer
       
  2146 //  ------------------------------------------------------------------------------------------------
       
  2147 // 
       
  2148 void CMPXVideoPlaybackController::RestartUserActivityTimer() 
       
  2149 {
       
  2150     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::RestartUserActivityTimer()"));
       
  2151     
       
  2152     if ( !iUserActivityTimer )
       
  2153     {
       
  2154        // This is first call. Create and initialize timer
       
  2155        MPX_TRAPD( err,
       
  2156        {   
       
  2157            InitUserActivityTimerL();
       
  2158        } );
       
  2159        // If user activity timer creation fails we can't detect user activity and 
       
  2160        // get lights back on when user taps screen. 
       
  2161        // Leave lights on.
       
  2162        if ( err != KErrNone )
       
  2163        { 
       
  2164            EnableDisplayBacklight(); 
       
  2165        }  
       
  2166     }
       
  2167       
       
  2168     if ( iUserActivityTimer )
       
  2169     {
       
  2170         if ( iUserActivityTimer->IsActive() )
       
  2171         {
       
  2172             iUserActivityTimer->Cancel();
       
  2173         }            
       
  2174         // Not interested about inactivity callback, only activity
       
  2175         // If CPeriodic::Inactivity is started with argument 0 
       
  2176         // timer will fire when system's user inactivity timer resets.
       
  2177         iUserActivityTimer->Inactivity( 0 );
       
  2178     } 
       
  2179 }
       
  2180 
       
  2181 //  ------------------------------------------------------------------------------------------------
       
  2182 //  CMPXVideoPlaybackController::CancelUserActivityTimer
       
  2183 //  ------------------------------------------------------------------------------------------------
       
  2184 // 
       
  2185 void CMPXVideoPlaybackController::CancelUserActivityTimer() 
       
  2186 {
       
  2187     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::CancelUserActivityTimer()"));
       
  2188 	
       
  2189     if  ( iUserActivityTimer ) 
       
  2190     {   
       
  2191         if ( iUserActivityTimer->IsActive() )
       
  2192         {
       
  2193             iUserActivityTimer->Cancel();
       
  2194         }
       
  2195     }
       
  2196 }
       
  2197 
       
  2198 //  ------------------------------------------------------------------------------------------------
       
  2199 //  CMPXVideoPlaybackController::HandleUserActivityTimeout
       
  2200 //  ------------------------------------------------------------------------------------------------
       
  2201 // 
       
  2202 TInt CMPXVideoPlaybackController::HandleUserActivityTimeout( TAny* aPtr )
       
  2203 {
       
  2204     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::HandleUserActivityTimeout()"));
       
  2205 	
       
  2206     static_cast<CMPXVideoPlaybackController*>(aPtr)->DoHandleUserActivityTimeout();
       
  2207     return KErrNone;     
       
  2208 }
       
  2209 
       
  2210 //  ------------------------------------------------------------------------------------------------
       
  2211 //  CMPXVideoPlaybackController::DoHandleUserActivityTimeout
       
  2212 //  ------------------------------------------------------------------------------------------------
       
  2213 // 
       
  2214 void CMPXVideoPlaybackController::DoHandleUserActivityTimeout()
       
  2215 {
       
  2216     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::DoHandleUserActivityTimeout()"));
       
  2217     
       
  2218     // Act only once for detected activity.
       
  2219     if ( iUserActivityTimer->IsActive() ) 
       
  2220     {
       
  2221         iUserActivityTimer->Cancel();
       
  2222     }
       
  2223     
       
  2224     // iUserActivityTimer runs when TV-out is connected and playback with video is going on
       
  2225     // This timer fires in two situations. 
       
  2226     // a) Lights are off and user activity is detected - Turn lights on and restart display timer
       
  2227     // b) Lights are on and user activity is detected - restart display timer to prevent lights go off
       
  2228     EnableDisplayBacklight();
       
  2229     
       
  2230     // Start counting down to next lights off
       
  2231     RestartDisplayTimer();
       
  2232 }
       
  2233 
       
  2234 //  ------------------------------------------------------------------------------------------------
       
  2235 //  CMPXVideoPlaybackController::GetLightsL
       
  2236 //  ------------------------------------------------------------------------------------------------
       
  2237 //
       
  2238 CHWRMLight* CMPXVideoPlaybackController::GetLightsL()
       
  2239 {
       
  2240     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::GetLightsL()"));
       
  2241 	
       
  2242     if ( !iLight ) 
       
  2243     {
       
  2244         MPX_DEBUG( _L("CMPXVideoPlaybackController::GetLightsL() - creating") );
       
  2245         iLight = CHWRMLight::NewL();
       
  2246     }
       
  2247     return iLight;
       
  2248 }
       
  2249 
       
  2250 //  ------------------------------------------------------------------------------------------------
       
  2251 //  CMPXVideoPlaybackController::ReleaseLights
       
  2252 //  ------------------------------------------------------------------------------------------------
       
  2253 //
       
  2254 void CMPXVideoPlaybackController::ReleaseLights()
       
  2255 {
       
  2256     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::ReleaseLights()"));
       
  2257 	
       
  2258     if ( iLight )
       
  2259     {
       
  2260         // If iLights was created when ReleaseLights was called then TV out must be connected and lights may be off. 
       
  2261         // This call ensures that lights are on again.
       
  2262         EnableDisplayBacklight();
       
  2263 		
       
  2264         MPX_DEBUG( _L("CMPXVideoPlaybackController::ReleaseLights() - deleting") );
       
  2265         delete iLight;
       
  2266         iLight = NULL;
       
  2267     }
  1841 }
  2268 }
  1842 
  2269 
  1843 // -------------------------------------------------------------------------------------------------
  2270 // -------------------------------------------------------------------------------------------------
  1844 // CMPXVideoPlaybackController::InitVolumeWatchers()
  2271 // CMPXVideoPlaybackController::InitVolumeWatchers()
  1845 // -------------------------------------------------------------------------------------------------
  2272 // -------------------------------------------------------------------------------------------------
  1846 //
  2273 //
  1847 void CMPXVideoPlaybackController::InitVolumeWatchers()
  2274 void CMPXVideoPlaybackController::InitVolumeWatchersL()
  1848 {
  2275 {
  1849     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::InitVolumeWatchers()"));
  2276     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::InitVolumeWatchers()"));
  1850 
  2277 
  1851     if ( ! iVolumeWatcher )
  2278     if ( ! iVolumeWatcher )
  1852     {
  2279     {
  1853         MPX_TRAPD( err,
  2280         iVolumeWatcher = CMPXCenRepWatcher::NewL( KCRUidMPXVideoSettings,
  1854                 iVolumeWatcher = CMPXCenRepWatcher::NewL( KCRUidMPXVideoSettings,
  2281                                                   KMPXVideoPlaybackVolume,
  1855                                                           KMPXVideoPlaybackVolume,
  2282                                                   this );
  1856                                                           this ) );
       
  1857     }
  2283     }
  1858 
  2284 
  1859     if ( ! iMuteWatcher )
  2285     if ( ! iMuteWatcher )
  1860     {
  2286     {
  1861         MPX_TRAPD( err,
  2287         iMuteWatcher = CMPXCenRepWatcher::NewL( KCRUidMPXVideoSettings,
  1862                 iMuteWatcher = CMPXCenRepWatcher::NewL( KCRUidMPXVideoSettings,
  2288                                                 KMPXVideoPlaybackMute,
  1863                                                         KMPXVideoPlaybackMute,
  2289                                                 this );
  1864                                                         this ) );
       
  1865     }
  2290     }
  1866 
  2291 
  1867     //
  2292     //
  1868     // MPX framework volume range : 0-100
  2293     // MPX framework volume range : 0-100
  1869     // Media player volume range : 0-10
  2294     // Media player volume range : 0-10
  1914     //
  2339     //
  1915     // Delete the video accessory observer when the plugin
  2340     // Delete the video accessory observer when the plugin
  1916     // goes back to Not Initialised state.
  2341     // goes back to Not Initialised state.
  1917     //
  2342     //
  1918     if ( iAccessoryMonitor )
  2343     if ( iAccessoryMonitor )
  1919     {    
  2344     {
  1920         delete iAccessoryMonitor;
  2345         delete iAccessoryMonitor;
  1921         iAccessoryMonitor = NULL;
  2346         iAccessoryMonitor = NULL;
  1922     }
  2347     }
  1923 
  2348 
  1924     if ( iFileDetails )
  2349     if ( iFileDetails )
  1963 
  2388 
  1964     //
  2389     //
  1965     //  Reset the flag to retrieve the Buffering percentage from Helix
  2390     //  Reset the flag to retrieve the Buffering percentage from Helix
  1966     //
  2391     //
  1967     iHelixLoadingStarted = EFalse;
  2392     iHelixLoadingStarted = EFalse;
       
  2393 
       
  2394     iSavedPosition = 0;
  1968 }
  2395 }
  1969 
  2396 
  1970 //  ------------------------------------------------------------------------------------------------
  2397 //  ------------------------------------------------------------------------------------------------
  1971 //  CMPXVideoPlaybackController::HandleVolumeL
  2398 //  CMPXVideoPlaybackController::HandleVolumeL
  1972 //  ------------------------------------------------------------------------------------------------
  2399 //  ------------------------------------------------------------------------------------------------
  2020 //    CMPXVideoPlaybackController::OpenFile64L()
  2447 //    CMPXVideoPlaybackController::OpenFile64L()
  2021 //  ------------------------------------------------------------------------------------------------
  2448 //  ------------------------------------------------------------------------------------------------
  2022 //
  2449 //
  2023 void CMPXVideoPlaybackController::OpenFile64L( const TDesC& aMediaFile,
  2450 void CMPXVideoPlaybackController::OpenFile64L( const TDesC& aMediaFile,
  2024                                                RFile64& aFile,
  2451                                                RFile64& aFile,
       
  2452                                                TInt aPosition,
  2025                                                TInt aAccessPointId )
  2453                                                TInt aAccessPointId )
  2026 {
  2454 {
  2027     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::OpenFile64L( RFile64 )"),
  2455     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::OpenFile64L( RFile64 )"),
  2028                    _L("file = %S"), &aMediaFile );
  2456                    _L("file = %S, position = %d"), &aMediaFile, aPosition );
  2029 
  2457 
  2030     TBool fileExists = EFalse;
  2458     TBool fileExists = EFalse;
  2031 
  2459 
  2032     ChangeState( EMPXVideoInitializing );
  2460     ChangeState( EMPXVideoInitializing );
  2033 
  2461 
  2050     }
  2478     }
  2051 
  2479 
  2052     DetermineMediaTypeL();
  2480     DetermineMediaTypeL();
  2053     SetPlaybackModeL();
  2481     SetPlaybackModeL();
  2054 
  2482 
       
  2483     iSavedPosition = aPosition; 
       
  2484     
  2055     //
  2485     //
  2056     //  Create accessory monitor to search for TV-Out events
  2486     //  Create accessory monitor to search for TV-Out events
  2057     //
  2487     //
  2058     if ( ! iAccessoryMonitor )
  2488     if ( ! iAccessoryMonitor )
  2059     {
  2489     {