- add sources.
[platform/framework/web/crosswalk.git] / src / media / base / byte_queue.h
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.
4
5 #ifndef MEDIA_BASE_BYTE_QUEUE_H_
6 #define MEDIA_BASE_BYTE_QUEUE_H_
7
8 #include "base/basictypes.h"
9 #include "base/memory/scoped_ptr.h"
10 #include "media/base/media_export.h"
11
12 namespace media {
13
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();
23
24   // Reset the queue to the empty state.
25   void Reset();
26
27   // Appends new bytes onto the end of the queue.
28   void Push(const uint8* data, int size);
29
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;
34
35   // Remove |count| bytes from the front of the queue.
36   void Pop(int count);
37
38  private:
39   // Returns a pointer to the front of the queue.
40   uint8* front() const;
41
42   scoped_ptr<uint8[]> buffer_;
43
44   // Size of |buffer_|.
45   size_t size_;
46
47   // Offset from the start of |buffer_| that marks the front of the queue.
48   size_t offset_;
49
50   // Number of bytes stored in the queue.
51   int used_;
52
53   DISALLOW_COPY_AND_ASSIGN(ByteQueue);
54 };
55
56 }  // namespace media
57
58 #endif  // MEDIA_BASE_BYTE_QUEUE_H_