Skip to content

Fix the Android blur cutout sticking on the first person - #246

Merged
sierpinskid merged 2 commits into
mainfrom
bugfix/UNI-276-android-blur-cutout
Dec 4, 2026
Merged

sierpinskid merged 2 commits into
mainfrom
bugfix/UNI-276-android-blur-cutout

Conversation

@sierpinskid

@sierpinskid sierpinskid commented Dec 4, 2026 •

Copy link
Copy Markdown
Member

Summary

Fixes UNI-276. On Android, the background-blur cutout stayed where the person was first detected.

The root cause is not isolated yet. On an OpenGLES3 device, the cutout tracked a live head at rotation 270 with this PR's changes applied together. At 90/270 the orientation change only adds a left/right mirror, and a per-frame bitmap on its own did not fix the problem earlier. So the fix is most likely the switch from AsyncGPUReadback to ReadPixels, the change of render-texture format, or both. A device A/B test will decide which changes stay.

What changed (Android only, #if UNITY_ANDROID && !UNITY_EDITOR):

  • Camera copy: ReadPixels of the small downscale target replaces AsyncGPUReadback. The copy runs only when ML Kit can accept a frame. The publish texture is never read back.
  • Render-texture format: the downscale target uses explicit linear R8G8B8A8_UNorm.
  • Orientation: ML Kit receives the same upright image the publisher sends. Bytes are flipped before rotation unless the camera reports videoVerticallyMirrored, and the mask is mapped back before upload. Previously, cameras at 0°/180° gave ML Kit an upside-down image. The rotation and flip return from Java with the mask, so a camera switch can't pair a mask with the wrong orientation. takeMaskIfNew captures the mask's size, rotation, and flip at the same moment it returns the bytes.
  • Java: a new Bitmap is used for each frame. The previous frame's bitmap is kept until the next frame finishes.
  • No public API changes. iOS, desktop, and the compositor are unchanged.

Removed during cleanup: the CPU GetPixels32 fallback and MaskFrameScale. The fallback's trigger condition was always true, so it could switch permanently to an 8 MB-per-frame CPU path, and it never fired on device. Also removed: per-frame input hashing, the debug heartbeat, and the per-submission GetRawTextureData allocation.

Replaces #242 (closed, not merged). UNI-270 is canceled.

Test plan

  • Unity 6000.6.2f1 EditMode (macOS, Metal): 189 of 190 passed. The only failure is RepositoryTests.When_imported_samples_expect_match_package_source_samples, caused by unrelated local Assets/Samples changes. The new tests cover rotations 0/90/180/270 with and without mirroring: ML Kit input matches PublisherVideoRotator's upright image exactly, and the mask maps back onto the original camera pixels.
  • Android-only C# compiled with UNITY_ANDROID against the Unity 2021.3.21f1 and 6000.2.4f1 engine DLLs, with and without STREAM_DEBUG_ENABLED;STREAM_LOG_BG_FILTER. 0 errors, 0 warnings.
  • Java bridge compiled with --release 8 against android.jar, using ML Kit stubs.
  • CI on all Android rows. The compositor "mask moves" test failed on CI's software OpenGL and now uses mask-wide color bands. It could not be run locally on OpenGL.
  • OpenGLES3 device, earlier build with all changes applied: the cutout followed a live head at rotation 270 and emptied when nobody was in frame.
  • Device A/B to isolate the root cause (ReadPixels, format, bitmap). Not run.
  • Device check with this commit on OpenGLES3 and Vulkan: front and back camera, camera switch, pause/resume. A live head on Vulkan has never been checked.
  • ReadPixels main-thread cost on a low-end OpenGLES device. Not measured.

ML Kit was given a bottom-up camera buffer and a reused bitmap, so STREAM_MODE kept the first mask. Flip the buffer before rotation and submit a new bitmap per frame.

Co-authored-by: Cursor <cursoragent@cursor.com>
@getstream-metis

Copy link
Copy Markdown

👋 Hi Daniel, want a second pair of eyes on this?

I'm Jeffery, Stream's review agent. I look for bugs, regressions, missing tests and slow paths, and I only post findings I've checked against the code.

  • Review this PR

Or comment /jeffery review. I'll stay quiet unless you ask.

…t orientation.

Remove the CPU GetPixels32 fallback, MaskFrameScale, input hashing, and the debug heartbeat.
Flip the ReadPixels bytes only when the camera is not vertically mirrored, matching
PublisherVideoRotator, and return the flip with the mask through Java. takeMaskIfNew now
snapshots the mask size, rotation, and flip so they always describe the returned bytes.
Copy the readback into a reused buffer instead of allocating per submission.
Widen the compositor mask-move test bands so half-texel resampling cannot fail it.

Co-authored-by: Cursor <cursoragent@cursor.com>
@sierpinskid
sierpinskid merged commit abac0fa into main Dec 4, 2026
16 of 18 checks passed
@sierpinskid
sierpinskid deleted the bugfix/UNI-276-android-blur-cutout branch December 4, 2026 14:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants