Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(264)

Side by Side Diff: media/audio/android/opensles_output.cc

Issue 2101303004: Pass delay and timestamp to AudioSourceCallback::OnMoreData. (Closed) Base URL: https://chromium.googlesource.com/chromium/src@master
Patch Set: Changes based on comments Created 4 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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
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 // Calculate the delay in frames.
miu 2016/08/31 23:26:54 nit: At first glance it feels wonky to get a time
James West 2016/09/13 07:40:50 Done.
344 err == SL_RESULT_SUCCESS 345 const int delay = err == SL_RESULT_SUCCESS
345 ? -delay_calculator_.GetFramesToTarget( 346 ? -delay_calculator_.GetFramesToTarget(
346 base::TimeDelta::FromMilliseconds(position_in_ms)) * 347 base::TimeDelta::FromMilliseconds(position_in_ms))
347 bytes_per_frame_ 348 : 0;
348 : 0;
349 DCHECK_GE(delay, 0); 349 DCHECK_GE(delay, 0);
350 350
351 // Calculate when the requested data will be played by converting the delay to
352 // time and adding it to the current time.
353 const base::TimeTicks target_playout_time =
354 base::TimeTicks::Now() +
355 base::TimeDelta::FromMicroseconds(
356 delay * base::Time::kMicrosecondsPerSecond / format_.samplesPerSec);
357
351 // Read data from the registered client source. 358 // Read data from the registered client source.
352 const int frames_filled = callback_->OnMoreData(audio_bus_.get(), delay, 0); 359 const int frames_filled =
360 callback_->OnMoreData(target_playout_time, 0, audio_bus_.get());
353 if (frames_filled <= 0) { 361 if (frames_filled <= 0) {
354 // Audio source is shutting down, or halted on error. 362 // Audio source is shutting down, or halted on error.
355 return; 363 return;
356 } 364 }
357 365
358 // Note: If the internal representation ever changes from 16-bit PCM to 366 // 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 367 // raw float, the data must be clipped and sanitized since it may come
360 // from an untrusted source such as NaCl. 368 // from an untrusted source such as NaCl.
361 audio_bus_->Scale(muted_ ? 0.0f : volume_); 369 audio_bus_->Scale(muted_ ? 0.0f : volume_);
362 audio_bus_->ToInterleaved(frames_filled, format_.bitsPerSample / 8, 370 audio_bus_->ToInterleaved(frames_filled, format_.bitsPerSample / 8,
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
394 } 402 }
395 } 403 }
396 404
397 void OpenSLESOutputStream::HandleError(SLresult error) { 405 void OpenSLESOutputStream::HandleError(SLresult error) {
398 DLOG(ERROR) << "OpenSLES Output error " << error; 406 DLOG(ERROR) << "OpenSLES Output error " << error;
399 if (callback_) 407 if (callback_)
400 callback_->OnError(this); 408 callback_->OnError(this);
401 } 409 }
402 410
403 } // namespace media 411 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698