diff --git a/media/base/audio_block_fifo.cc b/media/base/audio_block_fifo.cc index d98c40969f9c3..0e5627102189c 100644 --- a/media/base/audio_block_fifo.cc +++ b/media/base/audio_block_fifo.cc @@ -82,8 +82,15 @@ void AudioBlockFifo::IncreaseCapacity(int blocks) { audio_blocks_.begin() + original_size, audio_blocks_.end()); // Update the write pointer if it is on top of the new inserted blocks. - if (write_block_ >= read_block_) + // When write_block_ == read_block_ the ring is either empty + // (available_blocks_ == 0) or full (available_blocks_ == original_size). In + // the full case write_block_ must stay pointing at the first newly-inserted + // (empty) slot, otherwise subsequent Push() overwrites unconsumed data and + // Consume() returns the never-written AlignedUninit blocks. + if (write_block_ > read_block_ || + (write_block_ == read_block_ && available_blocks_ == 0)) { write_block_ += blocks; + } // Update the read pointers correspondingly. read_block_ += blocks;