From patchwork Sat Mar 25 02:13:29 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 3092 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.50.79 with SMTP id y76csp350277vsy; Fri, 24 Mar 2017 19:13:58 -0700 (PDT) X-Received: by 10.223.147.98 with SMTP id 89mr4275330wro.99.1490408038646; Fri, 24 Mar 2017 19:13:58 -0700 (PDT) Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 3si5758202wrd.272.2017.03.24.19.13.58; Fri, 24 Mar 2017 19:13:58 -0700 (PDT) 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; dkim=neutral (body hash did not verify) header.i=@gmail.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=gmail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 94FB068972F; Sat, 25 Mar 2017 04:13:34 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk0-f196.google.com (mail-qk0-f196.google.com [209.85.220.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8739F689224 for ; Sat, 25 Mar 2017 04:13:28 +0200 (EET) Received: by mail-qk0-f196.google.com with SMTP id v127so969076qkb.1 for ; Fri, 24 Mar 2017 19:13:49 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=PisduTEvLwbtIblWMMXgwSP9xrfr43wA5rSGgoXnPbo=; b=QAEYI/SZYQylAi7T7ZyTkIhOic+xk52dD9pWhX7e8kK0majQD6/huHpQysHPKvVczz 5rMKwxkLA6akTyfSbHIL/zPiLzkDnqgnoVEY9rSruvqKbawrP8eMurDoty2dsQRK409I Gb1XoEOeKmHp6C3T6DBAa1HT4uIsT4zMnGlKQUf0KSoQJMMk/11ExMO0Xi/EPhikYZLO 3tkkvsXzDuIALNufUBn/4A2Mc5AJgdL1AmZlRi8MBrKuNyVfWH1K1DYCOiIdJlxgj46o AtEGvedwSsCFD5dRyeBN0Fflk9Tw8YTaen0V0UCdnHDgLzrCp7ZubSfMfeqzW7muronZ ehPA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=PisduTEvLwbtIblWMMXgwSP9xrfr43wA5rSGgoXnPbo=; b=Z1/f7MVRnppjszC+Y9zVVP9dnoJB4livIjeiLohGt7kAaC0Cz8yn+6beq602qXbFhE YtNlEGDA+oYXMF0cf6xTfOttME1F++bIZjxe75ufRMxW8hMqIvG/y8w+zU8Je6azalw8 sjCUxm+rheROCgq0Dg4pqRHRl/SxOxORdGzGl5IzUYMnOEEW+Y0S0lHOrhJYIGVNNa/x Ax8aymX4pHlGIM1iqdDzzDvn3YiBiwR29XRDqoiZVLjFTj9tVxt0c3JKT+CYiib0By0b UiIA+vmHZdxwTfiu6KAjGXOVntnzyoMSv4vCWMYjFWdJZlafV590kngiG8/D15aqZMpW +Zvg== X-Gm-Message-State: AFeK/H3uGX1QAbDa2xsjTdHAiIFYGF0paq4fD0PFwpHIvNQDiOKgYPOUjD3kBRNkKizF8Q== X-Received: by 10.55.56.131 with SMTP id f125mr11059154qka.203.1490408027991; Fri, 24 Mar 2017 19:13:47 -0700 (PDT) Received: from localhost.localdomain ([181.231.62.139]) by smtp.gmail.com with ESMTPSA id v4sm2772078qtg.0.2017.03.24.19.13.46 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 24 Mar 2017 19:13:47 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 24 Mar 2017 23:13:29 -0300 Message-Id: <20170325021329.3232-1-jamrial@gmail.com> X-Mailer: git-send-email 2.12.0 In-Reply-To: <20170324223147.2692-1-jamrial@gmail.com> References: <20170324223147.2692-1-jamrial@gmail.com> Subject: [FFmpeg-devel] [PATCH] avcodec/extract_extradata_bsf: make sure parameter set NAL units were found for h264/hevc 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: James Almer --- This is an actual fix for the existing parsing code instead of a copy of the AVCodecParser code, as an alternative to patches 2 and 3 of this set. Five FATE tests will have to be updated with patch 6 if this is applied, as this parsing code filters unnecessary NAL units and that's reflected in the extradata size and checksum output of framecrc during codec copy. They are: fate-copy-trac2211-avi fate-h264_mp4toannexb_ticket2991 fate-h264_mp4toannexb_ticket5927 fate-h264_mp4toannexb_ticket5927_2 fate-segment-mp4-to-ts libavcodec/extract_extradata_bsf.c | 15 ++++++++++++--- 1 file changed, 12 insertions(+), 3 deletions(-) diff --git a/libavcodec/extract_extradata_bsf.c b/libavcodec/extract_extradata_bsf.c index d909ee6d17..af666574a3 100644 --- a/libavcodec/extract_extradata_bsf.c +++ b/libavcodec/extract_extradata_bsf.c @@ -65,7 +65,7 @@ static int extract_extradata_h2645(AVBSFContext *ctx, AVPacket *pkt, int extradata_size = 0; const int *extradata_nal_types; int nb_extradata_nal_types; - int i, ret = 0; + int i, has_sps = 0, has_vps = 0, ret = 0; if (ctx->par_in->codec_id == AV_CODEC_ID_HEVC) { extradata_nal_types = extradata_nal_types_hevc; @@ -82,11 +82,20 @@ static int extract_extradata_h2645(AVBSFContext *ctx, AVPacket *pkt, for (i = 0; i < h2645_pkt.nb_nals; i++) { H2645NAL *nal = &h2645_pkt.nals[i]; - if (val_in_array(extradata_nal_types, nb_extradata_nal_types, nal->type)) + if (val_in_array(extradata_nal_types, nb_extradata_nal_types, nal->type)) { extradata_size += nal->raw_size + 3; + if (ctx->par_in->codec_id == AV_CODEC_ID_HEVC) { + if (nal->type == HEVC_NAL_SPS) has_sps = 1; + if (nal->type == HEVC_NAL_VPS) has_vps = 1; + } else { + if (nal->type == H264_NAL_SPS) has_sps = 1; + } + } } - if (extradata_size) { + if (extradata_size && + ((ctx->par_in->codec_id == AV_CODEC_ID_HEVC && has_sps && has_vps) || + (ctx->par_in->codec_id == AV_CODEC_ID_H264 && has_sps))) { AVBufferRef *filtered_buf; uint8_t *extradata, *filtered_data;