Skip to content

Android: possible device-specific problems found in other projects (unconfirmed) #1

Backlog

Description

@andreialecu

This is a list of possible Android problems. Other projects that drive MediaCodec, AHardwareBuffer and EGL directly ran into them, and the same code paths exist here. None of them is confirmed in react-native-webcodecs. Nobody has reproduced them on a phone yet. Each one comes from reading our code next to the other project's workaround, bug report or comment.

The sources are Chromium (which implements WebCodecs on Android), WebRTC, Media3/ExoPlayer, react-native-vision-camera, Flutter's Impeller, Dawn and AOSP.

Each item has two boxes: one for a test that shows whether we're affected, one for a fix. Tick them as the work lands. A test that shows we're not affected also closes the item; say so in a comment.

Video decoder

  • The decoder ignores the crop rect, so decoded frames can include padding rows. Hardware decoders often allocate 1920x1088 for a 1080p video and mark the visible area with a crop rect. Android's own c2.android.avc decoder pads widths to a multiple of 128 from Android 12L. We take the frame size from AHardwareBuffer_describe (Surface.hpp) and never call AImage_getCropRect (VideoDecoder.hpp, deliver()), so codedHeight, visibleRect and displayHeight would all be 1088, and a transcode would carry the garbage rows into the output. Our e2e clips are 1280x720, which needs no padding, so the tests wouldn't catch it. A 720x1280 clip on an API 32+ emulator should.
    Sources: Chromium media_codec_util.cc (LookupCodedSizeAlignment), image_reader_gl_owner.cc (GetCropRectLocked), codec_wrapper.cc; WebRTC AndroidVideoDecoder.java (reads crop-left/right/top/bottom); Media3 MediaCodecVideoRenderer.java.
    • Test
    • Fix
  • The decoder doesn't set allow-frame-drop to 0. On API 29+ the decoder may drop a frame when the ImageReader is full. waitAcquired then waits 5 s, logs, and the frame is lost.
    Source: Media3 DefaultDecoderFactory.java (KEY_ALLOW_FRAME_DROP).
    • Test
    • Fix
  • No max-input-size, and a 1920x1080 default when codedWidth/codedHeight are missing (WebCodecs allows that). A large key frame, from a 4K or high-bitrate clip, can then fail with "chunk larger than the input buffer", with no retry. The size could come from the SPS in the avcC.
    Sources: Media3 MediaCodecVideoRenderer.java (getCodecMaxInputSize); Chromium sets KEY_MAX_INPUT_SIZE with the same heuristic.
    • Test
    • Fix
  • No fallback to another decoder. createDecoderByType takes the default hardware decoder, and a configure or start failure (too many instances, a level the hardware refuses) ends the decoder. Media3 works through the decoder list instead.
    Sources: Media3 MediaCodecRenderer.java, DefaultDecoderFactory.java.
    • Test
    • Fix
  • flush() queues end of stream even when nothing was decoded. Some codecs treat an end of stream as the first input as an error (crbug.com/672268). On API 29, c2.android.aac.decoder misbehaves when flushed before it output a format (b/141097367). This affects both the video and audio decoders.
    Sources: Chromium codec_wrapper.cc; Media3 MediaCodecRenderer.java (codecNeedsSosFlushWorkaround).
    • Test
    • Fix
  • Decoded frames go back to the decoder without a release fence. AImage_delete returns the buffer with no fence, so the decoder can write the next picture into it while the GPU still reads it (for example after copyExternalImageToTexture followed by frame.close()). The 16-image reader makes this rare unless JS holds most of the images. Chromium passes a fence to AImage_deleteAsync.
    Sources: AOSP NdkImageReader.cpp; Chromium image_reader_gl_owner.cc.
    • Test
    • Fix

