From f2339915971c2e9363da9a78bc67810ac678595b Mon Sep 17 00:00:00 2001 From: "Josh.5" Date: Thu, 6 Oct 2022 22:38:45 +1300 Subject: [PATCH] Add default sunshine config on startup if missing --- overlay/templates/sunshine/apps.json | 15 ++ overlay/templates/sunshine/sunshine.conf | 286 +++++++++++++++++++++++ overlay/usr/bin/start-sunshine.sh | 10 +- 3 files changed, 310 insertions(+), 1 deletion(-) create mode 100644 overlay/templates/sunshine/apps.json create mode 100644 overlay/templates/sunshine/sunshine.conf diff --git a/overlay/templates/sunshine/apps.json b/overlay/templates/sunshine/apps.json new file mode 100644 index 0000000..3674686 --- /dev/null +++ b/overlay/templates/sunshine/apps.json @@ -0,0 +1,15 @@ +{ + "env": { + "PATH": "$(PATH):$(HOME)\/.local\/bin" + }, + "apps": [ + { + "name": "Steam BigPicture", + "output": "steam.txt", + "cmd": "", + "detached": [ + "\/usr\/games\/steam steam:\/\/open\/bigpicture" + ] + } + ] +} \ No newline at end of file diff --git a/overlay/templates/sunshine/sunshine.conf b/overlay/templates/sunshine/sunshine.conf new file mode 100644 index 0000000..cf00432 --- /dev/null +++ b/overlay/templates/sunshine/sunshine.conf @@ -0,0 +1,286 @@ +# If no external IP address is given, Sunshine will attempt to automatically detect external ip-address +# external_ip = 123.456.789.12 + +# Set the familly of ports used by Sunshine +# port = 47989 + +# The private key must be 2048 bits +# pkey = /dir/pkey.pem + +# The certificate must be signed with a 2048 bit key +# cert = /dir/cert.pem + +# The name displayed by Moonlight +# If not specified, the PC's hostname is used +# sunshine_name = Sunshine + +# The minimum log level printed to standard out +# +# none -> no logs are printed to standard out +# +# verbose = [0] +# debug = [1] +# info = [2] +# warning = [3] +# error = [4] +# fatal = [5] +# none = [6] +# +min_log_level = info + +# The origin of the remote endpoint address that is not denied for HTTP method /pin +# Could be any of the following values: +# pc|lan|wan +# pc: Only localhost may access /pin +# lan: Only those in LAN may access /pin +# wan: Anyone may access /pin +# +# origin_pin_allowed = pc + +# The origin of the remote endpoint address that is not denied for HTTPS Web UI +# Could be any of the following values: +# pc|lan|wan +# pc: Only localhost may access the Web Manager +# lan: Only those in LAN may access the Web Manager +# wan: Anyone may access the Web Manager +# +# origin_web_ui_allowed = lan + +# If UPnP is enabled, Sunshine will attempt to open ports for streaming over the internet +# To enable it, uncomment the following line: +# upnp = on + +# The file where current state of Sunshine is stored +file_state = /home/default/sunshine_state.json + +# The file where user credentials for the UI are stored +# By default, credentials are stored in `file_state` +# credentials_file = sunshine_state.json + +# The display modes advertised by Sunshine +# +# Some versions of Moonlight, such as Moonlight-nx (Switch), +# rely on this list to ensure that the requested resolutions and fps +# are supported. +# +# fps = [10, 30, 60, 90, 120] +# resolutions = [ +# 352x240, +# 480x360, +# 858x480, +# 1280x720, +# 1920x1080, +# 2560x1080, +# 3440x1440, +# 1920x1200, +# 3860x2160, +# 3840x1600, +# ] + +# Sometimes it may be usefull to map keybindings. +# Wayland won't allow clients to capture the Win Key for example +# +# See https://docs.microsoft.com/en-us/windows/win32/inputdev/virtual-key-codes +# +# Note: +# keybindings needs to have a multiple of two elements +# keybindings = [ +# 0x10, 0xA0, +# 0x11, 0xA2, +# 0x12, 0xA4, +# 0x4A, 0x4B +# ] + +# How long to wait in milliseconds for data from moonlight before shutting down the stream +# ping_timeout = 10000 + +# The file where configuration for the different applications that Sunshine can run during a stream +file_apps = /home/default/sunshine/apps.json + +# Percentage of error correcting packets per data packet in each video frame +# Higher values can correct for more network packet loss, but at the cost of increasing bandwidth usage +# The default value of 20 is what GeForce Experience uses +# +# The value must be greater than 0 and lower than or equal to 255 +# fec_percentage = 20 + +# When multicasting, it could be usefull to have different configurations for each connected Client. +# For example: +# Clients connected through WAN and LAN have different bitrate contstraints. +# Decoders may require different settings for color +# +# Unlike simply broadcasting to multiple Client, this will generate distinct video streams. +# Note, CPU usage increases for each distinct video stream generated +# channels = 1 + +# The back/select button on the controller +# On the Shield, the home and powerbutton are not passed to Moonlight +# If, after the timeout, the back button is still pressed down, Home/Guide button press is emulated. +# If back_button_timeout < 0, then the Home/Guide button will not be emulated +# back_button_timeout = 2000 + +# !! Windows only !! +# Gamepads supported by Sunshine +# Possible values: +# x360 -- xbox 360 controller +# ds4 -- dualshock controller (PS4) +# gamepad = x360 + +# Control how fast keys will repeat themselves +# The initial delay in milliseconds before repeating keys +# key_repeat_delay = 500 +# +# How often keys repeat every second +# This configurable option supports decimals +# key_repeat_frequency = 24.9 + +# The name of the audio sink used for Audio Loopback +# If you do not specify this variable, pulseaudio will select the default monitor device. +# +# You can find the name of the audio sink using the following command: +# !! Linux only !! +# pacmd list-sinks | grep "name:" if running vanilla pulseaudio +# pPipewire: Use `pactl info | grep Source`. In some causes you'd need to use the `sink` device. Try `pactl info | grep Sink`, if _Source_ doesn't work +# audio_sink = alsa_output.pci-0000_09_00.3.analog-stereo +# +# !! Windows only !! +# tools\audio-info.exe +# audio_sink = {0.0.0.00000000}.{FD47D9CC-4218-4135-9CE2-0C195C87405B} +# +# The virtual sink, is the audio device that's virtual (Like Steam Streaming Speakers), it allows Sunshine +# to stream audio, while muting the speakers. +# virtual_sink = {0.0.0.00000000}.{8edba70c-1125-467c-b89c-15da389bc1d4} + +# !! Windows only !! +# You can select the video card you want to stream: +# The appropriate values can be found using the following command: +# tools\dxgi-info.exe +# adapter_name = Radeon RX 580 Series +# output_name = \\.\DISPLAY1 + +# !! Linux only !! +# Set the display number to stream. +# You can find them by the following command: +# xrandr --listmonitors +# Example output: "0: +HDMI-1 1920/518x1200/324+0+0 HDMI-1" +# ^ <-- You need this. +# output_name = 0 + +############################################### +# FFmpeg software encoding parameters +# Honestly, I have no idea what the optimal values would be. +# Play around with this :) + +# Quantitization Parameter +# Some devices don't support Constant Bit Rate. For those devices, QP is used instead +# Higher value means more compression, but less quality +# qp = 28 + +# Minimum number of threads used by ffmpeg to encode the video. +# Increasing the value slightly reduces encoding efficiency, but the tradeoff is usually +# worth it to gain the use of more CPU cores for encoding. The ideal value is the lowest +# value that can reliably encode at your desired streaming settings on your hardware. +# min_threads = 1 + +# Allows the client to request HEVC Main or HEVC Main10 video streams. +# HEVC is more CPU-intensive to encode, so enabling this may reduce performance when using software encoding. +# If set to 0 (default), Sunshine will specify support for HEVC based on encoder +# If set to 1, Sunshine will not advertise support for HEVC +# If set to 2, Sunshine will advertise support for HEVC Main profile +# If set to 3, Sunshine will advertise support for HEVC Main and Main10 (HDR) profiles +# hevc_mode = 2 + +# Force a specific encoder, otherwise Sunshine will use the first encoder that is available +# supported encoders: +# nvenc +# amdvce # NOTE: alpha stage. The cursor is not yet displayed +# software +# +# encoder = software +##################################### Software ##################################### +# See x264 --fullhelp for the different presets +# sw_preset = superfast +# sw_tune = zerolatency +# + +##################################### NVENC ##################################### +###### presets ########### +# default +# hp -- high performance +# hq -- high quality +# slow -- hq 2 passes +# medium -- hq 1 pass +# fast -- hp 1 pass +# bd +# ll -- low latency +# llhq +# llhp +# lossless +# losslesshp +########################## +# nv_preset = llhq +# +####### rate control ##### +# auto -- let ffmpeg decide rate control +# constqp -- constant QP mode +# vbr -- variable bitrate +# cbr -- constant bitrate +# cbr_hq -- cbr high quality +# cbr_ld_hq -- cbr low delay high quality +# vbr_hq -- vbr high quality +########################## +# nv_rc = auto + +###### h264 entropy ###### +# auto -- let ffmpeg nvenc decide the entropy encoding +# cabac +# cavlc +########################## +# nv_coder = auto + +##################################### AMD ##################################### +###### presets ########### +# default +# speed +# balanced +########################## +# amd_preset = balanced +# +####### rate control ##### +# auto -- let ffmpeg decide rate control +# constqp -- constant QP mode +# vbr_latency -- Latency Constrained Variable Bitrate +# vbr_peak -- Peak Contrained Variable Bitrate +# cbr -- constant bitrate +########################## +# amd_rc = auto + +###### h264 entropy ###### +# auto -- let ffmpeg nvenc decide the entropy encoding +# cabac +# cavlc +########################## +# amd_coder = auto + +#################################### VAAPI ################################### +####### adapter ########## +# Unlike with `amdvce` and `nvenc`, it doesn't matter if video encoding is done +# on a different GPU. +# Run the following commands: +# 1. ls /dev/dri/renderD* +# to find all devices capable of VAAPI +# 2. vainfo --display drm --device /dev/dri/renderD129 | grep -E "((VAProfileH264High|VAProfileHEVCMain|VAProfileHEVCMain10).*VAEntrypointEncSlice)|Driver version" +# Lists the name and capabilities of the device. +# To be supported by Sunshine, it needs to have at the very minimum: +# VAProfileH264High : VAEntrypointEncSlice +# adapter_name = /dev/dri/renderD128 + +############################################## +# Some configurable parameters, are merely toggles for specific features +# The first occurrence turns it on, the second occurence turns it off, the third occurence turns it on again, etc, etc +# Here, you change the default state of any flag +# +# To set the initial state of flags -0 and -1 to on, set the following flags: +# flags = 012 +# +# See: sunshine --help for all options under the header: flags \ No newline at end of file diff --git a/overlay/usr/bin/start-sunshine.sh b/overlay/usr/bin/start-sunshine.sh index 25c6b3f..a301042 100755 --- a/overlay/usr/bin/start-sunshine.sh +++ b/overlay/usr/bin/start-sunshine.sh @@ -19,7 +19,15 @@ trap _term SIGTERM SIGINT # CONFIGURE: -# TODO: Install default configurations +# Install default configurations +mkdir -p /home/${USER}/sunshine +if [[ ! -f /home/${USER}/sunshine/sunshine.conf ]]; then + cp -vf /templates/sunshine/* /home/${USER}/sunshine/ + # TODO: Set the default encoder '# encoder = nvenc' + # TODO: Enable the vaapi device if not using nvenc + # vainfo --display drm --device /dev/dri/renderD128 2> /dev/null | grep -E "((VAProfileH264High|VAProfileHEVCMain|VAProfileHEVCMain10).*VAEntrypointEncSlice)" +fi + # Reset the default username/password if ([ "X${SUNSHINE_USER:-}" != "X" ] && [ "X${SUNSHINE_PASS:-}" != "X" ]); then sunshine /home/${USER}/sunshine/sunshine.conf --creds ${SUNSHINE_USER:-} ${SUNSHINE_PASS:-}