From patchwork Wed Oct 16 02:50:41 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andriy Gelman X-Patchwork-Id: 15786 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 CEF78447FC7 for ; Wed, 16 Oct 2019 05:51:15 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id B2F1F68A495; Wed, 16 Oct 2019 05:51:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qk1-f195.google.com (mail-qk1-f195.google.com [209.85.222.195]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id B51E068A3C0 for ; Wed, 16 Oct 2019 05:51:07 +0300 (EEST) Received: by mail-qk1-f195.google.com with SMTP id p4so807056qkf.5 for ; Tue, 15 Oct 2019 19:51:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references:reply-to :mime-version:content-transfer-encoding; bh=pW4NaKJR2vxo8D3LU57oQo1Ko7htvezmF2FgB+eEwAE=; b=bx7Gmk4HXfMjy92eBJO6qBw7YQrolAUdWVbMMzyPhuuuZATZp2u7pz8AOuLGAA+Jqo 5ZqDlqy8S/syOwjJtIsRTbOOZJGRxdTGMySd0wnImHBtpWbmqSAWN2BX5dDkjN8HlMpS nUV/suWWVn7mCFZPxOVwr4/KUz/7xFlVZNBIF1V6UG03xP6K3jyO3UXNLL6hfP7iAtcM u/vKKSa/ayFILICVvU9XKMaPgbUnQjvQb4rTIuxpvdqWSqawEqMgV5C9ywtstTNiyw5G MpcTRHO0doNo406ndeqg8LKPn1R0nhh2DV8N1CDazdIJQUKk2fF9sGMPqUmaMJsN4SMQ +EOg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:reply-to:mime-version:content-transfer-encoding; bh=pW4NaKJR2vxo8D3LU57oQo1Ko7htvezmF2FgB+eEwAE=; b=kM8gzLwtIoqsEc1Wm6caWFjzj0i0ULdyL9L9skrr4oSC21drECT9NjFD81mhnhO8WC D6BxjSqouSxzC+qXaCnD4qCbFUBYbjf/MhUNvUWmpeeLPPXZQQ21v4r0QvvcEkPOnTRV qKFFNcRP1DBEOcVDAHWchs+scW7BX2GTGEALA+6YOld3wp2rcDrggG2E9Ui7/b68KDzx Av4alk8DK+Kk1zrpd+jHGhBOH/FHqvxgQE3zULHGF7UCJbMcXedcM7gTPJXP/vzFF4ti SCsQeNdI/kck7M0u2iH0Btu9MC9nzh7J85AhOGvVfNyrEnaEqxAt/tqlU8SLf4DUU8uc iPgw== X-Gm-Message-State: APjAAAXk6HPh5KnPmEWx1cQMTouQGzAxLXsFdX/ZLMiallLCYzWoT9YF 216tuj7x56pb/S7QLIFT3pw9Dz2d X-Google-Smtp-Source: APXvYqx22pgytFnStCpR9UAlXyjXBKzUGQXEhi/iVwH8Jh2tP0nqB+v483ey8XuAQpoKZLEuyQViTg== X-Received: by 2002:a37:8dc2:: with SMTP id p185mr39022070qkd.7.1571194266226; Tue, 15 Oct 2019 19:51:06 -0700 (PDT) Received: from localhost.localdomain (c-71-232-27-28.hsd1.ma.comcast.net. [71.232.27.28]) by smtp.gmail.com with ESMTPSA id 10sm657542qkp.39.2019.10.15.19.51.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 15 Oct 2019 19:51:05 -0700 (PDT) From: Andriy Gelman X-Google-Original-From: Andriy Gelman To: ffmpeg-devel@ffmpeg.org Date: Tue, 15 Oct 2019 22:50:41 -0400 Message-Id: <20191016025040.31273-4-andriy.gelman@gmail.com> X-Mailer: git-send-email 2.23.0 In-Reply-To: <20191016025040.31273-1-andriy.gelman@gmail.com> References: <20191016025040.31273-1-andriy.gelman@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH v6 3/3] hevc_mp4toannexb: Parse extradata directly from HVCC format 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: Andriy Gelman Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Andriy Gelman Since the original extradata is in HVCC format, there is no need to segment the output extradata into nal units. --- libavcodec/hevc_mp4toannexb_bsf.c | 66 ++++++++++++++++--------------- 1 file changed, 34 insertions(+), 32 deletions(-) diff --git a/libavcodec/hevc_mp4toannexb_bsf.c b/libavcodec/hevc_mp4toannexb_bsf.c index 1ca5f13807..938e01171d 100644 --- a/libavcodec/hevc_mp4toannexb_bsf.c +++ b/libavcodec/hevc_mp4toannexb_bsf.c @@ -243,12 +243,17 @@ static int update_paramset(AVBSFContext *ctx, H2645NAL *nal) static int hevc_extradata_to_annexb(AVBSFContext *ctx) { + HEVCBSFContext *s = ctx->priv_data; GetByteContext gb; int length_size, num_arrays, i, j; int ret = 0; uint8_t *new_extradata = NULL; size_t new_extradata_size = 0; + size_t start, end; + + H2645Packet pkt; + memset(&pkt, 0, sizeof(H2645Packet)); /* in case goto fail is called before pkt is initialized*/ bytestream2_init(&gb, ctx->par_in->extradata, ctx->par_in->extradata_size); @@ -268,6 +273,7 @@ static int hevc_extradata_to_annexb(AVBSFContext *ctx) goto fail; } + start = bytestream2_tell(&gb); for (j = 0; j < cnt; j++) { int nalu_len = bytestream2_get_be16(&gb); @@ -284,6 +290,32 @@ static int hevc_extradata_to_annexb(AVBSFContext *ctx) new_extradata_size += 4 + nalu_len; memset(new_extradata + new_extradata_size, 0, AV_INPUT_BUFFER_PADDING_SIZE); } + end = bytestream2_tell(&gb); + + /* split extradata into nalu packets*/ + ret = ff_h2645_packet_split(&pkt, ctx->par_in->extradata + start, + end - start, ctx, 1, 2, AV_CODEC_ID_HEVC, 1, 0); + if (ret < 0) + goto fail; + + /* parse the segmented nals*/ + for (j = 0; j < pkt.nb_nals; j++) { + H2645NAL *nal = &pkt.nals[j]; + + if (IS_PARAMSET(nal)) { + ret = update_paramset(ctx, nal); + if (ret < 0) + goto fail; + continue; + } + + if (nal->type == HEVC_NAL_SEI_PREFIX || nal->type == HEVC_NAL_SEI_SUFFIX) { + ret = append_sei_annexb(&s->ps.sei, nal); + if (ret < 0) + goto fail; + } + } + ff_h2645_packet_uninit(&pkt); } av_freep(&ctx->par_out->extradata); @@ -295,6 +327,7 @@ static int hevc_extradata_to_annexb(AVBSFContext *ctx) return length_size; fail: + ff_h2645_packet_uninit(&pkt); av_freep(&new_extradata); return ret; } @@ -302,7 +335,6 @@ fail: static int hevc_mp4toannexb_init(AVBSFContext *ctx) { HEVCBSFContext *s = ctx->priv_data; - H2645Packet pkt; int ret; if (ctx->par_in->extradata_size < MIN_HEVCC_LENGTH || @@ -310,44 +342,14 @@ static int hevc_mp4toannexb_init(AVBSFContext *ctx) AV_RB32(ctx->par_in->extradata) == 1) { av_log(ctx, AV_LOG_VERBOSE, "The input looks like it is Annex B already\n"); - return 0; } else { ret = hevc_extradata_to_annexb(ctx); if (ret < 0) return ret; s->length_size = ret; s->extradata_parsed = 1; - - memset(&pkt, 0, sizeof(H2645Packet)); - ret = ff_h2645_packet_split(&pkt, ctx->par_out->extradata, ctx->par_out->extradata_size, - ctx, 0, 0, AV_CODEC_ID_HEVC, 1, 0); - if (ret < 0) - goto done; - - for (int i = 0; i < pkt.nb_nals; ++i) { - H2645NAL *nal = &pkt.nals[i]; - - /*current segmentation algorithm includes next 0x00 from next nal unit*/ - if (nal->raw_data[nal->raw_size - 1] == 0x00) - nal->raw_size--; - - if (IS_PARAMSET(nal)) { - ret = update_paramset(ctx, nal); - if (ret < 0) - goto done; - continue; - } - - if (nal->type == HEVC_NAL_SEI_PREFIX || nal->type == HEVC_NAL_SEI_SUFFIX) { - ret = append_sei_annexb(&s->ps.sei, nal); - if (ret < 0) - goto done; - } - } } -done: - ff_h2645_packet_uninit(&pkt); - return ret; + return 0; } static void ps_uninit(ParamSets *ps)