当前位置: 首页>>代码示例>>C++>>正文


C++ IEvent::ToEmpty方法代码示例

本文整理汇总了C++中IEvent::ToEmpty方法的典型用法代码示例。如果您正苦于以下问题:C++ IEvent::ToEmpty方法的具体用法?C++ IEvent::ToEmpty怎么用?C++ IEvent::ToEmpty使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IEvent的用法示例。


在下文中一共展示了IEvent::ToEmpty方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: WaitForGeneric

IEventSPtr OMXComponent::WaitForGeneric(const list<IEventSPtr> &lstEvents, unsigned int uTimeoutMs)
{
	IEventSPtr pRes;
	uint32_t u32Sec;
	uint32_t u32NanoSec;

	m_pClock->GetCurrent(&u32Sec, &u32NanoSec);

	add_milliseconds(&u32Sec, &u32NanoSec, uTimeoutMs);

	bool bMatch = false;
	bool bFailure = false;

	// go until we either fail or succeed
	while ((!bFailure) && (!bMatch))
	{
		// go through all things we _can_ match with ...
		for (list<IEventSPtr>::const_iterator lsi = lstEvents.begin(); lsi != lstEvents.end(); lsi++)
		{
			// determine what type of event this is
			IEvent *pEvent = lsi->get();
			OMXEventData *pOMX = pEvent->ToEvent();
			EmptyBufferDoneData *pEmpty = pEvent->ToEmpty();
			FillBufferDoneData *pFill = pEvent->ToFill();

			Lock();

			if (pEmpty != NULL)
			{
				for (list<EmptyBufferDoneData>::iterator li = m_lstEmpty.begin(); li != m_lstEmpty.end(); li++)
				{
					if (li->pBuffer == pEmpty->pBuffer)
					{
						bMatch = true;
						m_lstEmpty.erase(li);
						pRes = *lsi;
						break;
					}
				}
			}

			// if we are waiting for an OMXEvent
			else if (pOMX != NULL)
			{
				for (list<OMXEventData>::iterator li = m_lstEvents.begin(); li != m_lstEvents.end(); li++)
				{
					// if we found the match
					if ((li->eEvent == pOMX->eEvent) && (pOMX->nData1 == li->nData1) && (pOMX->nData2 == li->nData2))
					{
						bMatch = true;
						m_lstEvents.erase(li);	// remove this item from the list because the caller knows about it now
						pRes = *lsi;
						break;	// must break here to about segfault since we just called erase()
					}
				}
			}
			else if (pFill != NULL)
			{
				for (list<FillBufferDoneData>::iterator li = m_lstFill.begin(); li != m_lstFill.end(); li++)
				{
					if (li->pBuffer == pFill->pBuffer)
					{
						bMatch = true;
						m_lstFill.erase(li);
						pRes = *lsi;
						break;
					}
				}
			}
			// else this should never happen
			else
			{
				assert(false);
			}

			Unlock();

			// if we found a match, we're done
			if (bMatch)
			{
				break;
			}
		}	// end for

		// if we didn't get a match we need to wait for success or a timeout
		if (!bMatch)
		{
			Lock();

			// If we got an error or timed out, then we're done
			// (this implicitly unlocks the mutex during the waiting period, then relocks it upon returning!)
			if (!m_pLocker->WaitForEvent(u32Sec, u32NanoSec))
			{
				bFailure = true;
			}

			Unlock();
		}

	} // end while we haven't succeeded or failed
//.........这里部分代码省略.........
开发者ID:Charles32,项目名称:SyncVideoPi,代码行数:101,代码来源:OMXComponent.cpp

示例2: decode

int JPEG::decode(const char* data_in, unsigned long int length_in, 
	char **out, unsigned int *width, unsigned int *height)
{
	try {
		// start of image
		width_out = width;
		height_out = height;

		bool bDone = false;
		bool bFillCalled = false;
		int iBufIdx = 0;

		const char* data = data_in;
		unsigned int length = length_in;

		// feed source buffer into component
		while (!bDone)
		{
			// get buffer to fill
			OMX_BUFFERHEADERTYPE *pBufHeader = vpBufHeaders[iBufIdx];
			iBufIdx++;

			// wraparound if necessary
			if (iBufIdx >= iBufferCount)
			{
				iBufIdx = 0;
			}

			size_t stBytesRead = (length > pBufHeader->nAllocLen) ? pBufHeader->nAllocLen : length;
			memcpy(pBufHeader->pBuffer, data, stBytesRead);
			data += stBytesRead;
			length -= stBytesRead;

			pBufHeader->nFilledLen = stBytesRead;
			pBufHeader->nOffset = 0;
			pBufHeader->nFlags = 0;

			// if we are at EOF
			if (length <= 0)
			{
				pBufHeader->nFlags = OMX_BUFFERFLAG_EOS;	// notify that the stream is done
				bDone = true;
			}

			m_pCompDecode->EmptyThisBuffer(pBufHeader);
			bool bGotEmpty = false;

			// we need to get an empty ack after calling EmptyThisBuffer,
			//   the only thing that can stand in our way is getting a port settings changed event.
			// For large JPEGs, more than one port settings changed event may occur (I haven't figured out why, I just handle it)
			// We also expect a port settings changed event if we have no output buffer and can't proceed without one.
			while ((!bGotEmpty) || (m_pBufOutput == NULL))
			{
				// we could get either a "empty done" or a "port settings changed" at this point
				IEventSPtr ev = m_pCompDecode->WaitForEventOrEmpty(OMX_EventPortSettingsChanged, m_iOutPortDecode, 0, pBufHeader, TIMEOUT_MS);

				IEvent *pEv = ev.get();
				OMXEventData *pEvOMX = pEv->ToEvent();
				EmptyBufferDoneData *pEvEmpty = pEv->ToEmpty();

				// if it's a port settings changed event
				if (pEvOMX != NULL)
				{
					// if we don't yet have an output buffer, then create one now
					if (m_pBufOutput == 0)
					{
						OnDecoderOutputChanged();	// setup output buffer
					}
					// else we already have an output buffer, so handle the event differently
					else
					{
						OnDecoderOutputChangedAgain();
					}
				}
				// else if this is an empty event
				else if (pEvEmpty != NULL)
				{
					bGotEmpty = true;
				}
				// else this is unexpected
				else
				{
					throw runtime_error("Unexpected IEvent");
				}
			}

			assert(m_pBufOutput != 0);
			assert(m_pHeaderOutput != 0);

			if (!bFillCalled)
			{
				m_pCompResize->FillThisBuffer(m_pHeaderOutput);
				bFillCalled = true;	// don't want to call FillThisBuffer twice
			}
		} // end while !bDone

		// both of these should be true at this point, if they're not it's a bug in my code
		assert(m_pBufOutput != 0);
		assert(bFillCalled);

//.........这里部分代码省略.........
开发者ID:trsaunders,项目名称:PhotoBooth,代码行数:101,代码来源:JPEG.cpp


注:本文中的IEvent::ToEmpty方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。