Skip to content

Commit

Permalink
tools: use SDL2_net for networking
Browse files Browse the repository at this point in the history
Also makes SDL2 mandatory for the tools.
  • Loading branch information
mbouron committed May 14, 2024
1 parent 4c67e0f commit 2e76cbd
Show file tree
Hide file tree
Showing 14 changed files with 142 additions and 202 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/ci_coverage.yml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ jobs:
- name: Install dependencies
run: |
sudo apt -y update
sudo apt -y install libsdl2-dev libva-dev python3-venv gcovr spirv-tools glslang-dev libvulkan-dev mesa-vulkan-drivers vulkan-validationlayers
sudo apt -y install libsdl2-dev libsdl2-net-dev libva-dev python3-venv gcovr spirv-tools glslang-dev libvulkan-dev mesa-vulkan-drivers vulkan-validationlayers
sudo apt -y install ffmpeg libavcodec-dev libavutil-dev libavformat-dev libavdevice-dev libavfilter-dev libswscale-dev libswresample-dev libpostproc-dev
sudo apt -y install libfreetype-dev libharfbuzz-dev libfribidi-dev
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_coverity.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:
#
# apt-get install python3-venv
#
sudo apt -y install libsdl2-dev libva-dev python3-venv valgrind spirv-tools glslang-dev libvulkan-dev mesa-vulkan-drivers vulkan-validationlayers
sudo apt -y install libsdl2-dev libsdl2-net-dev libva-dev python3-venv valgrind spirv-tools glslang-dev libvulkan-dev mesa-vulkan-drivers vulkan-validationlayers
sudo apt -y install ffmpeg libavcodec-dev libavutil-dev libavformat-dev libavdevice-dev libavfilter-dev libswscale-dev libswresample-dev libpostproc-dev
sudo apt -y install libfreetype-dev libharfbuzz-dev libfribidi-dev
sudo apt -y install graphviz
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ jobs:
#
# apt-get install python3-venv
#
sudo apt -y install libsdl2-dev libva-dev python3-venv valgrind spirv-tools glslang-dev libvulkan-dev mesa-vulkan-drivers vulkan-validationlayers
sudo apt -y install libsdl2-dev libsdl2-net-dev libva-dev python3-venv valgrind spirv-tools glslang-dev libvulkan-dev mesa-vulkan-drivers vulkan-validationlayers
sudo apt -y install ffmpeg libavcodec-dev libavutil-dev libavformat-dev libavdevice-dev libavfilter-dev libswscale-dev libswresample-dev libpostproc-dev
sudo apt -y install libfreetype-dev libharfbuzz-dev libfribidi-dev
sudo apt -y install graphviz
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_mac.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:

- name: Install dependencies
run: |
brew install python3 curl pkg-config sdl2 ffmpeg glslang molten-vk vulkan-headers freetype fribidi harfbuzz
brew install python3 curl pkg-config sdl2 sdl2_net ffmpeg glslang molten-vk vulkan-headers freetype fribidi harfbuzz
- name: Build
run: |
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/ci_mingw.yml
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ jobs:

- name: Install dependencies
run: |
pacman -S --noconfirm --needed git make mingw-w64-x86_64-{toolchain,ffmpeg,python,python3-pillow,meson,glslang}
pacman -S --noconfirm --needed git make mingw-w64-x86_64-{toolchain,SDL2,SDL2_net,ffmpeg,python,python3-pillow,meson,glslang}
# Install vulkan-devel packages explicitely to workaround a conflict between vulkan-utility-libraries and vulkan-validation-layers
pacman -S --noconfirm --needed mingw-w64-x86_64-{spirv-headers,spirv-tools,vulkan-headers,vulkan-loader,vulkan-validation-layers}
# Prevents random "SSL: CERTIFICATE_VERIFY_FAILED" error with urllib HTTPS calls
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release_linux.yml
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ jobs:
#
# apt-get install python3-venv
#
sudo apt -y install libsdl2-dev libva-dev python3-venv spirv-tools glslang-dev libvulkan-dev mesa-vulkan-drivers vulkan-validationlayers
sudo apt -y install libsdl2-dev libsdl2-net-dev libva-dev python3-venv spirv-tools glslang-dev libvulkan-dev mesa-vulkan-drivers vulkan-validationlayers
sudo apt -y install ffmpeg libavcodec-dev libavutil-dev libavformat-dev libavdevice-dev libavfilter-dev libswscale-dev libswresample-dev libpostproc-dev
sudo apt -y install libfreetype-dev libharfbuzz-dev libfribidi-dev
sudo apt -y install fuse
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release_macos.yml
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ jobs:

