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

Unified Diff: media/base/bit_reader.h

Issue 10780026: Add HE AAC support to ISO BMFF. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Remove WARN_UNUSED_RESULT on template function. 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
« no previous file with comments | « no previous file | media/base/bit_reader.cc » ('j') | media/base/bit_reader.cc » ('J')
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/base/bit_reader.h
diff --git a/media/base/bit_reader.h b/media/base/bit_reader.h
new file mode 100644
index 0000000000000000000000000000000000000000..67b0e4bcd5975fe3d1c83eff44b0945473df29df
--- /dev/null
+++ b/media/base/bit_reader.h
@@ -0,0 +1,76 @@
+// 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_BASE_BIT_READER_H_
+#define MEDIA_BASE_BIT_READER_H_
+
+#include <sys/types.h>
+
+#include "base/basictypes.h"
+#include "base/logging.h"
+#include "media/base/media_export.h"
+
+namespace media {
+
+// A class to read bit streams.
+class MEDIA_EXPORT BitReader {
+ public:
+ // Initialize the reader to start reading at |data|, |size| being size
+ // of |data| in bytes.
+ BitReader(const uint8* data, off_t size);
+ ~BitReader();
+
+ // Read |num_bits| next bits from stream and return in |*out|, first bit
+ // from the stream starting at |num_bits| position in |*out|.
+ // |num_bits| cannot be larger than the bits the type can hold.
+ // Return false if the given number of bits cannot be read (not enough
+ // bits in the stream), true otherwise. When return false, the stream will
+ // enter a state where further ReadBits/SkipBits operations will always
+ // return false unless |num_bits| is 0. The type |T| has to be a primitive
+ // integer type.
+ template<typename T>
+ bool ReadBits(int num_bits, T *out) {
+ DCHECK_LE(num_bits, static_cast<int>(sizeof(T) * 8));
Ami GONE FROM CHROMIUM 2012/07/19 00:28:59 For being in the header there's a lot of space tak
xiaomings 2012/07/19 01:11:02 Done.
+
+ uint64 temp;
+
+ if (ReadBitsInternal(num_bits, &temp)) {
+ *out = static_cast<T>(temp);
+
+ return true;
+ }
+
+ *out = 0;
+ return false;
+ }
+
+ private:
+ // Help function used by ReadBits to avoid inlining the bit reading logic.
+ bool ReadBitsInternal(int num_bits, uint64* out);
+
+ // Advance to the next byte, loading it into curr_byte_.
+ // If the num_remaining_bits_in_curr_byte_ is 0 after this function returns,
+ // the stream has reached the end.
+ void UpdateCurrByte();
+
+ // Pointer to the next unread (not in curr_byte_) byte in the stream.
+ const uint8* data_;
+
+ // Bytes left in the stream (without the curr_byte_).
+ off_t bytes_left_;
+
+ // Contents of the current byte; first unread bit starting at position
+ // 8 - num_remaining_bits_in_curr_byte_ from MSB.
+ uint8 curr_byte_;
+
+ // Number of bits remaining in curr_byte_
+ int num_remaining_bits_in_curr_byte_;
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(BitReader);
+};
+
+} // namespace media
+
+#endif // MEDIA_BASE_BIT_READER_H_
« no previous file with comments | « no previous file | media/base/bit_reader.cc » ('j') | media/base/bit_reader.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698