| 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 #ifndef MEDIA_FILTERS_AUDIO_CLOCK_H_ | 5 #ifndef MEDIA_FILTERS_AUDIO_CLOCK_H_ |
| 6 #define MEDIA_FILTERS_AUDIO_CLOCK_H_ | 6 #define MEDIA_FILTERS_AUDIO_CLOCK_H_ |
| 7 | 7 |
| 8 #include <deque> | 8 #include <deque> |
| 9 | 9 |
| 10 #include "base/time/time.h" | 10 #include "base/time/time.h" |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 88 // 1000 + 500 + 250 = 1750 ms. | 88 // 1000 + 500 + 250 = 1750 ms. |
| 89 base::TimeDelta front_timestamp() const { return front_timestamp_; } | 89 base::TimeDelta front_timestamp() const { return front_timestamp_; } |
| 90 base::TimeDelta back_timestamp() const { return back_timestamp_; } | 90 base::TimeDelta back_timestamp() const { return back_timestamp_; } |
| 91 | 91 |
| 92 // Returns the amount of wall time until |timestamp| will be played by the | 92 // Returns the amount of wall time until |timestamp| will be played by the |
| 93 // audio hardware. | 93 // audio hardware. |
| 94 // | 94 // |
| 95 // |timestamp| must be within front_timestamp() and back_timestamp(). | 95 // |timestamp| must be within front_timestamp() and back_timestamp(). |
| 96 base::TimeDelta TimeUntilPlayback(base::TimeDelta timestamp) const; | 96 base::TimeDelta TimeUntilPlayback(base::TimeDelta timestamp) const; |
| 97 | 97 |
| 98 // Returns the amount of contiguous media time buffered at the head of the | 98 void ContiguousAudioDataBufferedForTesting( |
| 99 // audio hardware buffer. Silence introduced into the audio hardware buffer is | 99 base::TimeDelta* total, |
| 100 // treated as a break in media time. | 100 base::TimeDelta* same_rate_total) const; |
| 101 base::TimeDelta contiguous_audio_data_buffered() const { | |
| 102 return contiguous_audio_data_buffered_; | |
| 103 } | |
| 104 | |
| 105 // Same as above, but also treats changes in playback rate as a break in media | |
| 106 // time. | |
| 107 base::TimeDelta contiguous_audio_data_buffered_at_same_rate() const { | |
| 108 return contiguous_audio_data_buffered_at_same_rate_; | |
| 109 } | |
| 110 | 101 |
| 111 private: | 102 private: |
| 112 // Even with a ridiculously high sample rate of 256kHz, using 64 bits will | 103 // Even with a ridiculously high sample rate of 256kHz, using 64 bits will |
| 113 // permit tracking up to 416999965 days worth of time (that's 1141 millenia). | 104 // permit tracking up to 416999965 days worth of time (that's 1141 millenia). |
| 114 // | 105 // |
| 115 // 32 bits on the other hand would top out at measly 2 hours and 20 minutes. | 106 // 32 bits on the other hand would top out at measly 2 hours and 20 minutes. |
| 116 struct AudioData { | 107 struct AudioData { |
| 117 AudioData(int64_t frames, double playback_rate); | 108 AudioData(int64_t frames, double playback_rate); |
| 118 | 109 |
| 119 int64_t frames; | 110 int64_t frames; |
| 120 double playback_rate; | 111 double playback_rate; |
| 121 }; | 112 }; |
| 122 | 113 |
| 123 // Helpers for operating on |buffered_|. | 114 // Helpers for operating on |buffered_|. |
| 124 void PushBufferedAudioData(int64_t frames, double playback_rate); | 115 void PushBufferedAudioData(int64_t frames, double playback_rate); |
| 125 void PopBufferedAudioData(int64_t frames); | 116 void PopBufferedAudioData(int64_t frames); |
| 126 base::TimeDelta ComputeBufferedMediaTime(int64_t frames) const; | 117 base::TimeDelta ComputeBufferedMediaDuration() const; |
| 127 | 118 |
| 128 const base::TimeDelta start_timestamp_; | 119 const base::TimeDelta start_timestamp_; |
| 129 const double microseconds_per_frame_; | 120 const double microseconds_per_frame_; |
| 130 | 121 |
| 131 std::deque<AudioData> buffered_; | 122 std::deque<AudioData> buffered_; |
| 132 int64_t total_buffered_frames_; | 123 int64_t total_buffered_frames_; |
| 133 | 124 |
| 134 base::TimeDelta front_timestamp_; | 125 base::TimeDelta front_timestamp_; |
| 135 base::TimeDelta back_timestamp_; | 126 base::TimeDelta back_timestamp_; |
| 136 | 127 |
| 137 // Cached results of last call to WroteAudio(). | |
| 138 base::TimeDelta contiguous_audio_data_buffered_; | |
| 139 base::TimeDelta contiguous_audio_data_buffered_at_same_rate_; | |
| 140 | |
| 141 DISALLOW_COPY_AND_ASSIGN(AudioClock); | 128 DISALLOW_COPY_AND_ASSIGN(AudioClock); |
| 142 }; | 129 }; |
| 143 | 130 |
| 144 } // namespace media | 131 } // namespace media |
| 145 | 132 |
| 146 #endif // MEDIA_FILTERS_AUDIO_CLOCK_H_ | 133 #endif // MEDIA_FILTERS_AUDIO_CLOCK_H_ |
| OLD | NEW |