os/mm/devsound/sounddevbt/src/Plugin/HwDevice/Audio/MmfBtPcm16ToPcmU8HwDevice.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     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 // MmfPcm16ToPcmU8HwDevice.cpp
    15 // 
    16 //
    17 
    18 #include "MmfBtPcm16ToPcmU8HwDevice.h"
    19 #include "../../MmfBtFileDependencyUtil.h"
    20 
    21 /**
    22  *
    23  *	Returns the created hw device for signed pcm16 to unsigned pcm8 audio.
    24  *
    25  *	@return	"CMMFPcm16ToPcmU8HwDevice"
    26  *
    27  */
    28 CMMFPcm16ToPcmU8HwDevice* CMMFPcm16ToPcmU8HwDevice::NewL()
    29 	{
    30     CMMFPcm16ToPcmU8HwDevice* self = new (ELeave) CMMFPcm16ToPcmU8HwDevice();
    31 	CleanupStack::PushL(self);
    32 	self->ConstructL();
    33 	CleanupStack::Pop(self);
    34 	return self;
    35 	}
    36 
    37 /**
    38  *
    39  *	Second phase constructor.
    40  *
    41  */
    42 void CMMFPcm16ToPcmU8HwDevice::ConstructL()
    43 	{
    44     iCodec = new (ELeave) CMMFPcm16ToPcmU8Codec();
    45 	}
    46 
    47 /**
    48 *
    49 * ~CMMFPcm16ToPcmU8HwDevice
    50 */
    51 CMMFPcm16ToPcmU8HwDevice::~CMMFPcm16ToPcmU8HwDevice()
    52 	{
    53 	//The codec is deleted in the base class CMMFSwCodecWrapper
    54 	}
    55 
    56 /**
    57 *
    58 * Codec
    59 * @return 'CMMFSwCodec&'
    60 *
    61 */
    62 CMMFSwCodec& CMMFPcm16ToPcmU8HwDevice::Codec()
    63 	{
    64 	return *iCodec;
    65 	}
    66 
    67 /**
    68 *
    69 * ProcessL
    70 * @param aSrc 
    71 * @param aDst
    72 * @return 'CMMFSwCodec::TCodecProcessResult'
    73 *
    74 */
    75 CMMFSwCodec::TCodecProcessResult CMMFPcm16ToPcmU8Codec::ProcessL(const CMMFBuffer& aSource, CMMFBuffer& aDest)
    76 	{
    77 	TCodecProcessResult result;
    78 	result.iCodecProcessStatus = 	result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
    79 	
    80 	//convert from generic CMMFBuffer to CMMFDataBuffer
    81 	const CMMFDataBuffer* src = STATIC_CAST(const CMMFDataBuffer*, &aSource);
    82 	CMMFDataBuffer* dst = STATIC_CAST(CMMFDataBuffer*, &aDest);
    83 	
    84 	if( !CheckPreconditions( src, dst ))
    85 		{
    86 		//[ precondition violation ]
    87 		User::Leave( KErrArgument );
    88 		}
    89 	
    90 	//we need to cast away CONST even on the source, as the TClass needs a TUint8*
    91 	TUint8* pSrc = CONST_CAST(TUint8*,src->Data().Ptr());
    92 	TUint8* pDst = CONST_CAST(TUint8*,dst->Data().Ptr());
    93     
    94 	TInt srcUse = src->Data().Length();
    95 	
    96 	TInt noSamples = srcUse /2;
    97 	iAudioS16ToU8Pcm.Convert(pSrc, pDst, noSamples );
    98 	
    99 	result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
   100 	result.iSrcBytesProcessed  = srcUse;
   101 	result.iDstBytesAdded      = srcUse / 2;
   102 	
   103 	dst->Data().SetLength(result.iDstBytesAdded);
   104 	
   105 	//[ post conditions
   106     // srcbytes/2 == destbytes added
   107 	// pos src == 0
   108 	// pos dest == 0 ]
   109 	__ASSERT_DEBUG( (src->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
   110 	__ASSERT_DEBUG( (dst->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
   111 	__ASSERT_DEBUG( src->Data().Length()/2 == dst->Data().Length(), TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
   112 	
   113 	return result;
   114 	}
   115 
   116 /**
   117 *
   118 * Preconditions
   119 * This methos tests the preconditions of the ProcessL method
   120 * @return TBool ETrue for sucess and EFalse for failure of the preconditions
   121 *
   122 **/
   123 TBool CMMFPcm16ToPcmU8Codec::CheckPreconditions( const CMMFDataBuffer* aSrcBuffer, CMMFDataBuffer* aDestBuffer )
   124 	{
   125 	TBool result = EFalse;
   126 	
   127 	if(! aSrcBuffer )
   128 		{
   129 		return result;
   130 		}
   131 	
   132 	if( ! aDestBuffer )
   133 		{
   134 		return result;
   135 		}
   136 	
   137 	// Check position of src and dest are 0
   138 	if( aSrcBuffer->Position() )
   139 		{
   140 		return result;
   141 		}
   142 	
   143 	// Check position of src and dest are 0
   144 	if( aDestBuffer->Position() )
   145 		{
   146 		return result;
   147 		}
   148 	
   149 	// check there are sufficient bytes in the output to consume the input
   150 	if( aSrcBuffer->Data().Length()/2 > aDestBuffer->Data().MaxLength() )
   151 		{
   152 		return result;
   153 		}
   154 	
   155 	result = ETrue;  // preconditions have been satisfied
   156 	
   157 	return result;
   158 	}