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

Unified Diff: media/filters/h264_bit_reader.cc

Issue 1107593004: Disregard trailing null bytes when locating RBSP stop bits. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 9 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | media/filters/h264_to_annex_b_bitstream_converter.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: media/filters/h264_bit_reader.cc
diff --git a/media/filters/h264_bit_reader.cc b/media/filters/h264_bit_reader.cc
index 8f7dda0324d7b05419bc26d66676074117aeb4a1..5b009a18281408ad4345e529e706de959a1bb5f8 100644
--- a/media/filters/h264_bit_reader.cc
+++ b/media/filters/h264_bit_reader.cc
@@ -90,20 +90,29 @@ off_t H264BitReader::NumBitsLeft() {
}
bool H264BitReader::HasMoreRBSPData() {
- // Make sure we have more bits, if we are at 0 bits in current byte
- // and updating current byte fails, we don't have more data anyway.
+ // Make sure we have more bits, if we are at 0 bits in current byte and
+ // updating current byte fails, we don't have more data anyway.
if (num_remaining_bits_in_curr_byte_ == 0 && !UpdateCurrByte())
return false;
- // On last byte?
- if (bytes_left_)
+ // If there is no more RBSP data, then |curr_byte_| contains the stop bit and
+ // zero padding. Check to see if there is other data instead.
+ // (We don't actually check for the stop bit itself, instead treating the
+ // invalid case of all trailing zeros identically).
+ if ((curr_byte_ & ((1 << (num_remaining_bits_in_curr_byte_ - 1)) - 1)) != 0)
return true;
- // Last byte, look for stop bit;
- // We have more RBSP data if the last non-zero bit we find is not the
- // first available bit.
- return (curr_byte_ &
- ((1 << (num_remaining_bits_in_curr_byte_ - 1)) - 1)) != 0;
+ // While the spec disallows it (7.4.1: "The last byte of the NAL unit shall
+ // not be equal to 0x00"), some streams have trailing null bytes anyway. We
+ // don't handle emulation prevention sequences because HasMoreRBSPData() is
+ // not used when parsing slices (where cabac_zero_word elements are legal).
+ for (off_t i = 0; i < bytes_left_; i++) {
+ if (data_[i] != 0)
+ return true;
+ }
+
+ bytes_left_ = 0;
+ return false;
}
size_t H264BitReader::NumEmulationPreventionBytesRead() {
« no previous file with comments | « no previous file | media/filters/h264_to_annex_b_bitstream_converter.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698