Ejemplo n.º 1
0
void RenderThread::UpdateLayout()
{
	QMutexLocker locker(&m_MutexLayout);

	// Find frames without layout info and delete them
	QMutableListIterator<FramePtr> i(m_RenderFrames);
	while (i.hasNext()) 
	{
		FramePtr renderFrame = i.next();
		if (!renderFrame)
		{
			i.remove();
			continue;
		}

		int j = m_ViewIDs.indexOf(renderFrame->Info(VIEW_ID).toUInt());
		if (j == -1)
		{
			m_Renderer->Deallocate(renderFrame);
			i.remove();
		}else
		{
			QRect srcRect = m_SrcRects.at(j);
			float scaleX = renderFrame->Info(RENDER_SRC_SCALE_X).toFloat();
			float scaleY = renderFrame->Info(RENDER_SRC_SCALE_Y).toFloat();
			srcRect.setLeft((int)(srcRect.left()*scaleX));
			srcRect.setRight((int)(srcRect.right()*scaleX));
			srcRect.setTop((int)(srcRect.top()*scaleY));
			srcRect.setBottom((int)(srcRect.bottom()*scaleY));

			renderFrame->SetInfo(SRC_RECT, srcRect);
			renderFrame->SetInfo(DST_RECT, m_DstRects.at(j));
		}
	}
}
Ejemplo n.º 2
0
void RenderThread::RenderFrames(FrameListPtr sourceFrames, YUV_PLANE plane)
{
	FrameImpl tempFrame;

	for (int i = 0; i < sourceFrames->size(); i++) 
	{
		FramePtr sourceFrameOrig = sourceFrames->at(i);
		if (!sourceFrameOrig)
		{
			continue;
		}
		unsigned int viewID = sourceFrameOrig->Info(VIEW_ID).toUInt();

		Frame* sourceFrame = sourceFrameOrig.data();
		float scaleX = 1;
		float scaleY = 1;
		if (plane != PLANE_COLOR)
		{
			COLOR_FORMAT c = sourceFrameOrig->Format()->Color();
			if (c == I420 || c == I422 || c == I444)
			{
				sourceFrame = &tempFrame;

				FormatPtr format = sourceFrameOrig->Format();
				sourceFrame->Format()->SetColor(Y800);
				sourceFrame->Format()->SetWidth(format->PlaneWidth(plane));
				sourceFrame->Format()->SetHeight(format->PlaneHeight(plane));
				sourceFrame->Format()->SetStride(0, format->Stride(plane));
				sourceFrame->Format()->PlaneSize(0);


				sourceFrame->SetData(0, sourceFrameOrig->Data(plane));

				scaleX = ((float)format->PlaneWidth(plane))/format->Width();
				scaleY = ((float)format->PlaneHeight(plane))/format->Height();
			}
		}
		
		int pos = -1;
		for (int k = 0; k < m_RenderFrames.size(); k++) 
		{
			FramePtr _frame = m_RenderFrames.at(k);
			if (_frame && _frame->Info(VIEW_ID).toUInt() == viewID)
			{
				pos = k;
				break;
			}
		}

		if (pos == -1)
		{
			pos = m_RenderFrames.size();
			m_RenderFrames.append(FramePtr());
		}

		FramePtr& renderFrame = m_RenderFrames[pos];
		// Deallocate if resolution changed
		if (renderFrame && (sourceFrame->Format()->Width() != 
			renderFrame->Format()->Width() || 
			sourceFrame->Format()->Height() != 
			renderFrame->Format()->Height()))
		{
			m_Renderer->Deallocate(renderFrame);
			renderFrame.clear();
		}

		// Allocate if needed
		if (!renderFrame)
		{
			m_Renderer->Allocate(renderFrame, sourceFrame->Format());
		}
		
		renderFrame->SetInfo(VIEW_ID, viewID);
		renderFrame->SetInfo(RENDER_SRC_SCALE_X, scaleX);
		renderFrame->SetInfo(RENDER_SRC_SCALE_Y, scaleY);

		// Render frame
		if (m_Renderer->GetFrame(renderFrame) == OK)
		{
			if (sourceFrame->Format() == renderFrame->Format())
			{
				for (int i=0; i<4; i++)
				{
					size_t len = renderFrame->Format()->PlaneSize(i);
					if (len > 0)
					{
						memcpy(renderFrame->Data(i), sourceFrame->Data(i), len);
					}
				}

			}else
			{
				ColorConversion(*sourceFrame, *renderFrame);
			}

			m_Renderer->ReleaseFrame(renderFrame);
		}
	}
}