[M120 Migration][hbbtv] Audio tracks count notification
[platform/framework/web/chromium-efl.git] / media / filters / vp9_raw_bits_reader.h
1 // Copyright 2015 The Chromium Authors
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_FILTERS_VP9_RAW_BITS_READER_H_
6 #define MEDIA_FILTERS_VP9_RAW_BITS_READER_H_
7
8 #include <stddef.h>
9 #include <stdint.h>
10
11 #include <memory>
12
13 #include "media/base/media_export.h"
14
15 namespace media {
16
17 class BitReader;
18
19 // A class to read raw bits stream. See VP9 spec, "RAW-BITS DECODING" section
20 // for detail.
21 class MEDIA_EXPORT Vp9RawBitsReader {
22  public:
23   Vp9RawBitsReader();
24
25   Vp9RawBitsReader(const Vp9RawBitsReader&) = delete;
26   Vp9RawBitsReader& operator=(const Vp9RawBitsReader&) = delete;
27
28   ~Vp9RawBitsReader();
29
30   // |data| is the input buffer with |size| bytes.
31   void Initialize(const uint8_t* data, size_t size);
32
33   // Returns true if none of the reads since the last Initialize() call has
34   // gone beyond the end of available data.
35   bool IsValid() const { return valid_; }
36
37   // Returns how many bytes were read since the last Initialize() call.
38   // Partial bytes will be counted as one byte. For example, it will return 1
39   // if 3 bits were read.
40   size_t GetBytesRead() const;
41
42   // Reads one bit.
43   // If the read goes beyond the end of buffer, the return value is undefined.
44   bool ReadBool();
45
46   // Reads a literal with |bits| bits.
47   // If the read goes beyond the end of buffer, the return value is undefined.
48   int ReadLiteral(int bits);
49
50   // Reads a signed literal with |bits| bits (not including the sign bit).
51   // If the read goes beyond the end of buffer, the return value is undefined.
52   int ReadSignedLiteral(int bits);
53
54   // Consumes trailing bits up to next byte boundary. Returns true if no
55   // trailing bits or they are all zero.
56   bool ConsumeTrailingBits();
57
58  private:
59   std::unique_ptr<BitReader> reader_;
60
61   // Indicates if none of the reads since the last Initialize() call has gone
62   // beyond the end of available data.
63   bool valid_;
64 };
65
66 }  // namespace media
67
68 #endif  // MEDIA_FILTERS_VP9_RAW_BITS_READER_H_