improve async queue logic hopefully

This commit is contained in:
Erica Z 2024-10-15 22:14:37 +02:00
parent 72e0745d52
commit c9b67977e0

View file

@ -46,7 +46,7 @@ class Playbin : Object {
public Playbin (ListModel play_queue) {
this.play_queue = play_queue;
this.next_uri = new AsyncQueue<string?> ();
this.next_uri = new AsyncQueue<string> ();
this.next_uri.push ("");
// gstreamer docs: GNOME-based applications, for example, will usually
@ -78,30 +78,21 @@ class Playbin : Object {
} else if (this.playing_index+1 == position) {
// next track was changed
// try to fix up gapless transition
this.next_uri.lock ();
switch (this.next_uri.length_unlocked ()) {
case 1:
string? next_uri = this.next_uri.try_pop ();
if (next_uri != null) {
// we're in luck, about-to-finish hasn't been triggered yet
// we can get away with replacing it
this.next_uri.try_pop_unlocked ();
if (this.playing_index+1 < play_queue.get_n_items ()) {
Song song = (Song) play_queue.get_item (this.playing_index+1);
this.next_uri.push_unlocked (this.api.stream_uri (song.id));
this.next_uri.push (this.api.stream_uri (song.id));
} else {
this.next_uri.push_unlocked ("");
this.next_uri.push ("");
}
break;
case 0:
} else {
// about-to-finish already triggered
// we'll need to stop the new track when it starts playing
assert (false); // TODO
break;
default:
error ("invalid next_uri queue length %u\n", this.next_uri.length_unlocked ());
}
this.next_uri.unlock ();
}
});
@ -193,29 +184,14 @@ class Playbin : Object {
this.playbin.set_state (Gst.State.PLAYING);
this.next_gapless = false;
this.next_uri.lock ();
switch (this.next_uri.length_unlocked ()) {
case 1:
string? next_uri = this.next_uri.try_pop ();
if (next_uri != null) {
// we're in luck, about-to-finish hasn't been triggered yet
this.next_uri.try_pop_unlocked ();
break;
case 0:
} else {
// about-to-finish already triggered
// we'll need to stop the new track when it starts playing
assert (false); // TODO
break;
case -1:
// about-to-finish is blocked
// extremely stupid edge case
assert (false); // TODO
break;
default:
error ("invalid next_uri queue length %u\n", this.next_uri.length_unlocked ());
}
this.next_uri.unlock ();
}
// ASSUMPTION: about-to-finish will be signalled exactly once per track