From d180aebb6bee4efdced23dd3fb46cadd69da426a Mon Sep 17 00:00:00 2001 From: Yandong Lin Date: Wed, 12 Jul 2023 15:03:52 +0800 Subject: [PATCH] [mpp_bitread]: add new type for sei payload parse The quantity of emulation prevention bytes is not included in the size payloadSize of an SEI payload. So add PSEUDO_CODE_H264_H265_SEI type for sei payload parse. Signed-off-by: Yandong Lin Change-Id: I92554de98ffca2f81785aa81b2f652099dbe6ae9 --- mpp/base/inc/mpp_bitread.h | 1 + mpp/base/mpp_bitread.c | 26 ++++++++++++++++++++++++++ 2 files changed, 27 insertions(+) diff --git a/mpp/base/inc/mpp_bitread.h b/mpp/base/inc/mpp_bitread.h index 538e21f3..ead014e1 100644 --- a/mpp/base/inc/mpp_bitread.h +++ b/mpp/base/inc/mpp_bitread.h @@ -96,6 +96,7 @@ typedef enum PseudoCodeType_e { PSEUDO_CODE_NONE = 0, PSEUDO_CODE_H264_H265, + PSEUDO_CODE_H264_H265_SEI, PSEUDO_CODE_AVS2, PSEUDO_CODE_BUT } PseudoCodeType; diff --git a/mpp/base/mpp_bitread.c b/mpp/base/mpp_bitread.c index afda2922..e5ec1f8e 100644 --- a/mpp/base/mpp_bitread.c +++ b/mpp/base/mpp_bitread.c @@ -63,6 +63,29 @@ static MPP_RET update_curbyte_h264(BitReadCtx_t *bitctx) return MPP_OK; } +static MPP_RET update_curbyte_h2645_sei(BitReadCtx_t *bitctx) +{ + if (bitctx->bytes_left_ < 1) + return MPP_ERR_READ_BIT; + + // Emulation prevention three-byte detection. + // If a sequence of 0x000003 is found, skip (ignore) the last byte (0x03). + if ((*bitctx->data_ == 0x03) + && ((bitctx->prev_two_bytes_ & 0xffff) == 0)) { + // Detected 0x000003, skip last byte. + ++bitctx->data_; + // Need another full three bytes before we can detect the sequence again. + bitctx->prev_two_bytes_ = 0xffff; + } + // Load a new byte and advance pointers. + bitctx->curr_byte_ = *bitctx->data_++ & 0xff; + --bitctx->bytes_left_; + bitctx->num_remaining_bits_in_curr_byte_ = 8; + bitctx->prev_two_bytes_ = (bitctx->prev_two_bytes_ << 8) | bitctx->curr_byte_; + + return MPP_OK; +} + static MPP_RET update_curbyte_avs2(BitReadCtx_t *bitctx) { if (bitctx->bytes_left_ < 1) @@ -320,6 +343,9 @@ void mpp_set_bitread_pseudo_code_type(BitReadCtx_t *bitctx, PseudoCodeType type) case PSEUDO_CODE_H264_H265: bitctx->update_curbyte = update_curbyte_h264; break; + case PSEUDO_CODE_H264_H265_SEI: + bitctx->update_curbyte = update_curbyte_h2645_sei; + break; case PSEUDO_CODE_AVS2: bitctx->update_curbyte = update_curbyte_avs2; break;