1. 16 2月, 2018 3 次提交
    • R
      Replace SDL_net by custom implementation · 9b056f50
      Romain Vimont 提交于
      SDL_net is not very suitable for scrcpy.
      
      For example, SDLNet_TCP_Accept() is non-blocking, so we have to wrap it
      by calling many SDL_Net-specific functions to make it blocking.
      
      But above all, SDLNet_TCP_Open() is a server socket only when no IP is
      provided; otherwise, it's a client socket. Therefore, it is not possible
      to create a server socket bound to localhost, so it accepts connections
      from anywhere.
      
      This is a problem for scrcpy, because on start, the application listens
      for nearly 1 second until it accepts the first connection, supposedly
      from the device. If someone on the local network manages to connect to
      the server socket first, then they can stream arbitrary H.264 video.
      This may be troublesome, for example during a public presentation ;-)
      
      Provide our own simplified API (net.h) instead, implemented for the
      different platforms.
      9b056f50
    • R
      Improve decoder stopped event · bf41e547
      Romain Vimont 提交于
      The syntax was correct, but less readable, and it unnecessarily zeroed
      the fields other than "type".
      
      Create the event properly, from a separate method.
      bf41e547
    • R
      Prevent new window opening with CreateProcess() · 518d6d5d
      Romain Vimont 提交于
      Executing commands (like "adb push") created a new terminal window on
      Windows. Avoid it.
      518d6d5d
  2. 15 2月, 2018 13 次提交
    • R
      Reword Ctrl+x description · e8cad790
      Romain Vimont 提交于
      Pressing Ctrl+x resizes the window to remove black borders, "optimal" is
      not well-defined.
      e8cad790
    • R
      Remove useless screen render on initialization · 5ebf31d4
      Romain Vimont 提交于
      screen_render() should not be called on initialization:
       1. it is useless, since the window is hidden until the first frame;
       2. it writes an empty texture (probably green) to the renderer.
      5ebf31d4
    • R
      Add Ctrl+i shortcut to enable/disable FPS counter · d9772022
      Romain Vimont 提交于
      Disable FPS counter on start, and use Ctrl+i to enable/disable it.
      d9772022
    • R
      Refactor screencontrol to inputmanager · 000ced9b
      Romain Vimont 提交于
      The "screen control" handled user input, which happened to be only
      used to control the screen.
      
      The controller and screen were passed to every function. Instead, group
      them in a struct input_manager.
      
      The purpose is to add a new shortcut to enable/disable FPS counter. This
      feature is not related to "screen control", and will require access to
      the "frames" instance.
      000ced9b
    • R
      Add description for meson options · fb0e4675
      Romain Vimont 提交于
      The descriptions are displayed in the result of:
      
          mesonconf builddir
      fb0e4675
    • R
      Expose skip_frames as a build option · 42882702
      Romain Vimont 提交于
      It can be initially configured by:
      
          meson builddir -Dskip_frames=false
      
      Or on an existing builddir by:
      
          mesonconf builddir -Dskip_frames=false
      42882702
    • R
      Add FPS counter · 38e66828
      Romain Vimont 提交于
      Remove frame counter from scrcpy.c and add a new FPS counter, logging as
      INFO the measured frame rate every second (on new frame).
      38e66828
    • R
      Do not print usage on command error · c6c17af8
      Romain Vimont 提交于
      On error, a message is printed. If we print usage afterwards, it's easy
      to miss it.
      c6c17af8
    • R
      Expose device serial as an optional argument · 86976598
      Romain Vimont 提交于
      The device serial was provided as a positional argument:
      
          scrcpy 0123456789abcdef
      
      Instead, expose it as an optional argument, -s or --serial:
      
          scrcpy -s 0123456789abcdef
      
      This avoids inconsistency between platforms when the positional
      argument is passed before the options (which is undefined).
      86976598
    • R
      Extract argument parsing to specific functions · 23d92a95
      Romain Vimont 提交于
      To avoid a big switch/case, implement the argument parsing logic in
      separate static functions.
      23d92a95
    • R
      Use SDL_bool return to indicate success · 111068d7
      Romain Vimont 提交于
      For clarity and consistency across the application, return SDL_TRUE
      (instead of 0) on success and SDL_FALSE on failure (instead of
      non-zero).
      111068d7
    • R
      Sort parameters by letter · d3c76c00
      Romain Vimont 提交于
      For readability, sort the command-line arguments parsing by letter.
      d3c76c00
    • R
      Add run script · 9a07b694
      Romain Vimont 提交于
      Add a script to simplify the execution of scrcpy generated in a specific
      build directory.
      
      To run scrcpy generated in builddir, with a video size of 1024:
      
          ./run builddir -m 1024
      9a07b694
  3. 14 2月, 2018 5 次提交
    • R
      Accept prebuilt server · 07983d91
      Romain Vimont 提交于
      Expose a 'prebuilt_server' option to pass the path of the prebuilt
      binary, so that the build does not require Android SDK.
      
      Usage:
      
          meson builddir -Dprebuilt_server=/tmp/my_prebuilt_server.jar
      07983d91
    • R
      Require Meson 0.37 · 0efa9305
      Romain Vimont 提交于
      Older versions of Meson are too limited, and it's simple to install a
      newer version ("pip3 install meson").
      0efa9305
    • R
      Always invoke gradle except as root · 4c49b27e
      Romain Vimont 提交于
      The custom target used to invoke Gradle from Meson should always
      be built, otherwise, the server would not be rebuilt on source changes.
      
      However, when enabling "build_always", gradle is invoked as root on
      "sudo ninja install" after "ninja", so it downloads the whole Gradle
      world into /root/.gradle.
      
      To avoid the problem, just do not call gradle if the effective user id
      is 0.
      4c49b27e
    • R
      Replace meson subprojects by subdir · c2127d08
      Romain Vimont 提交于
      Since Meson 0.44, subproject_dir may not be '.' anymore. This implies we
      must move app/ and server/ to a subprojects/ directory, which requires
      to also change some gradle files.
      
      Instead, just use subdir(), with options to disable building of the app
      or the server.
      c2127d08
    • R
      Refactor build system · ff94462d
      Romain Vimont 提交于
      The client was built with Meson, the server with Gradle, and were run by
      a Makefile.
      
      Add a Meson script for the server (which delegates to Gradle), and a
      parent script to build and install both the client and the server to the
      system, typically with:
      
          meson --buildtype release build
          cd build
          ninja
          sudo ninja install
      
      In addition, use a separate Makefile to build a "portable" version of
      the application (where the client expects the server to be in the
      current directory). Typically:
      
          make release-portable
          cd dist/scrcpy
          ./scrcpy
      
      This is especially useful for Windows builds, which are not "installed".
      ff94462d
  4. 13 2月, 2018 4 次提交
  5. 12 2月, 2018 6 次提交
  6. 09 2月, 2018 9 次提交
    • R
      Properly clean up on exit · 0fce4f95
      Romain Vimont 提交于
      The SDL clean up does not crash anymore on exit, probably since the
      memory corruption caused by calling SDLNet_TCP_Close() too early has
      been resolved.
      0fce4f95
    • R
      Timeout the server socket connection · eb09fefd
      Romain Vimont 提交于
      Wait no more than 2 seconds for accepting the connection from the
      device, since it blocks the event loop, preventing to react to SIGTERM
      (Ctrl+C).
      eb09fefd
    • R
      Improve startup time · 90a46b4c
      Romain Vimont 提交于
      On startup, the client has to:
       1. listen on a port
       2. push and start the server to the device
       3. wait for the server to connect (accept)
       4. read device name and size
       5. initialize SDL
       6. initialize the window and renderer
       7. show the window
      
      From the execution of the app_process command to start the server on the
      device, to the execution of the java main method, it takes ~800ms. As a
      consequence, step 3 also takes ~800ms on the client.
      
      Once complete, the client initializes SDL, which takes ~500ms.
      
      These two expensive actions are executed sequentially:
      
                           HOST              DEVICE
      listen on port        |                  |
      push/start the server |----------------->|| app_process loads the jar
      accept the connection .   ^              ||
                            .   |              ||
                            .   | WASTE        ||
                            .   |  OF          ||
                            .   | TIME         ||
                            .   |              ||
                            .   |              ||
                            .   v              X execution of our java main
      connection accepted   |<-----------------| connect to the host
      init SDL             ||                  |
                           || ,----------------| send frames
                           || |,---------------|
                           || ||,--------------|
                           || |||,-------------|
                           || ||||,------------|
      init window/renderer  | |||||,-----------|
      display frames        |<++++++-----------|
      (many frames skipped)
      
      The rationale for step 3 occuring before step 5 is that initializing
      SDL replaces the SIGTERM handler to receive the event in the event loop,
      so pressing Ctrl+C during step 5 would not work (since it blocks the
      event loop).
      
      But this is not so important; let's parallelize the SDL initialization
      with the app_process execution (we'll just add a timeout to the
      connection):
      
                           HOST              DEVICE
      listen on port        |                  |
      push/start the server |----------------->||app_process loads the jar
      init SDL             ||                  ||
                           ||                  ||
                           ||                  ||
                           ||                  ||
                           ||                  ||
                           ||                  ||
      accept the connection .                  ||
                            .                  X execution of our java main
      connection accepted   |<-----------------| connect to the host
      init window/renderer  |                  |
      display frames        |<-----------------| send frames
                            |<-----------------|
      
      In addition, show the window only once the first frame is available to
      avoid flickering (opening a black window for 100~200ms).
      
      Note: the window and renderer are initialized after the connection is
      accepted because they use the device information received from the
      device.
      90a46b4c
    • R
      Turn screen on in control() · 063cfd13
      Romain Vimont 提交于
      Turning the screen on is semantically associated to control(): only
      creating the EventController object should not turn the screen on.
      063cfd13
    • R
      Provide decoder_init() · 523097ea
      Romain Vimont 提交于
      Expose an initializer so that the caller does not have to guess what
      fields must be initialized.
      523097ea
    • R
      Do not release TCP sockets while still in use · 46621982
      Romain Vimont 提交于
      SDLNet_TCP_Close() not only closes, but also release the resources.
      
      Therefore, we must not close the socket if another thread attempts to
      read it.
      
      For that purpose, move socket closing from server_stop() to
      server_destroy().
      46621982
    • R
      Enable sanitizer in debug builds · d658586d
      Romain Vimont 提交于
      "make build-debug" will build with ASAN and USAN enabled.
      d658586d
    • R
      Move frame updating to screen.c · fe21d9df
      Romain Vimont 提交于
      Replace screen_update() by a higher-level screen_update_frame() handling
      the whole frame updating, so that scrcpy.c just call it without managing
      implementation details.
      fe21d9df
    • R
      Kill the server immediately on close · 7458d827
      Romain Vimont 提交于
      Do not wait 100ms anymore to let the server print any exception: we
      justly want to ignore them.
      
      Moreover, there is no nanosleep() on Windows, so this solve another
      problem.
      7458d827