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