Comments (2)
Sorry for taking so long to get to this! Thank you, @MartinClementson, for answering! I appreciate it when the community helps us out. 🙂
When OnFrameArrived
is called, there is already a frame waiting for you in the frame pool. You should retrieve it by calling TryGetNextFrame
, and then hold onto the Direct3D11CaptureFrame
object. As long as you're holding onto a reference, that frame will not be available to the DWM to draw to. Technically, if you sleep before TryGetNextFrame
, that frame still isn't available to the DWM but you are also waiting to process the frame until after the sleep. That may not be what you want given your scenario.
You may want to approach this a different way. If you have a frame rate you're shooting for, I'd create a new thread using DispatcherQueueController.CreateOnDedicatedThread
and then create a timer on that thread using CreateTimer
. When the timer ticks, I would then release the last frame object I was holding onto and wait for the next frame (depending on how close you are to the vblank, this will introduce a bit of latency). Depending on how you engineer your "wait", you may need to create your frame pool using CreateFreeThreaded
.
This model isn't too dissimilar to how I put together the Simple Screen Recorder app. The big difference is that instead of a timer, my requests were driven by the encoder I was using. Take a look at the CaptureFrameWait
object. That project is in C#, but the same approach should work in C++.
As far as the crash you're seeing, I'm unable to reproduce it. If you're able to share a memory dump at the moment you hit the crash, I can take a look to see why it happens.
from windows.ui.composition-win32-samples.
Hi.
I asked a similar question to robmihk some time back. His reply might help you.
from Robmikh, Re:Controling frame rate:
The DWM will render a new frame if a buffer is available. This means you can control the rendering by controlling the lifetimes of the Direct3D11CaptureFrame objects.
For example, if you have a frame pool with 2 buffers, you can stop the DWM from rendering by holding onto two Direct3D11CaptureFrame objects (don't release or dispose/close them). Releasing a frame will make it available to the DWM again.
We've had clients who make their frame pool 1 buffer to make that control easier.
I did some prototyping, but can't find the repo at the moment.
but basically change to one buffer;
m_framePool = winrt::Direct3D11CaptureFramePool::Create(m_device, m_pixelFormat, 1, newSize);
You may want to put your sleep after TryGetNextFrame. I think the sleep will make you lose the chance to get ownership of the frame buffer, and the DWM will start rendering a new frame while your function is sleeping. So the crash is probably because it's being used by the DMW.
try
auto frame = sender.TryGetNextFrame(); //
//Do stuff
Sleep(yourTime)
frame.Close() // <--- This makes it available to render again.
You'd want to calculate how much you need to sleep depending on the framerate you want and how long it took to render the last frame.
from windows.ui.composition-win32-samples.
Related Issues (20)
- Some samples use `WindowsRuntimeMarshal` class, that is no longer available in .NET 5+ HOT 4
- Cannot use IGraphicsCaptureItemInterop::CreateForWindow with electron apps HOT 6
- This repo is missing important files HOT 4
- How to capture Windows10/11 Virtual Desktop via Windows.Graphics.Capture ? HOT 2
- Accessing screen capture image bytes with MapFlags.DoNotWait for better CPU usage HOT 3
- Can I do successive captures on two different windows HOT 8
- ScreenCapture Sample - write capture stream to disk mp4? HOT 5
- Capture area of a monitor HOT 4
- Memory Leak? HOT 5
- BSODs on 4 separate Hard Drives HOT 3
- Multiple screen captures in a loop cause explorer.exe and native Windows app to lag? HOT 11
- Capture OnFrame Callback very slow on Win11 23H2 HOT 7
- access_denied in CreateForMonitor in some cases HOT 5
- Cannot catch errors in CreateCaptureItemForWindow HOT 3
- WGC CaptureFrame returns wrong SystemRelativeTime in window capture mode HOT 2
- Cursor may become invisible when recording some fullscreen games using WGC HOT 6
- Frame has issue after change window state (maximize from normal/ normal from maximize/ ...) HOT 1
- ScreenCaptureforHWND sample leaks handles leading to "Out of memory" crash HOT 1
- ScreenCaptureforHWND sample main thread hang HOT 2
- ScreenCaptureforHWND: How to get the byte data of the captured frame? HOT 4
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from windows.ui.composition-win32-samples.