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/virtual_audio_input_stream.h" | 5 #include "media/audio/virtual_audio_input_stream.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/bind.h" | 10 #include "base/bind.h" |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
78 } | 78 } |
79 | 79 |
80 bool VirtualAudioInputStream::Open() { | 80 bool VirtualAudioInputStream::Open() { |
81 memset(buffer_.get(), 0, params_.GetBytesPerBuffer()); | 81 memset(buffer_.get(), 0, params_.GetBytesPerBuffer()); |
82 return true; | 82 return true; |
83 } | 83 } |
84 | 84 |
85 void VirtualAudioInputStream::Start(AudioInputCallback* callback) { | 85 void VirtualAudioInputStream::Start(AudioInputCallback* callback) { |
86 DCHECK(message_loop_->BelongsToCurrentThread()); | 86 DCHECK(message_loop_->BelongsToCurrentThread()); |
87 callback_ = callback; | 87 callback_ = callback; |
88 next_read_time_ = base::Time::Now(); | |
88 on_more_data_cb_.Reset(base::Bind(&VirtualAudioInputStream::ReadAudio, | 89 on_more_data_cb_.Reset(base::Bind(&VirtualAudioInputStream::ReadAudio, |
89 base::Unretained(this))); | 90 base::Unretained(this))); |
90 audio_manager_->GetMessageLoop()->PostTask(FROM_HERE, | 91 audio_manager_->GetMessageLoop()->PostTask(FROM_HERE, |
91 on_more_data_cb_.callback()); | 92 on_more_data_cb_.callback()); |
92 } | 93 } |
93 | 94 |
94 void VirtualAudioInputStream::Stop() { | 95 void VirtualAudioInputStream::Stop() { |
95 DCHECK(message_loop_->BelongsToCurrentThread()); | 96 DCHECK(message_loop_->BelongsToCurrentThread()); |
96 on_more_data_cb_.Cancel(); | 97 on_more_data_cb_.Cancel(); |
97 } | 98 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
132 audio_bus_->ToInterleaved(params_.frames_per_buffer(), | 133 audio_bus_->ToInterleaved(params_.frames_per_buffer(), |
133 params_.bits_per_sample() / 8, | 134 params_.bits_per_sample() / 8, |
134 buffer_.get()); | 135 buffer_.get()); |
135 | 136 |
136 callback_->OnData(this, | 137 callback_->OnData(this, |
137 buffer_.get(), | 138 buffer_.get(), |
138 params_.GetBytesPerBuffer(), | 139 params_.GetBytesPerBuffer(), |
139 params_.GetBytesPerBuffer(), | 140 params_.GetBytesPerBuffer(), |
140 1.0); | 141 1.0); |
141 | 142 |
143 // Need to account for time spent here due to renderer side mixing. | |
144 next_read_time_ += buffer_duration_ms_; | |
145 base::TimeDelta delay = next_read_time_ - base::Time::Now(); | |
146 if (delay < base::TimeDelta()) | |
DaleCurtis
2013/01/15 21:00:08
I'd worry about drift over time here. Can you limi
justinlin
2013/01/15 22:36:21
I tested this and actually the comment I left ther
| |
147 delay = base::TimeDelta(); | |
148 | |
142 message_loop_->PostDelayedTask(FROM_HERE, | 149 message_loop_->PostDelayedTask(FROM_HERE, |
143 on_more_data_cb_.callback(), | 150 on_more_data_cb_.callback(), |
144 buffer_duration_ms_); | 151 delay); |
145 } | 152 } |
146 | 153 |
147 void VirtualAudioInputStream::Close() { | 154 void VirtualAudioInputStream::Close() { |
148 DCHECK(message_loop_->BelongsToCurrentThread()); | 155 DCHECK(message_loop_->BelongsToCurrentThread()); |
149 if (callback_) { | 156 if (callback_) { |
150 DCHECK(on_more_data_cb_.IsCancelled()); | 157 DCHECK(on_more_data_cb_.IsCancelled()); |
151 callback_->OnClose(this); | 158 callback_->OnClose(this); |
152 callback_ = NULL; | 159 callback_ = NULL; |
153 } | 160 } |
154 audio_manager_->ReleaseInputStream(this); | 161 audio_manager_->ReleaseInputStream(this); |
155 } | 162 } |
156 | 163 |
157 double VirtualAudioInputStream::GetMaxVolume() { | 164 double VirtualAudioInputStream::GetMaxVolume() { |
158 return 1.0; | 165 return 1.0; |
159 } | 166 } |
160 | 167 |
161 void VirtualAudioInputStream::SetVolume(double volume) {} | 168 void VirtualAudioInputStream::SetVolume(double volume) {} |
162 | 169 |
163 double VirtualAudioInputStream::GetVolume() { | 170 double VirtualAudioInputStream::GetVolume() { |
164 return 1.0; | 171 return 1.0; |
165 } | 172 } |
166 | 173 |
167 void VirtualAudioInputStream::SetAutomaticGainControl(bool enabled) {} | 174 void VirtualAudioInputStream::SetAutomaticGainControl(bool enabled) {} |
168 | 175 |
169 bool VirtualAudioInputStream::GetAutomaticGainControl() { | 176 bool VirtualAudioInputStream::GetAutomaticGainControl() { |
170 return false; | 177 return false; |
171 } | 178 } |
172 | 179 |
173 } // namespace media | 180 } // namespace media |
OLD | NEW |