Skip to content
This repository has been archived by the owner on Jun 5, 2024. It is now read-only.

[MAJOR] Add Go Server for Game Streaming in Watch Party #79

Open
wants to merge 29 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
40b0f4b
[MAJOR]Add Go Server for Game Streaming in Watch Party
wanjohiryan Jun 16, 2023
707b0ab
go mod tidy
wanjohiryan Jun 16, 2023
b6d2d1e
Add arc3dia to entrypoint
wanjohiryan Jun 18, 2023
689e3c4
Fix typing
wanjohiryan Jun 19, 2023
40c3de0
Fix go imports
wanjohiryan Jun 19, 2023
dfb968b
Move steamcmd script to its own dir
wanjohiryan Jun 19, 2023
350943c
Fix 2
wanjohiryan Jun 19, 2023
e70f92f
change arc3dia to warp
wanjohiryan Jun 19, 2023
d4cb950
testing
wanjohiryan Jun 19, 2023
c054e99
Found the bug: .gitignore removes ``internal`` dir
wanjohiryan Jun 19, 2023
b70d191
Change the color coding for logger.sh
wanjohiryan Jun 24, 2023
9d3b7c8
Fix info ANSI colors
wanjohiryan Jun 24, 2023
cb31bd7
Wait for 2 seconds for arc3dia to start
wanjohiryan Jun 24, 2023
b3b579b
Install wine and winetricks
wanjohiryan Jun 24, 2023
8c3dc2d
Fix some warp code
wanjohiryan Jun 24, 2023
beac19e
Add ``software-properties-common``
wanjohiryan Jun 24, 2023
280da84
Fix ``dockerd`` startup issue
wanjohiryan Jun 24, 2023
ce0324a
Fix ``dockerd`` startup error #2
wanjohiryan Jun 24, 2023
32a1ba6
Isntall ffmpeg6
wanjohiryan Jun 24, 2023
af1e9c9
Downgrade to ffmpeg5
wanjohiryan Jun 24, 2023
ebf9544
Fix 1 for ffmpeg installation
wanjohiryan Jun 24, 2023
699cc54
Fix 2
wanjohiryan Jun 24, 2023
b787d58
Fix 3
wanjohiryan Jun 24, 2023
1113bfe
Install ffmpeg 2
wanjohiryan Jun 24, 2023
1e7d7db
Parent arguments :(
wanjohiryan Jun 24, 2023
e89e73d
ffmpeg install
wanjohiryan Jun 24, 2023
43613ac
Get ffmpeg from new source
wanjohiryan Jun 24, 2023
143c4df
Add ffmpeg.sh
wanjohiryan Jun 25, 2023
80957a6
i don't remember
wanjohiryan Aug 2, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 4 additions & 3 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,10 @@ logs/
core
.build

# Test directory
tests/
test/

# Runtime data
pids
*.pid
Expand All @@ -35,8 +39,5 @@ node_modules
dist
bin

#not on this branch
internal

# Environment files
*.env
38 changes: 30 additions & 8 deletions docker/nvidia/Dockerfile
Original file line number Diff line number Diff line change
@@ -1,8 +1,7 @@
#! Some code was copied or inspired by https://github.com/ehfd/nvidia-dind/blob/main/Dockerfile
# Which is licensed under MPL-2.0 license
# Thanks ehfd :)
ARG UBUNTU_RELEASE=22.04
FROM ubuntu:${UBUNTU_RELEASE}
FROM ghcr.io/wanjohiryan/ffmpeg/v6:nightly

ARG DEBIAN_FRONTEND=noninteractive

Expand All @@ -14,7 +13,7 @@ RUN echo steam steam/question select "I AGREE" | debconf-set-selections \
#
#Install essential libraries
RUN dpkg --add-architecture i386 && apt-get update -y && apt-get install -y --no-install-recommends \
apt-utils ca-certificates openssh-client vim wget \
apt-utils ca-certificates openssh-client vim wget software-properties-common\
curl iptables git gnupg sudo locales\
#SteamCMD
steamcmd; \
Expand All @@ -28,6 +27,27 @@ RUN locale-gen en_US.UTF-8;\
ln -s /usr/games/steamcmd /usr/bin/steamcmd;\
steamcmd +quit

#
#Install wine
ARG WINE_BRANCH="staging"
RUN wget -nv -O- https://dl.winehq.org/wine-builds/winehq.key | APT_KEY_DONT_WARN_ON_DANGEROUS_USAGE=1 apt-key add - \
&& apt-add-repository "deb https://dl.winehq.org/wine-builds/ubuntu/ $(grep VERSION_CODENAME= /etc/os-release | cut -d= -f2) main" \
&& dpkg --add-architecture i386 \
&& apt-get update \
&& DEBIAN_FRONTEND="noninteractive" apt-get install -y --install-recommends winehq-${WINE_BRANCH} \
&& rm -rf /var/lib/apt/lists/*

#
#Install gecko and mono installers
COPY docker/nvidia/download_gecko_and_mono.sh /root/download_gecko_and_mono.sh
RUN chmod +x /root/download_gecko_and_mono.sh \
&& /root/download_gecko_and_mono.sh "$(dpkg -s wine-${WINE_BRANCH} | grep "^Version:\s" | awk '{print $2}' | sed -E 's/~.*$//')"

#
# Install winetricks
RUN wget -nv -O /usr/bin/winetricks https://raw.githubusercontent.com/Winetricks/winetricks/master/src/winetricks \
&& chmod +x /usr/bin/winetricks

#
# NVIDIA Container Toolkit & Docker
RUN distribution=$(. /etc/os-release;echo $ID$VERSION_ID); \
Expand All @@ -54,19 +74,20 @@ RUN groupadd --gid ${USER_GID} ${USERNAME}; \

#
#Copy files
COPY docker/nvidia/modprobe docker/nvidia/entrypoint.sh /usr/local/bin/
COPY docker/nvidia/modprobe docker/nvidia/ffmpeg.sh docker/nvidia/entrypoint.sh docker/nvidia/dockerd.sh /usr/local/bin/
COPY docker/nvidia/logger.sh /opt/bash-utils/logger.sh
COPY ./arc3dia /usr/local/bin/

#
#Add execution permissions
RUN chmod +x /usr/local/bin/entrypoint.sh /usr/local/bin/modprobe
RUN chmod +x /usr/local/bin/entrypoint.sh /usr/local/bin/dockerd.sh /usr/local/bin/modprobe /usr/local/bin/arc3dia /usr/local/bin/ffmpeg.sh

#
#Install tini https://github.com/krallin/tini
ARG TINI_VERSION=v0.19.0
ADD https://github.com/krallin/tini/releases/download/${TINI_VERSION}/tini /usr/bin/tini
RUN chmod +x /usr/bin/tini
ENTRYPOINT [ "/usr/bin/tini","--", "/usr/local/bin/entrypoint.sh" ]
ENTRYPOINT [ "/usr/bin/tini","--", "/usr/local/bin/dockerd.sh" ]

#
#Add env variables
Expand All @@ -77,11 +98,12 @@ ENV LANGUAGE 'en_US:en'
#
#volume for mounting
#1.preinstalled game #2. config file #3. game data for persisting games
VOLUME [ "/game", "/arc3dia", "/data" ]
#directories /certs and /media are for testing only
VOLUME [ "/game", "/arc3dia", "/data", "/certs", "/media" ]

#
#Run the bash shell as a non-root user
USER ${USERNAME}
WORKDIR /home/${USERNAME}

CMD ["sh"]
CMD ["/usr/local/bin/entrypoint.sh"]
37 changes: 37 additions & 0 deletions docker/nvidia/dockerd.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
#!/bin/bash
source /opt/bash-utils/logger.sh

function wait_for_process () {
local max_time_wait=30
local process_name="$1"
local waited_sec=0
while ! pgrep "$process_name" >/dev/null && ((waited_sec < max_time_wait)); do
INFO "Process $process_name is not running yet. Retrying in 1 seconds"
INFO "Waited $waited_sec seconds of $max_time_wait seconds"
sleep 1
((waited_sec=waited_sec+1))
if ((waited_sec >= max_time_wait)); then
return 1
fi
done
return 0
}

INFO "Starting dockerd"
sudo /usr/bin/dockerd -d >> /dev/null 2>&1 &

INFO "Waiting for processes to be running"
processes=(dockerd)

for process in "${processes[@]}"; do
wait_for_process "$process"
if [ $? -ne 0 ]; then
ERROR "$process is not running after max time"
exit 1
else
INFO "$process is running"
fi
done

# Wait processes to be running
"$@"
44 changes: 44 additions & 0 deletions docker/nvidia/download_gecko_and_mono.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
#!/usr/bin/env bash

# Scrapes the Wine source code for versions of mono and gecko to download for a given version of Wine

get_hrefs () {
local url="$1"
local regexp="$2"

wget -q -O- "${url}" | sed -E "s/></>\n</g" | sed -n -E "s|^.*<a href=\"(${regexp})\">.*|\1|p" | uniq
}

get_app_ver () {
local app="${1^^}" # Convert to uppercase
local url="https://raw.githubusercontent.com/wine-mirror/wine/wine-${WINE_VER}/dlls/appwiz.cpl/addons.c"

wget -q -O- "${url}" | grep -E "^#define ${app}_VERSION\s" | awk -F\" '{print $2}'
}


WINE_VER="$1"

if [ -z "${WINE_VER}" ]; then
echo "Please specify the version of wine that requires gecko and mono installers"
echo "e.g."
echo " $0 5.0.1"
exit 1
fi

for APP in "gecko" "mono"; do

# Get the pkg version required from wine source code
APP_VER=$(get_app_ver "${APP}")

# Get the list of files to download
APP_URL="http://dl.winehq.org/wine/wine-${APP}/${APP_VER}/"
mapfile -t FILES < <(get_hrefs "${APP_URL}" ".*\.msi")

# Download the files
[ ! -d "/usr/share/wine/${APP}" ] && mkdir -p "/usr/share/wine/${APP}"
for FILE in "${FILES[@]}"; do
echo "Downloading '${FILE}'"
wget -nv -O "/usr/share/wine/${APP}/${FILE}" "${APP_URL}${FILE}"
done
done
40 changes: 10 additions & 30 deletions docker/nvidia/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -1,37 +1,17 @@
#!/bin/bash
source /opt/bash-utils/logger.sh

function wait_for_process () {
local max_time_wait=30
local process_name="$1"
local waited_sec=0
while ! pgrep "$process_name" >/dev/null && ((waited_sec < max_time_wait)); do
INFO "Process $process_name is not running yet. Retrying in 1 seconds"
INFO "Waited $waited_sec seconds of $max_time_wait seconds"
sleep 1
((waited_sec=waited_sec+1))
if ((waited_sec >= max_time_wait)); then
return 1
fi
done
return 0
}
INFO "Starting ffmpeg"
/usr/local/bin/ffmpeg.sh &
sleep 10

INFO "Starting supervisor"
/usr/bin/dockerd -d >> /dev/null 2>&1 &
INFO "Starting arc3dia server" #FIXME: this is for testing purposes only #-cert /certs/cert.crt -key /certs/private.key -dash /media/playlist.mpd
/usr/local/bin/arc3dia -key /certs/key.pem -cert /certs/cert.pem -dash /media/playlist.mpd 2>&1 &
sleep 5

INFO "Waiting for processes to be running"
processes=(dockerd)
wait -n

for process in "${processes[@]}"; do
wait_for_process "$process"
if [ $? -ne 0 ]; then
ERROR "$process is not running after max time"
exit 1
else
INFO "$process is running"
fi
done
jobs -p | xargs --no-run-if-empty kill
wait

# Wait processes to be running
"$@"
exit
18 changes: 18 additions & 0 deletions docker/nvidia/ffmpeg.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
#!/bin/bash
ffmpeg -i /media/source.mp4 \
-f dash -ldash 1 \
-c:v libx264 \
-preset veryfast -tune zerolatency \
-c:a aac \
-b:a 128k -ac 2 -ar 44100 \
-map v:0 -s:v:0 1280x720 -b:v:0 3M \
-map v:0 -s:v:1 854x480 -b:v:1 1.1M \
-map v:0 -s:v:2 640x360 -b:v:2 365k \
-map 0:a \
-force_key_frames "expr:gte(t,n_forced*2)" \
-sc_threshold 0 \
-streaming 1 \
-use_timeline 0 \
-seg_duration 2 -frag_duration 0.01 \
-frag_type duration \
/media/playlist.mpd
4 changes: 2 additions & 2 deletions docker/nvidia/logger.sh
Original file line number Diff line number Diff line change
Expand Up @@ -12,12 +12,12 @@ function DEBUG(){
local function_name="${FUNCNAME[1]}"
local msg="$1"
timeAndDate=`date`
echo "[$timeAndDate] [DEBUG] [${0}] $msg"
echo "\033[01;33m[$timeAndDate] [DEBUG] [${0}] $msg\033[0m"
}

function ERROR(){
local function_name="${FUNCNAME[1]}"
local msg="$1"
timeAndDate=`date`
echo "[$timeAndDate] [ERROR] $msg"
echo "\033[01;31m[$timeAndDate] [ERROR] $msg033[0m"
}
29 changes: 28 additions & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,3 +1,30 @@
module github.com/wanjohiryan/Arc3dia

go 1.19
go 1.18

require (
github.com/abema/go-mp4 v0.7.2
github.com/kixelated/invoker v1.0.0
github.com/kixelated/quic-go v1.31.0
github.com/kixelated/webtransport-go v1.4.1
github.com/zencoder/go-dash/v3 v3.0.2
)

require (
github.com/francoispqt/gojay v1.2.13 // indirect
github.com/go-task/slim-sprig v0.0.0-20210107165309-348f09dbbbc0 // indirect
github.com/golang/mock v1.6.0 // indirect
github.com/google/pprof v0.0.0-20210407192527-94a9f03dee38 // indirect
github.com/google/uuid v1.1.2 // indirect
github.com/marten-seemann/qpack v0.3.0 // indirect
github.com/marten-seemann/qtls-go1-18 v0.1.3 // indirect
github.com/marten-seemann/qtls-go1-19 v0.1.1 // indirect
github.com/onsi/ginkgo/v2 v2.2.0 // indirect
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519 // indirect
golang.org/x/exp v0.0.0-20220722155223-a9213eeb770e // indirect
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4 // indirect
golang.org/x/net v0.0.0-20220722155237-a158d28d115b // indirect
golang.org/x/sys v0.1.1-0.20221102194838-fc697a31fa06 // indirect
golang.org/x/text v0.3.7 // indirect
golang.org/x/tools v0.1.12 // indirect
)
Loading