Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2013 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_BUFFER_QUEUE_H_ | |
| 6 #define MEDIA_BASE_AUDIO_BUFFER_QUEUE_H_ | |
| 7 | |
| 8 #include <deque> | |
| 9 | |
| 10 #include "base/basictypes.h" | |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "media/base/audio_buffer.h" | |
| 13 #include "media/base/media_export.h" | |
| 14 | |
| 15 namespace media { | |
| 16 | |
| 17 class AudioBus; | |
| 18 | |
| 19 // A queue of AudioBuffers to support reading of arbitrary chunks of a media | |
| 20 // data source. Audio data can be copied into an AudioBus for output. The | |
| 21 // current position can be forwarded to anywhere in the buffered data. | |
| 22 // | |
| 23 // This class is not inherently thread-safe. Concurrent access must be | |
| 24 // externally serialized. | |
| 25 class MEDIA_EXPORT AudioBufferQueue { | |
| 26 public: | |
| 27 AudioBufferQueue(); | |
| 28 ~AudioBufferQueue(); | |
| 29 | |
| 30 // Clears the buffer queue. | |
| 31 void Clear(); | |
| 32 | |
| 33 // Appends |buffer_in| to this queue. | |
| 34 void Append(const scoped_refptr<AudioBuffer>& buffer_in); | |
| 35 | |
| 36 // Reads a maximum of |frames| frames into |dest| from the current position. | |
| 37 // Returns the number of frames read. The current position will advance by the | |
| 38 // amount of frames read. | |
| 39 int ReadFrames(int frames, AudioBus* dest); | |
| 40 | |
| 41 // Copies up to |frames| frames from current position to |dest|. Returns | |
| 42 // number of frames copied. Doesn't advance current position. Optionally | |
| 43 // starts at a |forward_offset| from current position. | |
| 44 int PeekFrames(int frames, AudioBus* dest) { | |
|
scherkus (not reviewing)
2013/06/20 22:05:15
how many calls to do we have for each version of P
jrummell
2013/06/20 23:28:58
Peek (w/offset) called from audio_renderer_algorit
| |
| 45 return PeekFrames(frames, 0, dest); | |
| 46 } | |
| 47 int PeekFrames(int frames, int forward_offset, AudioBus* dest); | |
| 48 | |
| 49 // Moves the current position forward by |frames| frames. If |frames| exceeds | |
| 50 // frames available, the seek operation will fail. | |
| 51 void SeekFrames(int frames); | |
| 52 | |
| 53 // Returns the number of frames buffered beyond the current position. | |
| 54 int frames() const { return frames_; } | |
| 55 | |
| 56 // Returns the current timestamp, taking into account current offset. The | |
| 57 // value calculated based on the timestamp of the current buffer. If timestamp | |
| 58 // for the current buffer is set to 0, then returns value that corresponds to | |
| 59 // the last position in a buffer that had timestamp set. kNoTimestamp() is | |
| 60 // returned if no buffers we read from had timestamp set. | |
| 61 base::TimeDelta current_time() const { return current_time_; } | |
| 62 | |
| 63 private: | |
| 64 // Definition of the buffer queue. | |
| 65 typedef std::deque<scoped_refptr<AudioBuffer> > BufferQueue; | |
| 66 | |
| 67 // An internal method shared by ReadFrames() and SeekFrames() that actually | |
| 68 // does reading. It reads a maximum of |frames| frames into |dest|. Returns | |
| 69 // the number of frames read. The current position will be moved forward by | |
| 70 // the number of frames read if |advance_position| is set. If |dest| is NULL, | |
| 71 // only the current position will advance but no data will be copied. | |
| 72 // |forward_offset| can be used to skip frames before reading. | |
| 73 int InternalRead(int frames, | |
| 74 bool advance_position, | |
| 75 int forward_offset, | |
| 76 AudioBus* dest); | |
| 77 | |
| 78 // Updates |current_time_| with the time that corresponds to the specified | |
| 79 // position in the buffer. | |
| 80 void UpdateCurrentTime(BufferQueue::iterator buffer, int offset); | |
| 81 | |
| 82 BufferQueue::iterator current_buffer_; | |
| 83 BufferQueue buffers_; | |
| 84 int current_buffer_offset_; | |
| 85 | |
| 86 // Flag to keep track of the first buffer being added. | |
| 87 bool first_buffer_; | |
| 88 | |
| 89 // Number of frames available to be read in the buffer. | |
| 90 int frames_; | |
| 91 | |
| 92 // Keeps track of the most recent time we've seen in case the |buffers_| is | |
| 93 // empty when our owner asks what time it is. | |
| 94 base::TimeDelta current_time_; | |
| 95 | |
| 96 DISALLOW_COPY_AND_ASSIGN(AudioBufferQueue); | |
| 97 }; | |
| 98 | |
| 99 } // namespace media | |
| 100 | |
| 101 #endif // MEDIA_BASE_AUDIO_BUFFER_QUEUE_H_ | |
| OLD | NEW |