From patchwork Wed Nov 28 00:24:10 2018 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 11189 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 F21C944C460 for ; Wed, 28 Nov 2018 02:32:36 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 7895D68A6C6; Wed, 28 Nov 2018 02:32:37 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f47.google.com (mail-wm1-f47.google.com [209.85.128.47]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1CBC5689FCE for ; Wed, 28 Nov 2018 02:32:31 +0200 (EET) Received: by mail-wm1-f47.google.com with SMTP id r11-v6so806080wmb.2 for ; Tue, 27 Nov 2018 16:32:36 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=0L1abxd2qUserwaMvu6u0kYKyqSI40lAY4BDff2WGeI=; b=mTx02glWwO4XJcye7NHO7cOZ2OXbVvH/CmmoQLhP7CBxEy2xTmCtGLhXQa6KJeLrY5 WxASvCCNhA7leS+q42/RRWgDo7EWryKXNmz0c6rA5ZQOQmxwnMzBVrQBCT/D74cdsFTm OEXB7uMQJUeT0ZbgezDoL9ENEaN+jkgHiLY4OJYJrHh83SFJJscmK0iHiYeX3hNPVrNF RfzEGhxGrUciSs/CUYt4nkUDc/rBwkeZuyPy5/8dEhtXgYy67H78DyKcee25dDEahjgs ohplN6QRp6GG0r/HH7r5bpYqLyjtulssORohxFdz3qDfFEU+vMp10ch2N4ras1vpAuFt ZILQ== 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:mime-version:content-transfer-encoding; bh=0L1abxd2qUserwaMvu6u0kYKyqSI40lAY4BDff2WGeI=; b=nzdDT+BhEE8vp5ZyDNYR0ZkScg4kCTXrN8wL3BVp6xqlIvwkAYB7aI8iowfMony8gT 3Y2ViP07sPrHDzHgH1jK5pxadPRozOG8tCP0dezL73xh+jOK7F/3D7IhjZSjDx4j8TBv zFF86lyY3vIz/1HDqSAav0RZL2tPrtxszzcNPkBFdhrph9+U9fuYlvTCZhEnDfyto5xi f8MkccbW0Q+veRYBryz+KkAi073vtInYGLx/uj7oOYlyH1UxFlyhGO+Jie/G8G0SkGtF u4xhlU0z+5ZEnWGAk+206HyAmTZH6YXlHunnGpPPx3hLa4W9xgC0QFpsUeoEmo0bNwhb 2kfw== X-Gm-Message-State: AA+aEWZuNZpO9UKTnToLguWFlthQQSG+dJ/EIz0U8GwRL7OwDpLZbPA8 zwnGJ+u/NA96TsXrqiFcQw6iuoQm X-Google-Smtp-Source: AFSGD/Us26rtYXyEnbUnqHwYe/a+QJV7Sip+L6xjXeKtjiRgsQIi1qpfIa6yPjkNQ1ueoP8niyljIA== X-Received: by 2002:a1c:8fc2:: with SMTP id r185mr784055wmd.54.1543364702342; Tue, 27 Nov 2018 16:25:02 -0800 (PST) Received: from localhost.localdomain (ipbcc08c44.dynamic.kabel-deutschland.de. [188.192.140.68]) by smtp.googlemail.com with ESMTPSA id e8-v6sm1655323wmf.22.2018.11.27.16.25.01 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 27 Nov 2018 16:25:01 -0800 (PST) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Wed, 28 Nov 2018 01:24:10 +0100 Message-Id: <20181128002410.2244-3-andreas.rheinhardt@googlemail.com> X-Mailer: git-send-email 2.19.1 In-Reply-To: <4d7d94d1-2137-4fd9-3204-4af5aea9f27e@jkqxz.net> References: <4d7d94d1-2137-4fd9-3204-4af5aea9f27e@jkqxz.net> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 2/2] cbs_h2645: Avoid memcpy when splitting fragment #2 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: Andreas Rheinhardt Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Now memcpy can be avoided for NAL units containing escapes, too. Particularly improves performance for files with hardcoded black bars. For such a file, time spent in cbs_h2645_split_fragment went down from 369410 decicycles to 327677 decicycles. (It were 379114 decicycles when every NAL unit was copied.) Signed-off-by: Andreas Rheinhardt --- libavcodec/cbs_h2645.c | 33 +++++++++++---------------------- 1 file changed, 11 insertions(+), 22 deletions(-) diff --git a/libavcodec/cbs_h2645.c b/libavcodec/cbs_h2645.c index 574a53a60a..e74f8dce81 100644 --- a/libavcodec/cbs_h2645.c +++ b/libavcodec/cbs_h2645.c @@ -531,6 +531,7 @@ static int cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx, for (i = 0; i < packet->nb_nals; i++) { const H2645NAL *nal = &packet->nals[i]; + AVBufferRef *ref; size_t size = nal->size; // Remove trailing zeroes. @@ -538,25 +539,13 @@ static int cbs_h2645_fragment_add_nals(CodedBitstreamContext *ctx, --size; av_assert0(size > 0); - if (nal->data == nal->raw_data) { - err = ff_cbs_insert_unit_data(ctx, frag, -1, nal->type, - (uint8_t*)nal->data, size, frag->data_ref); - if (err < 0) - return err; - } else { - uint8_t *data = av_malloc(size + AV_INPUT_BUFFER_PADDING_SIZE); - if (!data) - return AVERROR(ENOMEM); - memcpy(data, nal->data, size); - memset(data + size, 0, AV_INPUT_BUFFER_PADDING_SIZE); + ref = (nal->data == nal->raw_data) ? frag->data_ref + : packet->rbsp.rbsp_buffer_ref; - err = ff_cbs_insert_unit_data(ctx, frag, -1, nal->type, - data, size, NULL); - if (err < 0) { - av_freep(&data); - return err; - } - } + err = ff_cbs_insert_unit_data(ctx, frag, -1, nal->type, + (uint8_t*)nal->data, size, ref); + if (err < 0) + return err; } return 0; @@ -612,7 +601,7 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx, err = ff_h2645_packet_split(&priv->read_packet, frag->data + start, end - start, - ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1, 0); + ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1, 1); if (err < 0) { av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split AVCC SPS array.\n"); return err; @@ -636,7 +625,7 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx, err = ff_h2645_packet_split(&priv->read_packet, frag->data + start, end - start, - ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1, 0); + ctx->log_ctx, 1, 2, AV_CODEC_ID_H264, 1, 1); if (err < 0) { av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split AVCC PPS array.\n"); return err; @@ -690,7 +679,7 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx, err = ff_h2645_packet_split(&priv->read_packet, frag->data + start, end - start, - ctx->log_ctx, 1, 2, AV_CODEC_ID_HEVC, 1, 0); + ctx->log_ctx, 1, 2, AV_CODEC_ID_HEVC, 1, 1); if (err < 0) { av_log(ctx->log_ctx, AV_LOG_ERROR, "Failed to split " "HVCC array %d (%d NAL units of type %d).\n", @@ -709,7 +698,7 @@ static int cbs_h2645_split_fragment(CodedBitstreamContext *ctx, frag->data, frag->data_size, ctx->log_ctx, priv->mp4, priv->nal_length_size, - codec_id, 1, 0); + codec_id, 1, 1); if (err < 0) return err;