OLD | NEW |
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 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 num_remaining_bits_in_curr_byte_ -= bits_left; | 83 num_remaining_bits_in_curr_byte_ -= bits_left; |
84 | 84 |
85 return true; | 85 return true; |
86 } | 86 } |
87 | 87 |
88 off_t H264BitReader::NumBitsLeft() { | 88 off_t H264BitReader::NumBitsLeft() { |
89 return (num_remaining_bits_in_curr_byte_ + bytes_left_ * 8); | 89 return (num_remaining_bits_in_curr_byte_ + bytes_left_ * 8); |
90 } | 90 } |
91 | 91 |
92 bool H264BitReader::HasMoreRBSPData() { | 92 bool H264BitReader::HasMoreRBSPData() { |
93 // 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 and |
94 // and updating current byte fails, we don't have more data anyway. | 94 // updating current byte fails, we don't have more data anyway. |
95 if (num_remaining_bits_in_curr_byte_ == 0 && !UpdateCurrByte()) | 95 if (num_remaining_bits_in_curr_byte_ == 0 && !UpdateCurrByte()) |
96 return false; | 96 return false; |
97 | 97 |
98 // On last byte? | 98 // If there is no more RBSP data, then |curr_byte_| contains the stop bit and |
99 if (bytes_left_) | 99 // zero padding. Check to see if there is other data instead. |
| 100 // (We don't actually check for the stop bit itself, instead treating the |
| 101 // invalid case of all trailing zeros identically). |
| 102 if ((curr_byte_ & ((1 << (num_remaining_bits_in_curr_byte_ - 1)) - 1)) != 0) |
100 return true; | 103 return true; |
101 | 104 |
102 // Last byte, look for stop bit; | 105 // While the spec disallows it (7.4.1: "The last byte of the NAL unit shall |
103 // We have more RBSP data if the last non-zero bit we find is not the | 106 // not be equal to 0x00"), some streams have trailing null bytes anyway. We |
104 // first available bit. | 107 // don't handle emulation prevention sequences because HasMoreRBSPData() is |
105 return (curr_byte_ & | 108 // not used when parsing slices (where cabac_zero_word elements are legal). |
106 ((1 << (num_remaining_bits_in_curr_byte_ - 1)) - 1)) != 0; | 109 for (off_t i = 0; i < bytes_left_; i++) { |
| 110 if (data_[i] != 0) |
| 111 return true; |
| 112 } |
| 113 |
| 114 bytes_left_ = 0; |
| 115 return false; |
107 } | 116 } |
108 | 117 |
109 size_t H264BitReader::NumEmulationPreventionBytesRead() { | 118 size_t H264BitReader::NumEmulationPreventionBytesRead() { |
110 return emulation_prevention_bytes_; | 119 return emulation_prevention_bytes_; |
111 } | 120 } |
112 | 121 |
113 } // namespace media | 122 } // namespace media |
OLD | NEW |