Skip to content

Commit

Permalink
AMD Display Capture reinit fix
Browse files Browse the repository at this point in the history
* Drain queued frames before termination
  • Loading branch information
radugrecu97 committed Oct 9, 2024
1 parent dee7ebc commit b65e56d
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 18 deletions.
35 changes: 20 additions & 15 deletions src/platform/windows/display_amd.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -27,25 +27,30 @@ namespace platf::dxgi {
}

amd_capture_t::~amd_capture_t() {
captureComp->Flush();
AMF_RESULT result;

// Before terminating the Display Capture component, we need to drain the remaining frames
result = captureComp->Drain();
if (result == AMF_OK) {
do {
result = captureComp->QueryOutput((amf::AMFData**) &capturedSurface);
Sleep(1);
} while (result != AMF_EOF);
}
captureComp->Terminate();

context->Terminate();
// capturedSurface = nullptr;
// free(context);
// free(captureComp);
// capturedSurface.Release();
// free(capturedSurface);
captureComp = nullptr;
context = nullptr;
capturedSurface = nullptr;
}

capture_e
amd_capture_t::release_frame() {
// BOOST_LOG(error) << "### R.G. release_frame, null pointer?: " << (capturedSurface == nullptr);
// if (capturedSurface != nullptr)
// {
// BOOST_LOG(error) << "### R.G. Releasing frame";
// Sleep(10);
// capturedSurface->Release();
// }
if (capturedSurface != nullptr)
{
capturedSurface = nullptr;
}

return capture_e::ok;
}
Expand Down Expand Up @@ -179,8 +184,8 @@ namespace platf::dxgi {

// Set parameters for non-blocking capture
captureComp->SetProperty(AMF_DISPLAYCAPTURE_MONITOR_INDEX, output_index);
captureComp->SetProperty(AMF_DISPLAYCAPTURE_FRAMERATE, AMFConstructRate(0, 1));
captureComp->SetProperty(AMF_DISPLAYCAPTURE_MODE, AMF_DISPLAYCAPTURE_MODE_GET_CURRENT_SURFACE);
captureComp->SetProperty(AMF_DISPLAYCAPTURE_FRAMERATE, AMFConstructRate(config.framerate, 1));
captureComp->SetProperty(AMF_DISPLAYCAPTURE_MODE, AMF_DISPLAYCAPTURE_MODE_WAIT_FOR_PRESENT);
captureComp->SetProperty(AMF_DISPLAYCAPTURE_DUPLICATEOUTPUT, true);

// Initialize capture
Expand Down
3 changes: 0 additions & 3 deletions src/platform/windows/display_vram.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1447,9 +1447,6 @@ namespace platf::dxgi {
}
dup.capturedSurface = output;

// // Line below breaks reinit
// dup.capturedSurface->Acquire();

texture2d_t src = (ID3D11Texture2D*) dup.capturedSurface->GetPlaneAt(0)->GetNative();
src->GetDesc(&desc);

Expand Down

0 comments on commit b65e56d

Please sign in to comment.