From 04ed61b1004282a632cdc1277d93183e15a8df93 Mon Sep 17 00:00:00 2001 From: Martin Storsjo Date: Wed, 7 Aug 2013 14:57:20 +0300 Subject: avcenc: Only do startcode escaping if the next byte requires it Section 7.4.1 in the H.264 standard says that the only valid bytes to follow a sequence that starts with 0x000003 are 0x00, 0x01, 0x02 or 0x03. This makes EncodeDecodeTest pass properly when decoding using OMX.google.h264.decoder, which is strict about the forbidden escape sequences. Change-Id: Ice113d9b934015003ea9cb10d0b21cee4d18d774 --- media/libstagefright/codecs/avc/enc/src/bitstream_io.cpp | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) (limited to 'media/libstagefright') diff --git a/media/libstagefright/codecs/avc/enc/src/bitstream_io.cpp b/media/libstagefright/codecs/avc/enc/src/bitstream_io.cpp index 0e3037f..d71c327 100644 --- a/media/libstagefright/codecs/avc/enc/src/bitstream_io.cpp +++ b/media/libstagefright/codecs/avc/enc/src/bitstream_io.cpp @@ -103,6 +103,15 @@ AVCEnc_Status AVCBitstreamSaveWord(AVCEncBitstream *stream) { num_bits -= 8; byte = (current_word >> num_bits) & 0xFF; + if (stream->count_zeros == 2) + { /* for num_bits = 32, this can add 2 more bytes extra for EPBS */ + if (byte <= 3) + { + *write_pnt++ = 0x3; + stream->write_pos++; + stream->count_zeros = 0; + } + } if (byte != 0) { *write_pnt++ = byte; @@ -114,12 +123,6 @@ AVCEnc_Status AVCBitstreamSaveWord(AVCEncBitstream *stream) stream->count_zeros++; *write_pnt++ = byte; stream->write_pos++; - if (stream->count_zeros == 2) - { /* for num_bits = 32, this can add 2 more bytes extra for EPBS */ - *write_pnt++ = 0x3; - stream->write_pos++; - stream->count_zeros = 0; - } } } -- cgit v1.1