os/mm/devsound/sounddevbt/src/Plugin/HwDevice/Audio/MmfBtPcmS16ToPcmU16Codec.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.
sl@0
     1
// Copyright (c) 2005-2009 Nokia Corporation and/or its subsidiary(-ies).
sl@0
     2
// All rights reserved.
sl@0
     3
// This component and the accompanying materials are made available
sl@0
     4
// under the terms of "Eclipse Public License v1.0"
sl@0
     5
// which accompanies this distribution, and is available
sl@0
     6
// at the URL "http://www.eclipse.org/legal/epl-v10.html".
sl@0
     7
//
sl@0
     8
// Initial Contributors:
sl@0
     9
// Nokia Corporation - initial contribution.
sl@0
    10
//
sl@0
    11
// Contributors:
sl@0
    12
//
sl@0
    13
// Description:
sl@0
    14
//
sl@0
    15
sl@0
    16
#include "MmfBtPcmS16ToPcmU16Codec.h"
sl@0
    17
#include "../../MmfBtFileDependencyUtil.h"
sl@0
    18
sl@0
    19
/**
sl@0
    20
 *
sl@0
    21
 *	Returns the created hw device for passing audio through audio.
sl@0
    22
 *  for the wins implementation this would always be pcm16 although
sl@0
    23
 *  this is effectively a null hw device that will pass any datatype through
sl@0
    24
 *	@return	"CMMFPcm16ToPcmU16BEHwDevice"
sl@0
    25
 *
sl@0
    26
 */
sl@0
    27
CMMFPcm16ToPcmU16HwDevice* CMMFPcm16ToPcmU16HwDevice::NewL()
sl@0
    28
	{
sl@0
    29
    CMMFPcm16ToPcmU16HwDevice* self = new (ELeave) CMMFPcm16ToPcmU16HwDevice();
sl@0
    30
	CleanupStack::PushL(self);
sl@0
    31
	self->ConstructL();
sl@0
    32
	CleanupStack::Pop(self);
sl@0
    33
	return self;
sl@0
    34
	}
sl@0
    35
sl@0
    36
/**
sl@0
    37
*
sl@0
    38
* ~CMMFPcm16ToPcmU16HwDevice
sl@0
    39
*
sl@0
    40
*/
sl@0
    41
CMMFPcm16ToPcmU16HwDevice::~CMMFPcm16ToPcmU16HwDevice()
sl@0
    42
	{
sl@0
    43
	}
sl@0
    44
sl@0
    45
/**
sl@0
    46
*
sl@0
    47
* ConstructL
sl@0
    48
*
sl@0
    49
*/
sl@0
    50
void CMMFPcm16ToPcmU16HwDevice::ConstructL()
sl@0
    51
	{
sl@0
    52
	iCodec = new (ELeave) CMMFPcm16ToPcmU16CodecCodec();
sl@0
    53
	}
sl@0
    54
sl@0
    55
/**
sl@0
    56
*
sl@0
    57
* Codec
sl@0
    58
* @return 'CMMFSwCodec&'
sl@0
    59
*
sl@0
    60
*/
sl@0
    61
CMMFSwCodec& CMMFPcm16ToPcmU16HwDevice::Codec()
sl@0
    62
	{
sl@0
    63
	return *iCodec;
sl@0
    64
	}
sl@0
    65
sl@0
    66
/**
sl@0
    67
*
sl@0
    68
* ProcessL
sl@0
    69
* @param aSrc
sl@0
    70
* @param aDst
sl@0
    71
* @return 'CMMFSwCodec::TCodecProcessResult'
sl@0
    72
* this codec has a does not expand or shrink destination data
sl@0
    73
*/
sl@0
    74
