summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2025-03-31 19:16:50 -0400
committerAndrew Opalach <andrew@akon.city> 2025-03-31 19:16:50 -0400
commitc8b3ed01a41c0215a4a33ce8468b162463129600 (patch)
treeb29fad1faf0d172e2e46be9a73f9b3bc73f8b29a /src
parent2f34d806e42b6d6299ef46284466b98536485839 (diff)
downloadcamu-c8b3ed01a41c0215a4a33ce8468b162463129600.tar.gz
camu-c8b3ed01a41c0215a4a33ce8468b162463129600.tar.bz2
camu-c8b3ed01a41c0215a4a33ce8468b162463129600.zip
Overall style change, small fixes
- Tweak sink switch_to() order. Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'src')
-rw-r--r--src/buffer/clock.c4
-rw-r--r--src/buffer/video.c4
-rw-r--r--src/buffer/video.h3
-rw-r--r--src/buffer/video_null.h4
-rw-r--r--src/buffer/volume.h4
-rw-r--r--src/cache/backings/file_common.h4
-rw-r--r--src/cache/handlers/http.c4
-rw-r--r--src/cache/range.h6
-rw-r--r--src/codec/codec.h8
-rw-r--r--src/fruits/cmc/cmc.c17
-rw-r--r--src/fruits/cmv/cmv.c33
-rw-r--r--src/fruits/common.h4
-rw-r--r--src/fruits/ctv/ctv.c2
-rw-r--r--src/liana/list.h17
-rw-r--r--src/liana/list_cmp.h26
-rw-r--r--src/liana/server.c3
-rw-r--r--src/liana/vcr.c16
-rw-r--r--src/libsink/sink.c147
-rw-r--r--src/mixer/mixer.c4
-rw-r--r--src/portal/src/post.c3
-rw-r--r--src/portal/src/search.c20
-rw-r--r--src/render/renderer_libplacebo.c22
-rw-r--r--src/screen/screen.c11
-rw-r--r--src/server/common.h6
-rw-r--r--src/server/db.c15
-rw-r--r--src/server/server.c24
-rw-r--r--src/util/color_palette.c23
-rw-r--r--src/util/queue.h96
28 files changed, 266 insertions, 264 deletions
diff --git a/src/buffer/clock.c b/src/buffer/clock.c
index a1a1eab..6a30af9 100644
--- a/src/buffer/clock.c
+++ b/src/buffer/clock.c
@@ -1,4 +1,3 @@
-#include <al/lib.h>
#include <nnwt/thread.h>
#include "clock.h"
@@ -46,7 +45,7 @@ void camu_clock_seek(struct camu_clock *clock, f64 base, u64 target)
}
} else {
// The value of clock->pause cannot be touched here. A reconnecting entry
- // may still be relying on a clock paused callback for sync.
+ // may be relying on a CLOCK_PAUSED callback for sync.
clock->paused_at = 0.0;
}
}
@@ -98,6 +97,7 @@ void camu_clock_resume(struct camu_clock *clock, u64 target)
}
al_atomic_store(f64)(&clock->pause, RUNNING, AL_ATOMIC_RELAXED);
+
clock->paused_at = -1.0;
}
diff --git a/src/buffer/video.c b/src/buffer/video.c
index 54d83af..67b23f6 100644
--- a/src/buffer/video.c
+++ b/src/buffer/video.c
@@ -23,6 +23,7 @@ bool camu_video_buffer_init(struct camu_video_buffer *buf, struct camu_clock *cl
buf->clock = clock;
buf->latency = 0.0;
al_atomic_store(f64)(&buf->pts, -1.0, AL_ATOMIC_RELAXED);
+ buf->reset_pts = -1.0;
// The least confusing behavior for single_frame is that it can't be
// set if the buffer is empty.
buf->single_frame = false;
@@ -211,7 +212,8 @@ void camu_video_buffer_flush(struct camu_video_buffer *buf)
// Not thread-safe, must be called while the buffer is not being read from or written to.
void camu_video_buffer_reset(struct camu_video_buffer *buf)
{
- al_atomic_store(f64)(&buf->pts, -1.0, AL_ATOMIC_RELAXED);
+ buf->reset_pts = al_atomic_load(f64)(&buf->pts, AL_ATOMIC_ACQUIRE);
+ al_atomic_store(f64)(&buf->pts, -1.0, AL_ATOMIC_RELEASE);
if (buf->queue) buf->queue->reset(buf->queue);
buf->buffered = false;
al_atomic_store(u8)(&buf->flow, FLOWING, AL_ATOMIC_RELAXED);
diff --git a/src/buffer/video.h b/src/buffer/video.h
index 5bdf267..b3b03bb 100644
--- a/src/buffer/video.h
+++ b/src/buffer/video.h
@@ -15,8 +15,9 @@ struct camu_video_buffer {
struct camu_codec_stream *stream;
struct camu_clock *clock;
- atomic(f64) pts;
f64 latency;
+ atomic(f64) pts;
+ f64 reset_pts;
bool single_frame;
f64 avg_frame_duration;
diff --git a/src/buffer/video_null.h b/src/buffer/video_null.h
index 60e73f1..11dc49b 100644
--- a/src/buffer/video_null.h
+++ b/src/buffer/video_null.h
@@ -21,7 +21,7 @@ struct camu_renderer {
u32 (*get_latency)(struct camu_renderer *);
};
-AL_UNUSED_FUNCTION_PUSH
+AL_IGNORE_WARNING("-Wunused-function")
static bool camu_video_buffer_init(struct camu_video_buffer *buf, struct camu_clock *clock)
{
@@ -92,4 +92,4 @@ static void camu_video_buffer_free(struct camu_video_buffer *buf)
(void)buf;
}
-AL_UNUSED_FUNCTION_POP
+AL_IGNORE_WARNING_END
diff --git a/src/buffer/volume.h b/src/buffer/volume.h
index 6a8cf0a..87b1945 100644
--- a/src/buffer/volume.h
+++ b/src/buffer/volume.h
@@ -1,7 +1,5 @@
#include "../codec/codec.h"
-AL_UNUSED_FUNCTION_PUSH
-
static inline f32 apply_volume_f32(f32 *data, size_t sample_count, s32 channel_count, f32 volume, f32 user, f32 step)
{
for (u32 i = 0; i < sample_count; i++) {
@@ -62,5 +60,3 @@ static inline f32 apply_volume(u8 *data, size_t size, struct camu_audio_format *
}
return volume;
}
-
-AL_UNUSED_FUNCTION_POP
diff --git a/src/cache/backings/file_common.h b/src/cache/backings/file_common.h
index 98bd420..3f4ed3b 100644
--- a/src/cache/backings/file_common.h
+++ b/src/cache/backings/file_common.h
@@ -5,7 +5,7 @@
#include "file.h"
-AL_UNUSED_FUNCTION_PUSH
+AL_IGNORE_WARNING("-Wunused-function")
static off_t file_backing_get_size_estimate(struct cch_backing *backing)
{
@@ -34,4 +34,4 @@ static bool file_open_internal(struct cch_backing_file *file, str *path, size_t
return true;
}
-AL_UNUSED_FUNCTION_POP
+AL_IGNORE_WARNING_END
diff --git a/src/cache/handlers/http.c b/src/cache/handlers/http.c
index d5c06dc..6ff5a3c 100644
--- a/src/cache/handlers/http.c
+++ b/src/cache/handlers/http.c
@@ -8,7 +8,7 @@
#include "http.h"
-static str USER_AGENT = al_str_c("Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:134.0) Gecko/20100101 Firefox/134.0");
+static str USER_AGENT = al_str_c("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/95.0.4638.69 Safari/537.36");
static bool handler_http_can_seek(struct cch_handler *handler)
{
@@ -72,7 +72,7 @@ static void handler_http_maybe_spawn_worker(struct cch_handler *handler, size_t
nn_http_set_url(request, &http->url);
nn_http_set_user_agent(request, &USER_AGENT);
nn_http_request_stream(request, NNWT_HTTP_GET, http->loop, http_callback, http);
- debug("Spawning worker for %.*s.", al_str_fmt(&http->url));
+ debug("Spawning worker for %.*s.", al_str_x(&http->url));
}
static bool handler_http_wait_for_range(struct cch_handler *handler, struct cch_handler_wait *wait)
diff --git a/src/cache/range.h b/src/cache/range.h
index 2a95953..c1ede09 100644
--- a/src/cache/range.h
+++ b/src/cache/range.h
@@ -4,12 +4,12 @@
#include "backing.h"
-AL_UNUSED_FUNCTION_PUSH
-
// @TODO:
// - cch_backing_remove_range().
// - Report overlap, don't unlock in backing_write() and handle fill in handler.
+AL_IGNORE_WARNING("-Wunused-function")
+
static void cch_backing_fill_range(struct cch_backing *backing, off_t index, off_t size)
{
struct cch_range *range;
@@ -22,4 +22,4 @@ static void cch_backing_fill_range(struct cch_backing *backing, off_t index, off
al_array_push(backing->available, ((struct cch_range){ index, index + size }));
}
-AL_UNUSED_FUNCTION_POP
+AL_IGNORE_WARNING_END
diff --git a/src/codec/codec.h b/src/codec/codec.h
index 09a1892..1c7c21f 100644
--- a/src/codec/codec.h
+++ b/src/codec/codec.h
@@ -233,8 +233,6 @@ struct camu_scaler {
void (*free)(struct camu_scaler **);
};
-AL_UNUSED_FUNCTION_PUSH
-
static inline bool camu_resampler_format_matches(struct camu_resampler_format *fmt)
{
return fmt->in.format == fmt->req.format
@@ -255,7 +253,7 @@ static inline void camu_audio_format_copy(struct camu_audio_format *dest, struct
dest->channel_count = src->channel_count;
}
-static const char *camu_audio_format_name(s32 format)
+static inline const char *camu_audio_format_name(s32 format)
{
#ifdef CAMU_HAVE_FFMPEG
return av_get_sample_fmt_name(format);
@@ -335,7 +333,7 @@ static inline void camu_video_format_copy(struct camu_video_format *dest, struct
dest->format = src->format;
}
-static const char *camu_pixel_format_name(s32 format)
+static inline const char *camu_pixel_format_name(s32 format)
{
#ifdef CAMU_HAVE_FFMPEG
return av_get_pix_fmt_name(format);
@@ -369,5 +367,3 @@ static inline void camu_codec_frame_discard(struct camu_codec_frame *frame)
if (frame->mode == CAMU_NORMAL && frame->data) al_free(frame->data);
al_free(frame);
}
-
-AL_UNUSED_FUNCTION_POP
diff --git a/src/fruits/cmc/cmc.c b/src/fruits/cmc/cmc.c
index 1046e41..61ac25a 100644
--- a/src/fruits/cmc/cmc.c
+++ b/src/fruits/cmc/cmc.c
@@ -29,9 +29,9 @@ static struct cmc_search *get_search_by_id(struct cmc *c, s32 id)
}
*/
-static void parse_list_entry(struct nn_packet *packet, struct cmc_list_entry *entry)
+static void parse_list_entry(struct nn_packet *packet, struct cmc_list_entry *entry, u32 id)
{
- entry->id = nn_packet_read_u32(packet);
+ entry->id = id;
entry->duration = nn_packet_read_u64(packet);
entry->start = nn_packet_read_u64(packet);
entry->paused_at = nn_packet_read_u64(packet);
@@ -65,8 +65,9 @@ static void parse_initial_user_state(struct cmc *c, struct nn_packet *packet)
al_array_init(list->entries);
u32 inner_count = nn_packet_read_s32(packet);
for (u32 j = 0; j < inner_count; j++) {
+ u32 id = nn_packet_read_u32(packet);
struct cmc_list_entry entry;
- parse_list_entry(packet, &entry);
+ parse_list_entry(packet, &entry, id);
al_array_push(list->entries, entry);
}
al_array_push(c->lists, list);
@@ -131,8 +132,9 @@ static void client_callback(void *userdata, u8 op, void *opaque)
al_array_foreach(c->lists, i, list) {
if (al_str_eq(&list->name, &name)) {
list->current = nn_packet_read_s32(packet);
+ u32 id = nn_packet_read_u32(packet);
struct cmc_list_entry *entry = &al_array_at(list->entries, list->current);
- parse_list_entry(packet, entry);
+ parse_list_entry(packet, entry, id);
break;
}
}
@@ -142,8 +144,9 @@ static void client_callback(void *userdata, u8 op, void *opaque)
case LIANA_META_ADDED_ENTRY: {
str name;
nn_packet_read_str(packet, &name);
+ u32 id = nn_packet_read_u32(packet);
struct cmc_list_entry entry;
- parse_list_entry(packet, &entry);
+ parse_list_entry(packet, &entry, id);
struct cmc_list *list;
al_array_foreach(c->lists, i, list) {
if (al_str_eq(&list->name, &name)) {
@@ -160,11 +163,11 @@ static void client_callback(void *userdata, u8 op, void *opaque)
struct cmc_list *list;
al_array_foreach(c->lists, i, list) {
if (al_str_eq(&list->name, &name)) {
- u32 id = nn_packet_peek_u32(packet);
+ u32 id = nn_packet_read_u32(packet);
struct cmc_list_entry *entry;
al_array_foreach_ptr(list->entries, j, entry) {
if (entry->id == id) {
- parse_list_entry(packet, entry);
+ parse_list_entry(packet, entry, id);
break;
}
}
diff --git a/src/fruits/cmv/cmv.c b/src/fruits/cmv/cmv.c
index 86b6f75..274319a 100644
--- a/src/fruits/cmv/cmv.c
+++ b/src/fruits/cmv/cmv.c
@@ -46,9 +46,9 @@ static nn_thread_result NNWT_THREADCALL event_loop_thread(void *userdata)
static bool parse_exe_name_params(str *exe_name, str *addr, struct lia_prefs *prefs)
{
u32 index = al_str_rfind(exe_name, '/');
- if (index == al_str_npos) {
+ if (index == AL_STR_NPOS) {
index = al_str_rfind(exe_name, '\\');
- if (index == al_str_npos) goto def;
+ if (index == AL_STR_NPOS) goto def;
}
str sub = al_str_substr(exe_name, index + 1, exe_name->length);
@@ -59,19 +59,19 @@ static bool parse_exe_name_params(str *exe_name, str *addr, struct lia_prefs *pr
// Skip version.
index = al_str_find(&sub, '-');
- if (index == al_str_npos) goto def;
+ if (index == AL_STR_NPOS) goto def;
sub = al_str_substr(&sub, index + 1, sub.length);
index = al_str_find(&sub, '-');
- if (index == al_str_npos) goto def;
+ if (index == AL_STR_NPOS) goto def;
*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_npos) {
+ if (index == AL_STR_NPOS) {
index = al_str_find(&sub, '.');
- if (index == al_str_npos) {
+ if (index == AL_STR_NPOS) {
index = sub.length;
} else {
sub.length = index;
@@ -104,8 +104,10 @@ def:
static struct cmv c = { 0 };
-s32 window_system_main(s32 argc, str *argv)
+s32 window_system_main(u32 argc, str *argv, void *extra)
{
+ (void)extra;
+
#ifdef CAMU_HAVE_FFMPEG
camu_ff_common_init();
#endif
@@ -180,7 +182,7 @@ s32 window_system_main(s32 argc, str *argv)
#ifndef CAMU_SINK_ONLY
if (local) {
- for (s32 i = 1; i < argc; i++) {
+ for (u32 i = 1; i < argc; i++) {
struct nn_packet *packet = nn_packet_create();
#if defined CAMU_HAVE_PORTAL
if (al_str_at(&argv[i], 0) == ';' || camu_is_url(&argv[i], 0)) {
@@ -231,12 +233,12 @@ static void sigint_handler(int signum)
}
#ifdef NAUNET_ON_WINDOWS
-s32 wmain(s32 argc, wchar_t **wargv)
+s32 wmain(s32 argc, wchar_t **argv)
#else
-s32 main(s32 argc, char *cargv[])
+s32 main(s32 argc, char *argv[])
#endif
{
- if (!nn_common_init()) {
+ if (!nn_common_init() || !stl_global_init(false)) {
return EXIT_FAILURE;
}
@@ -244,20 +246,21 @@ s32 main(s32 argc, char *cargv[])
array(str) args;
al_array_init(args);
+ al_array_reserve(args, argc);
for (s32 i = 0; i < argc; i++) {
str arg;
#ifdef NAUNET_ON_WINDOWS
- if (!al_str_from_wstr(&arg, &al_wstr_cr(wargv[i]))) {
- error("Failed to parse argument #%i.", i);
+ if (!al_str_from_wstr(&arg, &al_wstr_cr(argv[i]))) {
+ error("Failed to convert argument #%i from a wide string.", i);
continue;
}
#else
- al_str_from(&arg, cargv[i]);
+ al_str_from(&arg, argv[i]);
#endif
al_array_push(args, arg);
}
- s32 ret = stl_global_init((s32)args.count, args.data, window_system_main, false);
+ s32 ret = stl_swallow_main(args.count, args.data, window_system_main, NULL);
stl_global_close();
str *arg;
diff --git a/src/fruits/common.h b/src/fruits/common.h
index 2df5f73..1ff1b1e 100644
--- a/src/fruits/common.h
+++ b/src/fruits/common.h
@@ -1,7 +1,7 @@
#include <al/str.h>
#include <nnwt/socket.h>
-AL_UNUSED_VARIABLE_PUSH
+AL_IGNORE_WARNING("-Wunused-variable")
static str CAMU_DB_PATH = al_str_c("/home/andrew/c/camu/data/camu_db_test");
@@ -11,7 +11,7 @@ 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_UNUSED_VARIABLE_POP
+AL_IGNORE_WARNING_END
//#define CAMU_TEST_TYPE NNWT_SOCKET_UNIX
//#define CAMU_TEST_ADDR CAMU_TEST_PATH
diff --git a/src/fruits/ctv/ctv.c b/src/fruits/ctv/ctv.c
index 452cd39..d8094c3 100644
--- a/src/fruits/ctv/ctv.c
+++ b/src/fruits/ctv/ctv.c
@@ -45,7 +45,7 @@ static s32 log_callback(void *userdata, u8 level, char *message)
static struct ctv c = { 0 };
-s32 window_system_main(s32 argc, str *argv)
+s32 stl_platform_main(u32 argc, str *argv)
{
(void)argc;
(void)argv;
diff --git a/src/liana/list.h b/src/liana/list.h
index 754a4bd..70873ff 100644
--- a/src/liana/list.h
+++ b/src/liana/list.h
@@ -7,10 +7,10 @@
#define LIANA_SEQUENCE_ANY -1
#define LIANA_TIMESTAMP_INVALID ((u64)-1)
-#define LIANA_BASE_DELAY 500000Lu // 500ms
-#define LIANA_BASE_PING 125000Lu // 125ms
+#define LIANA_BASE_DELAY 500000u // 500ms
+#define LIANA_BASE_PING 125000u // 125ms
#define LIANA_PAUSE_DELAY LIANA_BASE_PING
-#define LIANA_DELAY_IGNORE 0Lu
+#define LIANA_DELAY_IGNORE 0u
#define LIANA_BUFFER_AHEAD 2
@@ -118,6 +118,17 @@ struct lia_list {
void *userdata;
};
+static inline const char *lia_pause_op_name(u8 pause)
+{
+ switch (pause) {
+ case LIANA_PAUSE_NONE: return "PAUSE_NONE";
+ case LIANA_PAUSE_RESUME: return "PAUSE_RESUME";
+ case LIANA_PAUSE_PAUSE: return "PAUSE_PAUSE";
+ case LIANA_PAUSE_BOTH: return "PAUSE_BOTH";
+ default: al_assert_and_return(NULL);
+ }
+}
+
void lia_list_init(struct lia_list *list, str *name);
void lia_list_pump(struct lia_list *list);
diff --git a/src/liana/list_cmp.h b/src/liana/list_cmp.h
index c9c0812..556f5dd 100644
--- a/src/liana/list_cmp.h
+++ b/src/liana/list_cmp.h
@@ -4,40 +4,40 @@
#include "list.h"
-AL_UNUSED_FUNCTION_PUSH
+AL_IGNORE_WARNING("-Wunused-function")
static void camu_db_num_from_path(wstr *path, s64 *id, s64 *index)
{
u32 last_slash = al_wstr_rfind(path, L'/');
- if (last_slash == al_wstr_npos) {
+ if (last_slash == AL_WSTR_NPOS) {
return;
}
- wstr temp = al_wstr_substr(path, last_slash + 1, path->length);
+ wstr sub = al_wstr_substr(path, last_slash + 1, path->length);
// Skip 2 '_' characters.
- if (!(al_wstr_tok(&temp, L'_') && al_wstr_tok(&temp, L'_'))) {
+ if (!(al_wstr_tok(&sub, L'_') && al_wstr_tok(&sub, L'_'))) {
return;
}
- u32 target = al_wstr_find(&temp, L'_');
- if (target == al_wstr_npos) {
+ u32 target = al_wstr_find(&sub, L'_');
+ if (target == AL_WSTR_NPOS) {
return;
}
- temp = al_wstr_substr(&temp, 0, target);
+ sub = al_wstr_substr(&sub, 0, target);
bool error;
- s64 num = al_wstr_to_long(&temp, 10, &error);
+ s64 num = al_wstr_to_long(&sub, 10, &error);
if (error) return;
*id = num;
u32 ext_dot = al_wstr_rfind(path, L'.');
- u32 media_a = al_wstr_rfind(path, 'a');
- if (ext_dot == al_wstr_npos || media_a == al_wstr_npos) {
+ u32 a_of_media = al_wstr_rfind(path, 'a');
+ if (ext_dot == AL_WSTR_NPOS || a_of_media == AL_WSTR_NPOS) {
return;
}
- temp = al_wstr_substr(path, media_a + 1, ext_dot);
+ sub = al_wstr_substr(path, a_of_media + 1, ext_dot);
- num = al_wstr_to_long(&temp, 10, &error);
+ num = al_wstr_to_long(&sub, 10, &error);
if (error) return;
*index = num;
}
@@ -60,4 +60,4 @@ static s32 camu_db_compare(const void *a, const void *b)
return 0;
}
-AL_UNUSED_FUNCTION_PUSH
+AL_IGNORE_WARNING_END
diff --git a/src/liana/server.c b/src/liana/server.c
index 808f810..6ab3532 100644
--- a/src/liana/server.c
+++ b/src/liana/server.c
@@ -118,8 +118,7 @@ static void free_connection(struct lia_node_connection *conn)
conn->handler->free(&conn->handler);
cch_entry_return_handle(conn->node->entry, &conn->handle);
nn_packet_pool_free(&conn->pool);
- bool removed;
- al_array_remove_checked(node->connections, conn, removed);
+ bool removed = al_array_remove(node->connections, conn);
al_assert(removed);
al_free(conn);
if (should_free_node(node)) {
diff --git a/src/liana/vcr.c b/src/liana/vcr.c
index a70a19a..ef2406c 100644
--- a/src/liana/vcr.c
+++ b/src/liana/vcr.c
@@ -1,3 +1,4 @@
+#define AL_LOG_SECTION "vcr"
#include <al/log.h>
#include "vcr.h"
@@ -103,7 +104,7 @@ static nn_thread_result NNWT_THREADCALL vcr_track_thread(void *userdata)
// NULL packet means flush.
bool success = track->client->handle_packet(track->client, packet);
if (!success) {
- al_log_error("liana", "Error handling packet, exiting track thread.");
+ error("Error handling packet, exiting track thread.");
return_entire_cache(track);
track->cache.disabled = true;
nn_packet_cache_unlock(&track->cache);
@@ -219,7 +220,7 @@ static void cork_if_buffered(struct lia_vcr *vcr, u64 buffer)
if (vcr->expand == VCR_EXPAND_UNTOUCHED) {
vcr->mark.buffered = buffer * 2;
vcr->expand = VCR_EXPAND_GROWN;
- al_log_info("vcr", "Expanded buffer to size %.2fMB.", vcr->mark.buffered / (f32)MB(1));
+ info("Expanded buffer to size %.2fMB.", vcr->mark.buffered / (f32)MB(1));
return;
} else if (vcr->expand == VCR_EXPAND_GROWN) {
vcr->mark.low = vcr->mark.buffered - MB(2);
@@ -252,7 +253,7 @@ static void update_metrics(struct lia_vcr *vcr, u32 size)
f32 kbps = (frame / 125.f) / (diff / 1000000.f);
f32 capacity = vcr->mark.buffered / (f32)MB(1);
f32 buffered = al_atomic_load(u64)(&vcr->count, AL_ATOMIC_RELAXED) / (f32)MB(1);
- al_log_info("vcr", "Receiving packets at %.2fkbps (%.2f/%.2fMB).", kbps, buffered, capacity);
+ info("Receiving packets at %.2fkbps (%.2f/%.2fMB).", kbps, buffered, capacity);
}
}
@@ -266,7 +267,7 @@ void lia_vcr_push_packet(struct lia_vcr *vcr, struct nn_packet *packet)
update_metrics(vcr, size);
track = get_track_from_index(vcr, nn_packet_read_s32(packet));
if (!track) {
- al_log_debug("liana", "Received data from errored or unknown track.");
+ debug("Received data from errored or unknown track.");
break;
}
if (VCR_TRACK_THREADED(track)) {
@@ -283,7 +284,7 @@ void lia_vcr_push_packet(struct lia_vcr *vcr, struct nn_packet *packet)
return;
} else {
if (!track->client->handle_packet(track->client, packet)) {
- al_log_warn("liana", "Error handling non-buffered packet.");
+ warn("Error handling non-buffered packet.");
}
}
break;
@@ -295,12 +296,13 @@ void lia_vcr_push_packet(struct lia_vcr *vcr, struct nn_packet *packet)
#ifndef CAMU_DIRECT_MODE
nn_signal_stop(&vcr->signal);
#endif
+ debug("Received EOF.");
break;
case LIANA_PACKET_ERROR:
- al_log_warn("liana", "Unhandled error packet.");
+ warn("Unhandled error packet.");
break;
default:
- al_log_warn("liana", "Erroneous packet.");
+ warn("Erroneous packet.");
break;
}
nn_packet_stream_return_packet(vcr->data, packet);
diff --git a/src/libsink/sink.c b/src/libsink/sink.c
index 5038566..5bf9597 100644
--- a/src/libsink/sink.c
+++ b/src/libsink/sink.c
@@ -22,7 +22,7 @@ enum {
enum {
// Created.
- BUFFER_INIT,
+ BUFFER_INIT = 0,
// Set but not configured.
BUFFER_QUEUED,
// Ready to receive data.
@@ -115,14 +115,11 @@ static inline bool entry_video_buffer_held(struct camu_sink_entry *entry)
static void queue_cmd(struct camu_sink *sink, struct camu_sink_cmd cmd)
{
-#ifdef CAMU_SINK_NO_VIDEO
- if (cmd.value.i == CAMU_SINK_VIDEO) return;
-#endif
camu_queue_push(sink->queue, cmd);
nn_signal_send(&sink->queue_signal);
}
-static void request_video_refresh(struct camu_sink *sink)
+static void refresh_video_output(struct camu_sink *sink)
{
#ifndef CAMU_SINK_NO_VIDEO
sink->callback(sink->userdata, CAMU_SINK_REFRESH_VIDEO, 0, NULL);
@@ -207,7 +204,7 @@ static void remove_entry_video_buffer(struct camu_sink_entry *entry)
// It's possible for some of an entry's buffers to be ENDED while others are still ADDED.
// This means entry->ended and BUFFER_ENDED have two distinct considerations.
-// entry->ended: Completely ignored, needs special consideration in CLIENT_REMOVE_BUFFERS.
+// entry->ended: Completely ignored and needs special consideration in CLIENT_REMOVE_BUFFERS.
// BUFFER_ENDED: No-op'd in remove_entry_buffers() and add_or_queue_entry() but otherwise unchanged.
static void remove_entry_buffers(struct camu_sink_entry *entry)
{
@@ -584,7 +581,7 @@ static void maybe_add_to_previous(struct camu_sink *sink, struct camu_sink_entry
al_assert(!previous->ended);
// If none of the entry's buffers are added, we don't care about adding it to previous.
bool dangling_target = target == (struct camu_sink_entry *)0xb00b;
- if (dangling_target || target->ended || !(AUDIO_STATE(previous) == BUFFER_ADDED || VIDEO_STATE(previous) == BUFFER_ADDED)) {
+ if (dangling_target || target->ended || (AUDIO_STATE(previous) != BUFFER_ADDED && VIDEO_STATE(previous) != BUFFER_ADDED)) {
remove_entry_buffers(previous);
return;
}
@@ -608,7 +605,7 @@ static void do_add_entry(struct camu_sink_entry *entry)
});
if (VIDEO_EMPTY(entry)) {
// Clear the screen if skipping from a video to an audio-only entry.
- request_video_refresh(entry->sink);
+ refresh_video_output(entry->sink);
}
queue_cmd(entry->sink, (struct camu_sink_cmd){
.op = (AUDIO_EMPTY(entry) || entry->paused) ? STOP : START,
@@ -629,7 +626,7 @@ void add_audio_if_set_and_buffered(struct camu_sink_entry *entry)
break;
case BUFFER_SET_OR_BUFFERED:
AUDIO_STATE(entry) = BUFFER_ADDED;
- if (VIDEO_ADDED_OR_EMPTY(entry)) {
+ if (VIDEO_ADDED_OR_EMPTY(entry) || VIDEO_IS_SINGLE_FRAME(entry)) {
do_add_entry(entry);
}
break;
@@ -639,6 +636,7 @@ void add_audio_if_set_and_buffered(struct camu_sink_entry *entry)
void add_video_if_set_and_buffered(struct camu_sink_entry *entry)
{
// Single frame entries will be added/removed with ended set.
+ if (entry->ended) al_assert(VIDEO_IS_SINGLE_FRAME(entry));
al_assert(VIDEO_STATE(entry) != BUFFER_INIT);
al_assert(VIDEO_STATE(entry) != BUFFER_QUEUED);
al_assert(VIDEO_STATE(entry) != BUFFER_ADDED);
@@ -649,8 +647,9 @@ void add_video_if_set_and_buffered(struct camu_sink_entry *entry)
break;
case BUFFER_SET_OR_BUFFERED:
VIDEO_STATE(entry) = BUFFER_ADDED;
- if (VIDEO_IS_SINGLE_FRAME(entry)) add_entry_video_buffer(entry);
- if (AUDIO_ADDED_OR_EMPTY(entry)) {
+ if (VIDEO_IS_SINGLE_FRAME(entry)) {
+ add_entry_video_buffer(entry);
+ } else if (AUDIO_ADDED_OR_EMPTY(entry)) {
do_add_entry(entry);
}
break;
@@ -661,11 +660,12 @@ static void switch_to(struct camu_sink *sink, struct camu_sink_entry *target)
{
trace("switch_to("ENTRY_FMT"), current: "ENTRY_FMT".", ENTRY_ARG(target), ENTRY_ARG(sink->current));
- if (sink->current) {
- struct camu_sink_entry *current = sink->current;
+ bool ensure_removed = false;
+ struct camu_sink_entry *current = sink->current;
+ if (current) {
struct camu_sink_entry *detached = sink->detached;
al_assert(current != target);
- bool ensure_removed = detached || current->ended;
+ ensure_removed = detached || current->ended;
if (detached) {
al_assert(detached == current);
sink->detached = NULL;
@@ -676,43 +676,47 @@ static void switch_to(struct camu_sink *sink, struct camu_sink_entry *target)
} else if (!current->ended) {
maybe_add_to_previous(sink, current, target);
}
- if (ensure_removed) {
- if (VIDEO_IS_SINGLE_FRAME(current)) {
- remove_entry_video_buffer(current);
+ }
+
+ bool stop_video = false;
+ bool dangling_target = target == (struct camu_sink_entry *)0xb00b;
+ if (!dangling_target) {
+ if (!target->ended) {
+ remove_previous_if_contains(sink, target);
+ add_or_queue_entry(target);
+ } else {
+ if (VIDEO_IS_SINGLE_FRAME(target)) {
+ add_video_if_set_and_buffered(target);
}
- al_assert(AUDIO_NOT_ADDED(current));
- al_assert(VIDEO_NOT_ADDED(current));
+ stop_video = true;
}
}
- if (target == (struct camu_sink_entry *)0xb00b) {
- sink->current = NULL;
- queue_cmd(sink, (struct camu_sink_cmd){
- .op = STOP,
- .value.i = CAMU_SINK_VIDEO
- });
- request_video_refresh(sink);
- return;
+ if (ensure_removed) {
+ if (VIDEO_IS_SINGLE_FRAME(current)) {
+ remove_entry_video_buffer(current);
+ }
+ al_assert(AUDIO_NOT_ADDED(current));
+ al_assert(VIDEO_NOT_ADDED(current));
}
- if (!target->ended) {
- remove_previous_if_contains(sink, target);
- add_or_queue_entry(target);
- } else {
- if (VIDEO_IS_SINGLE_FRAME(target)) {
- add_video_if_set_and_buffered(target);
- } else {
- queue_cmd(sink, (struct camu_sink_cmd){
- .op = STOP,
- .value.i = CAMU_SINK_VIDEO
- });
+ if (!dangling_target) {
+ sink->current = target;
+ sink->current->audio.ignore_paused = false;
+ if (!sink->current->paused) {
+ camu_audio_buffer_resync(&sink->current->audio.buf);
}
+ } else {
+ sink->current = NULL;
+ stop_video = true;
}
- sink->current = target;
- sink->current->audio.ignore_paused = false;
- if (!sink->current->paused) {
- camu_audio_buffer_resync(&sink->current->audio.buf);
+ if (stop_video) {
+ queue_cmd(sink, (struct camu_sink_cmd){
+ .op = STOP,
+ .value.i = CAMU_SINK_VIDEO
+ });
+ refresh_video_output(sink);
}
}
@@ -798,7 +802,7 @@ static void audio_buffer_callback(void *userdata, u8 op)
nn_mutex_lock(&sink->lock);
// This buffer's state could be ADDED, SET_OR_BUFFERED, or CONFIGURED.
// Having threaded outputs means anything could have happened while waiting on the lock.
- // If we were waiting in CLIENT_REMOVE_BUFFERS, state could very well be CONFIGURED.
+ // If we were waiting in CLIENT_REMOVE_BUFFERS, state could very well be CONFIGURED here.
if (AUDIO_STATE(entry) == BUFFER_ADDED) {
remove_entry_audio_buffer(entry);
}
@@ -824,13 +828,12 @@ static void video_buffer_callback(void *userdata, u8 op)
struct camu_sink_entry *entry = (struct camu_sink_entry *)userdata;
struct camu_sink *sink = entry->sink;
switch (op) {
- case CAMU_BUFFER_BUFFERED: {
+ case CAMU_BUFFER_BUFFERED:
lia_vcr_set_buffered(entry->video.track);
nn_mutex_lock(&sink->lock);
add_video_if_set_and_buffered(entry);
nn_mutex_unlock(&sink->lock);
break;
- }
case CAMU_BUFFER_CORK:
lia_vcr_cork(entry->video.track);
break;
@@ -903,7 +906,8 @@ static void evaluate_and_set_buffer_params(struct camu_sink *sink, struct camu_s
if (!AUDIO_EMPTY(entry) && !ignore_video) {
f64 audio = camu_mixer_get_latency(sink->audio.mixer);
s32 frames = audio / entry->video.buf.avg_frame_duration;
- frames -= sink->video.renderer->get_latency(sink->video.renderer);
+ struct camu_renderer *renderer = sink->video.renderer;
+ if (renderer) frames -= renderer->get_latency(renderer);
camu_video_buffer_set_latency(&entry->video.buf, -frames);
}
// If we're local we don't have to worry about syncing audio-only entries.
@@ -915,7 +919,8 @@ static void evaluate_and_set_buffer_params(struct camu_sink *sink, struct camu_s
f64 audio = camu_mixer_get_latency(sink->audio.mixer);
if (!VIDEO_EMPTY(entry)) {
s32 frames = audio / entry->video.buf.avg_frame_duration;
- frames += sink->video.renderer->get_latency(sink->video.renderer);
+ struct camu_renderer *renderer = sink->video.renderer;
+ if (renderer) frames += renderer->get_latency(renderer);
camu_video_buffer_set_latency(&entry->video.buf, frames);
}
bool ignore_video = VIDEO_EMPTY(entry) || VIDEO_IS_SINGLE_FRAME(entry);
@@ -1062,7 +1067,7 @@ static void client_callback(void *userdata, u8 op, struct camu_codec_stream *str
if (!AUDIO_ENDED_OR_EMPTY(entry)) {
// Remove for re-add in CLIENT_RECONNECTED.
remove_entry_audio_buffer(entry);
- // Remove again for BUFFER_BUFFERED.
+ // Remove again for another add in BUFFER_BUFFERED.
remove_entry_audio_buffer(entry);
}
// Slight optimization. A duplicate frame will still be sent but discarded in the video buffer.
@@ -1187,8 +1192,7 @@ static void client_callback(void *userdata, u8 op, struct camu_codec_stream *str
}
// @TODO: Mark for removal here instead.
- bool removed;
- al_array_remove_checked(sink->entries, entry, removed);
+ bool removed = al_array_remove(sink->entries, entry);
remove_from_queue_by_opaque(sink, entry);
if (entry == sink->target) {
@@ -1230,17 +1234,6 @@ static void client_callback(void *userdata, u8 op, struct camu_codec_stream *str
}
}
-static const char *pause_op_name(u8 pause)
-{
- switch (pause) {
- case LIANA_PAUSE_NONE: return "PAUSE_NONE";
- case LIANA_PAUSE_RESUME: return "PAUSE_RESUME";
- case LIANA_PAUSE_PAUSE: return "PAUSE_PAUSE";
- case LIANA_PAUSE_BOTH: return "PAUSE_BOTH";
- default: al_assert_and_return(NULL);
- };
-}
-
static struct camu_sink_entry *create_entry(struct camu_sink *sink, u32 id)
{
struct camu_sink_entry *entry = al_alloc_object(struct camu_sink_entry);
@@ -1343,7 +1336,7 @@ static bool set_command_callback(void *userdata, struct nn_rpc_connection *conn,
#ifdef CAMU_SINK_LOCAL
(void)at;
al_assert(entry != current);
- trace("set("ENTRY_FMT"), %s[local], created: %s.", ENTRY_ARG(entry), pause_op_name(pause), BOOLSTR(create));
+ trace("set("ENTRY_FMT"), %s[local], created: %s.", ENTRY_ARG(entry), lia_pause_op_name(pause), BOOLSTR(create));
if (current && !current->ended) {
current->audio.ignore_paused = true;
if (!current->paused) {
@@ -1360,7 +1353,7 @@ static bool set_command_callback(void *userdata, struct nn_rpc_connection *conn,
#else
// For target to be set that must mean current is set, armed to pause, and not ended.
struct camu_sink_entry *prev_target = sink->target;
- trace("set("ENTRY_FMT"), %s, created: %s, target: "ENTRY_FMT".", ENTRY_ARG(entry), pause_op_name(pause), BOOLSTR(create), ENTRY_ARG(prev_target));
+ trace("set("ENTRY_FMT"), %s, created: %s, target: "ENTRY_FMT".", ENTRY_ARG(entry), lia_pause_op_name(pause), BOOLSTR(create), ENTRY_ARG(prev_target));
switch (pause) {
case LIANA_PAUSE_NONE:
if (prev_target) {
@@ -1452,7 +1445,7 @@ static bool pause_command_callback(void *userdata, struct nn_rpc_connection *con
if (!entry) goto out;
al_assert(entry->sequence == sequence);
nn_mutex_lock(&sink->lock);
- trace("pause("ENTRY_FMT"), %s, audio_state: %hhu, video_state: %hhu.", ENTRY_ARG(entry), pause_op_name(pause), AUDIO_STATE(entry), VIDEO_STATE(entry));
+ trace("pause("ENTRY_FMT"), %s, audio_state: %hhu, video_state: %hhu.", ENTRY_ARG(entry), lia_pause_op_name(pause), AUDIO_STATE(entry), VIDEO_STATE(entry));
#ifdef CAMU_SINK_LOCAL
(void)at;
sink_local_pause(sink, entry);
@@ -1508,7 +1501,7 @@ static bool seek_command_callback(void *userdata, struct nn_rpc_connection *conn
if (!entry) goto out;
trace("seek("ENTRY_FMT"), reset_id: %u.", ENTRY_ARG(entry), reset_id);
entry->reset_id = reset_id;
- // The rest of the seek is handled in client_callback()'s.
+ // The rest of the seek is handled in CLIENT_REMOVE_BUFFERS/RESUME_AT/RECONNECTED.
lia_client_seek(&entry->client, pos, at);
out:
@@ -1613,13 +1606,12 @@ void camu_sink_toggle_pause(struct camu_sink *sink)
nn_mutex_lock(&sink->lock);
struct camu_sink_entry *current = sink->current;
nn_mutex_unlock(&sink->lock);
- if (current) {
- queue_cmd(sink, (struct camu_sink_cmd){
- .op = TOGGLE_PAUSE,
- .value.f = camu_clock_get_pts(&current->clock, 0.0, false),
- .opaque = current
- });
- }
+ if (!current) return;
+ queue_cmd(sink, (struct camu_sink_cmd){
+ .op = TOGGLE_PAUSE,
+ .value.f = camu_clock_get_pts(&current->clock, 0.0, false),
+ .opaque = current
+ });
}
void camu_sink_seek(struct camu_sink *sink, void *value, u8 mode)
@@ -1663,12 +1655,11 @@ void camu_sink_reseek(struct camu_sink *sink)
nn_mutex_lock(&sink->lock);
struct camu_sink_entry *current = sink->current;
nn_mutex_unlock(&sink->lock);
- if (current) {
- queue_cmd(sink, (struct camu_sink_cmd){
- .op = RESEEK,
- .opaque = current
- });
- }
+ if (!current) return;
+ queue_cmd(sink, (struct camu_sink_cmd){
+ .op = RESEEK,
+ .opaque = current
+ });
}
void camu_sink_shuffle(struct camu_sink *sink)
diff --git a/src/mixer/mixer.c b/src/mixer/mixer.c
index 079b582..fbe3105 100644
--- a/src/mixer/mixer.c
+++ b/src/mixer/mixer.c
@@ -131,6 +131,10 @@ f64 camu_mixer_get_latency(struct camu_mixer *mixer)
static void add_buffer_internal(struct camu_mixer *mixer, struct camu_audio_buffer *buf)
{
+ struct camu_audio_buffer *active;
+ al_array_foreach(mixer->buffers, i, active) {
+ al_assert(active != buf);
+ }
camu_audio_buffer_set_volume(buf, mixer->volume);
#ifdef CAMU_MIXER_THREADED
al_atomic_store(u8)(&buf->ref, 1, AL_ATOMIC_RELAXED);
diff --git a/src/portal/src/post.c b/src/portal/src/post.c
index 6ca8f23..1a8cb20 100644
--- a/src/portal/src/post.c
+++ b/src/portal/src/post.c
@@ -14,7 +14,8 @@ void camu_post_clone(struct camu_post *dest, struct camu_post *src)
dest->type = src->type;
al_str_clone(&dest->unique_id, &src->unique_id);
al_str_clone(&dest->url, &src->url);
- al_array_clone(dest->dates, src->dates);
+ al_array_init(dest->dates);
+ al_array_copy(dest->dates, src->dates);
al_str_clone(&dest->author.unique_id, &src->author.unique_id);
al_wstr_clone(&dest->author.username, &src->author.username);
al_wstr_clone(&dest->author.display_name, &src->author.display_name);
diff --git a/src/portal/src/search.c b/src/portal/src/search.c
index ab14d0e..c66e7a8 100644
--- a/src/portal/src/search.c
+++ b/src/portal/src/search.c
@@ -1,3 +1,4 @@
+#define AL_LOG_SECTION "portal"
#include <al/log.h>
#include "../../server/common.h"
@@ -19,12 +20,12 @@ bool camu_python_init(void)
PyStatus status = Py_PreInitialize(&pre_config);
if (PyStatus_Exception(status)) {
- al_log_error("portal", "Preinitialization failed.");
+ error("Preinitialization failed.");
return false;
}
if (PyImport_AppendInittab("portal", PyInit_portal) == -1) {
- al_log_error("portal", "Could not extend in-built modules table.");
+ error("Could not extend in-built modules table.");
return false;
}
@@ -33,7 +34,7 @@ bool camu_python_init(void)
PyObject *module = PyImport_ImportModule("portal");
if (!module) {
PyErr_Print();
- al_log_error("portal", "Could not import module.");
+ error("Could not import module.");
goto err;
}
@@ -72,7 +73,7 @@ static nn_thread_result NNWT_THREADCALL queue_thread(void *userdata)
if (!have_python) {
// Defer python init.
if (!(have_python = camu_python_init())) {
- al_log_error("portal", "Failed to initialize python.");
+ error("Failed to initialize python.");
break;
}
}
@@ -95,9 +96,9 @@ static nn_thread_result NNWT_THREADCALL queue_thread(void *userdata)
al_array_init(search->pages);
search->bridge = bridge;
al_array_push(bridge->searches, search);
- al_log_info("portal", "New search %x (%.*s).", result.id, al_str_fmt(&cmd->query));
+ info("New search %x (%.*s).", result.id, al_str_x(&cmd->query));
} else {
- al_log_info("portal", "Failed to create search (%.*s).", al_str_fmt(&cmd->query));
+ info("Failed to create search (%.*s).", al_str_x(&cmd->query));
}
al_str_free(&cmd->module);
al_str_free(&cmd->query);
@@ -107,17 +108,14 @@ static nn_thread_result NNWT_THREADCALL queue_thread(void *userdata)
struct camu_search *search = get_search_by_id(bridge, cmd->id);
if (search) {
result.id = search->id;
-
struct camu_result_page *page;
al_array_foreach_ptr(search->pages, j, page) {
if (page->num == cmd->num) break;
}
-
- al_log_info("portal", "Loading page %i (%.*s).", cmd->num, al_str_fmt(&search->query));
+ info("Loading page %i (%.*s).", cmd->num, al_str_x(&search->query));
if (portal_bridge_get_page(search, search->id, cmd->num) == -1) {
break;
}
-
result.page = &al_array_at(search->pages, cmd->num);
if (bridge->cache) {
struct camu_post *post;
@@ -126,7 +124,7 @@ static nn_thread_result NNWT_THREADCALL queue_thread(void *userdata)
}
}
} else {
- al_log_info("portal", "Requested search doesn't exist (id: %d).", search->id);
+ info("Requested search doesn't exist (id: %d).", search->id);
result.id = -1;
}
break;
diff --git a/src/render/renderer_libplacebo.c b/src/render/renderer_libplacebo.c
index 9fbcfc0..bd9a981 100644
--- a/src/render/renderer_libplacebo.c
+++ b/src/render/renderer_libplacebo.c
@@ -214,10 +214,10 @@ static bool renderer_lp_create_renderer(struct camu_renderer *renderer, u32 *wid
#if 0
struct nn_file file;
- if (nn_file_open(&file, al_str_c(""), 0)) {
- char *str;
- size_t len = nn_file_read_as_c_str(&file, &str);
- const struct pl_hook *hook = pl_mpv_user_shader_parse(lr->gpu, (const char *)str, len);
+ if (nn_file_open(&file, &al_str_c(""), 0)) {
+ char *c_str;
+ size_t length = nn_file_read_as_c_str(&file, &c_str);
+ const struct pl_hook *hook = pl_mpv_user_shader_parse(lr->gpu, (const char *)c_str, length);
const struct pl_hook **hooks = al_malloc(sizeof(struct pl_hook *));
hooks[0] = al_malloc(sizeof(struct pl_hook));
al_memcpy((void *)hooks[0], (void *)hook, sizeof(struct pl_hook));
@@ -311,11 +311,17 @@ static void renderer_lp_render(struct camu_renderer *renderer, struct camu_scree
do_gpu_finish |= weighted;
// Terrible hack. Let's us distinguish single frames with the same dimensions.
// Tied to a libplacebo patch to consider info_priv in the hash.
- // Add in last_pts to account for buffer resets. This is a completely
- // broken "hash" of the f64 pts value but hopefully works for now.
+ // Also, add in reset_pts to account for buffer resets. This is a completely
+ // broken "hash" of the f64 pts value but hopefully it works for now.
// https://www.virtualdub.org/blog2/entry_259.html
- f64 last_pts = camu_clock_get_last_pts(video->buf->clock);
- lr->params.info_priv = video->buf + (intptr_t)*((u64 *)&last_pts);
+ intptr_t hash = (intptr_t)video->buf;
+ union { f64 f; u64 u; } pts_hash;
+ pts_hash.f = video->buf->reset_pts;
+ hash += (intptr_t)pts_hash.u;
+#ifdef AL_WE_32BIT
+ hash += (intptr_t)(pts_hash.u >> 32);
+#endif
+ lr->params.info_priv = (void *)hash;
target->crop = mix.frames[0]->crop;
target->crop.x1 *= video->view.zoom / video->view.stretch;
target->crop.y1 *= video->view.zoom * video->view.stretch;
diff --git a/src/screen/screen.c b/src/screen/screen.c
index e35cfa0..62fe7dd 100644
--- a/src/screen/screen.c
+++ b/src/screen/screen.c
@@ -424,13 +424,12 @@ bool camu_screen_create_renderer(struct camu_screen *scr, struct camu_renderer *
static void add_buffer_internal(struct camu_screen *scr, struct camu_video_buffer *buf)
{
- struct camu_screen_video *added;
- al_array_foreach_ptr(scr->videos, i, added) {
- al_assert(added->buf != buf);
+ struct camu_screen_video *active;
+ al_array_foreach_ptr(scr->videos, i, active) {
+ al_assert(active->buf != buf);
}
- struct camu_screen_video video = {
- .buf = buf
- };
+ struct camu_screen_video video = { 0 };
+ video.buf = buf;
struct camu_video_format *fmt = &buf->fmt.req;
if (buf->view.mode != CAMU_VIEW_NONE) {
video.view = buf->view;
diff --git a/src/server/common.h b/src/server/common.h
index ffb98ec..4232de8 100644
--- a/src/server/common.h
+++ b/src/server/common.h
@@ -52,12 +52,8 @@ enum {
#endif
};
-AL_UNUSED_FUNCTION_PUSH
-
-static bool camu_is_url(str *s, u32 i)
+static inline bool camu_is_url(str *s, u32 i)
{
return al_str_cmp(s, &al_str_c("https://"), i, 8) == 0
|| al_str_cmp(s, &al_str_c("http://"), i, 7) == 0;
}
-
-AL_UNUSED_FUNCTION_POP
diff --git a/src/server/db.c b/src/server/db.c
index 3d44e11..fa768e2 100644
--- a/src/server/db.c
+++ b/src/server/db.c
@@ -1,3 +1,4 @@
+#define AL_LOG_SECTION "db"
#include <al/log.h>
#include <nnwt/file.h>
@@ -15,22 +16,20 @@ static void open_user(struct camu_server *server, struct nn_dir *camu_db, struct
if (!nn_file_open(&file, &path, 0)) {
goto out;
}
- str s;
- nn_file_read_as_str(&file, &s);
+ str buffer;
+ nn_file_read_as_str(&file, &buffer);
json_error_t error;
- json_t *root = json_loadb(s.data, s.length, 0, &error);
+ json_t *root = json_loadb(buffer.data, buffer.length, 0, &error);
+ al_str_free(&buffer);
if (!root) {
- al_log_error("server", "Failed to parse %.*s:%d:%d (%s).",
- al_str_fmt(&path), error.line, error.column, error.text);
- al_str_free(&s);
+ error("Failed to parse %.*s:%d:%d (%s).", al_str_x(&path), error.line, error.column, error.text);
goto out;
}
struct camu_user *user = al_alloc_object(struct camu_user);
al_str_from(&user->name, json_string_value(json_object_get(root, "username")));
- al_log_info("server", "Loaded user \"%.*s\"", al_str_fmt(&user->name));
+ info("Loaded user \"%.*s\"", al_str_x(&user->name));
al_array_push(server->users, user);
json_decref(root);
- al_str_free(&s);
out:
al_str_free(&path);
}
diff --git a/src/server/server.c b/src/server/server.c
index a1c3657..d7ff702 100644
--- a/src/server/server.c
+++ b/src/server/server.c
@@ -1,3 +1,4 @@
+#define AL_LOG_SECTION "server"
#include <al/log.h>
#include <al/lib.h>
@@ -106,7 +107,7 @@ static bool identify_callback(void *userdata, struct nn_rpc_connection *conn,
struct camu_server_node *node = al_alloc_object(struct camu_server_node);
node->conn = conn;
al_array_push(server->nodes, node);
- al_log_info("server", "New node.");
+ info("New node.");
break;
}
case CAMU_CLIENT: {
@@ -122,7 +123,7 @@ static bool identify_callback(void *userdata, struct nn_rpc_connection *conn,
}
client->user = user;
al_array_push(server->clients, client);
- al_log_info("server", "User \"%.*s\" logged in.", al_str_fmt(&user->name));
+ info("User \"%.*s\" logged in.", al_str_x(&user->name));
write_initial_user_state(server, user, rpacket);
break;
}
@@ -135,7 +136,7 @@ static bool identify_callback(void *userdata, struct nn_rpc_connection *conn,
sink->server = server;
al_array_push(server->sinks, sink);
handle_toggle_sink(server, &al_str_c("default"), sink, true);
- al_log_info("server", "New sink.");
+ info("New sink.");
break;
}
}
@@ -209,8 +210,9 @@ void handle_toggle_sink(struct camu_server *server, str *name, struct camu_serve
static void process_pending(struct camu_resource *resource)
{
array(struct lia_list_entry *) pending;
+ al_array_init(pending);
// resource->pending may be edited during a list_pump() call.
- al_array_clone(pending, resource->pending);
+ al_array_copy(pending, resource->pending);
resource->pending.count = 0;
struct lia_list_entry *entry;
al_array_foreach(pending, i, entry) {
@@ -282,7 +284,7 @@ static struct cch_entry *entry_from_post(struct camu_server *server, struct camu
}
}
if (!entry) {
- al_log_error("server", "Failed to load post media %.*s %u.", al_str_fmt(&post->unique_id), index);
+ error("Failed to load post media %.*s %u.", al_str_x(&post->unique_id), index);
return NULL;
}
entry->handler->maybe_spawn_worker(entry->handler, 0);
@@ -408,7 +410,7 @@ static void list_callback(void *userdata, u8 op, struct lia_list_entry *entry, v
}
switch (*(u8 *)opaque) {
case LIANA_META_CURRENT_CHANGED:
- al_log_info("server", "Now playing: %ls.", entry->name.data);
+ info("Now playing: %ls.", entry->name.data);
send_clients_current_changed(server, entry->list, entry);
break;
case LIANA_META_ADDED_ENTRY:
@@ -422,7 +424,7 @@ static void list_callback(void *userdata, u8 op, struct lia_list_entry *entry, v
send_clients_entry_seeked(server, entry->list, entry);
break;
case LIANA_META_ENTRY_ERRORED:
- al_log_error("server", "Failed to load: %ls.", entry->name.data);
+ error("Failed to load: %ls.", entry->name.data);
break;
case LIANA_META_ORDER_CHANGED:
break;
@@ -555,7 +557,7 @@ static void simple_search_portal_callback(void *userdata0, void *userdata1, stru
return;
}
// No return is the error case.
- al_log_warn("server", "Failed to process simple search request.");
+ warn("Failed to process simple search request.");
resource->load = LIANA_ENTRY_ERRORED;
}
#endif
@@ -746,7 +748,7 @@ static void connection_closed_callback(void *userdata, struct nn_rpc_connection
struct camu_server_node *node;
al_array_foreach(server->nodes, i, node) {
if (node->conn == conn) {
- al_log_info("server", "Node removed.");
+ info("Node removed.");
cleanup_node(node);
al_array_remove_at(server->nodes, i);
break;
@@ -756,7 +758,7 @@ static void connection_closed_callback(void *userdata, struct nn_rpc_connection
struct camu_server_client *client;
al_array_foreach(server->clients, i, client) {
if (client->conn == conn) {
- al_log_info("server", "User \"%.*s\" logged out.", al_str_fmt(&client->user->name));
+ info("User \"%.*s\" logged out.", al_str_x(&client->user->name));
cleanup_client(client);
al_array_remove_at(server->clients, i);
break;
@@ -766,7 +768,7 @@ static void connection_closed_callback(void *userdata, struct nn_rpc_connection
struct camu_server_sink *sink;
al_array_foreach(server->sinks, i, sink) {
if (sink->conn == conn) {
- al_log_info("server", "Sink removed.");
+ info("Sink removed.");
struct lia_list *list;
al_array_foreach(server->lists, j, list) {
lia_list_remove_sink(list, sink);
diff --git a/src/util/color_palette.c b/src/util/color_palette.c
index 9cfdf32..d386858 100644
--- a/src/util/color_palette.c
+++ b/src/util/color_palette.c
@@ -1,3 +1,4 @@
+#define AL_LOG_SECTION "color_palette"
#include <al/log.h>
#include "color_palette.h"
@@ -41,14 +42,14 @@ bool camu_color_palette_init(str *path)
return false;
}
- str s;
- nn_file_read_as_str(&file, &s);
+ str buffer;
+ nn_file_read_as_str(&file, &buffer);
nn_file_close(&file);
json_error_t error;
- json_t *root = json_loadb(s.data, s.length, 0, &error);
- al_str_free(&s);
+ json_t *root = json_loadb(buffer.data, buffer.length, 0, &error);
+ al_str_free(&buffer);
if (!root) {
- al_log_error("color_palette", "Failed to load %.*s as a json (%s).", al_str_fmt(path), error.text);
+ error("Failed to load %.*s as a json (%s).", al_str_x(path), error.text);
return false;
}
@@ -56,14 +57,14 @@ bool camu_color_palette_init(str *path)
json_t *special = json_object_get(root, "special");
if (!special) {
- al_log_error("color_palette", "\"special\" field missing from the color palette.");
+ error("\"special\" field missing from the color palette.");
parsed = false;
goto out;
}
json_t *colors = json_object_get(root, "colors");
if (!colors) {
- al_log_error("color_palette", "\"colors\" field missing from the color palette.");
+ error("\"colors\" field missing from the color palette.");
parsed = false;
goto out;
}
@@ -77,7 +78,7 @@ bool camu_color_palette_init(str *path)
for (u32 i = 0; i < ARRAY_SIZE(special_colors); i++) {
object = json_object_get(special, special_colors[i]);
if (!object) {
- al_log_error("color_palette", "Couldn't find special color: %s.", special_colors[i]);
+ error("Couldn't find special color: %s.", special_colors[i]);
return false;
}
color = json_string_value(object);
@@ -86,14 +87,14 @@ bool camu_color_palette_init(str *path)
if (!to_long_error) {
global_color_palette.colors[i] = value;
} else {
- al_log_warn("color_palette", "%s is not a valid hex color.", normal_colors[i]);
+ warn("%s is not a valid hex color.", normal_colors[i]);
}
}
for (u32 i = 0; i < ARRAY_SIZE(normal_colors); i++) {
object = json_object_get(colors, normal_colors[i]);
if (!object) {
- al_log_error("color_palette", "Couldn't find color: %s.", normal_colors[i]);
+ error("Couldn't find color: %s.", normal_colors[i]);
return false;
}
color = json_string_value(object);
@@ -102,7 +103,7 @@ bool camu_color_palette_init(str *path)
if (!to_long_error) {
global_color_palette.colors[i + 2] = value;
} else {
- al_log_warn("color_palette", "%s is not a valid hex color.", normal_colors[i]);
+ warn("%s is not a valid hex color.", normal_colors[i]);
}
}
diff --git a/src/util/queue.h b/src/util/queue.h
index d103831..17880e0 100644
--- a/src/util/queue.h
+++ b/src/util/queue.h
@@ -9,62 +9,54 @@
struct nn_mutex mutex; \
}
-#define camu_queue_lock(q) \
-AL_MACRO_WRAP \
-{ \
- nn_mutex_lock(&(q).mutex); \
-} AL_MACRO_END
+#define camu_queue_lock(q) \
+ do { \
+ nn_mutex_lock(&(q).mutex); \
+ } while (0)
-#define camu_queue_unlock(q) \
-AL_MACRO_WRAP \
-{ \
- nn_mutex_unlock(&(q).mutex); \
-} AL_MACRO_END
+#define camu_queue_unlock(q) \
+ do { \
+ nn_mutex_unlock(&(q).mutex); \
+ } while (0)
-#define camu_queue_count(q, r) \
-AL_MACRO_WRAP \
-{ \
- nn_mutex_lock(&(q).mutex); \
- r = (q).a.count; \
- nn_mutex_unlock(&(q).mutex); \
-} AL_MACRO_END
+#define camu_queue_count(q, r) \
+ do { \
+ nn_mutex_lock(&(q).mutex); \
+ r = (q).a.count; \
+ nn_mutex_unlock(&(q).mutex); \
+ } while (0)
-#define camu_queue_init(q) \
-AL_MACRO_WRAP \
-{ \
- al_array_init((q).a); \
- nn_mutex_init(&(q).mutex); \
-} AL_MACRO_END
+#define camu_queue_init(q) \
+ do { \
+ al_array_init((q).a); \
+ nn_mutex_init(&(q).mutex); \
+ } while (0)
-#define camu_queue_push(q, item) \
-AL_MACRO_WRAP \
-{ \
- nn_mutex_lock(&(q).mutex); \
- al_array_push((q).a, item); \
- nn_mutex_unlock(&(q).mutex); \
-} AL_MACRO_END
+#define camu_queue_push(q, item) \
+ do { \
+ nn_mutex_lock(&(q).mutex); \
+ al_array_push((q).a, item); \
+ nn_mutex_unlock(&(q).mutex); \
+ } while (0)
-#define camu_queue_pop(q, r) \
-AL_MACRO_WRAP \
-{ \
- nn_mutex_lock(&(q).mutex); \
- al_array_pop_at((q).a, 0, r); \
- nn_mutex_unlock(&(q).mutex); \
-} AL_MACRO_END
+#define camu_queue_pop(q, r) \
+ do { \
+ nn_mutex_lock(&(q).mutex); \
+ al_array_pop_at((q).a, 0, r); \
+ nn_mutex_unlock(&(q).mutex); \
+ } while (0)
-#define camu_queue_try_pop(q, s, r) \
-AL_MACRO_WRAP \
-{ \
- nn_mutex_lock(&(q).mutex); \
- if ((s = (q).a.count) > 0) { \
- al_array_pop_at((q).a, 0, r); \
- } \
- nn_mutex_unlock(&(q).mutex); \
-} AL_MACRO_END
+#define camu_queue_try_pop(q, s, r) \
+ do { \
+ nn_mutex_lock(&(q).mutex); \
+ if ((s = (q).a.count) > 0) { \
+ al_array_pop_at((q).a, 0, r); \
+ } \
+ nn_mutex_unlock(&(q).mutex); \
+ } while (0)
-#define camu_queue_free(q) \
-AL_MACRO_WRAP \
-{ \
- nn_mutex_destroy(&(q).mutex); \
- al_array_free((q).a); \
-} AL_MACRO_END
+#define camu_queue_free(q) \
+ do { \
+ nn_mutex_destroy(&(q).mutex); \
+ al_array_free((q).a); \
+ } while (0)