os/mm/devsound/sounddevbt/src/Plugin/HwDevice/Audio/MmfBtPcm16ToMulawHwDevice.cpp
1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000
1.2 +++ b/os/mm/devsound/sounddevbt/src/Plugin/HwDevice/Audio/MmfBtPcm16ToMulawHwDevice.cpp Fri Jun 15 03:10:57 2012 +0200
1.3 @@ -0,0 +1,156 @@
1.4 +// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
1.5 +// All rights reserved.
1.6 +// This component and the accompanying materials are made available
1.7 +// under the terms of "Eclipse Public License v1.0"
1.8 +// which accompanies this distribution, and is available
1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
1.10 +//
1.11 +// Initial Contributors:
1.12 +// Nokia Corporation - initial contribution.
1.13 +//
1.14 +// Contributors:
1.15 +//
1.16 +// Description:
1.17 +//
1.18 +
1.19 +#include "MmfBtPcm16ToMulawHwDevice.h"
1.20 +#include "../../MmfBtFileDependencyUtil.h"
1.21 +
1.22 +/**
1.23 +*
1.24 +* NewL
1.25 +*
1.26 +*/
1.27 +CMMFPcm16ToMulawHwDevice* CMMFPcm16ToMulawHwDevice::NewL()
1.28 + {
1.29 + CMMFPcm16ToMulawHwDevice* self=new(ELeave) CMMFPcm16ToMulawHwDevice();
1.30 + CleanupStack::PushL(self);
1.31 + self->ConstructL();
1.32 + CleanupStack::Pop(self);
1.33 + return self;
1.34 + }
1.35 +
1.36 +/**
1.37 +*
1.38 +* ~CMMFPcm16ToMulawHwDevice
1.39 +*
1.40 +*/
1.41 +CMMFPcm16ToMulawHwDevice::~CMMFPcm16ToMulawHwDevice()
1.42 + {
1.43 + }
1.44 +
1.45 +/**
1.46 +*
1.47 +* ConstructL
1.48 +*
1.49 +*/
1.50 +void CMMFPcm16ToMulawHwDevice::ConstructL()
1.51 + {
1.52 + iCodec = new (ELeave) CMMFPcm16ToMuLawCodec();
1.53 + }
1.54 +
1.55 +/**
1.56 +*
1.57 +* Codec
1.58 +*
1.59 +*/
1.60 +CMMFSwCodec &CMMFPcm16ToMulawHwDevice::Codec()
1.61 + {
1.62 + return *iCodec;
1.63 + }
1.64 +
1.65 +/**
1.66 +*
1.67 +* ProcessL
1.68 +* @param aSrc
1.69 +* @param aDst
1.70 +* @pre position of buffer aSrc is 0
1.71 +* @pre position of buffer aDst is 0
1.72 +* @pre sufficient bytes in output to consume input
1.73 +* @return TCodecProcessResult
1.74 +*
1.75 +*/
1.76 +CMMFSwCodec::TCodecProcessResult CMMFPcm16ToMuLawCodec::ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDst)
1.77 + {
1.78 + CMMFSwCodec::TCodecProcessResult result;
1.79 + result.iCodecProcessStatus = result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
1.80 +
1.81 + //convert from generic CMMFBuffer to CMMFDataBuffer
1.82 + const CMMFDataBuffer* src = STATIC_CAST(const CMMFDataBuffer*, &aSrc);
1.83 + CMMFDataBuffer* dst = STATIC_CAST(CMMFDataBuffer*, &aDst);
1.84 +
1.85 + if( !CheckPreconditions( src, dst ) )
1.86 + {
1.87 + //[ precondition(s) violation ]
1.88 + User::Leave(KErrArgument);
1.89 + }
1.90 +
1.91 + TUint8* pSrc = CONST_CAST(TUint8*,src->Data().Ptr());
1.92 + TUint8* pDst = CONST_CAST(TUint8*,dst->Data().Ptr());
1.93 +
1.94 + TUint destUse = src->Data().Length()/2;
1.95 +
1.96 + //compress TWO bytes (16-bit PCM word) into a to 1 byte sample
1.97 + iPcm16ToMuLaw.Convert(pSrc, pDst, destUse );
1.98 +
1.99 + result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
1.100 + result.iSrcBytesProcessed = src->Data().Length();
1.101 + result.iDstBytesAdded = destUse;
1.102 +
1.103 + dst->Data().SetLength(result.iDstBytesAdded);
1.104 +
1.105 + //[ post conditions
1.106 + // srcbytes/2 == destbytes added
1.107 + // pos src == 0
1.108 + // pos dest == 0 ]
1.109 + __ASSERT_DEBUG( (src->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
1.110 + __ASSERT_DEBUG( (dst->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
1.111 + __ASSERT_DEBUG( src->Data().Length()/2 == dst->Data().Length(), TMmfAudioCodecPanicsNameSpace::Panic( TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
1.112 +
1.113 + return result;
1.114 + }
1.115 +
1.116 +/**
1.117 +*
1.118 +* Preconditions
1.119 +* This method tests the preconditions of the ProcessL method
1.120 +* @return TBool ETrue for sucess and EFalse for failure of the preconditions
1.121 +*
1.122 +**/
1.123 +TBool CMMFPcm16ToMuLawCodec::CheckPreconditions( const CMMFDataBuffer* aSrcBuffer, CMMFDataBuffer* aDestBuffer )
1.124 + {
1.125 + TBool result = EFalse;
1.126 +
1.127 + if(! aSrcBuffer )
1.128 + {
1.129 + return result;
1.130 + }
1.131 +
1.132 + if( ! aDestBuffer )
1.133 + {
1.134 + return result;
1.135 + }
1.136 +
1.137 + // Check position of src and dest are 0
1.138 + if( aSrcBuffer->Position() )
1.139 + {
1.140 + return result;
1.141 + }
1.142 +
1.143 + // Check position of src and dest are 0
1.144 + if( aDestBuffer->Position() )
1.145 + {
1.146 + return result;
1.147 + }
1.148 +
1.149 + // check there are sufficient bytes in the output to consume the input
1.150 + if( ( aSrcBuffer->Data().Length()/2 > aDestBuffer->Data().MaxLength()) ||
1.151 + ( aSrcBuffer->Data().Length() % 2 != 0 ))
1.152 + {
1.153 + return result;
1.154 + }
1.155 +
1.156 + result = ETrue; // preconditions have been satisfied
1.157 +
1.158 + return result;
1.159 + }