From ab25cf214c188f6b8ecf3729c1deee8c9896ad1f Mon Sep 17 00:00:00 2001 From: John Preston Date: Thu, 8 Sep 2022 09:50:11 +0400 Subject: [PATCH] Fix FFmpeg frame generator ending. --- .../ffmpeg/ffmpeg_frame_generator.cpp | 28 +++++++++---------- 1 file changed, 14 insertions(+), 14 deletions(-) diff --git a/Telegram/SourceFiles/ffmpeg/ffmpeg_frame_generator.cpp b/Telegram/SourceFiles/ffmpeg/ffmpeg_frame_generator.cpp index c31a833ac..54c4cece8 100644 --- a/Telegram/SourceFiles/ffmpeg/ffmpeg_frame_generator.cpp +++ b/Telegram/SourceFiles/ffmpeg/ffmpeg_frame_generator.cpp @@ -343,22 +343,22 @@ void FrameGenerator::Impl::readNextFrame() { return; } } while (packet.fields().stream_index != _streamId); + if (finished) { - continue; + result = avcodec_send_packet(_codec.get(), nullptr); // Drain. + } else { + const auto native = &packet.fields(); + const auto guard = gsl::finally([ + &, + size = native->size, + data = native->data + ] { + native->size = size; + native->data = data; + packet = Packet(); + }); + result = avcodec_send_packet(_codec.get(), native); } - - const auto native = &packet.fields(); - const auto guard = gsl::finally([ - &, - size = native->size, - data = native->data - ] { - native->size = size; - native->data = data; - packet = Packet(); - }); - - result = avcodec_send_packet(_codec.get(), native); if (result < 0) { LOG(("Webm Error: Unable to avcodec_send_packet(), ") + wrapError(result));