From 7558b0935a64ef98ecdcf47c049133ee90ecf42d Mon Sep 17 00:00:00 2001 From: Rien Maertens Date: Wed, 12 Feb 2020 14:47:47 +0100 Subject: [PATCH] Graceful fallback to gzip if zstd is not present --- README.md | 8 +++----- reStream.sh | 36 ++++++++++++++++++++---------------- 2 files changed, 23 insertions(+), 21 deletions(-) diff --git a/README.md b/README.md index 1cb9989..e11665b 100644 --- a/README.md +++ b/README.md @@ -6,11 +6,9 @@ Snappy reMarkable screen sharing over SSH. On your **host** machine: - Any POSIX-shell (e.g. bash) -- [zstd](http://www.zstd.net/) - ffmpeg (with ffplay) - ssh -On your **reMarkable**: -- zstd (`opkg install zstd`) -- netcat (`opkg install netcat`) -- coreutils-head (`opkg install coreutils-head`) +On your **reMarkable** it is recommended to install [zstd](https://zstd.net) (`opkg install zstd` if you have [entware](https://github.com/evidlo/remarkable_entware) installed.) to have a smoother experience (sub-second latency). However, if you don't have it installed `reStream` will fall back to `gzip` which is installed by default. + + diff --git a/reStream.sh b/reStream.sh index 3eff4fe..0b43bbe 100755 --- a/reStream.sh +++ b/reStream.sh @@ -1,40 +1,44 @@ #!/bin/sh -set -eo pipefail - ssh_host="mohowzeg.usb" landscape=true -bin_head="/opt/bin/head" -bin_zstd="/opt/bin/zstd" -bin_ncat="/opt/bin/netcat" width=1408 height=1872 bytes_per_pixel=2 +loop_wait="true" +loglevel="info" + if ! ssh "$ssh_host" true; then echo "$ssh_host unreachable" exit 1 fi -for prog in $bin_head $bin_zstd $bin_ncat; do - if ! ssh "$ssh_host" "[ -f $prog ]"; then - echo "Program $prog is not present on $ssh_host." - exit 1 - fi -done +# Gracefully degrade to gzip if zstd is not present +if ssh "$ssh_host" "[ -f /opt/bin/zstd ]"; then + compress="/opt/bin/zstd" + decompress="zstd -d" +else + compress="gzip" + decompress="gzip -d" +fi window_bytes="$(($width*$height*$bytes_per_pixel))" -landscape_param="$($landscape && echo '-vf transpose=1')" -read_loop="while $bin_head -c $window_bytes /dev/fb0; do sleep .03; done | $bin_zstd" +orientation_param="$($landscape && echo '-vf transpose=1')" +head_fb0="dd if=/dev/fb0 count=1 bs=$window_bytes 2>/dev/null" +read_loop="while $head_fb0; do $loop_wait; done | $compress" + + +set -e ssh "$ssh_host" "$read_loop" \ - | zstd -d \ - | pv - \ + | $decompress \ | ffplay -vcodec rawvideo \ - -loglevel error \ + -loglevel "$loglevel" \ -f rawvideo \ -pixel_format gray16le \ -video_size "$width,$height" \ $landscape_param \ -i - +