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

Unified Diff: media/base/bit_reader.cc

Issue 10753005: Add HE AAC support to ISO BMFF. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 5 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/base/bit_reader.cc
diff --git a/media/base/bit_reader.cc b/media/base/bit_reader.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e4106fa24a8dab44ddcda11bb8eb555e113b485f
--- /dev/null
+++ b/media/base/bit_reader.cc
@@ -0,0 +1,74 @@
+// 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/base/bit_reader.h"
+
+namespace media {
+
+BitReader::BitReader()
+ : data_(NULL),
+ bytes_left_(0),
+ position_(0),
+ curr_byte_(0),
+ num_remaining_bits_in_curr_byte_(0) {
+}
+
+BitReader::BitReader(const uint8* data, off_t size) {
+ Initialize(data, size);
+}
+
+BitReader::~BitReader() {}
+
+void BitReader::Initialize(const uint8* data, off_t size) {
+ DCHECK(data != NULL || size == 0); // Data cannot be NULL if size is not 0.
+
+ data_ = data;
+ bytes_left_ = size;
+ position_ = 0;
+ num_remaining_bits_in_curr_byte_ = 0;
+
+ UpdateCurrByte();
+}
+
+void BitReader::UpdateCurrByte() {
+ DCHECK_EQ(num_remaining_bits_in_curr_byte_, 0);
+
+ if (bytes_left_ < 1)
+ return;
+
+ // Load a new byte and advance pointers.
+ curr_byte_ = *data_;
+ ++data_;
+ --bytes_left_;
+ num_remaining_bits_in_curr_byte_ = 8;
+}
+
+bool BitReader::SkipBits(int num_bits) {
+ int dummy;
+ const int kDummySize = static_cast<int>(sizeof(dummy)) * 8;
+
+ while (num_bits > kDummySize) {
+ if (ReadBits(kDummySize, &dummy)) {
+ num_bits -= kDummySize;
+ } else {
+ return false;
+ }
+ }
+
+ return ReadBits(num_bits, &dummy);
+}
+
+off_t BitReader::Tell() const {
+ return position_;
+}
+
+off_t BitReader::NumBitsLeft() const {
+ return (num_remaining_bits_in_curr_byte_ + bytes_left_ * 8);
+}
+
+bool BitReader::HasMoreData() const {
+ return num_remaining_bits_in_curr_byte_ != 0;
+}
+
+} // namespace media

Powered by Google App Engine
This is Rietveld 408576698