1813 if ( !iBackLightTimer->IsActive() ) |
1853 if ( !iBackLightTimer->IsActive() ) |
1814 { |
1854 { |
1815 iBackLightTimer->Start( |
1855 iBackLightTimer->Start( |
1816 0, |
1856 0, |
1817 KMPXBackLightTimeOut, |
1857 KMPXBackLightTimeOut, |
1818 TCallBack( CMPXVideoPlaybackController::HandleBackLightTimout, this )); |
1858 TCallBack( CMPXVideoPlaybackController::HandleBackLightTimeout, this )); |
1819 } |
1859 } |
|
1860 |
1820 } |
1861 } |
1821 |
1862 |
1822 // ------------------------------------------------------------------------------------------------- |
1863 // ------------------------------------------------------------------------------------------------- |
1823 // Handle back light timer timeout callback |
1864 // Handle back light timer timeout callback |
1824 // ------------------------------------------------------------------------------------------------- |
1865 // ------------------------------------------------------------------------------------------------- |
1825 // |
1866 // |
1826 TInt CMPXVideoPlaybackController::HandleBackLightTimout( TAny* aPtr ) |
1867 TInt CMPXVideoPlaybackController::HandleBackLightTimeout( TAny* aPtr ) |
1827 { |
1868 { |
1828 static_cast<CMPXVideoPlaybackController*>(aPtr)->DoHandleBackLightTimout(); |
1869 static_cast<CMPXVideoPlaybackController*>(aPtr)->DoHandleBackLightTimeout(); |
1829 return KErrNone; |
1870 return KErrNone; |
1830 } |
1871 } |
1831 |
1872 |
1832 // ------------------------------------------------------------------------------------------------- |
1873 // ------------------------------------------------------------------------------------------------- |
1833 // Handle back light timer timeout |
1874 // Handle back light timer timeout |
1834 // ------------------------------------------------------------------------------------------------- |
1875 // ------------------------------------------------------------------------------------------------- |
1835 // |
1876 // |
1836 void CMPXVideoPlaybackController::DoHandleBackLightTimout() |
1877 void CMPXVideoPlaybackController::DoHandleBackLightTimeout() |
1837 { |
1878 { |
1838 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::DoHandleBackLightTimout()")); |
1879 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::DoHandleBackLightTimeout()")); |
1839 |
1880 |
|
1881 TBool tvOutConnected( EFalse ); |
|
1882 if ( iAccessoryMonitor ) |
|
1883 { |
|
1884 tvOutConnected = iAccessoryMonitor->IsTvOutConnected(); |
|
1885 } |
|
1886 |
|
1887 // User activity timer runs always when TV-out is connected |
|
1888 // it keeps resetting display timer and keeps lights on whenever there is user activity |
|
1889 if ( tvOutConnected ) |
|
1890 { |
|
1891 MPX_DEBUG ( _L("CMPXVideoPlaybackController::DoHandleBackLightTimeout() inactivity time = %d"), User::InactivityTime().Int() ); |
|
1892 // Cancel activity timer. Otherwise resetting inactivity time would fire user activity detection |
|
1893 CancelUserActivityTimer(); |
|
1894 } |
|
1895 |
1840 User::ResetInactivityTime(); |
1896 User::ResetInactivityTime(); |
|
1897 |
|
1898 if ( tvOutConnected ) |
|
1899 { |
|
1900 // Restart user activity timer. It must be running between backlight timer intervals so that backlight |
|
1901 // can be turned on if user activity is detected. |
|
1902 RestartUserActivityTimer(); |
|
1903 } |
|
1904 } |
|
1905 |
|
1906 // ----------------------------------------------------------------------------- |
|
1907 // CMPXVideoPlaybackController::StartLightsControl |
|
1908 // ----------------------------------------------------------------------------- |
|
1909 // |
|
1910 void CMPXVideoPlaybackController::StartLightsControl() |
|
1911 { |
|
1912 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::StartLightsControl()")); |
|
1913 |
|
1914 StartBackLightTimer(); |
|
1915 |
|
1916 if (iAccessoryMonitor ) |
|
1917 { |
|
1918 if ( iAccessoryMonitor->IsTvOutConnected() ) |
|
1919 { |
|
1920 RestartDisplayTimer(); |
|
1921 } |
|
1922 } |
|
1923 } |
|
1924 |
|
1925 // ----------------------------------------------------------------------------- |
|
1926 // CMPXVideoPlaybackController::CancelLightsControl |
|
1927 // ----------------------------------------------------------------------------- |
|
1928 // |
|
1929 void CMPXVideoPlaybackController::CancelLightsControl() |
|
1930 { |
|
1931 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::CancelLightsControl()")); |
|
1932 |
|
1933 // This is called whenever there is no need to keep screensaver of anymore |
|
1934 // This means that also displaytimer and activity monitoring can be stopped. |
|
1935 // This method is not correct place for these calls |
|
1936 CancelBackLightTimer(); |
|
1937 |
|
1938 CancelUserActivityTimer(); |
|
1939 |
|
1940 CancelDisplayTimer(); |
|
1941 |
|
1942 // Ensure that lights are on |
|
1943 EnableDisplayBacklight(); |
|
1944 |
|
1945 // Release lights if releserved |
|
1946 ReleaseLights(); |
|
1947 } |
|
1948 |
|
1949 |
|
1950 // ----------------------------------------------------------------------------- |
|
1951 // CMPXVideoPlaybackController::InitDisplayTimerL |
|
1952 // ----------------------------------------------------------------------------- |
|
1953 // |
|
1954 TTimeIntervalMicroSeconds32 CMPXVideoPlaybackController::InitDisplayTimerL() |
|
1955 { |
|
1956 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::InitDisplayTimerL()")); |
|
1957 |
|
1958 if ( !iDisplayTimer ) |
|
1959 { |
|
1960 iDisplayTimer = CPeriodic::NewL( CPeriodic::EPriorityStandard ); |
|
1961 |
|
1962 MPX_DEBUG(_L("CMPXVideoPlaybackController::InitDisplayTimerL() - created") ); |
|
1963 |
|
1964 } |
|
1965 |
|
1966 if ( iDisplayTimerTimeout.Int() == 0 ) |
|
1967 { |
|
1968 // Get the display light time-out value from CenRep |
|
1969 CRepository* repository = CRepository::NewLC( KCRUidLightSettings ); |
|
1970 // What's the timeout value (in seconds ) for the display light? |
|
1971 TInt displayTimeOut ( 0 ); |
|
1972 repository->Get( KDisplayLightsTimeout, displayTimeOut ); |
|
1973 |
|
1974 if ( ( displayTimeOut * KMPXMicroSecondsInASecond ) > KMaxTInt ) |
|
1975 { |
|
1976 iDisplayTimerTimeout = KMaxTInt; |
|
1977 } |
|
1978 else |
|
1979 { |
|
1980 iDisplayTimerTimeout = displayTimeOut * KMPXMicroSecondsInASecond; |
|
1981 } |
|
1982 |
|
1983 CleanupStack::PopAndDestroy( repository ); |
|
1984 } |
|
1985 |
|
1986 |
|
1987 MPX_DEBUG( _L("CMPXVideoPlaybackController::InitDisplayTimerL Timeout(%d)"), iDisplayTimerTimeout.Int() ); |
|
1988 |
|
1989 // Convert the timeout value to microseconds |
|
1990 return iDisplayTimerTimeout; |
|
1991 } |
|
1992 |
|
1993 // ----------------------------------------------------------------------------- |
|
1994 // CMPXVideoPlaybackController::RestartDisplayTimer |
|
1995 // ----------------------------------------------------------------------------- |
|
1996 // |
|
1997 void CMPXVideoPlaybackController::RestartDisplayTimer() |
|
1998 { |
|
1999 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::RestartDisplayTimer")); |
|
2000 |
|
2001 TTimeIntervalMicroSeconds32 displayTimeOut(0); |
|
2002 // Leave system to safe state if following leaves. Lights stay on |
|
2003 MPX_TRAPD(err, displayTimeOut=InitDisplayTimerL(); ) |
|
2004 if ( err == KErrNone ) |
|
2005 { |
|
2006 // check if the display timer is running and cancel it |
|
2007 if ( iDisplayTimer->IsActive() ) |
|
2008 { |
|
2009 iDisplayTimer->Cancel(); |
|
2010 } |
|
2011 |
|
2012 MPX_DEBUG( _L("CMPXVideoPlaybackController::RestartDisplayTimer() restarting displayTimer to=%d ms"), displayTimeOut.Int() ); |
|
2013 |
|
2014 iDisplayTimer->Start( displayTimeOut, displayTimeOut, |
|
2015 TCallBack( CMPXVideoPlaybackController::HandleDisplayTimeout, this ) ); |
|
2016 } |
|
2017 |
|
2018 } |
|
2019 |
|
2020 // ----------------------------------------------------------------------------- |
|
2021 // CMPXVideoPlaybackController::CancelDisplayTimer |
|
2022 // ----------------------------------------------------------------------------- |
|
2023 // |
|
2024 void CMPXVideoPlaybackController::CancelDisplayTimer() |
|
2025 { |
|
2026 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::CancelDisplayTimer")); |
|
2027 |
|
2028 if ( iDisplayTimer ) |
|
2029 { |
|
2030 if ( iDisplayTimer->IsActive() ) |
|
2031 { |
|
2032 iDisplayTimer->Cancel(); |
|
2033 } |
|
2034 delete iDisplayTimer; |
|
2035 iDisplayTimer = NULL; |
|
2036 } |
|
2037 } |
|
2038 |
|
2039 // ------------------------------------------------------------------------------------------------- |
|
2040 // CMPXVideoPlaybackUserInputHandler::HandleDisplayTimeout |
|
2041 // ------------------------------------------------------------------------------------------------- |
|
2042 // |
|
2043 TInt CMPXVideoPlaybackController::HandleDisplayTimeout( TAny* aPtr ) |
|
2044 { |
|
2045 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::HandleDisplayTimeout")); |
|
2046 |
|
2047 static_cast<CMPXVideoPlaybackController*>(aPtr)->DoHandleDisplayTimeout(); |
|
2048 |
|
2049 return KErrNone; |
|
2050 } |
|
2051 |
|
2052 // ------------------------------------------------------------------------------------------------- |
|
2053 // CMPXVideoPlaybackUserInputHandler::DoHandleDisplayTimeout |
|
2054 // ------------------------------------------------------------------------------------------------- |
|
2055 // |
|
2056 void CMPXVideoPlaybackController::DoHandleDisplayTimeout( ) |
|
2057 { |
|
2058 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::DoHandleDisplayTimeout")); |
|
2059 |
|
2060 DisableDisplayBacklight(); |
|
2061 // Avoid missing user activity immediately after lights are turned off |
|
2062 RestartUserActivityTimer(); |
|
2063 } |
|
2064 |
|
2065 |
|
2066 |
|
2067 // ------------------------------------------------------------------------------------------------ |
|
2068 // CMPXVideoPlaybackController::EnableDisplayBacklight |
|
2069 // ------------------------------------------------------------------------------------------------ |
|
2070 // |
|
2071 void CMPXVideoPlaybackController::EnableDisplayBacklight() |
|
2072 { |
|
2073 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::EnableDisplayBacklight()")); |
|
2074 |
|
2075 // ELightStatusUnknown - We are not controlling lights and we don't care about lights |
|
2076 // ELightOn - Ligths are certainly on |
|
2077 MPX_DEBUG(_L("CMPXVideoPlaybackController::EnableDisplayBacklight() iLightStatus=%d"), iLightStatus ); |
|
2078 |
|
2079 // We are responsible of turning lights on only if we have switched them off. |
|
2080 if ( iLightStatus == CHWRMLight::ELightOff ) |
|
2081 { |
|
2082 |
|
2083 MPX_TRAPD( err, |
|
2084 { |
|
2085 // Following GetLightsL() call will not leave. |
|
2086 // This call should not result to creation of CHWRMLight in this case |
|
2087 // because CHWRMLight was created when lights were turned off. |
|
2088 CHWRMLight* lights= GetLightsL(); |
|
2089 if ( lights->LightStatus(CHWRMLight::EPrimaryDisplay) == CHWRMLight::ELightOff ) |
|
2090 { |
|
2091 MPX_DEBUG(_L("CMPXVideoPlaybackController::EnableDisplayBacklight() enabling") ); |
|
2092 |
|
2093 lights->LightOnL( CHWRMLight::EPrimaryDisplay, 0 ); |
|
2094 iLightStatus = CHWRMLight::ELightOn; |
|
2095 } |
|
2096 } ); |
|
2097 |
|
2098 } |
|
2099 |
|
2100 } |
|
2101 |
|
2102 // ------------------------------------------------------------------------------------------------ |
|
2103 // CMPXVideoPlaybackController::DisableDisplayBacklight |
|
2104 // ------------------------------------------------------------------------------------------------ |
|
2105 // |
|
2106 void CMPXVideoPlaybackController::DisableDisplayBacklight() |
|
2107 { |
|
2108 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::DisableDisplayBacklight()")); |
|
2109 |
|
2110 // No major harm done if following block leaves. Lights are left on |
|
2111 MPX_TRAPD( err, |
|
2112 { |
|
2113 CHWRMLight* lights = GetLightsL(); |
|
2114 if ( lights->LightStatus(CHWRMLight::EPrimaryDisplay) == CHWRMLight::ELightOn ) |
|
2115 { |
|
2116 MPX_DEBUG(_L("CMPXVideoPlaybackController::DisableDisplayBacklight() disabling") ); |
|
2117 |
|
2118 lights->LightOffL( CHWRMLight::EPrimaryDisplay, 0 ); |
|
2119 iLightStatus = CHWRMLight::ELightOff; |
|
2120 } |
|
2121 } ); |
|
2122 |
|
2123 } |
|
2124 |
|
2125 |
|
2126 // ------------------------------------------------------------------------------------------------ |
|
2127 // CMPXVideoPlaybackController::InitUserActivityTimer |
|
2128 // ------------------------------------------------------------------------------------------------ |
|
2129 // |
|
2130 void CMPXVideoPlaybackController::InitUserActivityTimerL() |
|
2131 { |
|
2132 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::InitUserActivityTimerL()")); |
|
2133 |
|
2134 iUserActivityTimer = CPeriodic::NewL( CActive::EPriorityStandard); |
|
2135 |
|
2136 // This timer will not run to the end. Timer will be canceled and reset at backlight timeout. |
|
2137 iUserActivityTimer->Start( |
|
2138 0, |
|
2139 KMPXInactivityTimeout, |
|
2140 TCallBack( CMPXVideoPlaybackController::HandleUserActivityTimeout, this )); |
|
2141 |
|
2142 } |
|
2143 |
|
2144 // ------------------------------------------------------------------------------------------------ |
|
2145 // CMPXVideoPlaybackController::RestartUserActivityTimer |
|
2146 // ------------------------------------------------------------------------------------------------ |
|
2147 // |
|
2148 void CMPXVideoPlaybackController::RestartUserActivityTimer() |
|
2149 { |
|
2150 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::RestartUserActivityTimer()")); |
|
2151 |
|
2152 if ( !iUserActivityTimer ) |
|
2153 { |
|
2154 // This is first call. Create and initialize timer |
|
2155 MPX_TRAPD( err, |
|
2156 { |
|
2157 InitUserActivityTimerL(); |
|
2158 } ); |
|
2159 // If user activity timer creation fails we can't detect user activity and |
|
2160 // get lights back on when user taps screen. |
|
2161 // Leave lights on. |
|
2162 if ( err != KErrNone ) |
|
2163 { |
|
2164 EnableDisplayBacklight(); |
|
2165 } |
|
2166 } |
|
2167 |
|
2168 if ( iUserActivityTimer ) |
|
2169 { |
|
2170 if ( iUserActivityTimer->IsActive() ) |
|
2171 { |
|
2172 iUserActivityTimer->Cancel(); |
|
2173 } |
|
2174 // Not interested about inactivity callback, only activity |
|
2175 // If CPeriodic::Inactivity is started with argument 0 |
|
2176 // timer will fire when system's user inactivity timer resets. |
|
2177 iUserActivityTimer->Inactivity( 0 ); |
|
2178 } |
|
2179 } |
|
2180 |
|
2181 // ------------------------------------------------------------------------------------------------ |
|
2182 // CMPXVideoPlaybackController::CancelUserActivityTimer |
|
2183 // ------------------------------------------------------------------------------------------------ |
|
2184 // |
|
2185 void CMPXVideoPlaybackController::CancelUserActivityTimer() |
|
2186 { |
|
2187 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::CancelUserActivityTimer()")); |
|
2188 |
|
2189 if ( iUserActivityTimer ) |
|
2190 { |
|
2191 if ( iUserActivityTimer->IsActive() ) |
|
2192 { |
|
2193 iUserActivityTimer->Cancel(); |
|
2194 } |
|
2195 } |
|
2196 } |
|
2197 |
|
2198 // ------------------------------------------------------------------------------------------------ |
|
2199 // CMPXVideoPlaybackController::HandleUserActivityTimeout |
|
2200 // ------------------------------------------------------------------------------------------------ |
|
2201 // |
|
2202 TInt CMPXVideoPlaybackController::HandleUserActivityTimeout( TAny* aPtr ) |
|
2203 { |
|
2204 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::HandleUserActivityTimeout()")); |
|
2205 |
|
2206 static_cast<CMPXVideoPlaybackController*>(aPtr)->DoHandleUserActivityTimeout(); |
|
2207 return KErrNone; |
|
2208 } |
|
2209 |
|
2210 // ------------------------------------------------------------------------------------------------ |
|
2211 // CMPXVideoPlaybackController::DoHandleUserActivityTimeout |
|
2212 // ------------------------------------------------------------------------------------------------ |
|
2213 // |
|
2214 void CMPXVideoPlaybackController::DoHandleUserActivityTimeout() |
|
2215 { |
|
2216 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::DoHandleUserActivityTimeout()")); |
|
2217 |
|
2218 // Act only once for detected activity. |
|
2219 if ( iUserActivityTimer->IsActive() ) |
|
2220 { |
|
2221 iUserActivityTimer->Cancel(); |
|
2222 } |
|
2223 |
|
2224 // iUserActivityTimer runs when TV-out is connected and playback with video is going on |
|
2225 // This timer fires in two situations. |
|
2226 // a) Lights are off and user activity is detected - Turn lights on and restart display timer |
|
2227 // b) Lights are on and user activity is detected - restart display timer to prevent lights go off |
|
2228 EnableDisplayBacklight(); |
|
2229 |
|
2230 // Start counting down to next lights off |
|
2231 RestartDisplayTimer(); |
|
2232 } |
|
2233 |
|
2234 // ------------------------------------------------------------------------------------------------ |
|
2235 // CMPXVideoPlaybackController::GetLightsL |
|
2236 // ------------------------------------------------------------------------------------------------ |
|
2237 // |
|
2238 CHWRMLight* CMPXVideoPlaybackController::GetLightsL() |
|
2239 { |
|
2240 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::GetLightsL()")); |
|
2241 |
|
2242 if ( !iLight ) |
|
2243 { |
|
2244 MPX_DEBUG( _L("CMPXVideoPlaybackController::GetLightsL() - creating") ); |
|
2245 iLight = CHWRMLight::NewL(); |
|
2246 } |
|
2247 return iLight; |
|
2248 } |
|
2249 |
|
2250 // ------------------------------------------------------------------------------------------------ |
|
2251 // CMPXVideoPlaybackController::ReleaseLights |
|
2252 // ------------------------------------------------------------------------------------------------ |
|
2253 // |
|
2254 void CMPXVideoPlaybackController::ReleaseLights() |
|
2255 { |
|
2256 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::ReleaseLights()")); |
|
2257 |
|
2258 if ( iLight ) |
|
2259 { |
|
2260 // If iLights was created when ReleaseLights was called then TV out must be connected and lights may be off. |
|
2261 // This call ensures that lights are on again. |
|
2262 EnableDisplayBacklight(); |
|
2263 |
|
2264 MPX_DEBUG( _L("CMPXVideoPlaybackController::ReleaseLights() - deleting") ); |
|
2265 delete iLight; |
|
2266 iLight = NULL; |
|
2267 } |
1841 } |
2268 } |
1842 |
2269 |
1843 // ------------------------------------------------------------------------------------------------- |
2270 // ------------------------------------------------------------------------------------------------- |
1844 // CMPXVideoPlaybackController::InitVolumeWatchers() |
2271 // CMPXVideoPlaybackController::InitVolumeWatchers() |
1845 // ------------------------------------------------------------------------------------------------- |
2272 // ------------------------------------------------------------------------------------------------- |
1846 // |
2273 // |
1847 void CMPXVideoPlaybackController::InitVolumeWatchers() |
2274 void CMPXVideoPlaybackController::InitVolumeWatchersL() |
1848 { |
2275 { |
1849 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::InitVolumeWatchers()")); |
2276 MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::InitVolumeWatchers()")); |
1850 |
2277 |
1851 if ( ! iVolumeWatcher ) |
2278 if ( ! iVolumeWatcher ) |
1852 { |
2279 { |
1853 MPX_TRAPD( err, |
2280 iVolumeWatcher = CMPXCenRepWatcher::NewL( KCRUidMPXVideoSettings, |
1854 iVolumeWatcher = CMPXCenRepWatcher::NewL( KCRUidMPXVideoSettings, |
2281 KMPXVideoPlaybackVolume, |
1855 KMPXVideoPlaybackVolume, |
2282 this ); |
1856 this ) ); |
|
1857 } |
2283 } |
1858 |
2284 |
1859 if ( ! iMuteWatcher ) |
2285 if ( ! iMuteWatcher ) |
1860 { |
2286 { |
1861 MPX_TRAPD( err, |
2287 iMuteWatcher = CMPXCenRepWatcher::NewL( KCRUidMPXVideoSettings, |
1862 iMuteWatcher = CMPXCenRepWatcher::NewL( KCRUidMPXVideoSettings, |
2288 KMPXVideoPlaybackMute, |
1863 KMPXVideoPlaybackMute, |
2289 this ); |
1864 this ) ); |
|
1865 } |
2290 } |
1866 |
2291 |
1867 // |
2292 // |
1868 // MPX framework volume range : 0-100 |
2293 // MPX framework volume range : 0-100 |
1869 // Media player volume range : 0-10 |
2294 // Media player volume range : 0-10 |