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

Side by Side 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: Fix unittest compile breakage caused by recent method rename. 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 unified diff | Download patch
« no previous file with comments | « media/base/BUILD.gn ('k') | media/base/audio_push_fifo.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 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.
4
5 #ifndef MEDIA_BASE_AUDIO_PUSH_FIFO_H_
6 #define MEDIA_BASE_AUDIO_PUSH_FIFO_H_
7
8 #include "base/callback.h"
9 #include "base/macros.h"
10 #include "base/memory/scoped_ptr.h"
11 #include "media/base/audio_bus.h"
12 #include "media/base/media_export.h"
13
14 namespace media {
15
16 // Yet another FIFO for audio data that re-buffers audio to a desired buffer
17 // size. Unlike AudioFifo and AudioBlockFifo, this FIFO cannot overflow: The
18 // client is required to provide a callback that is called synchronously during
19 // a push whenever enough data becomes available. This implementation
20 // eliminates redundant memory copies when the input buffer size always matches
21 // the desired buffer size.
22 class MEDIA_EXPORT AudioPushFifo final {
23 public:
24 // Called synchronously zero, one, or multiple times during a call to Push()
25 // to deliver re-buffered audio. |frame_delay| refers to the position of the
26 // first frame in |output| relative to the first frame in the Push() call. If
27 // negative, this indicates the output contains some data from a prior call to
28 // Push(). If zero or positive, the output contains data from the current
29 // call to Push(). Clients can use this to adjust timestamps.
30 using OutputCallback =
31 base::Callback<void(const AudioBus& output_bus, int frame_delay)>;
32
33 // Creates a new AudioPushFifo which delivers re-buffered audio by running
34 // |callback|.
35 explicit AudioPushFifo(const OutputCallback& callback);
36
37 ~AudioPushFifo();
38
39 // Returns the number of frames in each AudioBus delivered to the
40 // OutputCallback.
41 int frames_per_buffer() const { return frames_per_buffer_; }
42
43 // Must be called at least once before the first call to Push(). May be
44 // called later (e.g., to support an audio format change).
45 void Reset(int frames_per_buffer);
46
47 // Pushes all audio channel data from |input_bus| through the FIFO. This will
48 // result in zero, one, or multiple synchronous calls to the OutputCallback
49 // provided in the constructor. If the |input_bus| has a different number of
50 // channels than the prior Push() call, any currently-queued frames will be
51 // dropped.
52 void Push(const AudioBus& input_bus);
53
54 // Flushes any enqueued frames by invoking the OutputCallback with those
55 // frames plus padded zero samples. If there are no frames currently
56 // enqueued, OutputCallback is not run.
57 void Flush();
58
59 private:
60 const OutputCallback callback_;
61
62 int frames_per_buffer_;
63
64 // Queue of frames pending for delivery.
65 scoped_ptr<AudioBus> audio_queue_;
66 int queued_frames_;
67
68 DISALLOW_COPY_AND_ASSIGN(AudioPushFifo);
69 };
70
71 } // namespace media
72
73 #endif // MEDIA_BASE_AUDIO_PUSH_FIFO_H_
OLDNEW
« no previous file with comments | « media/base/BUILD.gn ('k') | media/base/audio_push_fifo.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698