Skip to content

Commit f7a33be

Browse files
MaxHeimbrockclaude
andauthored
Fix WebCamTexture orientation on the wire (#276)
* Fix WebCamTexture orientation on the wire Two related issues caused remote participants to see local video at wrong orientations: 1. GetVideoRotation was mismapping cases: 0→_180, 180→_0, 270→_180. Android front cam in portrait reports videoRotationAngle == 270, so remotes saw the stream 90° off. Replaced with a straight passthrough across all four angles. 2. GetPixels32 returns rows bottom-up but WebRTC expects top-down, so the buffer was being sent vertically flipped. The previous "0→_180" mapping was masking this on desktop (180° rotation visually approximates a Y-flip on roughly-symmetric subjects), but it was never actually correct. Flip rows during the buffer copy. Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com> * Adds missing meta file --------- Co-authored-by: Claude Haiku 4.5 <noreply@anthropic.com>
1 parent f4dd720 commit f7a33be

2 files changed

Lines changed: 22 additions & 4 deletions

File tree

Runtime/Scripts/Internal/TaskYieldInstruction.cs.meta

Lines changed: 11 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Runtime/Scripts/WebCameraSource.cs

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,10 +28,12 @@ protected override VideoRotation GetVideoRotation()
2828
{
2929
switch (CamTexture.videoRotationAngle)
3030
{
31+
case 0: return VideoRotation._0;
3132
case 90: return VideoRotation._90;
32-
case 180: return VideoRotation._0;
33+
case 180: return VideoRotation._180;
34+
case 270: return VideoRotation._270;
3335
}
34-
return VideoRotation._180;
36+
return VideoRotation._0;
3537
}
3638

3739
public WebCameraSource(WebCamTexture texture, VideoBufferType bufferType = VideoBufferType.Rgba) : base(VideoStreamSource.Texture, bufferType)
@@ -81,8 +83,13 @@ protected override bool ReadBuffer()
8183
}
8284

8385
CamTexture.GetPixels32(_readBuffer);
84-
MemoryMarshal.Cast<Color32, byte>(_readBuffer)
85-
.CopyTo(_captureBuffer.AsSpan());
86+
// GetPixels32 returns rows bottom-up; WebRTC expects top-down. Flip while copying.
87+
var src = MemoryMarshal.Cast<Color32, byte>(_readBuffer);
88+
var dst = _captureBuffer.AsSpan();
89+
int rowBytes = width * GetStrideForBuffer(_bufferType);
90+
for (int y = 0; y < height; y++)
91+
src.Slice(y * rowBytes, rowBytes)
92+
.CopyTo(dst.Slice((height - 1 - y) * rowBytes, rowBytes));
8693

8794
_requestPending = true;
8895

0 commit comments

Comments
 (0)