videoengine.cpp
上传用户:xinrui0099
上传日期:2010-03-05
资源大小:48k
文件大小:12k
- /*
- * ============================================================================
- * Name : CVideoEngine from CVideoEngine.h
- * Part of : Video
- * Created : 10/14/2003 by Forum Nokia
- * Implementation notes:
- *
- * Version :
- * Copyright: Nokia Corporation, 2003
- * ============================================================================
- */
- #include "videoengine.h"
- #include <eikenv.h>
- #include <VideoPlayer.h>
- #include <mmferrors.h>
- #include "MPlayerUIControllerListener.h"
- #include <documenthandler.h>
- #include "VideoFileDetails.h"
- #include <drmcommon.h>
- #include <f32file.h>
- /*
- -----------------------------------------------------------------------------
- CVideoEngine* CVideoEngine::NewL( )
- Description: Create an engine object
- Comments:
- Return values: CVideoEngine object pointer
- -----------------------------------------------------------------------------
- */
- CVideoEngine* CVideoEngine::NewL( )
- {
- CVideoEngine* self =
- new (ELeave) CVideoEngine( );
-
- CleanupStack::PushL( self );
- self->ConstructL( );
- CleanupStack::Pop();
- return self;
- }
- /*
- -----------------------------------------------------------------------------
- CVideoEngine::CVideoEngine( )
- Description: Constructor
- Comments:
- Return values: N/A
- -----------------------------------------------------------------------------
- */
- CVideoEngine::CVideoEngine( )
- {
- }
- /*
- -----------------------------------------------------------------------------
- CVideoEngine::ConstructL()
- Description: Second-phase constructor
- Comments:
- Return values: N/A
- -----------------------------------------------------------------------------
- */
- void CVideoEngine::ConstructL()
- {
- iMediaFile = HBufC::NewL(0);
- iMyState = EPNotInitialised;
- iFileDetails = new (ELeave) CVideoFileDetails();
- // Create a progress updater
- iProgressUpdater = CHeartbeat::NewL(0);
- }
- /*
- -----------------------------------------------------------------------------
- CVideoEngine::~CVideoEngine()
- Description: Destructor
- Comments:
- Return values: N/A
- -----------------------------------------------------------------------------
- */
- CVideoEngine::~CVideoEngine()
- {
- delete iDocHandler;
- delete iMediaFile;
- delete iFileDetails;
- delete iProgressUpdater;
- }
- /*
- -----------------------------------------------------------------------------
- void CVideoEngine::SetNewFileL(const TDesC &aFileName)
- Description : Set a file name for a video clip
- Comments : Possibly, we need to do something here to verify the file
- existence.
- Return values: N/A
- -----------------------------------------------------------------------------
- */
- void CVideoEngine::SetNewFileL(const TDesC &aFileName)
- {
- HBufC* newFile = aFileName.AllocL();
- delete iMediaFile; // after the AllocL succeeds
- iMediaFile = newFile;
- }
- /*
- -----------------------------------------------------------------------------
- void CVideoEngine::DoPlayL()
- Description : Play a video clip
- Comments :
- Return values: N/A
- -----------------------------------------------------------------------------
- */
- void CVideoEngine::DoPlayL()
- {
- // If the engine is not in the paused state, start the progress update.
- if ( !iProgressUpdater->IsActive())
- {
- iProgressUpdater->Start(ETwelveOClock,this);
- }
- iPlayer->Play();
- switch ( iMyState )
- {
- case EPStopped:
- {
- iPlayPosition = 0;
- iCallback->PlaybackPositionChangedL(iPlayPosition,iFileDetails->iDurationInSeconds);
- break;
- }
- case EPPaused:
- iCallback->PlaybackPositionChangedL(iPlayPosition,iFileDetails->iDurationInSeconds);
- break;
- default:
- break;
- }
- iMyState = EPPlaying;
- }
- /*
- -----------------------------------------------------------------------------
- void CVideoEngine::DoStop()
- Description : Stop a playing video clip
- Comments :
- Return values: N/A
- -----------------------------------------------------------------------------
- */
- void CVideoEngine::DoStop()
- {
- if ( iMyState != EPPlaying && iMyState != EPPaused )
- return;
- if (iProgressUpdater->IsActive())
- {
- iProgressUpdater->Cancel();
- }
- iPlayPosition = 0;
- iPlayer->Stop();
- iPlayer->Close();
- iMyState = EPStopped;
- }
- /*
- -----------------------------------------------------------------------------
- void CVideoEngine::MvpuoOpenComplete(TInt aError )
- Description : File open is completed
- Comments :
- Return values: N/A
- -----------------------------------------------------------------------------
- */
- void CVideoEngine::MvpuoOpenComplete(TInt /*aError*/ )
- {
- // Prepare for the loading the file
- iPlayer->Prepare();
- }
- /*
- -----------------------------------------------------------------------------
- void CVideoEngine::MvpuoFrameReady(CFbsBitmap& aFrame,TInt aError)
- Description : Frame is ready
- Comments :
- Return values: N/A
- -----------------------------------------------------------------------------
- */
- void CVideoEngine::MvpuoFrameReady(CFbsBitmap& /*aFrame*/,TInt /*aError*/)
- {
- // do nothing...
- }
- /*
- -----------------------------------------------------------------------------
- void CVideoEngine::MvpuoPlayComplete(TInt aError)
- Description : Play is complete
- Comments :
- Return values: N/A
- -----------------------------------------------------------------------------
- */
- void CVideoEngine::MvpuoPlayComplete(TInt aError)
- {
- if (iProgressUpdater->IsActive())
- {
- iProgressUpdater->Cancel();
- }
- iPlayPosition = 0;
- iCallback->PlayCompletedL(aError);
- iMyState = EPStopped;
- iPlayer->Close();
- }
- /*
- -----------------------------------------------------------------------------
- void CVideoEngine::MvpuoPrepareComplete(TInt aError )
- Description : Prepare is complete
- Comments :
- Return values: N/A
- -----------------------------------------------------------------------------
- */
- void CVideoEngine::MvpuoPrepareComplete(TInt aError )
- {
-
- TInt ret = aError;
-
- iMyState = EPStopped;
- iFileDetails->iDurationInSeconds = 0;
- if ( ret == KErrNone || ret == KErrMMPartialPlayback )
- {
- TSize size( 0, 0 );
- iPlayer->VideoFrameSizeL(size);
- iFileDetails->iResolutionHeight = size.iHeight;
- iFileDetails->iResolutionWidth = size.iWidth;
- // Is there any audio track?
- iFileDetails->iAudioTrack = iPlayer->AudioEnabledL();
-
- // video track
- iFileDetails->iVideoTrack = iPlayer->VideoBitRateL();
-
- // duration of the video clip
- iFileDetails->iDurationInSeconds = iPlayer->DurationL().Int64() / KMPOneSecond;
- }
- if ( iCallback )
- {
- TRAPD( ignore,iCallback->InitControllerCompletedL( ret ) );
- }
- }
- /*
- -----------------------------------------------------------------------------
- void CVideoEngine::MvpuoEvent(const TMMFEvent& aEvent)
- Description : Mvpuo Event
- Comments :
- Return values: N/A
- -----------------------------------------------------------------------------
- */
- void CVideoEngine::MvpuoEvent(const TMMFEvent& aEvent)
- {
- // Higher priority application has taken over the audio device. --> Do pause.
- if (aEvent.iEventType == KMMFEventCategoryVideoPlayerGeneralError &&
- aEvent.iErrorCode == KErrHardwareNotAvailable)
- {
- TRAPD(ignore,iCallback->PlayCompletedL(KErrAudioLost));
- }
- }
- /*
- -----------------------------------------------------------------------------
- void CVideoEngine::InitControllerL( MPlayerUIControllerListener* aCallback,
- RWsSession& aWs,
- CWsScreenDevice& aScreenDevice,
- RWindowBase& aWindow,
- TRect& aScreenRect,
- TRect& aClipRect )
- Description : Initialize the video controller
- Comments :
- Return values: N/A
- -----------------------------------------------------------------------------
- */
- void CVideoEngine::InitControllerL( MPlayerUIControllerListener* aCallback,
- RWsSession& aWs,
- CWsScreenDevice& aScreenDevice,
- RWindowBase& aWindow,
- TRect& aScreenRect,
- TRect& aClipRect )
- {
- iMyState = EPInitialising;
- iCallback = aCallback;
-
- delete iPlayer;
- iPlayer = NULL;
- iPlayer = CVideoPlayerUtility::NewL( *this, EMdaPriorityNormal,
- EMdaPriorityPreferenceNone, aWs,
- aScreenDevice,aWindow,aScreenRect,
- aClipRect );
- iPlayer->OpenFileL( iMediaFile->Des() );
- }
- /*
- -----------------------------------------------------------------------------
- CDocumentHandler& CVideoEngine::DocumentHandlerL()
- Description: Open the video clip using a document handler
- Comments :
- Return values: None
- -----------------------------------------------------------------------------
- */
- CDocumentHandler& CVideoEngine::DocumentHandlerL()
- {
- if( !iDocHandler )
- {
- iDocHandler = CDocumentHandler::NewL( CEikonEnv::Static()->Process() );
- }
- return *iDocHandler;
- }
- /*
- -----------------------------------------------------------------------------
- void CVideoEngine::Beat()
- Description: it is called when the periodic timer times out, provided by
- MBeating interface.
- Comments :
- Return values: None
- -----------------------------------------------------------------------------
- */
- void CVideoEngine::Beat()
- {
- // keep backlights on if clip has video
- if ( iFileDetails->iVideoTrack )
- {
- User::ResetInactivityTime();
- }
- if ( iMyState != EPPlaying )
- return;
- TInt64 ret = iPlayPosition%2;
-
- if ( ret.GetTInt() )
- {
- iPlayPosition = iPlayPosition + 1;
- if (iCallback)
- {
- TRAPD(ignore,iCallback->PlaybackPositionChangedL(iPlayPosition,iFileDetails->iDurationInSeconds));
- }
- }
- else
- {
- Synchronize();
- }
- }
- /*
- -----------------------------------------------------------------------------
- void CVideoEngine::Synchronize()
- Description: If one or more heartbeats are missed then the
- MBeating::Synchronize() function is called
- Comments :
- Return values: None
- -----------------------------------------------------------------------------
- */
- void CVideoEngine::Synchronize()
- {
- if ( iMyState != EPPlaying )
- return;
-
- TRAPD( ignore,
- // if live stream, fake progress
- iPlayPosition = iPlayer->PositionL().Int64() / KMPOneSecond;
-
- if (iCallback)
- {
- iCallback->PlaybackPositionChangedL(iPlayPosition,iFileDetails->iDurationInSeconds);
- }
- );
- }
- /*
- -----------------------------------------------------------------------------
- TInt CVideoEngine::GetEngineState()
- Description: Get the video engine state.
- Comments :
- Return values: None
- -----------------------------------------------------------------------------
- */
- TInt CVideoEngine::GetEngineState()
- {
- return iMyState;
- }
- /*
- -----------------------------------------------------------------------------
- void CVideoEngine::DoPauseL()
- Description: Pause a playing video if it is playing.
- Comments:
- Return values: None
- -----------------------------------------------------------------------------
- */
- void CVideoEngine::DoPauseL()
- {
- if ( iMyState == EPPlaying )
- {
- if (iProgressUpdater->IsActive())
- {
- iProgressUpdater->Cancel();
- }
- iPlayer->PauseL();
- iMyState = EPPaused;
- }
- }