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 AudioOutputMixer::AudioOutputMixer(AudioManager* audio_manager, | 19 AudioOutputMixer::AudioOutputMixer(AudioManager* audio_manager, |
20 const AudioParameters& params, | 20 const AudioParameters& params, |
21 const base::TimeDelta& close_delay) | 21 const base::TimeDelta& close_delay) |
22 : AudioOutputDispatcher(audio_manager, params), | 22 : AudioOutputDispatcher(audio_manager, params), |
23 mixer_data_(new DecoderBuffer(params_.GetBytesPerBuffer())), | |
scherkus (not reviewing)
2012/06/05 16:37:43
I'm not convinced we should be using DecoderBuffer
| |
23 ALLOW_THIS_IN_INITIALIZER_LIST(weak_this_(this)), | 24 ALLOW_THIS_IN_INITIALIZER_LIST(weak_this_(this)), |
24 close_timer_(FROM_HERE, | 25 close_timer_(FROM_HERE, |
25 close_delay, | 26 close_delay, |
26 weak_this_.GetWeakPtr(), | 27 weak_this_.GetWeakPtr(), |
27 &AudioOutputMixer::ClosePhysicalStream), | 28 &AudioOutputMixer::ClosePhysicalStream), |
28 pending_bytes_(0) { | 29 pending_bytes_(0) { |
29 // TODO(enal): align data. | |
30 mixer_data_.reset(new uint8[params_.GetBytesPerBuffer()]); | |
31 } | 30 } |
32 | 31 |
33 AudioOutputMixer::~AudioOutputMixer() { | 32 AudioOutputMixer::~AudioOutputMixer() { |
34 } | 33 } |
35 | 34 |
36 bool AudioOutputMixer::OpenStream() { | 35 bool AudioOutputMixer::OpenStream() { |
37 DCHECK_EQ(MessageLoop::current(), message_loop_); | 36 DCHECK_EQ(MessageLoop::current(), message_loop_); |
38 | 37 |
39 if (physical_stream_.get()) | 38 if (physical_stream_.get()) |
40 return true; | 39 return true; |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
201 if (volume != 1.0) { | 200 if (volume != 1.0) { |
202 media::AdjustVolume(actual_dest, | 201 media::AdjustVolume(actual_dest, |
203 actual_size, | 202 actual_size, |
204 params_.channels(), | 203 params_.channels(), |
205 bytes_per_sample, | 204 bytes_per_sample, |
206 volume); | 205 volume); |
207 } | 206 } |
208 if (actual_size < max_size) | 207 if (actual_size < max_size) |
209 memset(dest + actual_size, 0, max_size - actual_size); | 208 memset(dest + actual_size, 0, max_size - actual_size); |
210 first_stream = false; | 209 first_stream = false; |
211 actual_dest = mixer_data_.get(); | 210 actual_dest = mixer_data_->GetWritableData(); |
212 actual_total_size = actual_size; | 211 actual_total_size = actual_size; |
213 } else { | 212 } else { |
214 media::MixStreams(dest, | 213 media::MixStreams(dest, |
215 actual_dest, | 214 actual_dest, |
216 actual_size, | 215 actual_size, |
217 bytes_per_sample, | 216 bytes_per_sample, |
218 volume); | 217 volume); |
219 actual_total_size = std::max(actual_size, actual_total_size); | 218 actual_total_size = std::max(actual_size, actual_total_size); |
220 } | 219 } |
221 } | 220 } |
(...skipping 17 matching lines...) Expand all Loading... | |
239 } | 238 } |
240 | 239 |
241 void AudioOutputMixer::WaitTillDataReady() { | 240 void AudioOutputMixer::WaitTillDataReady() { |
242 base::AutoLock lock(lock_); | 241 base::AutoLock lock(lock_); |
243 for (ProxyMap::iterator it = proxies_.begin(); it != proxies_.end(); ++it) { | 242 for (ProxyMap::iterator it = proxies_.begin(); it != proxies_.end(); ++it) { |
244 it->second.audio_source_callback->WaitTillDataReady(); | 243 it->second.audio_source_callback->WaitTillDataReady(); |
245 } | 244 } |
246 } | 245 } |
247 | 246 |
248 } // namespace media | 247 } // namespace media |
OLD | NEW |