Skip to content

video-decoder#340

Merged
andreknieriem merged 4 commits intomainfrom
videodecoder
Apr 7, 2026
Merged

video-decoder#340
andreknieriem merged 4 commits intomainfrom
videodecoder

Conversation

@andreknieriem
Copy link
Copy Markdown
Owner

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.

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +56 to +58
if (messageBuffer.remaining() >= message.size) {
messageBuffer.put(message.data, 0, message.size)
}
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

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)
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

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.

@andreknieriem
Copy link
Copy Markdown
Owner Author

/gemini review

Copy link
Copy Markdown
Contributor

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment thread app/src/main/java/com/andrerinas/headunitrevived/decoder/VideoDecoder.kt Outdated
…Decoder.kt

Co-authored-by: gemini-code-assist[bot] <176961590+gemini-code-assist[bot]@users.noreply.github.com>
@andreknieriem andreknieriem marked this pull request as ready for review April 7, 2026 07:35
@andreknieriem andreknieriem merged commit 969c012 into main Apr 7, 2026
@andreknieriem andreknieriem deleted the videodecoder branch April 7, 2026 07:35
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.

1 participant