Fixed incorrect RBSP parsing. The original version would eat 0x3 as an emulation byte in places where it shouldn't, whereas the real parsing is only supposed to eat 0x3 preceded by 0x0 0x0.

Also, now that BitBuffer is getting a writer (https://webrtc-codereview.appspot.com/45259005/), I wrote a function that creates a fake SPS of a given resolution. The created SPS has an emulation 0x3 and a real 0x3, so it ensures the parser has the correct behavior.

BUG=
R=stefan@webrtc.org

Review URL: https://webrtc-codereview.appspot.com/44349004

Cr-Commit-Position: refs/heads/master@{#9108}
This commit is contained in:
Noah Richards
2015-04-28 17:55:36 -07:00
parent 86153c26a0
commit 97f13c5f7f
2 changed files with 108 additions and 2 deletions

View File

@ -32,10 +32,12 @@ bool H264SpsParser::Parse() {
const char* sps_bytes = reinterpret_cast<const char*>(sps_);
// First, parse out rbsp, which is basically the source buffer minus emulation
// bytes (0x03). RBSP is defined in section 7.3.1 of the H.264 standard.
// bytes (the last byte of a 0x00 0x00 0x03 sequence). RBSP is defined in
// section 7.3.1 of the H.264 standard.
rtc::ByteBuffer rbsp_buffer;
for (size_t i = 0; i < byte_length_;) {
if (i < byte_length_ - 3 && sps_[i + 3] == 3) {
if (i < byte_length_ - 3 &&
sps_[i] == 0 && sps_[i + 1] == 0 && sps_[i + 2] == 3) {
// Two rbsp bytes + the emulation byte.
rbsp_buffer.WriteBytes(sps_bytes + i, 2);
i += 3;