From patchwork Fri Dec 3 08:09:20 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Fei Wang X-Patchwork-Id: 31905 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:cd86:0:0:0:0:0 with SMTP id d128csp358524iog; Fri, 3 Dec 2021 00:12:31 -0800 (PST) X-Google-Smtp-Source: ABdhPJwRxMSUHgIk9A80aBkTy3+sBu5yJHZlod+KHVi/tH0qOpb8RcaNd71DmbWVhGXZ+Fuz/xfg X-Received: by 2002:a17:907:a426:: with SMTP id sg38mr21904787ejc.392.1638519151309; Fri, 03 Dec 2021 00:12:31 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1638519151; cv=none; d=google.com; s=arc-20160816; b=Ju/T99RXi81Mou4X9PT6EkmLHgIxESIjqofJn2fAzLN72Qej2N+/KEvmuq+7McJIEt 8uPjgEfdR8G+FbjkxxP7xtfsOQKMgE/4ctw4FZIGpUCTmMxa0WITGBNcNKmsyy2E+/da oB4SsHwv88jDsmOuQmwqTMWvOPLACEU4q5BPBVAL1htH8mGW2L3aLvr8nsqX+zTXr0/X i+n/G4hZRH6KhbHzB8FybX1P7XgnQZ6qDlV3VHN8oucIoRWswliy1AGmt8Py+KgPY4l/ fuZHZUXlCo+03uYeGmFzjy0qOGcD/CD3RLTVRgb0XuJgBjCwiUETHD5PYhwUsF7WOGbZ 1HdA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:mime-version:message-id:date:to:from :delivered-to; bh=qetI3+PHp2WhvJBc6Fa4JVmneMWjnG4ROMTKLAjcKac=; b=n7m+iuyCVN95A/bHXypAzHbGXJbfLXJczZGEh/ydCxAoUC9Ce05ESkHWy4FCMtZXb6 2VNUJeWRR/hD1p9IWP6ifbeNB4mvNADDaEGoFNypAyg4zrvpLG9DcH3Ay+P/BpRZ145j TWvOssyhFnaerPJyi3vSMz0zdiOobC2/aEyfI6K9ibtnS3N8EQVO0kvvx07DkHeEzoZk nMTeKopUBeLbEYcAGSQQVlDb0/iKYcFwlJ607PkUI6Ym4IhVSRlLYqJttf33G/ccYogY zsYguno92rTLgnldaX7mh/D4DTK+aG05pMQ45s3TuBbznKv4xWwU2mFcdBMoauKlQTZD aqbQ== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id h11si4643982ede.214.2021.12.03.00.12.30; Fri, 03 Dec 2021 00:12:31 -0800 (PST) Received-SPF: pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) client-ip=79.124.17.100; Authentication-Results: mx.google.com; spf=pass (google.com: domain of ffmpeg-devel-bounces@ffmpeg.org designates 79.124.17.100 as permitted sender) smtp.mailfrom=ffmpeg-devel-bounces@ffmpeg.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=intel.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 265076802C3; Fri, 3 Dec 2021 10:12:27 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mga18.intel.com (mga18.intel.com [134.134.136.126]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 7555E6802C3 for ; Fri, 3 Dec 2021 10:12:20 +0200 (EET) X-IronPort-AV: E=McAfee;i="6200,9189,10186"; a="223809663" X-IronPort-AV: E=Sophos;i="5.87,283,1631602800"; d="scan'208";a="223809663" Received: from orsmga007.jf.intel.com ([10.7.209.58]) by orsmga106.jf.intel.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 03 Dec 2021 00:12:17 -0800 X-ExtLoop1: 1 X-IronPort-AV: E=Sophos;i="5.87,283,1631602800"; d="scan'208";a="501104471" Received: from t.sh.intel.com ([10.239.159.147]) by orsmga007.jf.intel.com with ESMTP; 03 Dec 2021 00:12:17 -0800 From: Fei Wang To: ffmpeg-devel@ffmpeg.org Date: Fri, 3 Dec 2021 16:09:20 +0800 Message-Id: <20211203080920.1948453-1-fei.w.wang@intel.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v1] avcodec/av1_parser: ensure only one show frame packed data parsered X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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: Fei Wang Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: YXueR0zabV0E Split packed data when it contains multiple show frames in some non-standard bitstream. This can benefit downstream decoder which can decode continuously instead of interrupt with unexpected error. Signed-off-by: Fei Wang --- libavcodec/av1_parser.c | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/libavcodec/av1_parser.c b/libavcodec/av1_parser.c index d2dfdb3580..d6f5cace4b 100644 --- a/libavcodec/av1_parser.c +++ b/libavcodec/av1_parser.c @@ -59,11 +59,10 @@ static int av1_parser_parse(AVCodecParserContext *ctx, const CodedBitstreamAV1Context *av1 = s->cbc->priv_data; const AV1RawSequenceHeader *seq; const AV1RawColorConfig *color; + int pic_found = 0; + int next = 0; int ret; - *out_data = data; - *out_size = size; - ctx->key_frame = -1; ctx->pict_type = AV_PICTURE_TYPE_NONE; ctx->picture_structure = AV_PICTURE_STRUCTURE_UNKNOWN; @@ -100,6 +99,8 @@ static int av1_parser_parse(AVCodecParserContext *ctx, const AV1RawOBU *obu = unit->content; const AV1RawFrameHeader *frame; + next += unit->data_size; + if (unit->type == AV1_OBU_FRAME) frame = &obu->obu.frame.header; else if (unit->type == AV1_OBU_FRAME_HEADER) @@ -113,6 +114,12 @@ static int av1_parser_parse(AVCodecParserContext *ctx, if (!frame->show_frame && !frame->show_existing_frame) continue; + /* split data if it contains multi show frames */ + if (pic_found) { + next -= unit->data_size; + break; + } + ctx->width = frame->frame_width_minus_1 + 1; ctx->height = frame->frame_height_minus_1 + 1; @@ -131,8 +138,12 @@ static int av1_parser_parse(AVCodecParserContext *ctx, break; } ctx->picture_structure = AV_PICTURE_STRUCTURE_FRAME; + pic_found = 1; } + *out_size = next; + *out_data = data; + switch (av1->bit_depth) { case 8: ctx->format = color->mono_chrome ? AV_PIX_FMT_GRAY8 @@ -171,7 +182,7 @@ end: s->cbc->log_ctx = NULL; - return size; + return next; } static const CodedBitstreamUnitType decompose_unit_types[] = {