Conversation
There was a problem hiding this comment.
Code Review
This pull request updates the application version to 2.2.0-beta1 and introduces several improvements to video decoding and stream handling. Key changes include hardening H.265 hardware support by whitelisting reliable chipsets, optimizing buffer management in AapVideo to prevent cross-frame corruption, and refining the VideoDecoder to handle codec configuration flags and prevent deadlocks during shutdown. Feedback was provided regarding the silent dropping of video fragments which could lead to visual artifacts, and the potential for reducing memory allocations in the decoding pipeline for modern Android versions.
| if (messageBuffer.remaining() >= message.size) { | ||
| messageBuffer.put(message.data, 0, message.size) | ||
| } |
There was a problem hiding this comment.
Silently dropping a middle fragment when the buffer is full will result in a corrupted video frame being sent to the decoder. This is a major source of "melting" artifacts (inter-frame prediction errors) that this PR aims to address. If a fragment cannot be stored, the entire current frame should be invalidated (e.g., by clearing the buffer and potentially setting a flag to ignore subsequent fragments until the next start-of-frame/Flag 9). At the very least, a high-severity log should be added to help diagnose if the messageBuffer size is insufficient for the stream's bitrate.
| @@ -127,6 +156,7 @@ class VideoDecoder(private val settings: Settings) { | |||
| if (offset == 0 && size == buffer.size) buffer else buffer.copyOfRange(offset, offset + size) | |||
There was a problem hiding this comment.
Using copyOfRange for every video packet on modern devices (API 21+) introduces significant GC pressure and unnecessary memory overhead, especially for high-bitrate video. Since the decode method is synchronous and the data is copied into the MediaCodec input buffer via ByteBuffer.put (line 407/412) before the method returns, you should avoid this intermediate array allocation and use the original buffer with the provided offset throughout the method.
|
/gemini review |
There was a problem hiding this comment.
Code Review
This pull request updates the application version to 2.2.0-beta1 and introduces several improvements to video handling and decoding. Key changes include the implementation of corruption detection and overflow handling for video fragments in AapVideo, and enhanced buffer management and deadlock prevention in VideoDecoder. Additionally, SystemOptimizer now includes a check to filter out unreliable HEVC chipsets. A performance improvement was suggested for the BitReader class to use bitwise shifts instead of floating-point power functions for integer math.
…Decoder.kt Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
Try to fix the melting in decoders #219
Hardening the auto h265 detection, because lots of issues here are coming from h265 is set but not really supported and hang in endless starting loop.