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 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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::TimeUntilPlayback(base::TimeDelta timestamp) const { | 83 base::TimeDelta AudioClock::TimeUntilPlayback(base::TimeDelta timestamp) const { |
84 DCHECK(timestamp >= front_timestamp_); | 84 DCHECK_GE(timestamp, front_timestamp_); |
85 DCHECK(timestamp <= back_timestamp_); | 85 DCHECK_LE(timestamp, back_timestamp_); |
86 | 86 |
87 int64_t frames_until_timestamp = 0; | 87 int64_t frames_until_timestamp = 0; |
88 double timestamp_us = timestamp.InMicroseconds(); | 88 double timestamp_us = timestamp.InMicroseconds(); |
89 double media_time_us = front_timestamp_.InMicroseconds(); | 89 double media_time_us = front_timestamp_.InMicroseconds(); |
90 | 90 |
91 for (size_t i = 0; i < buffered_.size(); ++i) { | 91 for (size_t i = 0; i < buffered_.size(); ++i) { |
92 // Leading silence is always accounted prior to anything else. | 92 // Leading silence is always accounted prior to anything else. |
93 if (buffered_[i].playback_rate == 0) { | 93 if (buffered_[i].playback_rate == 0) { |
94 frames_until_timestamp += buffered_[i].frames; | 94 frames_until_timestamp += buffered_[i].frames; |
95 continue; | 95 continue; |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
159 int64_t min_frames = std::min(buffered_[i].frames, frames); | 159 int64_t min_frames = std::min(buffered_[i].frames, frames); |
160 scaled_frames += min_frames * buffered_[i].playback_rate; | 160 scaled_frames += min_frames * buffered_[i].playback_rate; |
161 frames -= min_frames; | 161 frames -= min_frames; |
162 } | 162 } |
163 | 163 |
164 return base::TimeDelta::FromMicroseconds(scaled_frames * | 164 return base::TimeDelta::FromMicroseconds(scaled_frames * |
165 microseconds_per_frame_); | 165 microseconds_per_frame_); |
166 } | 166 } |
167 | 167 |
168 } // namespace media | 168 } // namespace media |
OLD | NEW |