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

Unified Diff: content/common/gpu/media/h264_parser.cc

Issue 10710002: Add HE AAC support to ISO BMFF. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add unittest for 5.1 channel. Created 8 years, 6 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_parser.cc
diff --git a/content/common/gpu/media/h264_parser.cc b/content/common/gpu/media/h264_parser.cc
index ace3dabed033c7991c6d747c35c8226b530a0541..912b877acdbeb32360656615d3ab6b10ca087234 100644
--- a/content/common/gpu/media/h264_parser.cc
+++ b/content/common/gpu/media/h264_parser.cc
@@ -50,101 +50,40 @@ H264SEIMessage::H264SEIMessage() {
memset(this, 0, sizeof(*this));
}
-H264Parser::H264BitReader::H264BitReader()
- : data_(NULL),
- bytes_left_(0),
- curr_byte_(0),
- num_remaining_bits_in_curr_byte_(0),
- prev_two_bytes_(0) {
+H264Parser::H264BitReader::H264BitReader() {
}
H264Parser::H264BitReader::~H264BitReader() {}
-bool H264Parser::H264BitReader::Initialize(const uint8* data, off_t size) {
- DCHECK(data);
-
- if (size < 1)
- return false;
-
- data_ = data;
- bytes_left_ = size;
- num_remaining_bits_in_curr_byte_ = 0;
- // Initially set to 0xffff to accept all initial two-byte sequences.
- prev_two_bytes_ = 0xffff;
-
- return true;
-}
-
-bool H264Parser::H264BitReader::UpdateCurrByte() {
- if (bytes_left_ < 1)
- return false;
+void H264Parser::H264BitReader::UpdateCurrByte() {
+ DCHECK_EQ(num_remaining_bits_in_curr_byte_, 0);
+
+ if (bytes_left_ >= 1) {
+ // Emulation prevention three-byte detection.
+ // If a sequence of 0x000003 is found, skip (ignore) the last byte (0x03).
+ if (*data_ == 0x03 && Tell() >= 16 && data_[-1] == 0 && data_[-2] == 0) {
+ // Detected 0x000003, skip last byte.
+ ++data_;
+ --bytes_left_;
+ position_ += 8;
+ }
+ }
- // Emulation prevention three-byte detection.
- // If a sequence of 0x000003 is found, skip (ignore) the last byte (0x03).
- if (*data_ == 0x03 && (prev_two_bytes_ & 0xffff) == 0) {
- // Detected 0x000003, skip last byte.
+ if (bytes_left_ >= 1) {
+ // Load a new byte and advance pointers.
+ curr_byte_ = *data_;
++data_;
--bytes_left_;
- // Need another full three bytes before we can detect the sequence again.
- prev_two_bytes_ = 0xffff;
-
- if (bytes_left_ < 1)
- return false;
+ num_remaining_bits_in_curr_byte_ = 8;
}
- // Load a new byte and advance pointers.
- curr_byte_ = *data_++ & 0xff;
- --bytes_left_;
- num_remaining_bits_in_curr_byte_ = 8;
-
- prev_two_bytes_ = (prev_two_bytes_ << 8) | curr_byte_;
-
- return true;
-}
-
-// 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).
-bool H264Parser::H264BitReader::ReadBits(int num_bits, int *out) {
- int bits_left = num_bits;
- *out = 0;
- DCHECK(num_bits <= 31);
-
- while (num_remaining_bits_in_curr_byte_ < bits_left) {
- // Take all that's left in current byte, shift to make space for the rest.
- *out = (curr_byte_ << (bits_left - num_remaining_bits_in_curr_byte_));
- bits_left -= num_remaining_bits_in_curr_byte_;
-
- if (!UpdateCurrByte())
- return false;
+ // Check if this is the end of RBSP data.
+ if (bytes_left_ == 0) {
+ while (num_remaining_bits_in_curr_byte_ != 0 && curr_byte_ % 2 == 0) {
acolwell GONE FROM CHROMIUM 2012/06/28 17:31:25 nit: Since we are dealing with bits I'd prefer !(c
+ --num_remaining_bits_in_curr_byte_;
+ curr_byte_ /= 2;
+ }
}
-
- *out |= (curr_byte_ >> (num_remaining_bits_in_curr_byte_ - bits_left));
- *out &= ((1 << num_bits) - 1);
- num_remaining_bits_in_curr_byte_ -= bits_left;
-
- return true;
-}
-
-off_t H264Parser::H264BitReader::NumBitsLeft() {
- return (num_remaining_bits_in_curr_byte_ + bytes_left_ * 8);
-}
-
-bool H264Parser::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.
- if (num_remaining_bits_in_curr_byte_ == 0 && !UpdateCurrByte())
- return false;
-
- // On last byte?
- if (bytes_left_)
- 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;
}
#define READ_BITS_OR_RETURN(num_bits, out) \
@@ -358,7 +297,9 @@ H264Parser::Result H264Parser::AdvanceToNextNALU(H264NALU *nalu) {
nalu->data = stream_ + off_to_nalu_start;
// Initialize bit reader at the start of found NALU.
- if (!br_.Initialize(nalu->data, nalu->size))
+ br_.Initialize(nalu->data, nalu->size);
+
+ if (!br_.HasMoreData())
return kEOStream;
DVLOG(4) << "Looking for NALU, Stream bytes left: " << bytes_left_
@@ -812,7 +753,7 @@ H264Parser::Result H264Parser::ParsePPS(int* pps_id) {
READ_BOOL_OR_RETURN(&pps->constrained_intra_pred_flag);
READ_BOOL_OR_RETURN(&pps->redundant_pic_cnt_present_flag);
- if (br_.HasMoreRBSPData()) {
+ if (br_.HasMoreData()) {
READ_BOOL_OR_RETURN(&pps->transform_8x8_mode_flag);
READ_BOOL_OR_RETURN(&pps->pic_scaling_matrix_present_flag);

Powered by Google App Engine
This is Rietveld 408576698