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

Unified Diff: content/common/gpu/media/h264_bit_reader.h

Issue 10837058: Make H264BitReader ignore trailing zero bytes and stop bit. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add back tests after merge from master. Created 8 years, 3 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 | content/common/gpu/media/h264_bit_reader.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/common/gpu/media/h264_bit_reader.h
diff --git a/content/common/gpu/media/h264_bit_reader.h b/content/common/gpu/media/h264_bit_reader.h
index c43b6f774ecee53d1df9f2f7bd37a29e538ff566..a72dd1f871427139b460716757036c11122138c7 100644
--- a/content/common/gpu/media/h264_bit_reader.h
+++ b/content/common/gpu/media/h264_bit_reader.h
@@ -16,8 +16,13 @@ namespace content {
// A class to provide bit-granularity reading of H.264 streams.
// This is not a generic bit reader class, as it takes into account
-// H.264 stream-specific constraints, such as skipping emulation-prevention
-// bytes and stop bits. See spec for more details.
+// H.264 stream-specific constraints:
+// - Skipping emulation-prevention bytes, i.e. any byte aligned sequence
+// 0x00 0x00 0x03 will be replaced by 0x00 0x00.
+// - Ignore trailing zero bytes/bits, i.e. any consecutive zero bytes/bits at
+// the end of the stream will be ignored.
+// - Ignore stop bit, i.e. the last non-zero bit will be ignored.
+// See ISO 14496 Part 10 - 7.3 for more details.
class CONTENT_EXPORT H264BitReader {
public:
H264BitReader();
@@ -30,24 +35,28 @@ class CONTENT_EXPORT H264BitReader {
// heap-allocating and creating bit readers on demand instead.
bool Initialize(const uint8* data, off_t size);
- // Read |num_bits| next bits from stream and return in |*out|, first bit
- // from the stream starting at |num_bits| position in |*out|.
- // |num_bits| may be 1-32, inclusive.
+ // Read |num_bits| (1 to 31 inclusive) from the stream and return them
+ // in |*out|, with first bit in the stream as MSB in |*out| at position
+ // (|num_bits| - 1).
// Return false if the given number of bits cannot be read (not enough
// bits in the stream), true otherwise.
bool ReadBits(int num_bits, int *out);
- // Return the number of bits left in the stream.
- off_t NumBitsLeft();
-
- // See the definition of more_rbsp_data() in spec.
- bool HasMoreRBSPData();
+ // Return the number of bits left in the stream. This includes the
+ // stop bit and any trailing zero bytes.
+ off_t NumBitsLeft() const;
private:
// Advance to the next byte, loading it into curr_byte_.
// Return false on end of stream.
bool UpdateCurrByte();
+ // Remove the trailing zero bits if there are any. The trailing zero bits
+ // can spread among more than byte. Then remove the stop bit. So the bit
+ // stream 11001100 00000000 will become 11001.
+ // It returns true if there are still data bits left.
+ bool RemoveTrailingZeroAndStopBit();
+
// Pointer to the next unread (not in curr_byte_) byte in the stream.
const uint8* data_;
@@ -65,6 +74,13 @@ class CONTENT_EXPORT H264BitReader {
// Initially set to 0xffff to accept all initial two-byte sequences.
int prev_two_bytes_;
+ // Save the number of trailing zero bytes to be used in NumBitsLeft.
+ int trailing_zero_bytes_;
+
+ // The valid data bits in the last byte, excluding stop bit and trailing
+ // zero bits. It can never be 0.
+ int data_bits_in_last_byte_;
+
DISALLOW_COPY_AND_ASSIGN(H264BitReader);
};
« no previous file with comments | « no previous file | content/common/gpu/media/h264_bit_reader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698