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 314 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
333 } | 334 } |
334 | 335 |
335 void OpenSLESOutputStream::FillBufferQueueNoLock() { | 336 void OpenSLESOutputStream::FillBufferQueueNoLock() { |
336 // Ensure that the calling thread has acquired the lock since it is not | 337 // Ensure that the calling thread has acquired the lock since it is not |
337 // done in this method. | 338 // done in this method. |
338 lock_.AssertAcquired(); | 339 lock_.AssertAcquired(); |
339 | 340 |
340 // Calculate the position relative to the number of frames written. | 341 // Calculate the position relative to the number of frames written. |
341 uint32_t position_in_ms = 0; | 342 uint32_t position_in_ms = 0; |
342 SLresult err = (*player_)->GetPosition(player_, &position_in_ms); | 343 SLresult err = (*player_)->GetPosition(player_, &position_in_ms); |
343 const int delay = | 344 const base::TimeTicks target_playout_time = |
344 err == SL_RESULT_SUCCESS | 345 err == SL_RESULT_SUCCESS |
345 ? -delay_calculator_.GetFramesToTarget( | 346 ? base::TimeTicks::Now() - |
chcunningham
2016/07/29 01:21:09
I don't follow your math here. I think what you wa
jameswest
2016/08/26 02:08:47
Done.
| |
346 base::TimeDelta::FromMilliseconds(position_in_ms)) * | 347 base::TimeDelta::FromMilliseconds(position_in_ms) |
347 bytes_per_frame_ | 348 : base::TimeTicks(); |
chcunningham
2016/07/29 01:21:09
I don't think you want 0 ticks here. I think you w
jameswest
2016/08/26 02:08:47
Done.
| |
348 : 0; | 349 DCHECK_GE(target_playout_time, base::TimeTicks()); |
chcunningham
2016/07/29 01:21:09
Still use this to check delay >= 0 if you take my
jameswest
2016/08/26 02:08:47
Done.
| |
349 DCHECK_GE(delay, 0); | |
350 | 350 |
351 // Read data from the registered client source. | 351 // Read data from the registered client source. |
352 const int frames_filled = callback_->OnMoreData(audio_bus_.get(), delay, 0); | 352 const int frames_filled = callback_->OnMoreData(delay, 0, audio_bus_.get()); |
353 if (frames_filled <= 0) { | 353 if (frames_filled <= 0) { |
354 // Audio source is shutting down, or halted on error. | 354 // Audio source is shutting down, or halted on error. |
355 return; | 355 return; |
356 } | 356 } |
357 | 357 |
358 // Note: If the internal representation ever changes from 16-bit PCM to | 358 // Note: If the internal representation ever changes from 16-bit PCM to |
359 // raw float, the data must be clipped and sanitized since it may come | 359 // raw float, the data must be clipped and sanitized since it may come |
360 // from an untrusted source such as NaCl. | 360 // from an untrusted source such as NaCl. |
361 audio_bus_->Scale(muted_ ? 0.0f : volume_); | 361 audio_bus_->Scale(muted_ ? 0.0f : volume_); |
362 audio_bus_->ToInterleaved(frames_filled, format_.bitsPerSample / 8, | 362 audio_bus_->ToInterleaved(frames_filled, format_.bitsPerSample / 8, |
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
394 } | 394 } |
395 } | 395 } |
396 | 396 |
397 void OpenSLESOutputStream::HandleError(SLresult error) { | 397 void OpenSLESOutputStream::HandleError(SLresult error) { |
398 DLOG(ERROR) << "OpenSLES Output error " << error; | 398 DLOG(ERROR) << "OpenSLES Output error " << error; |
399 if (callback_) | 399 if (callback_) |
400 callback_->OnError(this); | 400 callback_->OnError(this); |
401 } | 401 } |
402 | 402 |
403 } // namespace media | 403 } // namespace media |
OLD | NEW |