Skip to content

Commit 7c0fb37

Browse files
committed
AMD Display Capture reinit fix
* Drain queued frames before termination
1 parent 7564f4f commit 7c0fb37

File tree

2 files changed

+20
-18
lines changed

2 files changed

+20
-18
lines changed

src/platform/windows/display_amd.cpp

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -27,25 +27,30 @@ namespace platf::dxgi {
2727
}
2828

2929
amd_capture_t::~amd_capture_t() {
30-
captureComp->Flush();
30+
AMF_RESULT result;
31+
32+
// Before terminating the Display Capture component, we need to drain the remaining frames
33+
result = captureComp->Drain();
34+
if (result == AMF_OK) {
35+
do {
36+
result = captureComp->QueryOutput((amf::AMFData**) &capturedSurface);
37+
Sleep(1);
38+
} while (result != AMF_EOF);
39+
}
3140
captureComp->Terminate();
41+
3242
context->Terminate();
33-
// capturedSurface = nullptr;
34-
// free(context);
35-
// free(captureComp);
36-
// capturedSurface.Release();
37-
// free(capturedSurface);
43+
captureComp = nullptr;
44+
context = nullptr;
45+
capturedSurface = nullptr;
3846
}
3947

4048
capture_e
4149
amd_capture_t::release_frame() {
42-
// BOOST_LOG(error) << "### R.G. release_frame, null pointer?: " << (capturedSurface == nullptr);
43-
// if (capturedSurface != nullptr)
44-
// {
45-
// BOOST_LOG(error) << "### R.G. Releasing frame";
46-
// Sleep(10);
47-
// capturedSurface->Release();
48-
// }
50+
if (capturedSurface != nullptr)
51+
{
52+
capturedSurface = nullptr;
53+
}
4954

5055
return capture_e::ok;
5156
}
@@ -179,8 +184,8 @@ namespace platf::dxgi {
179184

180185
// Set parameters for non-blocking capture
181186
captureComp->SetProperty(AMF_DISPLAYCAPTURE_MONITOR_INDEX, output_index);
182-
captureComp->SetProperty(AMF_DISPLAYCAPTURE_FRAMERATE, AMFConstructRate(0, 1));
183-
captureComp->SetProperty(AMF_DISPLAYCAPTURE_MODE, AMF_DISPLAYCAPTURE_MODE_GET_CURRENT_SURFACE);
187+
captureComp->SetProperty(AMF_DISPLAYCAPTURE_FRAMERATE, AMFConstructRate(config.framerate, 1));
188+
captureComp->SetProperty(AMF_DISPLAYCAPTURE_MODE, AMF_DISPLAYCAPTURE_MODE_WAIT_FOR_PRESENT);
184189
captureComp->SetProperty(AMF_DISPLAYCAPTURE_DUPLICATEOUTPUT, true);
185190

186191
// Initialize capture

src/platform/windows/display_vram.cpp

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1447,9 +1447,6 @@ namespace platf::dxgi {
14471447
}
14481448
dup.capturedSurface = output;
14491449

1450-
// // Line below breaks reinit
1451-
// dup.capturedSurface->Acquire();
1452-
14531450
texture2d_t src = (ID3D11Texture2D*) dup.capturedSurface->GetPlaneAt(0)->GetNative();
14541451
src->GetDesc(&desc);
14551452

0 commit comments

Comments
 (0)