os/mm/devsound/sounddevbt/src/Plugin/HwDevice/Audio/MmfBtMuLawToPcm16HwDevice.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 "MmfBtAudioCodec.h"
    17 #include <mmfpaniccodes.h>
    18 #include "MmfBtMuLawToPcm16HwDevice.h"
    19 #include "../../MmfBtFileDependencyUtil.h"
    20 
    21 /**
    22 *
    23 * NewL
    24 *
    25 */
    26 CMMFMulawToPcm16CodecHwDevice* CMMFMulawToPcm16CodecHwDevice::NewL()
    27 	{
    28 	CMMFMulawToPcm16CodecHwDevice* self=new(ELeave) CMMFMulawToPcm16CodecHwDevice();
    29 	CleanupStack::PushL(self);
    30 	self->ConstructL();
    31 	CleanupStack::Pop(self);
    32 	return self;
    33 	}
    34 
    35 /**
    36 *
    37 * ~CMMFMulawPcm16HwDevice
    38 *
    39 */
    40 CMMFMulawToPcm16CodecHwDevice::~CMMFMulawToPcm16CodecHwDevice()
    41 	{
    42 	}
    43 
    44 /**
    45 *
    46 * ConstructL
    47 *
    48 */
    49 void CMMFMulawToPcm16CodecHwDevice::ConstructL()
    50 	{
    51 	iCodec = new (ELeave) CMMFMulawToPcm16Codec();
    52 	}
    53 
    54 /**
    55 *
    56 * Codec
    57 *
    58 */
    59 CMMFSwCodec &CMMFMulawToPcm16CodecHwDevice::Codec()
    60 	{
    61 	return *iCodec;
    62 	}
    63 
    64 /**
    65 *
    66 * ProcessL
    67 * @param aSrc
    68 * @param aDst
    69 * @return TCodecProcessResult
    70 *
    71 */
    72 CMMFSwCodec::TCodecProcessResult CMMFMulawToPcm16Codec::ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDst)
    73 	{
    74 	CMMFSwCodec::TCodecProcessResult result;
    75 	result.iCodecProcessStatus = 	result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
    76 	
    77 	//convert from generic CMMFBuffer to CMMFDataBuffer
    78 	const CMMFDataBuffer* src = STATIC_CAST(const CMMFDataBuffer*, &aSrc);
    79 	CMMFDataBuffer* dst = STATIC_CAST(CMMFDataBuffer*, &aDst);
    80 	
    81 	//[check preconditions hold ]
    82 	if( !CheckPreconditions( src, dst ))
    83 		{
    84 		//[ precondition violation ]
    85 		User::Leave( KErrArgument );
    86 		}
    87 	
    88 	//we need to cast away CONST even on the source, as the TClass needs a TUint8*
    89 	TUint8* pSrc = CONST_CAST(TUint8*,src->Data().Ptr());
    90 	TUint8* pDst = CONST_CAST(TUint8*,dst->Data().Ptr());
    91 	TInt noSamples = src->Data().Length();
    92 	
    93 	iMulawTo16Pcm.Convert(pSrc, pDst, noSamples );
    94 	
    95 	TUint dstBytesAdded = noSamples*sizeof(TInt16);
    96 	
    97 	result.iCodecProcessStatus  = TCodecProcessResult::EProcessComplete;
    98 	result.iSrcBytesProcessed   = src->Data().Length();
    99 	result.iDstBytesAdded       = dstBytesAdded;
   100 	
   101 	dst->Data().SetLength( dstBytesAdded );
   102 	
   103 	//[ check post conditions ]
   104 	__ASSERT_DEBUG( (src->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
   105 	__ASSERT_DEBUG( (dst->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
   106 	__ASSERT_DEBUG( src->Data().Length() == dst->Data().Length()/2, TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation )); // 2 here signifies sizeof TInt16
   107 	__ASSERT_DEBUG( dst->Data().Length() % 2 == 0, TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation )); // pcm output
   108 	
   109 	return result;
   110 	}
   111 
   112 /**
   113 *
   114 * Preconditions
   115 * This methos tests the preconditions of the ProcessL method
   116 * @return TBool ETrue for sucess and EFalse for failure of the preconditions
   117 *
   118 **/
   119 TBool CMMFMulawToPcm16Codec::CheckPreconditions( const CMMFDataBuffer* aSrcBuffer, CMMFDataBuffer* aDestBuffer )
   120 	{
   121 	TBool result = EFalse;
   122 	
   123 	if(! aSrcBuffer )
   124 		{
   125 		return result;
   126 		}
   127 	
   128 	if( ! aDestBuffer )
   129 		{
   130 		return result;
   131 		}
   132 	
   133 	// Check position of src and dest are 0
   134 	if( aSrcBuffer->Position() )
   135 		{
   136 		return result;
   137 		}
   138 	
   139 	// Check position of src and dest are 0
   140 	if( aDestBuffer->Position() )
   141 		{
   142 		return result;
   143 		}
   144 	
   145 	// check there are sufficient bytes in the output to consume the input
   146 	if( aSrcBuffer->Data().Length() > aDestBuffer->Data().MaxLength()/2 )
   147 		{
   148 		return result;
   149 		}
   150 	
   151 	result = ETrue;  // preconditions have been satisfied
   152 	
   153 	return result;
   154 	}