Commit 163323d
committed
feat(linux)!: decouple video rendering from UI thread
Replace the direct renderer with a threaded offscreen renderer that
decouples video rendering from UI rendering to improve UI
responsiveness.
Updated Video Rendering:
- Windows: unchanged - mpvQC uses winId/HWND embedding as before
- Linux: threaded offscreen renderer (replaces direct rendering)
Technical Implementation:
The new renderer uses double-buffered framebuffers with rendering in a
dedicated background thread. The UI thread blits the latest completed
frame during its render operations:
┌─────┐ ┌────────┐ ┌─────────┐ ┌────────┐ ┌────────┐
│ mpv │ → │ render │ → │ display │ → │ Qt │ → │ screen │
│ │ │ fbo │ │ fbo │ │ fbo │ │ │
└─────┘ └────────┘ └─────────┘ └────────┘ └────────┘
└─ pointer swap ─┘ │
└────────── Background thread ──────────┘ │
│
└── UI thread ┘
blit
This allows the UI to remain responsive at the display's refresh rate
while video frames render independently at the content's native
framerate.
Audio Delay Compensation:
The double-buffered design introduces variable latency as frames wait
in display fbo for the next Qt render cycle. Assuming Qt processes
the render request on the next vsync cycle, frames wait on average
half a display frame period before being blitted to screen.
┌─────────────────────────────────────────────────────────────────┐
│ Consider a 60Hz display (16.67ms frame time): │
│ │
│ Display vsync: | | │
│ Time (ms): 0 16.67 │
│ │
│ Frame arrives at t=5ms: │
│ | F | │
│ ←------11.67ms wait-----→ │
│ │
│ Frame arrives at t=12ms: │
│ | F | │
│ ←-4.67ms--→ │
│ │
│ Average wait = 16.67ms / 2 ≈ 8.33ms │
└─────────────────────────────────────────────────────────────────┘
To compensate, mpvQC automatically adjusts mpv's audio delay to half
the current monitor's frame time: (1 / refresh_rate) / 2. This value
updates dynamically when the window moves to a different monitor or
when the refresh rate changes.
60Hz: 8.33ms
120Hz: 4.17ms
144Hz: 3.47ms
240Hz: 2.08ms
360Hz: 1.39ms
BREAKING CHANGE: Linux users must update their mpv.conf via Options ->
Edit mpv.conf by either restoring default values or removing the
video-timing-offset option. The new renderer handles timing
automatically through audio delay compensation.1 parent 1c3f958 commit 163323d
File tree
10 files changed
+552
-101
lines changed- data/config
- mpvqc
- services
- host_integration
- views
- test/services/player
10 files changed
+552
-101
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
5 | 5 | | |
6 | 6 | | |
7 | 7 | | |
8 | | - | |
9 | | - | |
10 | | - | |
11 | | - | |
12 | 8 | | |
13 | 9 | | |
14 | 10 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
2 | 2 | | |
3 | 3 | | |
4 | 4 | | |
| 5 | + | |
| 6 | + | |
5 | 7 | | |
6 | 8 | | |
| 9 | + | |
7 | 10 | | |
8 | 11 | | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
9 | 16 | | |
10 | 17 | | |
11 | 18 | | |
| |||
28 | 35 | | |
29 | 36 | | |
30 | 37 | | |
| 38 | + | |
31 | 39 | | |
32 | 40 | | |
33 | 41 | | |
34 | 42 | | |
| 43 | + | |
35 | 44 | | |
36 | 45 | | |
37 | 46 | | |
38 | 47 | | |
39 | 48 | | |
40 | 49 | | |
41 | | - | |
| 50 | + | |
42 | 51 | | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
43 | 60 | | |
44 | 61 | | |
45 | 62 | | |
| |||
48 | 65 | | |
49 | 66 | | |
50 | 67 | | |
51 | | - | |
52 | | - | |
| 68 | + | |
| 69 | + | |
| 70 | + | |
| 71 | + | |
| 72 | + | |
| 73 | + | |
| 74 | + | |
| 75 | + | |
| 76 | + | |
| 77 | + | |
| 78 | + | |
| 79 | + | |
| 80 | + | |
| 81 | + | |
| 82 | + | |
53 | 83 | | |
54 | 84 | | |
55 | 85 | | |
| |||
67 | 97 | | |
68 | 98 | | |
69 | 99 | | |
| 100 | + | |
| 101 | + | |
| 102 | + | |
| 103 | + | |
| 104 | + | |
| 105 | + | |
70 | 106 | | |
71 | 107 | | |
72 | 108 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
| |||
106 | 107 | | |
107 | 108 | | |
108 | 109 | | |
| 110 | + | |
| 111 | + | |
| 112 | + | |
| 113 | + | |
109 | 114 | | |
110 | 115 | | |
111 | 116 | | |
| |||
115 | 120 | | |
116 | 121 | | |
117 | 122 | | |
| 123 | + | |
| 124 | + | |
| 125 | + | |
| 126 | + | |
| 127 | + | |
118 | 128 | | |
119 | 129 | | |
120 | 130 | | |
| |||
173 | 183 | | |
174 | 184 | | |
175 | 185 | | |
| 186 | + | |
| 187 | + | |
| 188 | + | |
| 189 | + | |
| 190 | + | |
| 191 | + | |
| 192 | + | |
| 193 | + | |
176 | 194 | | |
177 | 195 | | |
178 | 196 | | |
| |||
230 | 248 | | |
231 | 249 | | |
232 | 250 | | |
| 251 | + | |
| 252 | + | |
| 253 | + | |
| 254 | + | |
| 255 | + | |
| 256 | + | |
| 257 | + | |
| 258 | + | |
| 259 | + | |
233 | 260 | | |
234 | 261 | | |
235 | 262 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
| 21 | + | |
20 | 22 | | |
21 | 23 | | |
22 | 24 | | |
| |||
27 | 29 | | |
28 | 30 | | |
29 | 31 | | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
30 | 37 | | |
31 | 38 | | |
32 | 39 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
3 | 3 | | |
4 | 4 | | |
5 | 5 | | |
6 | | - | |
7 | | - | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
This file was deleted.
0 commit comments