Chromium Code Reviews| 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..bc1cff8d2dcc044dbc93df36b384b3330c2b0f58 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,7 @@ 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()); |
| + current_target_playout_time_ = GetTargetPlayoutTime(output_time_stamp); |
| if (audio_fifo_) |
| audio_fifo_->Consume(output_bus_.get(), output_bus_->frames()); |
| @@ -258,10 +256,13 @@ void AUHALStream::ProvideInput(int frame_delay, AudioBus* dest) { |
| return; |
| } |
| + const base::TimeDelta delay = base::TimeDelta::FromMicroseconds( |
| + frame_delay * base::Time::kMicrosecondsPerSecond / 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,7 +335,7 @@ double AUHALStream::GetHardwareLatency() { |
| output_format_.mSampleRate) + device_latency_frames); |
| } |
| -double AUHALStream::GetPlayoutLatency( |
| +base::TimeTicks AUHALStream::GetTargetPlayoutTime( |
| const AudioTimeStamp* output_time_stamp) { |
| // Ensure mHostTime is valid. |
| if ((output_time_stamp->mFlags & kAudioTimeStampHostTimeValid) == 0) |
| @@ -351,10 +352,9 @@ double AUHALStream::GetPlayoutLatency( |
| if (now_ns > output_time_ns) |
| return 0; |
| - double delay_frames = static_cast<double> |
| - (1e-9 * (output_time_ns - now_ns) * output_format_.mSampleRate); |
| - |
| - return (delay_frames + hardware_latency_frames_); |
| + // TODO(jameswest): Find an alternative to FromInternalValue. |
| + return base::TimeTicks::FromInternalValue( |
|
miu
2016/08/31 23:26:54
I'd suggest adding a TimeTicks::FromMachAbsoluteTi
James West
2016/09/13 07:40:50
Done.
|
| + output_time_ns / base::Time::kNanosecondsPerMicrosecond); |
| } |
| void AUHALStream::UpdatePlayoutTimestamp(const AudioTimeStamp* timestamp) { |