OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2017 The WebRTC project authors. All Rights Reserved. |
3 * | 3 * |
4 * Use of this source code is governed by a BSD-style license | 4 * Use of this source code is governed by a BSD-style license |
5 * that can be found in the LICENSE file in the root of the source | 5 * that can be found in the LICENSE file in the root of the source |
6 * tree. An additional intellectual property rights grant can be found | 6 * tree. An additional intellectual property rights grant can be found |
7 * in the file PATENTS. All contributing project authors may | 7 * in the file PATENTS. All contributing project authors may |
8 * be found in the AUTHORS file in the root of the source tree. | 8 * be found in the AUTHORS file in the root of the source tree. |
9 */ | 9 */ |
10 | 10 |
11 #ifndef WEBRTC_MODULES_VIDEO_CODING_UTILITY_VP9_UNCOMPRESSED_HEADER_PARSER_H_ | 11 #ifndef WEBRTC_MODULES_VIDEO_CODING_UTILITY_VP9_UNCOMPRESSED_HEADER_PARSER_H_ |
12 #define WEBRTC_MODULES_VIDEO_CODING_UTILITY_VP9_UNCOMPRESSED_HEADER_PARSER_H_ | 12 #define WEBRTC_MODULES_VIDEO_CODING_UTILITY_VP9_UNCOMPRESSED_HEADER_PARSER_H_ |
13 | 13 |
14 #include <stddef.h> | 14 #include <stddef.h> |
15 #include <stdint.h> | 15 #include <stdint.h> |
16 | 16 |
17 #include "webrtc/base/bitbuffer.h" | |
18 #include "webrtc/base/logging.h" | |
19 | |
20 namespace webrtc { | 17 namespace webrtc { |
21 | 18 |
22 namespace vp9 { | 19 namespace vp9 { |
23 | 20 |
24 class VP9BitReader : public ::rtc::BitBuffer { | |
25 public: | |
26 VP9BitReader(const uint8_t* buffer, size_t length_) | |
27 : BitBuffer(buffer, length_) {} | |
28 | |
29 uint32_t GetBit() { | |
30 uint32_t bit = 0; | |
31 if (ReadBits(&bit, 1)) | |
32 return bit; | |
33 | |
34 LOG(LS_WARNING) << "Failed to get bit. Reached EOF."; | |
35 return 0; | |
36 } | |
37 | |
38 uint32_t GetValue(int bits) { | |
39 uint32_t value = 0; | |
40 if (ReadBits(&value, bits)) | |
41 return value; | |
42 | |
43 LOG(LS_WARNING) << "Failed to get bit. Reached EOF."; | |
44 return 0; | |
45 } | |
46 | |
47 int32_t GetSignedValue(int bits) { | |
48 const int32_t value = static_cast<int>(GetValue(bits)); | |
49 return GetBit() ? -value : value; | |
50 } | |
51 }; | |
52 | |
53 // Gets the QP, QP range: [0, 255]. | 21 // Gets the QP, QP range: [0, 255]. |
54 // Returns true on success, false otherwise. | 22 // Returns true on success, false otherwise. |
55 bool GetQp(const uint8_t* buf, size_t length, int* qp); | 23 bool GetQp(const uint8_t* buf, size_t length, int* qp); |
56 | 24 |
57 } // namespace vp9 | 25 } // namespace vp9 |
58 | 26 |
59 } // namespace webrtc | 27 } // namespace webrtc |
60 | 28 |
61 #endif // WEBRTC_MODULES_VIDEO_CODING_UTILITY_VP9_UNCOMPRESSED_HEADER_PARSER_H_ | 29 #endif // WEBRTC_MODULES_VIDEO_CODING_UTILITY_VP9_UNCOMPRESSED_HEADER_PARSER_H_ |
OLD | NEW |