etternagame / etterna

Advanced cross-platform rhythm game focused on keyboard play
https://etternaonline.com/
MIT License
497 stars 135 forks source link

Video set as background causes significant fps/stutter issues in gameplay #1173

Open poco0317 opened 2 years ago

poco0317 commented 2 years ago

old issue i made a lot worse in .71.0 so it should be fixed

example file is cant tell by deamerai in pack the void also speed of hell in some other packs

Sarrg commented 1 year ago

I took a look at this and I noticed that several threads were always exiting when the lag occurred (see attachment) , which is when the end of the video file is reach and m_bWantRewind in MovieTexture_Generic.cpp is set. When this flag is set, MovieDecoder_FFMpeg::Rewind() will be called which in turn calls MovieDecoder_FFMpeg::OpenCodec() and in Line 510 it destroys the avcodec thread. I am not sure however why this causes multiple threads to be exited.

The fix for this would be to just reset the internal fields instead of calling OpenCodec:

m_iEOF = 0;
m_fTimestamp = 0;
m_fLastFrameDelay = 0;
m_iFrameNumber = -1; /* decode one frame and you're on the 0th */
m_fTimestampOffset = 0;
m_fLastFrame = 0;

directly in MovieDecoder_FFMpeg::Rewind. I test this out and the video still loops. This almost removes the stutters, however avcodec::av_seek_frame is called in Rewind which still causes up to 8-12ms Lag outputs. A proper fix would either decode frames ahead of time or keep the first few frames in memory such that a rewind can be performed without blocking rendering.

ThreadLifetime