smasherprog / screen_capture_lite

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

Add stop_capturing function #23

Closed grz0zrg closed 7 years ago

grz0zrg commented 7 years ago

It would be more consistent to have a stop_capturing function.

smasherprog commented 7 years ago

I thought about this but decided to add a destroy() function on the ScreenCaptureManager class instead. destroy will stop all threads and clean everything up. Then, you can start everything back up again when you are ready

First, create a function to wire everything up that can be recalled, then call that when you need to start capturing again.


ScreenCaptureManager framgrabber ;
void start_capturing() {
    framgrabber =
        SL::Screen_Capture::CreateScreeCapture([]() { return SL::Screen_Capture::GetMonitors(); })
        .onFrameChanged([&](const SL::Screen_Capture::Image& img, const SL::Screen_Capture::Monitor& monitor) {
    }).onNewFrame([&](const SL::Screen_Capture::Image& img, const SL::Screen_Capture::Monitor& monitor) {
    }).onMouseChanged([&](const SL::Screen_Capture::Image* img, int x, int y) {
    }).start_capturing();
}
int main()
{
  start_capturing();
///program runs then decides to stop/pause capturing
  framgrabber .destroy();
//program runs then decides to start again
  start_capturing();
  return 0;
}

This is the most flexible way of starting/stopping/pausing/resuming

If the library handled this, it would complicate the internals alot. Let me know if that works

smasherprog commented 7 years ago

after thinking about it more, I could add a pause/resume function. This would lead to the internals of the library in a wait loop. This wouldnt be that bad as far as coding. Ill get that done shortly.

smasherprog commented 7 years ago

I added paused, isPaused, and resume functions to the public api. I think this is what you were looking for. To completely stop everything would be to call destroy on the object.