os/mm/mmdevicefw/mdfunittest/codecapi/video/src/videoplayfile.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include <mmf/devvideo/videoplayhwdevice.h>
sl@0
    17
#include <mmf/server/mmfdatabuffer.h>
sl@0
    18
#include "videoplayfile.h"
sl@0
    19
sl@0
    20
#include "../../PU/video/src/Plugin/VideoTestDecoderPU/videotestdecoderpu.hrh"
sl@0
    21
#include "../../PU/video/src/Plugin/VideoTestEncoderPU/videotestencoderpu.hrh"
sl@0
    22
sl@0
    23
const TInt KInputBufferSize = 8192;
sl@0
    24
const TInt KFilePositionZero = 0;
sl@0
    25
const TInt KTBufSize = 256;
sl@0
    26
const TInt KTRegionFixSize = 1;
sl@0
    27
sl@0
    28
// **************************************************
sl@0
    29
// instructs the Hw Device Adapter to play a file	
sl@0
    30
// **************************************************
sl@0
    31
CPlayVideoFile::CPlayVideoFile(RTestStepVideoCodecs* aParent) : 
sl@0
    32
	CActive(EPriorityNormal),
sl@0
    33
	iState(EHwDeviceInit),
sl@0
    34
	iParent(aParent)
sl@0
    35
	{
sl@0
    36
	}
sl@0
    37
sl@0
    38
void  CPlayVideoFile::ConstructL()
sl@0
    39
	{
sl@0
    40
	CActiveScheduler::Add(this);
sl@0
    41
	User::LeaveIfError(RFbsSession::Connect());
sl@0
    42
sl@0
    43
	TInt err = KErrNone;
sl@0
    44
	TRAP(err, iScreenDevice = CFbsScreenDevice::NewL(_L(""),EColor16MA));
sl@0
    45
	if (err == KErrNotSupported)
sl@0
    46
		{
sl@0
    47
		TRAP(err, iScreenDevice = CFbsScreenDevice::NewL(_L(""),EColor16M));
sl@0
    48
		}
sl@0
    49
	if (err == KErrNotSupported)
sl@0
    50
		{
sl@0
    51
		TRAP(err, iScreenDevice = CFbsScreenDevice::NewL(_L(""),EColor64K));
sl@0
    52
		}
sl@0
    53
	if (err == KErrNotSupported)
sl@0
    54
		{
sl@0
    55
		TRAP(err, iScreenDevice = CFbsScreenDevice::NewL(_L(""),EColor4K));
sl@0
    56
		}
sl@0
    57
	if (err == KErrNotSupported)
sl@0
    58
		{
sl@0
    59
		TRAP(err, iScreenDevice = CFbsScreenDevice::NewL(_L(""),EColor256));
sl@0
    60
		}
sl@0
    61
	if (err == KErrNotSupported)
sl@0
    62
		{
sl@0
    63
		iScreenDevice = CFbsScreenDevice::NewL(_L(""),EColor16MAP);
sl@0
    64
		}		
sl@0
    65
	else
sl@0
    66
		{
sl@0
    67
		User::LeaveIfError(err);		
sl@0
    68
		}
sl@0
    69
	}
sl@0
    70
sl@0
    71
CPlayVideoFile* CPlayVideoFile::NewL(RTestStepVideoCodecs* aParent)
sl@0
    72
	{
sl@0
    73
	CPlayVideoFile* self = new (ELeave) CPlayVideoFile(aParent);
sl@0
    74
	CleanupStack::PushL(self);
sl@0
    75
	self->ConstructL();
sl@0
    76
	CleanupStack::Pop(self);
sl@0
    77
	return self;
sl@0
    78
	}
sl@0
    79
	
sl@0
    80
	
sl@0
    81
void CPlayVideoFile::DoCancel()
sl@0
    82
	{
sl@0
    83
	}
sl@0
    84
sl@0
    85
CPlayVideoFile::~CPlayVideoFile()
sl@0
    86
	{
sl@0
    87
	iFile.Close();
sl@0
    88
	iFs.Close();
sl@0
    89
	
sl@0
    90
	delete iVideoHwDevice;
sl@0
    91
	delete iScreenDevice;
sl@0
    92
	RFbsSession::Disconnect();
sl@0
    93
	}
sl@0
    94
	
sl@0
    95
	
sl@0
    96
