devsound/sounddevbt/src/Plugin/HwDevice/Audio/MmfBtPcm16ToPcmU16BEHwDevice.cpp
changeset 0 40261b775718
equal deleted inserted replaced
-1:000000000000 0:40261b775718
       
     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 "MmfBtPcm16ToPcmU16BEHwDevice.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 CMMFPcm16ToPcmU16BEHwDevice* CMMFPcm16ToPcmU16BEHwDevice::NewL()
       
    28 	{
       
    29     CMMFPcm16ToPcmU16BEHwDevice* self = new (ELeave) CMMFPcm16ToPcmU16BEHwDevice();
       
    30 	CleanupStack::PushL(self);
       
    31 	self->ConstructL();
       
    32 	CleanupStack::Pop(self);
       
    33 	return self;
       
    34 	}
       
    35 
       
    36 /**
       
    37 *
       
    38 * ~CMMFPcm16ToPcmU16BEHwDevice
       
    39 */
       
    40 CMMFPcm16ToPcmU16BEHwDevice::~CMMFPcm16ToPcmU16BEHwDevice()
       
    41 	{
       
    42 	}
       
    43 
       
    44 /**
       
    45 *
       
    46 * ConstructL
       
    47 *
       
    48 */
       
    49 void CMMFPcm16ToPcmU16BEHwDevice::ConstructL()
       
    50 	{
       
    51 	iCodec = new (ELeave) CMMFPcm16ToPcmU16BECodec();
       
    52 	}
       
    53 
       
    54 /**
       
    55 *
       
    56 * Codec
       
    57 * @return 'CMMFSwCodec&'
       
    58 */
       
    59 CMMFSwCodec& CMMFPcm16ToPcmU16BEHwDevice::Codec()
       
    60 	{
       
    61 	return *iCodec;
       
    62 	}
       
    63 
       
    64 /**
       
    65 *
       
    66 * ProcessL
       
    67 * @param aSrc 
       
    68 * @param aDst
       
    69 * @pre position of buffer aSrc is 0
       
    70 * @pre position of buffer aDst is 0
       
    71 * @pre sufficient bytes in output to consume input
       
    72 * @return 'CMMFSwCodec::TCodecProcessResult'
       
    73 * this codec has a does not expand or shrink destination data
       
    74 */
       
    75 CMMFSwCodec::TCodecProcessResult CMMFPcm16ToPcmU16BECodec::ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDst)
       
    76 	{
       
    77 	TCodecProcessResult result;
       
    78 	result.iCodecProcessStatus = 	result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
       
    79 	
       
    80 	//convert from generic CMMFBuffer to CMMFDataBuffer
       
    81 	const CMMFDataBuffer* src = STATIC_CAST(const CMMFDataBuffer*, &aSrc);
       
    82 	CMMFDataBuffer* dst = STATIC_CAST(CMMFDataBuffer*, &aDst);
       
    83 	
       
    84 	//[ Check preconsitions ]
       
    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     
       
    95 	TInt srcUse = src->Data().Length();
       
    96 	
       
    97 	TInt noSamples = srcUse/2; // for pcm16 TInt16
       
    98 	iAudioPcm16ToPcmU16Be.Convert(pSrc, pDst, noSamples );
       
    99 	
       
   100 	result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
       
   101 	result.iSrcBytesProcessed  = srcUse;
       
   102 	result.iDstBytesAdded      = srcUse;
       
   103 	
       
   104 	dst->Data().SetLength(srcUse);
       
   105 	
       
   106 	//[ Check post conditions ]
       
   107 	__ASSERT_DEBUG( (src->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
       
   108 	__ASSERT_DEBUG( (dst->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
       
   109 	__ASSERT_DEBUG( src->Data().Length() == dst->Data().Length(), TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
       
   110 	__ASSERT_DEBUG( dst->Data().Length() % 2 == 0, TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation )); // pcm output
       
   111 	
       
   112 	return result;
       
   113 	}
       
   114 
       
   115 /**
       
   116 *
       
   117 * Preconditions
       
   118 * This methos tests the preconditions of the ProcessL method
       
   119 * @return TBool ETrue for sucess and EFalse for failure of the preconditions
       
   120 *
       
   121 **/
       
   122 TBool CMMFPcm16ToPcmU16BECodec::CheckPreconditions( const CMMFDataBuffer* aSrcBuffer, CMMFDataBuffer* aDestBuffer )
       
   123 	{
       
   124      TBool result = EFalse;
       
   125 	 
       
   126 	 if(! aSrcBuffer )
       
   127 		 {
       
   128 		 return result;
       
   129 		 }
       
   130 	 
       
   131 	 if( ! aDestBuffer )
       
   132 		 {
       
   133 		 return result;
       
   134 		 }
       
   135 	 
       
   136 	 // Check position of src and dest are 0
       
   137 	 if( aSrcBuffer->Position() )
       
   138 		 {
       
   139 		 return result;
       
   140 		 }
       
   141 	 
       
   142 	 // Check position of src and dest are 0
       
   143 	 if( aDestBuffer->Position() )
       
   144 		 {
       
   145 		 return result;
       
   146 		 }
       
   147 	 
       
   148 	 // check there are sufficient bytes in the output to consume the input
       
   149      if( ( aSrcBuffer->Data().Length() > aDestBuffer->Data().MaxLength() ) ||
       
   150 		 ( aSrcBuffer->Data().Length() % 2 != 0 ) ) // must have pcm16 samples on input
       
   151 		 {
       
   152 		 return result;
       
   153 		 }
       
   154 	 
       
   155 	 result = ETrue;  // preconditions have been satisfied
       
   156 	 
       
   157 	 return result;
       
   158 	}
       
   159