Index: third_party/WebKit/Source/platform/audio/PushPullFIFO.cpp |
diff --git a/third_party/WebKit/Source/platform/audio/PushPullFIFO.cpp b/third_party/WebKit/Source/platform/audio/PushPullFIFO.cpp |
index fdfafd7a37b7ebf3252a98ece9924cee92556794..dca1d44c147d093559ef207ccc4cd3701063ec24 100644 |
--- a/third_party/WebKit/Source/platform/audio/PushPullFIFO.cpp |
+++ b/third_party/WebKit/Source/platform/audio/PushPullFIFO.cpp |
@@ -34,6 +34,8 @@ PushPullFIFO::~PushPullFIFO() {} |
// Push the data from |inputBus| to FIFO. The size of push is determined by |
// the length of |inputBus|. |
void PushPullFIFO::Push(const AudioBus* input_bus) { |
+ MutexLocker locker(lock_); |
+ |
CHECK(input_bus); |
CHECK_EQ(input_bus->length(), AudioUtilities::kRenderQuantumFrames); |
SECURITY_CHECK(input_bus->length() <= fifo_length_); |
@@ -82,7 +84,11 @@ void PushPullFIFO::Push(const AudioBus* input_bus) { |
// Pull the data out of FIFO to |outputBus|. If remaining frame in the FIFO |
// is less than the frames to pull, provides remaining frame plus the silence. |
-void PushPullFIFO::Pull(AudioBus* output_bus, size_t frames_requested) { |
+void PushPullFIFO::Pull( |
+ AudioBus* output_bus, |
+ size_t frames_requested, |
+ std::unique_ptr<WTF::Function<void(size_t, size_t)>> |
+ push_request_render_callback) { |
#if OS(ANDROID) |
if (!output_bus) { |
// Log when outputBus or FIFO object is invalid. (crbug.com/692423) |
@@ -110,6 +116,9 @@ void PushPullFIFO::Pull(AudioBus* output_bus, size_t frames_requested) { |
<< " >= " << fifo_length_ << ")"; |
} |
#endif |
+ |
+ MutexLocker locker(lock_); |
+ |
CHECK(output_bus); |
SECURITY_CHECK(frames_requested <= output_bus->length()); |
SECURITY_CHECK(frames_requested <= fifo_length_); |
@@ -162,10 +171,20 @@ void PushPullFIFO::Pull(AudioBus* output_bus, size_t frames_requested) { |
// Update the number of frames in FIFO. |
frames_available_ -= frames_to_fill; |
DCHECK_EQ((index_read_ + frames_available_) % fifo_length_, index_write_); |
+ |
+ // Number of frames to render via WebAudio graph. |framesToRender > 0| means |
+ // the frames in FIFO is not enough to fulfill the requested frames from the |
+ // audio device. |
+ size_t frames_to_render = frames_requested > frames_available_ |
+ ? frames_requested - frames_available_ |
+ : 0; |
+ |
+ if (frames_to_render > 0) |
+ (*push_request_render_callback)(frames_requested, frames_to_render); |
nhiroki
2017/04/17 03:27:30
This callback is called within the mutex section (
hongchan
2017/04/17 16:03:29
Actually that'd be cleaner than what I have here.
|
} |
const PushPullFIFOStateForTest PushPullFIFO::GetStateForTest() const { |
- return {length(), NumberOfChannels(), FramesAvailable(), index_read_, |
+ return {length(), NumberOfChannels(), frames_available_, index_read_, |
index_write_, overflow_count_, underflow_count_}; |
} |