void CPlayVideoFile::LoadCodecL()	
sl@0
    97
	{
sl@0
    98
	iParent->InfoMessage(_L("Loading Hw Device Adapter and PU Codec"));
sl@0
    99
sl@0
   100
	RImplInfoPtrArray array;
sl@0
   101
	REComSession::ListImplementationsL(TUid::Uid(KUidMdfProcessingUnit), array);
sl@0
   102
	TBool found = EFalse;
sl@0
   103
	CImplementationInformation* info = NULL;
sl@0
   104
	for (TInt i=0;i<array.Count() && !found;i++)
sl@0
   105
		{
sl@0
   106
		info = array[i];
sl@0
   107
		if (info->ImplementationUid() == TUid::Uid(KUidVideoTestDecoderPu))
sl@0
   108
			{
sl@0
   109
			found = ETrue;
sl@0
   110
			}
sl@0
   111
		}
sl@0
   112
	TInt err = KErrNotFound;
sl@0
   113
	if (found)
sl@0
   114
		{
sl@0
   115
		TRAP(err, iVideoHwDevice = CMMFVideoDecodeHwDevice::NewPuAdapterL(*info,*this));
sl@0
   116
		}
sl@0
   117
	else
sl@0
   118
		{
sl@0
   119
		err = KErrNotFound;
sl@0
   120
		}
sl@0
   121
	array.ResetAndDestroy();
sl@0
   122
	User::LeaveIfError(err);
sl@0
   123
sl@0
   124
	}
sl@0
   125
	
sl@0
   126
void CPlayVideoFile::SetDSA(TBool aUseDSA)	
sl@0
   127
	{
sl@0
   128
	// Need new version of this to load from a PU based uid
sl@0
   129
	iUseDSA = aUseDSA;
sl@0
   130
	}
sl@0
   131
	
sl@0
   132
void CPlayVideoFile::StartPlaybackL()	
sl@0
   133
	{
sl@0
   134
	OpenTestFileL();
sl@0
   135
	SetState(EHwDeviceInit);
sl@0
   136
	CActiveScheduler::Start();
sl@0
   137
	}
sl@0
   138
sl@0
   139
void CPlayVideoFile::SetState(TPlayVideoFileState aState)
sl@0
   140
	{
sl@0
   141
	iState = aState;
sl@0
   142
	SetActive();	
sl@0
   143
	TRequestStatus* status = &iStatus;
sl@0
   144
	User::RequestComplete(status, KErrNone);	
sl@0
   145
	}
sl@0
   146
sl@0
   147
void CPlayVideoFile::OpenTestFileL()
sl@0
   148
	{
sl@0
   149
	TBuf<KTBufSize> buf;
sl@0
   150
	buf.Format(_L("Opening test input file %S"), &KTestPlaybackFile);
sl@0
   151
	iParent->InfoMessage(buf);
sl@0
   152
	User::LeaveIfError(iFs.Connect());
sl@0
   153
	User::LeaveIfError(iFile.Open(iFs, KTestPlaybackFile, EFileRead));
sl@0
   154
	}
sl@0
   155
sl@0
   156
void CPlayVideoFile::RunL()
sl@0
   157
	{
sl@0
   158
	switch (iState)
sl@0
   159
		{
sl@0
   160
		case EHwDeviceInit:
sl@0
   161
			{
sl@0
   162
			iParent->InfoMessage(_L("State: EHwDeviceInit"));
sl@0
   163
			TRAPD(err, InitializeL());
sl@0
   164
			if (err != KErrNone)
sl@0
   165
				{
sl@0
   166
				CleanupAndSetDeviceError(_L("Cannot intialize HwDevice"));
sl@0
   167
				break;
sl@0
   168
				}
sl@0
   169
			break;
sl@0
   170
			}
sl@0
   171
		case EHwDeviceStartDecode:
sl@0
   172
			{
sl@0
   173
			// if we are playing a file, first we have to open the file
sl@0
   174
			iParent->InfoMessage(_L("State: EHwDeviceStartDecode"));
sl@0
   175
			TRAPD(err, StartDecodeL());
sl@0
   176
			if (err != KErrNone)
sl@0
   177
				{
sl@0
   178
				CleanupAndSetDeviceError(_L("Cannot start decoding"));
sl@0
   179
				break;
sl@0
   180
				}
sl@0
   181
			break;
sl@0
   182
			}
sl@0
   183
		case EHwDeviceAllowToComplete:
sl@0
   184
			iParent->InfoMessage(_L("State: EHwDeviceAllowToComplete"));
sl@0
   185
			break;
sl@0
   186
		case EHwDeviceDone:
sl@0
   187
			{
sl@0
   188
			iParent->InfoMessage(_L("State: EHwDeviceDeviceDone"));
sl@0
   189
			Cancel();
sl@0
   190
			CActiveScheduler::Stop();
sl@0
   191
			break;
sl@0
   192
			}				
sl@0
   193
		case EHwDeviceError:
sl@0
   194
			{
sl@0
   195
			TBuf<KTBufSize> buf;
sl@0
   196
			buf.Format(_L("State: EHwDeviceDeviceError %d"), iError);
sl@0
   197
			iParent->SetVerdict(buf, EFail);
sl@0
   198
			
sl@0
   199
			CActiveScheduler::Stop();
sl@0
   200
			break;
sl@0
   201
			}
sl@0
   202
		default:
sl@0
   203
			{
sl@0
   204
			CleanupAndSetDeviceError(_L("Unknown CPlayVideoFile iState"));
sl@0
   205
			break;
sl@0
   206
			}
sl@0
   207
		}
sl@0
   208
	}