CMMFSwCodec::TCodecProcessResult CMMFPcm16ToPcmU16CodecCodec::ProcessL(const CMMFBuffer& aSrc, CMMFBuffer& aDst)
sl@0
    75
	{
sl@0
    76
	TCodecProcessResult result;
sl@0
    77
	result.iCodecProcessStatus = 	result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
sl@0
    78
	
sl@0
    79
	//convert from generic CMMFBuffer to CMMFDataBuffer
sl@0
    80
	const CMMFDataBuffer* src = STATIC_CAST(const CMMFDataBuffer*, &aSrc);
sl@0
    81
	CMMFDataBuffer* dst = STATIC_CAST(CMMFDataBuffer*, &aDst);
sl@0
    82
	
sl@0
    83
	//[Check Preconditions]
sl@0
    84
	if( !CheckPreconditions( src, dst ))
sl@0
    85
		{
sl@0
    86
		//[ precondition violation ]
sl@0
    87
		User::Leave( KErrArgument );
sl@0
    88
		}
sl@0
    89
	
sl@0
    90
	//we need to cast away CONST even on the source, as the TClass needs a TUint8*
sl@0
    91
	TUint8* pSrc = CONST_CAST(TUint8*,src->Data().Ptr());
sl@0
    92
	TUint8* pDst = CONST_CAST(TUint8*,dst->Data().Ptr());
sl@0
    93
    
sl@0
    94
	TInt srcUse = src->Data().Length();
sl@0
    95
	
sl@0
    96
	TInt noSamples = srcUse/2;
sl@0
    97
	iAudioPcm16ToPcmU16.Convert(pSrc, pDst, noSamples);
sl@0
    98
	
sl@0
    99
	result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
sl@0
   100
	result.iSrcBytesProcessed  = srcUse;
sl@0
   101
	result.iDstBytesAdded      = srcUse;
sl@0
   102
	
sl@0
   103
	dst->Data().SetLength(srcUse);
sl@0
   104
	
sl@0
   105
	//[ post conditions
sl@0
   106
    // srcbytes/2 == destbytes added
sl@0
   107
	// pos src == 0
sl@0
   108
	// pos dest == 0
sl@0
   109
	// src data length is even
sl@0
   110
	// dst data length is even ie pcm16 samples ]
sl@0
   111
	__ASSERT_DEBUG( (src->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
sl@0
   112
	__ASSERT_DEBUG( (dst->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
sl@0
   113
	__ASSERT_DEBUG( src->Data().Length() == dst->Data().Length(), TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
sl@0
   114
	__ASSERT_DEBUG( dst->Data().Length() % 2 == 0, TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
sl@0
   115
	__ASSERT_DEBUG( src->Data().Length() % 2 == 0, TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
sl@0
   116
	
sl@0
   117
	return result;
sl@0
   118
	}
sl@0
   119
sl@0
   120
/**
sl@0
   121
*
sl@0
   122
* Preconditions
sl@0
   123
* This methos tests the preconditions of the ProcessL method
sl@0
   124
* @return TBool ETrue for sucess and EFalse for failure of the preconditions
sl@0
   125
*
sl@0
   126
**/
sl@0
   127
TBool CMMFPcm16ToPcmU16CodecCodec::CheckPreconditions( const CMMFDataBuffer* aSrcBuffer, CMMFDataBuffer* aDestBuffer )
sl@0
   128
	{
sl@0
   129
	TBool result = EFalse;
sl@0
   130
	
sl@0
   131
	if(! aSrcBuffer )
sl@0
   132
		{
sl@0
   133
		return result;
sl@0
   134
		}
sl@0
   135
	
sl@0
   136
	if( ! aDestBuffer )
sl@0
   137
		{
sl@0
   138
		return result;
sl@0
   139
		}
sl@0
   140
	
sl@0
   141
	// Check position of src and dest are 0
sl@0
   142
	if( aSrcBuffer->Position() )
sl@0
   143
		{
sl@0
   144
		return result;
sl@0
   145
		}
sl@0
   146
	
sl@0
   147
	// Check position of src and dest are 0
sl@0
   148
	if( aDestBuffer->Position() )
sl@0
   149
		{
sl@0
   150
		return result;
sl@0
   151
		}
sl@0
   152
	
sl@0
   153
	// check there are sufficient bytes in the output to consume the input
sl@0
   154
	if( ( aSrcBuffer->Data().Length() > aDestBuffer->Data().MaxLength() ) ||
sl@0
   155
		( aSrcBuffer->Data().Length() % 2 != 0 ) ) // must have pcm16 samples on input
sl@0
   156
		{
sl@0
   157
		return result;
sl@0
   158
		}
sl@0
   159
	
sl@0
   160
	result = ETrue;  // preconditions have been satisfied
sl@0
   161
	
sl@0
   162
	return result;
sl@0
   163
	}