From 228a72b723f93db9878064915186636e0844e397 Mon Sep 17 00:00:00 2001 From: Conn O'Griofa Date: Tue, 24 Jan 2023 01:51:27 +0000 Subject: [PATCH] Fix image leak of hardware parallel encoder on display reinit When a reinit caused by a capture size change occurs via the Windows hardware encoder, the stream will freeze with display_wp->use_count() stuck at 2. Fix by ensuring pending images are freed before reinit event is checked. --- src/video.cpp | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/src/video.cpp b/src/video.cpp index 8fddb8f4eca..a86055c61ef 100644 --- a/src/video.cpp +++ b/src/video.cpp @@ -1574,6 +1574,12 @@ void capture_async( platf::adjust_thread_priority(platf::thread_priority_e::high); while(!shutdown_event->peek() && images->running()) { + // Free images that weren't consumed by the encoder before it quit. + // This is critical to allow the display_t to be freed correctly. + while(images->peek()) { + images->pop(); + } + // Wait for the main capture event when the display is being reinitialized if(ref->reinit_event.peek()) { std::this_thread::sleep_for(100ms); @@ -1622,12 +1628,6 @@ void capture_async( std::move(hwdevice), ref->reinit_event, *ref->encoder_p, channel_data); - - // Free images that weren't consumed by the encoder before it quit. - // This is critical to allow the display_t to be freed correctly. - while(images->peek()) { - images->pop(); - } } }