sl@0
   209
	
sl@0
   210
	
sl@0
   211
void CPlayVideoFile::InitializeL()
sl@0
   212
	{
sl@0
   213
	iParent->InfoMessage(_L("InitializeL()"));
sl@0
   214
sl@0
   215
	TUncompressedVideoFormat reqFormat;
sl@0
   216
	reqFormat.iDataFormat = ERgbFbsBitmap;
sl@0
   217
	reqFormat.iRgbFormat = EFbsBitmapColor16M;
sl@0
   218
	RArray<TUncompressedVideoFormat> decodeFormats;
sl@0
   219
	iVideoHwDevice->GetOutputFormatListL(decodeFormats);
sl@0
   220
	CleanupClosePushL(decodeFormats);
sl@0
   221
	User::LeaveIfError(decodeFormats.Find(reqFormat));
sl@0
   222
sl@0
   223
	iParent->InfoMessage(_L("Call VideoHwDevice->SetOutputFormat()"));
sl@0
   224
	iVideoHwDevice->SetOutputFormatL(reqFormat);
sl@0
   225
	CleanupStack::PopAndDestroy(&decodeFormats);	
sl@0
   226
	
sl@0
   227
	CMMFDescriptorBuffer* buffer = CMMFDescriptorBuffer::NewL(KInputBufferSize);
sl@0
   228
	CleanupStack::PushL(buffer);
sl@0
   229
	TVideoInputBuffer inputBuffer;
sl@0
   230
	
sl@0
   231
	TDes8& des = buffer->Data();
sl@0
   232
	// read header data from file
sl@0
   233
	User::LeaveIfError(iFile.Read(des));
sl@0
   234
	TInt pos = KFilePositionZero;
sl@0
   235
	// seek back to start
sl@0
   236
	User::LeaveIfError(iFile.Seek(ESeekStart, pos));
sl@0
   237
sl@0
   238
	TBuf<KTBufSize> buf;
sl@0
   239
	buf.Format(_L("Read header of size %d"),inputBuffer.iData.Length());
sl@0
   240
	iParent->InfoMessage(buf);
sl@0
   241
	
sl@0
   242
	if (des.Length()>0)
sl@0
   243
		{
sl@0
   244
		// Set the pointer
sl@0
   245
		inputBuffer.iData.Set(&des[0],des.Length(),des.MaxLength());
sl@0
   246
		
sl@0
   247
		iParent->InfoMessage(_L("Call VideoHwDevice GetHeaderInformationL()"));
sl@0
   248
		TVideoPictureHeader* header = iVideoHwDevice->GetHeaderInformationL(EDuArbitraryStreamSection, 
sl@0
   249
												EDuElementaryStream,
sl@0
   250
												&inputBuffer);
sl@0
   251
												
sl@0
   252
		iFrameSize = header->iSizeInMemory;
sl@0
   253
		iVideoHwDevice->ReturnHeader(header);
sl@0
   254
		}
sl@0
   255
	else
sl@0
   256
		{
sl@0
   257
		// Cannot read any data from file, so no point in continuing
sl@0
   258
		User::Leave(KErrCorrupt);
sl@0
   259
		}
sl@0
   260
		
sl@0
   261
	CleanupStack::PopAndDestroy(buffer);	
sl@0
   262
	
sl@0
   263
	iParent->InfoMessage(_L("Call VideoHwDevice SetVideoDestScreenL()"));
sl@0
   264
	iVideoHwDevice->SetVideoDestScreenL(iUseDSA);
sl@0
   265
	
sl@0
   266
	iParent->InfoMessage(_L("Call VideoHwDevice->Initialize()"));
sl@0
   267
	iVideoHwDevice->Initialize();
sl@0
   268
	}
