summaryrefslogtreecommitdiff
path: root/src/fruits
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2025-11-30 14:32:51 -0500
committerAndrew Opalach <andrew@akon.city> 2025-11-30 14:32:51 -0500
commitc8412bbedae0fce38db96833732e8ce904721e4c (patch)
tree4611046186c714513d042966ce97825df0fecf9e /src/fruits
parent0d6d13425015d78606232874498327cabcb0e4e2 (diff)
downloadcamu-c8412bbedae0fce38db96833732e8ce904721e4c.tar.gz
camu-c8412bbedae0fce38db96833732e8ce904721e4c.tar.bz2
camu-c8412bbedae0fce38db96833732e8ce904721e4c.zip
Build cleanup and fixes from sink testing
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'src/fruits')
-rw-r--r--src/fruits/cmc/cmc.c8
-rw-r--r--src/fruits/cmc/meson.build4
-rw-r--r--src/fruits/cmc/ui/util/waveform.c4
-rw-r--r--src/fruits/cmsrv/cmsrv.c18
-rw-r--r--src/fruits/cmsrv/meson.build8
-rw-r--r--src/fruits/cmsrv/ui.c6
-rw-r--r--src/fruits/cmsrv/ui.h1
-rw-r--r--src/fruits/cmv/cmv.c97
-rw-r--r--src/fruits/cmv/meson.build2
-rw-r--r--src/fruits/common.h24
-rw-r--r--src/fruits/ctv/ctv.c8
-rw-r--r--src/fruits/meson.build7
12 files changed, 88 insertions, 99 deletions
diff --git a/src/fruits/cmc/cmc.c b/src/fruits/cmc/cmc.c
index 3d91ba6..f44f82f 100644
--- a/src/fruits/cmc/cmc.c
+++ b/src/fruits/cmc/cmc.c
@@ -6,8 +6,6 @@
#include "../../liana/list.h"
#include "../../codec/packet_ext.h"
-#include "../common.h"
-
#include "cmc.h"
#include "ui/ui.h"
@@ -281,9 +279,13 @@ s32 main(s32 argc, char *argv[])
camu_post_cache_init(&c.cache);
al_array_init(c.searches);
+ str user = al_str_c("guest");
+ char *CMC_USER = getenv("CMC_USER");
+ if (CMC_USER) user = al_str_cr(CMC_USER);
+
c.client.callback = client_callback;
c.client.userdata = &c;
- if (!camu_client_login(&c.client, &al_str_c("andrew"), &c.loop, CAMU_TEST_TYPE, &CAMU_TEST_ADDR, CAMU_PORT)) {
+ if (!camu_client_login(&c.client, &user, &c.loop, NNWT_SOCKET_TCP, &al_str_c("127.0.0.1"), CAMU_PORT)) {
goto err;
}
diff --git a/src/fruits/cmc/meson.build b/src/fruits/cmc/meson.build
index de6d335..bb9d38d 100644
--- a/src/fruits/cmc/meson.build
+++ b/src/fruits/cmc/meson.build
@@ -20,7 +20,7 @@ if use_tui
endif
if is_windows and not is_msvc
- cmc_args += ['-static', '-static-libgcc', '-static-libstdc++', '-municode', '-mwindows']
+ cmc_args += ['-static', '-static-libgcc', '-static-libstdc++', '-mwindows', '-municode']
endif
-executable('cmc', cmc_src, dependencies: cmc_deps, link_args: cmc_args, install: true)
+executable('cmc', cmc_src, dependencies: cmc_deps, c_args: cmc_args, link_args: cmc_args, install: true)
diff --git a/src/fruits/cmc/ui/util/waveform.c b/src/fruits/cmc/ui/util/waveform.c
index bed34b7..624069e 100644
--- a/src/fruits/cmc/ui/util/waveform.c
+++ b/src/fruits/cmc/ui/util/waveform.c
@@ -22,8 +22,8 @@
// extra: #f6ac7f, #F5F4FA, #5b524b
// left channel: n == 0, right channel: n == 1.
#define COLOR_FOR_PIXEL(n, rms) rms ? \
- n == 0 ? nn_htonl(0xE4CAAF99) : nn_htonl(0xFF928FFF) : \
- n == 0 ? nn_htonl(0xF4EAE099) : nn_htonl(0xBC615EFF)
+ n == 0 ? nn_htonl(0xe4caaf99) : nn_htonl(0xff928fff) : \
+ n == 0 ? nn_htonl(0xf4eae099) : nn_htonl(0xbc615eff)
// ss: current sample, ns: next sample.
#define HIT_WAVE(low, high, ss, ns) \
diff --git a/src/fruits/cmsrv/cmsrv.c b/src/fruits/cmsrv/cmsrv.c
index ef66be8..babd5ef 100644
--- a/src/fruits/cmsrv/cmsrv.c
+++ b/src/fruits/cmsrv/cmsrv.c
@@ -1,8 +1,7 @@
-#define CMSRV_LOCAL_SOCKET
-#define CMSRV_USE_UI
-
+#define AL_LOG_SECTION "cmsrv"
#include <al/log.h>
#include <nnwt/common.h>
+#define CMSRV_LOCAL_SOCKET
#ifdef CMSRV_LOCAL_SOCKET
#include <nnwt/line_processor.h>
#endif
@@ -15,9 +14,9 @@
#include "../../cache/handlers/cdio.h"
#endif
-#include "../common.h"
-
+#ifdef CMSRV_USE_UI
#include "ui.h"
+#endif
struct cmsrv {
struct nn_event_loop loop;
@@ -186,8 +185,13 @@ s32 main(s32 argc, char *argv[])
nn_signal_start(&s.quit_signal);
signal(SIGINT, sigint_handler);
+ str addr = al_str_c("127.0.0.1");
+ char *CMSRV_IP = getenv("CMSRV_IP");
+ if (CMSRV_IP) addr = al_str_cr(CMSRV_IP);
+ log_info("Serving from %.*s.", al_str_x(&addr));
+
camu_server_init(&s.server, &s.loop);
- if (!camu_server_listen(&s.server, CAMU_TEST_TYPE, &CAMU_TEST_ADDR, CAMU_PORT)) {
+ if (!camu_server_listen(&s.server, NNWT_SOCKET_TCP, &addr, CAMU_PORT)) {
return EXIT_FAILURE;
}
@@ -198,7 +202,7 @@ s32 main(s32 argc, char *argv[])
s.local.cli.userdata = &s;
nn_line_processor_init(&s.local.cli, &al_str_c("\n"));
nn_line_processor_open_socket(&s.local.cli, &s.local.sock);
- if (nn_socket_bind(&s.local.sock, &CAMU_TEST_CONTROL_PATH, 0) && nn_socket_listen(&s.local.sock)) {
+ if (nn_socket_bind(&s.local.sock, &al_str_c("/tmp/camu_control"), 0) && nn_socket_listen(&s.local.sock)) {
nn_line_processor_run(&s.local.cli, &s.loop);
}
#endif
diff --git a/src/fruits/cmsrv/meson.build b/src/fruits/cmsrv/meson.build
index b12d00d..bfeabe0 100644
--- a/src/fruits/cmsrv/meson.build
+++ b/src/fruits/cmsrv/meson.build
@@ -2,14 +2,14 @@ cmsrv_src = ['cmsrv.c']
cmsrv_deps = [common_deps, server]
cmsrv_args = []
-use_tui = true
-if use_tui
+if use_tuis
cmsrv_src += ['ui.c']
cmsrv_deps += [notcurses_core]
+ cmsrv_args += ['-DCMSRV_USE_UI']
endif
if is_windows and not is_msvc
- cmsrv_args += ['-static', '-static-libgcc', '-static-libstdc++', '-municode', '-mwindows']
+ cmsrv_args += ['-static', '-static-libgcc', '-static-libstdc++', '-mwindows', '-municode']
endif
-executable('cmsrv', cmsrv_src, dependencies: cmsrv_deps, link_args: cmsrv_args, install: true)
+executable('cmsrv', cmsrv_src, dependencies: cmsrv_deps, c_args: cmsrv_args, link_args: cmsrv_args, install: true)
diff --git a/src/fruits/cmsrv/ui.c b/src/fruits/cmsrv/ui.c
index d96c09d..afbee58 100644
--- a/src/fruits/cmsrv/ui.c
+++ b/src/fruits/cmsrv/ui.c
@@ -29,6 +29,7 @@ bool cmsrv_ui_init(struct cmsrv_ui *ui, struct camu_server *server)
ncplane_set_userptr(stdplane, ui);
ui->pending_layout = true;
al_array_init(ui->log.messages);
+ nn_mutex_init(&ui->log.lock);
return true;
}
@@ -51,7 +52,9 @@ void cmsrv_ui_set_pane(struct cmsrv_ui *ui, u8 pane)
void cmsrv_ui_push_message(struct cmsrv_ui *ui, char *message)
{
+ nn_mutex_lock(&ui->log.lock);
al_array_push(ui->log.messages, message);
+ nn_mutex_unlock(&ui->log.lock);
}
static void layout_log(struct cmsrv_ui *ui, struct ncplane *parent)
@@ -80,6 +83,7 @@ static void render_log(struct cmsrv_ui *ui)
u32 max_width = ncplane_dim_x(n) - 2;
u32 max_height = ncplane_dim_y(n) - 2;
+ nn_mutex_lock(&ui->log.lock);
u32 size = ui->log.messages.count;
if (size > max_height) {
u32 index = size - max_height;
@@ -97,6 +101,7 @@ static void render_log(struct cmsrv_ui *ui)
// messages will have wide characters.
ncplane_putstr_yx(n, y, x, al_array_at(ui->log.messages, i));
}
+ nn_mutex_unlock(&ui->log.lock);
u64 c = 0;
ncchannels_set_fg_default(&c);
@@ -251,4 +256,5 @@ void cmsrv_ui_close(struct cmsrv_ui *ui)
al_free(message);
}
al_array_free(ui->log.messages);
+ nn_mutex_destroy(&ui->log.lock);
}
diff --git a/src/fruits/cmsrv/ui.h b/src/fruits/cmsrv/ui.h
index ebf7c1a..3615d3b 100644
--- a/src/fruits/cmsrv/ui.h
+++ b/src/fruits/cmsrv/ui.h
@@ -19,6 +19,7 @@ struct cmsrv_ui {
struct {
struct ncplane *n;
array(char *) messages;
+ struct nn_mutex lock;
} log;
struct {
struct ncplane *n;
diff --git a/src/fruits/cmv/cmv.c b/src/fruits/cmv/cmv.c
index fe0fbd6..535bf72 100644
--- a/src/fruits/cmv/cmv.c
+++ b/src/fruits/cmv/cmv.c
@@ -13,8 +13,6 @@
#include "../../codec/ffmpeg/common.h"
#endif
-#include "../common.h"
-
#if !defined CAMU_SINK_ONLY && !defined NAUNET_ON_WINDOWS
// https://unix.stackexchange.com/a/16884
#define PID_MAX_STR 7 // 0x400000 (2^22).
@@ -46,13 +44,32 @@ static nn_thread_result NNWT_THREADCALL event_loop_thread(void *userdata)
return 0;
}
-// sink-p12-108.52.160.112-aEN-v-sEN.exe
-static bool parse_exe_name_params(str *exe_name, str *addr, struct lia_prefs *prefs)
+static bool decode_addr(str *enc, str *addr)
+{
+ char value[4]; // max = 255.
+ for (u32 i = 0; i < 8; i += 2) {
+ str sub = al_str_substr(enc, i, i + 2);
+ bool error;
+ s64 l = al_str_to_long(&sub, 16, &error);
+ al_assert(l >= 0 && l <= 255);
+ if (error) return false;
+ al_snprintf(value, sizeof(value), "%hhu", (u8)l);
+ al_str_cat(addr, &al_str_cs(value));
+ if (i != 6) {
+ al_str_cat(addr, &al_str_c("."));
+ }
+ }
+ return true;
+}
+
+// sink-p12-976502a7.exe
+static bool parse_exe_name(str *exe_name, str *addr)
{
u32 index = al_str_rfind(exe_name, '/');
if (index == AL_STR_NO_POS) {
- index = al_str_rfind(exe_name, '\\');
- if (index == AL_STR_NO_POS) goto def;
+ if ((index = al_str_rfind(exe_name, '\\')) == AL_STR_NO_POS) {
+ goto def;
+ }
}
str sub = al_str_substr(exe_name, index + 1, exe_name->length);
@@ -62,51 +79,20 @@ static bool parse_exe_name_params(str *exe_name, str *addr, struct lia_prefs *pr
sub = al_str_substr(&sub, 5, sub.length);
// Skip version.
- index = al_str_find(&sub, '-');
- if (index == AL_STR_NO_POS) goto def;
+ if ((index = al_str_find(&sub, '-')) == AL_STR_NO_POS) {
+ goto def;
+ }
sub = al_str_substr(&sub, index + 1, sub.length);
- index = al_str_find(&sub, '-');
- if (index == AL_STR_NO_POS) goto def;
- al_str_clone(addr, &al_str_substr(&sub, 0, index));
-
- for (;;) {
- sub = al_str_substr(&sub, index + 1, sub.length);
- index = al_str_find(&sub, '-');
- if (index == AL_STR_NO_POS) {
- index = al_str_find(&sub, '.');
- if (index == AL_STR_NO_POS) {
- index = sub.length;
- } else {
- sub.length = index;
- }
- }
-
- str value;
- al_str_clone(&value, &al_str_substr(&sub, 0, index));
- al_str_to_lower(&value);
- if (al_str_at(&value, 0) == 'a') {
- prefs->enabled_mask |= 1 << CAMU_STREAM_AUDIO;
- } else if (al_str_at(&value, 0) == 'v') {
- prefs->enabled_mask |= 1 << CAMU_STREAM_VIDEO;
- } else if (al_str_at(&value, 0) == 's') {
- prefs->enabled_mask |= 1 << CAMU_STREAM_SUBTITLE;
- }
- al_str_free(&value);
-
- if (index == sub.length) break;
+ if ((index = al_str_find(&sub, '.')) != AL_STR_NO_POS) {
+ sub = al_str_substr(&sub, 0, index);
}
+ al_str_from(addr, "");
+ decode_addr(&sub, addr);
+ log_debug("Parsed address %.*s from exe filename.", al_str_x(addr));
return true;
def:
-#ifdef CAMU_HAVE_SUBTITLES
- prefs->enabled_mask = (1 << CAMU_STREAM_AUDIO) | (1 << CAMU_STREAM_VIDEO) | (1 << CAMU_STREAM_SUBTITLE);
-#else
- prefs->enabled_mask = (1 << CAMU_STREAM_AUDIO) | (1 << CAMU_STREAM_VIDEO);
-#endif
- prefs->audio_lang = CAMU_LANG_JAPANESE;
- prefs->subtitle_lang = CAMU_LANG_ENGLISH;
-
return false;
}
@@ -141,12 +127,12 @@ s32 window_system_main(u32 argc, str *argv, void *extra)
u8 type;
str addr;
- if (!parse_exe_name_params(&argv[0], &addr, &c.desktop.sink.prefs)) {
+ if (!parse_exe_name(&argv[0], &addr)) {
#ifndef CAMU_SINK_ONLY
if (local) {
#ifdef NAUNET_ON_WINDOWS
- type = NNWT_SOCKET_TCP;;
- al_str_clone(&addr, &CAMU_LOCALHOST);
+ type = NNWT_SOCKET_TCP;
+ al_str_clone(&addr, &al_str_c("127.0.0.1"));
#else
type = NNWT_SOCKET_UNIX;
al_str_clone(&addr, &CMV_UNIX_PATH);
@@ -155,17 +141,26 @@ s32 window_system_main(u32 argc, str *argv, void *extra)
al_str_cat(&addr, &al_str_cs(pid_str));
#endif
} else {
- type = CAMU_TEST_TYPE;
- al_str_clone(&addr, &CAMU_TEST_ADDR);
+ type = NNWT_SOCKET_TCP;
+ al_str_clone(&addr, &al_str_c("127.0.0.1"));
}
#else
type = NNWT_SOCKET_TCP;
- al_str_clone(&addr, &CAMU_TEST_ADDR);
+ al_str_clone(&addr, &al_str_c("127.0.0.1"));
#endif
} else {
type = NNWT_SOCKET_TCP;
}
+ struct lia_prefs *prefs = &c.desktop.sink.prefs;
+#ifdef CAMU_HAVE_SUBTITLES
+ prefs->enabled = (1 << CAMU_STREAM_AUDIO) | (1 << CAMU_STREAM_VIDEO) | (1 << CAMU_STREAM_SUBTITLE);
+#else
+ prefs->enabled = (1 << CAMU_STREAM_AUDIO) | (1 << CAMU_STREAM_VIDEO);
+#endif
+ prefs->language.audio = CAMU_LANG_JAPANESE;
+ prefs->language.subtitles = CAMU_LANG_ENGLISH;
+
#ifndef CAMU_SINK_ONLY
if (local) {
camu_server_init(&c.server, &c.loop);
diff --git a/src/fruits/cmv/meson.build b/src/fruits/cmv/meson.build
index bfd2182..3e78f05 100644
--- a/src/fruits/cmv/meson.build
+++ b/src/fruits/cmv/meson.build
@@ -15,7 +15,7 @@ endif
cmv_link_args = []
if is_windows and not is_msvc
- cmv_link_args += ['-static', '-static-libgcc', '-static-libstdc++', '-municode', '-mwindows']
+ cmv_link_args += ['-static', '-static-libgcc', '-static-libstdc++', '-mwindows', '-municode']
endif
executable('cmv', cmv_src, dependencies: cmv_deps, c_args: cmv_args, link_args: cmv_link_args, install: true)
diff --git a/src/fruits/common.h b/src/fruits/common.h
deleted file mode 100644
index 66a72bc..0000000
--- a/src/fruits/common.h
+++ /dev/null
@@ -1,24 +0,0 @@
-#include <al/str.h>
-#include <nnwt/socket.h>
-
-AL_IGNORE_WARNING("-Wunused-variable")
-
-static str CAMU_DB_PATH = al_str_c("/home/andrew/c/camu/data/camu_db_test");
-
-static str CAMU_TEST_IP = al_str_c("108.52.160.112");
-static str CAMU_LOCALHOST = al_str_c("127.0.0.1");
-
-static str CAMU_TEST_PATH = al_str_c("/tmp/camu_sock");
-static str CAMU_TEST_CONTROL_PATH = al_str_c("/tmp/camu_control_sock");
-
-AL_IGNORE_WARNING_END
-
-#ifdef NAUNET_ON_WINDOWS
-#define CAMU_TEST_TYPE NNWT_SOCKET_TCP
-#define CAMU_TEST_ADDR CAMU_TEST_IP
-#else
-//#define CAMU_TEST_TYPE NNWT_SOCKET_UNIX
-//#define CAMU_TEST_ADDR CAMU_TEST_PATH
-#define CAMU_TEST_TYPE NNWT_SOCKET_TCP
-#define CAMU_TEST_ADDR CAMU_TEST_IP
-#endif
diff --git a/src/fruits/ctv/ctv.c b/src/fruits/ctv/ctv.c
index 45942e6..8b173b0 100644
--- a/src/fruits/ctv/ctv.c
+++ b/src/fruits/ctv/ctv.c
@@ -24,12 +24,12 @@ static nn_thread_result NNWT_THREADCALL event_loop_thread(void *userdata)
struct lia_prefs *prefs = &c->desktop.sink.prefs;
#ifdef CAMU_HAVE_SUBTITLES
- prefs->enabled_mask = (1 << CAMU_STREAM_AUDIO) | (1 << CAMU_STREAM_VIDEO) | (1 << CAMU_STREAM_SUBTITLE);
+ prefs->enabled = (1 << CAMU_STREAM_AUDIO) | (1 << CAMU_STREAM_VIDEO) | (1 << CAMU_STREAM_SUBTITLE);
#else
- prefs->enabled_mask = (1 << CAMU_STREAM_AUDIO) | (1 << CAMU_STREAM_VIDEO);
+ prefs->enabled = (1 << CAMU_STREAM_AUDIO) | (1 << CAMU_STREAM_VIDEO);
#endif
- prefs->audio_lang = CAMU_LANG_JAPANESE;
- prefs->subtitle_lang = CAMU_LANG_ENGLISH;
+ prefs->language.audio = CAMU_LANG_JAPANESE;
+ prefs->language.subtitles = CAMU_LANG_ENGLISH;
if (!camu_desktop_connect(&c->desktop, &al_str_c("ctv"), &c->loop, CAMU_TEST_TYPE, &CAMU_TEST_ADDR, CAMU_PORT)) {
return 0;
diff --git a/src/fruits/meson.build b/src/fruits/meson.build
index 37edd0b..c82d71d 100644
--- a/src/fruits/meson.build
+++ b/src/fruits/meson.build
@@ -1,4 +1,9 @@
-if (get_option('server').enabled() or get_option('client').enabled()) and not is_windows
+use_tuis = true
+if is_windows
+ use_tuis = false
+endif
+
+if use_tuis and (get_option('server').enabled() or get_option('client').enabled())
notcurses = dependency('notcurses', required: false, allow_fallback: false)
notcurses_core = dependency('notcurses-core', required: false, allow_fallback: false)
if not notcurses.found() or not notcurses_core.found()