smasherprog / screen_capture_lite

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

attempting to add an example of sending data over boost socket #125

Closed EMCP closed 2 years ago

EMCP commented 2 years ago

I'm getting closer to having a working system in which I

1) parse some input commands fullscreen vs window 2) start a socket server 3) upon connection from a client, we start screen_capture_lite 4) when I frame comes in , I send it over the supplied by reference socket so client can receive it.

My issue is understanding an error when I added the socket to framegrabber in the example code

framgrabber =
    SL::Screen_Capture::CreateCaptureConfiguration([target_window, output_choice, server_socket]() {
   ...
    })  ->onNewFrame([&](const SL::Screen_Capture::Image &img, const SL::Screen_Capture::Window &window) {
        // Uncomment the below code to write the image to disk for debugging

        if(output_choice == "file"){
          ...
        } else if (output_choice == "stream"){
          std::cout << "WE WANT A STREAM!!!!" << std::endl;
          transmitsocketdata(socket, img);
        }

I successfully passed strings in like the target_window , but this server_socket (tcp::socket) seems to trigger some warning

Consolidate compiler generated dependencies of target screengrabber_static
[ 33%] Building CXX object CMakeFiles/screengrabber_static.dir/src/image_sender.cpp.o
/Users/emcp/Dev/git/screengrabber/src/image_sender.cpp:103:68: error: call to deleted constructor of 'tcp::socket' (aka 'basic_stream_socket<boost::asio::ip::tcp>')
    SL::Screen_Capture::CreateCaptureConfiguration([output_choice, server_socket]() {
                                                                   ^~~~~~~~~~~~~
/Users/emcp/.conan/data/boost/1.77.0/_/_/package/c5da5260a03de8416b30cdf8d910ad9bd46ff2b3/include/boost/asio/basic_stream_socket.hpp:1045:3: note: 'basic_stream_socket' has been explicitly marked deleted here
  basic_stream_socket(const basic_stream_socket&) BOOST_ASIO_DELETED;
  ^
/Users/emcp/Dev/git/screengrabber/src/image_sender.cpp:178:30: error: use of undeclared identifier 'server_socket'
          transmitsocketdata(server_socket, img);
                             ^
In file included from /Users/emcp/Dev/git/screengrabber/src/image_sender.cpp:1:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk/usr/include/c++/v1/iostream:37:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk/usr/include/c++/v1/ios:215:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk/usr/include/c++/v1/__locale:15:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk/usr/include/c++/v1/string:511:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk/usr/include/c++/v1/string_view:179:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk/usr/include/c++/v1/__string:57:
In file included from /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk/usr/include/c++/v1/algorithm:653:
/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX12.0.sdk/usr/include/c++/v1/memory:1270:9: error: call to implicitly-deleted copy constructor of '(lambda at /Users/emcp/Dev/git/screengrabber/src/image_sender.cpp:103:52)'
      : __value_(_VSTD::forward<_Args>(_VSTD::get<_Indexes>(__args))...) {}

should I explicitly pass the address via & , otherwise I will need to rethink how to construct the socket and maybe declare it inside the onNewFrame perhaps

Thank you

EMCP commented 2 years ago

okay I think I am through,

I must pass things into lambda functions .. and if it's a socket it only seems to want to get passed by reference, now the compiler has stopped complaining