smasherprog / screen_capture_lite

cross platform screen/window capturing library
MIT License
638 stars 156 forks source link

onNewFrame is switching between monitors #32

Closed grz0zrg closed 6 years ago

grz0zrg commented 6 years ago

Hello,

i have updated the library in my project and my "old" code don't work as expected anymore, it seem that each call of "onNewFrame" switch between monitors instead of capturing all the monitors in one go. Any ideas on how to capture all monitors in one call of "onNewFrame" ?

SL::Screen_Capture::CreateCaptureConfiguration([&]() {
      auto monitors = SL::Screen_Capture::GetMonitors();

      for (auto &monitor : monitors) {
        //capture_width += monitor.Width;
        //capture_height = monitor.Height;
      }

      return monitors;
    })
onNewFrame([&](const SL::Screen_Capture::Image& img, const SL::Screen_Capture::Monitor& monitor) {
    auto startsrc = StartSrc(img);
    auto capture_data_len = RowStride(img) * Height(img);
    std::memcpy(capture_data, startsrc, capture_data_len);
}})

Thank you.

smasherprog commented 6 years ago

Each monitor is always captured in separate calls to the onNewFrame. The reason is for performance. Each monitor runs in its own capture thread and so each time a new frame arrives, onnewframe will be called. For example, my home computer has three 4k monitors. I receive 3 callbacks for onNewFrame. Window capturing is the same-- each window would run in its own thread.

smasherprog commented 6 years ago

If you have one giant array of bytes big enough for all of your monitors, you can write to this as the calls come in because they will not overlap.

What are you trying to do that you are not able to?

smasherprog commented 6 years ago

Also to note, the monitor in the callback has an Id property which you can use. This is unique across the application

grz0zrg commented 6 years ago

Was it like that some month ago ? Just updated my project and found out that behavior which was rather odd at first but this is not an issue, i can work around it properly with what you have said. Thank.

smasherprog commented 6 years ago

I thought it has always worked this way, but I could be wrong. In any case, let me know of any changes that would be beneficial and ill do my best to make them. Or, do it yourself and issue a Pull Request :)

smasherprog commented 6 years ago

Closing this issue.... let me know how it goes