Repository navigation
Description
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.avcdecoder pads widths to a multiple of 128 from Android 12L. We take the frame size fromAHardwareBuffer_describe(Surface.hpp) and never callAImage_getCropRect(VideoDecoder.hpp,deliver()), socodedHeight,visibleRectanddisplayHeightwould 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: Chromiummedia_codec_util.cc(LookupCodedSizeAlignment),image_reader_gl_owner.cc(GetCropRectLocked),codec_wrapper.cc; WebRTCAndroidVideoDecoder.java(readscrop-left/right/top/bottom); Media3MediaCodecVideoRenderer.java.- Test
- Fix
- The decoder doesn't set
allow-frame-dropto 0. On API 29+ the decoder may drop a frame when the ImageReader is full.waitAcquiredthen waits 5 s, logs, and the frame is lost.
Source: Media3DefaultDecoderFactory.java(KEY_ALLOW_FRAME_DROP).- Test
- Fix
- No
max-input-size, and a 1920x1080 default whencodedWidth/codedHeightare 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: Media3MediaCodecVideoRenderer.java(getCodecMaxInputSize); Chromium setsKEY_MAX_INPUT_SIZEwith the same heuristic.- Test
- Fix
- No fallback to another decoder.
createDecoderByTypetakes 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: Media3MediaCodecRenderer.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.decodermisbehaves when flushed before it output a format (b/141097367). This affects both the video and audio decoders.
Sources: Chromiumcodec_wrapper.cc; Media3MediaCodecRenderer.java(codecNeedsSosFlushWorkaround).- Test
- Fix
- Decoded frames go back to the decoder without a release fence.
AImage_deletereturns the buffer with no fence, so the decoder can write the next picture into it while the GPU still reads it (for example aftercopyExternalImageToTexturefollowed byframe.close()). The 16-image reader makes this rare unless JS holds most of the images. Chromium passes a fence toAImage_deleteAsync.
Sources: AOSPNdkImageReader.cpp; Chromiumimage_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: AOSPACodec.cpp(setupAVCEncoderParameters); Media3DefaultEncoderFactory.java("Set profile and level at the same time to maximize compatibility"); Chromiumndk_video_encode_accelerator.cc.- Test
- Fix
-
The encoder check in
Capabilities.javais 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.encoderand the export runs in software with no error. When nothing passes,isConfigSupportedsays no, butconfigure()still goes ahead withcreateEncoderByType.
Sources: Media3EncoderUtil.java,MediaCodecInfo.java(ExoPlayer #6551 on alignment, b/153940404 on frame rates),DefaultEncoderFactory.java.- Test
- Fix
- 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
-
The default bitrate isn't checked against the encoder's range. With no
bitrate, we computewidth*height*fps*0.1and never compare it withgetBitrateRange(). 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: Media3DefaultCodec.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: Media3VideoSampleExporter.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, soflush()no longer hangs, but those frames are still lost.
Sources: AOSPGraphicBufferSource.cpp; Chromiumndk_video_encode_accelerator.cc(RecordFrameTimestamps); WebRTCHardwareVideoEncoder.java; Media3VideoSampleExporter.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 withNO_MEMORYafter 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 ineglSwapBuffers.close(),flush()andshutdown()all queue behind it, andshutdown()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'sstop(), so aconfigure()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 showsc2.qti.avc.encoderfailing withNO_MEMORYwhile 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: Media3DefaultDecoderFactory.java, androidx/media #2362; vision-camera #1212.- Test
- Fix
-
A key frame requested with
keyFrame: truemay land on a nearby frame.request-syncis 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: WebRTCHardwareVideoEncoder.java(requestKeyFrame); Chromiumndk_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.avcwould show it.- Test
- Fix
-
Minor GL hardening. WebRTC calls
glClearbefore 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 ofeglCreatePbufferSurface.
Source: WebRTCHardwareVideoEncoder.java.- Test
- Fix
GPU fences and buffers
- If
eglCreateSyncKHRfails, the fallback doesn't wait for the WebGPU work.waitFenceinGl.hppcloses the fence and callsglFinish(), which only waits for our own GL context, not for Dawn's Vulkan work, so the frame could be drawn half-rendered. The result ofeglWaitSyncKHRis 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'sGlEncoderFrameWriter(in the transformer library).- Test
- Fix
- HDR: the CPU fence wait ignores a timeout, and the buffer is then locked without the fence.
waitFenceCpupolls for 1 s and ignores the result, andqueueP010callsAHardwareBuffer_lockwith fence-1. A slow frame could be read half-written. Passing the fence toAHardwareBuffer_locklets it wait properly. Chromium's driver bug list also has Mali entries where readback after a GPU reset returns unwritten memory.
Sources: Chromiumgpu_driver_bug_list.json.- Test
- Fix
- HDR:
rgba16fToP010writes past the end of its chroma rows when the width is odd.cbandcrholdwidth / 2entries, but the loop writescb[x / 2]forx = width - 1. Odd sizes should be rejected up front, or the rows sized(width + 1) / 2. Related: when the codec doesn't reportstride/slice-height, we assume an unaligned layout; Chromium aligns to 16 in that case.
Source: Chromiumndk_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_lockfail on Galaxy S25 (Adreno 830) and A36 (Adreno 710) with Android 15, and crashes or reboots on Samsungs fromGPU_SAMPLED | CPU_READ_OFTENbuffers. We allocate the RGBA16F pool with CPU read usage and lock every HDR frame, with noAHardwareBuffer_isSupportedprobe.
Sources: vision-camera #3539, #2108, #2555.- Test
- Fix
- Camera frames passed to
wrapSurfacecan be overwritten before we draw them.AHardwareBuffer_acquirekeeps the memory alive but doesn't stop the camera from reusing the buffer, andencode()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: Chromiumgpu_driver_bug_list.json; AOSPNdkImageReader.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: Flutterandroid_context_dynamic_impeller.cc,driver_info_vk.cc, #186067, #186405, #161334; DawnSharedTextureMemoryVk.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 outputsAIMAGE_FORMAT_PRIVATE, which vendors map to their own format codes, soVideoFrame.formatis 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.createEncoderByTypecan return a manufacturer's own AAC encoder, which would cut the end of the audio or keep extra silence. Media3 also setsprofileas well asaac-profile, because some devices ignoreaac-profilealone.
Sources: Media3DefaultCodec.java,DefaultEncoderFactory.java.- Test
- Fix
Checked and probably not affected
- Encoders that throw on
operating-rateINT32_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.encoderis found. - B-frames despite High profile, and pre-API-29
max-bframesproblems: 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
eglTerminateon the shared display (vision-camera V3): we tear down on the GL thread and never calleglTerminate.
The research ran against v0.1.1 plus the unreleased review fixes.
Activity
andreialecu commentedon Nov 24, 2026
Ticked the boxes for the work in #3 (not merged yet).
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.Partly done, so the item stays unticked:
configure()still falls back tocreateEncoderByTypewhen no encoder passes the checks. That was kept on purpose, since it can't be tested on real phones here.AHardwareBuffer_isSupportedsays 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.Merge pull request #3 from andreialecu/fix/review-and-android-hardening
chore(release): 0.1.2 [skip ci]