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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
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 br->error_ = false; | |
pbos-webrtc
2016/04/18 19:25:33
Is this already covered by the eof_ flag? If so we
jackychen_
2016/04/18 20:49:47
Not really, the error here might not be the same w
pbos-webrtc
2016/04/18 20:52:02
Have you diagnosed the actual error that happens?
| |
69 VP8LoadNewBytes(br); | 70 VP8LoadNewBytes(br); |
70 } | 71 } |
71 | 72 |
72 // Read a bit with proba 'prob'. | 73 // Read a bit with proba 'prob'. |
73 static int VP8GetBit(VP8BitReader* const br, int prob) { | 74 static int VP8GetBit(VP8BitReader* const br, int prob) { |
74 uint8_t range = br->range_; | 75 uint8_t range = br->range_; |
75 if (br->bits_ < 0) { | 76 if (br->bits_ < 0) { |
76 VP8LoadNewBytes(br); | 77 VP8LoadNewBytes(br); |
77 } | 78 } |
78 | 79 if (br->bits_ < 0) { |
pbos-webrtc
2016/04/18 19:25:33
Shouldn't this be set inside VP8LoadNewBytes when
jackychen_
2016/04/18 20:49:47
I want to stop the operation on br->bits here sinc
| |
80 br->error_ = true; | |
81 return 0; | |
82 } | |
79 const int pos = br->bits_; | 83 const int pos = br->bits_; |
80 const uint8_t split = (range * prob) >> 8; | 84 const uint8_t split = (range * prob) >> 8; |
81 const uint8_t value = static_cast<uint8_t>(br->value_ >> pos); | 85 const uint8_t value = static_cast<uint8_t>(br->value_ >> pos); |
82 int bit; | 86 int bit; |
83 if (value > split) { | 87 if (value > split) { |
84 range -= split + 1; | 88 range -= split + 1; |
85 br->value_ -= static_cast<uint32_t>(split + 1) << pos; | 89 br->value_ -= static_cast<uint32_t>(split + 1) << pos; |
86 bit = 1; | 90 bit = 1; |
87 } else { | 91 } else { |
88 range = split; | 92 range = split; |
(...skipping 99 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
188 ParseSegmentHeader(&br); | 192 ParseSegmentHeader(&br); |
189 ParseFilterHeader(&br); | 193 ParseFilterHeader(&br); |
190 // Number of coefficient data partitions. | 194 // Number of coefficient data partitions. |
191 VP8GetValue(&br, 2); | 195 VP8GetValue(&br, 2); |
192 // Base QP. | 196 // Base QP. |
193 const int base_q0 = VP8GetValue(&br, 7); | 197 const int base_q0 = VP8GetValue(&br, 7); |
194 if (br.eof_ == 1) { | 198 if (br.eof_ == 1) { |
195 LOG(LS_WARNING) << "Failed to get QP, end of file reached."; | 199 LOG(LS_WARNING) << "Failed to get QP, end of file reached."; |
196 return false; | 200 return false; |
197 } | 201 } |
202 if (br.error_) { | |
203 LOG(LS_WARNING) << "Failed to get QP, invalid bitstream."; | |
pbos-webrtc
2016/04/18 20:56:46
Are you sure that this isn't because the stream is
| |
204 return false; | |
205 } | |
198 *qp = base_q0; | 206 *qp = base_q0; |
199 return true; | 207 return true; |
200 } | 208 } |
201 | 209 |
202 } // namespace vp8 | 210 } // namespace vp8 |
203 | 211 |
204 } // namespace webrtc | 212 } // namespace webrtc |
OLD | NEW |