Index: media/audio/mac/audio_auhal_mac.cc |
diff --git a/media/audio/mac/audio_auhal_mac.cc b/media/audio/mac/audio_auhal_mac.cc |
index c9134023924e8b74ecffd7346b304d0dccd64f96..3cbbf564498f63f295413d1f174cf2aa8ac87a2a 100644 |
--- a/media/audio/mac/audio_auhal_mac.cc |
+++ b/media/audio/mac/audio_auhal_mac.cc |
@@ -6,13 +6,14 @@ |
#include <CoreServices/CoreServices.h> |
+#include <string> |
+ |
#include "base/bind.h" |
#include "base/bind_helpers.h" |
#include "base/logging.h" |
#include "base/mac/mac_logging.h" |
#include "base/metrics/histogram_macros.h" |
#include "base/strings/stringprintf.h" |
-#include "base/time/time.h" |
#include "base/trace_event/trace_event.h" |
#include "media/audio/mac/audio_manager_mac.h" |
#include "media/base/audio_pull_fifo.h" |
@@ -236,10 +237,12 @@ OSStatus AUHALStream::Render( |
// Make |output_bus_| wrap the output AudioBufferList. |
WrapBufferList(data, output_bus_.get(), number_of_frames); |
- // Update the playout latency. |
- const double playout_latency_frames = GetPlayoutLatency(output_time_stamp); |
- current_hardware_pending_bytes_ = static_cast<uint32_t>( |
- (playout_latency_frames + 0.5) * params_.GetBytesPerFrame()); |
+ // Update the playout time. |
+ const UInt64 output_time_ns = |
+ AudioConvertHostTimeToNanos(output_time_stamp->mHostTime); |
+ // TODO(jameswest): Find an alternative to FromInternalValue. |
+ current_target_playout_time_ = base::TimeTicks::FromInternalValue( |
+ output_time_ns / base::Time::kNanosecondsPerMicrosecond); |
if (audio_fifo_) |
audio_fifo_->Consume(output_bus_.get(), output_bus_->frames()); |
@@ -258,10 +261,13 @@ void AUHALStream::ProvideInput(int frame_delay, AudioBus* dest) { |
return; |
} |
+ const base::TimeDelta delay = base::TimeDelta::FromSecondsD( |
+ static_cast<double>(frame_delay) / params_.sample_rate()); |
+ const base::TimeTicks target_playout_time = |
+ current_target_playout_time_ + delay; |
+ |
// Supply the input data and render the output data. |
- source_->OnMoreData(dest, current_hardware_pending_bytes_ + |
- frame_delay * params_.GetBytesPerFrame(), |
- current_lost_frames_); |
+ source_->OnMoreData(target_playout_time, current_lost_frames_, dest); |
dest->Scale(volume_); |
current_lost_frames_ = 0; |
} |
@@ -334,29 +340,6 @@ double AUHALStream::GetHardwareLatency() { |
output_format_.mSampleRate) + device_latency_frames); |
} |
-double AUHALStream::GetPlayoutLatency( |
- const AudioTimeStamp* output_time_stamp) { |
- // Ensure mHostTime is valid. |
- if ((output_time_stamp->mFlags & kAudioTimeStampHostTimeValid) == 0) |
chcunningham
2016/07/29 01:21:09
This method had checks for validity of host time..
jameswest
2016/08/26 02:08:47
Done.
|
- return 0; |
- |
- // Get the delay between the moment getting the callback and the scheduled |
- // time stamp that tells when the data is going to be played out. |
- UInt64 output_time_ns = AudioConvertHostTimeToNanos( |
- output_time_stamp->mHostTime); |
- UInt64 now_ns = AudioConvertHostTimeToNanos(AudioGetCurrentHostTime()); |
- |
- // Prevent overflow leading to huge delay information; occurs regularly on |
- // the bots, probably less so in the wild. |
- if (now_ns > output_time_ns) |
chcunningham
2016/07/29 01:21:09
I think you need to still account for this
jameswest
2016/08/26 02:08:47
Done.
|
- return 0; |
- |
- double delay_frames = static_cast<double> |
- (1e-9 * (output_time_ns - now_ns) * output_format_.mSampleRate); |
- |
- return (delay_frames + hardware_latency_frames_); |
-} |
- |
void AUHALStream::UpdatePlayoutTimestamp(const AudioTimeStamp* timestamp) { |
if ((timestamp->mFlags & kAudioTimeStampSampleTimeValid) == 0) |
return; |