OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2015 The WebRTC project authors. All Rights Reserved. | 2 * Copyright (c) 2015 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 #include "webrtc/modules/video_coding/utility/vp8_header_parser.h" | 10 #include "webrtc/modules/video_coding/utility/vp8_header_parser.h" |
(...skipping 25 matching lines...) Expand all Loading... |
36 } | 36 } |
37 | 37 |
38 static void VP8LoadNewBytes(VP8BitReader* const br) { | 38 static void VP8LoadNewBytes(VP8BitReader* const br) { |
39 int BITS = 24; | 39 int BITS = 24; |
40 // Read 'BITS' bits at a time. | 40 // Read 'BITS' bits at a time. |
41 if (br->buf_ + sizeof(uint32_t) <= br->buf_end_) { | 41 if (br->buf_ + sizeof(uint32_t) <= br->buf_end_) { |
42 uint32_t bits; | 42 uint32_t bits; |
43 const uint32_t in_bits = *(const uint32_t*)(br->buf_); | 43 const uint32_t in_bits = *(const uint32_t*)(br->buf_); |
44 br->buf_ += BITS >> 3; | 44 br->buf_ += BITS >> 3; |
45 #if defined(WEBRTC_ARCH_BIG_ENDIAN) | 45 #if defined(WEBRTC_ARCH_BIG_ENDIAN) |
46 bits = static_cast<uint32_t>(in_bits); | 46 bits = static_cast<uint32_t>(in_bits); |
47 if (BITS != 8 * sizeof(uint32_t)) | 47 if (BITS != 8 * sizeof(uint32_t)) |
48 bits >>= (8 * sizeof(uint32_t) - BITS); | 48 bits >>= (8 * sizeof(uint32_t) - BITS); |
49 #else | 49 #else |
50 bits = BSwap32(in_bits); | 50 bits = BSwap32(in_bits); |
51 bits >>= 32 - BITS; | 51 bits >>= 32 - BITS; |
52 #endif | 52 #endif |
53 br->value_ = bits | (br->value_ << BITS); | 53 br->value_ = bits | (br->value_ << BITS); |
54 br->bits_ += BITS; | 54 br->bits_ += BITS; |
55 } else { | 55 } else { |
56 VP8LoadFinalBytes(br); | 56 VP8LoadFinalBytes(br); |
57 } | 57 } |
58 } | 58 } |
59 | 59 |
60 static void VP8InitBitReader(VP8BitReader* const br, | 60 static void VP8InitBitReader(VP8BitReader* const br, |
61 const uint8_t* const start, | 61 const uint8_t* const start, |
62 const uint8_t* const end) { | 62 const uint8_t* const end) { |
63 br->range_ = 255 - 1; | 63 br->range_ = 255 - 1; |
64 br->buf_ = start; | 64 br->buf_ = start; |
65 br->buf_end_ = end; | 65 br->buf_end_ = end; |
66 br->value_ = 0; | 66 br->value_ = 0; |
67 br->bits_ = -8; // To load the very first 8bits. | 67 br->bits_ = -8; // To load the very first 8bits. |
68 br->eof_ = 0; | 68 br->eof_ = 0; |
69 VP8LoadNewBytes(br); | 69 VP8LoadNewBytes(br); |
70 } | 70 } |
71 | 71 |
72 // Read a bit with proba 'prob'. | 72 // Read a bit with proba 'prob'. |
73 static int VP8GetBit(VP8BitReader* const br, int prob) { | 73 static int VP8GetBit(VP8BitReader* const br, int prob) { |
74 uint8_t range = br->range_; | 74 uint8_t range = br->range_; |
75 if (br->bits_ < 0) { | 75 if (br->bits_ < 0) { |
76 VP8LoadNewBytes(br); | 76 VP8LoadNewBytes(br); |
77 } | 77 } |
78 | 78 |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
115 } | 115 } |
116 | 116 |
117 static void ParseSegmentHeader(VP8BitReader* br) { | 117 static void ParseSegmentHeader(VP8BitReader* br) { |
118 int use_segment = VP8Get(br); | 118 int use_segment = VP8Get(br); |
119 if (use_segment) { | 119 if (use_segment) { |
120 int update_map = VP8Get(br); | 120 int update_map = VP8Get(br); |
121 if (VP8Get(br)) { | 121 if (VP8Get(br)) { |
122 int s; | 122 int s; |
123 VP8Get(br); | 123 VP8Get(br); |
124 for (s = 0; s < NUM_MB_SEGMENTS; ++s) { | 124 for (s = 0; s < NUM_MB_SEGMENTS; ++s) { |
125 VP8Get(br) ? VP8GetSignedValue(br, 7) : 0; | 125 VP8Get(br) ? VP8GetSignedValue(br, 7) : 0; |
126 } | 126 } |
127 for (s = 0; s < NUM_MB_SEGMENTS; ++s) { | 127 for (s = 0; s < NUM_MB_SEGMENTS; ++s) { |
128 VP8Get(br) ? VP8GetSignedValue(br, 6) : 0; | 128 VP8Get(br) ? VP8GetSignedValue(br, 6) : 0; |
129 } | 129 } |
130 } | 130 } |
131 if (update_map) { | 131 if (update_map) { |
132 int s; | 132 int s; |
133 for (s = 0; s < MB_FEATURE_TREE_PROBS; ++s) { | 133 for (s = 0; s < MB_FEATURE_TREE_PROBS; ++s) { |
134 VP8Get(br) ? VP8GetValue(br, 8) : 255; | 134 VP8Get(br) ? VP8GetValue(br, 8) : 255; |
135 } | 135 } |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 LOG(LS_WARNING) << "Failed to get QP, end of file reached."; | 195 LOG(LS_WARNING) << "Failed to get QP, end of file reached."; |
196 return false; | 196 return false; |
197 } | 197 } |
198 *qp = base_q0; | 198 *qp = base_q0; |
199 return true; | 199 return true; |
200 } | 200 } |
201 | 201 |
202 } // namespace vp8 | 202 } // namespace vp8 |
203 | 203 |
204 } // namespace webrtc | 204 } // namespace webrtc |
OLD | NEW |