void AbstractStream::dataLoop(AbstractStream *stream) { switch (stream->mediaType()) { case AVMEDIA_TYPE_VIDEO: case AVMEDIA_TYPE_AUDIO: while (stream->m_runDataLoop) { stream->m_dataMutex.lock(); if (stream->m_frames.isEmpty()) stream->m_dataQueueNotEmpty.wait(&stream->m_dataMutex, THREAD_WAIT_LIMIT); if (!stream->m_frames.isEmpty()) { FramePtr frame = stream->m_frames.dequeue(); stream->processData(frame.data()); if (stream->m_frames.size() < stream->m_maxData) stream->m_dataQueueNotFull.wakeAll(); } stream->m_dataMutex.unlock(); } break; case AVMEDIA_TYPE_SUBTITLE: while (stream->m_runDataLoop) { stream->m_dataMutex.lock(); if (stream->m_subtitles.isEmpty()) stream->m_dataQueueNotEmpty.wait(&stream->m_dataMutex, THREAD_WAIT_LIMIT); if (!stream->m_subtitles.isEmpty()) { SubtitlePtr subtitle = stream->m_subtitles.dequeue(); stream->processData(subtitle.data()); if (stream->m_subtitles.size() < stream->m_maxData) stream->m_dataQueueNotFull.wakeAll(); } stream->m_dataMutex.unlock(); } break; default: break; } }
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); } } }