os/mm/devsound/devsoundrefplugin/src/plugin/audio/MMFpcmU8ToPcm16HwDevice.cpp
author sl
Tue, 10 Jun 2014 14:32:02 +0200
changeset 1 260cb5ec6c19
permissions -rw-r--r--
Update contrib.
sl@0
     1
// Copyright (c) 2003-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 "MMFpcmU8ToPcm16HwDevice.h"
sl@0
    17
sl@0
    18
/**
sl@0
    19
 *
sl@0
    20
 *	Returns the created hw device for unsigned pcm8 to signed pcm16 audio.
sl@0
    21
 *
sl@0
    22
 *	@return	"CMMFPcmU8ToPcm16HwDevice"
sl@0
    23
 *
sl@0
    24
 */
sl@0
    25
CMMFPcmU8ToPcm16HwDevice* CMMFPcmU8ToPcm16HwDevice::NewL()
sl@0
    26
	{
sl@0
    27
    CMMFPcmU8ToPcm16HwDevice* self = new (ELeave) CMMFPcmU8ToPcm16HwDevice();
sl@0
    28
	CleanupStack::PushL(self);
sl@0
    29
	self->ConstructL();
sl@0
    30
	CleanupStack::Pop(self);
sl@0
    31
	return self;
sl@0
    32
	}
sl@0
    33
sl@0
    34
/**
sl@0
    35
 *
sl@0
    36
 *	Second phase constructor.
sl@0
    37
 *
sl@0
    38
 */
sl@0
    39
void CMMFPcmU8ToPcm16HwDevice::ConstructL()
sl@0
    40
	{
sl@0
    41
    iCodec = new (ELeave) CMMFPcmU8ToPcm16Codec();
sl@0
    42
	}
sl@0
    43
sl@0
    44
/**
sl@0
    45
*
sl@0
    46
* ~CMMFPcmU8ToPcm16HwDevice
sl@0
    47
*
sl@0
    48
*/
sl@0
    49
CMMFPcmU8ToPcm16HwDevice::~CMMFPcmU8ToPcm16HwDevice()
sl@0
    50
	{
sl@0
    51
	//The codec is deleted in the base class CMMFSwCodecWrapper
sl@0
    52
	}
sl@0
    53
sl@0
    54
/**
sl@0
    55
*
sl@0
    56
* Codec
sl@0
    57
* @return 'CMMFSwCodec&'
sl@0
    58
*
sl@0
    59
*/
sl@0
    60
CMMFSwCodec& CMMFPcmU8ToPcm16HwDevice::Codec()
sl@0
    61
	{
sl@0
    62
	return *iCodec;
sl@0
    63
	}
sl@0
    64
sl@0
    65
/**
sl@0
    66
*
sl@0
    67
* ProcessL
sl@0
    68
* @param aSource
sl@0
    69
* @param aDst 
sl@0
    70
* @return 'CMMFSwCodec::TCodecProcessResult'
sl@0
    71
*
sl@0
    72
*/
sl@0
    73
CMMFSwCodec::TCodecProcessResult CMMFPcmU8ToPcm16Codec::ProcessL(const CMMFBuffer& aSource, CMMFBuffer& aDest)
sl@0
    74
	{
sl@0
    75
	TCodecProcessResult result;
sl@0
    76
	result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
sl@0
    77
	
sl@0
    78
	//convert from generic CMMFBuffer to CMMFDataBuffer
sl@0
    79
	const CMMFDataBuffer* src = STATIC_CAST(const CMMFDataBuffer*, &aSource);
sl@0
    80
	CMMFDataBuffer* dst = STATIC_CAST(CMMFDataBuffer*, &aDest);
sl@0
    81
	
sl@0
    82
	//[ check preconditions ]
sl@0
    83
	if( !CheckPreconditions( src, dst ))
sl@0
    84
		{
sl@0
    85
		//[ precondition violation ]
sl@0
    86
		User::Leave( KErrArgument );
sl@0
    87
		}
sl@0
    88
	
sl@0
    89
	//we need to cast away CONST even on the source, as the TClass needs a TUint8*
sl@0
    90
	TUint8* pSrc = CONST_CAST(TUint8*,src->Data().Ptr());
sl@0
    91
	TUint8* pDst = CONST_CAST(TUint8*,dst->Data().Ptr());
sl@0
    92
	
sl@0
    93
	TInt srcUse = src->Data().Length();
sl@0
    94
	TInt noSamples = srcUse;
sl@0
    95
	iAudioU8ToS16Pcm.Convert(pSrc, pDst, noSamples );
sl@0
    96
	
sl@0
    97
	TInt dstBytesAdded = srcUse * 2;
sl@0
    98
	result.iCodecProcessStatus = TCodecProcessResult::EProcessComplete;
sl@0
    99
	result.iSrcBytesProcessed  = srcUse;
sl@0
   100
	result.iDstBytesAdded      = dstBytesAdded;
sl@0
   101
	
sl@0
   102
	dst->Data().SetLength(dstBytesAdded);
sl@0
   103
	
sl@0
   104
	//[ check post conditions ]
sl@0
   105
	__ASSERT_DEBUG( (src->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
sl@0
   106
	__ASSERT_DEBUG( (dst->Position() == 0), TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation ));
sl@0
   107
	__ASSERT_DEBUG( src->Data().Length() == dst->Data().Length()/2, TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation )); // 2 here signifies sizeof TInt16
sl@0
   108
	__ASSERT_DEBUG( dst->Data().Length() % 2 == 0, TMmfAudioCodecPanicsNameSpace::Panic( 	TMmfAudioCodecPanicsNameSpace::EPostConditionViolation )); // pcm output
sl@0
   109
	
sl@0
   110
	return result;
sl@0
   111
	}
sl@0
   112
sl@0
   113
/**
sl@0
   114
*
sl@0
   115
* Preconditions
sl@0
   116
* This methos tests the preconditions of the ProcessL method
sl@0
   117
* @return TBool ETrue for sucess and EFalse for failure of the preconditions
sl@0
   118
*
sl@0
   119
**/
sl@0
   120
TBool CMMFPcmU8ToPcm16Codec::CheckPreconditions( const CMMFDataBuffer* aSrcBuffer, CMMFDataBuffer* aDestBuffer )
sl@0
   121
	{
sl@0
   122
	TBool result = EFalse;
sl@0
   123
	
sl@0
   124
	if(! aSrcBuffer )
sl@0
   125
		{
sl@0
   126
		return result;
sl@0
   127
		}
sl@0
   128
	
sl@0
   129
	if( ! aDestBuffer )
sl@0
   130
		{
sl@0
   131
		return result;
sl@0
   132
		}
sl@0
   133
	
sl@0
   134
	// Check position of src and dest are 0
sl@0
   135
	if( aSrcBuffer->Position() )
sl@0
   136
		{
sl@0
   137
		return result;
sl@0
   138
		}
sl@0
   139
	
sl@0
   140
	// Check position of src and dest are 0
sl@0
   141
	if( aDestBuffer->Position() )
sl@0
   142
		{
sl@0
   143
		return result;
sl@0
   144
		}
sl@0
   145
	
sl@0
   146
	// check there are sufficient bytes in the output to consume the input
sl@0
   147
	if( aSrcBuffer->Data().Length() * 2 > aDestBuffer->Data().MaxLength() )
sl@0
   148
		{
sl@0
   149
		return result;
sl@0
   150
		}
sl@0
   151
	
sl@0
   152
	result = ETrue;  // preconditions have been satisfied
sl@0
   153
	
sl@0
   154
	return result;
sl@0
   155
	}