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

Side by Side Diff: media/filters/h264_bit_reader.cc

Issue 1886423002: Avoid left shift of negative values when parsing H264 stream (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "base/logging.h" 5 #include "base/logging.h"
6 #include "media/filters/h264_bit_reader.h" 6 #include "media/filters/h264_bit_reader.h"
7 7
8 namespace media { 8 namespace media {
9 9
10 H264BitReader::H264BitReader() 10 H264BitReader::H264BitReader()
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after
49 49
50 if (bytes_left_ < 1) 50 if (bytes_left_ < 1)
51 return false; 51 return false;
52 } 52 }
53 53
54 // Load a new byte and advance pointers. 54 // Load a new byte and advance pointers.
55 curr_byte_ = *data_++ & 0xff; 55 curr_byte_ = *data_++ & 0xff;
56 --bytes_left_; 56 --bytes_left_;
57 num_remaining_bits_in_curr_byte_ = 8; 57 num_remaining_bits_in_curr_byte_ = 8;
58 58
59 prev_two_bytes_ = (prev_two_bytes_ << 8) | curr_byte_; 59 prev_two_bytes_ = ((prev_two_bytes_ & 0xff) << 8) | curr_byte_;
60 60
61 return true; 61 return true;
62 } 62 }
63 63
64 // Read |num_bits| (1 to 31 inclusive) from the stream and return them 64 // Read |num_bits| (1 to 31 inclusive) from the stream and return them
65 // in |out|, with first bit in the stream as MSB in |out| at position 65 // in |out|, with first bit in the stream as MSB in |out| at position
66 // (|num_bits| - 1). 66 // (|num_bits| - 1).
67 bool H264BitReader::ReadBits(int num_bits, int* out) { 67 bool H264BitReader::ReadBits(int num_bits, int* out) {
68 int bits_left = num_bits; 68 int bits_left = num_bits;
69 *out = 0; 69 *out = 0;
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
113 113
114 bytes_left_ = 0; 114 bytes_left_ = 0;
115 return false; 115 return false;
116 } 116 }
117 117
118 size_t H264BitReader::NumEmulationPreventionBytesRead() { 118 size_t H264BitReader::NumEmulationPreventionBytesRead() {
119 return emulation_prevention_bytes_; 119 return emulation_prevention_bytes_;
120 } 120 }
121 121
122 } // namespace media 122 } // namespace media
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698