From beac4b12932268ac0225bf21c46ec7f6c0ad0151 Mon Sep 17 00:00:00 2001 From: Oleksandr Voietsa Date: Tue, 16 Aug 2022 21:19:31 -0700 Subject: [PATCH] Free avPacket on EAGAIN decoder error Summary: According to the documentation the packet has to be freed after `av_read_frame()` call. ``` If pkt->buf is NULL, then the packet is valid until the next av_read_frame() or until avformat_close_input(). Otherwise the packet is valid indefinitely. In both cases the packet must be freed with av_packet_unref when it is no longer needed. ``` Differential Revision: D38747612 fbshipit-source-id: 28c2d195ee1be63531567a5a4e05f18ad7f6970f --- torchvision/csrc/io/decoder/decoder.cpp | 2 ++ 1 file changed, 2 insertions(+) diff --git a/torchvision/csrc/io/decoder/decoder.cpp b/torchvision/csrc/io/decoder/decoder.cpp index dad0c98e02d..f13e2c3ffcf 100644 --- a/torchvision/csrc/io/decoder/decoder.cpp +++ b/torchvision/csrc/io/decoder/decoder.cpp @@ -516,6 +516,8 @@ int Decoder::getFrame(size_t workingTimeInMs) { VLOG(4) << "Decoder is busy..."; std::this_thread::yield(); result = 0; // reset error, EAGAIN is not an error at all + // reset the packet to default settings + av_packet_unref(avPacket); continue; } else if (result == AVERROR_EOF) { flushStreams();