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

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

Issue 518613002: Have AudioRendererImpl advance time until it's told to stop. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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') | media/filters/audio_renderer_impl.cc » ('J')
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 <deque> 8 #include <deque>
9 9
10 #include "base/time/time.h" 10 #include "base/time/time.h"
(...skipping 11 matching lines...) Expand all
22 ~AudioClock(); 22 ~AudioClock();
23 23
24 // |frames_written| amount of audio data scaled to |playback_rate| written. 24 // |frames_written| amount of audio data scaled to |playback_rate| written.
25 // |frames_requested| amount of audio data requested by hardware. 25 // |frames_requested| amount of audio data requested by hardware.
26 // |delay_frames| is the current amount of hardware delay. 26 // |delay_frames| is the current amount of hardware delay.
27 void WroteAudio(int frames_written, 27 void WroteAudio(int frames_written,
28 int frames_requested, 28 int frames_requested,
29 int delay_frames, 29 int delay_frames,
30 float playback_rate); 30 float playback_rate);
31 31
32 // Calculates the current media timestamp taking silence and changes in 32 // Returns the current media timestamp taking silence and changes in
33 // playback rate into account. 33 // playback rate into account.
34 base::TimeDelta current_media_timestamp() const { 34 base::TimeDelta current_media_timestamp() const {
35 return current_media_timestamp_; 35 return current_media_timestamp_;
36 } 36 }
37 37
38 // Returns the latest media timestamp taking silence and changes in
DaleCurtis 2014/08/29 20:17:23 The difference between current and latest isn't re
39 // playback rate into account.
xhwang 2014/08/29 20:45:48 Only by looking at the comments, I have no idea wh
scherkus (not reviewing) 2014/08/30 00:24:12 Ah I guess I used "latest" in the sense of "furthe
40 base::TimeDelta latest_media_timestamp() const {
41 return latest_media_timestamp_;
42 }
43
38 // Clients can provide |time_since_writing| to simulate the passage of time 44 // Clients can provide |time_since_writing| to simulate the passage of time
39 // since last writing audio to get a more accurate current media timestamp. 45 // since last writing audio to get a more accurate current media timestamp.
40 base::TimeDelta CurrentMediaTimestampSinceWriting( 46 base::TimeDelta CurrentMediaTimestampSinceWriting(
41 base::TimeDelta time_since_writing) const; 47 base::TimeDelta time_since_writing) const;
42 48
43 // Returns the amount of contiguous media time buffered at the head of the 49 // Returns the amount of contiguous media time buffered at the head of the
44 // audio hardware buffer. Silence introduced into the audio hardware buffer is 50 // audio hardware buffer. Silence introduced into the audio hardware buffer is
45 // treated as a break in media time. 51 // treated as a break in media time.
46 base::TimeDelta contiguous_audio_data_buffered() const { 52 base::TimeDelta contiguous_audio_data_buffered() const {
47 return contiguous_audio_data_buffered_; 53 return contiguous_audio_data_buffered_;
48 } 54 }
49 55
50 // Same as above, but also treats changes in playback rate as a break in media 56 // Same as above, but also treats changes in playback rate as a break in media
51 // time. 57 // time.
52 base::TimeDelta contiguous_audio_data_buffered_at_same_rate() const { 58 base::TimeDelta contiguous_audio_data_buffered_at_same_rate() const {
53 return contiguous_audio_data_buffered_at_same_rate_; 59 return contiguous_audio_data_buffered_at_same_rate_;
54 } 60 }
55 61
56 // Returns true if there is any audio data buffered by the audio hardware,
57 // even if there is silence mixed in.
58 bool audio_data_buffered() const { return audio_data_buffered_; }
59
60 private: 62 private:
61 // Even with a ridiculously high sample rate of 256kHz, using 64 bits will 63 // Even with a ridiculously high sample rate of 256kHz, using 64 bits will
62 // permit tracking up to 416999965 days worth of time (that's 1141 millenia). 64 // permit tracking up to 416999965 days worth of time (that's 1141 millenia).
63 // 65 //
64 // 32 bits on the other hand would top out at measly 2 hours and 20 minutes. 66 // 32 bits on the other hand would top out at measly 2 hours and 20 minutes.
65 struct AudioData { 67 struct AudioData {
66 AudioData(int64_t frames, float playback_rate); 68 AudioData(int64_t frames, float playback_rate);
67 69
68 int64_t frames; 70 int64_t frames;
69 float playback_rate; 71 float playback_rate;
70 }; 72 };
71 73
72 // Helpers for operating on |buffered_|. 74 // Helpers for operating on |buffered_|.
73 void PushBufferedAudioData(int64_t frames, float playback_rate); 75 void PushBufferedAudioData(int64_t frames, float playback_rate);
74 void PopBufferedAudioData(int64_t frames); 76 void PopBufferedAudioData(int64_t frames);
75 base::TimeDelta ComputeBufferedMediaTime(int64_t frames) const; 77 base::TimeDelta ComputeBufferedMediaTime(int64_t frames) const;
76 78
77 const base::TimeDelta start_timestamp_; 79 const base::TimeDelta start_timestamp_;
78 const int sample_rate_; 80 const int sample_rate_;
79 const double microseconds_per_frame_; 81 const double microseconds_per_frame_;
80 82
81 std::deque<AudioData> buffered_; 83 std::deque<AudioData> buffered_;
82 int64_t total_buffered_frames_; 84 int64_t total_buffered_frames_;
83 85
84 base::TimeDelta current_media_timestamp_; 86 base::TimeDelta current_media_timestamp_;
87 base::TimeDelta latest_media_timestamp_;
85 88
86 // Cached results of last call to WroteAudio(). 89 // Cached results of last call to WroteAudio().
87 bool audio_data_buffered_;
88 base::TimeDelta contiguous_audio_data_buffered_; 90 base::TimeDelta contiguous_audio_data_buffered_;
89 base::TimeDelta contiguous_audio_data_buffered_at_same_rate_; 91 base::TimeDelta contiguous_audio_data_buffered_at_same_rate_;
90 92
91 DISALLOW_COPY_AND_ASSIGN(AudioClock); 93 DISALLOW_COPY_AND_ASSIGN(AudioClock);
92 }; 94 };
93 95
94 } // namespace media 96 } // namespace media
95 97
96 #endif // MEDIA_FILTERS_AUDIO_CLOCK_H_ 98 #endif // MEDIA_FILTERS_AUDIO_CLOCK_H_
OLDNEW
« no previous file with comments | « no previous file | media/filters/audio_clock.cc » ('j') | media/filters/audio_renderer_impl.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698