| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2009 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 // BufferQueue is a simple Buffer manager that handles requests for data | |
| 6 // while hiding Buffer boundaries, treating its internal queue of Buffers | |
| 7 // as a contiguous region. | |
| 8 // | |
| 9 // This class is not threadsafe and requires external locking. | |
| 10 | |
| 11 #ifndef MEDIA_BASE_BUFFER_QUEUE_H_ | |
| 12 #define MEDIA_BASE_BUFFER_QUEUE_H_ | |
| 13 | |
| 14 #include <deque> | |
| 15 | |
| 16 #include "base/ref_counted.h" | |
| 17 #include "base/time.h" | |
| 18 | |
| 19 namespace media { | |
| 20 | |
| 21 class Buffer; | |
| 22 | |
| 23 class BufferQueue { | |
| 24 public: | |
| 25 BufferQueue(); | |
| 26 ~BufferQueue(); | |
| 27 | |
| 28 // Clears |queue_|. | |
| 29 void Clear(); | |
| 30 | |
| 31 // Advances front pointer |bytes_to_be_consumed| bytes and discards | |
| 32 // "consumed" buffers. | |
| 33 void Consume(size_t bytes_to_be_consumed); | |
| 34 | |
| 35 // Tries to copy |bytes| bytes from our data to |dest|. Returns the number | |
| 36 // of bytes successfully copied. | |
| 37 size_t Copy(uint8* dest, size_t bytes); | |
| 38 | |
| 39 // Enqueues |buffer_in| and adds a reference. | |
| 40 void Enqueue(Buffer* buffer_in); | |
| 41 | |
| 42 // Returns the current timestamp, taking into account |data_offset_|. | |
| 43 base::TimeDelta GetTime(); | |
| 44 | |
| 45 // Returns true if the |queue_| is empty. | |
| 46 bool IsEmpty(); | |
| 47 | |
| 48 // Returns the number of bytes in the |queue_|. | |
| 49 size_t SizeInBytes(); | |
| 50 | |
| 51 private: | |
| 52 // Queued audio data. | |
| 53 std::deque< scoped_refptr<Buffer> > queue_; | |
| 54 | |
| 55 // Remembers the amount of remaining audio data in the front buffer. | |
| 56 size_t data_offset_; | |
| 57 | |
| 58 // Keeps track of the |queue_| size in bytes. | |
| 59 size_t size_in_bytes_; | |
| 60 | |
| 61 // Keeps track of the most recent time we've seen in case the |queue_| is | |
| 62 // empty when our owner asks what time it is. | |
| 63 base::TimeDelta most_recent_time_; | |
| 64 | |
| 65 DISALLOW_COPY_AND_ASSIGN(BufferQueue); | |
| 66 }; | |
| 67 | |
| 68 } // namespace media | |
| 69 | |
| 70 #endif // MEDIA_BASE_BUFFER_QUEUE_H_ | |
| OLD | NEW |