From patchwork Fri Mar 24 22:31:43 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 3085 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.103.50.79 with SMTP id y76csp293389vsy; Fri, 24 Mar 2017 15:32:59 -0700 (PDT) X-Received: by 10.28.61.11 with SMTP id k11mr5373824wma.119.1490394779452; Fri, 24 Mar 2017 15:32:59 -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 c8si4901594wmh.65.2017.03.24.15.32.59; Fri, 24 Mar 2017 15:32:59 -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 8CD6A6883D0; Sat, 25 Mar 2017 00:32:19 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk0-f194.google.com (mail-qk0-f194.google.com [209.85.220.194]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1D4C8688370 for ; Sat, 25 Mar 2017 00:32:12 +0200 (EET) Received: by mail-qk0-f194.google.com with SMTP id p22so543979qka.0 for ; Fri, 24 Mar 2017 15:32:32 -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=8afxBuor+qQWZLF6TfMdcwDA31w4MpaDU7BSBzm6vsg=; b=T2EoRi7qDsd8aE0zd9h5rZLzIMM2XGlweHvEF50ZT5oHZLkLJpqY8LTSES7ys3cyw1 ywYRnYiAmUopdPCgW1inHrHzboZm+8Br00VHzHIrflPx2cp9mZ2N0Mlkqup+VMjBjFh2 C+8zijc7gZpKQL91P5yWdi5hMeA1DDhxU5fWmSOPFf2V8nmPFHy9iH+JPdA433Rkutvc QFktjHasRepyha0e+78Yrubhe3cwK7wvQ3c59VJQ7he0ITx5MWhsZCGtbkaIokJEtbhv t4u/35P5GRuw+H5tc7E6qowMiK0QXn5xxtXzE9JrUnmXUIMlIyOWmeIa5koKYXI74Ust e8vA== 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=8afxBuor+qQWZLF6TfMdcwDA31w4MpaDU7BSBzm6vsg=; b=GRiC8ykCP+QcyBhEnhHjYSCuOgG/7BA/ltStnfSdlzup99CEEzyYAYf7VQffcoo7AT O9wgOjlqyQ6vipf9TrfoueDGZ+ABi2GSdnENK4k4cczRgOUxPOYeGPY+1WXZoH2exSIQ 7vidM9b5FWTTN4o3beQxZznf5JBOAtvnV5PFFeue92bBokYdKPBGpukt4roirUpVtmPB IKheZJAtxkeji4ruQ7neROh/bZSm6GjFifj9X98boyQrAb33TuqD9Xo9eB+MNP/uxRc1 ofWJYfTkLRlZw4lJ9GW4Z+VvNfsmOKTi4kaU2vrTtL7uW4OwyFXQem0D9mg4O/egUjmk Ug0w== X-Gm-Message-State: AFeK/H2/Hx1u3+O5Mg7mHTMo1+eUF4WKJgQhWK20Fz3IgGqZtl06h9MhE/ZtAo3SHBTIKw== X-Received: by 10.55.166.150 with SMTP id p144mr3403682qke.132.1490394751730; Fri, 24 Mar 2017 15:32:31 -0700 (PDT) Received: from localhost.localdomain ([181.231.62.139]) by smtp.gmail.com with ESMTPSA id e19sm2414824qta.68.2017.03.24.15.32.30 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-SHA bits=128/128); Fri, 24 Mar 2017 15:32:31 -0700 (PDT) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Fri, 24 Mar 2017 19:31:43 -0300 Message-Id: <20170324223147.2692-3-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 2/6] avcodec/extract_extradata_bsf: use the parsing code from h264_split() 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" The current code discards every non SPS/PPS NAL from extradata, which even if in theory they aren't needed there, some samples fail to decode without them, like "11159 HD-PVR sample.mpg". Signed-off-by: James Almer --- Someone who wants to look why those filtered NALs are needed by such samples, or if there's some problem in the ff_h2645_packet_split() based parsing code, would come in handy and be very welcome. libavcodec/extract_extradata_bsf.c | 66 ++++++++++++++++++++++++++++++-------- 1 file changed, 52 insertions(+), 14 deletions(-) diff --git a/libavcodec/extract_extradata_bsf.c b/libavcodec/extract_extradata_bsf.c index d909ee6d17..bb2e9bf68c 100644 --- a/libavcodec/extract_extradata_bsf.c +++ b/libavcodec/extract_extradata_bsf.c @@ -49,15 +49,58 @@ static int val_in_array(const int *arr, int len, int val) return 0; } -static int extract_extradata_h2645(AVBSFContext *ctx, AVPacket *pkt, - uint8_t **data, int *size) +static int extract_extradata_h264(AVBSFContext *ctx, AVPacket *pkt, + uint8_t **data, int *size) +{ + ExtractExtradataContext *s = ctx->priv_data; + uint32_t state = UINT32_MAX; + const uint8_t *ptr = pkt->data, *end = pkt->data + pkt->size; + int has_sps = 0; + int has_pps = 0; + int nalu_type; + + while (ptr < end) { + ptr = avpriv_find_start_code(ptr, end, &state); + if ((state & 0xFFFFFF00) != 0x100) + break; + nalu_type = state & 0x1F; + if (nalu_type == H264_NAL_SPS) { + has_sps = 1; + } else if (nalu_type == H264_NAL_PPS) + has_pps = 1; + else if ((nalu_type != H264_NAL_SEI || has_pps) && + nalu_type != H264_NAL_AUD && nalu_type != H264_NAL_SPS_EXT && + nalu_type != 0x0f) { + if (has_sps) { + while (ptr - 4 > pkt->data && ptr[-5] == 0) + ptr--; + if (ptr - pkt->data > 4) { + *size = ptr - 4 - pkt->data; + *data = av_malloc(*size + AV_INPUT_BUFFER_PADDING_SIZE); + if (!*data) + return AVERROR(ENOMEM); + + memcpy(*data, pkt->data, *size); + + if (s->remove) { + pkt->data += *size; + pkt->size -= *size; + } + } + return 0; + } + } + } + + return 0; +} + +static int extract_extradata_h265(AVBSFContext *ctx, AVPacket *pkt, + uint8_t **data, int *size) { static const int extradata_nal_types_hevc[] = { HEVC_NAL_VPS, HEVC_NAL_SPS, HEVC_NAL_PPS, }; - static const int extradata_nal_types_h264[] = { - H264_NAL_SPS, H264_NAL_PPS, - }; ExtractExtradataContext *s = ctx->priv_data; @@ -67,13 +110,8 @@ static int extract_extradata_h2645(AVBSFContext *ctx, AVPacket *pkt, int nb_extradata_nal_types; int i, ret = 0; - if (ctx->par_in->codec_id == AV_CODEC_ID_HEVC) { - extradata_nal_types = extradata_nal_types_hevc; - nb_extradata_nal_types = FF_ARRAY_ELEMS(extradata_nal_types_hevc); - } else { - extradata_nal_types = extradata_nal_types_h264; - nb_extradata_nal_types = FF_ARRAY_ELEMS(extradata_nal_types_h264); - } + extradata_nal_types = extradata_nal_types_hevc; + nb_extradata_nal_types = FF_ARRAY_ELEMS(extradata_nal_types_hevc); ret = ff_h2645_packet_split(&h2645_pkt, pkt->data, pkt->size, ctx, 0, 0, ctx->par_in->codec_id, 1); @@ -236,8 +274,8 @@ static const struct { uint8_t **data, int *size); } extract_tab[] = { { AV_CODEC_ID_CAVS, extract_extradata_mpeg4 }, - { AV_CODEC_ID_H264, extract_extradata_h2645 }, - { AV_CODEC_ID_HEVC, extract_extradata_h2645 }, + { AV_CODEC_ID_H264, extract_extradata_h264 }, + { AV_CODEC_ID_HEVC, extract_extradata_h265 }, { AV_CODEC_ID_MPEG1VIDEO, extract_extradata_mpeg12 }, { AV_CODEC_ID_MPEG2VIDEO, extract_extradata_mpeg12 }, { AV_CODEC_ID_MPEG4, extract_extradata_mpeg4 },