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

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

Issue 119153002: Move H264Parser and H264BitReader to media/filters. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 11 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 | Annotate | Revision Log
« no previous file with comments | « media/filters/h264_bit_reader.h ('k') | media/filters/h264_bit_reader_unittest.cc » ('j') | 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"
6 #include "base/logging.h" 5 #include "base/logging.h"
6 #include "media/filters/h264_bit_reader.h"
7 7
8 namespace content { 8 namespace media {
9 9
10 H264BitReader::H264BitReader() 10 H264BitReader::H264BitReader()
11 : data_(NULL), bytes_left_(0), curr_byte_(0), 11 : data_(NULL),
12 num_remaining_bits_in_curr_byte_(0), prev_two_bytes_(0), 12 bytes_left_(0),
13 emulation_prevention_bytes_(0) { 13 curr_byte_(0),
14 } 14 num_remaining_bits_in_curr_byte_(0),
15 prev_two_bytes_(0),
16 emulation_prevention_bytes_(0) {}
15 17
16 H264BitReader::~H264BitReader() {} 18 H264BitReader::~H264BitReader() {}
17 19
18 bool H264BitReader::Initialize(const uint8* data, off_t size) { 20 bool H264BitReader::Initialize(const uint8* data, off_t size) {
19 DCHECK(data); 21 DCHECK(data);
20 22
21 if (size < 1) 23 if (size < 1)
22 return false; 24 return false;
23 25
24 data_ = data; 26 data_ = data;
(...skipping 30 matching lines...) Expand all
55 num_remaining_bits_in_curr_byte_ = 8; 57 num_remaining_bits_in_curr_byte_ = 8;
56 58
57 prev_two_bytes_ = (prev_two_bytes_ << 8) | curr_byte_; 59 prev_two_bytes_ = (prev_two_bytes_ << 8) | curr_byte_;
58 60
59 return true; 61 return true;
60 } 62 }
61 63
62 // 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
63 // 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
64 // (|num_bits| - 1). 66 // (|num_bits| - 1).
65 bool H264BitReader::ReadBits(int num_bits, int *out) { 67 bool H264BitReader::ReadBits(int num_bits, int* out) {
66 int bits_left = num_bits; 68 int bits_left = num_bits;
67 *out = 0; 69 *out = 0;
68 DCHECK(num_bits <= 31); 70 DCHECK(num_bits <= 31);
69 71
70 while (num_remaining_bits_in_curr_byte_ < bits_left) { 72 while (num_remaining_bits_in_curr_byte_ < bits_left) {
71 // Take all that's left in current byte, shift to make space for the rest. 73 // Take all that's left in current byte, shift to make space for the rest.
72 *out |= (curr_byte_ << (bits_left - num_remaining_bits_in_curr_byte_)); 74 *out |= (curr_byte_ << (bits_left - num_remaining_bits_in_curr_byte_));
73 bits_left -= num_remaining_bits_in_curr_byte_; 75 bits_left -= num_remaining_bits_in_curr_byte_;
74 76
75 if (!UpdateCurrByte()) 77 if (!UpdateCurrByte())
76 return false; 78 return false;
77 } 79 }
78 80
79 *out |= (curr_byte_ >> (num_remaining_bits_in_curr_byte_ - bits_left)); 81 *out |= (curr_byte_ >> (num_remaining_bits_in_curr_byte_ - bits_left));
80 *out &= ((1 << num_bits) - 1); 82 *out &= ((1 << num_bits) - 1);
81 num_remaining_bits_in_curr_byte_ -= bits_left; 83 num_remaining_bits_in_curr_byte_ -= bits_left;
82 84
83 return true; 85 return true;
84 } 86 }
85 87
86 off_t H264BitReader::NumBitsLeft() { 88 off_t H264BitReader::NumBitsLeft() {
87 return (num_remaining_bits_in_curr_byte_ + bytes_left_ * 8); 89 return (num_remaining_bits_in_curr_byte_ + bytes_left_ * 8);
88 } 90 }
89 91
90 bool H264BitReader::HasMoreRBSPData() { 92 bool H264BitReader::HasMoreRBSPData() {
91 // Make sure we have more bits, if we are at 0 bits in current byte 93 // Make sure we have more bits, if we are at 0 bits in current byte
92 // and updating current byte fails, we don't have more data anyway. 94 // and updating current byte fails, we don't have more data anyway.
93 if (num_remaining_bits_in_curr_byte_ == 0 && !UpdateCurrByte()) 95 if (num_remaining_bits_in_curr_byte_ == 0 && !UpdateCurrByte())
94 return false; 96 return false;
95 97
96 // On last byte? 98 // On last byte?
97 if (bytes_left_) 99 if (bytes_left_)
98 return true; 100 return true;
99 101
100 // Last byte, look for stop bit; 102 // Last byte, look for stop bit;
101 // We have more RBSP data if the last non-zero bit we find is not the 103 // We have more RBSP data if the last non-zero bit we find is not the
102 // first available bit. 104 // first available bit.
103 return (curr_byte_ & 105 return (curr_byte_ &
104 ((1 << (num_remaining_bits_in_curr_byte_ - 1)) - 1)) != 0; 106 ((1 << (num_remaining_bits_in_curr_byte_ - 1)) - 1)) != 0;
105 } 107 }
106 108
107 size_t H264BitReader::NumEmulationPreventionBytesRead() 109 size_t H264BitReader::NumEmulationPreventionBytesRead() {
108 {
109 return emulation_prevention_bytes_; 110 return emulation_prevention_bytes_;
110 } 111 }
111 112
112 } // namespace content 113 } // namespace media
OLDNEW
« no previous file with comments | « media/filters/h264_bit_reader.h ('k') | media/filters/h264_bit_reader_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698