summaryrefslogtreecommitdiffstats
path: root/media/filters/vp9_raw_bits_reader.h
blob: 5cc46e25a9749c38f8fc48a9995cc3e8da387e9f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef MEDIA_FILTERS_VP9_RAW_BITS_READER_
#define MEDIA_FILTERS_VP9_RAW_BITS_READER_

#include <stddef.h>
#include <stdint.h>

#include "base/macros.h"
#include "base/memory/scoped_ptr.h"
#include "media/base/media_export.h"

namespace media {

class BitReader;

// A class to read raw bits stream. See VP9 spec, "RAW-BITS DECODING" section
// for detail.
class MEDIA_EXPORT Vp9RawBitsReader {
 public:
  Vp9RawBitsReader();
  ~Vp9RawBitsReader();

  // |data| is the input buffer with |size| bytes.
  void Initialize(const uint8_t* data, size_t size);

  // Returns true if none of the reads since the last Initialize() call has
  // gone beyond the end of available data.
  bool IsValid() const { return valid_; }

  // Returns how many bytes were read since the last Initialize() call.
  // Partial bytes will be counted as one byte. For example, it will return 1
  // if 3 bits were read.
  size_t GetBytesRead() const;

  // Reads one bit.
  // If the read goes beyond the end of buffer, the return value is undefined.
  bool ReadBool();

  // Reads a literal with |bits| bits.
  // If the read goes beyond the end of buffer, the return value is undefined.
  int ReadLiteral(int bits);

  // Reads a signed literal with |bits| bits (not including the sign bit).
  // If the read goes beyond the end of buffer, the return value is undefined.
  int ReadSignedLiteral(int bits);

 private:
  scoped_ptr<BitReader> reader_;

  // Indicates if none of the reads since the last Initialize() call has gone
  // beyond the end of available data.
  bool valid_;

  DISALLOW_COPY_AND_ASSIGN(Vp9RawBitsReader);
};

}  // namespace media

#endif  // MEDIA_FILTERS_VP9_RAW_BITS_READER_