Commit a31c82a
feat(video): refcount the capture pipeline; expose pauseVideo / resumeVideo
Introduces acquireVideoStream / releaseVideoStream / videoStreamHasConsumers
helpers in video.go that gate the native encoder's VideoStart / VideoStop
and the HDMI sleep ticker on a set of named consumers. The encoder runs
iff at least one consumer holds it; the 0→1 transition runs VideoStart so
the first delivered frame is an IDR.
Each WebRTC Session gets a stable id (uuid in newSession) and its own
consumer key "webrtc:<id>". The slot is acquired when ICE reaches
Connected and released when it reaches Closed. pauseVideo / resumeVideo
JSON-RPC notifications toggle the calling session's own slot, handled
inline in onRPCMessage so the dispatcher's session reference is in scope
(the generic reflection-based dispatch doesn't pass *Session).
This data model fixes by construction the two race classes Cursor Bugbot
flagged on earlier drafts of this PR:
- Handover-while-paused: the new session's own acquire is what starts
the encoder; no special-case "restart if the outgoing session was
paused" code at the handover site.
- Stale-session pause: a pauseVideo from the soon-to-close session
releases only its own slot, not the new session's; no need for a
session != currentSession gate.
The 1s handover overlap can briefly deliver frames to a paused session's
track if the other session is keeping the encoder alive; bounded by the
existing peer-connection close delay and acceptable for a feature aimed
at sustained idle bandwidth saving.
The refcount helpers are byte-identical to those in PR #1447 (commit
dec25e1), so that PR will merge cleanly on top.
Co-Authored-By: Claude Opus 4.7 <noreply@anthropic.com>1 parent 79c23ec commit a31c82a
3 files changed
Lines changed: 100 additions & 8 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
124 | 124 | | |
125 | 125 | | |
126 | 126 | | |
| 127 | + | |
| 128 | + | |
| 129 | + | |
| 130 | + | |
| 131 | + | |
| 132 | + | |
| 133 | + | |
| 134 | + | |
| 135 | + | |
| 136 | + | |
| 137 | + | |
| 138 | + | |
| 139 | + | |
| 140 | + | |
| 141 | + | |
| 142 | + | |
127 | 143 | | |
128 | 144 | | |
129 | 145 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
6 | 6 | | |
7 | 7 | | |
8 | 8 | | |
| 9 | + | |
9 | 10 | | |
10 | 11 | | |
11 | 12 | | |
12 | 13 | | |
13 | 14 | | |
14 | 15 | | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
15 | 19 | | |
16 | 20 | | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
| 61 | + | |
| 62 | + | |
| 63 | + | |
| 64 | + | |
| 65 | + | |
17 | 66 | | |
18 | 67 | | |
19 | 68 | | |
| |||
111 | 160 | | |
112 | 161 | | |
113 | 162 | | |
114 | | - | |
115 | | - | |
| 163 | + | |
| 164 | + | |
116 | 165 | | |
117 | 166 | | |
118 | 167 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
17 | 17 | | |
18 | 18 | | |
19 | 19 | | |
| 20 | + | |
20 | 21 | | |
21 | 22 | | |
22 | 23 | | |
23 | 24 | | |
24 | 25 | | |
25 | 26 | | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
26 | 32 | | |
27 | 33 | | |
28 | 34 | | |
| |||
44 | 50 | | |
45 | 51 | | |
46 | 52 | | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
47 | 60 | | |
48 | 61 | | |
49 | 62 | | |
| |||
354 | 367 | | |
355 | 368 | | |
356 | 369 | | |
357 | | - | |
| 370 | + | |
| 371 | + | |
| 372 | + | |
| 373 | + | |
358 | 374 | | |
359 | 375 | | |
360 | 376 | | |
| |||
435 | 451 | | |
436 | 452 | | |
437 | 453 | | |
| 454 | + | |
| 455 | + | |
| 456 | + | |
| 457 | + | |
| 458 | + | |
438 | 459 | | |
439 | 460 | | |
440 | 461 | | |
| |||
481 | 502 | | |
482 | 503 | | |
483 | 504 | | |
| 505 | + | |
| 506 | + | |
| 507 | + | |
| 508 | + | |
484 | 509 | | |
485 | 510 | | |
486 | 511 | | |
| |||
502 | 527 | | |
503 | 528 | | |
504 | 529 | | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
505 | 534 | | |
506 | 535 | | |
507 | 536 | | |
508 | 537 | | |
509 | 538 | | |
510 | | - | |
511 | | - | |
512 | 539 | | |
513 | 540 | | |
514 | 541 | | |
515 | | - | |
| 542 | + | |
| 543 | + | |
| 544 | + | |
516 | 545 | | |
517 | | - | |
518 | | - | |
519 | 546 | | |
0 commit comments