Commit abdf1cba authored by Muyuan Li's avatar Muyuan Li Committed by Commit Bot

assistant: fix garbage data at end of audio stream.

Bug: b/112431554
Test: Manual
Change-Id: I10e52dad59b2989fe9ba223b3c8cf130143ea9b8
Reviewed-on: https://chromium-review.googlesource.com/1170031
Commit-Queue: Muyuan Li <muyuanli@chromium.org>
Reviewed-by: default avatarXiaohui Chen <xiaohuic@chromium.org>
Cr-Commit-Position: refs/heads/master@{#581962}
parent 131641f0
......@@ -279,7 +279,23 @@ int AudioDeviceOwner::Render(base::TimeDelta delay,
// very beginning.
return 0;
}
audio_fifo_->Consume()->CopyTo(dest);
int available_frames = audio_fifo_->GetAvailableFrames();
if (available_frames < dest->frames()) {
// audio_fifo_->Consume() returns a whole audio bus. In our case,
// bus->frames() == dest->frames(). If there aren't enough frames to fill
// the bus, the rest of it would be garbage data. In such case,
// audio_fifo_->GetAvailableFrames() < dest->frames(). We use
// bus->CopyPartialFrames() to only copy the valid frames and zero out
// the rest to avoid playing the garbage.
const media::AudioBus* bus = audio_fifo_->Consume();
DCHECK(available_frames <= bus->frames());
bus->CopyPartialFramesTo(0, available_frames, 0, dest);
} else {
audio_fifo_->Consume()->CopyTo(dest);
}
ScheduleFillLocked(base::TimeTicks::Now());
return dest->frames();
}
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment