author Jean-Yves Avenard <>
Mon, 24 Oct 2016 17:22:05 +1100
changeset 447687 ba7ad23595c949e2829ebd02c413bed7e6a7df54
parent 404446 6feb50a80c5013874d09765ceb61d3c5cd576ad3
child 449447 8978dee37d7935d613814f7af17e119235725170
child 449490 58ea08b7f95186420ab27d59a881408e86717a54
permissions -rw-r--r--
Bug 1309163: Add BitReader::BitsLeft method. r?erald MozReview-Commit-ID: 9HOunJRb1ht

/* This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at */

#ifndef BIT_READER_H_
#define BIT_READER_H_

#include "nsAutoPtr.h"
#include "MediaData.h"

namespace stagefright { class ABitReader; }

namespace mp4_demuxer

class BitReader
  explicit BitReader(const mozilla::MediaByteBuffer* aBuffer);
  BitReader(const uint8_t* aBuffer, size_t aLength);
  uint32_t ReadBits(size_t aNum);
  uint32_t ReadBit() { return ReadBits(1); }
  uint32_t ReadU32() { return ReadBits(32); }
  uint64_t ReadU64();

  // Read the UTF-8 sequence and convert it to its 64-bit UCS-4 encoded form.
  // Return 0xfffffffffffffff if sequence was invalid.
  uint64_t ReadUTF8();
  // Read unsigned integer Exp-Golomb-coded.
  uint32_t ReadUE();
  // Read signed integer Exp-Golomb-coded.
  int32_t ReadSE();

  // Return the number of bits parsed so far;
  size_t BitCount() const;
  // Return the number of bits left.
  size_t BitsLeft() const;

  nsAutoPtr<stagefright::ABitReader> mBitReader;
  const size_t mSize;

} // namespace mp4_demuxer

#endif // BIT_READER_H_