diff --git a/ports/scrcpy.hash b/ports/scrcpy.hash new file mode 100644 index 0000000..54402ad --- /dev/null +++ b/ports/scrcpy.hash @@ -0,0 +1 @@ +525183653aaad23fc4700c5a482d4edfd2eaaa80 diff --git a/ports/scrcpy.port b/ports/scrcpy.port new file mode 100644 index 0000000..d722644 --- /dev/null +++ b/ports/scrcpy.port @@ -0,0 +1,10 @@ +LICENSE := GPL2 +VERSION := git +DOWNLOADS := scrcpy.git + +URL(scrcpy) := https://github.com/alex-ab/scrcpy.git +REV(scrcpy) := d7258fc4fbdcbf1cacb1bb04bbaa95a7bd8d8f45 +DIR(scrcpy) := src/app/scrcpy + +PATCHES := src/app/scrcpy/scrcpy.patch src/app/scrcpy/libav_smp.patch +PATCH_OPT := -p1 -d src/app/scrcpy diff --git a/run/scrcpy.run b/run/scrcpy.run new file mode 100644 index 0000000..82010be --- /dev/null +++ b/run/scrcpy.run @@ -0,0 +1,583 @@ +# To run this script, you need Scrcpy from: +# +# https://github.com/alex-ab/scrcpy.git - branch: direct +# +# build hints: +# snap install androidsdk +# androidsdk --list +# export ANDROID_HOME=/home//snap/androidsdk/24/AndroidSDK +# +# meson build --buildtype release --strip -Db_lto=true +# ninja -C build +# +# adb devices -l +# adb tcpip 5555 +# adb connect :5555 +# adb devices -l +# List of devices attached +# :5555 device product:gta3xlwifieea model:SM_T510 device:gta3xlwifi transport_id:6 +# +# adb push x/server/scrcpy-server /data/local/tmp/scrcpy-server.jar +# +# - 8Mbit, encode H264 with android resolution +# adb shell CLASSPATH=/data/local/tmp/scrcpy-server.jar app_process / com.genymobile.scrcpy.Server 1.13 0 8000000 0 -1 true - true true 0 27184 +# +# - 8Mbit, encode H264 on Android with 1280 +# adb shell CLASSPATH=/data/local/tmp/scrcpy-server.jar app_process / com.genymobile.scrcpy.Server 1.13 1280 8000000 0 -1 true - true true 0 27184 +# +# - 4Mbit, crop screen to reduce stretch load on Genode side +# adb shell CLASSPATH=/data/local/tmp/scrcpy-server.jar app_process / com.genymobile.scrcpy.Server 1.13 0 4000000 0 -1 true 1080:1920:0:0 true true 0 27184 +# +# Now, you can try to boot Genode with this script to connect to Android Scrcpy server +# or on Linux local testing, use: +# ./run build --server-local --server-port 27184 +# + +set use_lxip 0 +set use_nic_router 1 +set ld_nic "yes" +if {[have_spec linux]} { set ld_nic "no" } + +set use_interactive_pkg 1 +if { [have_spec x86] && ![have_include "power_on/qemu"] && ![have_spec linux] } { + # use intel_fb_drv on x86 to get max resolution + set use_interactive_pkg 0 +} + +# repos/libports/run/fetchurl.inc: +# +# This run script works on Linux with NAT setup from tap0 to uplink +# device uplink0 like follows. +# +# iptables -t nat -A POSTROUTING -o uplink0 -j MASQUERADE +# iptables -A FORWARD -i tap0 -o uplink0 -j ACCEPT +# iptables -A FORWARD -i uplink0 -o tap0 -m state --state RELATED,ESTABLISHED -j ACCEPT +# echo 1 > /proc/sys/net/ipv4/ip_forward +# + +set use_ping 0 +set use_top 0 +set use_top_view 0 +set use_trace [expr $use_top || $use_top_view] + +set use_backdrop 1 + +set use_nic 1 +set use_wifi [expr ![have_spec linux] && !$use_nic] + +set lx_ip_addr "10.0.2.55" +set lx_gw_addr "10.0.2.1" + +set dst_ip "10.0.0.8" +set dst_port "27184" + +proc socket_fs_plugin {} { + global use_lxip + if { $use_lxip } { return lxip } + return lwip +} + +proc binary_nic_drv { } { + if {[have_spec linux]} { return "linux_nic_drv" } + if {[have_spec x86]} { return "ipxe_nic_drv" } + if {[have_spec imx8q_evk]} { return "fec_nic_drv" } + return "unknown_nic_drv" +} + +proc binary_nic_config { } { + if {[have_spec imx8q_evk]} { + return {} + } + return "" +} + +# +# Configure wireless lan +# + +proc wifi_ssid { } { + if {[info exists ::env(GENODE_WIFI_SSID)]} { + return $::env(GENODE_WIFI_SSID) + } else { + return "unknown" + } +} + +proc wifi_psk { } { + if {[info exists ::env(GENODE_WIFI_PSK)]} { + return $::env(GENODE_WIFI_PSK) + } else { + return "unknown" + } +} + +# +# widi_drv config generator (supporting a network list) +# +# You may script your tests with this function in the dynamic_rom config below. +# The syntax for the networks parameter is +# +# { ssid protection passphrase explicit_scan } +# +# Example dynamic_rom config: +# +# { +# } [wifi_config 30 5 no [list "net1 WPA2 net1_psk no" "net2 WPA2 net2_psk no"]] { +# +# +# } [wifi_config 30 5 no [list "net1 WPA2 net1_psk no" "net2 WPA2 net2_psk yes"]] { +# } + +set wifi_verbose false +set wifi_verbose_state false + +proc wifi_config { connected_scan_interval scan_interval rfkill networks } { + global wifi_verbose + global wifi_verbose_state + + set config "\n" + foreach n $networks { + append config " \n" + } + append config "\n" + + return $config +} + +create_boot_directory + +import_from_depot [depot_user]/src/[base_src] \ + [depot_user]/pkg/[drivers_interactive_pkg] \ + [depot_user]/src/init \ + [depot_user]/src/nitpicker \ + [depot_user]/src/nit_focus \ + [depot_user]/src/vfs \ + [depot_user]/src/vfs_jitterentropy \ + [depot_user]/src/vfs_[socket_fs_plugin] \ + [depot_user]/src/zlib \ + [depot_user]/src/report_rom \ + [depot_user]/src/nic_router \ + [depot_user]/src/libpng \ + [depot_user]/src/libc \ + [depot_user]/raw/genode_bg \ + [depot_user]/pkg/backdrop \ + [depot_user]/pkg/fonts_fs + +set build_components { app/scrcpy } + +if { !$use_interactive_pkg } { + append build_components drivers/framebuffer + source ${genode_dir}/repos/base/run/platform_drv.inc + append_platform_drv_build_components +} + +lappend_if $use_nic build_components drivers/nic +lappend_if $use_wifi build_components drivers/wifi +lappend_if $use_wifi build_components drivers/rtc +lappend_if $use_ping build_components app/ping +lappend_if $use_top build_components app/top +append_if $use_top_view build_components { app/menu_view app/top_view + app/graph } + + +build $build_components + +set config { + + + + + + + + + + + + + + } + +append_if $use_trace config { + } + +append config { + + + + + + + + + + + + + + } + +append_if $use_interactive_pkg config { + + + + + + + + + + + + + + } + +if { !$use_interactive_pkg } { + append_platform_drv_config + + append_if [have_spec x86] config { + + + + + + + } + + append_if [have_spec x86] config { + + + + + + + + } +} + +append_if $use_nic config { + + + + + + } [binary_nic_config] { + } + +append_if $use_nic_router config { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + } + +append_if [expr $use_nic_router && $use_nic] config { + } + +append_if [expr $use_nic_router && $use_wifi] config { + } + +append_if $use_nic_router config { + + + } + +append config { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + } + +append_if $use_backdrop config { + + + + + + + + + + + + + + + } + +append_if $use_ping config { + + + + + + + + + } + +append_if $use_top config { + + + + + } + +append_if $use_top_view config { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + } + +append_if $use_wifi config { + + + + + + + + + + + + + + + + + + + + + + + + } + +append config { + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 2020-06-18 15:25 + 01234567890123456789 + + <} [socket_fs_plugin] { dhcp="yes"/> + + + + + + + +} + +install_config $config + +# write wifi config file +set cfg_fd [open "bin/wifi_config" w] +puts $cfg_fd [wifi_config 30 5 no [list "[wifi_ssid] WPA2 [wifi_psk] yes"]] +close $cfg_fd + +set firmware_modules { + iwlwifi-6000-4.ucode + iwlwifi-6000g2a-6.ucode + iwlwifi-6000g2b-6.ucode + iwlwifi-7260-17.ucode + iwlwifi-7265-17.ucode + iwlwifi-7265D-29.ucode + iwlwifi-8000C-36.ucode + iwlwifi-8265-36.ucode + regulatory.db} + +set boot_modules { + scrcpy sdl2.lib.so + avutil.lib.so avcodec.lib.so avformat.lib.so +} + +if { !$use_interactive_pkg } { + append_platform_drv_boot_modules + append_if [have_spec x86] boot_modules { intel_fb_drv } +} + +lappend_if $use_nic boot_modules [binary_nic_drv] +append_if $use_wifi boot_modules { wifi_drv + libcrypto.lib.so + libssl.lib.so + wifi.lib.so + wpa_driver_nl80211.lib.so + wpa_supplicant.lib.so } +append_if $use_wifi boot_modules $firmware_modules +lappend_if $use_wifi boot_modules rtc_drv +lappend_if $use_wifi boot_modules wifi_config +lappend_if $use_ping boot_modules ping +lappend_if $use_top boot_modules top +append_if $use_top_view boot_modules { menu_view menu_view_styles.tar top_view graph } + +build_boot_image $boot_modules + +append qemu_args " -net nic,model=e1000 -net user " + +run_genode_until forever diff --git a/src/app/scrcpy/config.h b/src/app/scrcpy/config.h new file mode 100644 index 0000000..a7712f5 --- /dev/null +++ b/src/app/scrcpy/config.h @@ -0,0 +1,33 @@ +/* + * Autogenerated by the Meson build system. + * Do not edit, your changes will be lost. + */ + +#pragma once + +#define DEFAULT_BIT_RATE 8000000 + +#define DEFAULT_LOCAL_PORT_RANGE_FIRST 27183 + +#define DEFAULT_LOCAL_PORT_RANGE_LAST 27199 + +#define DEFAULT_LOCK_VIDEO_ORIENTATION -1 + +#define DEFAULT_MAX_SIZE 0 + +#define HIDPI_SUPPORT + +#define NDEBUG + +#undef PORTABLE + +#define PREFIX "/usr/local" + +#define SCRCPY_VERSION "1.13" + +#undef SERVER_DEBUGGER + +#define SERVER_DEBUGGER_METHOD_NEW + +#undef WINDOWS_NOCONSOLE + diff --git a/src/app/scrcpy/libav_smp.patch b/src/app/scrcpy/libav_smp.patch new file mode 100644 index 0000000..fcd8131 --- /dev/null +++ b/src/app/scrcpy/libav_smp.patch @@ -0,0 +1,23 @@ +--- a/app/src/decoder.c ++++ b/app/src/decoder.c +@@ -44,12 +44,19 @@ decoder_open(struct decoder *decoder, const AVCodec *codec) { + return false; + } + +- if (avcodec_open2(decoder->codec_ctx, codec, NULL) < 0) { ++ AVDictionary *opts = NULL; ++// av_dict_set(&opts, "threads", "2", 0); ++ av_dict_set(&opts, "threads", "auto", 0); ++ ++ if (avcodec_open2(decoder->codec_ctx, codec, &opts) < 0) { + LOGE("Could not open codec"); + avcodec_free_context(&decoder->codec_ctx); + return false; + } + ++ if (opts) ++ av_dict_free(&opts); ++ + return true; + } + diff --git a/src/app/scrcpy/scrcpy.patch b/src/app/scrcpy/scrcpy.patch new file mode 100644 index 0000000..fa22b8c --- /dev/null +++ b/src/app/scrcpy/scrcpy.patch @@ -0,0 +1,114 @@ +--- a/app/src/server.c ++++ b/app/src/server.c +@@ -278,7 +278,7 @@ + char max_size_string[6]; + char bit_rate_string[11]; + char max_fps_string[6]; +- char lock_video_orientation_string[3]; ++ char lock_video_orientation_string[5]; + char display_id_string[6]; + sprintf(max_size_string, "%"PRIu16, params->max_size); + sprintf(bit_rate_string, "%"PRIu32, params->bit_rate); +--- a/app/src/cli.c ++++ b/app/src/cli.c +@@ -12,6 +12,10 @@ + + #include + ++#ifndef inet_network ++extern in_addr_t inet_network(char const *); ++#endif ++ + void + scrcpy_print_usage(const char *arg0) { + #ifdef __APPLE__ +--- a/app/src/screen.c ++++ b/app/src/screen.c +@@ -13,7 +13,7 @@ + #include "util/lock.h" + #include "util/log.h" + +-#define DISPLAY_MARGINS 96 ++#define DISPLAY_MARGINS 0 + + static inline struct size + get_rotated_size(struct size size, int rotation) { +@@ -246,7 +246,7 @@ screen_init_rendering(struct screen *screen, const char *window_title, + } + + screen->renderer = SDL_CreateRenderer(screen->window, -1, +- SDL_RENDERER_ACCELERATED); ++ SDL_RENDERER_SOFTWARE); + if (!screen->renderer) { + LOGC("Could not create renderer: %s", SDL_GetError()); + screen_destroy(screen); +@@ -383,6 +383,7 @@ + // frame dimension changed, destroy texture + SDL_DestroyTexture(screen->texture); + ++/* + struct size content_size = screen->content_size; + struct size windowed_size = get_windowed_window_size(screen); + struct size target_size = { +@@ -391,6 +392,9 @@ + (uint32_t) windowed_size.height * new_content_size.height + / content_size.height, + }; ++*/ ++ struct size target_size = new_content_size; ++ + target_size = get_optimal_size(target_size, new_content_size); + set_window_size(screen, target_size); + +--- a/app/src/decoder.c ++++ b/app/src/decoder.c +@@ -60,7 +60,7 @@ decoder_close(struct decoder *decoder) { + } + + bool +-decoder_push(struct decoder *decoder, const AVPacket *packet) { ++decoder_push(struct decoder *decoder, AVPacket *packet) { + // the new decoding/encoding API has been introduced by: + // + #ifdef SCRCPY_LAVF_HAS_NEW_ENCODING_DECODING_API +--- a/app/src/decoder.h ++++ b/app/src/decoder.h +@@ -23,7 +23,7 @@ void + decoder_close(struct decoder *decoder); + + bool +-decoder_push(struct decoder *decoder, const AVPacket *packet); ++decoder_push(struct decoder *decoder, AVPacket *packet); + + void + decoder_interrupt(struct decoder *decoder); +--- a/app/src/recorder.c ++++ b/app/src/recorder.c +@@ -28,7 +28,7 @@ find_muxer(const char *name) { + } + + static struct record_packet * +-record_packet_new(const AVPacket *packet) { ++record_packet_new(AVPacket *packet) { + struct record_packet *rec = SDL_malloc(sizeof(*rec)); + if (!rec) { + return NULL; +@@ -355,7 +355,7 @@ recorder_join(struct recorder *recorder) { + } + + bool +-recorder_push(struct recorder *recorder, const AVPacket *packet) { ++recorder_push(struct recorder *recorder, AVPacket *packet) { + mutex_lock(recorder->mutex); + assert(!recorder->stopped); + +--- a/app/src/recorder.h ++++ b/app/src/recorder.h +@@ -67,6 +67,6 @@ void + recorder_join(struct recorder *recorder); + + bool +-recorder_push(struct recorder *recorder, const AVPacket *packet); ++recorder_push(struct recorder *recorder, AVPacket *packet); + + #endif diff --git a/src/app/scrcpy/target.mk b/src/app/scrcpy/target.mk new file mode 100644 index 0000000..c3de534 --- /dev/null +++ b/src/app/scrcpy/target.mk @@ -0,0 +1,20 @@ +TARGET := scrcpy + +SCRCPY_DIR := $(call select_from_ports,scrcpy)/src/app/scrcpy + +SRC_C = $(notdir $(wildcard $(SCRCPY_DIR)/app/src/*.c)) +SRC_C += $(addprefix util/, $(notdir $(wildcard $(SCRCPY_DIR)/app/src/util/*.c))) +SRC_C += sys/unix/command.c + +#sys/unix/command.c - avoid missing strdup and strtok_r +CC_OPT_sys/unix/command += -include sys/cdefs.h + +#app/src/cli.c - avoid undefined reference to `__inet_network' +CC_OPT_cli += -D_C11_SOURCE + +INC_DIR += $(PRG_DIR) +INC_DIR += $(SCRCPY_DIR)/app/src + +LIBS += libc avformat avutil sdl2 + +vpath %.c $(SCRCPY_DIR)/app/src