| 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 "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/time/time.h" |
| 9 #include "base/trace_event/trace_event.h" | 10 #include "base/trace_event/trace_event.h" |
| 10 #include "media/audio/android/audio_manager_android.h" | 11 #include "media/audio/android/audio_manager_android.h" |
| 11 | 12 |
| 12 #define LOG_ON_FAILURE_AND_RETURN(op, ...) \ | 13 #define LOG_ON_FAILURE_AND_RETURN(op, ...) \ |
| 13 do { \ | 14 do { \ |
| 14 SLresult err = (op); \ | 15 SLresult err = (op); \ |
| 15 if (err != SL_RESULT_SUCCESS) { \ | 16 if (err != SL_RESULT_SUCCESS) { \ |
| 16 DLOG(ERROR) << #op << " failed: " << err; \ | 17 DLOG(ERROR) << #op << " failed: " << err; \ |
| 17 return __VA_ARGS__; \ | 18 return __VA_ARGS__; \ |
| 18 } \ | 19 } \ |
| (...skipping 310 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 329 SLresult err = (*player_)->GetPosition(player_, &position_in_ms); | 330 SLresult err = (*player_)->GetPosition(player_, &position_in_ms); |
| 330 const int delay = | 331 const int delay = |
| 331 err == SL_RESULT_SUCCESS | 332 err == SL_RESULT_SUCCESS |
| 332 ? -delay_calculator_.GetFramesToTarget( | 333 ? -delay_calculator_.GetFramesToTarget( |
| 333 base::TimeDelta::FromMilliseconds(position_in_ms)) * | 334 base::TimeDelta::FromMilliseconds(position_in_ms)) * |
| 334 bytes_per_frame_ | 335 bytes_per_frame_ |
| 335 : 0; | 336 : 0; |
| 336 DCHECK_GE(delay, 0); | 337 DCHECK_GE(delay, 0); |
| 337 | 338 |
| 338 // Read data from the registered client source. | 339 // Read data from the registered client source. |
| 339 const int frames_filled = callback_->OnMoreData(audio_bus_.get(), delay, 0); | 340 const int frames_filled = |
| 341 callback_->OnMoreData(audio_bus_.get(), delay, base::TimeDelta(), 0); |
| 340 if (frames_filled <= 0) { | 342 if (frames_filled <= 0) { |
| 341 // Audio source is shutting down, or halted on error. | 343 // Audio source is shutting down, or halted on error. |
| 342 return; | 344 return; |
| 343 } | 345 } |
| 344 | 346 |
| 345 // Note: If the internal representation ever changes from 16-bit PCM to | 347 // Note: If the internal representation ever changes from 16-bit PCM to |
| 346 // raw float, the data must be clipped and sanitized since it may come | 348 // raw float, the data must be clipped and sanitized since it may come |
| 347 // from an untrusted source such as NaCl. | 349 // from an untrusted source such as NaCl. |
| 348 audio_bus_->Scale(muted_ ? 0.0f : volume_); | 350 audio_bus_->Scale(muted_ ? 0.0f : volume_); |
| 349 audio_bus_->ToInterleaved(frames_filled, format_.bitsPerSample / 8, | 351 audio_bus_->ToInterleaved(frames_filled, format_.bitsPerSample / 8, |
| (...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 381 } | 383 } |
| 382 } | 384 } |
| 383 | 385 |
| 384 void OpenSLESOutputStream::HandleError(SLresult error) { | 386 void OpenSLESOutputStream::HandleError(SLresult error) { |
| 385 DLOG(ERROR) << "OpenSLES Output error " << error; | 387 DLOG(ERROR) << "OpenSLES Output error " << error; |
| 386 if (callback_) | 388 if (callback_) |
| 387 callback_->OnError(this); | 389 callback_->OnError(this); |
| 388 } | 390 } |
| 389 | 391 |
| 390 } // namespace media | 392 } // namespace media |
| OLD | NEW |