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