mirror of
https://github.com/Kelsidavis/WoWee.git
synced 2026-04-10 23:03:52 +00:00
fix: video player decode loop could spin indefinitely on corrupt files
The while(true) loop retried av_read_frame after seeking to the start on error. A corrupt file where read fails but seek succeeds would loop forever, blocking the main thread. Bounded to 500 attempts with a warning log on exhaustion.
This commit is contained in:
parent
c8dde0985f
commit
161b7981f9
1 changed files with 7 additions and 1 deletions
|
|
@ -187,7 +187,11 @@ bool VideoPlayer::decodeNextFrame() {
|
|||
AVPacket* pkt = reinterpret_cast<AVPacket*>(packet);
|
||||
SwsContext* sws = reinterpret_cast<SwsContext*>(swsCtx);
|
||||
|
||||
while (true) {
|
||||
// Cap iterations to prevent infinite spinning on corrupt/truncated video
|
||||
// files where av_read_frame fails but av_seek_frame succeeds, looping
|
||||
// endlessly through the same corrupt region.
|
||||
constexpr int kMaxDecodeAttempts = 500;
|
||||
for (int attempt = 0; attempt < kMaxDecodeAttempts; ++attempt) {
|
||||
int ret = av_read_frame(fmt, pkt);
|
||||
if (ret < 0) {
|
||||
if (av_seek_frame(fmt, videoStreamIndex, 0, AVSEEK_FLAG_BACKWARD) >= 0) {
|
||||
|
|
@ -224,6 +228,8 @@ bool VideoPlayer::decodeNextFrame() {
|
|||
uploadFrame();
|
||||
return true;
|
||||
}
|
||||
LOG_WARNING("Video decode: exceeded ", kMaxDecodeAttempts, " attempts — possible corrupt file");
|
||||
return false;
|
||||
}
|
||||
|
||||
void VideoPlayer::uploadFrame() {
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue