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/android/opensles_output.h" | 5 #include "media/audio/android/opensles_output.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "media/audio/audio_util.h" | |
9 #include "media/audio/android/audio_manager_android.h" | 8 #include "media/audio/android/audio_manager_android.h" |
10 | 9 |
11 namespace media { | 10 namespace media { |
12 | 11 |
13 OpenSLESOutputStream::OpenSLESOutputStream(AudioManagerAndroid* manager, | 12 OpenSLESOutputStream::OpenSLESOutputStream(AudioManagerAndroid* manager, |
14 const AudioParameters& params) | 13 const AudioParameters& params) |
15 : audio_manager_(manager), | 14 : audio_manager_(manager), |
16 callback_(NULL), | 15 callback_(NULL), |
17 player_(NULL), | 16 player_(NULL), |
18 simple_buffer_queue_(NULL), | 17 simple_buffer_queue_(NULL), |
(...skipping 241 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
260 uint32 hardware_delay = buffer_size_bytes_; | 259 uint32 hardware_delay = buffer_size_bytes_; |
261 int frames_filled = callback_->OnMoreData( | 260 int frames_filled = callback_->OnMoreData( |
262 audio_bus_.get(), AudioBuffersState(0, hardware_delay)); | 261 audio_bus_.get(), AudioBuffersState(0, hardware_delay)); |
263 if (frames_filled <= 0) | 262 if (frames_filled <= 0) |
264 return; // Audio source is shutting down, or halted on error. | 263 return; // Audio source is shutting down, or halted on error. |
265 int num_filled_bytes = | 264 int num_filled_bytes = |
266 frames_filled * audio_bus_->channels() * format_.bitsPerSample / 8; | 265 frames_filled * audio_bus_->channels() * format_.bitsPerSample / 8; |
267 DCHECK_LE(static_cast<size_t>(num_filled_bytes), buffer_size_bytes_); | 266 DCHECK_LE(static_cast<size_t>(num_filled_bytes), buffer_size_bytes_); |
268 // Note: If this ever changes to output raw float the data must be clipped and | 267 // Note: If this ever changes to output raw float the data must be clipped and |
269 // sanitized since it may come from an untrusted source such as NaCl. | 268 // sanitized since it may come from an untrusted source such as NaCl. |
| 269 audio_bus_->AdjustVolume(volume_); |
270 audio_bus_->ToInterleaved( | 270 audio_bus_->ToInterleaved( |
271 frames_filled, format_.bitsPerSample / 8, audio_data_[active_queue_]); | 271 frames_filled, format_.bitsPerSample / 8, audio_data_[active_queue_]); |
272 | 272 |
273 // Perform in-place, software-volume adjustments. | |
274 media::AdjustVolume(audio_data_[active_queue_], | |
275 num_filled_bytes, | |
276 format_.numChannels, | |
277 format_.bitsPerSample / 8, | |
278 volume_); | |
279 | |
280 // Enqueue the buffer for playback. | 273 // Enqueue the buffer for playback. |
281 SLresult err = (*simple_buffer_queue_)->Enqueue( | 274 SLresult err = (*simple_buffer_queue_)->Enqueue( |
282 simple_buffer_queue_, | 275 simple_buffer_queue_, |
283 audio_data_[active_queue_], | 276 audio_data_[active_queue_], |
284 num_filled_bytes); | 277 num_filled_bytes); |
285 if (SL_RESULT_SUCCESS != err) | 278 if (SL_RESULT_SUCCESS != err) |
286 HandleError(err); | 279 HandleError(err); |
287 | 280 |
288 active_queue_ = (active_queue_ + 1) % kNumOfQueuesInBuffer; | 281 active_queue_ = (active_queue_ + 1) % kNumOfQueuesInBuffer; |
289 } | 282 } |
(...skipping 14 matching lines...) Expand all Loading... |
304 } | 297 } |
305 } | 298 } |
306 | 299 |
307 void OpenSLESOutputStream::HandleError(SLresult error) { | 300 void OpenSLESOutputStream::HandleError(SLresult error) { |
308 DLOG(ERROR) << "OpenSLES error " << error; | 301 DLOG(ERROR) << "OpenSLES error " << error; |
309 if (callback_) | 302 if (callback_) |
310 callback_->OnError(this); | 303 callback_->OnError(this); |
311 } | 304 } |
312 | 305 |
313 } // namespace media | 306 } // namespace media |
OLD | NEW |