videoplayback/videohelix/src/mpxvideoplaybackcontroller.cpp
changeset 34 bbb98528c666
parent 30 4f111d64a341
child 35 3738fe97f027
equal deleted inserted replaced
33:48e74db5d516 34:bbb98528c666
    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: 43 %
    18 // Version : %version: ou1cpsw#49 %
    19 
    19 
    20 
    20 
    21 //
    21 //
    22 //  INCLUDE FILES
    22 //  INCLUDE FILES
    23 //
    23 //
    36 
    36 
    37 #include <coreapplicationuisdomainpskeys.h>
    37 #include <coreapplicationuisdomainpskeys.h>
    38 #include <ctsydomainpskeys.h>
    38 #include <ctsydomainpskeys.h>
    39 #include <mmf/common/mmferrors.h>
    39 #include <mmf/common/mmferrors.h>
    40 
    40 
    41 #include <hal.h>
       
    42 #include <hal_data.h>
       
    43 #include <e32std.h>
    41 #include <e32std.h>
    44 #include <devsoundif.h>
    42 #include <devsoundif.h>
       
    43 #include <avkondomainpskeys.h>
       
    44 #include <hwrmlight.h>  
       
    45 #include <centralrepository.h>  // For display timeout setting
       
    46 #include <hwrmlightdomaincrkeys.h>
    45 
    47 
    46 #include "mpxvideoregion.h"
    48 #include "mpxvideoregion.h"
    47 #include "mpxvideoplaybackcontroller.h"
    49 #include "mpxvideoplaybackcontroller.h"
    48 #include "mpxvideoplaybackstate.h"
    50 #include "mpxvideoplaybackstate.h"
    49 #include "mpxvideoprivatecrkeys.h"
    51 #include "mpxvideoprivatecrkeys.h"
    60 #define KMAXMIMETYPELENGTH 256
    62 #define KMAXMIMETYPELENGTH 256
    61 
    63 
    62 //
    64 //
    63 //  Backlight Timeout in Micro Seconds
    65 //  Backlight Timeout in Micro Seconds
    64 //
    66 //
    65 #define KMPXBackLightTimeOut 3500000
    67 const TInt KMPXBackLightTimeOut = 3500000;
       
    68 const TInt KMPXInactivityTimeout  = 3 * KMPXBackLightTimeOut;
       
    69 const TInt KMPXMicroSecondsInASecond = 1000000;
    66 
    70 
    67 #define KOneKilobyte 1024
    71 #define KOneKilobyte 1024
    68 
    72 
    69 _LIT( KTitle, "Title" );
    73 _LIT( KTitle, "Title" );
    70 _LIT( KLiveStream, "LiveStream" );
    74 _LIT( KLiveStream, "LiveStream" );
   143 void CMPXVideoPlaybackController::ConstructL( MMPXPlaybackPluginObserver& aObs )
   147 void CMPXVideoPlaybackController::ConstructL( MMPXPlaybackPluginObserver& aObs )
   144 {
   148 {
   145     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::ConstructL()"));
   149     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::ConstructL()"));
   146 
   150 
   147     iMPXPluginObs = &aObs;
   151     iMPXPluginObs = &aObs;
   148     iAccessPointId = -1;
   152     iAccessPointId = KUseDefaultIap;
   149     iVideoSeeker = CMPXVideoSeeker::NewL( this );
   153     iVideoSeeker = CMPXVideoSeeker::NewL( this );
   150 
   154 
   151     // Initiliaze to True
   155     // Initiliaze to True
   152     iSeekable = ETrue;
   156     iSeekable = ETrue;
   153 
   157 
   154     InitVolumeWatchers();
   158     InitVolumeWatchersL();
   155 
   159 
   156     CreatePreInitStatesL();
   160     CreatePreInitStatesL();
   157 
   161 
   158     iPlayer = CMpxVideoPlayerUtility::NewL( this );
   162     iPlayer = CMpxVideoPlayerUtility::NewL( this );
   159 
   163 
   160     iBackLightTimer = CPeriodic::NewL( CActive::EPriorityStandard );
   164     iBackLightTimer = CPeriodic::NewL( CActive::EPriorityStandard );
   161 
   165 
   162     iDrmHelper = CMpxVideoDrmHelper::NewL();
   166     iDrmHelper = CMpxVideoDrmHelper::NewL();
       
   167     
       
   168     iSavedPosition = 0;
   163 }
   169 }
   164 
   170 
   165 //  ----------------------------------------------------------------------------
   171 //  ----------------------------------------------------------------------------
   166 //  CMPXVideoPlaybackController::CloseController()
   172 //  CMPXVideoPlaybackController::CloseController()
   167 //  ----------------------------------------------------------------------------
   173 //  ----------------------------------------------------------------------------
   168 //
   174 //
   169 void CMPXVideoPlaybackController::CloseController()
   175 void CMPXVideoPlaybackController::CloseController()
   170 {
   176 {
   171     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::CloseController()"));
   177     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::CloseController()"));
   172 
       
   173     ChangeState( EMPXVideoNotInitialized );
   178     ChangeState( EMPXVideoNotInitialized );
   174 }
   179 }
   175 
   180 
   176 //  ------------------------------------------------------------------------------------------------
   181 //  ------------------------------------------------------------------------------------------------
   177 //    CMPXVideoPlaybackController::OpenFileL()
   182 //    CMPXVideoPlaybackController::OpenFileL()
   178 //  ------------------------------------------------------------------------------------------------
   183 //  ------------------------------------------------------------------------------------------------
   179 //
   184 //
   180 void CMPXVideoPlaybackController::OpenFileL( const TDesC& aMediaFile,
   185 void CMPXVideoPlaybackController::OpenFileL( const TDesC& aMediaFile,
   181                                              RFile& aFile,
   186                                              RFile& aFile,
   182                                              TInt aAccessPointId )
   187                                              TInt aPosition,
       
   188                                              TInt aAccessPointId ) 
   183 {
   189 {
   184     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::OpenFileL()"),
   190     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::OpenFileL()"),
   185                    _L("file = %S"), &aMediaFile );
   191                    _L("file = %S"), &aMediaFile );
   186 
   192 
   187     TBool fileExists = EFalse;
   193     TBool fileExists = EFalse;
   207     }
   213     }
   208 
   214 
   209     DetermineMediaTypeL();
   215     DetermineMediaTypeL();
   210     SetPlaybackModeL();
   216     SetPlaybackModeL();
   211 
   217 
       
   218     iSavedPosition = aPosition;
       
   219     
   212     //
   220     //
   213     //  Create accessory monitor to search for TV-Out events
   221     //  Create accessory monitor to search for TV-Out events
   214     //
   222     //
   215     if ( ! iAccessoryMonitor )
   223     if ( ! iAccessoryMonitor )
   216     {
   224     {
   256 CMPXVideoPlaybackController::CMPXVideoPlaybackController()
   264 CMPXVideoPlaybackController::CMPXVideoPlaybackController()
   257     : iAppInForeground(ETrue)
   265     : iAppInForeground(ETrue)
   258     , iForegroundPause(EFalse)
   266     , iForegroundPause(EFalse)
   259     , iAllowAutoPlay(ETrue)
   267     , iAllowAutoPlay(ETrue)
   260     , iHelixLoadingStarted(EFalse)
   268     , iHelixLoadingStarted(EFalse)
       
   269     , iLightStatus(CHWRMLight::ELightStatusUnknown)
   261 {
   270 {
   262 }
   271 }
   263 
   272 
   264 //  ----------------------------------------------------------------------------
   273 //  ----------------------------------------------------------------------------
   265 //    Destructor
   274 //    Destructor
   338     if ( iPlayer )
   347     if ( iPlayer )
   339     {
   348     {
   340         delete iPlayer;
   349         delete iPlayer;
   341         iPlayer = NULL;
   350         iPlayer = NULL;
   342     }
   351     }
       
   352    
       
   353     if ( iUserActivityTimer )
       
   354     {
       
   355         iUserActivityTimer->Cancel();
       
   356         delete iUserActivityTimer;
       
   357         iUserActivityTimer = NULL;
       
   358     }
       
   359     
       
   360     ReleaseLights();
       
   361     
       
   362     CancelDisplayTimer();
   343 
   363 
   344 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
   364 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
   345 
   365 
   346     if ( iFileHandle64.SubSessionHandle() )
   366     if ( iFileHandle64.SubSessionHandle() )
   347     {
   367     {
   521                 }
   541                 }
   522 
   542 
   523                 aCmd.SetTObjectValueL<TInt>( KMPXMediaVideoBufferingPercentage,
   543                 aCmd.SetTObjectValueL<TInt>( KMPXMediaVideoBufferingPercentage,
   524                                              bufferingPercentage );
   544                                              bufferingPercentage );
   525 
   545 
       
   546                 break;
       
   547             }
       
   548             case EPbCmdSurfaceRemoved:
       
   549             {
       
   550                 iPlayer->SurfaceRemovedFromView();
   526                 break;
   551                 break;
   527             }
   552             }
   528             default:
   553             default:
   529             {
   554             {
   530                 break;
   555                 break;
   973     {
   998     {
   974         switch ( aSettingId )
   999         switch ( aSettingId )
   975         {
  1000         {
   976             case KMPXVideoPlaybackMute:
  1001             case KMPXVideoPlaybackMute:
   977             {
  1002             {
       
  1003                 TInt muteValue( EFalse );
       
  1004 
       
  1005                 TRAP_IGNORE( muteValue = iMuteWatcher->CurrentValueL() );
       
  1006 
   978                 iMPXPluginObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPMuteChanged,
  1007                 iMPXPluginObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPMuteChanged,
   979                                                   iMuteWatcher->CurrentValueL(),
  1008                                                   muteValue,
   980                                                   KErrNone );
  1009                                                   KErrNone );
   981                 // fall through
  1010                 // fall through
   982             }
  1011             }
   983             case KMPXVideoPlaybackVolume:
  1012             case KMPXVideoPlaybackVolume:
   984             {
  1013             {
   985                 //
  1014                 //
   986                 //  this is the callback from cen-rep
  1015                 //  this is the callback from cen-rep
   987                 //  let the state decide if it needs to do something
  1016                 //  let the state decide if it needs to do something
   988                 //
  1017                 //
   989                 iState->HandleVolumeChange();
  1018                 iState->HandleVolumeChange();
   990                 break;
       
   991             }
       
   992             default:
       
   993             {
       
   994                 break;
  1019                 break;
   995             }
  1020             }
   996         }
  1021         }
   997     }
  1022     }
   998 }
  1023 }
  1184                 //  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
  1185                 //  start the backlight timer if needed
  1210                 //  start the backlight timer if needed
  1186                 //
  1211                 //
  1187                 if ( iFileDetails->iVideoEnabled )
  1212                 if ( iFileDetails->iVideoEnabled )
  1188                 {
  1213                 {
  1189                     StartBackLightTimer();
  1214                     StartLightsControl();
  1190                 }
  1215                 }
  1191                 else
  1216                 else
  1192                 {
  1217                 {
  1193                     CancelBackLightTimer();
  1218                     CancelLightsControl();
  1194                 }
  1219                 }
  1195                 
  1220                 
  1196                 break;
  1221                 break;
  1197             }
  1222             }
  1198             case EMPXVideoPaused:
  1223             case EMPXVideoPaused:
  1199             {
  1224             {
  1200                 iState = iPausedState;
  1225                 iState = iPausedState;
  1201                 CancelBackLightTimer();
  1226                 CancelLightsControl();
  1202                 break;
  1227                 break;
  1203             }
  1228             }
  1204             case EMPXVideoInitializing:
  1229             case EMPXVideoInitializing:
  1205             {
  1230             {
  1206                 iState = iInitialisingState;
  1231                 iState = iInitialisingState;
  1207                 StartBackLightTimer();
  1232                 StartLightsControl();
  1208                 break;
  1233                 break;
  1209             }
  1234             }
  1210             case EMPXVideoInitialized:
  1235             case EMPXVideoInitialized:
  1211             {
  1236             {
  1212                 iState = iInitialisedState;
  1237                 iState = iInitialisedState;
       
  1238                 StartLightsControl();
  1213                 break;
  1239                 break;
  1214             }
  1240             }
  1215             case EMPXVideoBuffering:
  1241             case EMPXVideoBuffering:
  1216             {
  1242             {
  1217                 iState = iBufferingState;
  1243                 iState = iBufferingState;
  1218                 StartBackLightTimer();
  1244                 StartLightsControl();
  1219                 break;
  1245                 break;
  1220             }
  1246             }
  1221             case EMPXVideoSeeking:
  1247             case EMPXVideoSeeking:
  1222             {
  1248             {
  1223                 iState = iSeekingState;
  1249                 iState = iSeekingState;
       
  1250                 StartLightsControl();
  1224                 break;
  1251                 break;
  1225             }
  1252             }
  1226             case EMPXVideoStopped:
  1253             case EMPXVideoStopped:
  1227             {
  1254             {
  1228                 iState = iStoppedState;
  1255                 iState = iStoppedState;
  1229                 CancelBackLightTimer();
  1256                 CancelLightsControl();
  1230                 break;
  1257                 break;
  1231             }
  1258             }
  1232             case EMPXVideoNotInitialized:
  1259             case EMPXVideoNotInitialized:
  1233             {
  1260             {
  1234                 ResetMemberVariables();
  1261                 ResetMemberVariables();
  1235                 iState = iNotIntialisedState;
  1262                 iState = iNotIntialisedState;
  1236                 CancelBackLightTimer();
  1263                 CancelLightsControl();
  1237                 break;
  1264                 break;
  1238             }
  1265             }
  1239         }
  1266         }
  1240     }
  1267     }
  1241 }
  1268 }
  1302     //
  1329     //
  1303     //  Max Volume
  1330     //  Max Volume
  1304     //
  1331     //
  1305     iFileDetails->iMaxVolume = iPlayer->MaxVolume();
  1332     iFileDetails->iMaxVolume = iPlayer->MaxVolume();
  1306 
  1333 
  1307     // 
  1334     //
  1308     //  FourCC Code
  1335     //  FourCC Code
  1309     //
  1336     //
  1310     iFileDetails->iFourCCCode  = iPlayer->FourCCCode();    
  1337     iFileDetails->iFourCCCode  = iPlayer->FourCCCode();
  1311     
  1338 
  1312     //
  1339     //
  1313     //  Mime Type
  1340     //  Mime Type
  1314     //
  1341     //
  1315     HBufC8* mimeType = HBufC8::NewL( KMAXMIMETYPELENGTH );
  1342     HBufC8* mimeType = HBufC8::NewL( KMAXMIMETYPELENGTH );
  1316     CleanupStack::PushL( mimeType );
  1343     CleanupStack::PushL( mimeType );
  1421             }
  1448             }
  1422             else if ( !metaData->Name().CompareF( KKeywords ) )
  1449             else if ( !metaData->Name().CompareF( KKeywords ) )
  1423             {
  1450             {
  1424                 iFileDetails->iKeywords = metaData->Value().AllocL();
  1451                 iFileDetails->iKeywords = metaData->Value().AllocL();
  1425             }
  1452             }
  1426             
  1453 
  1427             CleanupStack::PopAndDestroy( metaData );
  1454             CleanupStack::PopAndDestroy( metaData );
  1428         }
  1455         }
  1429 
  1456 
  1430         // Update the seek value for asx clips with the value
  1457         // Update the seek value for asx clips with the value
  1431         // received from the engine ( single item )
  1458         // received from the engine ( single item )
  1723 
  1750 
  1724     return alarm;
  1751     return alarm;
  1725 }
  1752 }
  1726 
  1753 
  1727 // -----------------------------------------------------------------------------
  1754 // -----------------------------------------------------------------------------
  1728 // CMPXVideoPlaybackController::IsDisplayOff
  1755 // CMPXVideoPlaybackController::IsKeyLocked
  1729 // -----------------------------------------------------------------------------
  1756 // -----------------------------------------------------------------------------
  1730 //
  1757 //
  1731 TBool CMPXVideoPlaybackController::IsDisplayOff()
  1758 TBool CMPXVideoPlaybackController::IsKeyLocked()
  1732 {
  1759 {
  1733     TBool displayState;
  1760     TBool keylock( EFalse );
  1734     HAL::Get( HALData::EDisplayState, displayState );
  1761     RProperty::Get( KPSUidAvkonDomain, KAknKeyguardStatus, keylock );
  1735 
  1762 
  1736     MPX_DEBUG(_L("CMPXVideoPlaybackController::IsDisplayOff(%d)"), !displayState);
  1763     MPX_DEBUG(_L("CMPXVideoPlaybackController::IsKeyLocked(%d)"), keylock);
  1737 
  1764 
  1738     return !displayState;
  1765     return keylock;
  1739 }
  1766 }
  1740 
  1767 
  1741 //  ------------------------------------------------------------------------------------------------
  1768 //  ------------------------------------------------------------------------------------------------
  1742 //    CMPXVideoPlaybackController::HandleTvOutEventL()
  1769 //    CMPXVideoPlaybackController::HandleTvOutEventL()
  1743 //  ------------------------------------------------------------------------------------------------
  1770 //  ------------------------------------------------------------------------------------------------
  1764 
  1791 
  1765             playbackAllowed = EFalse;
  1792             playbackAllowed = EFalse;
  1766 
  1793 
  1767             iState->SendErrorToViewL( KMPXVideoTvOutPlaybackNotAllowed );
  1794             iState->SendErrorToViewL( KMPXVideoTvOutPlaybackNotAllowed );
  1768         }
  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();
  1769     }
  1812     }
  1770 
  1813 
  1771     //
  1814     //
  1772     //  Send notice to the playback view with TV-Out connection status
  1815     //  Send notice to the playback view with TV-Out connection status
  1773     //  and TV-Out playback allowed flag
  1816     //  and TV-Out playback allowed flag
  1795 
  1838 
  1796     if ( iBackLightTimer->IsActive() )
  1839     if ( iBackLightTimer->IsActive() )
  1797     {
  1840     {
  1798         iBackLightTimer->Cancel();
  1841         iBackLightTimer->Cancel();
  1799     }
  1842     }
       
  1843     
  1800 }
  1844 }
  1801 
  1845 
  1802 //  ------------------------------------------------------------------------------------------------
  1846 //  ------------------------------------------------------------------------------------------------
  1803 //    CMPXVideoPlaybackState::StartBackLightTimer
  1847 //    CMPXVideoPlaybackState::StartBackLightTimer
  1804 //  ------------------------------------------------------------------------------------------------
  1848 //  ------------------------------------------------------------------------------------------------
  1809     if ( !iBackLightTimer->IsActive() )
  1853     if ( !iBackLightTimer->IsActive() )
  1810     {
  1854     {
  1811         iBackLightTimer->Start(
  1855         iBackLightTimer->Start(
  1812             0,
  1856             0,
  1813             KMPXBackLightTimeOut,
  1857             KMPXBackLightTimeOut,
  1814             TCallBack( CMPXVideoPlaybackController::HandleBackLightTimout, this ));
  1858             TCallBack( CMPXVideoPlaybackController::HandleBackLightTimeout, this ));
  1815     }
  1859     }
       
  1860     
  1816 }
  1861 }
  1817 
  1862 
  1818 // -------------------------------------------------------------------------------------------------
  1863 // -------------------------------------------------------------------------------------------------
  1819 // Handle back light timer timeout callback
  1864 // Handle back light timer timeout callback
  1820 // -------------------------------------------------------------------------------------------------
  1865 // -------------------------------------------------------------------------------------------------
  1821 //
  1866 //
  1822 TInt CMPXVideoPlaybackController::HandleBackLightTimout( TAny* aPtr )
  1867 TInt CMPXVideoPlaybackController::HandleBackLightTimeout( TAny* aPtr )
  1823 {
  1868 {
  1824     static_cast<CMPXVideoPlaybackController*>(aPtr)->DoHandleBackLightTimout();
  1869     static_cast<CMPXVideoPlaybackController*>(aPtr)->DoHandleBackLightTimeout();
  1825     return KErrNone;
  1870     return KErrNone;
  1826 }
  1871 }
  1827 
  1872 
  1828 // -------------------------------------------------------------------------------------------------
  1873 // -------------------------------------------------------------------------------------------------
  1829 // Handle back light timer timeout
  1874 // Handle back light timer timeout
  1830 // -------------------------------------------------------------------------------------------------
  1875 // -------------------------------------------------------------------------------------------------
  1831 //
  1876 //
  1832 void CMPXVideoPlaybackController::DoHandleBackLightTimout()
  1877 void CMPXVideoPlaybackController::DoHandleBackLightTimeout()
  1833 {
  1878 {
  1834     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::DoHandleBackLightTimout()"));
  1879     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::DoHandleBackLightTimeout()"));
  1835 
  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         
  1836     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     }
  1837 }
  2268 }
  1838 
  2269 
  1839 // -------------------------------------------------------------------------------------------------
  2270 // -------------------------------------------------------------------------------------------------
  1840 // CMPXVideoPlaybackController::InitVolumeWatchers()
  2271 // CMPXVideoPlaybackController::InitVolumeWatchers()
  1841 // -------------------------------------------------------------------------------------------------
  2272 // -------------------------------------------------------------------------------------------------
  1842 //
  2273 //
  1843 void CMPXVideoPlaybackController::InitVolumeWatchers()
  2274 void CMPXVideoPlaybackController::InitVolumeWatchersL()
  1844 {
  2275 {
  1845     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::InitVolumeWatchers()"));
  2276     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::InitVolumeWatchers()"));
  1846 
  2277 
  1847     if ( ! iVolumeWatcher )
  2278     if ( ! iVolumeWatcher )
  1848     {
  2279     {
  1849         MPX_TRAPD( err,
  2280         iVolumeWatcher = CMPXCenRepWatcher::NewL( KCRUidMPXVideoSettings,
  1850                 iVolumeWatcher = CMPXCenRepWatcher::NewL( KCRUidMPXVideoSettings,
  2281                                                   KMPXVideoPlaybackVolume,
  1851                                                           KMPXVideoPlaybackVolume,
  2282                                                   this );
  1852                                                           this ) );
       
  1853     }
  2283     }
  1854 
  2284 
  1855     if ( ! iMuteWatcher )
  2285     if ( ! iMuteWatcher )
  1856     {
  2286     {
  1857         MPX_TRAPD( err,
  2287         iMuteWatcher = CMPXCenRepWatcher::NewL( KCRUidMPXVideoSettings,
  1858                 iMuteWatcher = CMPXCenRepWatcher::NewL( KCRUidMPXVideoSettings,
  2288                                                 KMPXVideoPlaybackMute,
  1859                                                         KMPXVideoPlaybackMute,
  2289                                                 this );
  1860                                                         this ) );
       
  1861     }
  2290     }
  1862 
  2291 
  1863     //
  2292     //
  1864     // MPX framework volume range : 0-100
  2293     // MPX framework volume range : 0-100
  1865     // Media player volume range : 0-10
  2294     // Media player volume range : 0-10
  1905 {
  2334 {
  1906     MPX_ENTER_EXIT( _L("CMPXVideoPlaybackController::ResetMemberVariables()"));
  2335     MPX_ENTER_EXIT( _L("CMPXVideoPlaybackController::ResetMemberVariables()"));
  1907 
  2336 
  1908     iPlayer->Reset();
  2337     iPlayer->Reset();
  1909 
  2338 
       
  2339     //
       
  2340     // Delete the video accessory observer when the plugin
       
  2341     // goes back to Not Initialised state.
       
  2342     //
       
  2343     if ( iAccessoryMonitor )
       
  2344     {
       
  2345         delete iAccessoryMonitor;
       
  2346         iAccessoryMonitor = NULL;
       
  2347     }
       
  2348 
  1910     if ( iFileDetails )
  2349     if ( iFileDetails )
  1911     {
  2350     {
  1912         delete iFileDetails;
  2351         delete iFileDetails;
  1913         iFileDetails = NULL;
  2352         iFileDetails = NULL;
  1914     }
  2353     }
  1949 
  2388 
  1950     //
  2389     //
  1951     //  Reset the flag to retrieve the Buffering percentage from Helix
  2390     //  Reset the flag to retrieve the Buffering percentage from Helix
  1952     //
  2391     //
  1953     iHelixLoadingStarted = EFalse;
  2392     iHelixLoadingStarted = EFalse;
       
  2393 
       
  2394     iSavedPosition = 0;
  1954 }
  2395 }
  1955 
  2396 
  1956 //  ------------------------------------------------------------------------------------------------
  2397 //  ------------------------------------------------------------------------------------------------
  1957 //  CMPXVideoPlaybackController::HandleVolumeL
  2398 //  CMPXVideoPlaybackController::HandleVolumeL
  1958 //  ------------------------------------------------------------------------------------------------
  2399 //  ------------------------------------------------------------------------------------------------
  2006 //    CMPXVideoPlaybackController::OpenFile64L()
  2447 //    CMPXVideoPlaybackController::OpenFile64L()
  2007 //  ------------------------------------------------------------------------------------------------
  2448 //  ------------------------------------------------------------------------------------------------
  2008 //
  2449 //
  2009 void CMPXVideoPlaybackController::OpenFile64L( const TDesC& aMediaFile,
  2450 void CMPXVideoPlaybackController::OpenFile64L( const TDesC& aMediaFile,
  2010                                                RFile64& aFile,
  2451                                                RFile64& aFile,
       
  2452                                                TInt aPosition,
  2011                                                TInt aAccessPointId )
  2453                                                TInt aAccessPointId )
  2012 {
  2454 {
  2013     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::OpenFile64L( RFile64 )"),
  2455     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::OpenFile64L( RFile64 )"),
  2014                    _L("file = %S"), &aMediaFile );
  2456                    _L("file = %S, position = %d"), &aMediaFile, aPosition );
  2015 
  2457 
  2016     TBool fileExists = EFalse;
  2458     TBool fileExists = EFalse;
  2017 
  2459 
  2018     ChangeState( EMPXVideoInitializing );
  2460     ChangeState( EMPXVideoInitializing );
  2019 
  2461 
  2036     }
  2478     }
  2037 
  2479 
  2038     DetermineMediaTypeL();
  2480     DetermineMediaTypeL();
  2039     SetPlaybackModeL();
  2481     SetPlaybackModeL();
  2040 
  2482 
       
  2483     iSavedPosition = aPosition; 
       
  2484     
  2041     //
  2485     //
  2042     //  Create accessory monitor to search for TV-Out events
  2486     //  Create accessory monitor to search for TV-Out events
  2043     //
  2487     //
  2044     if ( ! iAccessoryMonitor )
  2488     if ( ! iAccessoryMonitor )
  2045     {
  2489     {