improve async queue logic hopefully
This commit is contained in:
parent
72e0745d52
commit
c9b67977e0
1 changed files with 9 additions and 33 deletions
|
@ -46,7 +46,7 @@ class Playbin : Object {
|
||||||
public Playbin (ListModel play_queue) {
|
public Playbin (ListModel play_queue) {
|
||||||
this.play_queue = play_queue;
|
this.play_queue = play_queue;
|
||||||
|
|
||||||
this.next_uri = new AsyncQueue<string?> ();
|
this.next_uri = new AsyncQueue<string> ();
|
||||||
this.next_uri.push ("");
|
this.next_uri.push ("");
|
||||||
|
|
||||||
// gstreamer docs: GNOME-based applications, for example, will usually
|
// gstreamer docs: GNOME-based applications, for example, will usually
|
||||||
|
@ -78,30 +78,21 @@ class Playbin : Object {
|
||||||
} else if (this.playing_index+1 == position) {
|
} else if (this.playing_index+1 == position) {
|
||||||
// next track was changed
|
// next track was changed
|
||||||
// try to fix up gapless transition
|
// try to fix up gapless transition
|
||||||
this.next_uri.lock ();
|
string? next_uri = this.next_uri.try_pop ();
|
||||||
switch (this.next_uri.length_unlocked ()) {
|
if (next_uri != null) {
|
||||||
case 1:
|
|
||||||
// we're in luck, about-to-finish hasn't been triggered yet
|
// we're in luck, about-to-finish hasn't been triggered yet
|
||||||
// we can get away with replacing it
|
// we can get away with replacing it
|
||||||
this.next_uri.try_pop_unlocked ();
|
|
||||||
if (this.playing_index+1 < play_queue.get_n_items ()) {
|
if (this.playing_index+1 < play_queue.get_n_items ()) {
|
||||||
Song song = (Song) play_queue.get_item (this.playing_index+1);
|
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 {
|
} else {
|
||||||
this.next_uri.push_unlocked ("");
|
this.next_uri.push ("");
|
||||||
}
|
}
|
||||||
break;
|
} else {
|
||||||
|
|
||||||
case 0:
|
|
||||||
// about-to-finish already triggered
|
// about-to-finish already triggered
|
||||||
// we'll need to stop the new track when it starts playing
|
// we'll need to stop the new track when it starts playing
|
||||||
assert (false); // TODO
|
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.playbin.set_state (Gst.State.PLAYING);
|
||||||
this.next_gapless = false;
|
this.next_gapless = false;
|
||||||
|
|
||||||
this.next_uri.lock ();
|
string? next_uri = this.next_uri.try_pop ();
|
||||||
switch (this.next_uri.length_unlocked ()) {
|
if (next_uri != null) {
|
||||||
case 1:
|
|
||||||
// we're in luck, about-to-finish hasn't been triggered yet
|
// we're in luck, about-to-finish hasn't been triggered yet
|
||||||
this.next_uri.try_pop_unlocked ();
|
} else {
|
||||||
break;
|
|
||||||
|
|
||||||
case 0:
|
|
||||||
// about-to-finish already triggered
|
// about-to-finish already triggered
|
||||||
// we'll need to stop the new track when it starts playing
|
// we'll need to stop the new track when it starts playing
|
||||||
assert (false); // TODO
|
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
|
// ASSUMPTION: about-to-finish will be signalled exactly once per track
|
||||||
|
|
Loading…
Reference in a new issue