Support for unpacked ARM packed relocations.
[chromium-blink-merge.git] / media / filters / audio_clock.h
bloba0d8212f94869cd8f929d39831b64e86fb1418bc
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
3 // found in the LICENSE file.
5 #ifndef MEDIA_FILTERS_AUDIO_CLOCK_H_
6 #define MEDIA_FILTERS_AUDIO_CLOCK_H_
8 #include <deque>
10 #include "base/time/time.h"
11 #include "media/base/media_export.h"
13 namespace media {
15 // Models a queue of buffered audio in a playback pipeline for use with
16 // estimating the amount of delay in wall clock time. Takes changes in playback
17 // rate into account to handle scenarios where multiple rates may be present in
18 // a playback pipeline with large delay.
19 class MEDIA_EXPORT AudioClock {
20 public:
21 explicit AudioClock(int sample_rate);
22 ~AudioClock();
24 // |frames| amount of audio data scaled to |playback_rate| was written.
25 // |delay_frames| is the current amount of hardware delay.
26 // |timestamp| is the endpoint media timestamp of the audio data written.
27 void WroteAudio(int frames,
28 int delay_frames,
29 float playback_rate,
30 base::TimeDelta timestamp);
32 // |frames| amount of silence was written.
33 // |delay_frames| is the current amount of hardware delay.
34 void WroteSilence(int frames, int delay_frames);
36 // Calculates the current media timestamp taking silence and changes in
37 // playback rate into account.
38 base::TimeDelta CurrentMediaTimestamp() const;
40 // Returns the last endpoint timestamp provided to WroteAudio().
41 base::TimeDelta last_endpoint_timestamp() const {
42 return last_endpoint_timestamp_;
45 private:
46 void TrimBufferedAudioToMatchDelay(int delay_frames);
47 void PushBufferedAudio(int frames,
48 float playback_rate,
49 base::TimeDelta endpoint_timestamp);
51 const int sample_rate_;
53 // Initially set to kNoTimestamp(), otherwise is the last endpoint timestamp
54 // delivered to WroteAudio(). A copy is kept outside of |buffered_audio_| to
55 // handle the case where all of |buffered_audio_| has been replaced with
56 // silence.
57 base::TimeDelta last_endpoint_timestamp_;
59 struct BufferedAudio {
60 BufferedAudio(int frames,
61 float playback_rate,
62 base::TimeDelta endpoint_timestamp);
64 int frames;
65 float playback_rate;
66 base::TimeDelta endpoint_timestamp;
69 std::deque<BufferedAudio> buffered_audio_;
71 DISALLOW_COPY_AND_ASSIGN(AudioClock);
74 } // namespace media
76 #endif // MEDIA_FILTERS_AUDIO_CLOCK_H_