Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
RecorderThread: Send input timestamps to MediaCodec encoders
This was previously disabled due to incorrect troubleshooting of an issue where the `c2.android.flac.encoder` component would crash during recording. It turns out the crash was caused by incorrect math: inputTimestamp += frames * 1000000 / audioRecord.sampleRate `frames` and `1000000` are both 32-bit integers, so the multiplication result overflowed and caused `inputTimestamp` (a 64-bit integer) to accumulate negative values, which would crash the encoder. This bug was inadvertently fixed during refactorying in commit 3d3eb82. This commit reenables the submission of timestamps to MediaCodec. To avoid accumulated error due to integer division when the microseconds per sample count is not perfectly divisible, the recording loop will keep track of the total frame count and only calculate the timestamp during buffer submission. This should fix issues where the encoded output files had overlapping audio or other weird audible artifacts. These were caused by MediaCodec's multithreaded encoding, where the lack of timestamps would cause encoded samples to be produced out of order. Fixes: #39 #54 Signed-off-by: Andrew Gunnerson <[email protected]>
- Loading branch information