Repository navigation
Commit be5304c
authored
Fix/windows desktop capture (#263)
* fix: define RTC_ENABLE_WIN_WGC for the JNI wrapper (Windows ABI mismatch)
Windows screen/window capture has been completely broken since the
branch-heads/7339 -> 7977 (m140 -> m152) bump: zero frames captured, and
the "screens" enumeration returned application windows.
Root cause is a DesktopCaptureOptions ABI mismatch between webrtc.lib and
the JNI wrapper. gn builds the lib with its default rtc_enable_win_wgc=true
(webrtc.gni: rtc_enable_win_wgc = is_win), so the lib-side class contains
the RTC_ENABLE_WIN_WGC-guarded members; the wrapper compiled without the
define sees a smaller class (64 vs 80 bytes on 7977) with different member
offsets for everything after the WGC block.
DesktopCaptureOptions::CreateDefault() and the copy constructor are defined
out-of-line in the lib, so `auto options = CreateDefault()` in the wrapper
writes an 80-byte object into a 64-byte stack slot: 16 bytes of adjacent
stack are zero-smashed on every capturer construction. That deterministic
smash is what zeroed jni::DesktopCapturer's spilled screenCapturer argument
(every ScreenCapturer.initialize() logged screenCapturer=0 and constructed
the window capturer instead - the "Screens tab lists applications" bug),
and general field-offset skew after the WGC block broke frame delivery
entirely.
The mismatch already existed on 7339, but the guarded block was then just
5 bools at the tail-adjacent position: an 8-byte zero overflow and skewed
reads of cosmetic flags (disable_effects_), which happened to be survivable
- which is why 0.14.0 worked. 7977 grew the block (7 bools + LUID) and
added std::optional<Environment> env_ after it, making the corruption
fatal.
Fix: define RTC_ENABLE_WIN_WGC for the wrapper so both sides agree on the
layout. This is the same ABI bug class already fixed on Linux with
WEBRTC_USE_X11 (#236) and WEBRTC_USE_PIPEWIRE (#261). All allow_wgc_*
options default to false, so capturer selection behavior is unchanged
(DirectX/GDI as before).
* fix: pass full frame height as libyuv src_height (broken window capture)
With the RTC_ENABLE_WIN_WGC ABI fix in place, screen capture works but
window (application) capture still delivered no frames: neither thumbnails
(DesktopCaptureCallback) nor the live share (VideoTrackDesktopSource).
Both files feed libyuv::ConvertToI420 with the cropped output height
(i420Buffer/buffer->height() == crop_h) in the src_height slot. libyuv
bounds-checks crop_y + crop_height <= src_height, so the conversion fails
with -1 whenever crop_y > 0. The Windows border-crop branch sets
crop_y = -top_left().y() for frames that start above the screen origin,
which is the case for every MAXIMIZED window (its frame sits at
-SM_CXPADDEDBORDER). Screen frames never enter that branch at all
(exact stride, `fullscreen == true`), which is why only window capture
appeared broken.
Confirmed at runtime on a diagnostic build (Komm, Windows 11):
size=1928x1043 crop_y=7 crop_w=1920 crop_h=1032
Failed to convert desktop frame to I420, libyuv result=-1
Also propagate non-SUCCESS capture results to the Java callback (with a
null frame) instead of silently returning, so callers don't have to burn
a timeout to notice a failed capture.1 parent bce0b2e commit be5304c
3 files changed
Lines changed: 28 additions & 3 deletions
File tree
- webrtc-jni/src/main/cpp
- dependencies/webrtc
- src/media/video
- desktop
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
228 | 228 | | |
229 | 229 | | |
230 | 230 | | |
231 | | - | |
| 231 | + | |
| 232 | + | |
| 233 | + | |
| 234 | + | |
| 235 | + | |
| 236 | + | |
| 237 | + | |
| 238 | + | |
| 239 | + | |
232 | 240 | | |
233 | 241 | | |
234 | 242 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
194 | 194 | | |
195 | 195 | | |
196 | 196 | | |
197 | | - | |
| 197 | + | |
| 198 | + | |
| 199 | + | |
| 200 | + | |
| 201 | + | |
| 202 | + | |
| 203 | + | |
198 | 204 | | |
199 | 205 | | |
200 | 206 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
44 | 44 | | |
45 | 45 | | |
46 | 46 | | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
47 | 52 | | |
48 | 53 | | |
49 | 54 | | |
| |||
83 | 88 | | |
84 | 89 | | |
85 | 90 | | |
86 | | - | |
| 91 | + | |
| 92 | + | |
| 93 | + | |
| 94 | + | |
| 95 | + | |
| 96 | + | |
| 97 | + | |
87 | 98 | | |
88 | 99 | | |
89 | 100 | | |
| |||
0 commit comments