First public contribution.
1 // Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
2 // All rights reserved.
3 // This component and the accompanying materials are made available
4 // under the terms of "Eclipse Public License v1.0"
5 // which accompanies this distribution, and is available
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
16 #include <mmf/devvideo/videoplayhwdevice.h>
17 #include <mmf/server/mmfdatabuffer.h>
18 #include "videoplayfile.h"
20 #include "../../PU/video/src/Plugin/VideoTestDecoderPU/videotestdecoderpu.hrh"
21 #include "../../PU/video/src/Plugin/VideoTestEncoderPU/videotestencoderpu.hrh"
23 const TInt KInputBufferSize = 8192;
24 const TInt KFilePositionZero = 0;
25 const TInt KTBufSize = 256;
26 const TInt KTRegionFixSize = 1;
28 // **************************************************
29 // instructs the Hw Device Adapter to play a file
30 // **************************************************
31 CPlayVideoFile::CPlayVideoFile(RTestStepVideoCodecs* aParent) :
32 CActive(EPriorityNormal),
33 iState(EHwDeviceInit),
38 void CPlayVideoFile::ConstructL()
40 CActiveScheduler::Add(this);
41 User::LeaveIfError(RFbsSession::Connect());
44 TRAP(err, iScreenDevice = CFbsScreenDevice::NewL(_L(""),EColor16MA));
45 if (err == KErrNotSupported)
47 TRAP(err, iScreenDevice = CFbsScreenDevice::NewL(_L(""),EColor16M));
49 if (err == KErrNotSupported)
51 TRAP(err, iScreenDevice = CFbsScreenDevice::NewL(_L(""),EColor64K));
53 if (err == KErrNotSupported)
55 TRAP(err, iScreenDevice = CFbsScreenDevice::NewL(_L(""),EColor4K));
57 if (err == KErrNotSupported)
59 TRAP(err, iScreenDevice = CFbsScreenDevice::NewL(_L(""),EColor256));
61 if (err == KErrNotSupported)
63 iScreenDevice = CFbsScreenDevice::NewL(_L(""),EColor16MAP);
67 User::LeaveIfError(err);
71 CPlayVideoFile* CPlayVideoFile::NewL(RTestStepVideoCodecs* aParent)
73 CPlayVideoFile* self = new (ELeave) CPlayVideoFile(aParent);
74 CleanupStack::PushL(self);
76 CleanupStack::Pop(self);
81 void CPlayVideoFile::DoCancel()
85 CPlayVideoFile::~CPlayVideoFile()
90 delete iVideoHwDevice;
92 RFbsSession::Disconnect();
96 void CPlayVideoFile::LoadCodecL()
98 iParent->InfoMessage(_L("Loading Hw Device Adapter and PU Codec"));
100 RImplInfoPtrArray array;
101 REComSession::ListImplementationsL(TUid::Uid(KUidMdfProcessingUnit), array);
102 TBool found = EFalse;
103 CImplementationInformation* info = NULL;
104 for (TInt i=0;i<array.Count() && !found;i++)
107 if (info->ImplementationUid() == TUid::Uid(KUidVideoTestDecoderPu))
112 TInt err = KErrNotFound;
115 TRAP(err, iVideoHwDevice = CMMFVideoDecodeHwDevice::NewPuAdapterL(*info,*this));
121 array.ResetAndDestroy();
122 User::LeaveIfError(err);
126 void CPlayVideoFile::SetDSA(TBool aUseDSA)
128 // Need new version of this to load from a PU based uid
132 void CPlayVideoFile::StartPlaybackL()
135 SetState(EHwDeviceInit);
136 CActiveScheduler::Start();
139 void CPlayVideoFile::SetState(TPlayVideoFileState aState)
143 TRequestStatus* status = &iStatus;
144 User::RequestComplete(status, KErrNone);
147 void CPlayVideoFile::OpenTestFileL()
150 buf.Format(_L("Opening test input file %S"), &KTestPlaybackFile);
151 iParent->InfoMessage(buf);
152 User::LeaveIfError(iFs.Connect());
153 User::LeaveIfError(iFile.Open(iFs, KTestPlaybackFile, EFileRead));
156 void CPlayVideoFile::RunL()
162 iParent->InfoMessage(_L("State: EHwDeviceInit"));
163 TRAPD(err, InitializeL());
166 CleanupAndSetDeviceError(_L("Cannot intialize HwDevice"));
171 case EHwDeviceStartDecode:
173 // if we are playing a file, first we have to open the file
174 iParent->InfoMessage(_L("State: EHwDeviceStartDecode"));
175 TRAPD(err, StartDecodeL());
178 CleanupAndSetDeviceError(_L("Cannot start decoding"));
183 case EHwDeviceAllowToComplete:
184 iParent->InfoMessage(_L("State: EHwDeviceAllowToComplete"));
188 iParent->InfoMessage(_L("State: EHwDeviceDeviceDone"));
190 CActiveScheduler::Stop();
196 buf.Format(_L("State: EHwDeviceDeviceError %d"), iError);
197 iParent->SetVerdict(buf, EFail);
199 CActiveScheduler::Stop();
204 CleanupAndSetDeviceError(_L("Unknown CPlayVideoFile iState"));
211 void CPlayVideoFile::InitializeL()
213 iParent->InfoMessage(_L("InitializeL()"));
215 TUncompressedVideoFormat reqFormat;
216 reqFormat.iDataFormat = ERgbFbsBitmap;
217 reqFormat.iRgbFormat = EFbsBitmapColor16M;
218 RArray<TUncompressedVideoFormat> decodeFormats;
219 iVideoHwDevice->GetOutputFormatListL(decodeFormats);
220 CleanupClosePushL(decodeFormats);
221 User::LeaveIfError(decodeFormats.Find(reqFormat));
223 iParent->InfoMessage(_L("Call VideoHwDevice->SetOutputFormat()"));
224 iVideoHwDevice->SetOutputFormatL(reqFormat);
225 CleanupStack::PopAndDestroy(&decodeFormats);
227 CMMFDescriptorBuffer* buffer = CMMFDescriptorBuffer::NewL(KInputBufferSize);
228 CleanupStack::PushL(buffer);
229 TVideoInputBuffer inputBuffer;
231 TDes8& des = buffer->Data();
232 // read header data from file
233 User::LeaveIfError(iFile.Read(des));
234 TInt pos = KFilePositionZero;
235 // seek back to start
236 User::LeaveIfError(iFile.Seek(ESeekStart, pos));
239 buf.Format(_L("Read header of size %d"),inputBuffer.iData.Length());
240 iParent->InfoMessage(buf);
245 inputBuffer.iData.Set(&des[0],des.Length(),des.MaxLength());
247 iParent->InfoMessage(_L("Call VideoHwDevice GetHeaderInformationL()"));
248 TVideoPictureHeader* header = iVideoHwDevice->GetHeaderInformationL(EDuArbitraryStreamSection,
252 iFrameSize = header->iSizeInMemory;
253 iVideoHwDevice->ReturnHeader(header);
257 // Cannot read any data from file, so no point in continuing
258 User::Leave(KErrCorrupt);
261 CleanupStack::PopAndDestroy(buffer);
263 iParent->InfoMessage(_L("Call VideoHwDevice SetVideoDestScreenL()"));
264 iVideoHwDevice->SetVideoDestScreenL(iUseDSA);
266 iParent->InfoMessage(_L("Call VideoHwDevice->Initialize()"));
267 iVideoHwDevice->Initialize();
271 void CPlayVideoFile::StartDecodeL()
273 iParent->InfoMessage(_L("StartDecodeL()"));
277 StartDirectScreenAccessL();
279 // tell the HwDeviceAdapter to play the file
280 iParent->InfoMessage(_L("Call VideoHwDevice->Start()"));
281 iVideoHwDevice->Start();
285 void CPlayVideoFile::ReadNextBufferL()
287 // check that we aren't waiting for the input buffer to be returned
288 iParent->InfoMessage(_L("ReadNextBufferL()"));
289 TVideoInputBuffer* inputBuffer = iVideoHwDevice->GetBufferL(KInputBufferSize);
293 buf.Format(_L("inputBuffer size %d"),inputBuffer->iData.Length());
294 iParent->InfoMessage(buf);
295 User::LeaveIfError(iFile.Read(inputBuffer->iData));
296 buf.Format(_L("Read from file %d bytes"),inputBuffer->iData.Length());
297 iParent->InfoMessage(buf);
298 if (inputBuffer->iData.Length()>0)
300 iParent->InfoMessage(_L("Call HwDevice->WriteCodedData()"));
301 iVideoHwDevice->WriteCodedDataL(inputBuffer);
305 iParent->InfoMessage(_L("End of input stream"));
306 iParent->InfoMessage(_L("Call HwDevice->InputEnd()"));
307 iVideoHwDevice->InputEnd();
312 void CPlayVideoFile::CleanupAndSetDeviceError(TPtrC16 aText)
314 iParent->SetVerdict(aText, EFail);
315 delete iVideoHwDevice;
316 SetState(EHwDeviceError);
319 void CPlayVideoFile::MdvppNewPicture(TVideoPicture* aPicture)
321 iParent->InfoMessage(_L("MdvppNewPicture - Received Frame"));
322 iVideoHwDevice->ReturnPicture(aPicture);
323 iParent->InfoMessage(_L("MdvppNewPicture - finished returning Frame"));
326 void CPlayVideoFile::MdvppNewBuffers()
328 iParent->InfoMessage(_L("MdvppNewBuffers()"));
329 TRAP(iError, ReadNextBufferL());
330 if (iError != KErrNone)
332 iParent->SetVerdict(_L("Error reading next buffer"),EFail);
333 iVideoHwDevice->Stop();
334 SetState(EHwDeviceError);
338 void CPlayVideoFile::MdvppReturnPicture(TVideoPicture* /*aPicture*/)
340 iParent->InfoMessage(_L("MdvppReturnPicture()"));
343 void CPlayVideoFile::MdvppSupplementalInformation(const TDesC8& /*aData*/,
344 const TTimeIntervalMicroSeconds& /*aTimestamp*/, const TPictureId& /*aPictureId*/)
348 void CPlayVideoFile::MdvppPictureLoss()
350 iParent->InfoMessage(_L("MdvppPictureLoss()"));
353 void CPlayVideoFile::MdvppPictureLoss(const TArray<TPictureId>& /*aPictures*/)
355 iParent->InfoMessage(_L("MdvppPictureLoss()"));
358 void CPlayVideoFile::MdvppSliceLoss(TUint /*aFirstMacroblock*/, TUint /*aNumMacroblocks*/, const TPictureId& /*aPicture*/)
360 iParent->InfoMessage(_L("MdvppSliceLoss()"));
363 void CPlayVideoFile::MdvppReferencePictureSelection(const TDesC8& /*aSelectionData*/)
367 void CPlayVideoFile::MdvppTimedSnapshotComplete(TInt /*aError*/, TPictureData* /*aPictureData*/,
368 const TTimeIntervalMicroSeconds& /*aPresentationTimestamp*/, const TPictureId& /*aPictureId*/)
372 void CPlayVideoFile::MdvppFatalError(CMMFVideoHwDevice* /*aDevice*/, TInt aError)
375 iParent->InfoMessage(_L("MdvppFatalError()"));
376 SetState(EHwDeviceError);
379 void CPlayVideoFile::MdvppInitializeComplete(CMMFVideoHwDevice* /*aDevice*/, TInt aError)
381 iParent->InfoMessage(_L("MdvppInitializeComplete()"));
383 if (iError == KErrNone)
385 iParent->InfoMessage(_L("The Hw Device Adapter initialised correctly"));
386 SetState(EHwDeviceStartDecode);
390 iParent->InfoMessage(_L("Failure intialising the hw device adapter"));
391 SetState(EHwDeviceError);
395 void CPlayVideoFile::MdvppStreamEnd()
397 iParent->InfoMessage(_L("MdvppStreamEnd()"));
398 SetState(EHwDeviceDone);
401 void CPlayVideoFile::StartDirectScreenAccessL()
403 TRegionFix<KTRegionFixSize> reg;
404 TRect pos(iFrameSize);
407 iVideoHwDevice->StartDirectScreenAccessL(pos, *iScreenDevice, reg);