devsound/devsoundrefplugin/tsrc/swcdwrap/TSU_SWCDWRAP_TestDevice/TSU_MMF_SWCDWRAP_TestDevice.cpp
changeset 0 79dd3e2336a0
equal deleted inserted replaced
-1:000000000000 0:79dd3e2336a0
       
     1 // Copyright (c) 2003-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".
       
     7 //
       
     8 // Initial Contributors:
       
     9 // Nokia Corporation - initial contribution.
       
    10 //
       
    11 // Contributors:
       
    12 //
       
    13 // Description:
       
    14 //
       
    15 
       
    16 
       
    17 #include "TSU_MMF_SWCDWRAP_TestDevice.h"
       
    18 
       
    19 void Panic()
       
    20 	{
       
    21 	_LIT(KMMF_SWCDWRAP_UnitTestPanic, "TSU_MMF_SWCDWRAP");
       
    22 	User::Panic(KMMF_SWCDWRAP_UnitTestPanic, 0);
       
    23 	}
       
    24 
       
    25 /**
       
    26  *
       
    27  *	test null hw device
       
    28  *	@return	"CMMFTestNullDevice"
       
    29  *
       
    30  */
       
    31 CMMFTestNullDevice* CMMFTestNullDevice::NewL()
       
    32 	{
       
    33     CMMFTestNullDevice* self = new (ELeave) CMMFTestNullDevice();
       
    34 	CleanupStack::PushL(self);
       
    35 	self->ConstructL();
       
    36 	CleanupStack::Pop();
       
    37 	return self;
       
    38 	}
       
    39 
       
    40 /**
       
    41  *
       
    42  *	Second phase constructor.
       
    43  *
       
    44  */
       
    45 void CMMFTestNullDevice::ConstructL()
       
    46 	{
       
    47     // Create device codec
       
    48 	iCodec = new (ELeave) CMMFTestNullCodec();
       
    49 	}
       
    50 
       
    51 
       
    52 CMMFTestNullDevice::~CMMFTestNullDevice()
       
    53 	{
       
    54 	}
       
    55 
       
    56 
       
    57 CMMFSwCodec& CMMFTestNullDevice::Codec()
       
    58 	{
       
    59 	__ASSERT_ALWAYS(iCodec, Panic());
       
    60 	return *iCodec;
       
    61 	}
       
    62 
       
    63 
       
    64 CMMFSwCodec::TCodecProcessResult CMMFTestNullCodec::ProcessL(const CMMFBuffer& /*aSource*/, CMMFBuffer& /*aDest*/)
       
    65 	{//no processing required for null codec
       
    66 	User::Leave(KErrNotSupported); 
       
    67 	//to keep compiler happy
       
    68 	TCodecProcessResult result;
       
    69 	result.iCodecProcessStatus = TCodecProcessResult::EEndOfData;
       
    70 	result.iSrcBytesProcessed = 0;
       
    71 	result.iDstBytesAdded = 0;
       
    72 	return result;
       
    73 	};
       
    74 
       
    75 
       
    76 
       
    77 /**
       
    78  *
       
    79  *	test null hw device
       
    80  *	@return	"CMMFTestNullDevice"
       
    81  *
       
    82  */
       
    83 CMMFTest2To1Device* CMMFTest2To1Device::NewL()
       
    84 	{
       
    85     CMMFTest2To1Device* self = new (ELeave) CMMFTest2To1Device();
       
    86 	CleanupStack::PushL(self);
       
    87 	self->ConstructL();
       
    88 	CleanupStack::Pop();
       
    89 	return self;
       
    90 	}
       
    91 
       
    92 /**
       
    93  *
       
    94  *	Second phase constructor.
       
    95  *
       
    96  */
       
    97 void CMMFTest2To1Device::ConstructL()
       
    98 	{
       
    99     // Create device codec
       
   100 	iCodec = new (ELeave) CMMFTest2To1Codec();
       
   101 	}
       
   102 
       
   103 
       
   104 CMMFTest2To1Device::~CMMFTest2To1Device()
       
   105 	{
       
   106 	}
       
   107 
       
   108 
       
   109 CMMFSwCodec& CMMFTest2To1Device::Codec()
       
   110 	{
       
   111 	__ASSERT_ALWAYS(iCodec, Panic());
       
   112 	return *iCodec;
       
   113 	}
       
   114 
       
   115 
       
   116 CMMFSwCodec::TCodecProcessResult CMMFTest2To1Codec::ProcessL(const CMMFBuffer& aSource, CMMFBuffer& aDest)
       
   117 	{//no processing required for null codec
       
   118 	
       
   119 	//convert from generic CMMFBuffer to CMMFDataBuffer
       
   120 	const CMMFDataBuffer* src = static_cast<const CMMFDataBuffer*>(&aSource);
       
   121 	CMMFDataBuffer* dst = static_cast<CMMFDataBuffer*>(&aDest);
       
   122 
       
   123 	const TUint dstMaxLen = dst->Data().MaxLength();
       
   124 
       
   125 	if (!dstMaxLen)
       
   126 	    {
       
   127 		User::Leave(KErrArgument);
       
   128 	    }
       
   129 
       
   130 	const TUint srcLen = src->Data().Length();
       
   131 
       
   132 	//we need to cast away CONST even on the source, as the TClass needs a TUint8*
       
   133 	const TUint8* pSrc = src->Data().Ptr();
       
   134 	TUint8* pDst = const_cast<TUint8*>(dst->Data().Ptr());
       
   135 	
       
   136 	TUint numberOfSamplesToGenerate = srcLen/4; // /2 to convert from bytes to samples and /2 as we only take every other
       
   137 	
       
   138 	ASSERT(numberOfSamplesToGenerate*2 <= dstMaxLen); // should be true for test
       
   139 	
       
   140 	TInt numberOfSamples = numberOfSamplesToGenerate;
       
   141 
       
   142 	while (numberOfSamples--)
       
   143 		{ 
       
   144 		*pDst++ = *pSrc++;
       
   145 		*pDst++ = *pSrc++;
       
   146 		pSrc += 2; //only send every other sample to destination
       
   147 		}
       
   148 
       
   149 	TCodecProcessResult result;
       
   150 	result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
       
   151 	result.iSrcBytesProcessed = numberOfSamplesToGenerate*4;
       
   152 	result.iDstBytesAdded = numberOfSamplesToGenerate*2;
       
   153 
       
   154 	dst->Data().SetLength(result.iDstBytesAdded);
       
   155 
       
   156 	return result;
       
   157 	};