diff options
| author | 2024-12-26 11:25:14 -0500 | |
|---|---|---|
| committer | 2024-12-26 11:25:14 -0500 | |
| commit | 9026e7f49f11e920eac666bd4159ec459b979623 (patch) | |
| tree | 999ae6fdf5ea4dbad5e777818a176a6b2d564553 /src/liana | |
| parent | 7021f0625cc018af58d61d7875fbeb21b64d99bf (diff) | |
| download | camu-9026e7f49f11e920eac666bd4159ec459b979623.tar.gz camu-9026e7f49f11e920eac666bd4159ec459b979623.tar.bz2 camu-9026e7f49f11e920eac666bd4159ec459b979623.zip | |
Incomplete buffer errored and sink queued
Signed-off-by: Andrew Opalach <andrew@akon.city>
Diffstat (limited to 'src/liana')
| -rw-r--r-- | src/liana/list.c | 97 | ||||
| -rw-r--r-- | src/liana/list.h | 2 | ||||
| -rw-r--r-- | src/liana/server.c | 4 |
3 files changed, 62 insertions, 41 deletions
diff --git a/src/liana/list.c b/src/liana/list.c index 7c4979b..2280eec 100644 --- a/src/liana/list.c +++ b/src/liana/list.c @@ -49,7 +49,6 @@ void lia_list_init(struct lia_list *list, str *name) { al_str_clone(&list->name, name); list->current = -1; - list->previous = -1; list->queued = -1; list->idle = true; list->increment = 0; @@ -103,6 +102,50 @@ static bool entry_load_and_get_duration(struct lia_list *list, struct lia_list_e return false; } +static void set_queued(struct lia_list *list) +{ + if (list->queued < 0) + return; + + struct lia_list_entry *queued = al_array_at(list->entries, list->queued); + + bool error; + struct lia_list_entry *current = al_array_at(list->entries, list->current); + if (!entry_load_and_get_duration(list, current, list->current, &error)) + return; + + queued->start = current->start + (current->duration - current->offset); + u8 pause = queued->paused_at == LIANA_TIMESTAMP_INVALID ? LIANA_PAUSE_RESUME : LIANA_PAUSE_NONE; + struct lia_timing time = { + .at = queued->start, + .seek_pos = queued->offset, + .pause = pause + }; + + struct lia_list_sink *sink; + al_array_foreach(list->sinks, i, sink) { + if (sink->queued != list->queued) { + sink->queued = list->queued; + sink->callback(sink->userdata, LIANA_SINK_BUFFER_AND_QUEUE, queued, list->queued, &time); + } + } +} + +static void evaluate_queued(struct lia_list *list) +{ + s32 size = (s32)list->entries.size; + s32 next = list->current + 1; + if (next >= size || next == list->queued) + return; + + bool error; + struct lia_list_entry *queued = al_array_at(list->entries, next); + if (!entry_load_and_get_duration(list, queued, next, &error)) + return; + + list->queued = next; +} + static bool handle_add_sink(struct lia_list *list, struct lia_list_sink *sink) { struct lia_list_entry *current; @@ -184,26 +227,7 @@ static bool handle_add(struct lia_list *list, struct lia_list_entry *entry) u8 meta = LIANA_META_PLAYING; list->callback(list->userdata, LIANA_LIST_META, entry, &meta); } else { - /* - if (list->queued == -1) { - // TODODODO: this is based on addeding entry to list->entries BEFORE this point. - struct lia_list_entry *current = al_array_at(list->entries, list->current); - list->queued = list->current + 1; - entry->start = current->start + (current->duration - current->offset); - struct lia_timing time = { - .at = entry->start, - .seek_pos = entry->offset, - .pause = LIANA_PAUSE_RESUME - }; - struct lia_list_sink *sink; - al_array_foreach(list->sinks, i, sink) { - sink->queued = list->queued; - sink->callback(sink->userdata, LIANA_SINK_BUFFER_AND_QUEUE, entry, list->queued, &time); - } - } else { - */ - entry->start = LIANA_TIMESTAMP_INVALID; - //} + entry->start = LIANA_TIMESTAMP_INVALID; u8 meta = LIANA_META_QUEUED; list->callback(list->userdata, LIANA_LIST_META, entry, &meta); } @@ -218,8 +242,8 @@ static void adjust_current(struct lia_list *list, struct lia_list_entry *previou struct lia_list_entry *entry; al_array_foreach(list->entries, i, entry) { if (entry->opaque == previous->opaque) { - list->previous = -1; - if (i == (u32)list->current) return; + if (i == (u32)list->current) + return; cmd->op = SKIPTO; cmd->sequence = i; cmd->value.i = list->current; @@ -234,7 +258,6 @@ static void adjust_current(struct lia_list *list, struct lia_list_entry *previou static void unset_all(struct lia_list *list) { list->current = -1; - list->previous = -1; list->queued = -1; struct lia_list_sink *sink; al_array_foreach(list->sinks, i, sink) { @@ -356,18 +379,16 @@ static bool handle_skipto(struct lia_list *list, s32 sequence, s32 index) current->held = true; } - al_log_debug("list", "skipto [%u-%u]: pause: %hhu, held: %s, current_ended: %s, target_ended: %s.", + al_log_debug("list", "skipto [#%u-#%u]: pause: %hhu, held: %s, current_ended: %s, target_ended: %s.", current->id, target->id, pause, BOOLSTR(current->held), BOOLSTR(current_ended), BOOLSTR(target_ended)); list->current = index; - list->previous = sequence; list->idle = false; struct lia_timing time = { .at = at, .seek_pos = target->offset, .pause = pause, - .previous_ended = current_ended, .ended = target_ended }; @@ -429,7 +450,7 @@ static void handle_toggle_pause(struct lia_list *list, s32 sequence, f64 pts) break; } - al_log_debug("list", "toggle_pause [%u]: pts: %f, pause: %hhu.", entry->id, pts, pause); + al_log_debug("list", "toggle_pause [#%u]: pts: %f, pause: %hhu.", entry->id, pts, pause); struct lia_timing time = { .at = at, @@ -472,7 +493,7 @@ static void handle_seek(struct lia_list *list, s32 sequence, u32 id, f64 percent list->idle = false; - al_log_debug("list", "seek [%u]: pos: %f.", entry->id, pos / 1000000.0); + al_log_debug("list", "seek [#%u]: pos: %f.", entry->id, pos / 1000000.0); struct lia_timing time = { .at = at, @@ -501,6 +522,7 @@ static bool handle_end(struct lia_list *list, s32 id) al_log_warn("list", "Got end() from an already ended resource, ignoring."); return true; } + al_log_debug("list", "end [#%u].", entry->id); entry->ended = true; entry->offset = entry->duration; @@ -509,11 +531,11 @@ static bool handle_end(struct lia_list *list, s32 id) s32 next = sequence + 1; if (list->queued >= 0) { list->current = list->queued; - list->previous = sequence; list->queued = -1; struct lia_list_sink *sink; al_array_foreach(list->sinks, i, sink) { sink->queued = -1; + sink->set = list->current; } struct lia_list_entry *current = al_array_at(list->entries, list->current); u8 meta = LIANA_META_PLAYING; @@ -527,12 +549,6 @@ static bool handle_end(struct lia_list *list, s32 id) return false; } else { list->idle = true; - /* - struct lia_list_sink *sink; - al_array_foreach(list->sinks, i, sink) { - sink->set = -1; - } - */ } } @@ -585,7 +601,7 @@ static void handle_clear(struct lia_list *list) list->entries.size = 0; } -void pump_queue(struct lia_list *list) +static void run_queue(struct lia_list *list) { if (!list->cmd) { if (list->queue.size == 0) return; @@ -651,6 +667,13 @@ void pump_queue(struct lia_list *list) pump_queue(list); } +void pump_queue(struct lia_list *list) +{ + run_queue(list); + //evaluate_queued(list); + //set_queued(list); +} + void lia_list_pump(struct lia_list *list) { pump_queue(list); diff --git a/src/liana/list.h b/src/liana/list.h index 8d47b72..4e5e343 100644 --- a/src/liana/list.h +++ b/src/liana/list.h @@ -60,7 +60,6 @@ struct lia_timing { u64 at; u64 seek_pos; u8 pause; - bool previous_ended; bool ended; }; @@ -97,7 +96,6 @@ struct lia_list_cmd { struct lia_list { str name; s32 current; - s32 previous; s32 queued; bool idle; u32 increment; diff --git a/src/liana/server.c b/src/liana/server.c index 27c253b..f4a6efd 100644 --- a/src/liana/server.c +++ b/src/liana/server.c @@ -37,14 +37,14 @@ static u8 packet_pool_callback(void *userdata, struct nn_packet *packet) static nn_thread_result NNWT_THREADCALL handler_thread(void *userdata) { struct lia_node_connection *conn = (struct lia_node_connection *)userdata; - do { + for (;;) { struct nn_packet *packet = nn_packet_pool_get(&conn->pool); if (!packet) break; conn->handler->step(conn->handler); conn->handler->write_packet(conn->handler, packet); nn_packet_pool_submit(&conn->pool, packet); if (conn->handler->status != CAMU_OK) break; - } while (1); + } nn_packet_pool_flush(&conn->pool); return 0; } |