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

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: Fix up comments. Created 8 years, 5 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: 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..96f28ca0d3e1a57d7b20d10de34bf9c4b603ef72 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,31 @@ 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();
+ // Return the number of bits left in the stream. This includes the
+ // stop bit and any trailing zero byte.
Ami GONE FROM CHROMIUM 2012/08/01 23:04:00 Why is this API reasonable, given that these bits
xiaomings 2012/08/01 23:39:54 This is actually used in h264_parser.cc:1081 for c
+ off_t NumBitsLeft() const;
// See the definition of more_rbsp_data() in spec.
- bool HasMoreRBSPData();
+ bool HasMoreRBSPData() const;
Ami GONE FROM CHROMIUM 2012/08/01 23:04:00 This name no longer makes as much sense since you'
xiaomings 2012/08/01 23:39:54 Removed. On 2012/08/01 23:04:00, Ami Fischman wro
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 +77,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, this doesn't take stop bit and
+ // trailing zero bits into account. It can never be 0.
Ami GONE FROM CHROMIUM 2012/08/01 23:04:00 "this doesn't take ... into account" is pretty con
xiaomings 2012/08/01 23:39:54 Modified. On 2012/08/01 23:04:00, Ami Fischman wr
+ 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') | content/common/gpu/media/h264_bit_reader.cc » ('J')

Powered by Google App Engine
This is Rietveld 408576698