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

Unified 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 side-by-side diff with in-line comments
Download patch
Index: media/audio/android/opensles_output.cc
diff --git a/media/audio/android/opensles_output.cc b/media/audio/android/opensles_output.cc
index 5dc916ae03a565994736814dfee7d47ba2fc332d..72418e46a6dc29f5a51a3c099988b46c89285e93 100644
--- a/media/audio/android/opensles_output.cc
+++ b/media/audio/android/opensles_output.cc
@@ -6,6 +6,7 @@
#include "base/logging.h"
#include "base/macros.h"
+#include "base/time/time.h"
#include "base/trace_event/trace_event.h"
#include "media/audio/android/audio_manager_android.h"
@@ -340,16 +341,30 @@ void OpenSLESOutputStream::FillBufferQueueNoLock() {
// Calculate the position relative to the number of frames written.
uint32_t position_in_ms = 0;
SLresult err = (*player_)->GetPosition(player_, &position_in_ms);
- const int delay =
- err == SL_RESULT_SUCCESS
- ? -delay_calculator_.GetFramesToTarget(
- base::TimeDelta::FromMilliseconds(position_in_ms)) *
- bytes_per_frame_
- : 0;
+ // Given the position of the playback head, compute the approximate number of
+ // frames that have been queued to the buffer but not yet played out.
+ // This will be added to the system reference time below to compute the target
+ // playout time to pass to OnMoreData().
+ // Note that the value returned by GetFramesToTarget() is negative because
+ // more frames have been added to |delay_calculator_| than have been played
+ // out and thus the target timestamp is earlier than the current timestamp of
+ // |delay_calculator_|.
+ const int delay = err == SL_RESULT_SUCCESS
+ ? -delay_calculator_.GetFramesToTarget(
+ base::TimeDelta::FromMilliseconds(position_in_ms))
+ : 0;
DCHECK_GE(delay, 0);
+ // Calculate when the requested data will be played by converting the delay to
+ // time and adding it to the current time.
+ const base::TimeTicks target_playout_time =
+ base::TimeTicks::Now() +
+ base::TimeDelta::FromMicroseconds(
+ delay * base::Time::kMicrosecondsPerSecond / format_.samplesPerSec);
+
// Read data from the registered client source.
- const int frames_filled = callback_->OnMoreData(audio_bus_.get(), delay, 0);
+ const int frames_filled =
+ callback_->OnMoreData(target_playout_time, 0, audio_bus_.get());
if (frames_filled <= 0) {
// Audio source is shutting down, or halted on error.
return;

Powered by Google App Engine
This is Rietveld 408576698