Update contrib.
1 // Copyright (c) 2003-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".
8 // Initial Contributors:
9 // Nokia Corporation - initial contribution.
14 // source\server\mmfswcodecdatapath.cpp
18 #include "mmfSwCodecDataPath.h"
21 CMMFSwCodecDataPath::~CMMFSwCodecDataPath()
27 Retrieves a custom interface to the device.
28 Usually the derived class should
29 return the implementation for this.
32 Interface UID, defined with the custom interface.
37 TAny* CMMFSwCodecDataPath::CustomInterface(TUid /*aInterface*/)
47 * Sets up a usable buffer for passing to MMF
49 * This method has been written such that it must allocate a new buffer before
50 * replacing the existing one. The purpose of this is to force creation of a
51 * new buffer. Simply deleting and then re-allocing may result in the same
54 * Only cycles if there is enough memory
57 #ifdef __CYCLE_MMF_DATABUFFERS__
58 CMMFDataBuffer* CMMFSwCodecDataPath::CycleAudioBuffer(CMMFDataBuffer* aBuffer)
60 CMMFDataBuffer* buffer = NULL;
61 TUint bufferSize = aBuffer->Data().MaxLength();
63 #ifdef __USE_MMF_TRANSFERBUFFERS__
64 TRAPD(err, buffer = CreateTransferBufferL(bufferSize, static_cast<CMMFTransferBuffer*>(aBuffer)));
66 TRAPD(err,buffer = CMMFDataBuffer::NewL(bufferSize));
74 {//there was a problem creating buffer eg OOM so use same buffer
84 * DoCleanupRHandleBase
86 * This method will initially Close the handle and then delete it.
89 #ifdef __USE_MMF_TRANSFERBUFFERS__
90 inline static void DoCleanupRHandleBase(TAny* aRHandleBase)
93 RHandleBase* rHandleBase = STATIC_CAST(RHandleBase*, aRHandleBase);
94 TRAPD(error, rHandleBase->Close());
98 CMMFTransferBuffer* CMMFSwCodecDataPath::CreateTransferBufferL(TUint aBufferSize, CMMFTransferBuffer* aOldBuffer)
100 CMMFTransferBuffer* buffer = NULL;
102 RTransferBuffer* transBuffer = new (ELeave) RTransferBuffer;
104 TCleanupItem bufferCleanupItem(DoCleanupRHandleBase, transBuffer); //closes and deletes.
105 CleanupStack::PushL(bufferCleanupItem);
107 RTransferWindow* transWindow = new (ELeave) RTransferWindow;
109 TCleanupItem windowCleanupItem(DoCleanupRHandleBase, transWindow); //closes and deletes.
110 CleanupStack::PushL(windowCleanupItem);
112 User::LeaveIfError(transBuffer->Create(aBufferSize));
113 User::LeaveIfError(transWindow->Create(aBufferSize));
114 User::LeaveIfError(transWindow->MapInBuffer(*transBuffer));
116 buffer = CMMFTransferBuffer::NewL(*transWindow);
118 delete aOldBuffer; //closes RTransferWindow
119 delete iTransferWindow;
123 iTransferBuffer->Close();
125 delete iTransferBuffer;
127 iTransferBuffer = transBuffer;
128 iTransferWindow = transWindow;
130 CleanupStack::Pop(transWindow);
131 CleanupStack::Pop(transBuffer);
138 #ifdef __USE_MMF_PTRBUFFERS__
139 CMMFPtrBuffer* CMMFSwCodecDataPath::CreatePtrBufferL(TUint aBufferSize)
141 CMMFPtrBuffer* buffer = NULL;
142 if (iPtrBufferMemoryBlock)
144 delete iPtrBufferMemoryBlock;//incase already exisits
145 iPtrBufferMemoryBlock = NULL;
147 iPtrBufferMemoryBlock = HBufC8::NewL(aBufferSize);
148 TPtr8 ptrMemoryBlock(iPtrBufferMemoryBlock->Des());
149 buffer = CMMFPtrBuffer::NewL(ptrMemoryBlock);
152 #endif // __USE_MMF_PTRBUFFERS__