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

Unified Diff: media/base/audio_push_fifo.h

Issue 1714593003: Introduce media::AudioPushFifo and a couple of use cases (and clean-ups). (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Addressed all review comments. Now called AudioPushFifo. REBASED 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 side-by-side diff with in-line comments
Download patch
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..4f95b13da1590560f20ea047a8ee2f018daed5e9
--- /dev/null
+++ b/media/base/audio_push_fifo.h
@@ -0,0 +1,68 @@
+// 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. In addition, this FIFO
+// shifts reference timestamps to account for any samples that were pending in
DaleCurtis 2016/02/23 20:34:26 Remove comments on reference timestamps?
miu 2016/02/23 23:32:33 Done.
+// internal buffers from prior pushes. 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_offset| 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 timestmaps.
DaleCurtis 2016/02/23 20:34:26 timestamps.
miu 2016/02/23 23:32:33 Done.
+ using OutputCallback =
+ base::Callback<void(const AudioBus& output_bus, int frame_offset)>;
DaleCurtis 2016/02/23 20:34:26 We typically call this frame_delay (see SincResamp
miu 2016/02/23 23:32:33 Done.
+
+ // Creates a new AudioPushFifo delivers re-buffered audio by running
+ // |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);
+
+ // 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.
+ void Push(const AudioBus& input_bus);
+
+ private:
+ const OutputCallback callback_;
+
+ int output_frames_;
+
+ // 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_

Powered by Google App Engine
This is Rietveld 408576698