os/mm/devsound/sounddevbt/src/Plugin/HwDevice/Audio/MmfBtPcmS16ToPcmU16Codec.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
     1 // Copyright (c) 2005-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 "MmfBtPcmS16ToPcmU16Codec.h"
    17 #include "../../MmfBtFileDependencyUtil.h"
    18 
    19 /**
    20  *
    21  *	Returns the created hw device for passing audio through audio.
    22  *  for the wins implementation this would always be pcm16 although
    23  *  this is effectively a null hw device that will pass any datatype through
    24  *	@return	"CMMFPcm16ToPcmU16BEHwDevice"
    25  *
    26  */
    27 CMMFPcm16ToPcmU16HwDevice* CMMFPcm16ToPcmU16HwDevice::NewL()
    28 	{
    29     CMMFPcm16ToPcmU16HwDevice* self = new (ELeave) CMMFPcm16ToPcmU16HwDevice();
    30 	CleanupStack::PushL(self);
    31 	self->ConstructL();
    32 	CleanupStack::Pop(self);
    33 	return self;
    34 	}
    35 
    36 /**
    37 *
    38 * ~CMMFPcm16ToPcmU16HwDevice
    39 *
    40 */
    41 CMMFPcm16ToPcmU16HwDevice::~CMMFPcm16ToPcmU16HwDevice()
    42 	{
    43 	}
    44 
    45 /**
    46 *
    47 * ConstructL
    48 *
    49 */
    50 void CMMFPcm16ToPcmU16HwDevice::ConstructL()
    51 	{
    52 	iCodec = new (ELeave) CMMFPcm16ToPcmU16CodecCodec();
    53 	}
    54 
    55 /**
    56 *
    57 * Codec
    58 * @return 'CMMFSwCodec&'
    59 *
    60 */
    61 CMMFSwCodec& CMMFPcm16ToPcmU16HwDevice::Codec()
    62 	{
    63 	return *iCodec;
    64 	}
    65 
    66 /**
    67 *
    68 * ProcessL
    69 * @param aSrc
    70 * @param aDst
    71 * @return 'CMMFSwCodec::TCodecProcessResult'
    72 * this codec has a does not expand or shrink destination data
    73 */
    74 CMMFSwCodec::TCodecProcessResult CMMFPcm16ToPcmU16CodecCodec::ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDst)
    75 	{
    76 	TCodecProcessResult result;
    77 	result.iCodecProcessStatus = 	result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
    78 	
    79 	//convert from generic CMMFBuffer to CMMFDataBuffer
    80 	const CMMFDataBuffer* src = STATIC_CAST(const CMMFDataBuffer*, &aSrc);
    81 	CMMFDataBuffer* dst = STATIC_CAST(CMMFDataBuffer*, &aDst);
    82 	
    83 	//[Check Preconditions]
    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 	iAudioPcm16ToPcmU16.Convert(pSrc, pDst, noSamples);
    98 	
    99 	result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
   100 	result.iSrcBytesProcessed  = srcUse;
   101 	result.iDstBytesAdded      = srcUse;
   102 	
   103 	dst->Data().SetLength(srcUse);
   104 	
   105 	//[ post conditions
   106     // srcbytes/2 == destbytes added
   107 	// pos src == 0
   108 	// pos dest == 0
   109 	// src data length is even
   110 	// dst data length is even ie pcm16 samples ]
   111 	__ASSERT_DEBUG( (src->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
   112 	__ASSERT_DEBUG( (dst->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
   113 	__ASSERT_DEBUG( src->Data().Length() == dst->Data().Length(), TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
   114 	__ASSERT_DEBUG( dst->Data().Length() % 2 == 0, TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
   115 	__ASSERT_DEBUG( src->Data().Length() % 2 == 0, TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
   116 	
   117 	return result;
   118 	}
   119 
   120 /**
   121 *
   122 * Preconditions
   123 * This methos tests the preconditions of the ProcessL method
   124 * @return TBool ETrue for sucess and EFalse for failure of the preconditions
   125 *
   126 **/
   127 TBool CMMFPcm16ToPcmU16CodecCodec::CheckPreconditions( const CMMFDataBuffer* aSrcBuffer, CMMFDataBuffer* aDestBuffer )
   128 	{
   129 	TBool result = EFalse;
   130 	
   131 	if(! aSrcBuffer )
   132 		{
   133 		return result;
   134 		}
   135 	
   136 	if( ! aDestBuffer )
   137 		{
   138 		return result;
   139 		}
   140 	
   141 	// Check position of src and dest are 0
   142 	if( aSrcBuffer->Position() )
   143 		{
   144 		return result;
   145 		}
   146 	
   147 	// Check position of src and dest are 0
   148 	if( aDestBuffer->Position() )
   149 		{
   150 		return result;
   151 		}
   152 	
   153 	// check there are sufficient bytes in the output to consume the input
   154 	if( ( aSrcBuffer->Data().Length() > aDestBuffer->Data().MaxLength() ) ||
   155 		( aSrcBuffer->Data().Length() % 2 != 0 ) ) // must have pcm16 samples on input
   156 		{
   157 		return result;
   158 		}
   159 	
   160 	result = ETrue;  // preconditions have been satisfied
   161 	
   162 	return result;
   163 	}