OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/filters/audio_clock.h" | 5 #include "media/filters/audio_clock.h" |
6 | 6 |
7 #include <algorithm> | 7 #include <algorithm> |
8 | 8 |
9 #include "base/logging.h" | 9 #include "base/logging.h" |
10 #include "media/base/buffers.h" | 10 #include "media/base/buffers.h" |
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
73 scaled_frames_at_same_rate = scaled_frames; | 73 scaled_frames_at_same_rate = scaled_frames; |
74 } | 74 } |
75 | 75 |
76 contiguous_audio_data_buffered_ = base::TimeDelta::FromMicroseconds( | 76 contiguous_audio_data_buffered_ = base::TimeDelta::FromMicroseconds( |
77 scaled_frames * microseconds_per_frame_); | 77 scaled_frames * microseconds_per_frame_); |
78 contiguous_audio_data_buffered_at_same_rate_ = | 78 contiguous_audio_data_buffered_at_same_rate_ = |
79 base::TimeDelta::FromMicroseconds(scaled_frames_at_same_rate * | 79 base::TimeDelta::FromMicroseconds(scaled_frames_at_same_rate * |
80 microseconds_per_frame_); | 80 microseconds_per_frame_); |
81 } | 81 } |
82 | 82 |
83 base::TimeDelta AudioClock::TimestampSinceWriting( | |
84 base::TimeDelta time_since_writing) const { | |
85 int64_t frames_played_since_writing = std::min( | |
86 total_buffered_frames_, | |
87 static_cast<int64_t>(time_since_writing.InSecondsF() * sample_rate_)); | |
88 return front_timestamp_ + | |
89 ComputeBufferedMediaTime(frames_played_since_writing); | |
90 } | |
91 | |
92 base::TimeDelta AudioClock::TimeUntilPlayback(base::TimeDelta timestamp) const { | 83 base::TimeDelta AudioClock::TimeUntilPlayback(base::TimeDelta timestamp) const { |
93 DCHECK(timestamp >= front_timestamp_); | 84 DCHECK(timestamp >= front_timestamp_); |
94 DCHECK(timestamp <= back_timestamp_); | 85 DCHECK(timestamp <= back_timestamp_); |
95 | 86 |
96 int64_t frames_until_timestamp = 0; | 87 int64_t frames_until_timestamp = 0; |
97 double timestamp_us = timestamp.InMicroseconds(); | 88 double timestamp_us = timestamp.InMicroseconds(); |
98 double media_time_us = front_timestamp_.InMicroseconds(); | 89 double media_time_us = front_timestamp_.InMicroseconds(); |
99 | 90 |
100 for (size_t i = 0; i < buffered_.size(); ++i) { | 91 for (size_t i = 0; i < buffered_.size(); ++i) { |
101 // Leading silence is always accounted prior to anything else. | 92 // Leading silence is always accounted prior to anything else. |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
168 int64_t min_frames = std::min(buffered_[i].frames, frames); | 159 int64_t min_frames = std::min(buffered_[i].frames, frames); |
169 scaled_frames += min_frames * buffered_[i].playback_rate; | 160 scaled_frames += min_frames * buffered_[i].playback_rate; |
170 frames -= min_frames; | 161 frames -= min_frames; |
171 } | 162 } |
172 | 163 |
173 return base::TimeDelta::FromMicroseconds(scaled_frames * | 164 return base::TimeDelta::FromMicroseconds(scaled_frames * |
174 microseconds_per_frame_); | 165 microseconds_per_frame_); |
175 } | 166 } |
176 | 167 |
177 } // namespace media | 168 } // namespace media |
OLD | NEW |