os/mm/devsound/devsoundrefplugin/src/swcodecwrapper/mmfSwCodecDataPath.cpp
changeset 0 bde4ae8d615e
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/os/mm/devsound/devsoundrefplugin/src/swcodecwrapper/mmfSwCodecDataPath.cpp	Fri Jun 15 03:10:57 2012 +0200
     1.3 @@ -0,0 +1,155 @@
     1.4 +// Copyright (c) 2003-2009 Nokia Corporation and/or its subsidiary(-ies).
     1.5 +// All rights reserved.
     1.6 +// This component and the accompanying materials are made available
     1.7 +// under the terms of "Eclipse Public License v1.0"
     1.8 +// which accompanies this distribution, and is available
     1.9 +// at the URL "http://www.eclipse.org/legal/epl-v10.html".
    1.10 +//
    1.11 +// Initial Contributors:
    1.12 +// Nokia Corporation - initial contribution.
    1.13 +//
    1.14 +// Contributors:
    1.15 +//
    1.16 +// Description:
    1.17 +// source\server\mmfswcodecdatapath.cpp
    1.18 +// 
    1.19 +//
    1.20 +
    1.21 +#include "mmfSwCodecDataPath.h"
    1.22 +
    1.23 +
    1.24 +CMMFSwCodecDataPath::~CMMFSwCodecDataPath()
    1.25 +	{
    1.26 +
    1.27 +	}
    1.28 +	
    1.29 +/**
    1.30 +Retrieves a custom interface to the device.
    1.31 +Usually the derived class should
    1.32 +return the implementation for this.
    1.33 +
    1.34 +@param	aInterface
    1.35 +		Interface UID, defined with the custom interface.
    1.36 +		
    1.37 +@return NULL 
    1.38 +
    1.39 +*/
    1.40 +TAny* CMMFSwCodecDataPath::CustomInterface(TUid /*aInterface*/)
    1.41 +	{
    1.42 +	return NULL;
    1.43 +	}
    1.44 +	
    1.45 +	
    1.46 +
    1.47 +/*
    1.48 + * CycleAudioBufferL
    1.49 + *
    1.50 + * Sets up a usable buffer for passing to MMF
    1.51 + *	
    1.52 + * This method has been written such that it must allocate a new buffer before
    1.53 + * replacing the existing one. The purpose of this is to force creation of a 
    1.54 + * new buffer. Simply deleting and then re-allocing may result in the same 
    1.55 + * address being used.
    1.56 + * 
    1.57 + * Only cycles if there is enough memory
    1.58 + *
    1.59 + */
    1.60 +#ifdef __CYCLE_MMF_DATABUFFERS__
    1.61 +CMMFDataBuffer* CMMFSwCodecDataPath::CycleAudioBuffer(CMMFDataBuffer* aBuffer)
    1.62 +	{
    1.63 +	CMMFDataBuffer* buffer = NULL;
    1.64 +	TUint bufferSize = aBuffer->Data().MaxLength();
    1.65 +
    1.66 +#ifdef __USE_MMF_TRANSFERBUFFERS__
    1.67 +	TRAPD(err, buffer = CreateTransferBufferL(bufferSize, static_cast<CMMFTransferBuffer*>(aBuffer)));
    1.68 +#else
    1.69 +	TRAPD(err,buffer = CMMFDataBuffer::NewL(bufferSize));
    1.70 +
    1.71 +	if (err == KErrNone)
    1.72 +		{
    1.73 +		delete aBuffer;
    1.74 +		}
    1.75 +#endif
    1.76 +	if (err != KErrNone)
    1.77 +		{//there was a problem creating buffer eg OOM so use same buffer
    1.78 +		buffer = aBuffer;
    1.79 +		}
    1.80 +
    1.81 +	return buffer;
    1.82 +
    1.83 +	}
    1.84 +#endif
    1.85 +
    1.86 +/*
    1.87 + * DoCleanupRHandleBase
    1.88 + *
    1.89 + * This method will initially Close the handle and then delete it.
    1.90 + *
    1.91 + */
    1.92 +#ifdef __USE_MMF_TRANSFERBUFFERS__
    1.93 +inline static void DoCleanupRHandleBase(TAny* aRHandleBase)
    1.94 +	{
    1.95 +	ASSERT(aRHandleBase);
    1.96 +	RHandleBase* rHandleBase = STATIC_CAST(RHandleBase*, aRHandleBase);
    1.97 +	TRAPD(error, rHandleBase->Close());
    1.98 +	delete aRHandleBase;
    1.99 +	}
   1.100 +
   1.101 +CMMFTransferBuffer* CMMFSwCodecDataPath::CreateTransferBufferL(TUint aBufferSize, CMMFTransferBuffer* aOldBuffer)
   1.102 +	{
   1.103 +	CMMFTransferBuffer* buffer = NULL;
   1.104 +
   1.105 +	RTransferBuffer* transBuffer = new  (ELeave) RTransferBuffer;
   1.106 +	
   1.107 +	TCleanupItem bufferCleanupItem(DoCleanupRHandleBase, transBuffer); //closes and deletes.
   1.108 +	CleanupStack::PushL(bufferCleanupItem);
   1.109 +
   1.110 +	RTransferWindow* transWindow = new (ELeave) RTransferWindow;
   1.111 +	
   1.112 +	TCleanupItem windowCleanupItem(DoCleanupRHandleBase, transWindow); //closes and deletes.
   1.113 +	CleanupStack::PushL(windowCleanupItem);
   1.114 +
   1.115 +	User::LeaveIfError(transBuffer->Create(aBufferSize));
   1.116 +	User::LeaveIfError(transWindow->Create(aBufferSize));
   1.117 +	User::LeaveIfError(transWindow->MapInBuffer(*transBuffer));
   1.118 +
   1.119 +	buffer = CMMFTransferBuffer::NewL(*transWindow);
   1.120 +
   1.121 +	delete aOldBuffer; //closes RTransferWindow
   1.122 +	delete iTransferWindow;
   1.123 +
   1.124 +	if(iTransferBuffer)
   1.125 +		{
   1.126 +		iTransferBuffer->Close();
   1.127 +		}
   1.128 +	delete iTransferBuffer;
   1.129 +
   1.130 +	iTransferBuffer = transBuffer;
   1.131 +	iTransferWindow = transWindow;
   1.132 +
   1.133 +	CleanupStack::Pop(transWindow); 
   1.134 +	CleanupStack::Pop(transBuffer); 
   1.135 +
   1.136 +	return buffer;
   1.137 +	}
   1.138 +#endif
   1.139 +
   1.140 +
   1.141 +#ifdef __USE_MMF_PTRBUFFERS__
   1.142 +CMMFPtrBuffer* CMMFSwCodecDataPath::CreatePtrBufferL(TUint aBufferSize)
   1.143 +	{
   1.144 +	CMMFPtrBuffer* buffer = NULL;
   1.145 +	if (iPtrBufferMemoryBlock)
   1.146 +		{
   1.147 +		delete iPtrBufferMemoryBlock;//incase already exisits
   1.148 +		iPtrBufferMemoryBlock = NULL;
   1.149 +		}
   1.150 +	iPtrBufferMemoryBlock = HBufC8::NewL(aBufferSize);
   1.151 +	TPtr8 ptrMemoryBlock(iPtrBufferMemoryBlock->Des());
   1.152 +	buffer = CMMFPtrBuffer::NewL(ptrMemoryBlock);
   1.153 +	return buffer;
   1.154 +	}
   1.155 +#endif  // __USE_MMF_PTRBUFFERS__
   1.156 +
   1.157 +
   1.158 +