@@ -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
0 commit comments