tsrc/xmltestharness/xmlclient/src/nontunneledhandler.cpp
changeset 0 0e4a32b9112d
equal deleted inserted replaced
-1:000000000000 0:0e4a32b9112d
       
     1 /*
       
     2 * Copyright (c) 2008 Nokia Corporation and/or its subsidiary(-ies).
       
     3 * All rights reserved.
       
     4 * This component and the accompanying materials are made available
       
     5 * under the terms of "Eclipse Public License v1.0"
       
     6 * which accompanies this distribution, and is available
       
     7 * at the URL "http://www.eclipse.org/legal/epl-v10.html".
       
     8 *
       
     9 * Initial Contributors:
       
    10 * Nokia Corporation - initial contribution.
       
    11 *
       
    12 * Contributors:
       
    13 *
       
    14 * Description:
       
    15 *
       
    16 */
       
    17 
       
    18 
       
    19 #include "nontunneledhandler.h"
       
    20 
       
    21 CNonTunneledHandler::CNonTunneledHandler()
       
    22 	{
       
    23 	}
       
    24 
       
    25 CNonTunneledHandler::~CNonTunneledHandler()
       
    26 	{
       
    27 	}
       
    28 
       
    29 void CNonTunneledHandler::AddLinkL(OMX_COMPONENTTYPE* aSourceComp,
       
    30                                    TInt aSourcePort,
       
    31                                    OMX_COMPONENTTYPE* aSinkComp,
       
    32                                    TInt aSinkPort,
       
    33                                    OMX_BUFFERSUPPLIERTYPE aSupplier,
       
    34                                    TInt aNumBufs, TInt aBufSize)
       
    35 	{
       
    36 	CComponentInfo* compInfo = NULL;
       
    37 	TInt pos = iComponents.Find(*aSourceComp, CComponentInfo::CompareComp);
       
    38 	if (pos >= 0)
       
    39 		{
       
    40 		compInfo = iComponents[pos];
       
    41 		}
       
    42 	else
       
    43 		{
       
    44 		compInfo = new (ELeave) CComponentInfo(aSourceComp);
       
    45 		CleanupStack::PushL(compInfo);
       
    46 		iComponents.AppendL(compInfo);
       
    47 		CleanupStack::Pop(compInfo);
       
    48 		}
       
    49 
       
    50 	CPortInfo* sourcePortInfo = compInfo->AddPortL(aSourcePort, ETrue, aNumBufs, aBufSize, aSupplier);
       
    51 
       
    52 	pos = iComponents.Find(*aSinkComp, CComponentInfo::CompareComp);
       
    53 	if (pos >= 0)
       
    54 		{
       
    55 		compInfo = iComponents[pos];
       
    56 		}
       
    57 	else
       
    58 		{
       
    59 		compInfo = new (ELeave) CComponentInfo(aSinkComp);
       
    60 		CleanupStack::PushL(compInfo);
       
    61 		iComponents.AppendL(compInfo);
       
    62 		CleanupStack::Pop(compInfo);
       
    63 		}
       
    64 
       
    65 	CPortInfo* sinkPortInfo = compInfo->AddPortL(aSinkPort, EFalse, aNumBufs, aBufSize, aSupplier);
       
    66 
       
    67 	sourcePortInfo->SetPeer(sinkPortInfo);
       
    68 	sinkPortInfo->SetPeer(sourcePortInfo);
       
    69 	}
       
    70 
       
    71 void CNonTunneledHandler::AllocateBuffersL(OMX_COMPONENTTYPE* aComp)
       
    72 	{
       
    73 	TInt pos = iComponents.Find(*aComp, CComponentInfo::CompareComp);
       
    74 	if (pos >= 0)
       
    75 		{
       
    76 		iComponents[pos]->AllocateBuffersL();
       
    77 		}
       
    78 	}
       
    79 
       
    80 void CNonTunneledHandler::FillBuffers(OMX_COMPONENTTYPE* aComp)
       
    81 	{
       
    82 	TInt pos = iComponents.Find(*aComp, CComponentInfo::CompareComp);
       
    83 	if (pos >= 0)
       
    84 		{
       
    85 		iComponents[pos]->FillBuffers();
       
    86 		}	
       
    87 	}
       
    88 
       
    89 void CNonTunneledHandler::BufferDone(OMX_COMPONENTTYPE* aComp, OMX_BUFFERHEADERTYPE* aBufHdr, TBool aSource)
       
    90 	{
       
    91 	TInt pos = iComponents.Find(*aComp, CComponentInfo::CompareComp);
       
    92 	if (pos >= 0)
       
    93 		{
       
    94 		iComponents[pos]->BufferDone(aBufHdr, aSource);
       
    95 		}
       
    96 	}
       
    97 
       
    98 void CNonTunneledHandler::HoldBuffers(OMX_COMPONENTTYPE* aComp)
       
    99 	{
       
   100 	TInt pos = iComponents.Find(*aComp, CComponentInfo::CompareComp);
       
   101 	if (pos >= 0)
       
   102 		{
       
   103 		iComponents[pos]->HoldBuffers();
       
   104 		}	
       
   105 	}
       
   106 
       
   107 void CNonTunneledHandler::FreeBuffers(OMX_COMPONENTTYPE* aComp)
       
   108 	{
       
   109 	TInt pos = iComponents.Find(*aComp, CComponentInfo::CompareComp);
       
   110 	if (pos >= 0)
       
   111 		{
       
   112 		iComponents[pos]->FreeBuffers();
       
   113 		}	
       
   114 	}
       
   115 
       
   116 CNonTunneledHandler::CComponentInfo::CComponentInfo(OMX_COMPONENTTYPE* aComp) :
       
   117  iComp(aComp)
       
   118 	{
       
   119 	}
       
   120 
       
   121 CNonTunneledHandler::CComponentInfo::~CComponentInfo()
       
   122 	{
       
   123 	iPorts.ResetAndDestroy();
       
   124 	}
       
   125 
       
   126 CNonTunneledHandler::CPortInfo* CNonTunneledHandler::CComponentInfo::AddPortL(TInt aPortNum, TBool aSource, TInt aNumBufs, TInt aBufSize, OMX_BUFFERSUPPLIERTYPE aSupplier)
       
   127 	{
       
   128 	__ASSERT_ALWAYS(iPorts.Find(aPortNum, CPortInfo::ComparePortNum) == KErrNotFound, User::Invariant());
       
   129 
       
   130 	CPortInfo* portInfo = new (ELeave) CPortInfo(iComp, aPortNum, aSource, aNumBufs, aBufSize, aSupplier);
       
   131 	CleanupStack::PushL(portInfo);
       
   132 	iPorts.AppendL(portInfo);
       
   133 	CleanupStack::Pop(portInfo);
       
   134 
       
   135 	return portInfo;
       
   136 	}
       
   137 
       
   138 void CNonTunneledHandler::CComponentInfo::AllocateBuffersL()
       
   139 	{
       
   140 	TInt numPorts = iPorts.Count();
       
   141 	
       
   142 	for (TInt port = 0; port < numPorts; ++port)
       
   143 		{
       
   144 		iPorts[port]->AllocateBuffersL();
       
   145 		}
       
   146 	}
       
   147 
       
   148 void CNonTunneledHandler::CComponentInfo::FillBuffers()
       
   149 	{
       
   150 	TInt numPorts = iPorts.Count();
       
   151 	
       
   152 	for (TInt port = 0; port < numPorts; ++port)
       
   153 		{
       
   154 		iPorts[port]->FillBuffers();
       
   155 		}
       
   156 	}
       
   157 
       
   158 void CNonTunneledHandler::CComponentInfo::BufferDone(OMX_BUFFERHEADERTYPE* aBufHdr, TBool aSource)
       
   159 	{
       
   160 	TInt pos = KErrNotFound;
       
   161 
       
   162 	if (aSource)
       
   163 		{
       
   164 		pos = iPorts.Find(static_cast<TInt>(aBufHdr->nOutputPortIndex), CPortInfo::ComparePortNum);
       
   165 		}
       
   166 	else
       
   167 		{
       
   168 		pos = iPorts.Find(static_cast<TInt>(aBufHdr->nInputPortIndex), CPortInfo::ComparePortNum);
       
   169 		}
       
   170 
       
   171 	__ASSERT_ALWAYS(pos != KErrNotFound, User::Invariant());
       
   172 
       
   173 	iPorts[pos]->BufferDone(aBufHdr);
       
   174 	}
       
   175 
       
   176 void CNonTunneledHandler::CComponentInfo::HoldBuffers()
       
   177 	{
       
   178 	for (TInt port = 0; port < iPorts.Count(); ++port)
       
   179 		{
       
   180 		iPorts[port]->HoldBuffers();
       
   181 		}
       
   182 	}
       
   183 
       
   184 void CNonTunneledHandler::CComponentInfo::FreeBuffers()
       
   185 	{
       
   186 	for (TInt port = 0; port < iPorts.Count(); ++port)
       
   187 		{
       
   188 		iPorts[port]->FreeBuffers();
       
   189 		}
       
   190 	}
       
   191 
       
   192 TBool CNonTunneledHandler::CComponentInfo::CompareComp(const OMX_COMPONENTTYPE* aComp, const CComponentInfo& aComponentInfo)
       
   193 	{
       
   194 	return (aComp == aComponentInfo.iComp);
       
   195 	}
       
   196 
       
   197 CNonTunneledHandler::CPortInfo::CPortInfo(OMX_COMPONENTTYPE* aComp, TInt aPortNum, TBool aSource, TInt aNumBufs, TInt aBufSize, OMX_BUFFERSUPPLIERTYPE aSupplier) :
       
   198  iComp(aComp),
       
   199  iPortNum(aPortNum),
       
   200  iSource(aSource),
       
   201  iNumBufs(aNumBufs),
       
   202  iBufSize(aBufSize),
       
   203  iSupplier(aSupplier),
       
   204  iEosSignalledtoInput(FALSE)
       
   205 	{
       
   206 	}
       
   207 
       
   208 CNonTunneledHandler::CPortInfo::~CPortInfo()
       
   209 	{
       
   210 	DeleteAllBuffers();
       
   211 	}
       
   212 
       
   213 void CNonTunneledHandler::CPortInfo::SetPeer(CPortInfo* aPeer)
       
   214 	{
       
   215 	iPeer = aPeer;
       
   216 	}
       
   217 
       
   218 void CNonTunneledHandler::CPortInfo::AllocateBuffersL()
       
   219 	{
       
   220 	OMX_BUFFERHEADERTYPE* bufHdr = NULL;
       
   221 
       
   222 	if (iSource)
       
   223 		{
       
   224 		if (iSupplier == OMX_BufferSupplyUnspecified)
       
   225 			{
       
   226 			OMX_U8* newBuffer = NULL;
       
   227 
       
   228 			for (TInt buf = 0; buf < iNumBufs; ++buf)
       
   229 				{
       
   230 				newBuffer = new (ELeave) OMX_U8[iBufSize];
       
   231 				CleanupStack::PushL(newBuffer);
       
   232 				iBuffers.AppendL(newBuffer);
       
   233 				CleanupStack::Pop(newBuffer);
       
   234 				iComp->UseBuffer(iComp, &bufHdr, iPortNum, NULL, iBufSize, newBuffer);
       
   235 				iBufferHeaders.AppendL(bufHdr);
       
   236 				SendAllocatedBufferToPeerL(newBuffer);
       
   237 				}
       
   238 			}
       
   239 		else if (iSupplier == OMX_BufferSupplyOutput)
       
   240 			{
       
   241 			for (TInt buf = 0; buf < iNumBufs; ++buf)
       
   242 				{			
       
   243 				iComp->AllocateBuffer(iComp, &bufHdr, iPortNum, NULL, iBufSize);
       
   244 				iBufferHeaders.AppendL(bufHdr);
       
   245 				SendAllocatedBufferToPeerL(bufHdr->pBuffer);
       
   246 				}
       
   247 			}
       
   248 		else
       
   249 			{
       
   250 			TInt bufCount = iBuffers.Count();
       
   251 
       
   252 			for (TInt buf = 0; buf < bufCount; ++buf)
       
   253 				{
       
   254 				iComp->UseBuffer(iComp, &bufHdr, iPortNum, NULL, iBufSize, iBuffers[buf]);
       
   255 				iBufferHeaders.AppendL(bufHdr);
       
   256 				}
       
   257 
       
   258 			if (bufCount < iNumBufs)
       
   259 				{
       
   260 				iWaitingForBuffers = ETrue;
       
   261 				}
       
   262 			}
       
   263 		}
       
   264 	else
       
   265 		{
       
   266 		if (iSupplier == OMX_BufferSupplyInput)
       
   267 			{
       
   268 			for (TInt buf = 0; buf < iNumBufs; ++buf)
       
   269 				{
       
   270 				iComp->AllocateBuffer(iComp, &bufHdr, iPortNum, NULL, iBufSize);
       
   271 				iBufferHeaders.AppendL(bufHdr);
       
   272 				SendAllocatedBufferToPeerL(bufHdr->pBuffer);
       
   273 				}
       
   274 			}
       
   275 		else
       
   276 			{
       
   277 			TInt bufCount = iBuffers.Count();
       
   278 
       
   279 			for (TInt buf = 0; buf < bufCount; ++buf)
       
   280 				{
       
   281 				iComp->UseBuffer(iComp, &bufHdr, iPortNum, NULL, iBufSize, iBuffers[buf]);
       
   282 				iBufferHeaders.AppendL(bufHdr);
       
   283 				}
       
   284 
       
   285 			if (bufCount < iNumBufs)
       
   286 				{
       
   287 				iWaitingForBuffers = ETrue;
       
   288 				}
       
   289 			}
       
   290 		}
       
   291 	}
       
   292 
       
   293 void CNonTunneledHandler::CPortInfo::SendAllocatedBufferToPeerL(OMX_U8* aBuffer)
       
   294 	{
       
   295 	__ASSERT_ALWAYS(iPeer, User::Invariant());
       
   296 
       
   297 	iPeer->ReceiveAllocatedBufferFromPeerL(aBuffer);
       
   298 	}
       
   299 
       
   300 void CNonTunneledHandler::CPortInfo::ReceiveAllocatedBufferFromPeerL(OMX_U8* aBuffer)
       
   301 	{
       
   302 	if (iWaitingForBuffers)
       
   303 		{
       
   304 		OMX_BUFFERHEADERTYPE* bufHdr = NULL;
       
   305 
       
   306 		iComp->UseBuffer(iComp, &bufHdr, iPortNum, NULL, iBufSize, aBuffer);
       
   307 		iBufferHeaders.AppendL(bufHdr);
       
   308 		
       
   309 		if (iBufferHeaders.Count() == iNumBufs)
       
   310 			{
       
   311 			iWaitingForBuffers = EFalse;
       
   312 			}
       
   313 		}
       
   314 	else
       
   315 		{
       
   316 		iBuffers.AppendL(aBuffer);
       
   317 		}
       
   318 	}
       
   319 
       
   320 void CNonTunneledHandler::CPortInfo::FillBuffers()
       
   321 	{
       
   322 	iHoldingBuffers = EFalse;
       
   323 	if (iSource)
       
   324 		{
       
   325 		for (TInt buf = 0; buf < iNumBufs; ++buf)
       
   326 			{
       
   327 			iComp->FillThisBuffer(iComp, iBufferHeaders[buf]);
       
   328 			}
       
   329 		}
       
   330 	}
       
   331 
       
   332 void CNonTunneledHandler::CPortInfo::BufferDone(OMX_BUFFERHEADERTYPE* aBufHdr)
       
   333 	{
       
   334 	for (TInt buf = 0; buf < iNumBufs; ++buf)
       
   335 		{
       
   336 		if (iBufferHeaders[buf] == aBufHdr)
       
   337 			{
       
   338 			iPeer->ReceiveBufferFromPeer(buf, aBufHdr);
       
   339 			}
       
   340 		}
       
   341 	}
       
   342 
       
   343 void CNonTunneledHandler::CPortInfo::SendBufferToPeer(TInt aBufHdrOffset, OMX_BUFFERHEADERTYPE* aPeerBufHdr)
       
   344 	{
       
   345 	__ASSERT_ALWAYS(iPeer, User::Invariant());
       
   346 
       
   347 	iPeer->ReceiveBufferFromPeer(aBufHdrOffset, aPeerBufHdr);
       
   348 	}
       
   349 
       
   350 void CNonTunneledHandler::CPortInfo::ReceiveBufferFromPeer(TInt aBufHdrOffset, OMX_BUFFERHEADERTYPE* aPeerBufHdr)
       
   351 	{
       
   352 	__ASSERT_ALWAYS(aBufHdrOffset < iNumBufs, User::Invariant());
       
   353 
       
   354 	if (!iHoldingBuffers)
       
   355 		{
       
   356 		iBufferHeaders[aBufHdrOffset]->nOffset = aPeerBufHdr->nOffset;
       
   357 		iBufferHeaders[aBufHdrOffset]->nFilledLen = aPeerBufHdr->nFilledLen;
       
   358 
       
   359 		if (iSource)
       
   360 			{
       
   361 			iComp->FillThisBuffer(iComp, iBufferHeaders[aBufHdrOffset]);
       
   362 			}
       
   363 		else
       
   364 			{
       
   365 			iBufferHeaders[aBufHdrOffset]->hMarkTargetComponent = aPeerBufHdr->hMarkTargetComponent;
       
   366 			iBufferHeaders[aBufHdrOffset]->pMarkData = aPeerBufHdr->pMarkData;
       
   367 			iBufferHeaders[aBufHdrOffset]->nTimeStamp = aPeerBufHdr->nTimeStamp;
       
   368 			iBufferHeaders[aBufHdrOffset]->nFlags = aPeerBufHdr->nFlags;
       
   369 
       
   370 			if(aPeerBufHdr->nFlags & OMX_BUFFERFLAG_EOS)
       
   371                 {
       
   372                 // TODO Logic for EOS
       
   373                 if(iEosSignalledtoInput == FALSE)
       
   374                     {
       
   375                     iComp->EmptyThisBuffer(iComp, iBufferHeaders[aBufHdrOffset]);
       
   376                     iEosSignalledtoInput = TRUE;
       
   377                     }
       
   378                 return;
       
   379                 }
       
   380 			iComp->EmptyThisBuffer(iComp, iBufferHeaders[aBufHdrOffset]);
       
   381 			}
       
   382 		}
       
   383 	}
       
   384 
       
   385 void CNonTunneledHandler::CPortInfo::HoldBuffers()
       
   386 	{
       
   387 	iHoldingBuffers = ETrue;
       
   388 	}
       
   389 
       
   390 void CNonTunneledHandler::CPortInfo::FreeBuffers()
       
   391 	{
       
   392 	for (TInt buf = 0; buf < iNumBufs; ++buf)
       
   393 		{
       
   394 		iComp->FreeBuffer(iComp, iPortNum, iBufferHeaders[buf]);
       
   395 		}
       
   396 
       
   397 	DeleteAllBuffers();
       
   398 	}
       
   399 
       
   400 void CNonTunneledHandler::CPortInfo::DeleteAllBuffers()
       
   401 	{
       
   402 	iBufferHeaders.Reset();
       
   403 
       
   404 	if (iSource && iSupplier == OMX_BufferSupplyUnspecified)
       
   405 		{
       
   406 		iBuffers.ResetAndDestroy();
       
   407 		}
       
   408 	else
       
   409 		{
       
   410 		iBuffers.Reset();
       
   411 		}
       
   412 	}
       
   413 
       
   414 TBool CNonTunneledHandler::CPortInfo::ComparePortNum(const TInt* aPortNum, const CPortInfo& aPortInfo)
       
   415 	{
       
   416 	return (*aPortNum == aPortInfo.iPortNum);
       
   417 	}