videoplayback/videohelix/src/mpxvideoplaybackcontroller.cpp
branchRCL_3
changeset 14 8970fbd719ec
parent 13 112a725ff2c2
child 16 7f2b2a65da29
equal deleted inserted replaced
13:112a725ff2c2 14:8970fbd719ec
    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: 50 %
    18 
       
    19 // Version : %version: 52 %
    19 
    20 
    20 
    21 
    21 //
    22 //
    22 //  INCLUDE FILES
    23 //  INCLUDE FILES
    23 //
    24 //
    39 #include <mmf/common/mmferrors.h>
    40 #include <mmf/common/mmferrors.h>
    40 
    41 
    41 #include <e32std.h>
    42 #include <e32std.h>
    42 #include <devsoundif.h>
    43 #include <devsoundif.h>
    43 #include <avkondomainpskeys.h>
    44 #include <avkondomainpskeys.h>
    44 #include <hwrmlight.h>  
    45 #include <hwrmlight.h>
    45 #include <centralrepository.h>  // For display timeout setting
    46 #include <centralrepository.h>  // For display timeout setting
    46 #include <hwrmlightdomaincrkeys.h>
    47 #include <hwrmlightdomaincrkeys.h>
    47 
    48 
    48 #include "mpxvideoregion.h"
    49 #include "mpxvideoregion.h"
    49 #include "mpxvideoplaybackcontroller.h"
    50 #include "mpxvideoplaybackcontroller.h"
   162     iPlayer = CMpxVideoPlayerUtility::NewL( this );
   163     iPlayer = CMpxVideoPlayerUtility::NewL( this );
   163 
   164 
   164     iBackLightTimer = CPeriodic::NewL( CActive::EPriorityStandard );
   165     iBackLightTimer = CPeriodic::NewL( CActive::EPriorityStandard );
   165 
   166 
   166     iDrmHelper = CMpxVideoDrmHelper::NewL();
   167     iDrmHelper = CMpxVideoDrmHelper::NewL();
   167     
   168 
   168     iSavedPosition = 0;
   169     iSavedPosition = 0;
   169 }
   170 }
   170 
   171 
   171 //  ----------------------------------------------------------------------------
   172 //  ----------------------------------------------------------------------------
   172 //  CMPXVideoPlaybackController::CloseController()
   173 //  CMPXVideoPlaybackController::CloseController()
   183 //  ------------------------------------------------------------------------------------------------
   184 //  ------------------------------------------------------------------------------------------------
   184 //
   185 //
   185 void CMPXVideoPlaybackController::OpenFileL( const TDesC& aMediaFile,
   186 void CMPXVideoPlaybackController::OpenFileL( const TDesC& aMediaFile,
   186                                              RFile& aFile,
   187                                              RFile& aFile,
   187                                              TInt aPosition,
   188                                              TInt aPosition,
   188                                              TInt aAccessPointId ) 
   189                                              TInt aAccessPointId )
   189 {
   190 {
   190     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::OpenFileL()"),
   191     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::OpenFileL()"),
   191                    _L("file = %S"), &aMediaFile );
   192                    _L("file = %S"), &aMediaFile );
   192 
   193 
   193     TBool fileExists = EFalse;
   194     TBool fileExists = EFalse;
   214 
   215 
   215     DetermineMediaTypeL();
   216     DetermineMediaTypeL();
   216     SetPlaybackModeL();
   217     SetPlaybackModeL();
   217 
   218 
   218     iSavedPosition = aPosition;
   219     iSavedPosition = aPosition;
   219     
   220 
   220     //
   221     //
   221     //  Create accessory monitor to search for TV-Out events
   222     //  Create accessory monitor to search for TV-Out events
   222     //
   223     //
   223     if ( ! iAccessoryMonitor )
   224     if ( ! iAccessoryMonitor )
   224     {
   225     {
   347     if ( iPlayer )
   348     if ( iPlayer )
   348     {
   349     {
   349         delete iPlayer;
   350         delete iPlayer;
   350         iPlayer = NULL;
   351         iPlayer = NULL;
   351     }
   352     }
   352    
   353 
   353     if ( iUserActivityTimer )
   354     if ( iUserActivityTimer )
   354     {
   355     {
   355         iUserActivityTimer->Cancel();
   356         iUserActivityTimer->Cancel();
   356         delete iUserActivityTimer;
   357         delete iUserActivityTimer;
   357         iUserActivityTimer = NULL;
   358         iUserActivityTimer = NULL;
   358     }
   359     }
   359     
   360 
   360     ReleaseLights();
   361     ReleaseLights();
   361     
   362 
   362     CancelDisplayTimer();
   363     CancelDisplayTimer();
   363 
   364 
   364 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
   365 #ifdef SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
   365 
   366 
   366     if ( iFileHandle64.SubSessionHandle() )
   367     if ( iFileHandle64.SubSessionHandle() )
   493             }
   494             }
   494             case EPbCmdUpdateSeekable:
   495             case EPbCmdUpdateSeekable:
   495             {
   496             {
   496                 iSeekable = aCmd.ValueTObjectL<TBool>(KMPXMediaGeneralExtVideoSeekable);
   497                 iSeekable = aCmd.ValueTObjectL<TBool>(KMPXMediaGeneralExtVideoSeekable);
   497 
   498 
   498                 if( iFileDetails )
   499                 if ( iFileDetails )
   499                 {
   500                 {
   500                     iFileDetails->iSeekable &= iSeekable;
   501                     iFileDetails->iSeekable &= iSeekable;
   501                 }
   502                 }
   502 
   503 
   503                 break;
   504                 break;
  1201         switch ( aChangeToState )
  1202         switch ( aChangeToState )
  1202         {
  1203         {
  1203             case EMPXVideoPlaying:
  1204             case EMPXVideoPlaying:
  1204             {
  1205             {
  1205                 iState = iPlayingState;
  1206                 iState = iPlayingState;
  1206                 
  1207 
  1207                 //
  1208                 //
  1208                 //  If clip is audio only, stop the backlight timer and break switch
  1209                 //  If clip is audio only, stop the backlight timer and break switch
  1209                 //  If clip has audio and video, proceed to the next case which will
  1210                 //  If clip has audio and video, proceed to the next case which will
  1210                 //  start the backlight timer if needed
  1211                 //  start the backlight timer if needed
  1211                 //
  1212                 //
  1215                 }
  1216                 }
  1216                 else
  1217                 else
  1217                 {
  1218                 {
  1218                     CancelLightsControl();
  1219                     CancelLightsControl();
  1219                 }
  1220                 }
  1220                 
  1221 
  1221                 break;
  1222                 break;
  1222             }
  1223             }
  1223             case EMPXVideoPaused:
  1224             case EMPXVideoPaused:
  1224             {
  1225             {
  1225                 iState = iPausedState;
  1226                 iState = iPausedState;
  1376 
  1377 
  1377             CleanupStack::PushL( metaData );
  1378             CleanupStack::PushL( metaData );
  1378 
  1379 
  1379             if ( ! metaData->Name().CompareF( KSeekable ) )
  1380             if ( ! metaData->Name().CompareF( KSeekable ) )
  1380             {
  1381             {
  1381                 if ( ! metaData->Value().CompareF( KTrue ) )
  1382                 if ( ! metaData->Value().CompareF( KFalse ) )
  1382                 {
  1383                 {
  1383                     iFileDetails->iSeekable = ETrue;
  1384                     iFileDetails->iSeekable = EFalse;
  1384                 }
  1385                 }
  1385             }
  1386             }
  1386             else if ( ! metaData->Name().CompareF( KLiveStream ) )
  1387             else if ( ! metaData->Name().CompareF( KLiveStream ) )
  1387             {
  1388             {
  1388                 if ( ! metaData->Value().CompareF( KTrue ) )
  1389                 if ( ! metaData->Value().CompareF( KTrue ) )
  1749     MPX_DEBUG(_L("CMPXVideoPlaybackController::IsAlarm(%d)"), alarm);
  1750     MPX_DEBUG(_L("CMPXVideoPlaybackController::IsAlarm(%d)"), alarm);
  1750 
  1751 
  1751     return alarm;
  1752     return alarm;
  1752 }
  1753 }
  1753 
  1754 
  1754 // -----------------------------------------------------------------------------
  1755 // -------------------------------------------------------------------------------------------------
  1755 // CMPXVideoPlaybackController::IsKeyLocked
  1756 //   CMPXVideoPlaybackController::IsKeyLocked
  1756 // -----------------------------------------------------------------------------
  1757 // -------------------------------------------------------------------------------------------------
  1757 //
  1758 //
  1758 TBool CMPXVideoPlaybackController::IsKeyLocked()
  1759 TBool CMPXVideoPlaybackController::IsKeyLocked()
  1759 {
  1760 {
  1760     TBool keylock( EFalse );
  1761     TBool keylock( EFalse );
  1761     RProperty::Get( KPSUidAvkonDomain, KAknKeyguardStatus, keylock );
  1762     RProperty::Get( KPSUidAvkonDomain, KAknKeyguardStatus, keylock );
  1763     MPX_DEBUG(_L("CMPXVideoPlaybackController::IsKeyLocked(%d)"), keylock);
  1764     MPX_DEBUG(_L("CMPXVideoPlaybackController::IsKeyLocked(%d)"), keylock);
  1764 
  1765 
  1765     return keylock;
  1766     return keylock;
  1766 }
  1767 }
  1767 
  1768 
       
  1769 // -------------------------------------------------------------------------------------------------
       
  1770 //   CMPXVideoPlaybackController::SendTvOutEventL
       
  1771 // -------------------------------------------------------------------------------------------------
       
  1772 //
       
  1773 TBool CMPXVideoPlaybackController::SendTvOutEventL( TBool aConnected, TBool aPlaybackAllowed )
       
  1774 {
       
  1775     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::SendTvOutEventL()"));
       
  1776 
       
  1777     //
       
  1778     //  Send notice to the playback view with TV-Out connection status
       
  1779     //  and TV-Out playback allowed flag
       
  1780     //
       
  1781     CMPXMessage* message = CMPXMessage::NewL();
       
  1782     CleanupStack::PushL( message );
       
  1783 
       
  1784     message->SetTObjectValueL<TMPXMessageId>( KMPXMessageGeneralId, KMPXMediaIdVideoPlayback );
       
  1785     message->SetTObjectValueL<TMPXVideoPlaybackCommand>
       
  1786         ( KMPXMediaVideoPlaybackCommand, EPbCmdTvOutEvent );
       
  1787     message->SetTObjectValueL<TInt>( KMPXMediaVideoTvOutConnected, aConnected );
       
  1788     message->SetTObjectValueL<TInt>( KMPXMediaVideoTvOutPlayAllowed, aPlaybackAllowed );
       
  1789 
       
  1790     iMPXPluginObs->HandlePlaybackMessage( message, KErrNone );
       
  1791 
       
  1792     CleanupStack::PopAndDestroy( message );
       
  1793 }
       
  1794 
  1768 //  ------------------------------------------------------------------------------------------------
  1795 //  ------------------------------------------------------------------------------------------------
  1769 //    CMPXVideoPlaybackController::HandleTvOutEventL()
  1796 //    CMPXVideoPlaybackController::HandleTvOutEventL()
  1770 //  ------------------------------------------------------------------------------------------------
  1797 //  ------------------------------------------------------------------------------------------------
  1771 //
  1798 //
  1772 void CMPXVideoPlaybackController::HandleTvOutEventL( TBool aConnected )
  1799 void CMPXVideoPlaybackController::HandleTvOutEventL( TBool aConnected )
  1773 {
  1800 {
  1774     MPX_ENTER_EXIT( _L("CMPXVideoPlaybackController::HandleTvOutEventL()"),
  1801     MPX_ENTER_EXIT( _L("CMPXVideoPlaybackController::HandleTvOutEventL()"),
  1775                     _L("aConnected = %d"), aConnected );
  1802                     _L("aConnected = %d"), aConnected );
  1776 
  1803 
  1777     TBool playbackAllowed = ETrue;
  1804     TBool playbackAllowed = iAccessoryMonitor->IsTvOutPlaybackAllowed();
  1778 
  1805 
       
  1806     SendTvOutEventL( aConnected, playbackAllowed );
       
  1807 
       
  1808     //
       
  1809     //  Check playback status of clip with new Tv-Out status
       
  1810     //
  1779     if ( aConnected )
  1811     if ( aConnected )
  1780     {
  1812     {
  1781         //
  1813         //
  1782         //  TV-Out accessory connected
  1814         //  TV-Out accessory connected
  1783         //
  1815         //
  1784         if ( ! iAccessoryMonitor->IsTvOutPlaybackAllowed() )
  1816         if ( ! playbackAllowed )
  1785         {
  1817         {
  1786             //
  1818             //
  1787             //  Clip has DRM protection and TV-Out is connected
  1819             //  Clip has DRM protection and TV-Out is connected
  1788             //  Pause playback and display info note
  1820             //  Pause playback and display info note
  1789             //
  1821             //
  1790             DoHandleCommandL( EPbCmdPause );
  1822             DoHandleCommandL( EPbCmdPause );
  1791 
  1823 
  1792             playbackAllowed = EFalse;
       
  1793 
       
  1794             iState->SendErrorToViewL( KMPXVideoTvOutPlaybackNotAllowed );
  1824             iState->SendErrorToViewL( KMPXVideoTvOutPlaybackNotAllowed );
  1795         }
  1825         }
  1796         else
  1826         else
  1797         {
  1827         {
  1798             // If lights are being controlled enable display timer so that screen backlight will be turned
  1828             // If lights are being controlled enable display timer so that screen backlight will be turned
  1799             // of after timeout.
  1829             // of after timeout.
  1800             if ( iBackLightTimer->IsActive() )
  1830             if ( iBackLightTimer->IsActive() )
  1801             {
  1831             {
  1802                 RestartDisplayTimer();
  1832                 RestartDisplayTimer();
  1803             }
  1833             }
  1804          } 
  1834          }
  1805     }
  1835     }
  1806     else 
  1836     else
  1807     {
  1837     {
  1808         // TV out disconnected
  1838         // TV out disconnected
  1809         CancelDisplayTimer();
  1839         CancelDisplayTimer();
  1810         
  1840 
  1811         // Ensure that lights are on after this 
  1841         // Ensure that lights are on after this
  1812         ReleaseLights();
  1842         ReleaseLights();
  1813         
  1843 
  1814         // Pause playback since TV-Out accessory has been disconnected.
  1844         // Pause playback since TV-Out accessory has been disconnected.
  1815         DoHandleCommandL( EPbCmdPause );
  1845         DoHandleCommandL( EPbCmdPause );
  1816     }
  1846     }
  1817 
       
  1818     //
       
  1819     //  Send notice to the playback view with TV-Out connection status
       
  1820     //  and TV-Out playback allowed flag
       
  1821     //
       
  1822     CMPXMessage* message = CMPXMessage::NewL();
       
  1823     CleanupStack::PushL( message );
       
  1824 
       
  1825     message->SetTObjectValueL<TMPXMessageId>( KMPXMessageGeneralId, KMPXMediaIdVideoPlayback );
       
  1826     message->SetTObjectValueL<TMPXVideoPlaybackCommand>
       
  1827         ( KMPXMediaVideoPlaybackCommand, EPbCmdTvOutEvent );
       
  1828     message->SetTObjectValueL<TInt>( KMPXMediaVideoTvOutConnected, aConnected );
       
  1829     message->SetTObjectValueL<TInt>( KMPXMediaVideoTvOutPlayAllowed, playbackAllowed );
       
  1830 
       
  1831     iMPXPluginObs->HandlePlaybackMessage( message, KErrNone );
       
  1832 
       
  1833     CleanupStack::PopAndDestroy( message );
       
  1834 }
  1847 }
  1835 
  1848 
  1836 //  ------------------------------------------------------------------------------------------------
  1849 //  ------------------------------------------------------------------------------------------------
  1837 //    CMPXVideoPlaybackController::CancelBackLightTimer
  1850 //    CMPXVideoPlaybackController::CancelBackLightTimer
  1838 //  ------------------------------------------------------------------------------------------------
  1851 //  ------------------------------------------------------------------------------------------------
  1842 
  1855 
  1843     if ( iBackLightTimer->IsActive() )
  1856     if ( iBackLightTimer->IsActive() )
  1844     {
  1857     {
  1845         iBackLightTimer->Cancel();
  1858         iBackLightTimer->Cancel();
  1846     }
  1859     }
  1847     
       
  1848 }
  1860 }
  1849 
  1861 
  1850 //  ------------------------------------------------------------------------------------------------
  1862 //  ------------------------------------------------------------------------------------------------
  1851 //    CMPXVideoPlaybackState::StartBackLightTimer
  1863 //    CMPXVideoPlaybackState::StartBackLightTimer
  1852 //  ------------------------------------------------------------------------------------------------
  1864 //  ------------------------------------------------------------------------------------------------
  1859         iBackLightTimer->Start(
  1871         iBackLightTimer->Start(
  1860             0,
  1872             0,
  1861             KMPXBackLightTimeOut,
  1873             KMPXBackLightTimeOut,
  1862             TCallBack( CMPXVideoPlaybackController::HandleBackLightTimeout, this ));
  1874             TCallBack( CMPXVideoPlaybackController::HandleBackLightTimeout, this ));
  1863     }
  1875     }
  1864     
       
  1865 }
  1876 }
  1866 
  1877 
  1867 // -------------------------------------------------------------------------------------------------
  1878 // -------------------------------------------------------------------------------------------------
  1868 // Handle back light timer timeout callback
  1879 // Handle back light timer timeout callback
  1869 // -------------------------------------------------------------------------------------------------
  1880 // -------------------------------------------------------------------------------------------------
  1879 // -------------------------------------------------------------------------------------------------
  1890 // -------------------------------------------------------------------------------------------------
  1880 //
  1891 //
  1881 void CMPXVideoPlaybackController::DoHandleBackLightTimeout()
  1892 void CMPXVideoPlaybackController::DoHandleBackLightTimeout()
  1882 {
  1893 {
  1883     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::DoHandleBackLightTimeout()"));
  1894     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::DoHandleBackLightTimeout()"));
  1884     
  1895 
  1885     TBool tvOutConnected( EFalse );
  1896     TBool tvOutConnected( EFalse );
  1886     if ( iAccessoryMonitor )
  1897     if ( iAccessoryMonitor )
  1887     {
  1898     {
  1888         tvOutConnected = iAccessoryMonitor->IsTvOutConnected();
  1899         tvOutConnected = iAccessoryMonitor->IsTvOutConnected();
  1889     }
  1900     }
  1890     
  1901 
  1891     // User activity timer runs always when TV-out is connected
  1902     // User activity timer runs always when TV-out is connected
  1892     // it keeps resetting display timer and keeps lights on whenever there is user activity
  1903     // it keeps resetting display timer and keeps lights on whenever there is user activity
  1893     if ( tvOutConnected )
  1904     if ( tvOutConnected )
  1894     {
  1905     {
  1895         MPX_DEBUG ( _L("CMPXVideoPlaybackController::DoHandleBackLightTimeout() inactivity time = %d"), User::InactivityTime().Int() );
  1906         MPX_DEBUG ( _L("CMPXVideoPlaybackController::DoHandleBackLightTimeout() inactivity time = %d"), User::InactivityTime().Int() );
  1896         // Cancel activity timer. Otherwise resetting inactivity time would fire user activity detection
  1907         // Cancel activity timer. Otherwise resetting inactivity time would fire user activity detection
  1897         CancelUserActivityTimer();
  1908         CancelUserActivityTimer();
  1898     }
  1909     }
  1899         
  1910 
  1900     User::ResetInactivityTime();
  1911     User::ResetInactivityTime();
  1901     
  1912 
  1902     if ( tvOutConnected )
  1913     if ( tvOutConnected )
  1903     {
  1914     {
  1904         // Restart user activity timer. It must be running between backlight timer intervals so that backlight
  1915         // Restart user activity timer. It must be running between backlight timer intervals so that backlight
  1905         // can be turned on if user activity is detected.
  1916         // can be turned on if user activity is detected.
  1906         RestartUserActivityTimer();
  1917         RestartUserActivityTimer();
  1914 void CMPXVideoPlaybackController::StartLightsControl()
  1925 void CMPXVideoPlaybackController::StartLightsControl()
  1915 {
  1926 {
  1916     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::StartLightsControl()"));
  1927     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::StartLightsControl()"));
  1917 
  1928 
  1918     StartBackLightTimer();
  1929     StartBackLightTimer();
  1919              
  1930 
  1920     if (iAccessoryMonitor )
  1931     if (iAccessoryMonitor )
  1921     {
  1932     {
  1922         if ( iAccessoryMonitor->IsTvOutConnected() )
  1933         if ( iAccessoryMonitor->IsTvOutConnected() )
  1923         {
  1934         {
  1924             RestartDisplayTimer();
  1935             RestartDisplayTimer();
  1931 // -----------------------------------------------------------------------------
  1942 // -----------------------------------------------------------------------------
  1932 //
  1943 //
  1933 void CMPXVideoPlaybackController::CancelLightsControl()
  1944 void CMPXVideoPlaybackController::CancelLightsControl()
  1934 {
  1945 {
  1935     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::CancelLightsControl()"));
  1946     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::CancelLightsControl()"));
  1936 	
  1947 
  1937     // This is called whenever there is no need to keep screensaver of anymore
  1948     // This is called whenever there is no need to keep screensaver of anymore
  1938     // This means that also displaytimer and activity monitoring can be stopped. 
  1949     // This means that also displaytimer and activity monitoring can be stopped.
  1939     // This method is not correct place for these calls
  1950     // This method is not correct place for these calls
  1940     CancelBackLightTimer();
  1951     CancelBackLightTimer();
  1941    
  1952 
  1942     CancelUserActivityTimer();
  1953     CancelUserActivityTimer();
  1943     
  1954 
  1944     CancelDisplayTimer();
  1955     CancelDisplayTimer();
  1945 	
  1956 
  1946     // Ensure that lights are on
  1957     // Ensure that lights are on
  1947     EnableDisplayBacklight();
  1958     EnableDisplayBacklight();
  1948     
  1959 
  1949 	// Release lights if releserved
  1960     // Release lights if releserved
  1950     ReleaseLights();  
  1961     ReleaseLights();
  1951 }
  1962 }
  1952 
  1963 
  1953 
  1964 
  1954 // -----------------------------------------------------------------------------
  1965 // -----------------------------------------------------------------------------
  1955 // CMPXVideoPlaybackController::InitDisplayTimerL
  1966 // CMPXVideoPlaybackController::InitDisplayTimerL
  1956 // -----------------------------------------------------------------------------
  1967 // -----------------------------------------------------------------------------
  1957 //
  1968 //
  1958 TTimeIntervalMicroSeconds32 CMPXVideoPlaybackController::InitDisplayTimerL()
  1969 TTimeIntervalMicroSeconds32 CMPXVideoPlaybackController::InitDisplayTimerL()
  1959 {
  1970 {
  1960     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::InitDisplayTimerL()"));
  1971     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::InitDisplayTimerL()"));
  1961 	
  1972 
  1962     if ( !iDisplayTimer )
  1973     if ( !iDisplayTimer )
  1963     {
  1974     {
  1964         iDisplayTimer = CPeriodic::NewL( CPeriodic::EPriorityStandard );
  1975         iDisplayTimer = CPeriodic::NewL( CPeriodic::EPriorityStandard );
  1965 		
  1976 
  1966         MPX_DEBUG(_L("CMPXVideoPlaybackController::InitDisplayTimerL() - created") );	
  1977         MPX_DEBUG(_L("CMPXVideoPlaybackController::InitDisplayTimerL() - created") );
  1967         
  1978     }
  1968     }
  1979 
  1969    
       
  1970     if ( iDisplayTimerTimeout.Int() == 0 )
  1980     if ( iDisplayTimerTimeout.Int() == 0 )
  1971     {
  1981     {
  1972         // Get the display light time-out value from CenRep
  1982         // Get the display light time-out value from CenRep
  1973         CRepository* repository = CRepository::NewLC( KCRUidLightSettings  );    
  1983         CRepository* repository = CRepository::NewLC( KCRUidLightSettings  );
  1974         // What's the timeout value (in seconds ) for the display light?
  1984         // What's the timeout value (in seconds ) for the display light?
  1975         TInt displayTimeOut ( 0 );
  1985         TInt displayTimeOut ( 0 );
  1976         repository->Get( KDisplayLightsTimeout, displayTimeOut );
  1986         repository->Get( KDisplayLightsTimeout, displayTimeOut );
  1977         
  1987 
  1978         if ( ( displayTimeOut * KMPXMicroSecondsInASecond ) > KMaxTInt )
  1988         if ( ( displayTimeOut * KMPXMicroSecondsInASecond ) > KMaxTInt )
  1979         {
  1989         {
  1980             iDisplayTimerTimeout = KMaxTInt;
  1990             iDisplayTimerTimeout = KMaxTInt;
  1981         }
  1991         }
  1982         else
  1992         else
  1983         {
  1993         {
  1984             iDisplayTimerTimeout = displayTimeOut * KMPXMicroSecondsInASecond;
  1994             iDisplayTimerTimeout = displayTimeOut * KMPXMicroSecondsInASecond;
  1985         }
  1995         }
  1986         
  1996 
  1987         CleanupStack::PopAndDestroy( repository );
  1997         CleanupStack::PopAndDestroy( repository );
  1988     }     
  1998     }
  1989     
  1999 
  1990     
       
  1991     MPX_DEBUG( _L("CMPXVideoPlaybackController::InitDisplayTimerL Timeout(%d)"), iDisplayTimerTimeout.Int() );
  2000     MPX_DEBUG( _L("CMPXVideoPlaybackController::InitDisplayTimerL Timeout(%d)"), iDisplayTimerTimeout.Int() );
  1992 	
  2001 
  1993     // Convert the timeout value to microseconds
  2002     // Convert the timeout value to microseconds
  1994     return iDisplayTimerTimeout;   
  2003     return iDisplayTimerTimeout;
  1995 }
  2004 }
  1996 
  2005 
  1997 // -----------------------------------------------------------------------------
  2006 // -----------------------------------------------------------------------------
  1998 // CMPXVideoPlaybackController::RestartDisplayTimer
  2007 // CMPXVideoPlaybackController::RestartDisplayTimer
  1999 // -----------------------------------------------------------------------------
  2008 // -----------------------------------------------------------------------------
  2004 
  2013 
  2005     TTimeIntervalMicroSeconds32 displayTimeOut(0);
  2014     TTimeIntervalMicroSeconds32 displayTimeOut(0);
  2006     // Leave system to safe state if following leaves. Lights stay on
  2015     // Leave system to safe state if following leaves. Lights stay on
  2007     MPX_TRAPD(err, displayTimeOut=InitDisplayTimerL(); )
  2016     MPX_TRAPD(err, displayTimeOut=InitDisplayTimerL(); )
  2008     if ( err == KErrNone )
  2017     if ( err == KErrNone )
  2009     {   
  2018     {
  2010         // check if the display timer is running and cancel it
  2019         // check if the display timer is running and cancel it
  2011         if ( iDisplayTimer->IsActive() )
  2020         if ( iDisplayTimer->IsActive() )
  2012         {
  2021         {
  2013             iDisplayTimer->Cancel();
  2022             iDisplayTimer->Cancel();
  2014         }
  2023         }
  2015       
  2024 
  2016         MPX_DEBUG( _L("CMPXVideoPlaybackController::RestartDisplayTimer() restarting displayTimer to=%d ms"), displayTimeOut.Int() );
  2025         MPX_DEBUG( _L("CMPXVideoPlaybackController::RestartDisplayTimer() restarting displayTimer to=%d ms"), displayTimeOut.Int() );
  2017         
  2026 
  2018         iDisplayTimer->Start( displayTimeOut, displayTimeOut,
  2027         iDisplayTimer->Start( displayTimeOut, displayTimeOut,
  2019             TCallBack( CMPXVideoPlaybackController::HandleDisplayTimeout, this ) );
  2028             TCallBack( CMPXVideoPlaybackController::HandleDisplayTimeout, this ) );
  2020     }
  2029     }
  2021     
       
  2022 }
  2030 }
  2023 
  2031 
  2024 // -----------------------------------------------------------------------------
  2032 // -----------------------------------------------------------------------------
  2025 // CMPXVideoPlaybackController::CancelDisplayTimer
  2033 // CMPXVideoPlaybackController::CancelDisplayTimer
  2026 // -----------------------------------------------------------------------------
  2034 // -----------------------------------------------------------------------------
  2027 //
  2035 //
  2028 void CMPXVideoPlaybackController::CancelDisplayTimer() 
  2036 void CMPXVideoPlaybackController::CancelDisplayTimer()
  2029 {
  2037 {
  2030     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::CancelDisplayTimer"));
  2038     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::CancelDisplayTimer"));
  2031     
  2039 
  2032     if ( iDisplayTimer )
  2040     if ( iDisplayTimer )
  2033     {
  2041     {
  2034         if ( iDisplayTimer->IsActive() )
  2042         if ( iDisplayTimer->IsActive() )
  2035         {
  2043         {
  2036             iDisplayTimer->Cancel();
  2044             iDisplayTimer->Cancel();
  2069 
  2077 
  2070 
  2078 
  2071 //  ------------------------------------------------------------------------------------------------
  2079 //  ------------------------------------------------------------------------------------------------
  2072 //  CMPXVideoPlaybackController::EnableDisplayBacklight
  2080 //  CMPXVideoPlaybackController::EnableDisplayBacklight
  2073 //  ------------------------------------------------------------------------------------------------
  2081 //  ------------------------------------------------------------------------------------------------
  2074 // 
  2082 //
  2075 void CMPXVideoPlaybackController::EnableDisplayBacklight()
  2083 void CMPXVideoPlaybackController::EnableDisplayBacklight()
  2076 {
  2084 {
  2077     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::EnableDisplayBacklight()"));
  2085     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::EnableDisplayBacklight()"));
  2078     
  2086 
  2079     // ELightStatusUnknown - We are not controlling lights and we don't care about lights
  2087     // ELightStatusUnknown - We are not controlling lights and we don't care about lights
  2080     // ELightOn            - Ligths are certainly on 
  2088     // ELightOn            - Ligths are certainly on
  2081     MPX_DEBUG(_L("CMPXVideoPlaybackController::EnableDisplayBacklight() iLightStatus=%d"), iLightStatus );
  2089     MPX_DEBUG(_L("CMPXVideoPlaybackController::EnableDisplayBacklight() iLightStatus=%d"), iLightStatus );
  2082     
  2090 
  2083     // We are responsible of turning lights on only if we have switched them off.
  2091     // We are responsible of turning lights on only if we have switched them off.
  2084     if ( iLightStatus == CHWRMLight::ELightOff )
  2092     if ( iLightStatus == CHWRMLight::ELightOff )
  2085     {
  2093     {
  2086 
  2094 
  2087         MPX_TRAPD( err,
  2095         MPX_TRAPD( err,
  2088         {   
  2096         {
  2089             // Following GetLightsL() call will not leave.
  2097             // Following GetLightsL() call will not leave.
  2090             // This call should not result to creation of CHWRMLight in this case
  2098             // This call should not result to creation of CHWRMLight in this case
  2091             // because CHWRMLight was created when lights were turned off.
  2099             // because CHWRMLight was created when lights were turned off.
  2092             CHWRMLight* lights= GetLightsL();
  2100             CHWRMLight* lights= GetLightsL();
  2093             if ( lights->LightStatus(CHWRMLight::EPrimaryDisplay) == CHWRMLight::ELightOff )
  2101             if ( lights->LightStatus(CHWRMLight::EPrimaryDisplay) == CHWRMLight::ELightOff )
  2094             {
  2102             {
  2095                 MPX_DEBUG(_L("CMPXVideoPlaybackController::EnableDisplayBacklight() enabling") );
  2103                 MPX_DEBUG(_L("CMPXVideoPlaybackController::EnableDisplayBacklight() enabling") );
  2096 			
  2104 
  2097                 lights->LightOnL( CHWRMLight::EPrimaryDisplay, 0  );
  2105                 lights->LightOnL( CHWRMLight::EPrimaryDisplay, 0  );
  2098                 iLightStatus = CHWRMLight::ELightOn;
  2106                 iLightStatus = CHWRMLight::ELightOn;
  2099             }
  2107             }
  2100         } );
  2108         } );
  2101         
  2109     }
  2102     }
       
  2103    
       
  2104 }
  2110 }
  2105 
  2111 
  2106 //  ------------------------------------------------------------------------------------------------
  2112 //  ------------------------------------------------------------------------------------------------
  2107 //  CMPXVideoPlaybackController::DisableDisplayBacklight
  2113 //  CMPXVideoPlaybackController::DisableDisplayBacklight
  2108 //  ------------------------------------------------------------------------------------------------
  2114 //  ------------------------------------------------------------------------------------------------
  2109 // 
  2115 //
  2110 void CMPXVideoPlaybackController::DisableDisplayBacklight()
  2116 void CMPXVideoPlaybackController::DisableDisplayBacklight()
  2111 {
  2117 {
  2112     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::DisableDisplayBacklight()"));
  2118     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::DisableDisplayBacklight()"));
  2113        
  2119 
  2114     // No major harm done if following block leaves. Lights are left on
  2120     // No major harm done if following block leaves. Lights are left on
  2115     MPX_TRAPD( err,
  2121     MPX_TRAPD( err,
  2116     {  
  2122     {
  2117         CHWRMLight* lights = GetLightsL();
  2123         CHWRMLight* lights = GetLightsL();
  2118         if ( lights->LightStatus(CHWRMLight::EPrimaryDisplay) == CHWRMLight::ELightOn )
  2124         if ( lights->LightStatus(CHWRMLight::EPrimaryDisplay) == CHWRMLight::ELightOn )
  2119         {
  2125         {
  2120            MPX_DEBUG(_L("CMPXVideoPlaybackController::DisableDisplayBacklight() disabling") );
  2126            MPX_DEBUG(_L("CMPXVideoPlaybackController::DisableDisplayBacklight() disabling") );
  2121 		   
  2127 
  2122            lights->LightOffL( CHWRMLight::EPrimaryDisplay, 0  );
  2128            lights->LightOffL( CHWRMLight::EPrimaryDisplay, 0  );
  2123            iLightStatus = CHWRMLight::ELightOff;
  2129            iLightStatus = CHWRMLight::ELightOff;
  2124         }
  2130         }
  2125     } );
  2131     } );
  2126    
       
  2127 }
  2132 }
  2128 
  2133 
  2129 
  2134 
  2130 //  ------------------------------------------------------------------------------------------------
  2135 //  ------------------------------------------------------------------------------------------------
  2131 //  CMPXVideoPlaybackController::InitUserActivityTimer
  2136 //  CMPXVideoPlaybackController::InitUserActivityTimer
  2132 //  ------------------------------------------------------------------------------------------------
  2137 //  ------------------------------------------------------------------------------------------------
  2133 // 
  2138 //
  2134 void CMPXVideoPlaybackController::InitUserActivityTimerL()
  2139 void CMPXVideoPlaybackController::InitUserActivityTimerL()
  2135 {
  2140 {
  2136     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::InitUserActivityTimerL()"));
  2141     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::InitUserActivityTimerL()"));
  2137     
  2142 
  2138     iUserActivityTimer = CPeriodic::NewL( CActive::EPriorityStandard);
  2143     iUserActivityTimer = CPeriodic::NewL( CActive::EPriorityStandard);
  2139     
  2144 
  2140     // This timer will not run to the end. Timer will be canceled and reset at backlight timeout.    
  2145     // This timer will not run to the end. Timer will be canceled and reset at backlight timeout.
  2141     iUserActivityTimer->Start(
  2146     iUserActivityTimer->Start(
  2142         0,
  2147         0,
  2143         KMPXInactivityTimeout,
  2148         KMPXInactivityTimeout,
  2144         TCallBack( CMPXVideoPlaybackController::HandleUserActivityTimeout, this ));
  2149         TCallBack( CMPXVideoPlaybackController::HandleUserActivityTimeout, this ));
  2145     
       
  2146 }
  2150 }
  2147 
  2151 
  2148 //  ------------------------------------------------------------------------------------------------
  2152 //  ------------------------------------------------------------------------------------------------
  2149 //  CMPXVideoPlaybackController::RestartUserActivityTimer
  2153 //  CMPXVideoPlaybackController::RestartUserActivityTimer
  2150 //  ------------------------------------------------------------------------------------------------
  2154 //  ------------------------------------------------------------------------------------------------
  2151 // 
  2155 //
  2152 void CMPXVideoPlaybackController::RestartUserActivityTimer() 
  2156 void CMPXVideoPlaybackController::RestartUserActivityTimer()
  2153 {
  2157 {
  2154     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::RestartUserActivityTimer()"));
  2158     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::RestartUserActivityTimer()"));
  2155     
  2159 
  2156     if ( !iUserActivityTimer )
  2160     if ( !iUserActivityTimer )
  2157     {
  2161     {
  2158        // This is first call. Create and initialize timer
  2162        // This is first call. Create and initialize timer
  2159        MPX_TRAPD( err,
  2163        MPX_TRAPD( err,
  2160        {   
  2164        {
  2161            InitUserActivityTimerL();
  2165            InitUserActivityTimerL();
  2162        } );
  2166        } );
  2163        // If user activity timer creation fails we can't detect user activity and 
  2167 
  2164        // get lights back on when user taps screen. 
  2168        // If user activity timer creation fails we can't detect user activity and
       
  2169        // get lights back on when user taps screen.
  2165        // Leave lights on.
  2170        // Leave lights on.
  2166        if ( err != KErrNone )
  2171        if ( err != KErrNone )
  2167        { 
  2172        {
  2168            EnableDisplayBacklight(); 
  2173            EnableDisplayBacklight();
  2169        }  
  2174        }
  2170     }
  2175     }
  2171       
  2176 
  2172     if ( iUserActivityTimer )
  2177     if ( iUserActivityTimer )
  2173     {
  2178     {
  2174         if ( iUserActivityTimer->IsActive() )
  2179         if ( iUserActivityTimer->IsActive() )
  2175         {
  2180         {
  2176             iUserActivityTimer->Cancel();
  2181             iUserActivityTimer->Cancel();
  2177         }            
  2182         }
       
  2183 
  2178         // Not interested about inactivity callback, only activity
  2184         // Not interested about inactivity callback, only activity
  2179         // If CPeriodic::Inactivity is started with argument 0 
  2185         // If CPeriodic::Inactivity is started with argument 0
  2180         // timer will fire when system's user inactivity timer resets.
  2186         // timer will fire when system's user inactivity timer resets.
  2181         iUserActivityTimer->Inactivity( 0 );
  2187         iUserActivityTimer->Inactivity( 0 );
  2182     } 
  2188     }
  2183 }
  2189 }
  2184 
  2190 
  2185 //  ------------------------------------------------------------------------------------------------
  2191 //  ------------------------------------------------------------------------------------------------
  2186 //  CMPXVideoPlaybackController::CancelUserActivityTimer
  2192 //  CMPXVideoPlaybackController::CancelUserActivityTimer
  2187 //  ------------------------------------------------------------------------------------------------
  2193 //  ------------------------------------------------------------------------------------------------
  2188 // 
  2194 //
  2189 void CMPXVideoPlaybackController::CancelUserActivityTimer() 
  2195 void CMPXVideoPlaybackController::CancelUserActivityTimer()
  2190 {
  2196 {
  2191     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::CancelUserActivityTimer()"));
  2197     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::CancelUserActivityTimer()"));
  2192 	
  2198 
  2193     if  ( iUserActivityTimer ) 
  2199     if  ( iUserActivityTimer )
  2194     {   
  2200     {
  2195         if ( iUserActivityTimer->IsActive() )
  2201         if ( iUserActivityTimer->IsActive() )
  2196         {
  2202         {
  2197             iUserActivityTimer->Cancel();
  2203             iUserActivityTimer->Cancel();
  2198         }
  2204         }
  2199     }
  2205     }
  2200 }
  2206 }
  2201 
  2207 
  2202 //  ------------------------------------------------------------------------------------------------
  2208 //  ------------------------------------------------------------------------------------------------
  2203 //  CMPXVideoPlaybackController::HandleUserActivityTimeout
  2209 //  CMPXVideoPlaybackController::HandleUserActivityTimeout
  2204 //  ------------------------------------------------------------------------------------------------
  2210 //  ------------------------------------------------------------------------------------------------
  2205 // 
  2211 //
  2206 TInt CMPXVideoPlaybackController::HandleUserActivityTimeout( TAny* aPtr )
  2212 TInt CMPXVideoPlaybackController::HandleUserActivityTimeout( TAny* aPtr )
  2207 {
  2213 {
  2208     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::HandleUserActivityTimeout()"));
  2214     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::HandleUserActivityTimeout()"));
  2209 	
  2215 
  2210     static_cast<CMPXVideoPlaybackController*>(aPtr)->DoHandleUserActivityTimeout();
  2216     static_cast<CMPXVideoPlaybackController*>(aPtr)->DoHandleUserActivityTimeout();
  2211     return KErrNone;     
  2217     return KErrNone;
  2212 }
  2218 }
  2213 
  2219 
  2214 //  ------------------------------------------------------------------------------------------------
  2220 //  ------------------------------------------------------------------------------------------------
  2215 //  CMPXVideoPlaybackController::DoHandleUserActivityTimeout
  2221 //  CMPXVideoPlaybackController::DoHandleUserActivityTimeout
  2216 //  ------------------------------------------------------------------------------------------------
  2222 //  ------------------------------------------------------------------------------------------------
  2217 // 
  2223 //
  2218 void CMPXVideoPlaybackController::DoHandleUserActivityTimeout()
  2224 void CMPXVideoPlaybackController::DoHandleUserActivityTimeout()
  2219 {
  2225 {
  2220     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::DoHandleUserActivityTimeout()"));
  2226     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::DoHandleUserActivityTimeout()"));
  2221     
  2227 
  2222     // Act only once for detected activity.
  2228     // Act only once for detected activity.
  2223     if ( iUserActivityTimer->IsActive() ) 
  2229     if ( iUserActivityTimer->IsActive() )
  2224     {
  2230     {
  2225         iUserActivityTimer->Cancel();
  2231         iUserActivityTimer->Cancel();
  2226     }
  2232     }
  2227     
  2233 
  2228     // iUserActivityTimer runs when TV-out is connected and playback with video is going on
  2234     // iUserActivityTimer runs when TV-out is connected and playback with video is going on
  2229     // This timer fires in two situations. 
  2235     // This timer fires in two situations.
  2230     // a) Lights are off and user activity is detected - Turn lights on and restart display timer
  2236     // a) Lights are off and user activity is detected - Turn lights on and restart display timer
  2231     // b) Lights are on and user activity is detected - restart display timer to prevent lights go off
  2237     // b) Lights are on and user activity is detected - restart display timer to prevent lights go off
  2232     EnableDisplayBacklight();
  2238     EnableDisplayBacklight();
  2233     
  2239 
  2234     // Start counting down to next lights off
  2240     // Start counting down to next lights off
  2235     RestartDisplayTimer();
  2241     RestartDisplayTimer();
  2236 }
  2242 }
  2237 
  2243 
  2238 //  ------------------------------------------------------------------------------------------------
  2244 //  ------------------------------------------------------------------------------------------------
  2240 //  ------------------------------------------------------------------------------------------------
  2246 //  ------------------------------------------------------------------------------------------------
  2241 //
  2247 //
  2242 CHWRMLight* CMPXVideoPlaybackController::GetLightsL()
  2248 CHWRMLight* CMPXVideoPlaybackController::GetLightsL()
  2243 {
  2249 {
  2244     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::GetLightsL()"));
  2250     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::GetLightsL()"));
  2245 	
  2251 
  2246     if ( !iLight ) 
  2252     if ( !iLight )
  2247     {
  2253     {
  2248         MPX_DEBUG( _L("CMPXVideoPlaybackController::GetLightsL() - creating") );
  2254         MPX_DEBUG( _L("CMPXVideoPlaybackController::GetLightsL() - creating") );
  2249         iLight = CHWRMLight::NewL();
  2255         iLight = CHWRMLight::NewL();
  2250     }
  2256     }
  2251     return iLight;
  2257     return iLight;
  2256 //  ------------------------------------------------------------------------------------------------
  2262 //  ------------------------------------------------------------------------------------------------
  2257 //
  2263 //
  2258 void CMPXVideoPlaybackController::ReleaseLights()
  2264 void CMPXVideoPlaybackController::ReleaseLights()
  2259 {
  2265 {
  2260     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::ReleaseLights()"));
  2266     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::ReleaseLights()"));
  2261 	
  2267 
  2262     if ( iLight )
  2268     if ( iLight )
  2263     {
  2269     {
  2264         // If iLights was created when ReleaseLights was called then TV out must be connected and lights may be off. 
  2270         // If iLights was created when ReleaseLights was called then TV out must be connected and lights may be off.
  2265         // This call ensures that lights are on again.
  2271         // This call ensures that lights are on again.
  2266         EnableDisplayBacklight();
  2272         EnableDisplayBacklight();
  2267 		
  2273 
  2268         MPX_DEBUG( _L("CMPXVideoPlaybackController::ReleaseLights() - deleting") );
  2274         MPX_DEBUG( _L("CMPXVideoPlaybackController::ReleaseLights() - deleting") );
  2269         delete iLight;
  2275         delete iLight;
  2270         iLight = NULL;
  2276         iLight = NULL;
  2271     }
  2277     }
  2272 }
  2278 }
  2377     if ( iFileHandle64.SubSessionHandle() )
  2383     if ( iFileHandle64.SubSessionHandle() )
  2378     {
  2384     {
  2379         iFileHandle64.Close();
  2385         iFileHandle64.Close();
  2380     }
  2386     }
  2381 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
  2387 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
  2382     
  2388 
  2383     // reset to True
  2389     // reset to True
  2384     iSeekable = ETrue;
  2390     iSeekable = ETrue;
  2385 
  2391 
  2386     //
  2392     //
  2387     //  Needs to be last thing destroyed since PDL requires the
  2393     //  Needs to be last thing destroyed since PDL requires the
  2482     }
  2488     }
  2483 
  2489 
  2484     DetermineMediaTypeL();
  2490     DetermineMediaTypeL();
  2485     SetPlaybackModeL();
  2491     SetPlaybackModeL();
  2486 
  2492 
  2487     iSavedPosition = aPosition; 
  2493     iSavedPosition = aPosition;
  2488     
  2494 
  2489     //
  2495     //
  2490     //  Create accessory monitor to search for TV-Out events
  2496     //  Create accessory monitor to search for TV-Out events
  2491     //
  2497     //
  2492     if ( ! iAccessoryMonitor )
  2498     if ( ! iAccessoryMonitor )
  2493     {
  2499     {