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 24 matching lines...) Expand all Loading... | |
35 | 35 |
36 // First write: initialize buffer with silence. | 36 // First write: initialize buffer with silence. |
37 if (start_timestamp_ == front_timestamp_ && buffered_.empty()) | 37 if (start_timestamp_ == front_timestamp_ && buffered_.empty()) |
38 PushBufferedAudioData(delay_frames, 0.0); | 38 PushBufferedAudioData(delay_frames, 0.0); |
39 | 39 |
40 // Move frames from |buffered_| into the computed timestamp based on | 40 // Move frames from |buffered_| into the computed timestamp based on |
41 // |delay_frames|. | 41 // |delay_frames|. |
42 // | 42 // |
43 // The ordering of compute -> push -> pop eliminates unnecessary memory | 43 // The ordering of compute -> push -> pop eliminates unnecessary memory |
44 // reallocations in cases where |buffered_| gets emptied. | 44 // reallocations in cases where |buffered_| gets emptied. |
45 const int64_t original_buffered_frames = total_buffered_frames_; | |
jrummell
2015/07/10 00:32:57
Since this is only used in the DCHECK, will a rele
DaleCurtis
2015/07/10 00:34:22
Nope, the DCHECK still counts as usage.
| |
45 int64_t frames_played = | 46 int64_t frames_played = |
46 std::max(INT64_C(0), total_buffered_frames_ - delay_frames); | 47 std::max(INT64_C(0), total_buffered_frames_ - delay_frames); |
47 front_timestamp_ += ComputeBufferedMediaTime(frames_played); | 48 front_timestamp_ += ComputeBufferedMediaTime(frames_played); |
48 PushBufferedAudioData(frames_written, playback_rate); | 49 PushBufferedAudioData(frames_written, playback_rate); |
49 PushBufferedAudioData(frames_requested - frames_written, 0.0); | 50 PushBufferedAudioData(frames_requested - frames_written, 0.0); |
50 PopBufferedAudioData(frames_played); | 51 PopBufferedAudioData(frames_played); |
51 | 52 |
52 back_timestamp_ += base::TimeDelta::FromMicroseconds( | 53 back_timestamp_ += base::TimeDelta::FromMicroseconds( |
53 frames_written * playback_rate * microseconds_per_frame_); | 54 frames_written * playback_rate * microseconds_per_frame_); |
54 | 55 |
56 // Ensure something crazy hasn't happened to desync the front and back values. | |
57 DCHECK_LE(front_timestamp_.InMicroseconds(), back_timestamp_.InMicroseconds()) | |
58 << "frames_written=" << frames_written | |
59 << ", frames_requested=" << frames_requested | |
60 << ", delay_frames=" << delay_frames | |
61 << ", playback_rate=" << playback_rate | |
62 << ", frames_played=" << frames_played | |
63 << ", original_buffered_frames=" << original_buffered_frames | |
64 << ", total_buffered_frames_=" << total_buffered_frames_; | |
65 | |
55 // Update cached values. | 66 // Update cached values. |
56 double scaled_frames = 0; | 67 double scaled_frames = 0; |
57 double scaled_frames_at_same_rate = 0; | 68 double scaled_frames_at_same_rate = 0; |
58 bool found_silence = false; | 69 bool found_silence = false; |
59 for (size_t i = 0; i < buffered_.size(); ++i) { | 70 for (size_t i = 0; i < buffered_.size(); ++i) { |
60 if (buffered_[i].playback_rate == 0) { | 71 if (buffered_[i].playback_rate == 0) { |
61 found_silence = true; | 72 found_silence = true; |
62 continue; | 73 continue; |
63 } | 74 } |
64 | 75 |
(...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
175 int64_t min_frames = std::min(buffered_[i].frames, frames); | 186 int64_t min_frames = std::min(buffered_[i].frames, frames); |
176 scaled_frames += min_frames * buffered_[i].playback_rate; | 187 scaled_frames += min_frames * buffered_[i].playback_rate; |
177 frames -= min_frames; | 188 frames -= min_frames; |
178 } | 189 } |
179 | 190 |
180 return base::TimeDelta::FromMicroseconds(scaled_frames * | 191 return base::TimeDelta::FromMicroseconds(scaled_frames * |
181 microseconds_per_frame_); | 192 microseconds_per_frame_); |
182 } | 193 } |
183 | 194 |
184 } // namespace media | 195 } // namespace media |
OLD | NEW |