Conversation
…onversion Introduce a callback-based DecodeToPcmStream function on both platforms that writes each decoded PCM chunk directly to the output file instead of accumulating all data in a std::vector before writing. This drastically reduces peak memory usage for large audio files. The existing DecodeToPcm now delegates to DecodeToPcmStream, preserving the accumulation behavior for callers that still need all data in memory (GetWaveform, Windows TrimAudio M4A branch). Affected paths: ConvertToWav, ConvertToM4a (Linux), and TrimAudio on both platforms. Adds a ~4 GB WAV size guard (kMaxWavDataSize).
- Add try/catch in DecodeToPcmStream (Linux/Windows) to prevent GStreamer/Media Foundation resource leaks when the onChunk callback throws (e.g. WAV size overflow) - Extract streamPcmToWav helper that encapsulates the placeholder-header, stream, seek-back, finalize pattern with proper file cleanup on error - Simplify ConvertToWav, ConvertToM4a, and TrimAudio to use the helper, eliminating ~5x code duplication - Add kMaxWavDataSize guard to Linux ConvertToM4a (was missing) - Document why Windows TrimAudio M4A path uses full buffering
There was a problem hiding this comment.
Pull request overview
This PR implements streaming-to-disk decoding for Linux and Windows audio conversion, eliminating the need to buffer entire decoded PCM audio in memory before writing. This follows the same approach previously implemented for Android (issue #14) and iOS/macOS (issue #18).
Changes:
- Introduces
DecodeToPcmStreamcallback-based API on Windows (Media Foundation) and Linux (GStreamer) - Refactors
ConvertToWav,ConvertToM4a(Linux), andTrimAudioto use streaming writes with placeholder WAV headers - Adds 4 GB WAV size limit enforcement consistent with Android/iOS implementations
Reviewed changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 5 comments.
| File | Description |
|---|---|
| windows/audio_decoder_plugin.h | Adds PcmInfo struct, streamPcmToWav, and DecodeToPcmStream method declarations; changes WriteWavHeader signature to accept std::ostream& |
| windows/audio_decoder_plugin.cpp | Implements streaming decode with Media Foundation, refactors WAV/trim operations to stream data, adds WAV size limit |
| linux/audio_decoder_plugin.cc | Implements streaming decode with GStreamer, refactors WAV/M4A/trim operations to stream data, adds WAV size limit |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
- Rename streamPcmToWav to StreamPcmToWav for consistency with project naming conventions (Linux + Windows) - Add error check after file.write() in onChunk callback to detect write failures early - Add error check after file.seekp(0) with cleanup on failure
This was referenced Feb 16, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
DecodeToPcmStreamfunction on both Linux (GStreamer) and Windows (Media Foundation) that writes each decoded PCM chunk directly to the output file instead of accumulating all data in astd::vector<uint8_t>before writingConvertToWav,ConvertToM4a(Linux), andTrimAudio(both platforms) to stream PCM to disk during decoding using placeholder WAV header + seek-back patternkMaxWavDataSize) consistent with Android/iOS implementationsTest plan
flutter test integration_test/)flutter test integration_test/)Closes #19