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

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: Update bitstream converter as well. Created 4 years, 10 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
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..7437e1ad0185cddafd15a91d1899914a7d452c3b 100644
--- a/media/filters/h264_bit_reader.cc
+++ b/media/filters/h264_bit_reader.cc
@@ -90,20 +90,31 @@ 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;
+ // If there are remaining non-zero bytes, then there is more data. We don't
+ // handle emulation prevention sequences because it is non-sensical to use
+ // them when there is no data. (At least for PPS NAL units, which is the only
Pawel Osciak 2016/03/01 08:56:21 I would perhaps remove the comment in parenthesis,
sandersd (OOO until July 31) 2016/03/17 19:07:51 Done.
+ // case currently considered.)
+ if (bytes_left_) {
Pawel Osciak 2016/03/01 08:56:21 This if could be dropped?
sandersd (OOO until July 31) 2016/03/17 19:07:51 Done.
+ for (off_t i = 0; i < bytes_left_; i++) {
+ if (data_[i] != 0)
+ return true;
+ }
+ }
+
+ bytes_left_ = 0;
+ return false;
}
size_t H264BitReader::NumEmulationPreventionBytesRead() {

Powered by Google App Engine
This is Rietveld 408576698