1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/mmdevicefw/mdfunittest/codecapi/video/src/videoplayfile.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,408 @@
1.4 +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include <mmf/devvideo/videoplayhwdevice.h>
1.20 +#include <mmf/server/mmfdatabuffer.h>
1.21 +#include "videoplayfile.h"
1.22 +
1.23 +#include "../../PU/video/src/Plugin/VideoTestDecoderPU/videotestdecoderpu.hrh"
1.24 +#include "../../PU/video/src/Plugin/VideoTestEncoderPU/videotestencoderpu.hrh"
1.25 +
1.26 +const TInt KInputBufferSize = 8192;
1.27 +const TInt KFilePositionZero = 0;
1.28 +const TInt KTBufSize = 256;
1.29 +const TInt KTRegionFixSize = 1;
1.30 +
1.31 +// **************************************************
1.32 +// instructs the Hw Device Adapter to play a file
1.33 +// **************************************************
1.34 +CPlayVideoFile::CPlayVideoFile(RTestStepVideoCodecs* aParent) :
1.35 + CActive(EPriorityNormal),
1.36 + iState(EHwDeviceInit),
1.37 + iParent(aParent)
1.38 + {
1.39 + }
1.40 +
1.41 +void CPlayVideoFile::ConstructL()
1.42 + {
1.43 + CActiveScheduler::Add(this);
1.44 + User::LeaveIfError(RFbsSession::Connect());
1.45 +
1.46 + TInt err = KErrNone;
1.47 + TRAP(err, iScreenDevice = CFbsScreenDevice::NewL(_L(""),EColor16MA));
1.48 + if (err == KErrNotSupported)
1.49 + {
1.50 + TRAP(err, iScreenDevice = CFbsScreenDevice::NewL(_L(""),EColor16M));
1.51 + }
1.52 + if (err == KErrNotSupported)
1.53 + {
1.54 + TRAP(err, iScreenDevice = CFbsScreenDevice::NewL(_L(""),EColor64K));
1.55 + }
1.56 + if (err == KErrNotSupported)
1.57 + {
1.58 + TRAP(err, iScreenDevice = CFbsScreenDevice::NewL(_L(""),EColor4K));
1.59 + }
1.60 + if (err == KErrNotSupported)
1.61 + {
1.62 + TRAP(err, iScreenDevice = CFbsScreenDevice::NewL(_L(""),EColor256));
1.63 + }
1.64 + if (err == KErrNotSupported)
1.65 + {
1.66 + iScreenDevice = CFbsScreenDevice::NewL(_L(""),EColor16MAP);
1.67 + }
1.68 + else
1.69 + {
1.70 + User::LeaveIfError(err);
1.71 + }
1.72 + }
1.73 +
1.74 +CPlayVideoFile* CPlayVideoFile::NewL(RTestStepVideoCodecs* aParent)
1.75 + {
1.76 + CPlayVideoFile* self = new (ELeave) CPlayVideoFile(aParent);
1.77 + CleanupStack::PushL(self);
1.78 + self->ConstructL();
1.79 + CleanupStack::Pop(self);
1.80 + return self;
1.81 + }
1.82 +
1.83 +
1.84 +void CPlayVideoFile::DoCancel()
1.85 + {
1.86 + }
1.87 +
1.88 +CPlayVideoFile::~CPlayVideoFile()
1.89 + {
1.90 + iFile.Close();
1.91 + iFs.Close();
1.92 +
1.93 + delete iVideoHwDevice;
1.94 + delete iScreenDevice;
1.95 + RFbsSession::Disconnect();
1.96 + }
1.97 +
1.98 +
1.99 +void CPlayVideoFile::LoadCodecL()
1.100 + {
1.101 + iParent->InfoMessage(_L("Loading Hw Device Adapter and PU Codec"));
1.102 +
1.103 + RImplInfoPtrArray array;
1.104 + REComSession::ListImplementationsL(TUid::Uid(KUidMdfProcessingUnit), array);
1.105 + TBool found = EFalse;
1.106 + CImplementationInformation* info = NULL;
1.107 + for (TInt i=0;i<array.Count() && !found;i++)
1.108 + {
1.109 + info = array[i];
1.110 + if (info->ImplementationUid() == TUid::Uid(KUidVideoTestDecoderPu))
1.111 + {
1.112 + found = ETrue;
1.113 + }
1.114 + }
1.115 + TInt err = KErrNotFound;
1.116 + if (found)
1.117 + {
1.118 + TRAP(err, iVideoHwDevice = CMMFVideoDecodeHwDevice::NewPuAdapterL(*info,*this));
1.119 + }
1.120 + else
1.121 + {
1.122 + err = KErrNotFound;
1.123 + }
1.124 + array.ResetAndDestroy();
1.125 + User::LeaveIfError(err);
1.126 +
1.127 + }
1.128 +
1.129 +void CPlayVideoFile::SetDSA(TBool aUseDSA)
1.130 + {
1.131 + // Need new version of this to load from a PU based uid
1.132 + iUseDSA = aUseDSA;
1.133 + }
1.134 +
1.135 +void CPlayVideoFile::StartPlaybackL()
1.136 + {
1.137 + OpenTestFileL();
1.138 + SetState(EHwDeviceInit);
1.139 + CActiveScheduler::Start();
1.140 + }
1.141 +
1.142 +void CPlayVideoFile::SetState(TPlayVideoFileState aState)
1.143 + {
1.144 + iState = aState;
1.145 + SetActive();
1.146 + TRequestStatus* status = &iStatus;
1.147 + User::RequestComplete(status, KErrNone);
1.148 + }
1.149 +
1.150 +void CPlayVideoFile::OpenTestFileL()
1.151 + {
1.152 + TBuf<KTBufSize> buf;
1.153 + buf.Format(_L("Opening test input file %S"), &KTestPlaybackFile);
1.154 + iParent->InfoMessage(buf);
1.155 + User::LeaveIfError(iFs.Connect());
1.156 + User::LeaveIfError(iFile.Open(iFs, KTestPlaybackFile, EFileRead));
1.157 + }
1.158 +
1.159 +void CPlayVideoFile::RunL()
1.160 + {
1.161 + switch (iState)
1.162 + {
1.163 + case EHwDeviceInit:
1.164 + {
1.165 + iParent->InfoMessage(_L("State: EHwDeviceInit"));
1.166 + TRAPD(err, InitializeL());
1.167 + if (err != KErrNone)
1.168 + {
1.169 + CleanupAndSetDeviceError(_L("Cannot intialize HwDevice"));
1.170 + break;
1.171 + }
1.172 + break;
1.173 + }
1.174 + case EHwDeviceStartDecode:
1.175 + {
1.176 + // if we are playing a file, first we have to open the file
1.177 + iParent->InfoMessage(_L("State: EHwDeviceStartDecode"));
1.178 + TRAPD(err, StartDecodeL());
1.179 + if (err != KErrNone)
1.180 + {
1.181 + CleanupAndSetDeviceError(_L("Cannot start decoding"));
1.182 + break;
1.183 + }
1.184 + break;
1.185 + }
1.186 + case EHwDeviceAllowToComplete:
1.187 + iParent->InfoMessage(_L("State: EHwDeviceAllowToComplete"));
1.188 + break;
1.189 + case EHwDeviceDone:
1.190 + {
1.191 + iParent->InfoMessage(_L("State: EHwDeviceDeviceDone"));
1.192 + Cancel();
1.193 + CActiveScheduler::Stop();
1.194 + break;
1.195 + }
1.196 + case EHwDeviceError:
1.197 + {
1.198 + TBuf<KTBufSize> buf;
1.199 + buf.Format(_L("State: EHwDeviceDeviceError %d"), iError);
1.200 + iParent->SetVerdict(buf, EFail);
1.201 +
1.202 + CActiveScheduler::Stop();
1.203 + break;
1.204 + }
1.205 + default:
1.206 + {
1.207 + CleanupAndSetDeviceError(_L("Unknown CPlayVideoFile iState"));
1.208 + break;
1.209 + }
1.210 + }
1.211 + }
1.212 +
1.213 +
1.214 +void CPlayVideoFile::InitializeL()
1.215 + {
1.216 + iParent->InfoMessage(_L("InitializeL()"));
1.217 +
1.218 + TUncompressedVideoFormat reqFormat;
1.219 + reqFormat.iDataFormat = ERgbFbsBitmap;
1.220 + reqFormat.iRgbFormat = EFbsBitmapColor16M;
1.221 + RArray<TUncompressedVideoFormat> decodeFormats;
1.222 + iVideoHwDevice->GetOutputFormatListL(decodeFormats);
1.223 + CleanupClosePushL(decodeFormats);
1.224 + User::LeaveIfError(decodeFormats.Find(reqFormat));
1.225 +
1.226 + iParent->InfoMessage(_L("Call VideoHwDevice->SetOutputFormat()"));
1.227 + iVideoHwDevice->SetOutputFormatL(reqFormat);
1.228 + CleanupStack::PopAndDestroy(&decodeFormats);
1.229 +
1.230 + CMMFDescriptorBuffer* buffer = CMMFDescriptorBuffer::NewL(KInputBufferSize);
1.231 + CleanupStack::PushL(buffer);
1.232 + TVideoInputBuffer inputBuffer;
1.233 +
1.234 + TDes8& des = buffer->Data();
1.235 + // read header data from file
1.236 + User::LeaveIfError(iFile.Read(des));
1.237 + TInt pos = KFilePositionZero;
1.238 + // seek back to start
1.239 + User::LeaveIfError(iFile.Seek(ESeekStart, pos));
1.240 +
1.241 + TBuf<KTBufSize> buf;
1.242 + buf.Format(_L("Read header of size %d"),inputBuffer.iData.Length());
1.243 + iParent->InfoMessage(buf);
1.244 +
1.245 + if (des.Length()>0)
1.246 + {
1.247 + // Set the pointer
1.248 + inputBuffer.iData.Set(&des[0],des.Length(),des.MaxLength());
1.249 +
1.250 + iParent->InfoMessage(_L("Call VideoHwDevice GetHeaderInformationL()"));
1.251 + TVideoPictureHeader* header = iVideoHwDevice->GetHeaderInformationL(EDuArbitraryStreamSection,
1.252 + EDuElementaryStream,
1.253 + &inputBuffer);
1.254 +
1.255 + iFrameSize = header->iSizeInMemory;
1.256 + iVideoHwDevice->ReturnHeader(header);
1.257 + }
1.258 + else
1.259 + {
1.260 + // Cannot read any data from file, so no point in continuing
1.261 + User::Leave(KErrCorrupt);
1.262 + }
1.263 +
1.264 + CleanupStack::PopAndDestroy(buffer);
1.265 +
1.266 + iParent->InfoMessage(_L("Call VideoHwDevice SetVideoDestScreenL()"));
1.267 + iVideoHwDevice->SetVideoDestScreenL(iUseDSA);
1.268 +
1.269 + iParent->InfoMessage(_L("Call VideoHwDevice->Initialize()"));
1.270 + iVideoHwDevice->Initialize();
1.271 + }
1.272 +
1.273 +
1.274 +void CPlayVideoFile::StartDecodeL()
1.275 + {
1.276 + iParent->InfoMessage(_L("StartDecodeL()"));
1.277 +
1.278 + if (iUseDSA)
1.279 + {
1.280 + StartDirectScreenAccessL();
1.281 + }
1.282 + // tell the HwDeviceAdapter to play the file
1.283 + iParent->InfoMessage(_L("Call VideoHwDevice->Start()"));
1.284 + iVideoHwDevice->Start();
1.285 + }
1.286 +
1.287 +
1.288 +void CPlayVideoFile::ReadNextBufferL()
1.289 + {
1.290 + // check that we aren't waiting for the input buffer to be returned
1.291 + iParent->InfoMessage(_L("ReadNextBufferL()"));
1.292 + TVideoInputBuffer* inputBuffer = iVideoHwDevice->GetBufferL(KInputBufferSize);
1.293 + if (inputBuffer)
1.294 + {
1.295 + TBuf<KTBufSize> buf;
1.296 + buf.Format(_L("inputBuffer size %d"),inputBuffer->iData.Length());
1.297 + iParent->InfoMessage(buf);
1.298 + User::LeaveIfError(iFile.Read(inputBuffer->iData));
1.299 + buf.Format(_L("Read from file %d bytes"),inputBuffer->iData.Length());
1.300 + iParent->InfoMessage(buf);
1.301 + if (inputBuffer->iData.Length()>0)
1.302 + {
1.303 + iParent->InfoMessage(_L("Call HwDevice->WriteCodedData()"));
1.304 + iVideoHwDevice->WriteCodedDataL(inputBuffer);
1.305 + }
1.306 + else
1.307 + {
1.308 + iParent->InfoMessage(_L("End of input stream"));
1.309 + iParent->InfoMessage(_L("Call HwDevice->InputEnd()"));
1.310 + iVideoHwDevice->InputEnd();
1.311 + }
1.312 + }
1.313 + }
1.314 +
1.315 +void CPlayVideoFile::CleanupAndSetDeviceError(TPtrC16 aText)
1.316 + {
1.317 + iParent->SetVerdict(aText, EFail);
1.318 + delete iVideoHwDevice;
1.319 + SetState(EHwDeviceError);
1.320 + }
1.321 +
1.322 +void CPlayVideoFile::MdvppNewPicture(TVideoPicture* aPicture)
1.323 + {
1.324 + iParent->InfoMessage(_L("MdvppNewPicture - Received Frame"));
1.325 + iVideoHwDevice->ReturnPicture(aPicture);
1.326 + iParent->InfoMessage(_L("MdvppNewPicture - finished returning Frame"));
1.327 + }
1.328 +
1.329 +void CPlayVideoFile::MdvppNewBuffers()
1.330 + {
1.331 + iParent->InfoMessage(_L("MdvppNewBuffers()"));
1.332 + TRAP(iError, ReadNextBufferL());
1.333 + if (iError != KErrNone)
1.334 + {
1.335 + iParent->SetVerdict(_L("Error reading next buffer"),EFail);
1.336 + iVideoHwDevice->Stop();
1.337 + SetState(EHwDeviceError);
1.338 + }
1.339 + }
1.340 +
1.341 +void CPlayVideoFile::MdvppReturnPicture(TVideoPicture* /*aPicture*/)
1.342 + {
1.343 + iParent->InfoMessage(_L("MdvppReturnPicture()"));
1.344 + }
1.345 +
1.346 +void CPlayVideoFile::MdvppSupplementalInformation(const TDesC8& /*aData*/,
1.347 + const TTimeIntervalMicroSeconds& /*aTimestamp*/, const TPictureId& /*aPictureId*/)
1.348 + {
1.349 + }
1.350 +
1.351 +void CPlayVideoFile::MdvppPictureLoss()
1.352 + {
1.353 + iParent->InfoMessage(_L("MdvppPictureLoss()"));
1.354 + }
1.355 +
1.356 +void CPlayVideoFile::MdvppPictureLoss(const TArray<TPictureId>& /*aPictures*/)
1.357 + {
1.358 + iParent->InfoMessage(_L("MdvppPictureLoss()"));
1.359 + }
1.360 +
1.361 +void CPlayVideoFile::MdvppSliceLoss(TUint /*aFirstMacroblock*/, TUint /*aNumMacroblocks*/, const TPictureId& /*aPicture*/)
1.362 + {
1.363 + iParent->InfoMessage(_L("MdvppSliceLoss()"));
1.364 + }
1.365 +
1.366 +void CPlayVideoFile::MdvppReferencePictureSelection(const TDesC8& /*aSelectionData*/)
1.367 + {
1.368 + }
1.369 +
1.370 +void CPlayVideoFile::MdvppTimedSnapshotComplete(TInt /*aError*/, TPictureData* /*aPictureData*/,
1.371 + const TTimeIntervalMicroSeconds& /*aPresentationTimestamp*/, const TPictureId& /*aPictureId*/)
1.372 + {
1.373 + }
1.374 +
1.375 +void CPlayVideoFile::MdvppFatalError(CMMFVideoHwDevice* /*aDevice*/, TInt aError)
1.376 + {
1.377 + iError = aError;
1.378 + iParent->InfoMessage(_L("MdvppFatalError()"));
1.379 + SetState(EHwDeviceError);
1.380 + }
1.381 +
1.382 +void CPlayVideoFile::MdvppInitializeComplete(CMMFVideoHwDevice* /*aDevice*/, TInt aError)
1.383 + {
1.384 + iParent->InfoMessage(_L("MdvppInitializeComplete()"));
1.385 + iError = aError;
1.386 + if (iError == KErrNone)
1.387 + {
1.388 + iParent->InfoMessage(_L("The Hw Device Adapter initialised correctly"));
1.389 + SetState(EHwDeviceStartDecode);
1.390 + }
1.391 + else
1.392 + {
1.393 + iParent->InfoMessage(_L("Failure intialising the hw device adapter"));
1.394 + SetState(EHwDeviceError);
1.395 + }
1.396 + }
1.397 +
1.398 +void CPlayVideoFile::MdvppStreamEnd()
1.399 + {
1.400 + iParent->InfoMessage(_L("MdvppStreamEnd()"));
1.401 + SetState(EHwDeviceDone);
1.402 + }
1.403 +
1.404 +void CPlayVideoFile::StartDirectScreenAccessL()
1.405 + {
1.406 + TRegionFix<KTRegionFixSize> reg;
1.407 + TRect pos(iFrameSize);
1.408 + reg.AddRect(pos);
1.409 +
1.410 + iVideoHwDevice->StartDirectScreenAccessL(pos, *iScreenDevice, reg);
1.411 + }