Commit 051911e2 authored by Olga Sharonova's avatar Olga Sharonova Committed by Commit Bot

Reduce Remove dynamic memory allocations in AudioSourceProviderImpl

Reduce the frequency of dynamic memory allocations
in MediaStreamComponent::AudioSourceProviderImpl::ProvideInput()
which is running a on realtime audio thread.

Bug: 1138927
Change-Id: I73853fd5dcd7e0ab4de42204e81c081d260a3413
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2485164
Commit-Queue: Olga Sharonova <olka@chromium.org>
Commit-Queue: Guido Urdaneta <guidou@chromium.org>
Auto-Submit: Olga Sharonova <olka@chromium.org>
Reviewed-by: default avatarGuido Urdaneta <guidou@chromium.org>
Cr-Commit-Position: refs/heads/master@{#818886}
parent 4d58234a
...@@ -124,11 +124,13 @@ void MediaStreamComponent::AudioSourceProviderImpl::ProvideInput( ...@@ -124,11 +124,13 @@ void MediaStreamComponent::AudioSourceProviderImpl::ProvideInput(
// Wrap the AudioBus channel data using WebVector. // Wrap the AudioBus channel data using WebVector.
uint32_t n = bus->NumberOfChannels(); uint32_t n = bus->NumberOfChannels();
WebVector<float*> web_audio_data(n); if (web_audio_data_.size() != n)
web_audio_data_ = WebVector<float*>(static_cast<size_t>(n));
for (uint32_t i = 0; i < n; ++i) for (uint32_t i = 0; i < n; ++i)
web_audio_data[i] = bus->Channel(i)->MutableData(); web_audio_data_[i] = bus->Channel(i)->MutableData();
web_audio_source_provider_->ProvideInput(web_audio_data, frames_to_process); web_audio_source_provider_->ProvideInput(web_audio_data_, frames_to_process);
} }
void MediaStreamComponent::Trace(Visitor* visitor) const { void MediaStreamComponent::Trace(Visitor* visitor) const {
......
...@@ -35,6 +35,7 @@ ...@@ -35,6 +35,7 @@
#include <memory> #include <memory>
#include "third_party/blink/public/platform/modules/mediastream/web_media_stream_track.h" #include "third_party/blink/public/platform/modules/mediastream/web_media_stream_track.h"
#include "third_party/blink/public/platform/web_vector.h"
#include "third_party/blink/renderer/platform/audio/audio_source_provider.h" #include "third_party/blink/renderer/platform/audio/audio_source_provider.h"
#include "third_party/blink/renderer/platform/heap/handle.h" #include "third_party/blink/renderer/platform/heap/handle.h"
#include "third_party/blink/renderer/platform/mediastream/media_constraints.h" #include "third_party/blink/renderer/platform/mediastream/media_constraints.h"
...@@ -125,6 +126,9 @@ class PLATFORM_EXPORT MediaStreamComponent final ...@@ -125,6 +126,9 @@ class PLATFORM_EXPORT MediaStreamComponent final
private: private:
WebAudioSourceProvider* web_audio_source_provider_; WebAudioSourceProvider* web_audio_source_provider_;
Mutex provide_input_lock_; Mutex provide_input_lock_;
// Used to wrap AudioBus to be passed into |web_audio_source_provider_|.
WebVector<float*> web_audio_data_;
}; };
AudioSourceProviderImpl source_provider_; AudioSourceProviderImpl source_provider_;
......
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