Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(30)

Side by Side Diff: webrtc/base/bitbuffer.cc

Issue 1314473008: H264 bitstream parser. (Closed) Base URL: https://chromium.googlesource.com/external/webrtc.git@master
Patch Set: remove DCHECK_GT Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
1 /* 1 /*
2 * Copyright 2015 The WebRTC Project Authors. All rights reserved. 2 * Copyright 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 10
(...skipping 169 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 // read the value. 180 // read the value.
181 size_t value_bit_count = zero_bit_count + 1; 181 size_t value_bit_count = zero_bit_count + 1;
182 if (value_bit_count > 32 || !ReadBits(val, value_bit_count)) { 182 if (value_bit_count > 32 || !ReadBits(val, value_bit_count)) {
183 CHECK(Seek(original_byte_offset, original_bit_offset)); 183 CHECK(Seek(original_byte_offset, original_bit_offset));
184 return false; 184 return false;
185 } 185 }
186 *val -= 1; 186 *val -= 1;
187 return true; 187 return true;
188 } 188 }
189 189
190 bool BitBuffer::ReadSignedExponentialGolomb(int32_t* val) {
191 // TODO(pbos): Is there a corner case I'm missing here?
192 uint32_t unsigned_val;
193 if (!ReadExponentialGolomb(&unsigned_val))
noahric 2015/09/03 17:48:58 Brackets to match the rest of the file :-p
pbos-webrtc 2015/09/04 10:01:20 Done.
194 return false;
195 if ((unsigned_val & 1) == 0)
noahric 2015/09/03 17:48:58 This if just falls through and overwrites val, so
pbos-webrtc 2015/09/04 10:01:20 Done, which also uncovered additional bugs. That a
196 *val = (unsigned_val + 1) / 2;
197 *val = -(unsigned_val / 2);
198 return true;
199 }
200
190 void BitBuffer::GetCurrentOffset( 201 void BitBuffer::GetCurrentOffset(
191 size_t* out_byte_offset, size_t* out_bit_offset) { 202 size_t* out_byte_offset, size_t* out_bit_offset) {
192 CHECK(out_byte_offset != NULL); 203 CHECK(out_byte_offset != NULL);
193 CHECK(out_bit_offset != NULL); 204 CHECK(out_bit_offset != NULL);
194 *out_byte_offset = byte_offset_; 205 *out_byte_offset = byte_offset_;
195 *out_bit_offset = bit_offset_; 206 *out_bit_offset = bit_offset_;
196 } 207 }
197 208
198 bool BitBuffer::Seek(size_t byte_offset, size_t bit_offset) { 209 bool BitBuffer::Seek(size_t byte_offset, size_t bit_offset) {
199 if (byte_offset > byte_count_ || bit_offset > 7 || 210 if (byte_offset > byte_count_ || bit_offset > 7 ||
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 } 285 }
275 uint64_t val_to_encode = static_cast<uint64_t>(val) + 1; 286 uint64_t val_to_encode = static_cast<uint64_t>(val) + 1;
276 287
277 // We need to write CountBits(val+1) 0s and then val+1. Since val (as a 288 // We need to write CountBits(val+1) 0s and then val+1. Since val (as a
278 // uint64_t) has leading zeros, we can just write the total golomb encoded 289 // uint64_t) has leading zeros, we can just write the total golomb encoded
279 // size worth of bits, knowing the value will appear last. 290 // size worth of bits, knowing the value will appear last.
280 return WriteBits(val_to_encode, CountBits(val_to_encode) * 2 - 1); 291 return WriteBits(val_to_encode, CountBits(val_to_encode) * 2 - 1);
281 } 292 }
282 293
283 } // namespace rtc 294 } // namespace rtc
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698