Video encoder

  • The H.264 profile is set without a level. AOSP's ACodec refuses a profile without a level on OMX encoders, which many phones that launched on Android 10 or 11 still use. Our first two configure attempts would then fail. The third drops the profile (so Baseline), caps the frame rate at 30 and drops operating-rate, so offline exports may run in real time. Codec2 (c2.*) encoders don't need the level. Chromium and Media3 always set both.
    Sources: AOSP ACodec.cpp (setupAVCEncoderParameters); Media3 DefaultEncoderFactory.java ("Set profile and level at the same time to maximize compatibility"); Chromium ndk_video_encode_accelerator.cc.

    • Test
    • Fix
  • The encoder check in Capabilities.java is stricter than Media3's, so we may pick a software encoder or report "unsupported":

    • Some Samsung, Huawei and Pixel 6 devices report a maximum height of 1072 for H.264 1920x1080, and 2144 for HEVC 3840x2160 (b/222095724, b/229825948). Media3 cross-checks with CamcorderProfile.
    • We don't align sizes before checking, and don't retry a portrait size swapped.
    • The frame rate and bitrate reject an encoder instead of being treated as hints and clamped.

    When the hardware encoder fails a check, the loop falls through to c2.android.avc.encoder and the export runs in software with no error. When nothing passes, isConfigSupported says no, but configure() still goes ahead with createEncoderByType.
    Sources: Media3 EncoderUtil.java, MediaCodecInfo.java (ExoPlayer #6551 on alignment, b/153940404 on frame rates), DefaultEncoderFactory.java.

    • Test
    • Fix
  • The default bitrate isn't checked against the encoder's range. With no bitrate, we compute width*height*fps*0.1 and never compare it with getBitrateRange(). 4K at 120 fps gives about 99.5 Mbps. vision-camera hit exactly this: a 100 Mbps default above the encoder's 80 Mbps maximum made it fail.
    Source: vision-camera #2208.

    • Test
    • Fix
  • Signalling end of stream right after the last frame can lose that frame on short encodes. Media3 found that on some devices the frame gets lost and an empty output comes out, and waits up to 100 ms before signalling (b/301603935). We signal straight after the last eglSwapBuffers, and the lost frame would come out as an empty chunk. Encodes of 1 to a few frames (thumbnails, a still image to video) are the risk.
    Source: Media3 DefaultCodec.java (signalEndOfInputStream).

    • Test
    • Fix
  • The encoder never sends end of stream, and flush() rejects after 10 s. Media3 reports encoders that never return the end-of-stream buffer and treats "every frame came out" as done (b/365484741). Our flush waits for the flag, with a fixed 10 s timeout that a slow software encoder holding many frames can also run past.
    Source: Media3 VideoSampleExporter.java.

    • Test
    • Fix
  • Real WebCodecs timestamps go straight to MediaCodec. The input surface drops frames whose timestamp repeats or goes backwards (AOSP GraphicBufferSource, "Dropping frame that's going backward in time"). Rate control also expects even spacing: WebRTC applies a frame-rate bitrate adjuster to Exynos encoders, whose rate control assumes a fixed frame rate. Chromium and WebRTC both feed evenly spaced timestamps and put the real ones back on output. Media3 also reports encoders that stamp the second-to-last output with 0 (b/235045165). Partly handled: since the review fixes, frames dropped this way come out as empty chunks at the end of the stream, so flush() no longer hangs, but those frames are still lost.
    Sources: AOSP GraphicBufferSource.cpp; Chromium ndk_video_encode_accelerator.cc (RecordFrameTimestamps); WebRTC HardwareVideoEncoder.java; Media3 VideoSampleExporter.java.

    • Test
    • Fix
  • A codec that dies after start() can block the GL thread forever. In vision-camera #3346 (moto g34, Qualcomm), the encoder failed with NO_MEMORY after start, its input queue filled up, and recording got stuck with no error. Our drain thread would notice (codec error or the 20 s stall check), but the GL thread can stay blocked in eglSwapBuffers. close(), flush() and shutdown() all queue behind it, and shutdown() waits with no timeout, which could hang the app.
    Source: vision-camera #3346.

    • Test
    • Fix
  • Reconfiguring, or running several codecs at once, can hit the hardware codec limit. close() only queues the codec's stop(), so a configure() creates the new codec before the old one is released. Media3 lists devices that can't configure a 1080p hardware encoder while a 1080p hardware decoder exists (vivo 1906, Redmi 7A, Redmi 8; b/283768701), and androidx/media #2362 shows c2.qti.avc.encoder failing with NO_MEMORY while a player was still alive. When all configure attempts fail, we also don't try another encoder, and our error ("does not take WxH") hides the real status.
    Sources: Media3 DefaultDecoderFactory.java, androidx/media #2362; vision-camera #1212.

    • Test
    • Fix
  • A key frame requested with keyFrame: true may land on a nearby frame. request-sync is asynchronous, and frames already queued in the input surface may be the ones it hits. WebRTC and Chromium both note that the key-frame flag has no effect in surface mode.
    Sources: WebRTC HardwareVideoEncoder.java (requestKeyFrame); Chromium ndk_video_encode_accelerator.cc.

    • Test
    • Fix
  • Black or corrupted frames on Snapdragon 8 Gen 3 with Android 16. androidx/media #3087 reports black, purple or brown frames on Galaxy S24, S24+ and Z Flip 6 from a GL-to-encoder-surface pipeline shaped like ours. Google couldn't reproduce it, and the root cause is unknown.
    Source: androidx/media #3087.

    • Test
    • Fix
  • Some vendor encoders may convert RGB to YUV with a different matrix than the BT.709 limited range we tag. The conversion from the RGBA input surface happens inside the vendor encoder or gralloc. Comparing colour bars through a hardware encoder and through c2.android.avc would show it.

    • Test
    • Fix
  • Minor GL hardening. WebRTC calls glClear before drawing into the encoder surface as a workaround for webrtc:5147. Our EGL config requires window, pbuffer and recordable together, and we don't check the result of eglCreatePbufferSurface.
    Source: WebRTC HardwareVideoEncoder.java.

    • Test
    • Fix

GPU fences and buffers

  • If eglCreateSyncKHR fails, the fallback doesn't wait for the WebGPU work. waitFence in Gl.hpp closes the fence and calls glFinish(), which only waits for our own GL context, not for Dawn's Vulkan work, so the frame could be drawn half-rendered. The result of eglWaitSyncKHR is also ignored, and the GPU wait has no timeout; Media3 waits 500 ms on its fence. The extensions involved are nearly universal on Android 10+, so this is rare.
    Source: Media3's GlEncoderFrameWriter (in the transformer library).
    • Test
    • Fix
  • HDR: the CPU fence wait ignores a timeout, and the buffer is then locked without the fence. waitFenceCpu polls for 1 s and ignores the result, and queueP010 calls AHardwareBuffer_lock with fence -1. A slow frame could be read half-written. Passing the fence to AHardwareBuffer_lock lets it wait properly. Chromium's driver bug list also has Mali entries where readback after a GPU reset returns unwritten memory.
    Sources: Chromium gpu_driver_bug_list.json.
    • Test
    • Fix
  • HDR: rgba16fToP010 writes past the end of its chroma rows when the width is odd. cb and cr hold width / 2 entries, but the loop writes cb[x / 2] for x = width - 1. Odd sizes should be rejected up front, or the rows sized (width + 1) / 2. Related: when the codec doesn't report stride/slice-height, we assume an unaligned layout; Chromium aligns to 16 in that case.
    Source: Chromium ndk_video_encode_accelerator.cc (SetInputBufferLayout).
    • Test
    • Fix
  • HDR: locking a GPU-written RGBA16F buffer on the CPU can fail on some devices. vision-camera saw AHardwareBuffer_lock fail on Galaxy S25 (Adreno 830) and A36 (Adreno 710) with Android 15, and crashes or reboots on Samsungs from GPU_SAMPLED | CPU_READ_OFTEN buffers. We allocate the RGBA16F pool with CPU read usage and lock every HDR frame, with no AHardwareBuffer_isSupported probe.
    Sources: vision-camera #3539, #2108, #2555.
    • Test
    • Fix
  • Camera frames passed to wrapSurface can be overwritten before we draw them. AHardwareBuffer_acquire keeps the memory alive but doesn't stop the camera from reusing the buffer, and encode() only queues the draw for the GL thread. Once the camera frame closes, the next frame can land in the same buffer first. Chromium has also turned off zero-copy video capture on several Android devices (bug list entries 511 and 512). Those bugs are private, so the cause there may be different. vision-camera also notes that CPU-written YUV buffers are sampled with swapped chroma by some GPU drivers, and we ignore the frame's rotation and mirroring.
    Sources: Chromium gpu_driver_bug_list.json; AOSP NdkImageReader.cpp.
    • Test
    • Fix
  • Importing an AHardwareBuffer into Vulkan crashes or misbehaves on some chips. This happens in react-native-webgpu's importSharedTextureMemory (Dawn), which every frame we render goes through, not in our code. Flutter turns Vulkan off for Huawei ("AHB imports do not consistently work"), MediaTek with a vendor SDK below 32 ("crashes when importing AHB"), a list of older Exynos chips, Rockchip and emulators. Impeller also blocks Adreno 650 and older, and Xclipse below Vulkan 1.3. A one-frame probe at startup with a fallback, or a matching denylist, would cover it.
    Sources: Flutter android_context_dynamic_impeller.cc, driver_info_vk.cc, #186067, #186405, #161334; Dawn SharedTextureMemoryVk.cpp.
    • Test
    • Fix
  • A GPU hang on MediaTek Mali can block the GL thread in a fence wait. Flutter #193428 shows ANRs stuck in osup_sync_object_wait. A bounded CPU wait on the fence before the GL wait would let us fail the frame instead.
    Source: Flutter #193428.
    • Test
    • Fix
  • Decoded frames report format unknown. The decoder outputs AIMAGE_FORMAT_PRIVATE, which vendors map to their own format codes, so VideoFrame.format is null while we advertise NV12. vision-camera #4207 shows the same buffers on a Galaxy A14.
    Source: vision-camera #4207.
    • Test
    • Fix

Audio

  • The AAC encoder delay of 1600 samples is applied to every AAC encoder. It's the delay of Android's built-in encoder (c2.android.aac.encoder, FDK), and Media3 applies it only to that encoder. createEncoderByType can return a manufacturer's own AAC encoder, which would cut the end of the audio or keep extra silence. Media3 also sets profile as well as aac-profile, because some devices ignore aac-profile alone.
    Sources: Media3 DefaultCodec.java, DefaultEncoderFactory.java.
    • Test
    • Fix

Checked and probably not affected

  • Encoders that throw on operating-rate INT32_MAX (SM8550, SM7450, SM6450, SC9863A, T612/T606/T603): our second configure attempt uses 1000.
  • Exynos failing with an I-frame interval of -1: we use 3600, as WebRTC does.
  • Unisoc minimum encoder width (androidx/media #3451): we try every encoder, so c2.android.avc.encoder is found.
  • B-frames despite High profile, and pre-API-29 max-bframes problems: we require API 29.
  • HDR dataspace and FP16 EGL window bugs: our HDR path converts to P010 on the CPU and never uses an HDR window surface.
  • EGL torn down on the wrong thread, or eglTerminate on the shared display (vision-camera V3): we tear down on the GL thread and never call eglTerminate.

The research ran against v0.1.1 plus the unreleased review fixes.

Activity

  1. andreialecu commented on Nov 24, 2026

    @andreialecu
    OwnerAuthor

    Ticked the boxes for the work in #3 (not merged yet).

    • Test is ticked only where a test failed before its fix. Items with only a regression or host test that never failed are left unticked: the decoder fallback when configure or start fails, allow-frame-drop, flush with nothing queued, the EOS wait on short encodes, the GL hardening, the HDR lock fence, the RGBA16F probe, and the AAC encoder items.
    • Fix is ticked where a change landed. The item itself is ticked only when nothing from it is left.

    Partly done, so the item stays unticked:

    • Capabilities: configure() still falls back to createEncoderByType when no encoder passes the checks. That was kept on purpose, since it can't be tested on real phones here.
    • Timestamps: repeated and backward timestamps no longer drop frames, but timestamps are not respaced for rate control.
    • P010: odd sizes no longer overflow, but the stride is still unaligned when the codec doesn't report one.
    • RGBA16F: the pool is refused when AHardwareBuffer_isSupported says no, but a lock that fails anyway is not handled.
    • wrapSurface: encode() now waits until the frame is read, but rotation, mirroring and swapped chroma are not handled.

    Not addressed: the decoder release fence, the Snapdragon 8 Gen 3 black frames, the vendor RGB to YUV matrix, and the Dawn AHardwareBuffer import.

    Everything was tested on an Android emulator (API 35) with only c2.android.* codecs. OMX encoders, vendor encoders and real GPUs are still untested.

  2. added a commit that references this issue on Nov 24, 2026
  3. added a commit that references this issue on Nov 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions