Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for v4l2loopback #2232

Closed
wants to merge 59 commits into from
Closed

Support for v4l2loopback #2232

wants to merge 59 commits into from

Commits on Jan 4, 2021

  1. Increase display id range

    Some devices use big display id values.
    
    Refs #2009 <#2009>
    rom1v committed Jan 4, 2021
    Configuration menu
    Copy the full SHA
    aa8b571 View commit details
    Browse the repository at this point in the history

Commits on Jan 8, 2021

  1. Split command into process and adb

    The process API provides the system-specific implementation, the adb API
    uses it to expose adb commands.
    rom1v committed Jan 8, 2021
    Configuration menu
    Copy the full SHA
    4bd9da4 View commit details
    Browse the repository at this point in the history
  2. Move conditional src files in meson.build

    Declare all the source files (including the platform-specific ones) at
    the beginning.
    rom1v committed Jan 8, 2021
    Configuration menu
    Copy the full SHA
    cc6f502 View commit details
    Browse the repository at this point in the history
  3. Rename process_simple_wait to process_wait

    Adding "simple" in the function name brings no benefit.
    rom1v committed Jan 8, 2021
    Configuration menu
    Copy the full SHA
    821c175 View commit details
    Browse the repository at this point in the history
  4. Separate process wait and close

    On Linux, waitpid() both waits for the process to terminate and reaps it
    (closes its handle). On Windows, these actions are separated into
    WaitForSingleObject() and CloseHandle().
    
    Expose these actions separately, so that it is possible to send a signal
    to a process while waiting for its termination without race condition.
    
    This allows to wait for server termination normally, but kill the
    process without race condition if it is not terminated after some delay.
    rom1v committed Jan 8, 2021
    Configuration menu
    Copy the full SHA
    d580ee3 View commit details
    Browse the repository at this point in the history
  5. Remove unused struct port_range

    It had been replaced by struct sc_port_range in scrcpy.h.
    rom1v committed Jan 8, 2021
    Configuration menu
    Copy the full SHA
    1e21519 View commit details
    Browse the repository at this point in the history
  6. Fix compat missing include

    The header libavformat/version.h was included, but not
    libavcodec/version.h.
    
    As a consequence, the LIBAVCODEC_VERSION_INT definition depended on the
    caller includes.
    rom1v committed Jan 8, 2021
    Configuration menu
    Copy the full SHA
    037be4a View commit details
    Browse the repository at this point in the history
  7. Move common structs to coords.h

    The size, point and position structs were defined in common.h. Move them
    to coords.h so that common.h could be used for generic code to be
    included in all source files.
    rom1v committed Jan 8, 2021
    Configuration menu
    Copy the full SHA
    6385b8c View commit details
    Browse the repository at this point in the history
  8. Group common includes into common.h

    Include config.h and compat.h in common.h, and include common.h from all
    source files.
    rom1v committed Jan 8, 2021
    Configuration menu
    Copy the full SHA
    59feb2a View commit details
    Browse the repository at this point in the history

Commits on Jan 17, 2021

  1. Define feature test macros in common.h

    This enables necessary functions once for all.
    
    As a consequence, define common.h before any other header.
    rom1v committed Jan 17, 2021
    Configuration menu
    Copy the full SHA
    ab912c2 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    8dbb167 View commit details
    Browse the repository at this point in the history
  3. Fix size_t incorrectly assigned to int

    The function control_msg_serialize() returns a size_t.
    rom1v committed Jan 17, 2021
    Configuration menu
    Copy the full SHA
    94eff0a View commit details
    Browse the repository at this point in the history

Commits on Jan 22, 2021

  1. Simplify process_wait()

    The function process_wait() returned a bool (true if the process
    terminated successfully) and provided the exit code via an output
    parameter exit_code.
    
    But the returned value was always equivalent to exit_code == 0, so just
    return the exit code instead.
    rom1v committed Jan 22, 2021
    Configuration menu
    Copy the full SHA
    b8edcf5 View commit details
    Browse the repository at this point in the history

Commits on Jan 24, 2021

  1. Expose a single process_wait()

    There were two versions: process_wait() and process_wait_noclose().
    
    Expose a single version with a flag (it was already implemented that way
    internally).
    rom1v committed Jan 24, 2021
    Configuration menu
    Copy the full SHA
    6a50231 View commit details
    Browse the repository at this point in the history
  2. Fix file_handler process race condition

    The current process could be waited both by run_file_handler() and
    file_handler_stop().
    
    To avoid the race condition, wait the process without closing, then
    close with mutex locked.
    rom1v committed Jan 24, 2021
    Configuration menu
    Copy the full SHA
    7afd149 View commit details
    Browse the repository at this point in the history
  3. Kill process with SIGKILL signal

    An "adb push" command is not terminated by SIGTERM.
    rom1v committed Jan 24, 2021
    Configuration menu
    Copy the full SHA
    b566700 View commit details
    Browse the repository at this point in the history
  4. Improve file handler error message

    Terminating the file handler current process may be either a "push" or
    "install" command.
    rom1v committed Jan 24, 2021
    Configuration menu
    Copy the full SHA
    d8e9ad2 View commit details
    Browse the repository at this point in the history
  5. Fix undefined left shift

    Small unsigned integers promote to signed int. As a consequence, if v is
    a uint8_t, then (v << 24) yields an int, so the left shift is undefined
    if the MSB is 1.
    
    Cast to uint32_t to yield an unsigned value.
    
    Reported by USAN (meson x -Db_sanitize=undefined):
    
        runtime error: left shift of 255 by 24 places cannot be represented
        in type 'int'
    rom1v committed Jan 24, 2021
    Configuration menu
    Copy the full SHA
    97b001e View commit details
    Browse the repository at this point in the history

Commits on Feb 14, 2021

  1. Remove unused custom event

    rom1v committed Feb 14, 2021
    Configuration menu
    Copy the full SHA
    8e83f3e View commit details
    Browse the repository at this point in the history
  2. Remove unused port_range field

    The port_range is used from "struct server_params", the copy in
    "struct server" was unused.
    rom1v committed Feb 14, 2021
    Configuration menu
    Copy the full SHA
    ace438e View commit details
    Browse the repository at this point in the history

Commits on Feb 17, 2021

  1. Provide strdup() compat

    Make strdup() available on all platforms.
    rom1v committed Feb 17, 2021
    Configuration menu
    Copy the full SHA
    c0dde0f View commit details
    Browse the repository at this point in the history
  2. Replace SDL_strdup() by strdup()

    The functions SDL_malloc(), SDL_free() and SDL_strdup() were used only
    because strdup() was not available everywhere.
    
    Now that it is available, use the native version of these functions.
    rom1v committed Feb 17, 2021
    Configuration menu
    Copy the full SHA
    30e619d View commit details
    Browse the repository at this point in the history
  3. Wrap SDL thread functions into scrcpy-specific API

    The goal is to expose a consistent API for system tools, and paves the
    way to make the "core" independant of SDL in the future.
    rom1v committed Feb 17, 2021
    Configuration menu
    Copy the full SHA
    f6320c7 View commit details
    Browse the repository at this point in the history
  4. Expose thread id

    rom1v committed Feb 17, 2021
    Configuration menu
    Copy the full SHA
    d2689fc View commit details
    Browse the repository at this point in the history
  5. Expose mutex assertions

    Add a function to assert that the mutex is held (or not).
    rom1v committed Feb 17, 2021
    Configuration menu
    Copy the full SHA
    21d206f View commit details
    Browse the repository at this point in the history
  6. Add mutex assertions

    rom1v committed Feb 17, 2021
    Configuration menu
    Copy the full SHA
    54f5c42 View commit details
    Browse the repository at this point in the history
  7. Configuration menu
    Copy the full SHA
    c53bd4d View commit details
    Browse the repository at this point in the history
  8. Add intermediate frame in video buffer

    There were only two frames simultaneously:
     - one used by the decoder;
     - one used by the renderer.
    
    When the decoder finished decoding a frame, it swapped it with the
    rendering frame.
    
    Adding a third frame provides several benefits:
     - the decoder do not have to wait for the renderer to release the
       mutex;
     - it simplifies the video_buffer API;
     - it makes the rendering frame valid until the next call to
       video_buffer_take_rendering_frame(), which will be useful for
       swscaling on window resize.
    rom1v committed Feb 17, 2021
    Configuration menu
    Copy the full SHA
    c0c4ba7 View commit details
    Browse the repository at this point in the history
  9. Make use_opengl local

    The flag is used only locally, there is no need to store it in the
    screen structure.
    rom1v committed Feb 17, 2021
    Configuration menu
    Copy the full SHA
    862948b View commit details
    Browse the repository at this point in the history
  10. Configuration menu
    Copy the full SHA
    a566635 View commit details
    Browse the repository at this point in the history
  11. Handle window events only once visible

    This will avoid corner cases where we need to resize while no frame has
    been received yet.
    rom1v committed Feb 17, 2021
    Configuration menu
    Copy the full SHA
    626094a View commit details
    Browse the repository at this point in the history

