Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(84)

Side by Side Diff: media/filters/audio_clock.h

Issue 1716753002: Revert of Use double microseconds for tracking back/front timestamp in AudioClock. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | media/filters/audio_clock.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <stdint.h> 8 #include <stdint.h>
9 9
10 #include <cmath>
11 #include <deque> 10 #include <deque>
12 11
13 #include "base/macros.h" 12 #include "base/macros.h"
14 #include "base/time/time.h" 13 #include "base/time/time.h"
15 #include "media/base/media_export.h" 14 #include "media/base/media_export.h"
16 15
17 namespace media { 16 namespace media {
18 17
19 // Models a queue of buffered audio in a playback pipeline for use with 18 // Models a queue of buffered audio in a playback pipeline for use with
20 // estimating the amount of delay in wall clock time. Takes changes in playback 19 // estimating the amount of delay in wall clock time. Takes changes in playback
(...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after
83 // +-----------------------+-----------------------+-----------------------+ 82 // +-----------------------+-----------------------+-----------------------+
84 // | 10 frames silence | 20 frames @ 1.0x | 20 frames @ 0.5x | 83 // | 10 frames silence | 20 frames @ 1.0x | 20 frames @ 0.5x |
85 // | = 250 ms (wall) | = 500 ms (wall) | = 500 ms (wall) | 84 // | = 250 ms (wall) | = 500 ms (wall) | = 500 ms (wall) |
86 // | = 0 ms (media) | = 500 ms (media) | = 250 ms (media) | 85 // | = 0 ms (media) | = 500 ms (media) | = 250 ms (media) |
87 // +-----------------------+-----------------------+-----------------------+ 86 // +-----------------------+-----------------------+-----------------------+
88 // ^ ^ 87 // ^ ^
89 // front_timestamp() is equal to back_timestamp() is equal to 88 // front_timestamp() is equal to back_timestamp() is equal to
90 // |start_timestamp| since no amount of media frames tracked 89 // |start_timestamp| since no amount of media frames tracked
91 // media data has been played yet. by AudioClock, which would be 90 // media data has been played yet. by AudioClock, which would be
92 // 1000 + 500 + 250 = 1750 ms. 91 // 1000 + 500 + 250 = 1750 ms.
93 base::TimeDelta front_timestamp() const { 92 base::TimeDelta front_timestamp() const { return front_timestamp_; }
94 return base::TimeDelta::FromMicroseconds( 93 base::TimeDelta back_timestamp() const { return back_timestamp_; }
95 std::round(front_timestamp_micros_));
96 }
97 base::TimeDelta back_timestamp() const {
98 return base::TimeDelta::FromMicroseconds(
99 std::round(back_timestamp_micros_));
100 }
101 94
102 // Returns the amount of wall time until |timestamp| will be played by the 95 // Returns the amount of wall time until |timestamp| will be played by the
103 // audio hardware. 96 // audio hardware.
104 // 97 //
105 // |timestamp| must be within front_timestamp() and back_timestamp(). 98 // |timestamp| must be within front_timestamp() and back_timestamp().
106 base::TimeDelta TimeUntilPlayback(base::TimeDelta timestamp) const; 99 base::TimeDelta TimeUntilPlayback(base::TimeDelta timestamp) const;
107 100
108 void ContiguousAudioDataBufferedForTesting( 101 void ContiguousAudioDataBufferedForTesting(
109 base::TimeDelta* total, 102 base::TimeDelta* total,
110 base::TimeDelta* same_rate_total) const; 103 base::TimeDelta* same_rate_total) const;
111 104
112 private: 105 private:
113 // Even with a ridiculously high sample rate of 256kHz, using 64 bits will 106 // Even with a ridiculously high sample rate of 256kHz, using 64 bits will
114 // permit tracking up to 416999965 days worth of time (that's 1141 millenia). 107 // permit tracking up to 416999965 days worth of time (that's 1141 millenia).
115 // 108 //
116 // 32 bits on the other hand would top out at measly 2 hours and 20 minutes. 109 // 32 bits on the other hand would top out at measly 2 hours and 20 minutes.
117 struct AudioData { 110 struct AudioData {
118 AudioData(int64_t frames, double playback_rate); 111 AudioData(int64_t frames, double playback_rate);
119 112
120 int64_t frames; 113 int64_t frames;
121 double playback_rate; 114 double playback_rate;
122 }; 115 };
123 116
124 // Helpers for operating on |buffered_|. 117 // Helpers for operating on |buffered_|.
125 void PushBufferedAudioData(int64_t frames, double playback_rate); 118 void PushBufferedAudioData(int64_t frames, double playback_rate);
126 void PopBufferedAudioData(int64_t frames); 119 void PopBufferedAudioData(int64_t frames);
127 double ComputeBufferedMediaDurationMicros() const; 120 base::TimeDelta ComputeBufferedMediaDuration() const;
128 121
129 const base::TimeDelta start_timestamp_; 122 const base::TimeDelta start_timestamp_;
130 const double microseconds_per_frame_; 123 const double microseconds_per_frame_;
131 124
132 std::deque<AudioData> buffered_; 125 std::deque<AudioData> buffered_;
133 int64_t total_buffered_frames_; 126 int64_t total_buffered_frames_;
134 127
135 // Use double rather than TimeDelta to avoid loss of partial microseconds when 128 base::TimeDelta front_timestamp_;
136 // converting between frames-written/delayed and time-passed (see conversion 129 base::TimeDelta back_timestamp_;
137 // in WroteAudio()). Particularly for |back_timestamp|, which accumulates more
138 // time with each call to WroteAudio(), the loss of precision can accumulate
139 // to create noticeable audio/video sync drift for longer (2-3 hr) videos.
140 // See http://crbug.com/564604.
141 double front_timestamp_micros_;
142 double back_timestamp_micros_;
143 130
144 DISALLOW_COPY_AND_ASSIGN(AudioClock); 131 DISALLOW_COPY_AND_ASSIGN(AudioClock);
145 }; 132 };
146 133
147 } // namespace media 134 } // namespace media
148 135
149 #endif // MEDIA_FILTERS_AUDIO_CLOCK_H_ 136 #endif // MEDIA_FILTERS_AUDIO_CLOCK_H_
OLDNEW
« no previous file with comments | « no previous file | media/filters/audio_clock.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698