| 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 "base/basictypes.h" | |
| 9 #include "base/compiler_specific.h" | 8 #include "base/compiler_specific.h" |
| 10 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 11 #include "media/base/bit_reader_core.h" | 10 #include "media/base/bit_reader_core.h" |
| 12 #include "media/base/media_export.h" | 11 #include "media/base/media_export.h" |
| 13 | 12 |
| 14 namespace media { | 13 namespace media { |
| 15 | 14 |
| 16 class MEDIA_EXPORT BitReader | 15 class MEDIA_EXPORT BitReader |
| 17 : NON_EXPORTED_BASE(private BitReaderCore::ByteStreamProvider) { | 16 : NON_EXPORTED_BASE(private BitReaderCore::ByteStreamProvider) { |
| 18 public: | 17 public: |
| 19 // Initialize the reader to start reading at |data|, |size| being size | 18 // Initialize the reader to start reading at |data|, |size| being size |
| 20 // of |data| in bytes. | 19 // of |data| in bytes. |
| 21 BitReader(const uint8* data, int size); | 20 BitReader(const uint8_t* data, int size); |
| 22 ~BitReader() override; | 21 ~BitReader() override; |
| 23 | 22 |
| 24 template<typename T> bool ReadBits(int num_bits, T* out) { | 23 template<typename T> bool ReadBits(int num_bits, T* out) { |
| 25 return bit_reader_core_.ReadBits(num_bits, out); | 24 return bit_reader_core_.ReadBits(num_bits, out); |
| 26 } | 25 } |
| 27 | 26 |
| 28 bool ReadFlag(bool* flag) { | 27 bool ReadFlag(bool* flag) { |
| 29 return bit_reader_core_.ReadFlag(flag); | 28 return bit_reader_core_.ReadFlag(flag); |
| 30 } | 29 } |
| 31 | 30 |
| 32 bool SkipBits(int num_bits) { | 31 bool SkipBits(int num_bits) { |
| 33 return bit_reader_core_.SkipBits(num_bits); | 32 return bit_reader_core_.SkipBits(num_bits); |
| 34 } | 33 } |
| 35 | 34 |
| 36 int bits_available() const { | 35 int bits_available() const { |
| 37 return initial_size_ * 8 - bits_read(); | 36 return initial_size_ * 8 - bits_read(); |
| 38 } | 37 } |
| 39 | 38 |
| 40 int bits_read() const { | 39 int bits_read() const { |
| 41 return bit_reader_core_.bits_read(); | 40 return bit_reader_core_.bits_read(); |
| 42 } | 41 } |
| 43 | 42 |
| 44 private: | 43 private: |
| 45 // BitReaderCore::ByteStreamProvider implementation. | 44 // BitReaderCore::ByteStreamProvider implementation. |
| 46 int GetBytes(int max_n, const uint8** out) override; | 45 int GetBytes(int max_n, const uint8_t** out) override; |
| 47 | 46 |
| 48 // Total number of bytes that was initially passed to BitReader. | 47 // Total number of bytes that was initially passed to BitReader. |
| 49 const int initial_size_; | 48 const int initial_size_; |
| 50 | 49 |
| 51 // Pointer to the next unread byte in the stream. | 50 // Pointer to the next unread byte in the stream. |
| 52 const uint8* data_; | 51 const uint8_t* data_; |
| 53 | 52 |
| 54 // Bytes left in the stream. | 53 // Bytes left in the stream. |
| 55 int bytes_left_; | 54 int bytes_left_; |
| 56 | 55 |
| 57 BitReaderCore bit_reader_core_; | 56 BitReaderCore bit_reader_core_; |
| 58 | 57 |
| 59 DISALLOW_COPY_AND_ASSIGN(BitReader); | 58 DISALLOW_COPY_AND_ASSIGN(BitReader); |
| 60 }; | 59 }; |
| 61 | 60 |
| 62 } // namespace media | 61 } // namespace media |
| 63 | 62 |
| 64 #endif // MEDIA_BASE_BIT_READER_H_ | 63 #endif // MEDIA_BASE_BIT_READER_H_ |
| OLD | NEW |