summaryrefslogtreecommitdiff
path: root/src/liana
diff options
context:
space:
mode:
authorAndrew Opalach <andrew@akon.city> 2025-03-05 14:37:12 -0500
committerAndrew Opalach <andrew@akon.city> 2025-03-06 16:05:01 -0500
commit46d5660a2582323e1c9c33a56694c322bc21b7bc (patch)
treed7db990d5978eb66847d4daadcd45bd723a62f01 /src/liana
parent2f7e7ed84b6dafa0a81dde686b4a8e7cbecfcd94 (diff)
downloadcamu-46d5660a2582323e1c9c33a56694c322bc21b7bc.tar.gz
camu-46d5660a2582323e1c9c33a56694c322bc21b7bc.tar.bz2
camu-46d5660a2582323e1c9c33a56694c322bc21b7bc.zip
More robust disconnect for errored entries
- Improve >1 width character handling in tui input. Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'src/liana')
-rw-r--r--src/liana/client.c9
-rw-r--r--src/liana/list.c32
-rw-r--r--src/liana/list.h2
3 files changed, 27 insertions, 16 deletions
diff --git a/src/liana/client.c b/src/liana/client.c
index 54b5584..b53fb7e 100644
--- a/src/liana/client.c
+++ b/src/liana/client.c
@@ -13,7 +13,8 @@
enum {
RECONNECT_NONE = 0,
RECONNECT_ON_CONNECTION_CLOSED,
- RECONNECT_SIGNAL_CLIENT
+ RECONNECT_SIGNAL_CLIENT,
+ RECONNECT_DISCONNECTED
};
static void data_packet_callback(void *userdata, struct nn_packet_stream *stream, struct nn_packet *packet)
@@ -259,8 +260,9 @@ void lia_client_connect(struct lia_client *client, struct nn_event_loop *loop,
void lia_client_seek(struct lia_client *client, u64 pos, u64 at)
{
+ if (client->reconnect == RECONNECT_DISCONNECTED) return;
// If reconnect = ON_CONNECTION_CLOSED or SIGNAL_CLIENT, we are safe to edit pos
- // and at inplace because they aren't evaluated until connection_callback().
+ // and at in-place because they aren't evaluated until connection_callback().
client->pos = pos;
client->at = at;
if (client->reconnect == RECONNECT_NONE) {
@@ -277,7 +279,8 @@ void lia_client_reseek(struct lia_client *client)
void lia_client_disconnect(struct lia_client *client)
{
u8 reconnect = client->reconnect;
- client->reconnect = RECONNECT_NONE;
+ al_assert(reconnect != RECONNECT_DISCONNECTED);
+ client->reconnect = RECONNECT_DISCONNECTED;
if (reconnect != RECONNECT_ON_CONNECTION_CLOSED) {
nn_packet_stream_disconnect(&client->data);
}
diff --git a/src/liana/list.c b/src/liana/list.c
index cccca8e..650b6c5 100644
--- a/src/liana/list.c
+++ b/src/liana/list.c
@@ -40,7 +40,7 @@ void lia_list_init(struct lia_list *list, str *name)
al_array_init(list->entries);
al_array_init(list->sinks);
al_array_init(list->command_queue);
- list->active_cmd = NULL;
+ list->cmd = NULL;
}
static bool assume_ended(struct lia_list_entry *entry, u64 at)
@@ -73,10 +73,18 @@ static bool entry_load_and_get_duration(struct lia_list *list, struct lia_list_e
if (status == LIANA_ENTRY_ERRORED) {
if (sequence >= 0) {
al_array_remove_at(list->entries, (u32)sequence);
- if (sequence == list->current && (u32)list->current == list->entries.count) {
- // This maps to the behavior of only skipping ahead on errors.
+ if (list->cmd->sequence == sequence) {
+ // @TODO: This command has to be effectively discarded.
+ list->cmd->sequence = -1;
+ } else if (list->cmd->sequence > sequence) {
+ list->cmd->sequence--;
+ }
+ if (list->current >= sequence) {
list->current--;
- list->idle = true;
+ // This maps to the behavior of only skipping ahead on errors.
+ if ((u32)list->current == list->entries.count) {
+ list->idle = true;
+ }
}
}
*error = true;
@@ -391,7 +399,7 @@ static bool handle_skipto(struct lia_list *list, s32 sequence, s32 index)
static bool handle_skip(struct lia_list *list, s32 sequence, s32 n)
{
if (sequence == LIANA_SEQUENCE_ANY) sequence = list->current;
- struct lia_list_cmd *cmd = list->active_cmd;
+ struct lia_list_cmd *cmd = list->cmd;
cmd->op = SKIPTO;
cmd->sequence = sequence;
cmd->arg0.i = sequence + n;
@@ -556,7 +564,7 @@ static bool handle_end(struct lia_list *list, u32 id, u32 reset_id)
list->queued = -1;
signal_meta(list, queued, LIANA_META_CURRENT_CHANGED);
} else if (next < size) {
- struct lia_list_cmd *cmd = list->active_cmd;
+ struct lia_list_cmd *cmd = list->cmd;
cmd->op = SKIPTO;
cmd->sequence = sequence;
cmd->arg0.i = next;
@@ -573,7 +581,7 @@ static bool handle_end(struct lia_list *list, u32 id, u32 reset_id)
static bool adjust_current(struct lia_list *list, struct lia_list_entry *previous)
{
al_assert(list->current >= 0);
- struct lia_list_cmd *cmd = list->active_cmd;
+ struct lia_list_cmd *cmd = list->cmd;
struct lia_list_entry *entry;
al_array_foreach(list->entries, i, entry) {
if (entry->opaque == previous->opaque) {
@@ -646,11 +654,11 @@ static bool handle_shuffle(struct lia_list *list)
static void run_queue(struct lia_list *list)
{
// @TODO: What does current = -1/currentless really mean.
- if (!list->active_cmd) {
+ if (!list->cmd) {
if (!list->command_queue.count) return;
- al_array_pop_at(list->command_queue, 0, list->active_cmd);
+ al_array_pop_at(list->command_queue, 0, list->cmd);
}
- struct lia_list_cmd *cmd = list->active_cmd;
+ struct lia_list_cmd *cmd = list->cmd;
switch (cmd->op) {
case ADD_SINK:
if (!handle_add_sink(list, cmd->sink)) {
@@ -711,7 +719,7 @@ static void run_queue(struct lia_list *list)
break;
}
al_free(cmd);
- list->active_cmd = NULL;
+ list->cmd = NULL;
pump_queue(list);
}
@@ -876,7 +884,7 @@ void lia_list_free(struct lia_list *list)
al_free(cmd);
}
al_array_free(list->command_queue);
- if (list->active_cmd) al_free(list->active_cmd);
+ if (list->cmd) al_free(list->cmd);
struct lia_list_entry *entry;
al_array_foreach(list->entries, i, entry) {
diff --git a/src/liana/list.h b/src/liana/list.h
index a60790a..0d80dde 100644
--- a/src/liana/list.h
+++ b/src/liana/list.h
@@ -113,7 +113,7 @@ struct lia_list {
array(struct lia_list_entry *) entries;
array(struct lia_list_sink *) sinks;
array(struct lia_list_cmd *) command_queue;
- struct lia_list_cmd *active_cmd;
+ struct lia_list_cmd *cmd;
void (*callback)(void *, u8, struct lia_list_entry *, void *);
void *userdata;
};