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

Unified Diff: media/mp4/offset_byte_queue.cc

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.cc
diff --git a/media/mp4/offset_byte_queue.cc b/media/mp4/offset_byte_queue.cc
new file mode 100644
index 0000000000000000000000000000000000000000..862d9370b20b58ffdee8f874c5a4ba2b6c574e44
--- /dev/null
+++ b/media/mp4/offset_byte_queue.cc
@@ -0,0 +1,63 @@
+// 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.
+
+#include "media/mp4/offset_byte_queue.h"
+
+#include "base/basictypes.h"
+#include "base/logging.h"
+
+namespace media {
+
+OffsetByteQueue::OffsetByteQueue() : buf_(NULL), size_(0), head_(0) {}
+OffsetByteQueue::~OffsetByteQueue() {}
+
+void OffsetByteQueue::Reset() {
+ queue_.Reset();
+ buf_ = NULL;
+ size_ = 0;
+ head_ = 0;
+}
+
+void OffsetByteQueue::Push(const uint8* buf, int size) {
+ queue_.Push(buf, size);
+ Sync();
+ DVLOG(4) << "Buffer pushed. head=" << head() << " tail=" << tail();
+}
+
+void OffsetByteQueue::Peek(const uint8** buf, int* size) {
+ *buf = size_ > 0 ? buf_ : NULL;
+ *size = size_;
+}
+
+void OffsetByteQueue::Pop(int count) {
+ queue_.Pop(count);
+ head_ += count;
+ Sync();
+}
+
+void OffsetByteQueue::PeekAt(int64 offset, const uint8** buf, int* size) {
+ if (offset < head() || offset >= tail()) {
+ *buf = NULL;
+ *size = 0;
+ return;
+ }
+ *buf = &buf_[offset - head()];
+ *size = tail() - offset;
+}
+
+bool OffsetByteQueue::Trim(int64 max_offset) {
+ if (max_offset < head_) return true;
+ if (max_offset > tail()) {
+ Pop(size_);
+ return false;
+ }
+ Pop(max_offset - head_);
+ return true;
+}
+
+void OffsetByteQueue::Sync() {
+ queue_.Peek(&buf_, &size_);
+}
+
+} // namespace media

Powered by Google App Engine
This is Rietveld 408576698