[Sync] Move DataTypeStatusTable ownership into DataTypeManager.
[chromium-blink-merge.git] / media / base / audio_fifo.h
blobc00dd40fef9c99b202e18c35cbce7d09b69e4eea
1 // Copyright (c) 2012 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.
5 #ifndef MEDIA_BASE_AUDIO_FIFO_H_
6 #define MEDIA_BASE_AUDIO_FIFO_H_
8 #include "media/base/audio_bus.h"
9 #include "media/base/media_export.h"
11 namespace media {
13 // First-in first-out container for AudioBus elements.
14 // The maximum number of audio frames in the FIFO is set at construction and
15 // can not be extended dynamically. The allocated memory is utilized as a
16 // ring buffer.
17 // This class is thread-unsafe.
18 class MEDIA_EXPORT AudioFifo {
19 public:
20 // Creates a new AudioFifo and allocates |channels| of length |frames|.
21 AudioFifo(int channels, int frames);
22 virtual ~AudioFifo();
24 // Pushes all audio channel data from |source| to the FIFO.
25 // Push() will crash if the allocated space is insufficient.
26 void Push(const AudioBus* source);
28 // Consumes |frames_to_consume| audio frames from the FIFO and copies
29 // them to |destination| starting at position |start_frame|.
30 // Consume() will crash if the FIFO does not contain |frames_to_consume|
31 // frames or if there is insufficient space in |destination| to store the
32 // frames.
33 void Consume(AudioBus* destination, int start_frame, int frames_to_consume);
35 // Empties the FIFO without deallocating any memory.
36 void Clear();
38 // Number of actual audio frames in the FIFO.
39 int frames() const;
41 int max_frames() const { return max_frames_; }
43 private:
44 // The actual FIFO is an audio bus implemented as a ring buffer.
45 scoped_ptr<AudioBus> audio_bus_;
47 // Maximum number of elements the FIFO can contain.
48 // This value is set by |frames| in the constructor.
49 const int max_frames_;
51 // Number of actual elements in the FIFO.
52 int frames_pushed_;
53 int frames_consumed_;
55 // Current read position.
56 int read_pos_;
58 // Current write position.
59 int write_pos_;
61 DISALLOW_COPY_AND_ASSIGN(AudioFifo);
64 } // namespace media
66 #endif // MEDIA_BASE_AUDIO_FIFO_H_