From patchwork Tue Nov 27 12:16:55 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Fu, Linjie" X-Patchwork-Id: 11183 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id 745AE44DC77 for ; Tue, 27 Nov 2018 14:17:08 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E1D0368A3B5; Tue, 27 Nov 2018 14:17:08 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga12.intel.com (mga12.intel.com [192.55.52.136]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1F7D768A391 for ; Tue, 27 Nov 2018 14:17:01 +0200 (EET) X-Amp-Result: SKIPPED(no attachment in message) X-Amp-File-Uploaded: False Received: from fmsmga008.fm.intel.com ([10.253.24.58]) by fmsmga106.fm.intel.com with ESMTP/TLS/DHE-RSA-AES256-GCM-SHA384; 27 Nov 2018 04:17:05 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.56,286,1539673200"; d="scan'208";a="93366087" Received: from kubernetes-master.sh.intel.com ([10.239.159.155]) by fmsmga008.fm.intel.com with ESMTP; 27 Nov 2018 04:17:05 -0800 From: Linjie Fu To: ffmpeg-devel@ffmpeg.org Date: Tue, 27 Nov 2018 20:16:55 +0800 Message-Id: <20181127121655.1973-1-linjie.fu@intel.com> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH] lavc/hevc_parser: add 4 bytes startcode condition in hevc_find_frame_end X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.20 Precedence: list List-Id: FFmpeg development discussions and patches List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Reply-To: FFmpeg development discussions and patches Cc: Linjie Fu MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" The startcode before VPS,SPS,PPS and the first NALU in an AU is 4 bytes. Blindly taking the startcode as 3 bytes will leave 0x00 in last packet and may lead to some warnings in parse_nal_units when s->flags is set to PARSER_FLAG_COMPLETE_FRAMES. Add 4 bytes startcode condition in hevc_find_frame_end. Modify the code to print the buf_size like in H264 and reduce the duplication. Signed-off-by: Linjie Fu --- libavcodec/hevc_parser.c | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/libavcodec/hevc_parser.c b/libavcodec/hevc_parser.c index 369d1338d0..aa216e3c8d 100644 --- a/libavcodec/hevc_parser.c +++ b/libavcodec/hevc_parser.c @@ -32,6 +32,7 @@ #include "parser.h" #define START_CODE 0x000001 ///< start_code_prefix_one_3bytes +#define START_CODE_4 0x00000001 ///< start_code_4bytes #define IS_IRAP_NAL(nal) (nal->type >= 16 && nal->type <= 23) #define IS_IDR_NAL(nal) (nal->type == HEVC_NAL_IDR_W_RADL || nal->type == HEVC_NAL_IDR_N_LP) @@ -239,7 +240,7 @@ static int parse_nal_units(AVCodecParserContext *s, const uint8_t *buf, } } /* didn't find a picture! */ - av_log(avctx, AV_LOG_ERROR, "missing picture in access unit\n"); + av_log(avctx, AV_LOG_ERROR, "missing picture in access unit with size %d\n", buf_size); return -1; } @@ -267,8 +268,7 @@ static int hevc_find_frame_end(AVCodecParserContext *s, const uint8_t *buf, if ((nut >= HEVC_NAL_VPS && nut <= HEVC_NAL_EOB_NUT) || nut == HEVC_NAL_SEI_PREFIX || (nut >= 41 && nut <= 44) || (nut >= 48 && nut <= 55)) { if (pc->frame_start_found) { - pc->frame_start_found = 0; - return i - 5; + goto found; } } else if (nut <= HEVC_NAL_RASL_R || (nut >= HEVC_NAL_BLA_W_LP && nut <= HEVC_NAL_CRA_NUT)) { @@ -277,14 +277,19 @@ static int hevc_find_frame_end(AVCodecParserContext *s, const uint8_t *buf, if (!pc->frame_start_found) { pc->frame_start_found = 1; } else { // First slice of next frame found - pc->frame_start_found = 0; - return i - 5; + goto found; } } } } return END_NOT_FOUND; + +found: + pc->frame_start_found = 0; + if (((pc->state64 >> 3 * 8) & 0xFFFFFFFF) == START_CODE_4) + return i - 6; + return i - 5; } static int hevc_parse(AVCodecParserContext *s, AVCodecContext *avctx,