summaryrefslogtreecommitdiff
path: root/src/sink
diff options
context:
space:
mode:
Diffstat (limited to 'src/sink')
-rw-r--r--src/sink/desktop.c66
-rw-r--r--src/sink/util.h21
2 files changed, 50 insertions, 37 deletions
diff --git a/src/sink/desktop.c b/src/sink/desktop.c
index fa8d623..fcb7cf1 100644
--- a/src/sink/desktop.c
+++ b/src/sink/desktop.c
@@ -15,6 +15,7 @@
#endif
#include "desktop.h"
+#include "util.h"
#ifdef CAMU_SCREEN_DEBUG_KEY
#include "input_simulator.h"
#endif
@@ -30,13 +31,13 @@ static u8 sink_callback(void *userdata, u8 op, u8 type, void *opaque)
case CAMU_SINK_AUDIO: {
struct camu_audio_buffer *buf = (struct camu_audio_buffer *)opaque;
camu_mixer_add_buffer(mixer, buf);
- info("Audio buffer added.");
+ log_info("Audio buffer added.");
break;
}
case CAMU_SINK_VIDEO: {
struct camu_video_buffer *buf = (struct camu_video_buffer *)opaque;
camu_screen_add_buffer(scr, buf);
- info("Video buffer added.");
+ log_info("Video buffer added.");
break;
}
}
@@ -46,13 +47,13 @@ static u8 sink_callback(void *userdata, u8 op, u8 type, void *opaque)
case CAMU_SINK_AUDIO: {
struct camu_audio_buffer *buf = (struct camu_audio_buffer *)opaque;
camu_mixer_remove_buffer(mixer, buf);
- info("Audio buffer removed.");
+ log_info("Audio buffer removed.");
break;
}
case CAMU_SINK_VIDEO: {
struct camu_video_buffer *buf = (struct camu_video_buffer *)opaque;
camu_screen_remove_buffer(scr, buf);
- info("Video buffer removed.");
+ log_info("Video buffer removed.");
break;
}
}
@@ -61,12 +62,12 @@ static u8 sink_callback(void *userdata, u8 op, u8 type, void *opaque)
switch (type) {
case CAMU_SINK_AUDIO:
camu_mixer_resume(mixer);
- info("Audio started.");
+ log_info("Audio started.");
break;
case CAMU_SINK_VIDEO:
camu_screen_set_state(scr, CAMU_SCREEN_PLAYING);
camu_screen_wake(scr);
- info("Video started.");
+ log_info("Video started.");
break;
}
break;
@@ -74,11 +75,11 @@ static u8 sink_callback(void *userdata, u8 op, u8 type, void *opaque)
switch (type) {
case CAMU_SINK_AUDIO:
camu_mixer_pause(mixer);
- info("Audio stopped.");
+ log_info("Audio stopped.");
break;
case CAMU_SINK_VIDEO:
camu_screen_set_state(scr, CAMU_SCREEN_PAUSED);
- info("Video stopped.");
+ log_info("Video stopped.");
break;
}
break;
@@ -109,50 +110,41 @@ static u8 sink_callback(void *userdata, u8 op, u8 type, void *opaque)
return CAMU_SINK_OK;
}
-static char status[128];
+static char status[64];
static void print_status(struct camu_sink *sink)
{
struct camu_sink_entry *current = camu_sink_get_current(sink);
if (!current) {
- info("Not playing.");
camu_sink_return_current(sink);
- return;
+ goto notplaying;
}
- f64 pts = camu_clock_get_last_pts(&current->clock);
- f64 duration = current->client.duration / 1000000.0;
+ u64 pts = camu_clock_get_last_pts(&current->clock) * 1000000u;
+ u64 duration = current->client.duration;
+ pts = MIN(duration, pts);
bool paused = current->paused;
camu_sink_return_current(sink);
- s32 text = 0;
- if (paused) {
- text += al_snprintf(status + text, sizeof(status) - text, "⏸ ");
- } else {
- text += al_snprintf(status + text, sizeof(status) - text, "⏵ ");
+ u64 remaining = duration - pts;
+ if (remaining == 0) {
+ goto notplaying;
}
- text += al_snprintf(status + text, sizeof(status) - text, "[");
+ bool show_hour = duration > 60u * 60u * 1000000u;
+ s32 offset = al_snprintf(status, sizeof(status), paused ? "⏸ " : "⏵ ");
+ offset += al_snprintf(status + offset, sizeof(status) - offset, "[");
+ offset += camu_print_time(status + offset, sizeof(status) - offset, pts, show_hour, 2);
+ offset += al_snprintf(status + offset, sizeof(status) - offset, "/");
+ offset += camu_print_time(status + offset, sizeof(status) - offset, duration, show_hour, 2);
+ offset += al_snprintf(status + offset, sizeof(status) - offset, "]");
+ status[offset] = '\0';
- u32 minute = (u32)(pts / 60);
- u32 hour = minute / 60;
- minute -= hour * 60;
- bool show_hour = duration >= 60.0 * 60.0;
- if (show_hour) text += al_snprintf(status + text, sizeof(status) - text, "%.2d:", hour);
- text += al_snprintf(status + text, sizeof(status) - text, "%.2d:%.2d/", minute, (u32)pts % 60);
-
- minute = (u32)(duration / 60);
- hour = minute / 60;
- minute -= hour * 60;
- if (show_hour) text += al_snprintf(status + text, sizeof(status) - text, "%.2d:", hour);
- text += al_snprintf(status + text, sizeof(status) - text, "%.2d:%.2d", minute, (u32)duration % 60);
-
- text += al_snprintf(status + text, sizeof(status) - text, "]");
-
- status[text] = '\0';
-
- info("%s", status);
+ log_info("%s", status);
+ return;
+notplaying:
+ log_info("Not playing.");
}
static void screen_callback(void *userdata, u8 op, void *opaque)
diff --git a/src/sink/util.h b/src/sink/util.h
new file mode 100644
index 0000000..d9dd4cc
--- /dev/null
+++ b/src/sink/util.h
@@ -0,0 +1,21 @@
+#pragma once
+
+#include <al/lib.h>
+
+static inline s32 camu_print_time(char *buf, size_t size, u64 nanoseconds, bool always_show_hour, u32 hour_padding)
+{
+ u32 hours = nanoseconds / 3600000000u;
+ u32 minutes = nanoseconds / 60000000u;
+ bool show_hour = always_show_hour || minutes >= 60u;
+ u32 seconds = nanoseconds / 1000000u;
+ seconds -= minutes * 60u;
+ minutes -= hours * 60u;
+ s32 offset = 0;
+ if (show_hour) {
+ static const char *padding_table[] = { "%.2u:", "%.3u:", "%.4u:" };
+ hour_padding = CLAMP(hour_padding, 2u, 4u) - 2u;
+ offset += al_snprintf(buf, size, padding_table[hour_padding], hours);
+ }
+ offset += al_snprintf(buf + offset, size - offset, "%.2u:%.2u", minutes, seconds);
+ return offset;
+}