videoplayback/videohelix/src/mpxvideoplaybackcontroller.cpp
branchRCL_3
changeset 21 55fa1ec415c6
parent 16 7f2b2a65da29
child 23 8f0df5c82986
equal deleted inserted replaced
16:7f2b2a65da29 21:55fa1ec415c6
    14 * Description:  This class plays local video file
    14 * Description:  This class plays local video file
    15  *
    15  *
    16 */
    16 */
    17 
    17 
    18 
    18 
    19 // Version : %version: 56 %
    19 // Version : %version: 58 %
    20 
    20 
    21 
    21 
    22 //
    22 //
    23 //  INCLUDE FILES
    23 //  INCLUDE FILES
    24 //
    24 //
   153 
   153 
   154     iMPXPluginObs = &aObs;
   154     iMPXPluginObs = &aObs;
   155     iAccessPointId = KUseDefaultIap;
   155     iAccessPointId = KUseDefaultIap;
   156     iVideoSeeker = CMPXVideoSeeker::NewL( this );
   156     iVideoSeeker = CMPXVideoSeeker::NewL( this );
   157 
   157 
   158     // Initiliaze to True
       
   159     iSeekable = ETrue;
   158     iSeekable = ETrue;
   160 
   159 
   161     InitVolumeWatchersL();
   160     InitVolumeWatchersL();
   162 
   161 
   163     CreatePreInitStatesL();
   162     CreatePreInitStatesL();
   195 
   194 
   196     TBool fileExists = EFalse;
   195     TBool fileExists = EFalse;
   197 
   196 
   198     ChangeState( EMPXVideoInitializing );
   197     ChangeState( EMPXVideoInitializing );
   199 
   198 
       
   199     if ( iClipName )
       
   200     {
       
   201         delete iClipName;
       
   202         iClipName = NULL;
       
   203     }
       
   204 
   200     iClipName = aMediaFile.AllocL();
   205     iClipName = aMediaFile.AllocL();
   201     iAccessPointId = aAccessPointId;
   206     iAccessPointId = aAccessPointId;
   202 
   207 
   203     //
   208     //
   204     //  If file handle exists, duplicate it to the controller
   209     //  If file handle exists, duplicate it to the controller
   226     if ( ! iAccessoryMonitor )
   231     if ( ! iAccessoryMonitor )
   227     {
   232     {
   228         iAccessoryMonitor = CMPXVideoAccessoryObserver::NewL( this );
   233         iAccessoryMonitor = CMPXVideoAccessoryObserver::NewL( this );
   229     }
   234     }
   230 
   235 
   231     if ( iAccessoryMonitor->IsTvOutPlaybackAllowed() )
   236     if ( fileExists )
   232     {
   237     {
   233         if ( fileExists )
   238         //
       
   239         //  Ensure there are rights for protected clips
       
   240         //
       
   241         TInt drmError = iDrmHelper->GetDrmRightsStatus( iFileHandle );
       
   242 
       
   243         if ( drmError )
   234         {
   244         {
   235             //
   245             //
   236             //  Ensure there are rights for protected clips
   246             //  Send error to observer for handling
   237             //
   247             //
   238             TInt drmError = iDrmHelper->GetDrmRightsStatus( iFileHandle );
   248             HandleError( drmError );
   239 
       
   240             if ( drmError )
       
   241             {
       
   242                 //
       
   243                 //  Send error to observer for handling
       
   244                 //
       
   245                 HandleError( drmError );
       
   246             }
       
   247             else
       
   248             {
       
   249                 iState->OpenFileL( iFileHandle );
       
   250             }
       
   251         }
   249         }
   252         else
   250         else
   253         {
   251         {
   254             iState->OpenFileL( iClipName->Des() );
   252             iState->OpenFileL( iFileHandle );
   255         }
   253         }
   256     }
   254     }
   257     else
   255     else
   258     {
   256     {
   259         HandleError( KMPXVideoTvOutPlaybackNotAllowedClose );
   257         iState->OpenFileL( iClipName->Des() );
   260     }
   258     }
   261 }
   259 }
   262 
   260 
   263 //  ----------------------------------------------------------------------------
   261 //  ----------------------------------------------------------------------------
   264 //    C++ constructor
   262 //    C++ constructor
   416 
   414 
   417         switch ( cmd )
   415         switch ( cmd )
   418         {
   416         {
   419             case EPbCmdInitView:
   417             case EPbCmdInitView:
   420             {
   418             {
   421                 if ( iState != iNotIntialisedState)
   419                 if ( iState != iNotIntialisedState )
   422                 {
   420                 {
   423                     aCmd.SetTextValueL( KMPXMediaVideoPlaybackFileName, *iClipName );
   421                     aCmd.SetTextValueL( KMPXMediaVideoPlaybackFileName, *iClipName );
   424                     aCmd.SetTObjectValueL<TInt>( KMPXMediaVideoMode, iPlaybackMode->GetMode() );
   422                     aCmd.SetTObjectValueL<TInt>( KMPXMediaVideoMode, iPlaybackMode->GetMode() );
   425 
   423 
   426                     aCmd.SetTObjectValueL<TInt>( KMPXMediaVideoTvOutConnected,
   424                     aCmd.SetTObjectValueL<TInt>( KMPXMediaVideoTvOutConnected,
   427                                                  iAccessoryMonitor->IsTvOutConnected() );
   425                                                  iAccessoryMonitor->IsTvOutConnected() );
   428 
   426 
   429                     aCmd.SetTObjectValueL<TInt>( KMPXMediaVideoTvOutPlayAllowed,
       
   430                                                  iAccessoryMonitor->IsTvOutPlaybackAllowed() );
       
   431 
       
   432                     if ( iRecognizedMimeType )
   427                     if ( iRecognizedMimeType )
   433                     {
   428                     {
   434                         aCmd.SetTextValueL( KMPXMediaVideoRecognizedMimeType, *iRecognizedMimeType );
   429                         aCmd.SetTextValueL( KMPXMediaVideoRecognizedMimeType,
       
   430                                             *iRecognizedMimeType );
   435                     }
   431                     }
   436                 }
   432                 }
   437 
   433 
   438                 break;
   434                 break;
   439             }
   435             }
   473                 iState->HandleForeground();
   469                 iState->HandleForeground();
   474                 break;
   470                 break;
   475             }
   471             }
   476             case EPbCmdHandleBackground:
   472             case EPbCmdHandleBackground:
   477             {
   473             {
   478                 iAppInForeground = static_cast<TBool>(aCmd.ValueTObjectL<TBool>(KMPXMediaVideoAppForeground));
   474                 iAppInForeground =
       
   475                     static_cast<TBool>(aCmd.ValueTObjectL<TBool>(KMPXMediaVideoAppForeground));
       
   476 
   479                 iState->HandleBackground();
   477                 iState->HandleBackground();
   480                 break;
   478                 break;
   481             }
   479             }
   482             case EPbCmdNaturalAspectRatio:
   480             case EPbCmdNaturalAspectRatio:
   483             {
   481             {
   494                 iState->SetAspectRatioL( aCmd, EMMFStretch );
   492                 iState->SetAspectRatioL( aCmd, EMMFStretch );
   495                 break;
   493                 break;
   496             }
   494             }
   497             case EPbCmdUpdateSeekable:
   495             case EPbCmdUpdateSeekable:
   498             {
   496             {
   499                 iSeekable = aCmd.ValueTObjectL<TBool>(KMPXMediaGeneralExtVideoSeekable);
   497                 iState->UpdateSeekableL( aCmd );
   500 
       
   501                 if ( iFileDetails )
       
   502                 {
       
   503                     iFileDetails->iSeekable &= iSeekable;
       
   504                 }
       
   505 
       
   506                 break;
   498                 break;
   507             }
   499             }
   508             case EPbCmdEndofClipReached:
   500             case EPbCmdEndofClipReached:
   509             {
   501             {
   510                 iState->HandleEndOfClip();
   502                 iState->HandleEndOfClip();
  1771 
  1763 
  1772 // -------------------------------------------------------------------------------------------------
  1764 // -------------------------------------------------------------------------------------------------
  1773 //   CMPXVideoPlaybackController::SendTvOutEventL
  1765 //   CMPXVideoPlaybackController::SendTvOutEventL
  1774 // -------------------------------------------------------------------------------------------------
  1766 // -------------------------------------------------------------------------------------------------
  1775 //
  1767 //
  1776 void CMPXVideoPlaybackController::SendTvOutEventL( TBool aConnected, TBool aPlaybackAllowed )
  1768 void CMPXVideoPlaybackController::SendTvOutEventL( TBool aConnected )
  1777 {
  1769 {
  1778     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::SendTvOutEventL()"));
  1770     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::SendTvOutEventL()"));
  1779 
  1771 
  1780     //
  1772     //
  1781     //  Send notice to the playback view with TV-Out connection status
  1773     //  Send notice to the playback view with TV-Out connection status
  1786 
  1778 
  1787     message->SetTObjectValueL<TMPXMessageId>( KMPXMessageGeneralId, KMPXMediaIdVideoPlayback );
  1779     message->SetTObjectValueL<TMPXMessageId>( KMPXMessageGeneralId, KMPXMediaIdVideoPlayback );
  1788     message->SetTObjectValueL<TMPXVideoPlaybackCommand>
  1780     message->SetTObjectValueL<TMPXVideoPlaybackCommand>
  1789         ( KMPXMediaVideoPlaybackCommand, EPbCmdTvOutEvent );
  1781         ( KMPXMediaVideoPlaybackCommand, EPbCmdTvOutEvent );
  1790     message->SetTObjectValueL<TInt>( KMPXMediaVideoTvOutConnected, aConnected );
  1782     message->SetTObjectValueL<TInt>( KMPXMediaVideoTvOutConnected, aConnected );
  1791     message->SetTObjectValueL<TInt>( KMPXMediaVideoTvOutPlayAllowed, aPlaybackAllowed );
       
  1792 
  1783 
  1793     iMPXPluginObs->HandlePlaybackMessage( message, KErrNone );
  1784     iMPXPluginObs->HandlePlaybackMessage( message, KErrNone );
  1794 
  1785 
  1795     CleanupStack::PopAndDestroy( message );
  1786     CleanupStack::PopAndDestroy( message );
  1796 }
  1787 }
  1827 void CMPXVideoPlaybackController::HandleTvOutEventL( TBool aConnected )
  1818 void CMPXVideoPlaybackController::HandleTvOutEventL( TBool aConnected )
  1828 {
  1819 {
  1829     MPX_ENTER_EXIT( _L("CMPXVideoPlaybackController::HandleTvOutEventL()"),
  1820     MPX_ENTER_EXIT( _L("CMPXVideoPlaybackController::HandleTvOutEventL()"),
  1830                     _L("aConnected = %d"), aConnected );
  1821                     _L("aConnected = %d"), aConnected );
  1831 
  1822 
  1832     TBool playbackAllowed = iAccessoryMonitor->IsTvOutPlaybackAllowed();
  1823     SendTvOutEventL( aConnected );
  1833 
       
  1834     SendTvOutEventL( aConnected, playbackAllowed );
       
  1835 
  1824 
  1836     //
  1825     //
  1837     //  Check playback status of clip with new Tv-Out status
  1826     //  Check playback status of clip with new Tv-Out status
  1838     //
  1827     //
  1839     if ( aConnected )
  1828     if ( aConnected )
  1840     {
  1829     {
  1841         //
  1830         //
  1842         //  TV-Out accessory connected
  1831         //  TV-Out accessory connected
  1843         //
  1832         //
  1844         if ( ! playbackAllowed )
  1833         // If lights are being controlled enable display timer so that screen backlight will be turned
  1845         {
  1834         // of after timeout.
  1846             //
  1835         if ( iBackLightTimer->IsActive() )
  1847             //  Clip has DRM protection and TV-Out is connected
  1836         {
  1848             //  Pause playback and display info note
  1837             RestartDisplayTimer();
  1849             //
  1838         }
  1850             DoHandleCommandL( EPbCmdPause );
       
  1851 
       
  1852             iState->SendErrorToViewL( KMPXVideoTvOutPlaybackNotAllowed );
       
  1853         }
       
  1854         else
       
  1855         {
       
  1856             // If lights are being controlled enable display timer so that screen backlight will be turned
       
  1857             // of after timeout.
       
  1858             if ( iBackLightTimer->IsActive() )
       
  1859             {
       
  1860                 RestartDisplayTimer();
       
  1861             }
       
  1862          }
       
  1863     }
  1839     }
  1864     else
  1840     else
  1865     {
  1841     {
  1866         // TV out disconnected
  1842         // TV out disconnected
  1867         CancelDisplayTimer();
  1843         CancelDisplayTimer();
  1920 void CMPXVideoPlaybackController::DoHandleBackLightTimeout()
  1896 void CMPXVideoPlaybackController::DoHandleBackLightTimeout()
  1921 {
  1897 {
  1922     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::DoHandleBackLightTimeout()"));
  1898     MPX_ENTER_EXIT(_L("CMPXVideoPlaybackController::DoHandleBackLightTimeout()"));
  1923 
  1899 
  1924     TBool tvOutConnected( EFalse );
  1900     TBool tvOutConnected( EFalse );
       
  1901 
  1925     if ( iAccessoryMonitor )
  1902     if ( iAccessoryMonitor )
  1926     {
  1903     {
  1927         tvOutConnected = iAccessoryMonitor->IsTvOutConnected();
  1904         tvOutConnected = iAccessoryMonitor->IsTvOutConnected();
  1928     }
  1905     }
  1929 
  1906 
  1930     // User activity timer runs always when TV-out is connected
  1907     // User activity timer runs always when TV-out is connected
  1931     // it keeps resetting display timer and keeps lights on whenever there is user activity
  1908     // it keeps resetting display timer and keeps lights on whenever there is user activity
  1932     if ( tvOutConnected )
  1909     if ( tvOutConnected )
  1933     {
  1910     {
  1934         MPX_DEBUG ( _L("CMPXVideoPlaybackController::DoHandleBackLightTimeout() inactivity time = %d"), User::InactivityTime().Int() );
  1911         MPX_DEBUG(_L("CMPXVideoPlaybackController::DoHandleBackLightTimeout() inactivity time = %d"), User::InactivityTime().Int() );
       
  1912 
  1935         // Cancel activity timer. Otherwise resetting inactivity time would fire user activity detection
  1913         // Cancel activity timer. Otherwise resetting inactivity time would fire user activity detection
  1936         CancelUserActivityTimer();
  1914         CancelUserActivityTimer();
  1937     }
  1915     }
  1938 
  1916 
  1939     User::ResetInactivityTime();
  1917     User::ResetInactivityTime();
  2355                     _L("error = %d"), error );
  2333                     _L("error = %d"), error );
  2356 
  2334 
  2357     ChangeState( EMPXVideoNotInitialized );
  2335     ChangeState( EMPXVideoNotInitialized );
  2358 
  2336 
  2359     //
  2337     //
  2360     // Move the FW state to Initialized so that it can request for Media
  2338     //  Move the FW state to Initialized so that it can request for Media
  2361     //
  2339     //
  2362     iMPXPluginObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPInitialised, 0, KErrNone );
  2340     iMPXPluginObs->HandlePluginEvent( MMPXPlaybackPluginObserver::EPInitialised, 0, KErrNone );
  2363 
  2341 
  2364     iPBPluginError = error;
  2342     iPBPluginError = error;
  2365 }
  2343 }
  2388     {
  2366     {
  2389         delete iFileDetails;
  2367         delete iFileDetails;
  2390         iFileDetails = NULL;
  2368         iFileDetails = NULL;
  2391     }
  2369     }
  2392 
  2370 
  2393     if ( iClipName )
       
  2394     {
       
  2395         delete iClipName;
       
  2396         iClipName = NULL;
       
  2397     }
       
  2398 
       
  2399     if ( iRecognizedMimeType )
  2371     if ( iRecognizedMimeType )
  2400     {
  2372     {
  2401         delete iRecognizedMimeType;
  2373         delete iRecognizedMimeType;
  2402         iRecognizedMimeType = NULL;
  2374         iRecognizedMimeType = NULL;
  2403     }
  2375     }
  2412     {
  2384     {
  2413         iFileHandle64.Close();
  2385         iFileHandle64.Close();
  2414     }
  2386     }
  2415 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
  2387 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
  2416 
  2388 
  2417     // reset to True
       
  2418     iSeekable = ETrue;
  2389     iSeekable = ETrue;
  2419 
  2390 
  2420     //
  2391     //
  2421     //  Needs to be last thing destroyed since PDL requires the
  2392     //  Needs to be last thing destroyed since PDL requires the
  2422     //  controller to be unloaded to move clip
  2393     //  controller to be unloaded to move clip
  2495 
  2466 
  2496     TBool fileExists = EFalse;
  2467     TBool fileExists = EFalse;
  2497 
  2468 
  2498     ChangeState( EMPXVideoInitializing );
  2469     ChangeState( EMPXVideoInitializing );
  2499 
  2470 
       
  2471     if ( iClipName )
       
  2472     {
       
  2473         delete iClipName;
       
  2474         iClipName = NULL;
       
  2475     }
       
  2476 
  2500     iClipName = aMediaFile.AllocL();
  2477     iClipName = aMediaFile.AllocL();
  2501     iAccessPointId = aAccessPointId;
  2478     iAccessPointId = aAccessPointId;
  2502 
  2479 
  2503     //
  2480     //
  2504     //  If file handle exists, duplicate it to the controller
  2481     //  If file handle exists, duplicate it to the controller
  2526     if ( ! iAccessoryMonitor )
  2503     if ( ! iAccessoryMonitor )
  2527     {
  2504     {
  2528         iAccessoryMonitor = CMPXVideoAccessoryObserver::NewL( this );
  2505         iAccessoryMonitor = CMPXVideoAccessoryObserver::NewL( this );
  2529     }
  2506     }
  2530 
  2507 
  2531     if ( iAccessoryMonitor->IsTvOutPlaybackAllowed() )
  2508     if ( fileExists )
  2532     {
  2509     {
  2533         if ( fileExists )
  2510         //
       
  2511         //  Ensure there are rights for protected clips
       
  2512         //
       
  2513         TInt drmError = iDrmHelper->GetDrmRightsStatus64( iFileHandle64 );
       
  2514 
       
  2515         if ( drmError )
  2534         {
  2516         {
  2535             //
  2517             //
  2536             //  Ensure there are rights for protected clips
  2518             //  Send error to observer for handling
  2537             //
  2519             //
  2538             TInt drmError = iDrmHelper->GetDrmRightsStatus64( iFileHandle64 );
  2520             HandleError( drmError );
  2539 
       
  2540             if ( drmError )
       
  2541             {
       
  2542                 //
       
  2543                 //  Send error to observer for handling
       
  2544                 //
       
  2545                 HandleError( drmError );
       
  2546             }
       
  2547             else
       
  2548             {
       
  2549                 iState->OpenFile64L( iFileHandle64 );
       
  2550             }
       
  2551         }
  2521         }
  2552         else
  2522         else
  2553         {
  2523         {
  2554             iState->OpenFileL( iClipName->Des() );
  2524             iState->OpenFile64L( iFileHandle64 );
  2555         }
  2525         }
  2556     }
  2526     }
  2557     else
  2527     else
  2558     {
  2528     {
  2559         HandleError( KMPXVideoTvOutPlaybackNotAllowedClose );
  2529         iState->OpenFileL( iClipName->Des() );
  2560     }
  2530     }
  2561 }
  2531 }
  2562 
  2532 
  2563 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
  2533 #endif // SYMBIAN_ENABLE_64_BIT_FILE_SERVER_API
  2564 
  2534