OLD | NEW |
---|---|
(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. In addition, this FIFO | |
20 // 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.
| |
21 // internal buffers from prior pushes. This implementation eliminates redundant | |
22 // memory copies when the input buffer size always matches the desired buffer | |
23 // size. | |
24 class MEDIA_EXPORT AudioPushFifo final { | |
25 public: | |
26 // Called synchronously zero, one, or multiple times during a call to Push() | |
27 // to deliver re-buffered audio. |frame_offset| refers to the position of the | |
28 // first frame in |output| relative to the first frame in the Push() call. If | |
29 // negative, this indicates the output contains some data from a prior call to | |
30 // Push(). If zero or positive, the output contains data from the current | |
31 // 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.
| |
32 using OutputCallback = | |
33 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.
| |
34 | |
35 // Creates a new AudioPushFifo delivers re-buffered audio by running | |
36 // |callback|. | |
37 explicit AudioPushFifo(const OutputCallback& callback); | |
38 | |
39 ~AudioPushFifo(); | |
40 | |
41 // Returns the number of frames in each AudioBus delivered to the | |
42 // OutputCallback. | |
43 int output_frames() const { return output_frames_; } | |
44 | |
45 // Must be called at least once before the first call to Push(). May be | |
46 // called later (e.g., to support an audio format change). | |
47 void Reset(int frames_per_buffer); | |
48 | |
49 // Pushes all audio channel data from |input_bus| through the FIFO. This will | |
50 // result in zero, one, or multiple synchronous calls to the OutputCallback | |
51 // provided in the constructor. | |
52 void Push(const AudioBus& input_bus); | |
53 | |
54 private: | |
55 const OutputCallback callback_; | |
56 | |
57 int output_frames_; | |
58 | |
59 // Queue of frames pending for delivery. | |
60 scoped_ptr<AudioBus> audio_queue_; | |
61 int queued_frames_; | |
62 | |
63 DISALLOW_COPY_AND_ASSIGN(AudioPushFifo); | |
64 }; | |
65 | |
66 } // namespace media | |
67 | |
68 #endif // MEDIA_BASE_AUDIO_PUSH_FIFO_H_ | |
OLD | NEW |