Chromium Code Reviews| Index: media/filters/audio_clock.h |
| diff --git a/media/filters/audio_clock.h b/media/filters/audio_clock.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..d788082f6a675737a5eb9f34cba69ceda87afafb |
| --- /dev/null |
| +++ b/media/filters/audio_clock.h |
| @@ -0,0 +1,74 @@ |
| +// Copyright 2014 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef MEDIA_FILTERS_AUDIO_CLOCK_H_ |
| +#define MEDIA_FILTERS_AUDIO_CLOCK_H_ |
| + |
| +#include <deque> |
| + |
| +#include "base/time/time.h" |
| +#include "media/base/media_export.h" |
| + |
| +namespace media { |
| + |
| +// Models a queue of buffered audio in a playback pipeline for use with |
| +// estimating the amount of delay in wall clock time. Takes changes in playback |
| +// rate into account to handle scenarios where multiple rates may be present in |
| +// a playback pipeline with large delay. |
| +class MEDIA_EXPORT AudioClock { |
| + public: |
| + explicit AudioClock(int sample_rate); |
| + ~AudioClock(); |
| + |
| + // |frames| amount of audio data scaled to |playback_rate| was written. |
| + // |delay_frames| is the current amount of hardware delay. |
| + // |timestamp| is the endpoint media timestamp of the audio data written. |
| + void WroteAudio(int frames, |
| + int delay_frames, |
| + float playback_rate, |
| + base::TimeDelta timestamp); |
| + |
| + // |frames| amount of silence was written. |
| + // |delay_frames| is the current amount of hardware delay. |
| + void WroteSilence(int frames, int delay_frames); |
|
scherkus (not reviewing)
2014/04/30 19:13:58
went with two separate APIs as it started to look
|
| + |
| + // Calculates the current media timestamp taking silence and changes in |
| + // playback rate into account. |
| + base::TimeDelta CurrentMediaTimestamp() const; |
| + |
| + // Returns the last endpoint timestamp provided to WroteAudio(). |
| + base::TimeDelta LastEndpointTimestamp() const; |
| + |
| + private: |
| + void TrimBufferedAudioToMatchDelay(int delay_frames); |
| + void PushBufferedAudio(int frames, |
| + float playback_rate, |
| + base::TimeDelta endpoint_timestamp); |
| + |
| + int sample_rate_; |
|
DaleCurtis
2014/04/30 20:36:33
const
scherkus (not reviewing)
2014/05/02 19:26:05
Done.
|
| + |
| + // Initially set to kNoTimestamp(), otherwise is the last endpoint timestamp |
| + // delivered to WroteAudio(). A copy is kept outside of |buffered_audio_| to |
| + // handle the case where all of |buffered_audio_| has been replaced with |
| + // silence. |
| + base::TimeDelta last_endpoint_timestamp_; |
| + |
| + struct BufferedAudio { |
| + BufferedAudio(int frames, |
| + float playback_rate, |
| + base::TimeDelta endpoint_timestamp); |
| + |
| + int frames; |
| + float playback_rate; |
|
DaleCurtis
2014/04/30 20:36:33
Looks like this could be const?
scherkus (not reviewing)
2014/05/02 19:26:05
adding const interferes with the implicit copy ope
|
| + base::TimeDelta endpoint_timestamp; |
| + }; |
| + |
| + std::deque<BufferedAudio> buffered_audio_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(AudioClock); |
| +}; |
| + |
| +} // namespace media |
| + |
| +#endif // MEDIA_FILTERS_AUDIO_CLOCK_H_ |