Chromium Code Reviews| Index: media/base/audio_push_fifo.h |
| diff --git a/media/base/audio_push_fifo.h b/media/base/audio_push_fifo.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..4db5a8e5c6074ed4127261c27f24a6b5b2954ca6 |
| --- /dev/null |
| +++ b/media/base/audio_push_fifo.h |
| @@ -0,0 +1,73 @@ |
| +// Copyright 2016 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_BASE_AUDIO_PUSH_FIFO_H_ |
| +#define MEDIA_BASE_AUDIO_PUSH_FIFO_H_ |
| + |
| +#include "base/callback.h" |
| +#include "base/macros.h" |
| +#include "base/memory/scoped_ptr.h" |
| +#include "media/base/audio_bus.h" |
| +#include "media/base/media_export.h" |
| + |
| +namespace media { |
| + |
| +// Yet another FIFO for audio data that re-buffers audio to a desired buffer |
| +// size. Unlike AudioFifo and AudioBlockFifo, this FIFO cannot overflow: The |
| +// client is required to provide a callback that is called synchronously during |
| +// a push whenever enough data becomes available. This implementation |
| +// eliminates redundant memory copies when the input buffer size always matches |
| +// the desired buffer size. |
| +class MEDIA_EXPORT AudioPushFifo final { |
| + public: |
| + // Called synchronously zero, one, or multiple times during a call to Push() |
| + // to deliver re-buffered audio. |frame_delay| refers to the position of the |
| + // first frame in |output| relative to the first frame in the Push() call. If |
| + // negative, this indicates the output contains some data from a prior call to |
| + // Push(). If zero or positive, the output contains data from the current |
| + // call to Push(). Clients can use this to adjust timestamps. |
| + using OutputCallback = |
| + base::Callback<void(const AudioBus& output_bus, int frame_delay)>; |
| + |
| + // Creates a new AudioPushFifo delivers re-buffered audio by running |
|
Irfan
2016/02/24 19:04:30
AudioPushFifo which delivers ?
miu
2016/02/24 22:16:42
Done.
|
| + // |callback|. |
| + explicit AudioPushFifo(const OutputCallback& callback); |
| + |
| + ~AudioPushFifo(); |
| + |
| + // Returns the number of frames in each AudioBus delivered to the |
| + // OutputCallback. |
| + int output_frames() const { return output_frames_; } |
| + |
| + // Must be called at least once before the first call to Push(). May be |
| + // called later (e.g., to support an audio format change). |
| + void Reset(int frames_per_buffer); |
|
o1ka
2016/02/24 09:23:30
match parameter name with |output_frames_| member
miu
2016/02/24 22:16:42
Done.
|
| + |
| + // Pushes all audio channel data from |input_bus| through the FIFO. This will |
| + // result in zero, one, or multiple synchronous calls to the OutputCallback |
| + // provided in the constructor. If the |input_bus| has a different number of |
| + // channels than the prior Push() call, any currently-queued frames will be |
| + // dropped. |
| + void Push(const AudioBus& input_bus); |
| + |
| + // Flushes any enqueued frames by invoking the OutputCallback with those |
| + // frames plus padded zero samples. If there are no frames currently |
| + // enqueued, OutputCallback is not run. |
| + void Flush(); |
| + |
| + private: |
| + const OutputCallback callback_; |
| + |
| + int output_frames_; |
|
o1ka
2016/02/24 09:23:30
frames_per_buffer_ seems to be a more common name
miu
2016/02/24 22:16:42
Done.
|
| + |
| + // Queue of frames pending for delivery. |
| + scoped_ptr<AudioBus> audio_queue_; |
| + int queued_frames_; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(AudioPushFifo); |
| +}; |
| + |
| +} // namespace media |
| + |
| +#endif // MEDIA_BASE_AUDIO_PUSH_FIFO_H_ |