Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "media/audio/audio_output_mixer.h" | 5 #include "media/audio/audio_output_mixer.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/message_loop.h" | 11 #include "base/message_loop.h" |
| 12 #include "base/time.h" | 12 #include "base/time.h" |
| 13 #include "media/audio/audio_io.h" | 13 #include "media/audio/audio_io.h" |
| 14 #include "media/audio/audio_output_proxy.h" | 14 #include "media/audio/audio_output_proxy.h" |
| 15 #include "media/audio/audio_util.h" | 15 #include "media/audio/audio_util.h" |
| 16 | 16 |
| 17 namespace media { | 17 namespace media { |
| 18 | 18 |
| 19 // Align audio data to 64-byte boundary. That is current max AVX can use. | |
| 20 const size_t kMixerDataAlignment = 64; | |
| 21 | |
| 19 AudioOutputMixer::AudioOutputMixer(AudioManager* audio_manager, | 22 AudioOutputMixer::AudioOutputMixer(AudioManager* audio_manager, |
| 20 const AudioParameters& params, | 23 const AudioParameters& params, |
| 21 const base::TimeDelta& close_delay) | 24 const base::TimeDelta& close_delay) |
| 22 : AudioOutputDispatcher(audio_manager, params), | 25 : AudioOutputDispatcher(audio_manager, params), |
| 23 ALLOW_THIS_IN_INITIALIZER_LIST(weak_this_(this)), | 26 ALLOW_THIS_IN_INITIALIZER_LIST(weak_this_(this)), |
| 24 close_timer_(FROM_HERE, | 27 close_timer_(FROM_HERE, |
| 25 close_delay, | 28 close_delay, |
| 26 weak_this_.GetWeakPtr(), | 29 weak_this_.GetWeakPtr(), |
| 27 &AudioOutputMixer::ClosePhysicalStream), | 30 &AudioOutputMixer::ClosePhysicalStream), |
| 28 pending_bytes_(0) { | 31 pending_bytes_(0) { |
| 29 // TODO(enal): align data. | 32 mixer_data_.reset( |
|
DaleCurtis
2012/06/04 20:48:12
Drive by: if you don't mind a 32 byte alignment yo
| |
| 30 mixer_data_.reset(new uint8[params_.GetBytesPerBuffer()]); | 33 new uint8[params_.GetBytesPerBuffer() + kMixerDataAlignment - 1]); |
| 34 aligned_mixer_data_ = reinterpret_cast<uint8*>( | |
| 35 (reinterpret_cast<size_t>(mixer_data_.get()) + kMixerDataAlignment - 1) & | |
| 36 ~(kMixerDataAlignment - 1)); | |
| 31 } | 37 } |
| 32 | 38 |
| 33 AudioOutputMixer::~AudioOutputMixer() { | 39 AudioOutputMixer::~AudioOutputMixer() { |
| 34 } | 40 } |
| 35 | 41 |
| 36 bool AudioOutputMixer::OpenStream() { | 42 bool AudioOutputMixer::OpenStream() { |
| 37 DCHECK_EQ(MessageLoop::current(), message_loop_); | 43 DCHECK_EQ(MessageLoop::current(), message_loop_); |
| 38 | 44 |
| 39 if (physical_stream_.get()) | 45 if (physical_stream_.get()) |
| 40 return true; | 46 return true; |
| (...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 190 // particular proxy stream. Use zero instead. | 196 // particular proxy stream. Use zero instead. |
| 191 uint32 actual_size = proxy_data->audio_source_callback->OnMoreData( | 197 uint32 actual_size = proxy_data->audio_source_callback->OnMoreData( |
| 192 actual_dest, | 198 actual_dest, |
| 193 max_size, | 199 max_size, |
| 194 AudioBuffersState(proxy_data->pending_bytes, 0)); | 200 AudioBuffersState(proxy_data->pending_bytes, 0)); |
| 195 if (actual_size == 0) | 201 if (actual_size == 0) |
| 196 continue; | 202 continue; |
| 197 | 203 |
| 198 // No need to mix muted stream. | 204 // No need to mix muted stream. |
| 199 double volume = proxy_data->volume; | 205 double volume = proxy_data->volume; |
| 200 if (volume == 0.0) | |
| 201 continue; | |
| 202 | 206 |
| 203 // Different handling for first and all subsequent streams. | 207 // Different handling for first and all subsequent streams. |
| 204 if (first_stream) { | 208 if (first_stream) { |
| 205 if (volume != 1.0) { | 209 if (volume != 1.0) { |
| 206 media::AdjustVolume(actual_dest, | 210 media::AdjustVolume(actual_dest, |
| 207 actual_size, | 211 actual_size, |
| 208 params_.channels(), | 212 params_.channels(), |
| 209 bytes_per_sample, | 213 bytes_per_sample, |
| 210 volume); | 214 volume); |
| 211 } | 215 } |
| 212 if (actual_size < max_size) | 216 if (actual_size < max_size) |
| 213 memset(dest + actual_size, 0, max_size - actual_size); | 217 memset(dest + actual_size, 0, max_size - actual_size); |
| 214 first_stream = false; | 218 first_stream = false; |
| 215 actual_dest = mixer_data_.get(); | 219 actual_dest = aligned_mixer_data_; |
| 216 actual_total_size = actual_size; | 220 actual_total_size = actual_size; |
| 217 } else { | 221 } else { |
| 218 media::MixStreams(dest, | 222 media::MixStreams(dest, |
| 219 actual_dest, | 223 actual_dest, |
| 220 actual_size, | 224 actual_size, |
| 221 bytes_per_sample, | 225 bytes_per_sample, |
| 222 volume); | 226 volume); |
| 223 actual_total_size = std::max(actual_size, actual_total_size); | 227 actual_total_size = std::max(actual_size, actual_total_size); |
| 224 } | 228 } |
| 225 } | 229 } |
| (...skipping 17 matching lines...) Expand all Loading... | |
| 243 } | 247 } |
| 244 | 248 |
| 245 void AudioOutputMixer::WaitTillDataReady() { | 249 void AudioOutputMixer::WaitTillDataReady() { |
| 246 base::AutoLock lock(lock_); | 250 base::AutoLock lock(lock_); |
| 247 for (ProxyMap::iterator it = proxies_.begin(); it != proxies_.end(); ++it) { | 251 for (ProxyMap::iterator it = proxies_.begin(); it != proxies_.end(); ++it) { |
| 248 it->second.audio_source_callback->WaitTillDataReady(); | 252 it->second.audio_source_callback->WaitTillDataReady(); |
| 249 } | 253 } |
| 250 } | 254 } |
| 251 | 255 |
| 252 } // namespace media | 256 } // namespace media |
| OLD | NEW |