Commits on Feb 25, 2021

  1. Improve error handling in screen initialization

    After the struct screen is initialized, the window, the renderer and the
    texture are necessarily valid, so there is no need to check in
    screen_destroy().
    rom1v committed Feb 25, 2021
    Configuration menu
    Copy the full SHA
    0538e96 View commit details
    Browse the repository at this point in the history
  2. Reference video buffer from screen

    This paves the way to handle EVENT_NEW_FRAME from screen.c, by allowing
    to call screen_update_frame() without an explicit video_buffer instance.
    rom1v committed Feb 25, 2021
    Configuration menu
    Copy the full SHA
    ea2369f View commit details
    Browse the repository at this point in the history
  3. Configuration menu
    Copy the full SHA
    50b4a73 View commit details
    Browse the repository at this point in the history
  4. Inline window events handling

    Now that all screen-related events are handled from screen.c, there is
    no need for a separate method for window events.
    rom1v committed Feb 25, 2021
    Configuration menu
    Copy the full SHA
    76a3d98 View commit details
    Browse the repository at this point in the history
  5. Configuration menu
    Copy the full SHA
    24b637b View commit details
    Browse the repository at this point in the history
  6. Configuration menu
    Copy the full SHA
    9cd1a73 View commit details
    Browse the repository at this point in the history
  7. Remove unused no_window field

    rom1v committed Feb 25, 2021
    Configuration menu
    Copy the full SHA
    0207e3d View commit details
    Browse the repository at this point in the history
  8. Configuration menu
    Copy the full SHA
    a3aa5ac View commit details
    Browse the repository at this point in the history
  9. Simplify default values

    It makes sense to extract default values for bitrate and port range
    (which are arbitrary and might be changed in the future).
    
    However, the default values for "max size" and "lock video orientation"
    are naturally unlimited/unlocked, and will never be changed. Extracting
    these options just added complexity for no benefit, so hardcode them.
    rom1v committed Feb 25, 2021
    Configuration menu
    Copy the full SHA
    b16b65a View commit details
    Browse the repository at this point in the history

Commits on Mar 3, 2021

  1. Configuration menu
    Copy the full SHA
    218636d View commit details
    Browse the repository at this point in the history

Commits on Mar 6, 2021

  1. Move fps counter out of video buffer

    In order to make video buffer more generic, move out its specific
    responsibility to count the fps between the decoder and the renderer.
    rom1v committed Mar 6, 2021
    Configuration menu
    Copy the full SHA
    cb197ee View commit details
    Browse the repository at this point in the history
  2. Make video buffer more generic

    Video buffer is a tool between a frame producer and a frame consumer.
    
    For now, it is used between a decoder and a renderer, but in the future
    another instance might be used to swscale decoded frames.
    rom1v committed Mar 6, 2021
    Configuration menu
    Copy the full SHA
    441d3fb View commit details
    Browse the repository at this point in the history
  3. Initialize screen before starting the stream

    As soon as the stream is started, the video buffer could notify a new
    frame available.
    
    In order to pass this event to the screen without race condition, the
    screen must be initialized before the screen is started.
    rom1v committed Mar 6, 2021
    Configuration menu
    Copy the full SHA
    c50b958 View commit details
    Browse the repository at this point in the history
  4. Use a callback to notify a new frame

    Make the decoder independant of the SDL even mechanism, by making the
    consumer register a callback on the video_buffer.
    rom1v committed Mar 6, 2021
    Configuration menu
    Copy the full SHA
    fb9f984 View commit details
    Browse the repository at this point in the history
  5. Use a callback to notify frame skip

    A skipped frame is detected when the producer offers a frame while the
    current pending frame has not been consumed.
    
    However, the producer (in practice the decoder) is not interested in the
    fact that a frame has been skipped, only the consumer (the renderer) is.
    
    Therefore, notify frame skip via a consumer callback. This allows to
    manage the skipped and rendered frames count at the same place, and
    remove fps_counter from decoder.
    rom1v committed Mar 6, 2021
    Configuration menu
    Copy the full SHA
    cb9c42b View commit details
    Browse the repository at this point in the history
  6. Remove screen static initializer

    Most of the fields are initialized dynamically.
    rom1v committed Mar 6, 2021
    Configuration menu
    Copy the full SHA
    955da3b View commit details
    Browse the repository at this point in the history
  7. Group screen parameters into a struct

    The function screen_init_rendering had too many parameters.
    rom1v committed Mar 6, 2021
    Configuration menu
    Copy the full SHA
    597c54f View commit details
    Browse the repository at this point in the history
  8. Simplify screen initialization

    Use a single function to initialize the screen instance.
    rom1v committed Mar 6, 2021
    Configuration menu
    Copy the full SHA
    cc48b24 View commit details
    Browse the repository at this point in the history
  9. Factorize frame swap

    rom1v committed Mar 6, 2021
    Configuration menu
    Copy the full SHA
    386f017 View commit details
    Browse the repository at this point in the history
  10. Release frame data as soon as possible

    During a frame swap, one of the two frames involved can be released.
    rom1v committed Mar 6, 2021
    Configuration menu
    Copy the full SHA
    eb7e107 View commit details
    Browse the repository at this point in the history

