summaryrefslogtreecommitdiffstats
path: root/media/base/buffer_queue.h
diff options
context:
space:
mode:
authorkylep@chromium.org <kylep@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-08 23:54:55 +0000
committerkylep@chromium.org <kylep@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2009-07-08 23:54:55 +0000
commit12f3ede02f588cce7c8a9e18daad19b08e582039 (patch)
tree567da4810d5a44eda72d8de120f1eb9a89cac097 /media/base/buffer_queue.h
parent1677984e6a69087de30496b2a9e7cfa21e172a77 (diff)
downloadchromium_src-12f3ede02f588cce7c8a9e18daad19b08e582039.zip
chromium_src-12f3ede02f588cce7c8a9e18daad19b08e582039.tar.gz
chromium_src-12f3ede02f588cce7c8a9e18daad19b08e582039.tar.bz2
BufferQueue class to hide audio data micromanagement from scaling algorithms. May be useful in other contexts.
BUG=16011 TEST=src/media/base/buffer_queue_unittest.cc Review URL: http://codereview.chromium.org/155193 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@20211 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'media/base/buffer_queue.h')
-rw-r--r--media/base/buffer_queue.h62
1 files changed, 62 insertions, 0 deletions
diff --git a/media/base/buffer_queue.h b/media/base/buffer_queue.h
new file mode 100644
index 0000000..363b136
--- /dev/null
+++ b/media/base/buffer_queue.h
@@ -0,0 +1,62 @@
+// Copyright (c) 2009 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+// BufferQueue is a simple Buffer manager that handles requests for data
+// while hiding Buffer boundaries, treating its internal queue of Buffers
+// as a contiguous region.
+//
+// This class is not threadsafe and requires external locking.
+
+#ifndef MEDIA_BASE_BUFFER_QUEUE_H_
+#define MEDIA_BASE_BUFFER_QUEUE_H_
+
+#include <deque>
+
+#include "base/ref_counted.h"
+
+namespace media {
+
+class Buffer;
+
+class BufferQueue {
+ public:
+ BufferQueue();
+ ~BufferQueue();
+
+ // Clears |queue_|.
+ void Clear();
+
+ // Advances front pointer |bytes_to_be_consumed| bytes and discards
+ // "consumed" buffers.
+ void Consume(size_t bytes_to_be_consumed);
+
+ // Tries to copy |bytes| bytes from our data to |dest|. Returns the number
+ // of bytes successfully copied.
+ size_t Copy(uint8* dest, size_t bytes);
+
+ // Enqueues |buffer_in| and adds a reference.
+ void Enqueue(Buffer* buffer_in);
+
+ // Returns true if the |queue_| is empty.
+ bool IsEmpty();
+
+ // Returns the number of bytes in the |queue_|.
+ size_t SizeInBytes();
+
+ private:
+ // Queued audio data.
+ std::deque< scoped_refptr<Buffer> > queue_;
+
+ // Remembers the amount of remaining audio data in the front buffer.
+ size_t data_offset_;
+
+ // Keeps track of the |queue_| size in bytes.
+ size_t size_in_bytes_;
+
+ DISALLOW_COPY_AND_ASSIGN(BufferQueue);
+};
+
+} // namespace media
+
+#endif // MEDIA_BASE_BUFFER_QUEUE_H_