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

Side by Side Diff: content/common/gpu/media/h264_bit_reader.cc

Issue 10843057: Fix a bug that H264BitReader::ReadBits cannot read more than 16 bits. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 8 years, 4 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 (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 "content/common/gpu/media/h264_bit_reader.h" 5 #include "content/common/gpu/media/h264_bit_reader.h"
6 #include "base/logging.h" 6 #include "base/logging.h"
7 7
8 namespace content { 8 namespace content {
9 9
10 H264BitReader::H264BitReader() 10 H264BitReader::H264BitReader()
(...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 // Read |num_bits| (1 to 31 inclusive) from the stream and return them 59 // Read |num_bits| (1 to 31 inclusive) from the stream and return them
60 // in |out|, with first bit in the stream as MSB in |out| at position 60 // in |out|, with first bit in the stream as MSB in |out| at position
61 // (|num_bits| - 1). 61 // (|num_bits| - 1).
62 bool H264BitReader::ReadBits(int num_bits, int *out) { 62 bool H264BitReader::ReadBits(int num_bits, int *out) {
63 int bits_left = num_bits; 63 int bits_left = num_bits;
64 *out = 0; 64 *out = 0;
65 DCHECK(num_bits <= 31); 65 DCHECK(num_bits <= 31);
66 66
67 while (num_remaining_bits_in_curr_byte_ < bits_left) { 67 while (num_remaining_bits_in_curr_byte_ < bits_left) {
68 // Take all that's left in current byte, shift to make space for the rest. 68 // Take all that's left in current byte, shift to make space for the rest.
69 *out = (curr_byte_ << (bits_left - num_remaining_bits_in_curr_byte_)); 69 *out |= (curr_byte_ << (bits_left - num_remaining_bits_in_curr_byte_));
70 bits_left -= num_remaining_bits_in_curr_byte_; 70 bits_left -= num_remaining_bits_in_curr_byte_;
71 71
72 if (!UpdateCurrByte()) 72 if (!UpdateCurrByte())
73 return false; 73 return false;
74 } 74 }
75 75
76 *out |= (curr_byte_ >> (num_remaining_bits_in_curr_byte_ - bits_left)); 76 *out |= (curr_byte_ >> (num_remaining_bits_in_curr_byte_ - bits_left));
77 *out &= ((1 << num_bits) - 1); 77 *out &= ((1 << num_bits) - 1);
78 num_remaining_bits_in_curr_byte_ -= bits_left; 78 num_remaining_bits_in_curr_byte_ -= bits_left;
79 79
(...skipping 15 matching lines...) Expand all
95 return true; 95 return true;
96 96
97 // Last byte, look for stop bit; 97 // Last byte, look for stop bit;
98 // We have more RBSP data if the last non-zero bit we find is not the 98 // We have more RBSP data if the last non-zero bit we find is not the
99 // first available bit. 99 // first available bit.
100 return (curr_byte_ & 100 return (curr_byte_ &
101 ((1 << (num_remaining_bits_in_curr_byte_ - 1)) - 1)) != 0; 101 ((1 << (num_remaining_bits_in_curr_byte_ - 1)) - 1)) != 0;
102 } 102 }
103 103
104 } // namespace content 104 } // namespace content
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