| 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 <stdint.h> | 8 #include <stdint.h> |
| 9 #include <string> |
| 9 | 10 |
| 10 #include "base/compiler_specific.h" | 11 #include "base/compiler_specific.h" |
| 11 #include "base/macros.h" | 12 #include "base/macros.h" |
| 12 #include "base/memory/scoped_ptr.h" | 13 #include "base/memory/scoped_ptr.h" |
| 13 #include "media/base/bit_reader_core.h" | 14 #include "media/base/bit_reader_core.h" |
| 14 #include "media/base/media_export.h" | 15 #include "media/base/media_export.h" |
| 15 | 16 |
| 16 namespace media { | 17 namespace media { |
| 17 | 18 |
| 18 class MEDIA_EXPORT BitReader | 19 class MEDIA_EXPORT BitReader |
| 19 : NON_EXPORTED_BASE(private BitReaderCore::ByteStreamProvider) { | 20 : NON_EXPORTED_BASE(private BitReaderCore::ByteStreamProvider) { |
| 20 public: | 21 public: |
| 21 // Initialize the reader to start reading at |data|, |size| being size | 22 // Initialize the reader to start reading at |data|, |size| being size |
| 22 // of |data| in bytes. | 23 // of |data| in bytes. |
| 23 BitReader(const uint8_t* data, int size); | 24 BitReader(const uint8_t* data, int size); |
| 24 ~BitReader() override; | 25 ~BitReader() override; |
| 25 | 26 |
| 26 template<typename T> bool ReadBits(int num_bits, T* out) { | 27 template<typename T> bool ReadBits(int num_bits, T* out) { |
| 27 return bit_reader_core_.ReadBits(num_bits, out); | 28 return bit_reader_core_.ReadBits(num_bits, out); |
| 28 } | 29 } |
| 29 | 30 |
| 30 bool ReadFlag(bool* flag) { | 31 bool ReadFlag(bool* flag) { |
| 31 return bit_reader_core_.ReadFlag(flag); | 32 return bit_reader_core_.ReadFlag(flag); |
| 32 } | 33 } |
| 33 | 34 |
| 35 // Read |num_bits| of binary data into |str|. |num_bits| must be a multiple |
| 36 // of 8. This is not efficient for extracting large strings. |
| 37 bool ReadString(int num_bits, std::string* str); |
| 38 |
| 34 bool SkipBits(int num_bits) { | 39 bool SkipBits(int num_bits) { |
| 35 return bit_reader_core_.SkipBits(num_bits); | 40 return bit_reader_core_.SkipBits(num_bits); |
| 36 } | 41 } |
| 37 | 42 |
| 38 int bits_available() const { | 43 int bits_available() const { |
| 39 return initial_size_ * 8 - bits_read(); | 44 return initial_size_ * 8 - bits_read(); |
| 40 } | 45 } |
| 41 | 46 |
| 42 int bits_read() const { | 47 int bits_read() const { |
| 43 return bit_reader_core_.bits_read(); | 48 return bit_reader_core_.bits_read(); |
| (...skipping 13 matching lines...) Expand all Loading... |
| 57 int bytes_left_; | 62 int bytes_left_; |
| 58 | 63 |
| 59 BitReaderCore bit_reader_core_; | 64 BitReaderCore bit_reader_core_; |
| 60 | 65 |
| 61 DISALLOW_COPY_AND_ASSIGN(BitReader); | 66 DISALLOW_COPY_AND_ASSIGN(BitReader); |
| 62 }; | 67 }; |
| 63 | 68 |
| 64 } // namespace media | 69 } // namespace media |
| 65 | 70 |
| 66 #endif // MEDIA_BASE_BIT_READER_H_ | 71 #endif // MEDIA_BASE_BIT_READER_H_ |
| OLD | NEW |