mirror of
https://github.com/androidx/media.git
synced 2025-04-30 06:46:50 +08:00

This more closely matches the intended, documented behaviour of this method. The previous implementation was incorrectly checking `sampleDataEnd + newSampleSize`, but it's more correct to compare `existingSampleDataLength + newSampleSize`, in order to handle the case of non-zero `sampleDataStart`. We've already checked above whether `newSampleSize` fits after `sampleDataEnd` without growing or reshuffling the array, so no need to basically repeat that check. In the case of handling one sample at a time, the previous implementation resulted in `sampleData` growing by `sampleSize` **every time** the pointers reached the end. With the new check for `sampleDataStart == sampleDataEnd`, this is avoided by always writing each new sample at the start of the array (because the previous sample has already been consumed), meaning `sampleData` remains equal to `sampleSize` without growing. PiperOrigin-RevId: 593119927