Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1592)

Unified Diff: media/base/multi_channel_resampler.cc

Issue 14969017: Cleanup and reduce memory usage for MultiChannelResampler. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Cleanup. Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « media/base/multi_channel_resampler.h ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/multi_channel_resampler.cc
diff --git a/media/base/multi_channel_resampler.cc b/media/base/multi_channel_resampler.cc
index a9aa8d68909fc2bcb238aeef715282d56cf0b50f..801e5344cf2bb4c6671a6fa883d91c947df19322 100644
--- a/media/base/multi_channel_resampler.cc
+++ b/media/base/multi_channel_resampler.cc
@@ -15,8 +15,8 @@ MultiChannelResampler::MultiChannelResampler(int channels,
double io_sample_rate_ratio,
size_t request_size,
const ReadCB& read_cb)
- : last_frame_count_(0),
- read_cb_(read_cb),
+ : read_cb_(read_cb),
+ wrapped_resampler_audio_bus_(AudioBus::CreateWrapper(channels)),
output_frames_ready_(0) {
// Allocate each channel's resampler.
resamplers_.reserve(channels);
@@ -25,6 +25,19 @@ MultiChannelResampler::MultiChannelResampler(int channels,
io_sample_rate_ratio, request_size, base::Bind(
&MultiChannelResampler::ProvideInput, base::Unretained(this), i)));
}
+
+ // Setup the wrapped AudioBus for channel data.
+ wrapped_resampler_audio_bus_->set_frames(request_size);
+
+ // Allocate storage for all channels except the first, which will use the
+ // |destination| provided to ProvideInput() directly.
+ if (channels > 1) {
+ resampler_audio_bus_ = AudioBus::Create(channels - 1, request_size);
+ for (int i = 0; i < resampler_audio_bus_->channels(); ++i) {
+ wrapped_resampler_audio_bus_->SetChannelData(
+ i + 1, resampler_audio_bus_->channel(i));
+ }
+ }
}
MultiChannelResampler::~MultiChannelResampler() {}
@@ -72,40 +85,20 @@ void MultiChannelResampler::ProvideInput(int channel,
// for it. For subsequent channels, we can just dish out the channel data
// from that (stored in |resampler_audio_bus_|).
if (channel == 0) {
- // Allocate staging arrays on the first request and if the frame size or
- // |destination| changes (should only happen once).
- if (!resampler_audio_bus_.get() ||
- resampler_audio_bus_->frames() != frames ||
- wrapped_resampler_audio_bus_->channel(0) != destination) {
- resampler_audio_bus_ = AudioBus::Create(resamplers_.size(), frames);
-
- // Create a channel vector based on |resampler_audio_bus_| but using
- // |destination| directly for the first channel and then wrap it in a new
- // AudioBus so we can avoid an extra memcpy later.
- resampler_audio_data_.clear();
- resampler_audio_data_.reserve(resampler_audio_bus_->channels());
- resampler_audio_data_.push_back(destination);
- for (int i = 1; i < resampler_audio_bus_->channels(); ++i)
- resampler_audio_data_.push_back(resampler_audio_bus_->channel(i));
- wrapped_resampler_audio_bus_ = AudioBus::WrapVector(
- frames, resampler_audio_data_);
- }
-
- last_frame_count_ = frames;
+ wrapped_resampler_audio_bus_->SetChannelData(0, destination);
read_cb_.Run(output_frames_ready_, wrapped_resampler_audio_bus_.get());
} else {
// All channels must ask for the same amount. This should always be the
// case, but let's just make sure.
- DCHECK_EQ(frames, last_frame_count_);
+ DCHECK_EQ(frames, wrapped_resampler_audio_bus_->frames());
// Copy the channel data from what we received from |read_cb_|.
- memcpy(destination, resampler_audio_bus_->channel(channel),
- sizeof(*resampler_audio_bus_->channel(channel)) * frames);
+ memcpy(destination, wrapped_resampler_audio_bus_->channel(channel),
+ sizeof(*wrapped_resampler_audio_bus_->channel(channel)) * frames);
}
}
void MultiChannelResampler::Flush() {
- last_frame_count_ = 0;
for (size_t i = 0; i < resamplers_.size(); ++i)
resamplers_[i]->Flush();
}
« no previous file with comments | « media/base/multi_channel_resampler.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698