MCPcopy Create free account
hub / github.com/Aleksoid1978/VideoRenderer / ThreadProc

Method ThreadProc

Source/SubPic/SubPicQueueImpl.cpp:498–659  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

496// overrides
497
498DWORD CSubPicQueue::ThreadProc()
499{
500 bool bDisableAnim = m_bDisableAnim;
501 SetThreadName(DWORD(-1), "Subtitle Renderer Thread");
502 SetThreadPriority(m_hThread, bDisableAnim ? THREAD_PRIORITY_LOWEST : THREAD_PRIORITY_ABOVE_NORMAL);
503
504 bool bWaitForEvent = false;
505 for (; !m_bExitThread;) {
506 // When we have nothing to render, we just wait a bit
507 if (bWaitForEvent) {
508 bWaitForEvent = false;
509 m_runQueueEvent.Wait();
510 }
511
512 auto pSubPicProviderWithSharedLock = GetSubPicProviderWithSharedLock();
513 if (pSubPicProviderWithSharedLock && SUCCEEDED(pSubPicProviderWithSharedLock->Lock())) {
514 auto& pSubPicProvider = pSubPicProviderWithSharedLock->pSubPicProvider;
515 double fps = m_fps;
516 REFERENCE_TIME rtTimePerFrame = m_rtTimePerFrame;
517 m_bInvalidate = false;
518 CComPtr<ISubPic> pSubPic;
519
520 SUBTITLE_TYPE sType = pSubPicProvider->GetType();
521
522 REFERENCE_TIME rtStartRendering = GetCurrentRenderingTime();
523 POSITION pos = pSubPicProvider->GetStartPosition(rtStartRendering, fps);
524 if (!pos) {
525 bWaitForEvent = true;
526 }
527 for (; pos; pos = pSubPicProvider->GetNext(pos)) {
528 REFERENCE_TIME rtStart = pSubPicProvider->GetStart(pos, fps);
529 REFERENCE_TIME rtStop = pSubPicProvider->GetStop(pos, fps);
530
531 // We are already one minute ahead, this should be enough
532 if (rtStart >= m_rtNow + 60 * 10000000i64) {
533 bWaitForEvent = true;
534 break;
535 }
536
537 REFERENCE_TIME rtCurrent = std::max(rtStart, rtStartRendering);
538 if (rtCurrent > m_rtNow && rtTimePerFrame <= rtStop - rtStart) {
539 // Round current time to the next estimated video frame timing
540 REFERENCE_TIME rtCurrentRounded = (rtCurrent / rtTimePerFrame) * rtTimePerFrame;
541 if (rtCurrentRounded < rtCurrent) {
542 rtCurrent = rtCurrentRounded + rtTimePerFrame;
543 }
544 } else {
545 rtCurrent = m_rtNow;
546 }
547
548 // Check that we aren't late already...
549 if (rtCurrent < rtStop) {
550 bool bIsAnimated = pSubPicProvider->IsAnimated(pos) && !bDisableAnim;
551 bool bStopRendering = false;
552
553 while (rtCurrent < rtStop) {
554 SIZE maxTextureSize, virtualSize;
555 POINT virtualTopLeft;

Callers

nothing calls this directly

Calls 15

SetThreadNameFunction · 0.85
DLogFunction · 0.85
GetStartPositionMethod · 0.80
GetNextMethod · 0.80
IsAnimatedMethod · 0.80
GetTextureSizeMethod · 0.80
GetStaticMethod · 0.80
SetSegmentStartMethod · 0.80
SetSegmentStopMethod · 0.80
GetDirtyRectMethod · 0.80
AllocDynamicMethod · 0.80
SetVirtualTextureSizeMethod · 0.80

Tested by

no test coverage detected