Graceful fallback to gzip if zstd is not present

This commit is contained in:
Rien Maertens 2020-02-12 14:47:47 +01:00
parent 0cdbae1cb2
commit 7558b0935a
No known key found for this signature in database
GPG Key ID: AE66CE42F1AF9DEF
2 changed files with 23 additions and 21 deletions

View File

@ -6,11 +6,9 @@ Snappy reMarkable screen sharing over SSH.
On your **host** machine: On your **host** machine:
- Any POSIX-shell (e.g. bash) - Any POSIX-shell (e.g. bash)
- [zstd](http://www.zstd.net/)
- ffmpeg (with ffplay) - ffmpeg (with ffplay)
- ssh - ssh
On your **reMarkable**: 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.
- zstd (`opkg install zstd`)
- netcat (`opkg install netcat`)
- coreutils-head (`opkg install coreutils-head`)

View File

@ -1,40 +1,44 @@
#!/bin/sh #!/bin/sh
set -eo pipefail
ssh_host="mohowzeg.usb" ssh_host="mohowzeg.usb"
landscape=true landscape=true
bin_head="/opt/bin/head"
bin_zstd="/opt/bin/zstd"
bin_ncat="/opt/bin/netcat"
width=1408 width=1408
height=1872 height=1872
bytes_per_pixel=2 bytes_per_pixel=2
loop_wait="true"
loglevel="info"
if ! ssh "$ssh_host" true; then if ! ssh "$ssh_host" true; then
echo "$ssh_host unreachable" echo "$ssh_host unreachable"
exit 1 exit 1
fi fi
for prog in $bin_head $bin_zstd $bin_ncat; do # Gracefully degrade to gzip if zstd is not present
if ! ssh "$ssh_host" "[ -f $prog ]"; then if ssh "$ssh_host" "[ -f /opt/bin/zstd ]"; then
echo "Program $prog is not present on $ssh_host." compress="/opt/bin/zstd"
exit 1 decompress="zstd -d"
fi else
done compress="gzip"
decompress="gzip -d"
fi
window_bytes="$(($width*$height*$bytes_per_pixel))" window_bytes="$(($width*$height*$bytes_per_pixel))"
landscape_param="$($landscape && echo '-vf transpose=1')" orientation_param="$($landscape && echo '-vf transpose=1')"
read_loop="while $bin_head -c $window_bytes /dev/fb0; do sleep .03; done | $bin_zstd" 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" \ ssh "$ssh_host" "$read_loop" \
| zstd -d \ | $decompress \
| pv - \
| ffplay -vcodec rawvideo \ | ffplay -vcodec rawvideo \
-loglevel error \ -loglevel "$loglevel" \
-f rawvideo \ -f rawvideo \
-pixel_format gray16le \ -pixel_format gray16le \
-video_size "$width,$height" \ -video_size "$width,$height" \
$landscape_param \ $landscape_param \
-i - -i -