Skip to content

Commit

Permalink
xvfb.sh (#114)
Browse files Browse the repository at this point in the history
  • Loading branch information
fenollp authored Nov 2, 2021
1 parent fc05e22 commit 91e117f
Show file tree
Hide file tree
Showing 8 changed files with 117 additions and 12 deletions.
4 changes: 3 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
@@ -1,8 +1,10 @@
*
!/.bazelrc
!/BUILD
!/data/
!/resolved.bzl
!/variables.bzl
!/third_party
!/variables.bzl
!/voidstar
!/WORKSPACE
!/xvfb.sh
11 changes: 10 additions & 1 deletion .github/workflows/workflow.yml
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ jobs:
- uses: actions/checkout@v2
- run: DOCKER_BUILDKIT=1 docker build -o=./bin/ --target=voidstar . --progress=plain
- run: ./bin/voidstar --help
- uses: Wandalen/[email protected]
with:
command: DOCKER_BUILDKIT=1 docker build -o=. --target=video-gcc . --progress=plain
attempt_limit: 20
attempt_delay: 1000

build_on_ubuntu_with_clang:
name: Build on ubuntu with Clang
Expand All @@ -41,7 +46,11 @@ jobs:
- uses: actions/checkout@v2
- run: DOCKER_BUILDKIT=1 docker build -o=./bin/ --target=voidstar-clang . --progress=plain
- run: ./bin/voidstar --help

- uses: Wandalen/[email protected]
with:
command: DOCKER_BUILDKIT=1 docker build -o=. --target=video-clang . --progress=plain
attempt_limit: 20
attempt_delay: 1000

build_on_macos:
name: Build on macos
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,4 @@
/bazelisk

/bin/*
/video.webm
31 changes: 29 additions & 2 deletions Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,17 @@ RUN \
ca-certificates \
clang \
curl \
ffmpeg \
git \
gzip \
libgl1-mesa-dev \
python3 \
software-properties-common \
tar \
unzip \
xauth \
xorg-dev \
xvfb \
&& update-alternatives --install /usr/bin/python python /usr/bin/python3 1
RUN \
--mount=type=cache,target=/var/cache/apt \
Expand Down Expand Up @@ -77,8 +80,6 @@ RUN \
&& bazel build --repo_env=CC=clang voidstar \
# Necessary as COPY --from does not follow symlinks
&& cp /app/bazel-bin/voidstar/voidstar /
FROM scratch AS voidstar-clang
COPY --from=builder-clang /voidstar /

# voidstar GCC
FROM base AS builder-gcc
Expand All @@ -88,5 +89,31 @@ RUN \
&& bazel build voidstar \
# Necessary as COPY --from does not follow symlinks
&& cp /app/bazel-bin/voidstar/voidstar /


# xvfb GCC
FROM builder-gcc AS xvfb-gcc
ARG WxHxD=800x600x24
ARG BIN=/voidstar
ARG FILE=./data/BigPictureBG.tga
ARG OUT=video.webm
RUN ./xvfb.sh
FROM scratch AS video-gcc
COPY --from=xvfb-gcc /app/video.webm /

# xvfb Clang
FROM builder-clang AS xvfb-clang
ARG WxHxD=800x600x24
ARG BIN=/voidstar
ARG FILE=./data/BigPictureBG.tga
ARG OUT=video.webm
RUN ./xvfb.sh
FROM scratch AS video-clang
COPY --from=xvfb-clang /app/video.webm /


FROM scratch AS voidstar-clang
COPY --from=builder-clang /voidstar /

FROM scratch AS voidstar
COPY --from=builder-gcc /voidstar /
2 changes: 1 addition & 1 deletion snap/snapcraft.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: voidstar
version: v1.34.1 # FIXME: 'git'
version: v1.35.0 # FIXME: 'git'
summary: void* casts files onto 2D/3D colored spaces for your mind blowing needs # 79 char long summary
description: |
Usage:
Expand Down
7 changes: 5 additions & 2 deletions voidstar/managers/glfw3.cc
Original file line number Diff line number Diff line change
Expand Up @@ -229,8 +229,11 @@ bool GLFW3Manager::updateFirst(float deltaTime, glm::mat4* MVP) {
// User loaded a different file
file_changed || false) {
if (args_->move_window) slide_window_right();
bool slid = slide_window(scene_->selected(), scene_->indices());
if (!slid && args_->move_window) args_->move_window = false;
auto slid = slide_window(scene_->selected(), scene_->indices());
if (previously_slid_ != slid)
std::cout << "#selected: " << slid << std::endl;
previously_slid_ = slid;
if (slid < 1 && args_->move_window) args_->move_window = false;
}

return true;
Expand Down
9 changes: 4 additions & 5 deletions voidstar/managers/manager.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
#include "voidstar/managers/events.h"
#include "voidstar/registrar.h"
#include "voidstar/scenes/scene.h"
#include "voidstar/size2str.h"

class Manager {
public:
Expand Down Expand Up @@ -62,7 +61,8 @@ class Manager {
: args_->sliding_window_length;
}

bool slide_window(VertIndices& selected, const VertIndices& indices) {
size_t previously_slid_ = 0;
size_t slide_window(VertIndices& selected, const VertIndices& indices) {
using offset_t = VertIndices::const_iterator::difference_type;
const offset_t woffset = static_cast<offset_t>(sliding_window_offset_);
const offset_t wlength = static_cast<offset_t>(sliding_window_length_);
Expand All @@ -75,10 +75,9 @@ class Manager {
selected.assign(left, right);
sliding_window_left_ = &left[0];
sliding_window_right_ = &right[0];
std::cout << "#selected: " << size2str(selected.size()) << std::endl;
return true;
return selected.size();
}
return false;
return 0;
}

protected:
Expand Down
64 changes: 64 additions & 0 deletions xvfb.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
#!/bin/bash -eux
set -o pipefail

_kill_procs() {
kill -TERM $companion
wait $companion
kill -TERM $xvfb
}
trap _kill_procs SIGTERM

display=99

wxhxd=${WxHxD:-800x600x24}
bin=${BIN:-./bin/voidstar}
file=${FILE:-"$bin"}
out=${OUT:-video.webm}

case "$file" in
http://*|https://*)
curl -fsSLo /file "$file"
file=/file
# ls -lh "$file"; exit 42
;;*) ;;
esac

rm -rf /tmp/xvfb-run.*

xvfb-run \
--server-num="$display" \
--error-file=/dev/stdout \
-s "-screen 0 $wxhxd" \
"$bin" \
--move \
--exit-at-fin \
"$file" &
xvfb=$!

touch ~/.Xauthority
xauth generate :0 . trusted || true
xauth list

ls /tmp/xvfb*/Xauthority >/dev/null

XAUTHORITY=$(echo /tmp/xvfb*/Xauthority) \
ffmpeg \
-r 30 \
-f x11grab \
-draw_mouse 0 \
-s "$(cut -dx -f1-2 <<<"$wxhxd")" \
-i :"$display" \
-c:v libvpx \
-quality realtime \
-cpu-used 0 \
-b:v 384k \
-qmin 10 \
-qmax 42 \
-maxrate 384k \
-bufsize 1000k \
-an "$out" &
companion=$!

wait $xvfb
kill -TERM $companion
wait $companion || true

0 comments on commit 91e117f

Please sign in to comment.