• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright 2019 The libgav1 Authors
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  *      http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */
16 
17 #ifndef LIBGAV1_SRC_UTILS_BIT_READER_H_
18 #define LIBGAV1_SRC_UTILS_BIT_READER_H_
19 
20 #include <cstdint>
21 
22 namespace libgav1 {
23 
24 class BitReader {
25  public:
26   virtual ~BitReader() = default;
27 
28   virtual int ReadBit() = 0;
29   // |num_bits| has to be <= 32. The function returns a value in the range [0,
30   // 2^num_bits - 1] (inclusive) on success and -1 on failure.
31   virtual int64_t ReadLiteral(int num_bits) = 0;
32 
33   bool DecodeSignedSubexpWithReference(int low, int high, int reference,
34                                        int control, int* value);  // 5.9.26.
35   // Decodes a nonnegative integer with maximum number of values |n| (i.e.,
36   // output in range 0..n-1) by following the process specified in Section
37   // 4.10.7 ns(n) and Section 4.10.10 NS(n) of the spec.
38   bool DecodeUniform(int n, int* value);
39 
40  private:
41   // Helper functions for DecodeSignedSubexpWithReference.
42   bool DecodeUnsignedSubexpWithReference(int mx, int reference, int control,
43                                          int* value);           // 5.9.27.
44   bool DecodeSubexp(int num_symbols, int control, int* value);  // 5.9.28.
45 };
46 
47 }  // namespace libgav1
48 
49 #endif  // LIBGAV1_SRC_UTILS_BIT_READER_H_
50