Revert "use pipe for mpv wakeup callback"

This reverts commit 72d4e63249.

more trouble than it's worth
This commit is contained in:
Erica Z 2024-10-26 09:10:55 +02:00
parent d666c8fb49
commit 9f6bc7b10b
2 changed files with 100 additions and 130 deletions

View file

@ -57,6 +57,9 @@ public class Playbin : GLib.Object {
public ListStore _play_queue; public ListStore _play_queue;
public ListModel play_queue { get { return this._play_queue; } } public ListModel play_queue { get { return this._play_queue; } }
// try to prevent wait_event to be called twice
private bool is_handling_event = false;
private async Mpv.Error mpv_command_async (string[] args) { private async Mpv.Error mpv_command_async (string[] args) {
CommandCallback cc = {}; CommandCallback cc = {};
@ -67,9 +70,6 @@ public class Playbin : GLib.Object {
return cc.error; return cc.error;
} }
// should be Mpv.WakeupCallback, but i think there's a vala bug here
private SourceOnceFunc wakeup_callback; // anchor reference here, mpv won't remind us
public Playbin () { public Playbin () {
this._play_queue = new ListStore (typeof (Subsonic.Song)); this._play_queue = new ListStore (typeof (Subsonic.Song));
@ -83,42 +83,10 @@ public class Playbin : GLib.Object {
assert (this.mpv.observe_property (2, "playlist-pos", Mpv.Format.INT64) >= 0); assert (this.mpv.observe_property (2, "playlist-pos", Mpv.Format.INT64) >= 0);
assert (this.mpv.observe_property (3, "pause", Mpv.Format.FLAG) >= 0); assert (this.mpv.observe_property (3, "pause", Mpv.Format.FLAG) >= 0);
int wakeup_fds[2]; this.mpv.wakeup_callback = () => {
try { Idle.add (() => {
assert (Unix.open_pipe (wakeup_fds, 0)); if (this.is_handling_event) return false;
} catch (Error e) { this.is_handling_event = true;
error (@"could not open pipe for mpv wakeup: $(e.message)");
}
IOChannel wakeup_read = new IOChannel.unix_new (wakeup_fds[0]);
IOChannel wakeup_write = new IOChannel.unix_new (wakeup_fds[1]);
wakeup_read.set_close_on_unref (true);
wakeup_write.set_close_on_unref (true);
try {
wakeup_read.set_encoding (null);
wakeup_write.set_encoding (null);
wakeup_write.set_buffered (false);
} catch (Error e) {
error (@"could not set up pipes for mpv wakeup: $(e.message)");
}
this.wakeup_callback = () => {
try {
wakeup_write.write_chars ({0}, null);
} catch (Error e) {
error (@"could not write to mpv wakeup pipe: $(e.message)");
}
};
this.mpv.wakeup_callback = this.wakeup_callback;
assert (0 < wakeup_read.add_watch (IOCondition.IN, (source, condition) => {
try {
wakeup_read.read_chars ({0}, null);
} catch (Error e) {
error (@"could not read from mpv wakeup pipe: $(e.message)");
}
while (true) { while (true) {
var event = this.mpv.wait_event (0.0); var event = this.mpv.wait_event (0.0);
@ -228,8 +196,10 @@ public class Playbin : GLib.Object {
} }
} }
return true; this.is_handling_event = false;
})); return false;
});
};
} }
public void seek (double position) { public void seek (double position) {

View file

@ -43,7 +43,7 @@ namespace Mpv {
[CCode (cname = "mpv_wait_event")] [CCode (cname = "mpv_wait_event")]
public unowned Event? wait_event (double timeout); public unowned Event? wait_event (double timeout);
public unowned WakeupCallback wakeup_callback { public WakeupCallback wakeup_callback {
[CCode (cname = "mpv_set_wakeup_callback")] set; [CCode (cname = "mpv_set_wakeup_callback")] set;
} }