Commit 746130e2 authored by Ken MacKay's avatar Ken MacKay Committed by Commit Bot

[Chromecast] Reduce copying in CastAudioOutputStream

Change-Id: I3d09f627e3e3e808ecf5a288c39d048bf3a34852
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1872128Reviewed-by: default avatarYuchen Liu <yucliu@chromium.org>
Commit-Queue: Kenneth MacKay <kmackay@chromium.org>
Cr-Commit-Position: refs/heads/master@{#707923}
parent 0257b4cf
...@@ -239,13 +239,15 @@ void CastAudioOutputStream::MixerServiceWrapper::FillNextBuffer( ...@@ -239,13 +239,15 @@ void CastAudioOutputStream::MixerServiceWrapper::FillNextBuffer(
playout_timestamp = 0; playout_timestamp = 0;
} }
// If |audio_bus_| has been created (i.e., this is not the first // Wrap the data buffer so we can write directly into it.
// FillNextBuffer call) and |frames| doesn't change, which is expected behavir if (!audio_bus_) {
// from MixerServiceConnection, the |audio_bus_| won't be recreated but be audio_bus_ = ::media::AudioBus::CreateWrapper(audio_params_.channels());
// reused.
if (!audio_bus_ || frames != audio_bus_->frames()) {
audio_bus_ = ::media::AudioBus::Create(audio_params_.channels(), frames);
} }
float* channel_data = static_cast<float*>(buffer);
for (int c = 0; c < audio_params_.channels(); ++c) {
audio_bus_->SetChannelData(c, channel_data + c * frames);
}
audio_bus_->set_frames(frames);
base::TimeDelta delay = kMixerStartThreshold; base::TimeDelta delay = kMixerStartThreshold;
base::TimeTicks delay_timestamp = base::TimeTicks delay_timestamp =
...@@ -253,14 +255,8 @@ void CastAudioOutputStream::MixerServiceWrapper::FillNextBuffer( ...@@ -253,14 +255,8 @@ void CastAudioOutputStream::MixerServiceWrapper::FillNextBuffer(
int frames_filled = int frames_filled =
source_callback_->OnMoreData(delay, delay_timestamp, 0, audio_bus_.get()); source_callback_->OnMoreData(delay, delay_timestamp, 0, audio_bus_.get());
DCHECK_EQ(frames_filled, frames);
float* channel_data = static_cast<float*>(buffer); mixer_connection_->SendNextBuffer(frames);
for (int channel = 0; channel < audio_params_.channels(); channel++) {
std::copy_n(audio_bus_->channel(channel), frames_filled, channel_data);
channel_data += frames_filled;
}
mixer_connection_->SendNextBuffer(frames_filled);
} }
CastAudioOutputStream::CastAudioOutputStream( CastAudioOutputStream::CastAudioOutputStream(
......
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