sl@0: /* sl@0: * Copyright (c) 2005-2008 Nokia Corporation and/or its subsidiary(-ies). sl@0: * All rights reserved. sl@0: * This component and the accompanying materials are made available sl@0: * under the terms of "Eclipse Public License v1.0" sl@0: * which accompanies this distribution, and is available sl@0: * at the URL "http://www.eclipse.org/legal/epl-v10.html". sl@0: * sl@0: * Initial Contributors: sl@0: * Nokia Corporation - initial contribution. sl@0: * sl@0: * Contributors: sl@0: * sl@0: * Description: sl@0: * sl@0: */ sl@0: sl@0: sl@0: /** sl@0: @file sl@0: @test sl@0: @internalComponent - Internal Symbian test code sl@0: */ sl@0: sl@0: /** sl@0: This test depends on the following environment: sl@0: sl@0: ========================================================================== sl@0: == Required step - Install Xvid codec sl@0: ========================================================================== sl@0: Note that these drivers are distributed under the GNU GENERAL PUBLIC LICENSE. sl@0: sl@0: ** Go to: sl@0: http://developer.symbian.com/wiki/display/pub/Open+source+projects sl@0: and get the XviD source zip: sl@0: http://developer.symbian.com/wiki/download/attachments/1154/xvid.zip sl@0: sl@0: ** Unzip this file and build the source in sl@0: xvidhwdevice\group sl@0: xvidpu\group sl@0: sl@0: sl@0: ========================================================================== sl@0: == Required step - Running on emulator - Modify epoc.ini and wsini.ini sl@0: ========================================================================== sl@0: sl@0: ** Update your epoc.ini so that GCE is enabled. Add: sl@0: ... sl@0: SYMBIAN_GRAPHICS_USE_GCE ON sl@0: SYMBIAN_BASE_USE_GCE ON sl@0: ... sl@0: sl@0: ** Update your wsini.ini so that the following is present: sl@0: ... sl@0: WINDOWMODE COLOR16MAP sl@0: KEYCLICKPLUGIN KeyClickRef sl@0: TRANSPARENCY sl@0: CHROMAKEYCOLOR 0xFFFF00FF sl@0: ... sl@0: sl@0: sl@0: ========================================================================== sl@0: == Required step - Running on hardware - Buildrom command sl@0: ========================================================================== sl@0: sl@0: ** When building the rom, make sure you use the following flags sl@0: buildrom sl@0: sl@0: -DSYMBIAN_BASE_USE_GCE sl@0: -DSYMBIAN_GRAPHICS_USE_GCE sl@0: -DUSE_24BPP_DISPLAY_VARIANT sl@0: sl@0: videoplay.iby sl@0: sl@0: sl@0: the xvid video drivers being installed in the runtime environment. sl@0: */ sl@0: sl@0: #include "tuiandvideo.h" sl@0: sl@0: #include sl@0: sl@0: #ifdef __WINS__ sl@0: _LIT(KDefaultDirName, "c:\\videoplay\\"); sl@0: #else sl@0: _LIT(KDefaultDirName, "e:\\videoplay\\"); sl@0: #endif sl@0: sl@0: _LIT(KDefaultFileExt, "*.avi"); sl@0: _LIT(KDefaultFile, "skiing2.avi"); sl@0: sl@0: const TTimeIntervalMicroSeconds KTapTimeOut(300*1000); sl@0: const TTimeIntervalMicroSeconds32 KIdleTimeOut(1*1000*1000); sl@0: const TTimeIntervalMicroSeconds32 KPlayTimeOut(2*1000*1000); sl@0: const TTimeIntervalMicroSeconds32 KButtonTimeOut(2*1000*1000); sl@0: sl@0: _LIT(KVideoAppBitmapsFile, "z:\\resource\\apps\\videoplay2.mbm"); sl@0: sl@0: //From videoplay.hrh sl@0: enum TTestCommands sl@0: { sl@0: ETestCmdOpen = 1000, sl@0: ETestCmdStop, sl@0: ETestCmdPlayFile sl@0: }; sl@0: sl@0: //UIBench test step commands sl@0: enum TTestStepCommand sl@0: { sl@0: ETestCmdInitialised = 0, sl@0: ETestCmdPlay, sl@0: ETestCmdPause, sl@0: ETestCmdBounce, sl@0: ETestCmdJump, sl@0: ETestCmdStill, sl@0: ETestCmdExit sl@0: }; sl@0: sl@0: // From videoplay.mbg sl@0: enum TMbmVideoplay sl@0: { sl@0: EMbmVideoplayBackground, sl@0: EMbmVideoplayBackground_mask, sl@0: }; sl@0: sl@0: sl@0: /** sl@0: A command handler to act as an interface through which to drive the test. sl@0: @param aController View controller, in the classic sense of MVC. This object sl@0: is used to drive the test. sl@0: */ sl@0: CCommandSink::CCommandSink (CTestAppView* aTestView) : sl@0: CActive(EPriorityStandard), sl@0: iTestView (aTestView) sl@0: { sl@0: CActiveScheduler::Add(this); sl@0: iStatus = KRequestPending; sl@0: SetActive(); sl@0: } sl@0: sl@0: void CCommandSink::DoCancel() sl@0: { sl@0: TRequestStatus* status = &iStatus; sl@0: User::RequestComplete(status, KErrNone); sl@0: } sl@0: sl@0: CCommandSink::~CCommandSink() sl@0: { sl@0: Cancel(); sl@0: } sl@0: sl@0: void CCommandSink::Init(RThread* aTargetThread, TRequestStatus* aTargetStatus) sl@0: { sl@0: iTargetThread = aTargetThread; sl@0: iTargetStatus = aTargetStatus; sl@0: } sl@0: sl@0: /** sl@0: Signals the control thread (target) with a command. There must be a protocol between the sl@0: controller and the control (the test thread) in terms of communication of command sl@0: signals. sl@0: */ sl@0: void CCommandSink::RunL () sl@0: { sl@0: switch (iStatus.Int()) sl@0: { sl@0: case ETestCmdPlay: sl@0: iTestView->PlayVideo(); sl@0: break; sl@0: case ETestCmdPause: sl@0: iTestView->PauseVideo(); sl@0: break; sl@0: case ETestCmdBounce: sl@0: case ETestCmdJump: sl@0: case ETestCmdStill: sl@0: iTestView->SetRunMode(iStatus.Int()); sl@0: break; sl@0: } sl@0: sl@0: iStatus = KRequestPending; sl@0: SetActive(); sl@0: } sl@0: sl@0: CTUiAndVideo::CTUiAndVideo() sl@0: { sl@0: SetTestStepName(KTUiAndVideo); sl@0: } sl@0: sl@0: void CTUiAndVideo::IssueCommand (TUint aCommand) sl@0: { sl@0: TRequestStatus* targetStatus = iAppUi->CommandSink(); sl@0: ConeThread()->RequestComplete(targetStatus, aCommand); sl@0: } sl@0: sl@0: void CTUiAndVideo::StepState (TUint aNextState, TUint aPause) sl@0: { sl@0: User::After(aPause); sl@0: TRequestStatus* testState = &iTestState; sl@0: User::RequestComplete (testState, aNextState); sl@0: } sl@0: sl@0: /** sl@0: @SYMTestCaseID GRAPHICS-UI-BENCH-XXXX sl@0: @SYMTestCaseDesc Put description here sl@0: @SYMTestActions Put description here sl@0: @SYMTestExpectedResults Put description here sl@0: */ sl@0: TVerdict CTUiAndVideo::doTestStepL() sl@0: { sl@0: iProfiler->InitResults(); sl@0: sl@0: StepState(ETestCmdInitialised, 0); sl@0: sl@0: TBool continueTest = ETrue; sl@0: while (continueTest) sl@0: { sl@0: User::WaitForRequest(iTestState); sl@0: switch (iTestState.Int()) sl@0: { sl@0: case ETestCmdInitialised: sl@0: User::After(5000000); sl@0: case ETestCmdPlay: sl@0: IssueCommand(ETestCmdPlay); sl@0: StepState(ETestCmdBounce, 5000000); sl@0: break; sl@0: case ETestCmdPause: sl@0: break; sl@0: case ETestCmdBounce: sl@0: IssueCommand(ETestCmdBounce); sl@0: StepState(ETestCmdJump, 15000000); sl@0: break; sl@0: case ETestCmdJump: sl@0: IssueCommand(ETestCmdJump); sl@0: StepState(ETestCmdExit, 15000000); sl@0: case ETestCmdExit: sl@0: continueTest = EFalse; sl@0: break; sl@0: default: sl@0: continueTest = EFalse; sl@0: RDebug::Printf("Invalid test state!"); sl@0: } sl@0: } sl@0: sl@0: return TestStepResult(); sl@0: } sl@0: sl@0: /** sl@0: Runs on test thread. sl@0: */ sl@0: void CTUiAndVideo::InitUIL(CCoeEnv* aCoeEnv) sl@0: { sl@0: iAppUi = new CTUiAndVideoAppUi(); sl@0: sl@0: iAppUi->ConstructL(iTestState); sl@0: aCoeEnv->SetAppUi(iAppUi); sl@0: } sl@0: sl@0: //############################################################################################################ sl@0: //############################################################################################################ sl@0: //############################################################################################################ sl@0: //############################################################################################################ sl@0: sl@0: //************************************************************************************************************ sl@0: // Application UI implementation sl@0: // -- most control logic is here sl@0: //************************************************************************************************************ sl@0: sl@0: void SetCenter(TRect& aRect, const TPoint& aCenterPoint) sl@0: { sl@0: const TSize size = aRect.Size(); sl@0: const TPoint pos(aCenterPoint-TSize(size.iWidth/2,size.iHeight/2).AsPoint()); sl@0: aRect.SetRect(pos, size); sl@0: } sl@0: sl@0: void CTUiAndVideoAppUi::ConstructL(TRequestStatus /*iCommandSource*/) sl@0: { sl@0: BaseConstructL(ENoAppResourceFile); sl@0: sl@0: // Calculate the size of the application window sl@0: // Make the player square, slightly (one 16th) smaller than sl@0: // the smallest side of the screen sl@0: TRect rect (0, 0, 300, 150); sl@0: sl@0: TRect screenRect = iCoeEnv->ScreenDevice()->SizeInPixels(); sl@0: SetCenter(rect, screenRect.Center()); // Center the rect on the screen sl@0: sl@0: // Create the application view sl@0: iAppView = CTestAppView::NewL(rect); sl@0: AddToStackL(iAppView); sl@0: sl@0: iCommandSink = new (ELeave) CCommandSink(iAppView); sl@0: sl@0: // Enable iIdleTimer to make the app return to foreground after a set delay sl@0: iIdleTimer = CPeriodic::NewL(CActive::EPriorityStandard); sl@0: // iUIMover moves the UI around the display. sl@0: iUIMover = CPeriodic::NewL(CActive::EPriorityStandard); sl@0: iUIMover->Start(KIdleTimeOut, 50000, TCallBack(UIMoverCallBack, this)); sl@0: // Enable iPlayTimer to make the video pause a little while before starting playing again sl@0: iPlayTimer = CPeriodic::NewL(CActive::EPriorityStandard); sl@0: sl@0: iAppView->SetPos(&rect.iTl); sl@0: iAppView->ActivateL(); sl@0: iAppView->DrawNow(); sl@0: sl@0: // Load default video clip sl@0: if (KErrNone == PopulateDirFilesL(KDefaultDirName)) sl@0: { sl@0: OpenSelectedFileL(KDefaultFile); sl@0: } sl@0: } sl@0: sl@0: TRequestStatus* CTUiAndVideoAppUi::CommandSink () sl@0: { sl@0: return &(iCommandSink->iStatus); sl@0: } sl@0: sl@0: CTUiAndVideoAppUi::~CTUiAndVideoAppUi() sl@0: { sl@0: if(iAppView) sl@0: { sl@0: RemoveFromStack(iAppView); sl@0: delete iAppView; sl@0: } sl@0: delete iCommandSink; sl@0: delete iIdleTimer; sl@0: delete iUIMover; sl@0: delete iPlayTimer; sl@0: delete iLoadingPlayer; sl@0: delete iDirList; sl@0: } sl@0: sl@0: TInt CTUiAndVideoAppUi::UIMoverCallBack(TAny* aSelf) sl@0: { sl@0: CTUiAndVideoAppUi* self = static_cast(aSelf); sl@0: self->SetPos(); sl@0: return KErrNone; sl@0: } sl@0: sl@0: void CTUiAndVideoAppUi::SetPos() sl@0: { sl@0: iAppView->SetPos(NULL); sl@0: } sl@0: sl@0: TInt CTUiAndVideoAppUi::PopulateDirFilesL(const TDesC& aDir) sl@0: { sl@0: // Load files in default folder sl@0: RFs fs; sl@0: User::LeaveIfError(fs.Connect()); sl@0: sl@0: // Get the file list, sorted by name - Only with KDefaultFileExt sl@0: TFileName dir(aDir); sl@0: dir.Append(KDefaultFileExt); sl@0: sl@0: delete iDirList; sl@0: iDirList = NULL; sl@0: TInt err = fs.GetDir(dir, KEntryAttMaskSupported, ESortByName, iDirList); sl@0: fs.Close(); sl@0: sl@0: if ((err == KErrPathNotFound) || (err == KErrNone && iDirList->Count()==0)) sl@0: { sl@0: LogError(KNullDesC, _L("Default clip not found!")); sl@0: return KErrNotFound; sl@0: } sl@0: __ASSERT_DEBUG(err==KErrNone, User::Panic(_L("PopulateDirFiles"), err)); sl@0: sl@0: // set the current file with the current folder (for the time being) sl@0: iCurrentFile.Zero(); sl@0: iCurrentFile.Append(aDir); sl@0: return KErrNone; sl@0: } sl@0: sl@0: void CTUiAndVideoAppUi::OpenSelectedFileL(const TDesC& aFile) sl@0: { sl@0: __ASSERT_DEBUG(iDirList, User::Panic(_L("iDirList"), 0)); sl@0: TBool defaultFound = EFalse; sl@0: for (iCurrentIndex=0; iCurrentIndex < iDirList->Count(); iCurrentIndex++) sl@0: { sl@0: TFileName fileName = (*iDirList)[iCurrentIndex].iName; sl@0: if (fileName.Compare(aFile) ==0) sl@0: { sl@0: defaultFound = ETrue; sl@0: break; sl@0: } sl@0: } sl@0: if (!defaultFound) sl@0: { sl@0: // To avoid linking with eikcore.lib sl@0: //iEikonEnv->InfoMsg(_L("Default file not found...")); sl@0: iCurrentIndex = 0; // if no default, pick the first movie on the list sl@0: } sl@0: sl@0: iCurrentFile.Append((*iDirList)[iCurrentIndex].iName); sl@0: // play the selected file. sl@0: HandleCommandL(ETestCmdOpen); sl@0: } sl@0: sl@0: TInt CTUiAndVideoAppUi::PlayNextFileL() sl@0: { sl@0: __ASSERT_DEBUG(iDirList, User::Panic(_L("iDirList"), 0)); sl@0: if (iCurrentIndex == (iDirList->Count()-1)) sl@0: { sl@0: return KErrNotFound; sl@0: } sl@0: iCurrentIndex++; sl@0: TParse file; sl@0: file.Set(iCurrentFile, NULL, NULL); sl@0: iCurrentFile = file.DriveAndPath(); sl@0: iCurrentFile.Append((*iDirList)[iCurrentIndex].iName); sl@0: HandleCommandL(ETestCmdOpen); sl@0: return KErrNone; sl@0: } sl@0: sl@0: TInt CTUiAndVideoAppUi::PlayPreviousFileL() sl@0: { sl@0: __ASSERT_DEBUG(iDirList, User::Panic(_L("iDirList"), 0)); sl@0: if (iCurrentIndex == 0) sl@0: { sl@0: return KErrNotFound; sl@0: } sl@0: iCurrentIndex--; sl@0: TParse file; sl@0: file.Set(iCurrentFile, NULL, NULL); sl@0: iCurrentFile = file.DriveAndPath(); sl@0: iCurrentFile.Append((*iDirList)[iCurrentIndex].iName); sl@0: HandleCommandL(ETestCmdOpen); sl@0: return KErrNone; sl@0: } sl@0: sl@0: void CTUiAndVideoAppUi::LogError(const TDesC& /* aFileName */, const TDesC& /* aErrorMsg */) sl@0: { sl@0: // TODO: Fix this logging strategy. Printf uses C-like pointers, not Symbian sl@0: // descriptors sl@0: //RDebug::Printf("Error: %s %s", aFileName, aErrorMsg); sl@0: if(iAppView) sl@0: iAppView->DisableVideo(); sl@0: } sl@0: sl@0: void CTUiAndVideoAppUi::HandleForegroundEventL(TBool aForeground) sl@0: { sl@0: if(!aForeground && iIdleTimer) sl@0: { sl@0: if(!iIdleTimer->IsActive()) sl@0: iIdleTimer->Start(KIdleTimeOut, 0, TCallBack(BackgroundCallBack, this) ); sl@0: } sl@0: } sl@0: sl@0: TInt CTUiAndVideoAppUi::BackgroundCallBack(TAny* aSelf) sl@0: { sl@0: CTUiAndVideoAppUi* self = static_cast(aSelf); sl@0: self->BringToForeground(); sl@0: return KErrNone; sl@0: } sl@0: sl@0: void CTUiAndVideoAppUi::BringToForeground() sl@0: { sl@0: iIdleTimer->Cancel(); sl@0: const TInt err = iCoeEnv->WsSession().SetWindowGroupOrdinalPosition(iCoeEnv->RootWin().Identifier(), 0); sl@0: } sl@0: sl@0: TInt CTUiAndVideoAppUi::PlayTimerCallBack(TAny* aSelf) sl@0: { sl@0: CTUiAndVideoAppUi* self = static_cast(aSelf); sl@0: self->iPlayTimer->Cancel(); sl@0: self->iAppView->PlayVideo(); sl@0: self->iInitialised = ETrue; sl@0: sl@0: return KErrNone; sl@0: } sl@0: sl@0: void CTUiAndVideoAppUi::HandleCommandL(TInt aCommand) sl@0: { sl@0: switch (aCommand) sl@0: { sl@0: case ETestCmdOpen: // Open and prepare sl@0: { sl@0: iAppView->DisableVideo(); sl@0: if(iLoadingPlayer) sl@0: { sl@0: iLoadingPlayer->RemoveDisplayWindow(const_cast(iAppView->TheWindow())); sl@0: iLoadingPlayer->Close(); sl@0: delete iLoadingPlayer; sl@0: iLoadingPlayer = NULL; sl@0: } sl@0: iLoadingPlayer = CVideoPlayerUtility2::NewL(*this, EMdaPriorityNormal, EMdaPriorityPreferenceNone); sl@0: iLoadingPlayer->OpenFileL(iCurrentFile); sl@0: break; sl@0: } sl@0: case ETestCmdPlay: // Start playback sl@0: iAppView->PlayVideo(); sl@0: break; sl@0: case ETestCmdStop: // Stop playback sl@0: iAppView->StopVideo(); sl@0: break; sl@0: case ETestCmdPlayFile: sl@0: break; sl@0: case EEikCmdExit: // Exit sl@0: if(iLoadingPlayer) sl@0: iLoadingPlayer->RemoveDisplayWindow(const_cast(iAppView->TheWindow())); sl@0: // Exit(); sl@0: break; sl@0: } sl@0: } sl@0: sl@0: // Video player utility callback: open complete sl@0: void CTUiAndVideoAppUi::MvpuoOpenComplete(TInt aError) sl@0: { sl@0: if (aError == KErrNone ) sl@0: { sl@0: iLoadingPlayer->Prepare(); sl@0: } sl@0: else if(aError == KErrNotFound) sl@0: LogError(iCurrentFile, _L("Clip not found!")); sl@0: else if(aError == KErrNotReady) sl@0: LogError(iCurrentFile, _L("Clip not ready!")); sl@0: else if(aError == KErrNotSupported) sl@0: LogError(iCurrentFile, _L("Clip format not supported!")); sl@0: else sl@0: { sl@0: User::Panic(_L("MvpuoOpen"), aError); sl@0: } sl@0: } sl@0: sl@0: // Video player utility callback: prepare complete sl@0: void CTUiAndVideoAppUi::MvpuoPrepareComplete(TInt aError) sl@0: { sl@0: switch ( aError ) sl@0: { sl@0: case KErrNone: sl@0: { sl@0: TBuf<256> loadingMsg(_L("Loading ")); sl@0: TParse file; sl@0: file.Set(iCurrentFile, NULL, NULL); sl@0: loadingMsg.Append(file.Name()); sl@0: sl@0: TRAPD(err, iLoadingPlayer->AddDisplayWindowL(iEikonEnv->WsSession(), *iEikonEnv->ScreenDevice(), iAppView->TheWindow())); sl@0: if(err == KErrInUse) sl@0: LogError(iCurrentFile, _L("Window Display in use!")); sl@0: else if(err == KErrNotReady) sl@0: LogError(iCurrentFile, _L("Window Display not ready!")); sl@0: else if(err) sl@0: User::Panic(_L("PrepareComplete1"), err); sl@0: sl@0: iAppView->EnableVideo(iLoadingPlayer); sl@0: } sl@0: break; sl@0: sl@0: case KErrMMPartialPlayback: sl@0: LogError(iCurrentFile, _L("Partial playback")); sl@0: break; sl@0: sl@0: default: sl@0: User::Panic(_L("Prepare"), aError); sl@0: } sl@0: } sl@0: sl@0: // Video player utility callback, not used sl@0: void CTUiAndVideoAppUi::MvpuoFrameReady(CFbsBitmap& /*aFrame*/, TInt aError) sl@0: { sl@0: User::Panic(_L("FrameReady"), aError); sl@0: } sl@0: sl@0: // Video player utility callback: play complete (error or EOF) sl@0: void CTUiAndVideoAppUi::MvpuoPlayComplete(TInt aError) sl@0: { sl@0: iAppView->PlayComplete(aError); sl@0: sl@0: if (aError == KErrNone) sl@0: { sl@0: if(iPlayTimer && !iPlayTimer->IsActive()) sl@0: iPlayTimer->Start(KPlayTimeOut, 0, TCallBack(PlayTimerCallBack, this)); sl@0: } sl@0: else if(aError == KErrNotSupported) sl@0: LogError(iCurrentFile, _L("Clip format not supported!")); sl@0: else if(aError == KErrTooBig) sl@0: LogError(iCurrentFile, _L("The clip is too big!")); sl@0: else if(aError == KErrNoMemory) sl@0: LogError(KNullDesC, _L("Out of memory. Likely memory leak!")); sl@0: else if(aError == KErrNotReady) sl@0: LogError(KNullDesC, _L("Clip not ready. Removed MMC?!")); sl@0: else if (aError) sl@0: User::Panic(_L("PlayComplete"), aError); sl@0: } sl@0: sl@0: // Video player utility callback: event (not used?) sl@0: void CTUiAndVideoAppUi::MvpuoEvent(const TMMFEvent& aEvent) sl@0: { sl@0: User::Panic(_L("Event"), aEvent.iErrorCode); sl@0: } sl@0: sl@0: sl@0: //************************************************************************************************************ sl@0: // View implementation sl@0: // -- draws the display sl@0: //************************************************************************************************************ sl@0: sl@0: CTestAppView* CTestAppView::NewL(const TRect& aRect) sl@0: { sl@0: CTestAppView* self = new(ELeave) CTestAppView(); sl@0: CleanupStack::PushL(self); sl@0: self->ConstructL(aRect); sl@0: CleanupStack::Pop(); sl@0: return self; sl@0: } sl@0: sl@0: CTestAppView::~CTestAppView() sl@0: { sl@0: if(iCurrentPlayer) sl@0: { sl@0: iCurrentPlayer->RemoveDisplayWindow(TheWindow()); sl@0: iCurrentPlayer->Close(); sl@0: delete iCurrentPlayer; sl@0: } sl@0: delete iBkgrdImage; sl@0: delete iBkgrdMask; sl@0: } sl@0: sl@0: CTestAppView::CTestAppView() : sl@0: iIncrement (2, 2), sl@0: iDirection (1, 1) sl@0: { sl@0: } sl@0: sl@0: RWindow& CTestAppView::TheWindow() sl@0: { sl@0: __ASSERT_ALWAYS(iVideoPane, User::Panic(_L("TheWindow"), 0)); sl@0: return iVideoPane->TheWindow(); sl@0: } sl@0: sl@0: void CTestAppView::ConstructL(const TRect& aWindowedRect) sl@0: { sl@0: iWindowedViewRect = aWindowedRect; // The rect used when the view is not full-screen sl@0: CreateWindowL(); sl@0: EnableWindowTransparency(); sl@0: EnableDragEvents(); sl@0: Window().SetPointerGrab(ETrue); sl@0: sl@0: InitComponentArrayL(); sl@0: sl@0: iVideoPane = new (ELeave) CVideoPane(); sl@0: Components().AppendLC(iVideoPane, KVideoControlID); sl@0: iVideoPane->ConstructL(*this); sl@0: CleanupStack::Pop(iVideoPane); sl@0: sl@0: SetRect(iWindowedViewRect); sl@0: sl@0: iBkgrdImage = new(ELeave) CFbsBitmap; sl@0: User::LeaveIfError(iBkgrdImage->Load(KVideoAppBitmapsFile, EMbmVideoplayBackground)); sl@0: sl@0: iBkgrdMask = new(ELeave) CFbsBitmap; sl@0: User::LeaveIfError(iBkgrdMask->Load(KVideoAppBitmapsFile, EMbmVideoplayBackground_mask)); sl@0: sl@0: ActivateL(); sl@0: } sl@0: sl@0: void CTestAppView::SizeChanged() sl@0: { sl@0: const TRect reservedVideoRect = VideoPaneRect(); sl@0: const TRect usedVideoRect = VideoPaneRect(); sl@0: sl@0: if(iVideoPane) sl@0: { sl@0: iVideoPane->BlackoutPane(); sl@0: iVideoPane->SetRect(reservedVideoRect); sl@0: if(iCurrentPlayer) sl@0: SetVideoSize(*iCurrentPlayer); sl@0: } sl@0: } sl@0: sl@0: /** sl@0: Sets the size and stretch characteristics of the video. sl@0: */ sl@0: void CTestAppView::SetVideoSize(CVideoPlayerUtility2& aVideo) const sl@0: { sl@0: const TRect videoRect(iVideoPane->Rect()); sl@0: sl@0: CTUiAndVideoAppUi* myAppUi = dynamic_cast(iCoeEnv->AppUi()); sl@0: sl@0: TRAPD(err, aVideo.SetWindowClipRectL(TheWindow(), videoRect)); sl@0: if(err == KErrArgument) sl@0: myAppUi->LogError(KNullDesC, _L("Clip rect not within window!")); sl@0: else if(err == KErrNotReady) sl@0: myAppUi->LogError(KNullDesC, _L("Video not ready!")); sl@0: else if(err) sl@0: User::Panic(_L("SetVideoSize2"), err); sl@0: #if 1 sl@0: TRAP(err, aVideo.SetAutoScaleL(TheWindow(), EAutoScaleStretch)); sl@0: if(err == KErrNotFound) sl@0: myAppUi->LogError(KNullDesC, _L("Window not added to iLoadingPlayer!")); sl@0: else if(err == KErrNotReady) sl@0: myAppUi->LogError(KNullDesC, _L("Controller not been opened!")); sl@0: else if(err) sl@0: User::Panic(_L("SetVideoSize2"), err); sl@0: #endif sl@0: iVideoPane->SetVideoUseRect(VideoPaneRect()); sl@0: } sl@0: sl@0: /** sl@0: @return The rect of the video pane, relative to the view. sl@0: */ sl@0: TRect CTestAppView::VideoPaneRect() const sl@0: { sl@0: TRect result = Rect(); sl@0: sl@0: // Make the video screen rect 10% smaller than the whole app window sl@0: result.Shrink(result.Width()/10, result.Height()/10); sl@0: return result; sl@0: } sl@0: sl@0: void CTestAppView::HandlePointerEventL(const TPointerEvent& aPointerEvent) sl@0: { sl@0: // call base class to dispatch any possible child events first sl@0: // except we don't want to enter into a loop if this method has alraedy been sl@0: // called from the video child control.... sl@0: if (!iVideoPane->IsVideoPanePointerEvent()) sl@0: CCoeControl::HandlePointerEventL(aPointerEvent); sl@0: sl@0: if(aPointerEvent.iType == TPointerEvent::EButton1Down) sl@0: { sl@0: // get the position (we may need to get the parent's if event came from video child control) sl@0: iPointerDownPos = iVideoPane->IsVideoPanePointerEvent() ? aPointerEvent.iParentPosition : aPointerEvent.iPosition; sl@0: TTime now; sl@0: now.UniversalTime(); sl@0: #if 0 sl@0: if(now.MicroSecondsFrom(iPointerDownTime) < KTapTimeOut) // If quick double-tap sl@0: { sl@0: IgnoreEventsUntilNextPointerUp(); sl@0: ToggleViewSize(); sl@0: } sl@0: #endif sl@0: iPointerDownTime.UniversalTime(); sl@0: } sl@0: else if(aPointerEvent.iType == TPointerEvent::EDrag) sl@0: { sl@0: // Set new position relative to the amount of movement with pointer down event sl@0: TPoint newPos = (iVideoPane->IsVideoPanePointerEvent() ? aPointerEvent.iParentPosition : aPointerEvent.iPosition) - iPointerDownPos; sl@0: if(newPos != TPoint()) sl@0: SetPosition(Position()+newPos); sl@0: } sl@0: } sl@0: sl@0: TKeyResponse CTestAppView::OfferKeyEventL(const TKeyEvent& aKeyEvent, TEventCode aType) sl@0: { sl@0: if(aType == EEventKey) sl@0: { sl@0: switch(aKeyEvent.iCode) sl@0: { sl@0: case EKeyEscape: sl@0: // To avoid linking with eikcore.lib sl@0: //if(iEikonEnv->QueryWinL(_L("Exit?"), _L("Sure you want to exit?"))) sl@0: { sl@0: iEikonEnv->EikAppUi()->HandleCommandL(EEikCmdExit); sl@0: return EKeyWasConsumed; sl@0: } sl@0: case EKeyLeftArrow: sl@0: PlayPrevious(); sl@0: return EKeyWasConsumed; sl@0: case EKeyRightArrow: sl@0: PlayNext(); sl@0: return EKeyWasConsumed; sl@0: case EKeySpace: sl@0: if (iIsPlaying) sl@0: PauseVideo(); sl@0: else sl@0: PlayVideo(); sl@0: sl@0: return EKeyWasConsumed; sl@0: case EKeyEnter: sl@0: iRunMode = ETestCmdStill; sl@0: return EKeyWasConsumed; sl@0: case EKeyTab: sl@0: return EKeyWasConsumed; sl@0: default: sl@0: break; sl@0: } sl@0: } sl@0: sl@0: return EKeyWasNotConsumed; sl@0: } sl@0: sl@0: void CTestAppView::Draw(const TRect& /*aRect*/) const sl@0: { sl@0: CWindowGc& gc = SystemGc(); sl@0: sl@0: // Fill the window solid sl@0: gc.SetDrawMode(CGraphicsContext::EDrawModePEN); sl@0: gc.SetBrushStyle(CGraphicsContext::ENullBrush); sl@0: gc.DrawBitmapMasked(Rect(), iBkgrdImage, iBkgrdImage->SizeInPixels(), iBkgrdMask, EFalse); sl@0: } sl@0: sl@0: void CTestAppView::HandleControlEventL(CCoeControl */*aControl*/, TCoeEvent /*aEventType*/) sl@0: { sl@0: return; sl@0: } sl@0: sl@0: // Enable video sl@0: void CTestAppView::EnableVideo(CVideoPlayerUtility2*& aPlayer) sl@0: { sl@0: if(iCurrentPlayer) sl@0: { sl@0: iCurrentPlayer->RemoveDisplayWindow(TheWindow()); sl@0: iCurrentPlayer->Close(); sl@0: delete iCurrentPlayer; sl@0: } sl@0: sl@0: iCurrentPlayer = aPlayer; sl@0: aPlayer = NULL; // Take ownership sl@0: const TSize oldSize = iNativeVideoSize; sl@0: iCurrentPlayer->VideoFrameSizeL(iNativeVideoSize); sl@0: SetVideoSize(*iCurrentPlayer); sl@0: if (oldSize!=iNativeVideoSize) sl@0: SizeChanged(); sl@0: sl@0: #if 0 sl@0: // Was getting a crash at startup on the emulator...not sure why. sl@0: // Not currently a requirement. sl@0: #ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT sl@0: if (iCurrentPlayer->SubtitlesAvailable()) sl@0: { sl@0: iCurrentPlayer->EnableSubtitlesL(); sl@0: iVideoPane->EnableSubtitle(iCurrentPlayer); sl@0: } sl@0: #endif sl@0: #endif sl@0: PlayVideo(); sl@0: } sl@0: sl@0: // Disable video sl@0: void CTestAppView::DisableVideo() sl@0: { sl@0: iVideoPane->BlackoutPane(); sl@0: PauseVideo(); // Stop playing sl@0: sl@0: if(iCurrentPlayer) sl@0: { sl@0: iCurrentPlayer->RemoveDisplayWindow(TheWindow()); sl@0: iCurrentPlayer->Close(); sl@0: delete iCurrentPlayer; sl@0: } sl@0: iVideoPane->EnableSubtitle(NULL); sl@0: iCurrentPlayer = NULL; sl@0: iNativeVideoSize = TSize(); sl@0: } sl@0: sl@0: void CTestAppView::SetRunMode (TUint32 aMode) sl@0: { sl@0: iRunMode = aMode; sl@0: } sl@0: sl@0: void CTestAppView::PlayVideo() sl@0: { sl@0: if(iCurrentPlayer && !iIsPlaying) sl@0: { sl@0: iCurrentPlayer->Play(); sl@0: iIsPlaying = ETrue; sl@0: } sl@0: else sl@0: iIsPlaying = EFalse; // Can't play if there's no player sl@0: sl@0: UpdateButtonState(); sl@0: DrawNow(); sl@0: } sl@0: sl@0: void CTestAppView::PauseVideo() sl@0: { sl@0: if(iCurrentPlayer && iIsPlaying) sl@0: { sl@0: TRAPD(err, iCurrentPlayer->PauseL()); sl@0: if(err) sl@0: iCurrentPlayer->Stop(); sl@0: } sl@0: sl@0: iIsPlaying = EFalse; sl@0: UpdateButtonState(); sl@0: DrawNow(); sl@0: } sl@0: sl@0: void CTestAppView::StopVideo() sl@0: { sl@0: if(iCurrentPlayer && iIsPlaying) sl@0: { sl@0: iCurrentPlayer->Stop(); sl@0: iIsPlaying = EFalse; sl@0: } sl@0: else sl@0: iIsPlaying = ETrue; // Can't play if there's no player sl@0: sl@0: UpdateButtonState(); sl@0: DrawNow(); sl@0: } sl@0: sl@0: void CTestAppView::PlayComplete(TInt /*aError*/) sl@0: { sl@0: iIsPlaying = EFalse; sl@0: UpdateButtonState(); sl@0: DrawNow(); sl@0: } sl@0: sl@0: void CTestAppView::PlayPrevious() sl@0: { sl@0: CTUiAndVideoAppUi* myAppUi = dynamic_cast(iCoeEnv->AppUi()); sl@0: if (myAppUi->PlayPreviousFileL() != KErrNone) sl@0: { sl@0: // To avoid linking with eikcore.lib sl@0: //EikonEnv->InfoMsg(_L("First clip")); sl@0: } sl@0: } sl@0: sl@0: void CTestAppView::PlayNext() sl@0: { sl@0: CTUiAndVideoAppUi* myAppUi = dynamic_cast(iCoeEnv->AppUi()); sl@0: if (myAppUi->PlayNextFileL() != KErrNone) sl@0: { sl@0: // To avoid linking with eikcore.lib sl@0: //iEikonEnv->InfoMsg(_L("Last clip")); sl@0: } sl@0: } sl@0: sl@0: void CTestAppView::UpdateButtonState() sl@0: { sl@0: } sl@0: sl@0: /** sl@0: Calculate and set the position of the video UI. If iAutoPosition is zero then this sl@0: method is a no-op. sl@0: */ sl@0: void CTestAppView::SetPos(TPoint* aPos) sl@0: { sl@0: if (!aPos) sl@0: { sl@0: TRect screenRect = iCoeEnv->ScreenDevice()->SizeInPixels(); sl@0: sl@0: TSize currentSize = Size(); sl@0: TPoint currentPos = Position(); sl@0: sl@0: switch (iRunMode) sl@0: { sl@0: case (ETestCmdBounce): sl@0: { sl@0: if ((currentPos.iX + (currentSize.iWidth >> 1)) > screenRect.iBr.iX) sl@0: iDirection.iX = -1; sl@0: sl@0: if ((currentPos.iY + (currentSize.iHeight >> 1)) > screenRect.iBr.iY) sl@0: iDirection.iY = -1; sl@0: sl@0: if ((currentPos.iX + (currentSize.iWidth >> 1)) < 0) sl@0: iDirection.iX = 1; sl@0: sl@0: if ((currentPos.iY + (currentSize.iHeight >> 1)) < 0) sl@0: iDirection.iY = 1; sl@0: sl@0: iVidPos.iX += iIncrement.iX* iDirection.iX; sl@0: iVidPos.iY += iIncrement.iY * iDirection.iY; sl@0: break; sl@0: } sl@0: case (ETestCmdJump): sl@0: { sl@0: iVidPos.iX = Math::Random() % 100;//(screenRect.iBr.iX + (currentSize.iWidth >> 1)); sl@0: iVidPos.iY = Math::Random() % 100;//(screenRect.iBr.iY + (currentSize.iHeight >> 1)); sl@0: break; sl@0: } sl@0: default: sl@0: {} // Do nothing. sl@0: sl@0: } sl@0: } sl@0: else sl@0: { sl@0: iVidPos = *aPos; sl@0: } sl@0: sl@0: SetPosition(iVidPos); sl@0: } sl@0: sl@0: //************************************************************************************************************ sl@0: //** CVideoPane class - place 'video' window. sl@0: //************************************************************************************************************ sl@0: sl@0: /** sl@0: This controll is used so that the video is not rendered onto transparency. sl@0: */ sl@0: CVideoPane::~CVideoPane() sl@0: { sl@0: } sl@0: sl@0: CVideoPane::CVideoPane() sl@0: { sl@0: } sl@0: sl@0: void CVideoPane::ConstructL(CCoeControl& aParent) sl@0: { sl@0: CreateWindowL(&aParent); sl@0: EnableDragEvents(); sl@0: Window().SetPointerGrab(ETrue); sl@0: } sl@0: sl@0: void CVideoPane::HandlePointerEventL(const TPointerEvent& aPointerEvent) sl@0: { sl@0: // we need to set this flag to true, which is checked in the parent to avoid loops sl@0: iIsVideoPanePointerEvent = ETrue; sl@0: TRAPD(err, Parent()->HandlePointerEventL(aPointerEvent)); sl@0: iIsVideoPanePointerEvent = EFalse; sl@0: User::LeaveIfError(err); sl@0: } sl@0: sl@0: sl@0: void CVideoPane::BlackoutPane() sl@0: { sl@0: iVideoUseRect = TRect(); // reset sl@0: } sl@0: sl@0: void CVideoPane::SetVideoUseRect(const TRect& aRect) sl@0: { sl@0: iVideoUseRect = aRect; sl@0: iVideoUseRect.Move(-Position()); // Compensate for the fact that the pane is window owning sl@0: } sl@0: sl@0: void CVideoPane::SizeChanged() sl@0: { sl@0: CCoeControl::SizeChanged(); sl@0: iVideoUseRect = TRect(); // reset sl@0: } sl@0: sl@0: TBool CVideoPane::IsVideoPanePointerEvent() sl@0: { sl@0: return iIsVideoPanePointerEvent; sl@0: } sl@0: sl@0: void CVideoPane::EnableSubtitle(CVideoPlayerUtility2* aSubtitlePlayer) sl@0: { sl@0: iSubtitlePlayer = aSubtitlePlayer; sl@0: } sl@0: sl@0: void CVideoPane::Draw(const TRect& aRect) const sl@0: { sl@0: (void)aRect; //to remove warning if SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT not defined sl@0: CWindowGc& gc=SystemGc(); sl@0: #ifdef _DEBUG sl@0: gc.SetBrushColor(KRgbRed); sl@0: #else sl@0: gc.SetBrushColor(KRgbBlack); sl@0: #endif sl@0: DrawUtils::ClearBetweenRects(gc, Rect(), iVideoUseRect); sl@0: sl@0: #ifdef SYMBIAN_MULTIMEDIA_SUBTITLE_SUPPORT sl@0: if (iSubtitlePlayer) sl@0: iSubtitlePlayer->RedrawSubtitle(Window(), aRect); sl@0: #endif sl@0: }