sl@0
   269
	
sl@0
   270
	
sl@0
   271
void CPlayVideoFile::StartDecodeL()
sl@0
   272
	{
sl@0
   273
	iParent->InfoMessage(_L("StartDecodeL()"));
sl@0
   274
sl@0
   275
	if (iUseDSA)
sl@0
   276
		{
sl@0
   277
		StartDirectScreenAccessL();
sl@0
   278
		}
sl@0
   279
	// tell the HwDeviceAdapter to play the file
sl@0
   280
	iParent->InfoMessage(_L("Call VideoHwDevice->Start()"));
sl@0
   281
	iVideoHwDevice->Start();
sl@0
   282
	}
sl@0
   283
	
sl@0
   284
	
sl@0
   285
void CPlayVideoFile::ReadNextBufferL()
sl@0
   286
	{
sl@0
   287
	// check that we aren't waiting for the input buffer to be returned
sl@0
   288
	iParent->InfoMessage(_L("ReadNextBufferL()"));
sl@0
   289
	TVideoInputBuffer* inputBuffer = iVideoHwDevice->GetBufferL(KInputBufferSize);	
sl@0
   290
	if (inputBuffer)
sl@0
   291
		{
sl@0
   292
		TBuf<KTBufSize> buf;
sl@0
   293
		buf.Format(_L("inputBuffer size %d"),inputBuffer->iData.Length());
sl@0
   294
		iParent->InfoMessage(buf);
sl@0
   295
		User::LeaveIfError(iFile.Read(inputBuffer->iData));
sl@0
   296
		buf.Format(_L("Read from file %d bytes"),inputBuffer->iData.Length());
sl@0
   297
		iParent->InfoMessage(buf);
sl@0
   298
		if (inputBuffer->iData.Length()>0)
sl@0
   299
			{
sl@0
   300
			iParent->InfoMessage(_L("Call HwDevice->WriteCodedData()"));
sl@0
   301
			iVideoHwDevice->WriteCodedDataL(inputBuffer);
sl@0
   302
			}
sl@0
   303
		else
sl@0
   304
			{
sl@0
   305
			iParent->InfoMessage(_L("End of input stream"));
sl@0
   306
			iParent->InfoMessage(_L("Call HwDevice->InputEnd()"));
sl@0
   307
			iVideoHwDevice->InputEnd();
sl@0
   308
			}
sl@0
   309
		}
sl@0
   310
	}
sl@0
   311
		
sl@0
   312
void CPlayVideoFile::CleanupAndSetDeviceError(TPtrC16 aText)
sl@0
   313
	{
sl@0
   314
	iParent->SetVerdict(aText, EFail);
sl@0
   315
	delete iVideoHwDevice;
sl@0
   316
	SetState(EHwDeviceError);
sl@0
   317
	}
sl@0
   318
	
sl@0
   319
void CPlayVideoFile::MdvppNewPicture(TVideoPicture* aPicture)
sl@0
   320
	{
sl@0
   321
	iParent->InfoMessage(_L("MdvppNewPicture - Received Frame"));
sl@0
   322
	iVideoHwDevice->ReturnPicture(aPicture);
sl@0
   323
	iParent->InfoMessage(_L("MdvppNewPicture - finished returning Frame"));
sl@0
   324
	}
sl@0
   325
sl@0
   326
void CPlayVideoFile::MdvppNewBuffers()
sl@0
   327
	{
sl@0
   328
	iParent->InfoMessage(_L("MdvppNewBuffers()"));
sl@0
   329
	TRAP(iError, ReadNextBufferL());
sl@0
   330
	if (iError != KErrNone)
sl@0
   331
		{
sl@0
   332
		iParent->SetVerdict(_L("Error reading next buffer"),EFail);		
sl@0
   333
		iVideoHwDevice->Stop();
sl@0
   334
		SetState(EHwDeviceError);
sl@0
   335
		}
sl@0
   336
	}
