esphome / home-assistant-voice-pe

Home Assistant Voice PE
Other
42 stars 7 forks source link

FLAC decoder improvements #151

Open gnumpi opened 1 day ago

gnumpi commented 1 day ago

Resolved Issues:

  1. Frames are now flagged as corrupted if an invalid block size is detected, preventing memory access beyond allocated bounds.
  2. Frames are marked as corrupted when an unsupported bit depth is parsed (currently restricted to 16-bit).
  3. Correctly handle Rice partitions when encountering an escape code and when the bits per sample is zero.
  4. Ensure that failed frames are not retried for decoding if the buffer hasn’t changed, avoiding potential infinite loops.
  5. Discard processed buffer data after detecting a corrupted frame to force new data reading and initiate a fresh sync-code search.
  6. Reject frames marked as potentially failed when they are the last frame of a stream or file, preventing deadlocks.
  7. Residuals and predicted samples are now written directly to the frame_buffer, eliminating the need for dynamic memory allocation by avoiding the use of a vector.

None of the files in the FLAC bitstream test set (https://github.com/ietf-wg-cellar/flac-test-files) cause the decoder to crash anymore, but not all playable files are decoded correctly with this implementation. In addition to unsupported formats, such as 24-bit and multi-channel files, the following issues remain:

Remaining Issues:

esphome[bot] commented 3 hours ago

Please take a look at the requested changes, and use the Ready for review button when you are done, thanks :+1:

Learn more about our pull request process.