os/mm/devsound/sounddevbt/src/Plugin/HwDevice/Audio/MmfBtPcmS8ToPcmS16HwDevice.cpp
author sl@SLION-WIN7.fritz.box
Fri, 15 Jun 2012 03:10:57 +0200
changeset 0 bde4ae8d615e
permissions -rw-r--r--
First public contribution.
     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 
    17 #include "MmfBtPcmS8ToPcmS16HwDevice.h"
    18 #include "../../MmfBtFileDependencyUtil.h"
    19 
    20 /**
    21  *
    22  *	Returns the created hw device for passing audio through audio.
    23  *  for the wins implementation this would always be pcm16 although
    24  *  this is effectively a null hw device that will pass any datatype through
    25  *	@return	"CMMFPcm16ToPcmU16BEHwDevice"
    26  *
    27  */
    28 CMMFPcm8ToPcm16HwDevice* CMMFPcm8ToPcm16HwDevice::NewL()
    29 	{
    30     CMMFPcm8ToPcm16HwDevice* self = new (ELeave) CMMFPcm8ToPcm16HwDevice();
    31 	CleanupStack::PushL(self);
    32 	self->ConstructL();
    33 	CleanupStack::Pop(self);
    34 	return self;
    35 	}
    36 
    37 /**
    38 *
    39 * ~CMMFPcm8ToPcm16HwDevice
    40 */
    41 CMMFPcm8ToPcm16HwDevice::~CMMFPcm8ToPcm16HwDevice()
    42 	{
    43 	}
    44 
    45 /**
    46 *
    47 * ConstructL
    48 *
    49 */
    50 void CMMFPcm8ToPcm16HwDevice::ConstructL()
    51 	{
    52 	iCodec = new (ELeave) CMMFPcm8ToPcm16Codec();
    53 	}
    54 
    55 /**
    56 *
    57 * Codec
    58 * @return 'CMMFSwCodec&'
    59 *
    60 */
    61 CMMFSwCodec& CMMFPcm8ToPcm16HwDevice::Codec()
    62 	{
    63 	return *iCodec;
    64 	}
    65 
    66 /**
    67 *
    68 * ProcessL
    69 * @param aSrc
    70 * @param aDst
    71 * @return 'CMMFSwCodec::TCodecProcessResult'
    72 * this codec expands 1 byte to 2 bytes
    73 */
    74 CMMFSwCodec::TCodecProcessResult CMMFPcm8ToPcm16Codec::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 noSamples = src->Data().Length();
    95 	iAudioPcm8ToPcm16.Convert(pSrc, pDst, noSamples );
    96 	
    97 	result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
    98 	
    99 	TInt dstBytesAdded         = noSamples *sizeof(TInt16);
   100 	result.iSrcBytesProcessed = src->Data().Length();
   101 	result.iDstBytesAdded     = dstBytesAdded;
   102 	dst->Data().SetLength(dstBytesAdded);
   103 	
   104 	//[ check post conditions ]
   105 	__ASSERT_DEBUG( (src->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
   106 	__ASSERT_DEBUG( (dst->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
   107 	__ASSERT_DEBUG( src->Data().Length() == dst->Data().Length()/2, TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation )); // 2 here signifies sizeof TInt16
   108 	__ASSERT_DEBUG( dst->Data().Length() % 2 == 0, TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation )); // pcm output
   109 	
   110 	return result;
   111 	}
   112 
   113 /**
   114 *
   115 * Preconditions
   116 * This methos tests the preconditions of the ProcessL method
   117 * @return TBool ETrue for sucess and EFalse for failure of the preconditions
   118 *
   119 **/
   120 TBool CMMFPcm8ToPcm16Codec::CheckPreconditions( const CMMFDataBuffer* aSrcBuffer, CMMFDataBuffer* aDestBuffer )
   121 	{
   122      TBool result = EFalse;
   123 	 
   124 	 if(! aSrcBuffer )
   125 		 {
   126 		 return result;
   127 		 }
   128 
   129 	 if( ! aDestBuffer )
   130 		 {
   131 		 return result;
   132 		 }
   133 
   134 	 // Check position of src and dest are 0
   135 	 if( aSrcBuffer->Position() )
   136 		 {
   137 		 return result;
   138 		 }
   139 
   140 	  // Check position of src and dest are 0
   141 	 if( aDestBuffer->Position() )
   142 		 {
   143 		 return result;
   144 		 }
   145 
   146 	 // check there are sufficient bytes in the output to consume the input
   147      if( aSrcBuffer->Data().Length() * 2 > aDestBuffer->Data().MaxLength() )
   148 		 {
   149 		 return result;
   150 		 }
   151 
   152 	 result = ETrue;  // preconditions have been satisfied
   153 
   154 	 return result;
   155 	}
   156 
   157 
   158