Skip to content

Commit

Permalink
Merge pull request #139 from games-on-whales/fix-mdns
Browse files Browse the repository at this point in the history
Fix mDNS uncaught exception
  • Loading branch information
ABeltramo authored Oct 21, 2024
2 parents 64a3822 + c5c7dae commit c731862
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 34 deletions.
2 changes: 1 addition & 1 deletion src/moonlight-server/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,7 @@ target_link_libraries_system(wolf_runner PUBLIC simple-web-server)
# mDNS
FetchContent_Declare(
mdns_cpp
GIT_REPOSITORY https://github.com/gocarlos/mdns_cpp.git)
GIT_REPOSITORY https://github.com/games-on-whales/mdns_cpp.git)
FetchContent_MakeAvailable(mdns_cpp)
target_link_libraries_system(wolf_runner PUBLIC mdns_cpp::mdns_cpp)

Expand Down
65 changes: 45 additions & 20 deletions src/moonlight-server/state/default/config.include.toml
Original file line number Diff line number Diff line change
Expand Up @@ -120,9 +120,37 @@ base_create_json = """
\
"""

[[apps]]
title = "Lutris"
start_virtual_compositor = true

[apps.runner]
type = "docker"
name = "WolfLutris"
image = "ghcr.io/games-on-whales/lutris:edge"
mounts = ["lutris:/var/lutris/:rw"]
env = [
"RUN_SWAY=1",
"GOW_REQUIRED_DEVICES=/dev/input/event* /dev/dri/* /dev/nvidia* /var/lutris/",
]
devices = []
ports = []
base_create_json = """
{
"HostConfig": {
"IpcMode": "host",
"CapAdd": ["NET_RAW", "MKNOD", "NET_ADMIN", "SYS_ADMIN", "SYS_NICE"],
"Privileged": false,
"DeviceCgroupRules": ["c 13:* rmw", "c 244:* rmw"]
}
}
\
"""

[[apps]]
title = "Test ball"
start_virtual_compositor = false
start_audio_server = false

[apps.runner]
type = "process"
Expand All @@ -144,7 +172,7 @@ source = "audiotestsrc wave=ticks is-live=true"

[gstreamer.video]

default_source = "appsrc name=wolf_wayland_source is-live=true block=false format=3 stream-type=0"
default_source = "interpipesrc listen-to={session_id}_video is-live=true stream-sync=restart-ts max-bytes=0 max-buffers=3 block=false"
default_sink = """
rtpmoonlightpay_video name=moonlight_pay \
payload_size={payload_size} fec_percentage={fec_percentage} min_required_fec_packets={min_required_fec_packets} !
Expand All @@ -166,14 +194,14 @@ chroma-site={color_range}, format=NV12, colorimetry={color_space}, pixel-aspect-
[gstreamer.video.defaults.qsv]
video_params = """
queue !
videoconvert !
videoconvertscale !
video/x-raw, chroma-site={color_range}, width={width}, height={height}, format=NV12, colorimetry={color_space}\
"""

[gstreamer.video.defaults.vaapi]
video_params = """
queue !
videoconvert !
videoconvertscale !
video/x-raw, chroma-site={color_range}, width={width}, height={height}, format=NV12, colorimetry={color_space}\
"""

Expand All @@ -192,7 +220,7 @@ video/x-h265, profile=main, stream-format=byte-stream\

[[gstreamer.video.hevc_encoders]]
plugin_name = "qsv"
check_elements = ["qsvh265enc", "videoconvert"]
check_elements = ["qsvh265enc", "videoconvertscale"]
encoder_pipeline = """
qsvh265enc b-frames=0 gop-size=0 idr-interval=1 ref-frames=1 bitrate={bitrate} rate-control=cbr low-latency=1 target-usage=6 !
h265parse !
Expand All @@ -201,7 +229,7 @@ video/x-h265, profile=main, stream-format=byte-stream\

[[gstreamer.video.hevc_encoders]]
plugin_name = "vaapi"
check_elements = ["vah265lpenc", "videoconvert"] # lp: (Low Power)
check_elements = ["vah265lpenc", "videoconvertscale"] # lp: (Low Power)
encoder_pipeline = """
vah265lpenc aud=false b-frames=0 ref-frames=1 num-slices={slices_per_frame} bitrate={bitrate} mbbrc=1 rate-control=cbr target-usage=6 !
h265parse !
Expand All @@ -210,7 +238,7 @@ video/x-h265, profile=main, stream-format=byte-stream\

[[gstreamer.video.hevc_encoders]]
plugin_name = "vaapi"
check_elements = ["vah265enc", "videoconvert"]
check_elements = ["vah265enc", "videoconvertscale"]
encoder_pipeline = """
vah265enc aud=false b-frames=0 ref-frames=1 num-slices={slices_per_frame} bitrate={bitrate} mbbrc=1 rate-control=cbr target-usage=6 !
h265parse !
Expand All @@ -221,8 +249,7 @@ video/x-h265, profile=main, stream-format=byte-stream\
plugin_name = "x265" # SW Encoding
check_elements = ["x265enc"]
video_params = """
videoscale !
videoconvert !
videoconvertscale !
videorate !
video/x-raw, width={width}, height={height}, framerate={fps}/1, format=I420,
chroma-site={color_range}, colorimetry={color_space}\
Expand All @@ -249,7 +276,7 @@ video/x-h264, profile=main, stream-format=byte-stream\

[[gstreamer.video.h264_encoders]]
plugin_name = "qsv"
check_elements = ["qsvh264enc", "videoconvert"]
check_elements = ["qsvh264enc", "videoconvertscale"]
encoder_pipeline = """
qsvh264enc b-frames=0 gop-size=0 idr-interval=1 ref-frames=1 bitrate={bitrate} rate-control=cbr target-usage=6 !
h264parse !
Expand All @@ -258,7 +285,7 @@ video/x-h264, profile=main, stream-format=byte-stream\

[[gstreamer.video.h264_encoders]]
plugin_name = "vaapi"
check_elements = ["vah264lpenc", "videoconvert"] # lp: (Low Power)
check_elements = ["vah264lpenc", "videoconvertscale"] # lp: (Low Power)
encoder_pipeline = """
vah264lpenc aud=false b-frames=0 ref-frames=1 num-slices={slices_per_frame} bitrate={bitrate} target-usage=6 !
h264parse !
Expand All @@ -267,7 +294,7 @@ video/x-h264, profile=main, stream-format=byte-stream\

[[gstreamer.video.h264_encoders]]
plugin_name = "vaapi"
check_elements = ["vah264enc", "videoconvert"]
check_elements = ["vah264enc", "videoconvertscale"]
encoder_pipeline = """
vah264enc aud=false b-frames=0 ref-frames=1 num-slices={slices_per_frame} bitrate={bitrate} target-usage=6 !
h264parse !
Expand All @@ -278,8 +305,7 @@ video/x-h264, profile=main, stream-format=byte-stream\
plugin_name = "x264" # SW Encoding
check_elements = ["x264enc"]
video_params = """
videoscale !
videoconvert !
videoconvertscale !
videorate !
video/x-raw, width={width}, height={height}, framerate={fps}/1, format=I420,
chroma-site={color_range}, colorimetry={color_space}\
Expand All @@ -305,7 +331,7 @@ video/x-av1, stream-format=obu-stream, alignment=frame, profile=main\

[[gstreamer.video.av1_encoders]]
plugin_name = "qsv"
check_elements = ["qsvav1enc", "videoconvert"]
check_elements = ["qsvav1enc", "videoconvertscale"]
encoder_pipeline = """
qsvav1enc gop-size=0 ref-frames=1 bitrate={bitrate} rate-control=cbr low-latency=1 target-usage=6 !
av1parse !
Expand All @@ -314,7 +340,7 @@ video/x-av1, stream-format=obu-stream, alignment=frame, profile=main\

[[gstreamer.video.av1_encoders]]
plugin_name = "vaapi"
check_elements = ["vaav1enc", "videoconvert"]
check_elements = ["vaav1enc", "videoconvertscale"]
encoder_pipeline = """
vaav1enc gop-size=0 ref-frames=1 bitrate={bitrate} rate-control=cbr !
av1parse !
Expand All @@ -323,7 +349,7 @@ video/x-av1, stream-format=obu-stream, alignment=frame, profile=main\

[[gstreamer.video.av1_encoders]]
plugin_name = "vaapi"
check_elements = ["vaav1lpenc", "videoconvert"] # LP = Low Power
check_elements = ["vaav1lpenc", "videoconvertscale"] # LP = Low Power
encoder_pipeline = """
vaav1lpenc gop-size=0 ref-frames=1 bitrate={bitrate} rate-control=cbr !
av1parse !
Expand All @@ -334,8 +360,7 @@ video/x-av1, stream-format=obu-stream, alignment=frame, profile=main\
plugin_name = "aom"
check_elements = ["av1enc"]
video_params = """
videoscale !
videoconvert !
videoconvertscale !
videorate !
video/x-raw, width={width}, height={height}, framerate={fps}/1, format=I420,
chroma-site={color_range}, colorimetry={color_space}\
Expand All @@ -351,10 +376,10 @@ video/x-av1, stream-format=obu-stream, alignment=frame, profile=main\
###
[gstreamer.audio]
default_source = """
pulsesrc device="{sink_name}" server="{server_name}"\
interpipesrc listen-to={session_id}_audio is-live=true stream-sync=restart-ts max-bytes=0 max-buffers=3 block=false\
"""

default_audio_params = "audio/x-raw, channels={channels}, rate=48000"
default_audio_params = "queue max-size-buffers=3 leaky=downstream ! audiorate ! audioconvert"

default_opus_encoder = """
opusenc bitrate={bitrate} bitrate-type=cbr frame-size={packet_duration} bandwidth=fullband \
Expand Down
29 changes: 16 additions & 13 deletions src/moonlight-server/wolf.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -501,19 +501,22 @@ void run() {
std::thread([local_state]() { wolf::api::start_server(local_state); }).detach();

// mDNS
try {
mdns_cpp::Logger::setLoggerSink([](const std::string &msg) {
// msg here will include a /n at the end, so we remove it
logs::log(logs::trace, "mDNS: {}", msg.substr(0, msg.size() - 1));
});
mdns_cpp::mDNS mdns;
mdns.setServiceName("_nvstream._tcp.local.");
mdns.setServiceHostname(local_state->config->hostname);
mdns.setServicePort(state::HTTP_PORT);
mdns.startService();
} catch (const std::exception &e) {
logs::log(logs::error, "mDNS error: {}", e.what());
}
std::thread([hostname = local_state->config->hostname]() {
logs::log(logs::info, "Starting mDNS service");
try {
mdns_cpp::Logger::setLoggerSink([](const std::string &msg) {
// msg here will include a /n at the end, so we remove it
logs::log(logs::trace, "mDNS: {}", msg.substr(0, msg.size() - 1));
});
mdns_cpp::mDNS mdns;
mdns.setServiceName("_nvstream._tcp.local.");
mdns.setServiceHostname(hostname);
mdns.setServicePort(state::HTTP_PORT);
mdns.startService(false);
} catch (const std::exception &e) {
logs::log(logs::error, "mDNS error: {}", e.what());
}
}).detach();

auto audio_server = setup_audio_server(runtime_dir);
auto sess_handlers = setup_sessions_handlers(local_state, runtime_dir, audio_server);
Expand Down

0 comments on commit c731862

Please sign in to comment.