From 7e5043a2505efa383ae372662fa4849051cd9799 Mon Sep 17 00:00:00 2001 From: Andrew Opalach Date: Sat, 11 Nov 2023 17:51:49 -0500 Subject: Improve basic cmv usage - Make cap more robust - Disable ECHO in the TUI - Improve youtube playback url selection - Some cleanup Signed-off-by: Andrew Opalach --- src/fruits/cmv/cmv2.c | 13 +++++++++---- src/fruits/cmv/tui.c | 14 +++++++++++--- src/fruits/cmv/tui.h | 5 ++++- 3 files changed, 24 insertions(+), 8 deletions(-) (limited to 'src/fruits/cmv') diff --git a/src/fruits/cmv/cmv2.c b/src/fruits/cmv/cmv2.c index d8f4fc2..3c70317 100644 --- a/src/fruits/cmv/cmv2.c +++ b/src/fruits/cmv/cmv2.c @@ -42,8 +42,6 @@ struct cmv { #endif }; -static struct cmv c; - static str *default_list = al_str_c("default"); static u8 sink_callback(void *userdata, u8 op, u8 type, void *opaque) @@ -97,6 +95,10 @@ static u8 sink_callback(void *userdata, u8 op, u8 type, void *opaque) } } break; + case CAMU_SINK_SET_BUFFERED: { + cap_list_pump(&c->cap, default_list, true); + break; + } case CAMU_SINK_START: switch (type) { case CAMU_SINK_AUDIO: { @@ -177,6 +179,7 @@ static bool cap_callback(void *userdata, u8 op, str *name, str *unique_id, void return camu_sink_local_buffer(&c->sink, unique_id, (struct cch_entry *)opaque); case CAP_SET: camu_sink_local_set(&c->sink, unique_id); + al_log_info("cmv", "Now playing: %.*s.", AL_STR_PRINTF(unique_id)); break; case CAP_SWAP: camu_sink_local_swap(&c->sink, unique_id); @@ -237,12 +240,14 @@ s32 main(s32 argc, char *argv[]) { aki_common_init(); + struct cmv c = { }; + #if CMV_USE_TUI if (!tui_init(&c.tui)) { aki_common_close(); return EXIT_FAILURE; } - al_set_print(&c, log_callback); + al_set_print(log_callback, &c); #ifdef HAVE_FFMPEG camu_lav_set_log_callback(lav_log_callback); #endif @@ -297,7 +302,7 @@ s32 main(s32 argc, char *argv[]) #if CMV_USE_TUI aki_timer_init(&c.timer, &c.loop, timer_callback, &c); - aki_timer_set_repeat(&c.timer, 0.15); + aki_timer_set_repeat(&c.timer, 0.10); aki_timer_again(&c.timer); #endif diff --git a/src/fruits/cmv/tui.c b/src/fruits/cmv/tui.c index 84a1846..21aeac8 100644 --- a/src/fruits/cmv/tui.c +++ b/src/fruits/cmv/tui.c @@ -1,7 +1,6 @@ #include #include #include -#include #include "tui.h" @@ -31,15 +30,22 @@ bool tui_init(struct cmv_tui *tui) tui->height = 0; //tui->prev_lines = 0; - tui->fd = STDIN_FILENO; + tui->fd = fileno(stdin); tui->out = fdopen(tui->fd, "w"); if (!tui->out) return false; - setbuf(tui->out, NULL); tui_global = tui; aki_mutex_init(&tui->mutex); signal(SIGWINCH, handle_winch); + // Disable buffer. + setbuf(tui->out, NULL); + + // Disable echo. + tcgetattr(tui->fd, &tui->term); + tui->term.c_lflag &= ~ECHO; + tcsetattr(tui->fd, 0, &tui->term); + al_array_init(tui->log_buffer); tui->last_pts = 0.0; @@ -114,5 +120,7 @@ void tui_close(struct cmv_tui *tui) aki_mutex_destroy(&tui->mutex); fprintf(tui->out, "\n"); fflush(tui->out); + tui->term.c_lflag |= ECHO; + tcsetattr(tui->fd, 0, &tui->term); fclose(tui->out); } diff --git a/src/fruits/cmv/tui.h b/src/fruits/cmv/tui.h index 8cf58c0..fb4215e 100644 --- a/src/fruits/cmv/tui.h +++ b/src/fruits/cmv/tui.h @@ -1,18 +1,21 @@ #pragma once +#include + #include "../../bimu/local.h" #include "../../buffer/clock.h" struct cmv_tui { s32 fd; FILE *out; + struct aki_mutex mutex; + struct termios term; bool update_size; u32 width; u32 height; //u32 prev_lines; array(char *) log_buffer; f64 last_pts; - struct aki_mutex mutex; }; bool tui_init(struct cmv_tui *tui); -- cgit v1.2.3-101-g0448