- name: Install dependencies
run: |
brew install ffmpeg freetype fribidi harfbuzz [email protected] curl pkg-config nasm create-dmg
brew install sdl2 sdl2_net ffmpeg freetype fribidi harfbuzz [email protected] curl pkg-config nasm create-dmg
- name: Setup venv
run: |
Expand Down
30 changes: 29 additions & 1 deletion configure.py
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,12 @@ def _gen_ios_cross_file(cfg):
dst_file="SDL2-@[email protected]",
sha256="fc5d6c096a6b82f86613060dfef553a09b9e08afcb401fefac4b9ca221265cda",
),
sdl2_net_Windows=dict(
version="2.2.0",
url="https://github.com/libsdl-org/SDL_net/releases/download/release-2.2.0/SDL2_net-devel-@[email protected]",
dst_file="SDL2_net-@[email protected]",
sha256="f364e55babb44e47b41d039a43c640aa1f76615b726855591b555321c7d870dd",
),
glslang=dict(
version="14.1.0",
dst_file="glslang-@[email protected]",
Expand Down Expand Up @@ -298,6 +304,7 @@ def _get_external_deps(args):
deps.append("opengl_registry")
deps.append("ffmpeg_Windows")
deps.append("sdl2_Windows")
deps.append("sdl2_net_Windows")
deps.append("glslang_Windows")
deps.append("freetype")
deps.append("harfbuzz")
Expand Down Expand Up @@ -784,6 +791,27 @@ def _sdl2_install(cfg):
return cmds


@_block("sdl_2net-install", [])
def _sdl2_net_install(cfg):
dirs = (
"lib",
"include",
"cmake",
)
cmds = []
for d in dirs:
src = op.join(cfg.externals["sdl2_net_Windows"], d, "*")
dst = op.join(cfg.prefix, d)
os.makedirs(dst, exist_ok=True)
cmds.append(_cmd_join("xcopy", src, dst, "/s", "/y"))

src = op.join(cfg.externals["sdl2_net_Windows"], "lib", "x64", "SDL2_net.dll")
dst = op.join(cfg.prefix, "Scripts")
cmds.append(_cmd_join("xcopy", src, dst, "/y"))

return cmds


@_block("moltenvk-install", [])
def _moltenvk_install(cfg):
resources = (
Expand Down Expand Up @@ -877,7 +905,7 @@ def _glslang_install(cfg):
{
"Android": [_ffmpeg_install],
"iOS": [_ffmpeg_install],
"Windows": [_pkgconf_install, _ffmpeg_install, _sdl2_install],
"Windows": [_pkgconf_install, _ffmpeg_install, _sdl2_install, _sdl2_net_install],
},
)
def _nopemd_setup(cfg):
Expand Down
30 changes: 16 additions & 14 deletions ngl-tools/ipc.c
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright 2024 Nope Forge
* Copyright 2020-2022 GoPro Inc.
*
* Licensed to the Apache Software Foundation (ASF) under one
Expand All @@ -19,16 +20,13 @@
* under the License.
*/

#include <limits.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#ifdef _WIN32
#include <winsock2.h>
#else
#include <sys/socket.h>
#endif

#include <nopegl.h>
#include <SDL2/SDL_net.h>

#include "ipc.h"

Expand Down Expand Up @@ -150,11 +148,15 @@ void ipc_pkt_freep(struct ipc_pkt **pktp)
*pktp = NULL;
}

int ipc_send(int fd, const struct ipc_pkt *pkt)
int ipc_send(TCPsocket socket, const struct ipc_pkt *pkt)
{
const int n = (int)send(fd, pkt->data, pkt->size, 0);
if (pkt->size > INT_MAX) {
printf("Packet size exceeds limits");
return NGL_ERROR_IO;
}
const int n = SDLNet_TCP_Send(socket, pkt->data, (int)pkt->size);
if (n < 0) {
perror("send");
printf("SDLNet_TCP_Send: %s\n", SDLNet_GetError());
return NGL_ERROR_IO;
}
// XXX: should we loop instead?
Expand All @@ -165,15 +167,15 @@ int ipc_send(int fd, const struct ipc_pkt *pkt)
return 0;
}

