me

/

vendetta Public
17 commits 0 issues 0 pull requests 1 contributor Discussions Projects Snippets LOC history Platform CI

fix playback (updated V video, fix pipewire audio)

diviocity committed last Nov 7 · be31fb5eab1ef975e9fa113cce91e677eca2c557 View patch
Unverified signature 4 files changed +59 -10
AGENTS.md +14 -3

@@ -449,7 +449,12 @@ time the widget's surface id is handed to the GL renderer, because it needs

449449the host's GL context. On that first call the widget also claims its wake

450450slot, registers the render update callback, spawns the relay, and flushes

451451its `startup` queue into mpv (`loadfile ... replace` for the first,

452-`append-play` for the rest).

452+`append-play` for the rest). ui2 calls the surface renderer one frame after

453+the `opengl` element first appears, and an on-demand window asks for no second

454+frame by itself, so `build()` asks for one paint (`ui2.request_paint`) while

455+the render context is still nil. Without that ask, startup depended on a

456+stray X event or timer landing after the first frame. When none did, nothing

457+loaded and playback never started.

453458

454459`destroy()` is the teardown twin of the first draw: it parks and joins the

455460relay (`stop_relay` — flag + one bump empties the parked wait so a destroy

@@ -867,7 +872,10 @@ Every window event string goes through `handle(event)` then

867872

868873- `track:<audio|sub|video>:<id>` → writes `aid`/`sid`/`vid` async (50).

869874- `chapter:<i>` → `chapter` write (51).

870-- `audio_device:<name>` → `audio-device` write (56).

875+- `audio_device:<name>` → `audio-device` write (56). The Output device

876+ menu lists only the devices `device_fits_ao` allows under the current

877+ server. A pinned `ao` ignores another driver's `driver/device` and keeps

878+ playing on its own default sink.

871879- `ao_server:<name>` → app mirror + `ao` write (`''` for auto, 57), an

872880 immediate `refresh_media_async(true)` (the device list belongs to the new

873881 server; the device property silently changes once the server runs) + menus.

@@ -1064,7 +1072,10 @@ which is slow and can block for a long time against a dead server, so the

10641072per-file and per-selection bursts never ask for devices; only the start-up

10651073pass and the audio-server/output-device writes do. Results arrive on

10661074`media_chan` and `drain_media` applies them (`set_menu_bar` follows;

1067-`media_read_busy` released; a dirty flag re-reads without devices).

1075+`media_read_busy` released; a dirty flag re-reads without devices). Each

1076+`MediaData` carries `read_devices`, and only a read that asked for devices

1077+replaces `p.devices`. Before this, the file-load read emptied the Output

1078+device menu.

10681079

10691080### 7.12 Settings, queue, migration

10701081

libvendetta/draw.v +8 -0

@@ -763,6 +763,14 @@ pub fn (mut p Player) build(frame ui2.Rect) ui2.Element {

763763 video_rect := ui2.rect(0, 0, frame.width, video_h)

764764 // Overlay controls hide on a rest deadline; docked controls never hide.

765765 controls_shown := p.strip_shown()

766+ // ui2 hands an opengl element to the surface renderer one frame after it

767+ // first appears, and the render context, the relay and the startup files

768+ // all wait for that first draw. An on-demand window asks for no second

769+ // frame by itself, so until the surface has drawn, every build asks for

770+ // one paint; once the context is up, the relay paces the frames.

771+ if p.render_ctx == unsafe { nil } {

772+ ui2.request_paint()

773+ }

766774 mut children := [ui2.opengl(video_surface_id, video_rect)]

767775 if !controls_shown {

768776 return ui2.view(root_id, frame, ui2.BoxStyle{ transparent: true }, children)

src/media.v +15 -7

@@ -599,10 +599,13 @@ fn (mut p Player) show_thumb() {

599599// slow, can block a long time against a dead server, and rarely changes. The

600600// file-load and track bursts therefore carry no devices; the device readers —

601601// the start-up pass and the audio-device/ao writes — ask for them.

602+// read_devices tells drain_media whether devices is a fresh list or merely

603+// left unread: a read without the devices must keep the menu's last list.

602604struct MediaData {

603- tracks []Track

604- chapters []Chapter

605- devices []AudioDevice

605+ tracks []Track

606+ chapters []Chapter

607+ devices []AudioDevice

608+ read_devices bool

606609}

607610

608611// read_media_worker runs on its own thread. libmpv core calls are safe from

@@ -655,9 +658,10 @@ fn read_media_worker(ctx voidptr, res chan MediaData, with_devices bool) {

655658 }

656659 }

657660 res <- MediaData{

658- tracks: tracks

659- chapters: chapters

660- devices: devices

661+ tracks: tracks

662+ chapters: chapters

663+ devices: devices

664+ read_devices: with_devices

661665 }

662666}

663667

@@ -694,7 +698,11 @@ fn (mut p Player) drain_media() {

694698 }

695699 p.tracks = data.tracks

696700 p.chapters = data.chapters

697- p.devices = data.devices

701+ // The per-file reads skip the devices; only a read that asked for

702+ // them replaces the list, or every file load would empty the menu.

703+ if data.read_devices {

704+ p.devices = data.devices

705+ }

698706 p.media_read_busy = false

699707 ui2.set_menu_bar(p.menus())

700708 if p.media_dirty {

src/player.v +22 -0

@@ -1775,6 +1775,12 @@ fn (mut p Player) handle_media(event string) bool {

17751775 // belongs to the new server, so this explicit hand-off re-reads it

17761776 // (the device property silently changes once the server runs).

17771777 mpv.set_string_async(p.mpv_ctx, 57, 'ao', if name == 'auto' { '' } else { name })

1778+ // A device of the old server means nothing to the new one: mpv

1779+ // would play on the new server's default while the menu still

1780+ // ticked the old device, so the choice goes back to auto.

1781+ if !device_fits_ao(p.audio_device, name) {

1782+ mpv.set_string_async(p.mpv_ctx, 56, 'audio-device', 'auto')

1783+ }

17781784 p.refresh_media_async(true)

17791785 ui2.set_menu_bar(p.menus())

17801786 }

@@ -2032,6 +2038,19 @@ fn (p &Player) mpv_menu_items() []ui2.MenuItem {

20322038 return items

20332039}

20342040

2041+// device_fits_ao reports whether mpv would use the audio device `name` under

2042+// the audio server `ao`. mpv names devices `driver/device` (`pulse/...`,

2043+// `pipewire/...`), plus `auto` and a bare driver name for that driver's

2044+// default. Under autoprobing a prefixed device picks its own driver, so every

2045+// device fits. A pinned server ignores other drivers' devices and keeps

2046+// playing on its default sink.

2047+fn device_fits_ao(name string, ao string) bool {

2048+ if ao == 'auto' || name == 'auto' {

2049+ return true

2050+ }

2051+ return name == ao || name.starts_with('${ao}/')

2052+}

2053+

20352054// audio_server_names lists the audio servers the menus offer and the --ao

20362055// flag accepts — the outputs this platform's mpv can be expected to have.

20372056// 'auto' is mpv's own autoprobing, which tries its drivers in built-in order;

@@ -2078,6 +2097,9 @@ fn (p &Player) menus() []ui2.Menu {

20782097

20792098 mut devices := []ui2.MenuItem{}

20802099 for device in p.devices {

2100+ if !device_fits_ao(device.name, p.ao) {

2101+ continue

2102+ }

20812103 devices << ui2.menu_check_item('audio_device:${device.name}', device.description,

20822104 device.name == p.audio_device)

20832105 }