os/mm/devsound/devsoundrefplugin/src/swcodecwrapper/mmfSwCodecDataPath.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.
     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".
     7 //
     8 // Initial Contributors:
     9 // Nokia Corporation - initial contribution.
    10 //
    11 // Contributors:
    12 //
    13 // Description:
    14 // source\server\mmfswcodecdatapath.cpp
    15 // 
    16 //
    17 
    18 #include "mmfSwCodecDataPath.h"
    19 
    20 
    21 CMMFSwCodecDataPath::~CMMFSwCodecDataPath()
    22 	{
    23 
    24 	}
    25 	
    26 /**
    27 Retrieves a custom interface to the device.
    28 Usually the derived class should
    29 return the implementation for this.
    30 
    31 @param	aInterface
    32 		Interface UID, defined with the custom interface.
    33 		
    34 @return NULL 
    35 
    36 */
    37 TAny* CMMFSwCodecDataPath::CustomInterface(TUid /*aInterface*/)
    38 	{
    39 	return NULL;
    40 	}
    41 	
    42 	
    43 
    44 /*
    45  * CycleAudioBufferL
    46  *
    47  * Sets up a usable buffer for passing to MMF
    48  *	
    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 
    52  * address being used.
    53  * 
    54  * Only cycles if there is enough memory
    55  *
    56  */
    57 #ifdef __CYCLE_MMF_DATABUFFERS__
    58 CMMFDataBuffer* CMMFSwCodecDataPath::CycleAudioBuffer(CMMFDataBuffer* aBuffer)
    59 	{
    60 	CMMFDataBuffer* buffer = NULL;
    61 	TUint bufferSize = aBuffer->Data().MaxLength();
    62 
    63 #ifdef __USE_MMF_TRANSFERBUFFERS__
    64 	TRAPD(err, buffer = CreateTransferBufferL(bufferSize, static_cast<CMMFTransferBuffer*>(aBuffer)));
    65 #else
    66 	TRAPD(err,buffer = CMMFDataBuffer::NewL(bufferSize));
    67 
    68 	if (err == KErrNone)
    69 		{
    70 		delete aBuffer;
    71 		}
    72 #endif
    73 	if (err != KErrNone)
    74 		{//there was a problem creating buffer eg OOM so use same buffer
    75 		buffer = aBuffer;
    76 		}
    77 
    78 	return buffer;
    79 
    80 	}
    81 #endif
    82 
    83 /*
    84  * DoCleanupRHandleBase
    85  *
    86  * This method will initially Close the handle and then delete it.
    87  *
    88  */
    89 #ifdef __USE_MMF_TRANSFERBUFFERS__
    90 inline static void DoCleanupRHandleBase(TAny* aRHandleBase)
    91 	{
    92 	ASSERT(aRHandleBase);
    93 	RHandleBase* rHandleBase = STATIC_CAST(RHandleBase*, aRHandleBase);
    94 	TRAPD(error, rHandleBase->Close());
    95 	delete aRHandleBase;
    96 	}
    97 
    98 CMMFTransferBuffer* CMMFSwCodecDataPath::CreateTransferBufferL(TUint aBufferSize, CMMFTransferBuffer* aOldBuffer)
    99 	{
   100 	CMMFTransferBuffer* buffer = NULL;
   101 
   102 	RTransferBuffer* transBuffer = new  (ELeave) RTransferBuffer;
   103 	
   104 	TCleanupItem bufferCleanupItem(DoCleanupRHandleBase, transBuffer); //closes and deletes.
   105 	CleanupStack::PushL(bufferCleanupItem);
   106 
   107 	RTransferWindow* transWindow = new (ELeave) RTransferWindow;
   108 	
   109 	TCleanupItem windowCleanupItem(DoCleanupRHandleBase, transWindow); //closes and deletes.
   110 	CleanupStack::PushL(windowCleanupItem);
   111 
   112 	User::LeaveIfError(transBuffer->Create(aBufferSize));
   113 	User::LeaveIfError(transWindow->Create(aBufferSize));
   114 	User::LeaveIfError(transWindow->MapInBuffer(*transBuffer));
   115 
   116 	buffer = CMMFTransferBuffer::NewL(*transWindow);
   117 
   118 	delete aOldBuffer; //closes RTransferWindow
   119 	delete iTransferWindow;
   120 
   121 	if(iTransferBuffer)
   122 		{
   123 		iTransferBuffer->Close();
   124 		}
   125 	delete iTransferBuffer;
   126 
   127 	iTransferBuffer = transBuffer;
   128 	iTransferWindow = transWindow;
   129 
   130 	CleanupStack::Pop(transWindow); 
   131 	CleanupStack::Pop(transBuffer); 
   132 
   133 	return buffer;
   134 	}
   135 #endif
   136 
   137 
   138 #ifdef __USE_MMF_PTRBUFFERS__
   139 CMMFPtrBuffer* CMMFSwCodecDataPath::CreatePtrBufferL(TUint aBufferSize)
   140 	{
   141 	CMMFPtrBuffer* buffer = NULL;
   142 	if (iPtrBufferMemoryBlock)
   143 		{
   144 		delete iPtrBufferMemoryBlock;//incase already exisits
   145 		iPtrBufferMemoryBlock = NULL;
   146 		}
   147 	iPtrBufferMemoryBlock = HBufC8::NewL(aBufferSize);
   148 	TPtr8 ptrMemoryBlock(iPtrBufferMemoryBlock->Des());
   149 	buffer = CMMFPtrBuffer::NewL(ptrMemoryBlock);
   150 	return buffer;
   151 	}
   152 #endif  // __USE_MMF_PTRBUFFERS__
   153 
   154 
   155