Count Pacer delay in frame stats

This commit is contained in:
Cameron Gutman 2018-12-25 12:09:45 -08:00
parent 35aac18b4e
commit c054536fab
3 changed files with 12 additions and 2 deletions

View File

@ -16,6 +16,7 @@ typedef struct _VIDEO_STATS {
uint32_t pacerDroppedFrames; uint32_t pacerDroppedFrames;
uint32_t totalReassemblyTime; uint32_t totalReassemblyTime;
uint32_t totalDecodeTime; uint32_t totalDecodeTime;
uint32_t totalPacerTime;
uint32_t totalRenderTime; uint32_t totalRenderTime;
float receivedFps; float receivedFps;
float decodedFps; float decodedFps;

View File

@ -87,7 +87,6 @@ void Pacer::vsyncCallback(int timeUntilNextVsyncMillis)
av_frame_free(&frame); av_frame_free(&frame);
} }
if (m_FrameQueue.isEmpty()) { if (m_FrameQueue.isEmpty()) {
SDL_AtomicUnlock(&m_FrameQueueLock); SDL_AtomicUnlock(&m_FrameQueueLock);
@ -112,8 +111,11 @@ RenderNextFrame:
AVFrame* frame = m_FrameQueue.dequeue(); AVFrame* frame = m_FrameQueue.dequeue();
SDL_AtomicUnlock(&m_FrameQueueLock); SDL_AtomicUnlock(&m_FrameQueueLock);
// Render it // Count time spent in Pacer's queues
Uint32 beforeRender = SDL_GetTicks(); Uint32 beforeRender = SDL_GetTicks();
m_VideoStats->totalPacerTime += beforeRender - frame->pts;
// Render it
m_VsyncRenderer->renderFrameAtVsync(frame); m_VsyncRenderer->renderFrameAtVsync(frame);
m_VideoStats->totalRenderTime += SDL_GetTicks() - beforeRender; m_VideoStats->totalRenderTime += SDL_GetTicks() - beforeRender;
m_VideoStats->renderedFrames++; m_VideoStats->renderedFrames++;

View File

@ -258,6 +258,7 @@ void FFmpegVideoDecoder::addVideoStats(VIDEO_STATS& src, VIDEO_STATS& dst)
dst.pacerDroppedFrames += src.pacerDroppedFrames; dst.pacerDroppedFrames += src.pacerDroppedFrames;
dst.totalReassemblyTime += src.totalReassemblyTime; dst.totalReassemblyTime += src.totalReassemblyTime;
dst.totalDecodeTime += src.totalDecodeTime; dst.totalDecodeTime += src.totalDecodeTime;
dst.totalPacerTime += src.totalPacerTime;
dst.totalRenderTime += src.totalRenderTime; dst.totalRenderTime += src.totalRenderTime;
Uint32 now = SDL_GetTicks(); Uint32 now = SDL_GetTicks();
@ -311,6 +312,9 @@ void FFmpegVideoDecoder::logVideoStats(VIDEO_STATS& stats, const char* title)
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"Average decode time: %.2f ms", "Average decode time: %.2f ms",
(float)stats.totalDecodeTime / stats.decodedFrames); (float)stats.totalDecodeTime / stats.decodedFrames);
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"Average frame pacing delay: %.2f ms",
(float)stats.totalPacerTime / stats.renderedFrames);
SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION, SDL_LogInfo(SDL_LOG_CATEGORY_APPLICATION,
"Average render time: %.2f ms", "Average render time: %.2f ms",
(float)stats.totalRenderTime / stats.renderedFrames); (float)stats.totalRenderTime / stats.renderedFrames);
@ -577,6 +581,9 @@ int FFmpegVideoDecoder::submitDecodeUnit(PDECODE_UNIT du)
// Reset failed decodes count if we reached this far // Reset failed decodes count if we reached this far
m_ConsecutiveFailedDecodes = 0; m_ConsecutiveFailedDecodes = 0;
// Capture a frame timestamp to measuring pacing delay
frame->pts = SDL_GetTicks();
// Queue the frame for rendering from the main thread // Queue the frame for rendering from the main thread
SDL_AtomicIncRef(&m_QueuedFrames); SDL_AtomicIncRef(&m_QueuedFrames);
queueFrame(frame); queueFrame(frame);