Commits on Mar 9, 2021

  1. meson: Do not use full path with mingw tools name

    This helps to use mingw toolchains which are not in /usr/bin path.
    
    PR #2185 <#2185>
    
    Signed-off-by: Romain Vimont <rom@rom1v.com>
    Biswa96 authored and rom1v committed Mar 9, 2021
    Configuration menu
    Copy the full SHA
    d1789f0 View commit details
    Browse the repository at this point in the history

Commits on Mar 11, 2021

  1. Fix encoder parameter suggestion

    The option is --encoder, not --encoder-name.
    rom1v committed Mar 11, 2021
    Configuration menu
    Copy the full SHA
    429fdef View commit details
    Browse the repository at this point in the history

Commits on Mar 14, 2021

  1. Use device id 0 for touch/mouse events

    Virtual device is only for keyboard sources, not mouse or touchscreen
    sources. Here is the value of InputDevice.getDevice(-1).toString():
    
        Input Device -1: Virtual
          Descriptor: ...
          Generation: 2
          Location: built-in
          Keyboard Type: alphabetic
          Has Vibrator: false
          Has mic: false
          Sources: 0x301 ( keyboard dpad )
    
    InputDevice.getDeviceId() documentation says:
    
    > An id of zero indicates that the event didn't come from a physical
    > device and maps to the default keymap.
    
    <https://developer.android.com/reference/android/view/InputEvent#getDeviceId()>
    
    However, injecting events with a device id of 0 causes event.getDevice()
    to be null on the client-side.
    
    Commit 26529d3 used -1 as a workaround
    to avoid a NPE on a specific Android TV device. But this is a bug in the
    device system, which wrongly assumes that input device may not be null.
    
    A similar issue was present in Flutter, but it is now fixed:
     - <flutter/flutter#30665>
     - <flutter/engine#7986>
    
    On the other hand, using an id of -1 for touchscreen events (which is
    invalid) causes issues for some apps:
    <#2125 (comment)>
    
    Therefore, use a device id of 0.
    
    An alternative could be to find an existing device matching the source,
    like "adb shell input" does. See getInputDeviceId():
    <https://android.googlesource.com/platform/frameworks/base.git/+/master/cmds/input/src/com/android/commands/input/Input.java>
    
    But it seems better to indicate that the event didn't come from a
    physical device, and it would not solve #962 anyway, because an Android
    TV has no touchscreen.
    
    Refs #962 <#962>
    Fixes #2125 <#2125>
    rom1v committed Mar 14, 2021
    Configuration menu
    Copy the full SHA
    40febf4 View commit details
    Browse the repository at this point in the history

Commits on Mar 15, 2021

  1. Do not set buttons on touch events

    BUTTON_PRIMARY must not be set for touch events:
    
    > This button constant is not set in response to simple touches with a
    > finger or stylus tip. The user must actually push a button.
    
    <https://developer.android.com/reference/android/view/MotionEvent#BUTTON_PRIMARY>
    
    Fixes #2169 <#2169>
    rom1v committed Mar 15, 2021
    Configuration menu
    Copy the full SHA
    0308ef4 View commit details
    Browse the repository at this point in the history

Commits on Mar 16, 2021

  1. Pass scrcpy-noconsole arguments through to scrcpy

    PR #2052 <#2052>
    
    Signed-off-by: Romain Vimont <rom@rom1v.com>
    slingmint authored and rom1v committed Mar 16, 2021
    Configuration menu
    Copy the full SHA
    dd453ad View commit details
    Browse the repository at this point in the history
  2. Export static method to power off screen in Device

    PR #824 <#824>
    
    Signed-off-by: Yu-Chen Lin <npes87184@gmail.com>
    Signed-off-by: Romain Vimont <rom@rom1v.com>
    npes87184 authored and rom1v committed Mar 16, 2021
    Configuration menu
    Copy the full SHA
    fb0bcae View commit details
    Browse the repository at this point in the history
  3. Support power off on close

    PR #824 <#824>
    
    Signed-off-by: Yu-Chen Lin <npes87184@gmail.com>
    Signed-off-by: Romain Vimont <rom@rom1v.com>
    npes87184 authored and rom1v committed Mar 16, 2021
    Configuration menu
    Copy the full SHA
    1d615a0 View commit details
    Browse the repository at this point in the history

Commits on Apr 3, 2021

  1. v4l2loopback support

    martinellimarco committed Apr 3, 2021
    Configuration menu
    Copy the full SHA
    77447ff View commit details
    Browse the repository at this point in the history