static int readbuf(int fd, uint8_t *buf, int size)
static int readbuf(TCPsocket socket, uint8_t *buf, int size)
{
int nr = 0;
while (nr != size) {
const int n = (int)recv(fd, buf + nr, size - nr, 0);
const int n = SDLNet_TCP_Recv(socket, buf, size);
if (n == 0)
return 0;
if (n < 0) {
perror("recv");
printf("SDLNet_TCP_Recv: %s\n", SDLNet_GetError());
return NGL_ERROR_IO;
}
nr += n;
Expand All @@ -187,9 +189,9 @@ void ipc_pkt_reset(struct ipc_pkt *pkt)
pkt_update_header(pkt);
}

int ipc_recv(int fd, struct ipc_pkt *pkt)
int ipc_recv(TCPsocket socket, struct ipc_pkt *pkt)
{
int ret = readbuf(fd, pkt->data, 8);
int ret = readbuf(socket, pkt->data, 8);
if (ret <= 0)
return ret;

Expand All @@ -210,7 +212,7 @@ int ipc_recv(int fd, struct ipc_pkt *pkt)
return NGL_ERROR_MEMORY;
pkt->data = dst;

ret = readbuf(fd, pkt->data + 8, size);
ret = readbuf(socket, pkt->data + 8, size);
if (ret <= 0)
return ret;

Expand Down
7 changes: 5 additions & 2 deletions ngl-tools/ipc.h
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
/*
* Copyright 2024 Nope Forge
* Copyright 2020-2022 GoPro Inc.
*
* Licensed to the Apache Software Foundation (ASF) under one
Expand All @@ -25,6 +26,8 @@
#include <stdint.h>
#include <stdlib.h>

#include <SDL2/SDL_net.h>

#define IPC_U32(a,b,c,d) (((uint32_t)(a))<<24 | (b)<<16 | (c)<<8 | (d))
#define IPC_U32_READ(buf) IPC_U32((buf)[0], (buf)[1], (buf)[2], (buf)[3])
#define IPC_U32_FMT(tag) (tag)>>24, (tag)>>16&0xff, (tag)>>8&0xff, (tag)&0xff
Expand Down Expand Up @@ -63,7 +66,7 @@ int ipc_pkt_add_rtag_info(struct ipc_pkt *pkt, const char *info);
int ipc_pkt_add_rtag_filepart(struct ipc_pkt *pkt, int written);
int ipc_pkt_add_rtag_fileend(struct ipc_pkt *pkt, const char *dest_filename);

int ipc_send(int fd, const struct ipc_pkt *pkt);
int ipc_recv(int fd, struct ipc_pkt *pkt);
int ipc_send(TCPsocket socket, const struct ipc_pkt *pkt);
int ipc_recv(TCPsocket socket, struct ipc_pkt *pkt);

#endif
8 changes: 2 additions & 6 deletions ngl-tools/meson.build
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ wsi_src_system = {
'windows': files('wsi_windows.c'),
}
wsi_src = files('wsi.c') + wsi_src_system.get(host_system, [])
sdl_dep = dependency('sdl2', required: get_option('sdl'))
sdl_dep = dependency('sdl2', required: true)
wsi_deps = [sdl_dep]
if host_system == 'darwin'
wsi_deps += [dependency('appleframeworks', modules: 'AppKit', required: false)]
Expand All @@ -106,11 +106,7 @@ endif
#
# Network dependencies
#
net_deps = []
if host_system == 'windows'
net_deps += [cc.find_library('ws2_32')]
endif

net_deps = [dependency('sdl2_net', required: true)]

#
# Tools specifications
Expand Down
2 changes: 0 additions & 2 deletions ngl-tools/meson_options.txt
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@

option('python', type: 'feature', value: 'auto',
description: 'Python support')
option('sdl', type: 'feature', value: 'auto',
description: 'SDL support')

option('rpath', type: 'boolean', value: false,
description: 'install with rpath')
Loading

0 comments on commit 2e76cbd

Please sign in to comment.