Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2014 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_BLOCK_FIFO_H_ | |
| 6 #define MEDIA_BASE_AUDIO_BLOCK_FIFO_H_ | |
| 7 | |
| 8 #include <queue> | |
| 9 | |
| 10 #include "base/memory/scoped_vector.h" | |
| 11 #include "media/base/audio_bus.h" | |
| 12 #include "media/base/media_export.h" | |
| 13 | |
| 14 namespace media { | |
| 15 | |
| 16 // First-in first-out container for AudioBus elements. | |
| 17 // The FIFO is composed of blocks of AudioBus elements, it accepts interleaved | |
| 18 // data as input and will deinterleave it into the FIFO, and it only allows | |
| 19 // consuming a whole block of AudioBus element. | |
| 20 // This class is thread-unsafe. | |
| 21 class MEDIA_EXPORT AudioBlockFifo { | |
| 22 public: | |
| 23 // Creates a new AudioBlockFifo and allocates |blocks| memory, each block | |
| 24 // of memory can store |channels| of length |frames| data. | |
| 25 AudioBlockFifo(int channels, int frames, int blocks); | |
| 26 virtual ~AudioBlockFifo(); | |
| 27 | |
| 28 // Pushes interleaved audio data from |source| to the FIFO. | |
| 29 // The method will deinterleave the data into a audio bus. | |
| 30 // Push() will crash if the allocated space is insufficient. | |
| 31 void Push(const void* source, int frames, int bytes_per_sample); | |
| 32 | |
| 33 // Consumes a block of audio from the FIFO. Returns an AudioBus which | |
| 34 // contains the consumed audio data to avoid copying. | |
| 35 // Consume() will crash if the FIFO does not contain a block of data. | |
| 36 const AudioBus* Consume(); | |
| 37 | |
| 38 // Empties the FIFO without deallocating any memory. | |
| 39 void Clear(); | |
| 40 | |
| 41 // Number of block of memory ready to be consumed in the FIFO. | |
| 42 int filled_blocks() const; | |
|
DaleCurtis
2014/07/11 22:33:33
Hacker_style requires the methods to be defined in
no longer working on chromium
2014/07/14 11:28:27
Done. Just a though, since I change the empty_fram
DaleCurtis
2014/07/14 20:14:26
I still like available better, but it's up to you.
| |
| 43 | |
| 44 int empty_frames() const; | |
|
DaleCurtis
2014/07/11 22:33:33
Ditto. This also needs a comment since it's not r
no longer working on chromium
2014/07/14 11:28:27
I want this to tell the number of unfilled frames
| |
| 45 | |
| 46 private: | |
| 47 // The actual FIFO is a vector of audio buses. | |
| 48 ScopedVector<AudioBus> audio_blocks_; | |
| 49 | |
| 50 // Queues used to keep track which blocks of memory to be wirteen and | |
| 51 // consumed. | |
| 52 std::queue<AudioBus*> empty_blocks_; | |
|
DaleCurtis
2014/07/11 22:33:33
Why do you need these? Shouldn't you just need a
no longer working on chromium
2014/07/14 11:28:27
Indexes might work but require more complicated lo
DaleCurtis
2014/07/14 20:14:26
Good point, you can just drop the head==tail check
no longer working on chromium
2014/07/15 21:51:42
:) Both work for me. But since you prefer indices,
| |
| 53 std::queue<AudioBus*> filled_blocks_; | |
| 54 | |
| 55 // Maximum number of frames of data one block of memory can contain. | |
| 56 // This value is set by |frames| in the constructor. | |
| 57 const int block_frames_; | |
| 58 | |
| 59 // Current write position in the current written block. | |
| 60 int write_pos_; | |
| 61 | |
| 62 DISALLOW_COPY_AND_ASSIGN(AudioBlockFifo); | |
| 63 }; | |
| 64 | |
| 65 } // namespace media | |
| 66 | |
| 67 #endif // MEDIA_BASE_AUDIO_BLOCK_FIFO_H_ | |
| OLD | NEW |