Merge Chromium + Blink git repositories
[chromium-blink-merge.git] / media / base / byte_queue.h
blobf25328d3628bca4bd1f60765590a8e7799d5bb62
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_BYTE_QUEUE_H_
6 #define MEDIA_BASE_BYTE_QUEUE_H_
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "media/base/media_export.h"
12 namespace media {
14 // Represents a queue of bytes.
15 // Data is added to the end of the queue via an Push() call and removed via
16 // Pop(). The contents of the queue can be observed via the Peek() method.
17 // This class manages the underlying storage of the queue and tries to minimize
18 // the number of buffer copies when data is appended and removed.
19 class MEDIA_EXPORT ByteQueue {
20 public:
21 ByteQueue();
22 ~ByteQueue();
24 // Reset the queue to the empty state.
25 void Reset();
27 // Appends new bytes onto the end of the queue.
28 void Push(const uint8* data, int size);
30 // Get a pointer to the front of the queue and the queue size.
31 // These values are only valid until the next Push() or
32 // Pop() call.
33 void Peek(const uint8** data, int* size) const;
35 // Remove |count| bytes from the front of the queue.
36 void Pop(int count);
38 private:
39 // Returns a pointer to the front of the queue.
40 uint8* front() const;
42 scoped_ptr<uint8[]> buffer_;
44 // Size of |buffer_|.
45 size_t size_;
47 // Offset from the start of |buffer_| that marks the front of the queue.
48 size_t offset_;
50 // Number of bytes stored in the queue.
51 int used_;
53 DISALLOW_COPY_AND_ASSIGN(ByteQueue);
56 } // namespace media
58 #endif // MEDIA_BASE_BYTE_QUEUE_H_