Shield now passes this correctly through Plex and soon Kodi. Hopefully others will follow.
[Fix] Reworked TrueHD MAT packer to support high bitrate Atmos streams (fix audio dropouts)
xbmc:master
← thexai:fix-TrueHD
## Description Reworked TrueHD MAT packer to support high bitrate Atmos streams… (fix audio dropouts). Fixes https://github.com/xbmc/xbmc/issues/16704 ## Motivation and context This is a follow up of https://github.com/xbmc/xbmc/pull/17068 referenced PR only fix crashes but not audio dropouts. @anssih says: > However, audio dropouts still remain. To fix those, the TrueHD packet > offsets will need to be dynamically scaled based on the input_timing > field (TrueHD bytes 2-3) which allows determining the amount of time > required between the previous frame and the current frame. This PR basically does the aforementioned. Lets handle audio chunks of arbitrary length and variable offsets throughout the entire chain (CDVDAudioCodecPassthrough, CActiveAESink, CAEBitstreamPacker and IEC packer). The hardest work is in MAT packer and luckily there is already a code in ffmpeg that has been able to adapt. Seems also exist a secondary bug: After fixing the main issue of audio chunks > 2560 bytes that causes dropouts at specific timestamps, there are still smaller but more random dropouts.... I have solved this by reducing the number of consecutive audio chunks (basic audio units) that are stored in the buffer from 24 which is the "nominal" value to 12. I guess some part of code can't handle buffers of `TRUEHD_BUF_SIZE 61440` bytes length due some bug and memory gets corrupted/overwritten under some specific conditions when all or most of the available space is used. ## How has this been tested? Runtime tested on RTX 2060 + Denon AVR and Intel NUC8i3BEK + Denon AVR (Windows x64 only) As code touched is common in all platforms should fix audio dropouts on Android and Linux too. Forum feedback is positive 😃 https://forum.kodi.tv/showthread.php?tid=327153&pid=3065548#pid3065548 ## What is the effect on users? Fixes audio dropouts playing high bitrate TrueHD Atmos streams. ## Types of change - [X] **Bug fix** (non-breaking change which fixes an issue) - [ ] **Clean up** (non-breaking change which removes non-working, unmaintained functionality) - [ ] **Improvement** (non-breaking change which improves existing functionality) - [ ] **New feature** (non-breaking change which adds functionality) - [ ] **Breaking change** (fix or feature that will cause existing functionality to change) - [ ] **Cosmetic change** (non-breaking change that doesn't touch code) - [ ] **None of the above** (please explain below) ## Checklist: - [X] My code follows the **[Code Guidelines](https://github.com/xbmc/xbmc/blob/master/docs/CODE_GUIDELINES.md)** of this project - [ ] My change requires a change to the documentation, either Doxygen or wiki - [ ] I have updated the documentation accordingly - [X] I have read the **[Contributing](https://github.com/xbmc/xbmc/blob/master/docs/CONTRIBUTING.md)** document - [ ] I have added tests to cover my change - [ ] All new and existing tests passed