OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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_controller.h" | 5 #include "media/audio/audio_output_controller.h" |
6 | 6 |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 | 8 |
9 // Signal a pause in low-latency mode. | 9 // Signal a pause in low-latency mode. |
10 static const int kPauseMark = -1; | 10 static const int kPauseMark = -1; |
(...skipping 111 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
122 | 122 |
123 void AudioOutputController::SetVolume(double volume) { | 123 void AudioOutputController::SetVolume(double volume) { |
124 DCHECK(message_loop_); | 124 DCHECK(message_loop_); |
125 message_loop_->PostTask( | 125 message_loop_->PostTask( |
126 FROM_HERE, | 126 FROM_HERE, |
127 NewRunnableMethod(this, &AudioOutputController::DoSetVolume, volume)); | 127 NewRunnableMethod(this, &AudioOutputController::DoSetVolume, volume)); |
128 } | 128 } |
129 | 129 |
130 void AudioOutputController::EnqueueData(const uint8* data, uint32 size) { | 130 void AudioOutputController::EnqueueData(const uint8* data, uint32 size) { |
131 // Write data to the push source and ask for more data if needed. | 131 // Write data to the push source and ask for more data if needed. |
132 AutoLock auto_lock(lock_); | 132 base::AutoLock auto_lock(lock_); |
133 pending_request_ = false; | 133 pending_request_ = false; |
134 // If |size| is set to 0, it indicates that the audio source doesn't have | 134 // If |size| is set to 0, it indicates that the audio source doesn't have |
135 // more data right now, and so it doesn't make sense to send additional | 135 // more data right now, and so it doesn't make sense to send additional |
136 // request. | 136 // request. |
137 if (size) { | 137 if (size) { |
138 buffer_.Append(data, size); | 138 buffer_.Append(data, size); |
139 SubmitOnMoreData_Locked(); | 139 SubmitOnMoreData_Locked(); |
140 } | 140 } |
141 } | 141 } |
142 | 142 |
(...skipping 28 matching lines...) Expand all Loading... |
171 stream_->SetVolume(volume_); | 171 stream_->SetVolume(volume_); |
172 | 172 |
173 // Finally set the state to kCreated. | 173 // Finally set the state to kCreated. |
174 state_ = kCreated; | 174 state_ = kCreated; |
175 | 175 |
176 // And then report we have been created. | 176 // And then report we have been created. |
177 handler_->OnCreated(this); | 177 handler_->OnCreated(this); |
178 | 178 |
179 // If in normal latency mode then start buffering. | 179 // If in normal latency mode then start buffering. |
180 if (!LowLatencyMode()) { | 180 if (!LowLatencyMode()) { |
181 AutoLock auto_lock(lock_); | 181 base::AutoLock auto_lock(lock_); |
182 SubmitOnMoreData_Locked(); | 182 SubmitOnMoreData_Locked(); |
183 } | 183 } |
184 } | 184 } |
185 | 185 |
186 void AudioOutputController::DoPlay() { | 186 void AudioOutputController::DoPlay() { |
187 DCHECK_EQ(message_loop_, MessageLoop::current()); | 187 DCHECK_EQ(message_loop_, MessageLoop::current()); |
188 | 188 |
189 // We can start from created or paused state. | 189 // We can start from created or paused state. |
190 if (state_ != kCreated && state_ != kPaused) | 190 if (state_ != kCreated && state_ != kPaused) |
191 return; | 191 return; |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 DCHECK_EQ(message_loop_, MessageLoop::current()); | 273 DCHECK_EQ(message_loop_, MessageLoop::current()); |
274 if (state_ != kClosed) | 274 if (state_ != kClosed) |
275 handler_->OnError(this, code); | 275 handler_->OnError(this, code); |
276 } | 276 } |
277 | 277 |
278 uint32 AudioOutputController::OnMoreData( | 278 uint32 AudioOutputController::OnMoreData( |
279 AudioOutputStream* stream, uint8* dest, | 279 AudioOutputStream* stream, uint8* dest, |
280 uint32 max_size, AudioBuffersState buffers_state) { | 280 uint32 max_size, AudioBuffersState buffers_state) { |
281 // If regular latency mode is used. | 281 // If regular latency mode is used. |
282 if (!sync_reader_) { | 282 if (!sync_reader_) { |
283 AutoLock auto_lock(lock_); | 283 base::AutoLock auto_lock(lock_); |
284 | 284 |
285 // Save current buffers state. | 285 // Save current buffers state. |
286 buffers_state_ = buffers_state; | 286 buffers_state_ = buffers_state; |
287 | 287 |
288 if (state_ != kPlaying) { | 288 if (state_ != kPlaying) { |
289 // Don't read anything. Save the number of bytes in the hardware buffer. | 289 // Don't read anything. Save the number of bytes in the hardware buffer. |
290 return 0; | 290 return 0; |
291 } | 291 } |
292 | 292 |
293 uint32 size = buffer_.Read(dest, max_size); | 293 uint32 size = buffer_.Read(dest, max_size); |
(...skipping 24 matching lines...) Expand all Loading... |
318 if (pending_request_) | 318 if (pending_request_) |
319 return; | 319 return; |
320 pending_request_ = true; | 320 pending_request_ = true; |
321 | 321 |
322 AudioBuffersState buffers_state = buffers_state_; | 322 AudioBuffersState buffers_state = buffers_state_; |
323 buffers_state.pending_bytes += buffer_.forward_bytes(); | 323 buffers_state.pending_bytes += buffer_.forward_bytes(); |
324 | 324 |
325 // If we need more data then call the event handler to ask for more data. | 325 // If we need more data then call the event handler to ask for more data. |
326 // It is okay that we don't lock in this block because the parameters are | 326 // It is okay that we don't lock in this block because the parameters are |
327 // correct and in the worst case we are just asking more data than needed. | 327 // correct and in the worst case we are just asking more data than needed. |
328 AutoUnlock auto_unlock(lock_); | 328 base::AutoUnlock auto_unlock(lock_); |
329 handler_->OnMoreData(this, buffers_state); | 329 handler_->OnMoreData(this, buffers_state); |
330 } | 330 } |
331 | 331 |
332 } // namespace media | 332 } // namespace media |
OLD | NEW |