OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #ifndef MEDIA_BASE_BIT_READER_H_ | 5 #ifndef MEDIA_BASE_BIT_READER_H_ |
6 #define MEDIA_BASE_BIT_READER_H_ | 6 #define MEDIA_BASE_BIT_READER_H_ |
7 | 7 |
8 #include <sys/types.h> | 8 #include <sys/types.h> |
9 | 9 |
10 #include "base/basictypes.h" | 10 #include "base/basictypes.h" |
(...skipping 19 matching lines...) Expand all Loading... |
30 // return false unless |num_bits| is 0. The type |T| has to be a primitive | 30 // return false unless |num_bits| is 0. The type |T| has to be a primitive |
31 // integer type. | 31 // integer type. |
32 template<typename T> bool ReadBits(int num_bits, T *out) { | 32 template<typename T> bool ReadBits(int num_bits, T *out) { |
33 DCHECK_LE(num_bits, static_cast<int>(sizeof(T) * 8)); | 33 DCHECK_LE(num_bits, static_cast<int>(sizeof(T) * 8)); |
34 uint64 temp; | 34 uint64 temp; |
35 bool ret = ReadBitsInternal(num_bits, &temp); | 35 bool ret = ReadBitsInternal(num_bits, &temp); |
36 *out = static_cast<T>(temp); | 36 *out = static_cast<T>(temp); |
37 return ret; | 37 return ret; |
38 } | 38 } |
39 | 39 |
| 40 // Skip |num_bits| next bits from stream. Return false if the given number of |
| 41 // bits cannot be skipped (not enough bits in the stream), true otherwise. |
| 42 // When return false, the stream will enter a state where further ReadBits/ |
| 43 // SkipBits operations will always return false unless |num_bits| is 0. |
| 44 bool SkipBits(int num_bits); |
| 45 |
40 // Returns the number of bits available for reading. | 46 // Returns the number of bits available for reading. |
41 int bits_available() const; | 47 int bits_available() const; |
42 | 48 |
43 private: | 49 private: |
44 // Help function used by ReadBits to avoid inlining the bit reading logic. | 50 // Help function used by ReadBits to avoid inlining the bit reading logic. |
45 bool ReadBitsInternal(int num_bits, uint64* out); | 51 bool ReadBitsInternal(int num_bits, uint64* out); |
46 | 52 |
47 // Advance to the next byte, loading it into curr_byte_. | 53 // Advance to the next byte, loading it into curr_byte_. |
48 // If the num_remaining_bits_in_curr_byte_ is 0 after this function returns, | 54 // If the num_remaining_bits_in_curr_byte_ is 0 after this function returns, |
49 // the stream has reached the end. | 55 // the stream has reached the end. |
(...skipping 12 matching lines...) Expand all Loading... |
62 // Number of bits remaining in curr_byte_ | 68 // Number of bits remaining in curr_byte_ |
63 int num_remaining_bits_in_curr_byte_; | 69 int num_remaining_bits_in_curr_byte_; |
64 | 70 |
65 private: | 71 private: |
66 DISALLOW_COPY_AND_ASSIGN(BitReader); | 72 DISALLOW_COPY_AND_ASSIGN(BitReader); |
67 }; | 73 }; |
68 | 74 |
69 } // namespace media | 75 } // namespace media |
70 | 76 |
71 #endif // MEDIA_BASE_BIT_READER_H_ | 77 #endif // MEDIA_BASE_BIT_READER_H_ |
OLD | NEW |