Fix issue with failing to call AudioBufferSource.onended in some cases.

AudioBufferSource.onended was not being called because we thought the
source should have already stopped but had not actually stopped.  This
happened when starting the source via start().  The current context
time was recorded as the start time of the source, but in some cases,
this was already too late, and the source would get started at the
next rendering quantum.

However, the stop time was computed using the recorded start time, so we
would expect the source to stop one rendering quantum sooner than it
actually would.  Because of this, we would stop the source but NOT fire
the onended event.

To fix this, change the check to add a little extra time before
stopping the source.  We don't need to be extra precise here; just
stop the source some time after it would have stopped.

This can't be tested using an offline context because start() always
starts at the correct time.

Run the manual test and watch the results (in the window) and the
console.log.  Both tones should be played if everything is working.

BUG=478301
TEST=ManualTests/webaudio/audiobuffersource-onended.html

Review URL: https://codereview.chromium.org/1097373003

git-svn-id: svn://svn.chromium.org/blink/trunk@194413 bbb929c8-8fbe-4397-9dbb-9b2b20218538
2 files changed