devsound/devsoundrefplugin/src/plugin/audio/mmfpcmU16TopcmS16HwDevice.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 #include "mmfpcmU16TopcmS16HwDevice.h"
       
    17 
       
    18 /**
       
    19  *
       
    20  *	Returns the created hw device for passing audio through audio.
       
    21  *  for the wins implementation this would always be pcm16 although
       
    22  *  this is effectively a null hw device that will pass any datatype through
       
    23  *	@return	"CMMFPcm16ToPcmU16BEHwDevice"
       
    24  *
       
    25  */
       
    26 CMMFPcmU16ToPcm16HwDevice* CMMFPcmU16ToPcm16HwDevice::NewL()
       
    27 	{
       
    28     CMMFPcmU16ToPcm16HwDevice* self = new (ELeave) CMMFPcmU16ToPcm16HwDevice();
       
    29 	CleanupStack::PushL(self);
       
    30 	self->ConstructL();
       
    31 	CleanupStack::Pop(self);
       
    32 	return self;
       
    33 	}
       
    34 
       
    35 /**
       
    36 *
       
    37 * ~CMMFPcmU16ToPcm16HwDevice
       
    38 *
       
    39 */
       
    40 CMMFPcmU16ToPcm16HwDevice::~CMMFPcmU16ToPcm16HwDevice()
       
    41 	{
       
    42 	}
       
    43 
       
    44 /**
       
    45 *
       
    46 * Codec
       
    47 * @return 'CMMFSwCodec&'
       
    48 *
       
    49 */
       
    50 CMMFSwCodec& CMMFPcmU16ToPcm16HwDevice::Codec()
       
    51 	{
       
    52 	return *iCodec;
       
    53 	}
       
    54 
       
    55 /**
       
    56 *
       
    57 * ConstructL
       
    58 * 
       
    59 */
       
    60 void CMMFPcmU16ToPcm16HwDevice::ConstructL()
       
    61 	{
       
    62 	iCodec = new (ELeave) CMMFPcmU16ToPcm16Codec();
       
    63 	}
       
    64 
       
    65 /**
       
    66 *
       
    67 * ProcessL
       
    68 * @param aSrc
       
    69 * @param aDst
       
    70 * @return CMMFSwCodec::TCodecProcessResult
       
    71 * this codec has a does not expand or shrink destination data
       
    72 */
       
    73 CMMFSwCodec::TCodecProcessResult CMMFPcmU16ToPcm16Codec::ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDst)
       
    74 	{
       
    75 	TCodecProcessResult result;
       
    76 	result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
       
    77 	
       
    78 	//convert from generic CMMFBuffer to CMMFDataBuffer
       
    79 	const CMMFDataBuffer* src = STATIC_CAST(const CMMFDataBuffer*, &aSrc);
       
    80 	CMMFDataBuffer* dst = STATIC_CAST(CMMFDataBuffer*, &aDst);
       
    81 	
       
    82 	//[ check preconditions ]
       
    83 	if( !CheckPreconditions( src, dst ))
       
    84 		{
       
    85 		//[ precondition violation ]
       
    86 		User::Leave( KErrArgument );
       
    87 		}
       
    88 	
       
    89 	//we need to cast away CONST even on the source, as the TClass needs a TUint8*
       
    90 	TUint8* pSrc = CONST_CAST(TUint8*,src->Data().Ptr());
       
    91 	TUint8* pDst = CONST_CAST(TUint8*,dst->Data().Ptr());
       
    92 	
       
    93 	TInt srcUse = src->Data().Length();
       
    94 	TInt noSamples = srcUse/2;
       
    95 	iAudioU16ToS16Pcm.Convert(pSrc, pDst, noSamples);
       
    96 	
       
    97 	result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
       
    98 	result.iSrcBytesProcessed  = srcUse;
       
    99 	result.iDstBytesAdded      = srcUse;
       
   100 	dst->Data().SetLength(srcUse);
       
   101 	
       
   102 	//[ post conditions
       
   103     // srcbytes/2 == destbytes added
       
   104 	// pos src == 0
       
   105 	// pos dest == 0
       
   106 	// src data length is even
       
   107 	// dst data length is even ie pcm16 samples ]
       
   108 	__ASSERT_DEBUG( (src->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
       
   109 	__ASSERT_DEBUG( (dst->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
       
   110 	__ASSERT_DEBUG( src->Data().Length() == dst->Data().Length(), TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
       
   111 	__ASSERT_DEBUG( dst->Data().Length() % 2 == 0, TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
       
   112 	__ASSERT_DEBUG( src->Data().Length() % 2 == 0, TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
       
   113 	
       
   114 	return result;
       
   115 	}
       
   116 
       
   117 /**
       
   118 *
       
   119 * Preconditions
       
   120 * This methos tests the preconditions of the ProcessL method
       
   121 * @return TBool ETrue for sucess and EFalse for failure of the preconditions
       
   122 *
       
   123 **/
       
   124 TBool CMMFPcmU16ToPcm16Codec::CheckPreconditions( const CMMFDataBuffer* aSrcBuffer, CMMFDataBuffer* aDestBuffer )
       
   125 	{
       
   126 	TBool result = EFalse;
       
   127 	
       
   128 	if(! aSrcBuffer )
       
   129 		{
       
   130 		return result;
       
   131 		}
       
   132 	
       
   133 	if( ! aDestBuffer )
       
   134 		{
       
   135 		return result;
       
   136 		}
       
   137 	
       
   138 	// Check position of src and dest are 0
       
   139 	if( aSrcBuffer->Position() )
       
   140 		{
       
   141 		return result;
       
   142 		}
       
   143 	
       
   144 	// Check position of src and dest are 0
       
   145 	if( aDestBuffer->Position() )
       
   146 		{
       
   147 		return result;
       
   148 		}
       
   149 	
       
   150 	// check there are sufficient bytes in the output to consume the input
       
   151 	if( ( aSrcBuffer->Data().Length() > aDestBuffer->Data().MaxLength() ) ||
       
   152 		( aSrcBuffer->Data().Length() % 2 != 0 ) ) // must have pcm16 samples on input
       
   153 		{
       
   154 		return result;
       
   155 		}
       
   156 	
       
   157 	result = ETrue;  // preconditions have been satisfied
       
   158 	
       
   159 	return result;
       
   160 	}