sl@0
   337
sl@0
   338
void CPlayVideoFile::MdvppReturnPicture(TVideoPicture* /*aPicture*/)
sl@0
   339
	{
sl@0
   340
	iParent->InfoMessage(_L("MdvppReturnPicture()"));
sl@0
   341
	}
sl@0
   342
	
sl@0
   343
void CPlayVideoFile::MdvppSupplementalInformation(const TDesC8& /*aData*/, 
sl@0
   344
	const TTimeIntervalMicroSeconds& /*aTimestamp*/, const TPictureId& /*aPictureId*/)
sl@0
   345
	{
sl@0
   346
	}
sl@0
   347
	
sl@0
   348
void CPlayVideoFile::MdvppPictureLoss()
sl@0
   349
	{
sl@0
   350
	iParent->InfoMessage(_L("MdvppPictureLoss()"));
sl@0
   351
	}
sl@0
   352
	
sl@0
   353
void CPlayVideoFile::MdvppPictureLoss(const TArray<TPictureId>& /*aPictures*/)
sl@0
   354
	{
sl@0
   355
	iParent->InfoMessage(_L("MdvppPictureLoss()"));
sl@0
   356
	}
sl@0
   357
	
sl@0
   358
void CPlayVideoFile::MdvppSliceLoss(TUint /*aFirstMacroblock*/, TUint /*aNumMacroblocks*/, const TPictureId& /*aPicture*/)
sl@0
   359
	{
sl@0
   360
	iParent->InfoMessage(_L("MdvppSliceLoss()"));
sl@0
   361
	}
sl@0
   362
	
sl@0
   363
void CPlayVideoFile::MdvppReferencePictureSelection(const TDesC8& /*aSelectionData*/)
sl@0
   364
	{
sl@0
   365
	}
sl@0
   366
	
sl@0
   367
void CPlayVideoFile::MdvppTimedSnapshotComplete(TInt /*aError*/, TPictureData* /*aPictureData*/, 
sl@0
   368
	const TTimeIntervalMicroSeconds& /*aPresentationTimestamp*/, const TPictureId& /*aPictureId*/)
sl@0
   369
	{
sl@0
   370
	}
sl@0
   371
	
sl@0
   372
void CPlayVideoFile::MdvppFatalError(CMMFVideoHwDevice* /*aDevice*/, TInt aError)
sl@0
   373
	{
sl@0
   374
	iError = aError;
sl@0
   375
	iParent->InfoMessage(_L("MdvppFatalError()"));
sl@0
   376
	SetState(EHwDeviceError);
sl@0
   377
	}
sl@0
   378
	
sl@0
   379
void CPlayVideoFile::MdvppInitializeComplete(CMMFVideoHwDevice* /*aDevice*/, TInt aError)
sl@0
   380
	{
sl@0
   381
	iParent->InfoMessage(_L("MdvppInitializeComplete()"));
sl@0
   382
	iError = aError;
sl@0
   383
	if (iError == KErrNone)
sl@0
   384
		{
sl@0
   385
		iParent->InfoMessage(_L("The Hw Device Adapter initialised correctly"));
sl@0
   386
		SetState(EHwDeviceStartDecode);
sl@0
   387
		}
sl@0
   388
	else
sl@0
   389
		{
sl@0
   390
		iParent->InfoMessage(_L("Failure intialising the hw device adapter"));
sl@0
   391
		SetState(EHwDeviceError);
sl@0
   392
		}
sl@0
   393
	}
sl@0
   394
	
sl@0
   395
void CPlayVideoFile::MdvppStreamEnd()
sl@0
   396
	{
sl@0
   397
	iParent->InfoMessage(_L("MdvppStreamEnd()"));
sl@0
   398
	SetState(EHwDeviceDone);
sl@0
   399
	}
sl@0
   400
sl@0
   401
void CPlayVideoFile::StartDirectScreenAccessL()
sl@0
   402
	{
sl@0
   403
	TRegionFix<KTRegionFixSize> reg;
sl@0
   404
	TRect pos(iFrameSize);
sl@0
   405
	reg.AddRect(pos);
sl@0
   406
	
sl@0
   407
	iVideoHwDevice->StartDirectScreenAccessL(pos, *iScreenDevice, reg);
sl@0
   408
	}