Giter Club home page Giter Club logo

Comments (2)

robmikh avatar robmikh commented on May 17, 2024 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.

MartinClementson avatar MartinClementson commented on May 17, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.