Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(447)

Unified Diff: media/mp4/offset_byte_queue.h

Issue 10534172: Implement ISO BMFF support in Media Source (try 2). (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: media/mp4/offset_byte_queue.h
diff --git a/media/mp4/offset_byte_queue.h b/media/mp4/offset_byte_queue.h
new file mode 100644
index 0000000000000000000000000000000000000000..9349b96088f4b07dc70dbb97ce62bf018d68cc28
--- /dev/null
+++ b/media/mp4/offset_byte_queue.h
@@ -0,0 +1,66 @@
+// Copyright (c) 2012 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.
+
+#ifndef MEDIA_MP4_OFFSET_BYTE_QUEUE_H_
+#define MEDIA_MP4_OFFSET_BYTE_QUEUE_H_
+
+#include "base/basictypes.h"
+#include "media/base/byte_queue.h"
+#include "media/base/media_export.h"
+
+namespace media {
+
+// A wrapper around a ByteQueue which maintains a notion of a
+// monotonically-increasing offset. All buffer access is done by passing these
+// offsets into this class, going some way towards preventing the proliferation
+// of many different meanings of "offset", "head", etc.
+class MEDIA_EXPORT OffsetByteQueue {
+ public:
+ OffsetByteQueue();
+ ~OffsetByteQueue();
+
+ // These work like their underlying ByteQueue counterparts.
+ void Reset();
+ void Push(const uint8* buf, int size);
+ void Peek(const uint8** buf, int* size);
+ void Pop(int count);
+
+ // Sets |buf| to point at the first buffered byte corresponding to |offset|,
+ // and |size| to the number of bytes available starting from that offset.
+ //
+ // It is an error if the offset is before the current head. It's not an error
+ // if the current offset is beyond tail(), but you will of course get back
+ // a null |buf| and a |size| of zero.
+ void PeekAt(int64 offset, const uint8** buf, int* size);
+
+ // Marks the bytes up to (but not including) |max_offset| as ready for
+ // deletion. This is relatively inexpensive, but will not necessarily reduce
+ // the resident buffer size right away (or ever).
+ //
+ // Returns true if the full range of bytes were successfully trimmed,
+ // including the case where |max_offset| is less than the current head.
+ // Returns false if |max_offset| > tail() (although all bytes currently
+ // buffered are still cleared).
+ bool Trim(int64 max_offset);
+
+ // The head and tail positions, in terms of the file's absolute offsets.
+ // tail() is an exclusive bound.
+ int64 head() { return head_; }
+ int64 tail() { return head_ + size_; }
+
+ private:
+ // Synchronize |buf_| and |size_| with |queue_|.
+ void Sync();
+
+ ByteQueue queue_;
+ const uint8* buf_;
+ int size_;
+ int64 head_;
+
+ DISALLOW_COPY_AND_ASSIGN(OffsetByteQueue);
+};
+
+} // namespace media
+
+#endif // MEDIA_MP4_MP4_STREAM_PARSER_H_

Powered by Google App Engine
This is Rietveld 408576698