diff options
| author | 2025-03-15 20:40:38 -0400 | |
|---|---|---|
| committer | 2025-03-15 20:40:38 -0400 | |
| commit | 846bd3d1b7bcec3653aa9d662f559235c4689e1b (patch) | |
| tree | 56906544460079681f46d23d48d76f1a8242ea75 /src/sink | |
| parent | 46d5660a2582323e1c9c33a56694c322bc21b7bc (diff) | |
| download | camu-846bd3d1b7bcec3653aa9d662f559235c4689e1b.tar.gz camu-846bd3d1b7bcec3653aa9d662f559235c4689e1b.tar.bz2 camu-846bd3d1b7bcec3653aa9d662f559235c4689e1b.zip | |
Sink refactor wip
Dangling target won't stay around. I have a couple of ideas about how to massively simplify the handling of ended entries.
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'src/sink')
| -rw-r--r-- | src/sink/common.c | 84 | ||||
| -rw-r--r-- | src/sink/common.h | 4 | ||||
| -rw-r--r-- | src/sink/desktop.c | 188 | ||||
| -rw-r--r-- | src/sink/input_simulator.c | 2 | ||||
| -rw-r--r-- | src/sink/meson.build | 2 |
5 files changed, 151 insertions, 129 deletions
diff --git a/src/sink/common.c b/src/sink/common.c deleted file mode 100644 index 9ed6a44..0000000 --- a/src/sink/common.c +++ /dev/null @@ -1,84 +0,0 @@ -#include <al/log.h> - -#include "../libsink/sink.h" - -#include "common.h" - -bool camu_default_sink_callback(struct camu_screen *scr, struct camu_mixer *mixer, u8 op, u8 type, void *opaque) -{ - switch (op) { - case CAMU_SINK_ADD_BUFFER: - switch (type) { - case CAMU_SINK_AUDIO: { - struct camu_audio_buffer *buf = (struct camu_audio_buffer *)opaque; - camu_mixer_add_buffer(mixer, buf); - al_log_info("camu_desktop", "Audio buffer added."); - break; - } - case CAMU_SINK_VIDEO: { - struct camu_video_buffer *buf = (struct camu_video_buffer *)opaque; - camu_screen_add_buffer(scr, buf); - al_log_info("camu_desktop", "Video buffer added."); - break; - } - } - break; - case CAMU_SINK_REMOVE_BUFFER: - switch (type) { - case CAMU_SINK_AUDIO: { - struct camu_audio_buffer *buf = (struct camu_audio_buffer *)opaque; - camu_mixer_remove_buffer(mixer, buf); - al_log_info("camu_desktop", "Audio buffer removed."); - break; - } - case CAMU_SINK_VIDEO: { - struct camu_video_buffer *buf = (struct camu_video_buffer *)opaque; - camu_screen_remove_buffer(scr, buf); - al_log_info("camu_desktop", "Video buffer removed."); - break; - } - } - break; - case CAMU_SINK_START: - switch (type) { - case CAMU_SINK_AUDIO: - camu_mixer_resume(mixer); - al_log_info("camu_desktop", "Audio started."); - break; - case CAMU_SINK_VIDEO: - camu_screen_set_state(scr, CAMU_SCREEN_PLAYING); - camu_screen_wake(scr); - al_log_info("camu_desktop", "Video started."); - break; - } - break; - case CAMU_SINK_STOP: - switch (type) { - case CAMU_SINK_AUDIO: - camu_mixer_pause(mixer); - al_log_info("camu_desktop", "Audio stopped."); - break; - case CAMU_SINK_VIDEO: - camu_screen_set_state(scr, CAMU_SCREEN_PAUSED); - al_log_info("camu_desktop", "Video stopped."); - break; - } - break; - case CAMU_SINK_REFRESH_VIDEO: - camu_screen_force_refresh(scr); - break; - case CAMU_SINK_CLEAR: - switch (type) { - case CAMU_SINK_AUDIO: - camu_mixer_clear(mixer); - break; - case CAMU_SINK_VIDEO: - camu_screen_clear(scr); - break; - } - break; - case CAMU_SINK_EXIT: - return false; - } - return true; -} diff --git a/src/sink/common.h b/src/sink/common.h deleted file mode 100644 index 5d02ed1..0000000 --- a/src/sink/common.h +++ /dev/null @@ -1,4 +0,0 @@ -#include "../screen/screen.h" -#include "../mixer/mixer.h" - -bool camu_default_sink_callback(struct camu_screen *scr, struct camu_mixer *mixer, u8 op, u8 type, void *opaque); diff --git a/src/sink/desktop.c b/src/sink/desktop.c index 73a1667..6632827 100644 --- a/src/sink/desktop.c +++ b/src/sink/desktop.c @@ -1,7 +1,13 @@ +#define AL_LOG_SECTION "desktop" #include <al/log.h> +//#define DESKTOP_NULL_AUDIO + +#ifdef DESKTOP_NULL_AUDIO #include "../mixer/audio_null.h" +#else #include "../mixer/audio_miniaudio.h" +#endif #if defined CAMU_RENDERER_TIGER #include "../render/renderer_tiger.h" #elif defined CAMU_RENDERER_LIBPLACEBO @@ -9,7 +15,6 @@ #endif #include "desktop.h" -#include "common.h" #ifdef CAMU_SCREEN_DEBUG_KEY #include "input_simulator.h" #endif @@ -17,52 +22,169 @@ static u8 sink_callback(void *userdata, u8 op, u8 type, void *opaque) { struct camu_desktop *c = (struct camu_desktop *)userdata; - - if (op == CAMU_SINK_MOCK_CLOSE) { + struct camu_mixer *mixer = &c->mixer; + struct camu_screen *scr = &c->scr; + switch (op) { + case CAMU_SINK_MOCK_CLOSE: c->should_quit = 1; camu_screen_wake(&c->scr); - return CAMU_SINK_OK; - } - - if (!camu_default_sink_callback(&c->scr, &c->mixer, op, type, opaque)) { + break; + case CAMU_SINK_ADD_BUFFER: + switch (type) { + case CAMU_SINK_AUDIO: { + struct camu_audio_buffer *buf = (struct camu_audio_buffer *)opaque; + camu_mixer_add_buffer(mixer, buf); + 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."); + break; + } + } + break; + case CAMU_SINK_REMOVE_BUFFER: + switch (type) { + case CAMU_SINK_AUDIO: { + struct camu_audio_buffer *buf = (struct camu_audio_buffer *)opaque; + camu_mixer_remove_buffer(mixer, buf); + 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."); + break; + } + } + break; + case CAMU_SINK_START: + switch (type) { + case CAMU_SINK_AUDIO: + camu_mixer_resume(mixer); + info("Audio started."); + break; + case CAMU_SINK_VIDEO: + camu_screen_set_state(scr, CAMU_SCREEN_PLAYING); + camu_screen_wake(scr); + info("Video started."); + break; + } + break; + case CAMU_SINK_STOP: + switch (type) { + case CAMU_SINK_AUDIO: + camu_mixer_pause(mixer); + info("Audio stopped."); + break; + case CAMU_SINK_VIDEO: + camu_screen_set_state(scr, CAMU_SCREEN_PAUSED); + info("Video stopped."); + break; + } + break; + case CAMU_SINK_REFRESH_VIDEO: + camu_screen_force_refresh(scr); + break; + case CAMU_SINK_CLEAR: + switch (type) { + case CAMU_SINK_AUDIO: + camu_mixer_clear(mixer); + break; + case CAMU_SINK_VIDEO: + camu_screen_clear(scr); + break; + } + break; + case CAMU_SINK_EXIT: camu_sink_close(&c->sink); if (c->exit_callback) { c->exit_callback(c->userdata, c); } } - return CAMU_SINK_OK; } +static char status[128]; + +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; + } + + f64 pts = camu_clock_get_last_pts(¤t->clock); + f64 duration = current->client.duration / 1000000.0; + 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, "⏵ "); + } + + text += al_snprintf(status + text, sizeof(status) - text, "["); + + 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); +} + static void screen_callback(void *userdata, u8 op, void *opaque) { struct camu_desktop *c = (struct camu_desktop *)userdata; switch (op) { - case CAMU_SCREEN_NEXT: - camu_sink_skip(&c->sink, 1); + case CAMU_SCREEN_SET_VOLUME: + camu_mixer_set_volume(&c->mixer, *(f32 *)opaque); break; - case CAMU_SCREEN_PREVIOUS: - camu_sink_skip(&c->sink, -1); + case CAMU_SCREEN_OFFSET_VOLUME: + camu_mixer_offset_volume(&c->mixer, *(f32 *)opaque); break; - case CAMU_SCREEN_SHUFFLE: - camu_sink_shuffle(&c->sink); + case CAMU_SCREEN_SKIP: + camu_sink_skip(&c->sink, *(s32 *)opaque); break; case CAMU_SCREEN_TOGGLE_PAUSE: camu_sink_toggle_pause(&c->sink); break; - case CAMU_SCREEN_SEEK: { - f64 percent = *(f64 *)opaque; - camu_sink_seek(&c->sink, percent); + case CAMU_SCREEN_PERCENT_SEEK: + camu_sink_seek(&c->sink, opaque, CAMU_SEEK_PERCENT); break; - } - case CAMU_SCREEN_RELATIVE_SEEK: { - f64 offset = *(f64 *)opaque; - camu_sink_relative_seek(&c->sink, offset); + case CAMU_SCREEN_RELATIVE_SEEK: + camu_sink_seek(&c->sink, opaque, CAMU_SEEK_RELATIVE); break; - } case CAMU_SCREEN_RESEEK: camu_sink_reseek(&c->sink); break; + case CAMU_SCREEN_SHUFFLE: + camu_sink_shuffle(&c->sink); + break; + case CAMU_SCREEN_STATUS: + print_status(&c->sink); + break; #ifdef CAMU_SCREEN_DEBUG_KEY case CAMU_SCREEN_DEBUG: if (camu_input_simulator_running()) { @@ -70,23 +192,8 @@ static void screen_callback(void *userdata, u8 op, void *opaque) } else { camu_input_simulator_run(&c->sink); } - //camu_sink_unset(&c->sink); break; #endif - case CAMU_SCREEN_SET_VOLUME: { - f32 volume = *(f32 *)opaque; - camu_sink_set_volume(&c->sink, volume); - break; - } - case CAMU_SCREEN_OFFSET_VOLUME: { - f64 amount = *(f64 *)opaque; - camu_sink_offset_volume(&c->sink, (f32)amount); - break; - } - case CAMU_SCREEN_STATUS: { - camu_sink_status(&c->sink); - break; - } case CAMU_SCREEN_CLOSE: c->should_quit = 1; break; @@ -109,8 +216,11 @@ bool camu_desktop_init(struct camu_desktop *c, const char *name) return false; } c->renderer->render(c->renderer, &c->scr, true); +#ifdef DESKTOP_NULL_AUDIO + if (!camu_mixer_init(&c->mixer, (struct camu_audio *)&audio_plugin_null)) { +#else if (!camu_mixer_init(&c->mixer, camu_audio_miniaudio_create())) { - //if (!camu_mixer_init(&c->mixer, (struct camu_audio *)&audio_plugin_null)) { +#endif return false; } if (!c->mixer.audio->configure_stream(c->mixer.audio, NULL)) { @@ -130,7 +240,7 @@ bool camu_desktop_connect(struct camu_desktop *c, u8 type, struct nn_event_loop al_str_from(&c->sink.default_list, "default"); c->sink.callback = sink_callback; c->sink.userdata = c; - return camu_sink_connect(&c->sink, type, addr, port, &al_str_c("desktop")); + return camu_sink_connect(&c->sink, &al_str_c("desktop"), type, addr, port); } bool camu_desktop_tick(struct camu_desktop *c) diff --git a/src/sink/input_simulator.c b/src/sink/input_simulator.c index 9cf395f..80fde02 100644 --- a/src/sink/input_simulator.c +++ b/src/sink/input_simulator.c @@ -41,7 +41,7 @@ static nn_thread_result NNWT_THREADCALL input_simulation_thread(void *userdata) if (pos < 0.005) pos = 0.0; if (pos > 0.995) pos = 1.0; else if (pos > 0.99) pos = .9999; - camu_sink_seek(sink, pos); + camu_sink_seek(sink, &pos, CAMU_SEEK_PERCENT); break; } } diff --git a/src/sink/meson.build b/src/sink/meson.build index 0c115f8..8d13b26 100644 --- a/src/sink/meson.build +++ b/src/sink/meson.build @@ -1,4 +1,4 @@ -desktop_src = ['desktop.c', 'common.c', 'input_simulator.c'] +desktop_src = ['desktop.c', 'input_simulator.c'] desktop_deps = [libsink] desktop_args = ['-DCAMU_MIXER_THREADED', '-DCAMU_SCREEN_THREADED'] desktop = declare_dependency(sources: desktop_src, dependencies: desktop_deps, compile_args: desktop_args) |