From patchwork Sun Sep 13 02:57:50 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andreas Rheinhardt X-Patchwork-Id: 22324 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 6E862449E91 for ; Sun, 13 Sep 2020 05:58:42 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 53D2268BC02; Sun, 13 Sep 2020 05:58:42 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-wm1-f65.google.com (mail-wm1-f65.google.com [209.85.128.65]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 5E65368BBB2 for ; Sun, 13 Sep 2020 05:58:32 +0300 (EEST) Received: by mail-wm1-f65.google.com with SMTP id a9so8075320wmm.2 for ; Sat, 12 Sep 2020 19:58:32 -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 :mime-version:content-transfer-encoding; bh=ZuHS2BItckTa/pqSkCz7I3cy85O0CeekvwItpduyTyk=; b=T7F23W849tbgNh5QVKbrGiA/abaFhTOuEK4uowRNDGOYI7BIfjz95wnD0xtYPIB03w 9aN96Zn+bWTdsXKNVDwunv6wTH5kfMI8UaPTp5fTByiFMd4xI8PEbjKyR8Z32obiLuqR gx3DhdvVNWC0DdZTtHiRR2N5TsxL8zL7UwTEemcRt0T+RDbqzKsvlQKqYuAORAZX0CKl 52zx8LEI9bAUWmZy5LeMXfwV/OjoWKoOCu9SG7xuISn6TyYQfKZolwAPMnmfrywwOAX6 rTbX506VYdIIItAwuEwV/GsWR2DBw3V/RKc1hWukicEIgYyl5Fsrcqgmki0AjbOQmL3E l9XQ== 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=ZuHS2BItckTa/pqSkCz7I3cy85O0CeekvwItpduyTyk=; b=MVNcTzdK9yZosKBrbZQNNPXpJl7tvYDZl2gg9+jGEPMWHvosGEv4VDyJJu/O4aD16/ J8zCdgVK7fbIGf59ntIz2T3jeOXjcTLHVg8pBZ6p+3sA0MuNdIKy9OEbeUQrrGA34vKn IdewTdyY0XaV5qTvUcVcRQmzLpAfpOSCG3GdUw0Bub/FOtRP8XPbHZh6e/roCGyujDx1 csYyX+fCnXoLTFTLJ7RpjjOzYZzRnnBrmu2BSH5mTa5ViL/ODXeLiTZFqdniXJHjUva6 cfFgGhw4MSSzITvlV7sOMoxBMGlKngVRG0BhxlnbGRJ7fmZ7YjbgfbTcZd/USuu7yjJW G6wQ== X-Gm-Message-State: AOAM5306vgx/0wQhQfU7FTYarNBsN+5dI5LctjUkaaYDzD+KHC7mrpUj BLbtwR1IVgVYFllxFEtcaEI1Mon/7B0= X-Google-Smtp-Source: ABdhPJw+ZDpFKZbH/l++mgsvUnwku3HPGtGRQ78RSRTUmS0Bv7C3+xUw2BH87v5ZOjYvwyo58eRCyA== X-Received: by 2002:a1c:4b04:: with SMTP id y4mr8903183wma.111.1599965911394; Sat, 12 Sep 2020 19:58:31 -0700 (PDT) Received: from sblaptop.fritz.box (ipbcc1fb0f.dynamic.kabel-deutschland.de. [188.193.251.15]) by smtp.gmail.com with ESMTPSA id f3sm11883355wmb.35.2020.09.12.19.58.30 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 12 Sep 2020 19:58:30 -0700 (PDT) From: Andreas Rheinhardt To: ffmpeg-devel@ffmpeg.org Date: Sun, 13 Sep 2020 04:57:50 +0200 Message-Id: <20200913025753.274772-13-andreas.rheinhardt@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200913025753.274772-1-andreas.rheinhardt@gmail.com> References: <20200913025753.274772-1-andreas.rheinhardt@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 13/16] avcodec/svq3: Avoid overhead of AVBuffer API 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" Up until now, the SVQ3 decoder allocated several refcounted buffers, despite no sharing/refcounting happening at all: Their refcount never exceeds one and they are treated like ordinary buffers (with the exception that the pointer used to access them is in the middle of the allocated buffer, but this does not warrant using the AVBuffer API at all). Given that using the AVBuffer API incurs overhead, it is no longer used at all. Signed-off-by: Andreas Rheinhardt --- libavcodec/svq3.c | 17 ++++++++--------- 1 file changed, 8 insertions(+), 9 deletions(-) diff --git a/libavcodec/svq3.c b/libavcodec/svq3.c index 0ac81364bd..fb7b992496 100644 --- a/libavcodec/svq3.c +++ b/libavcodec/svq3.c @@ -70,11 +70,10 @@ typedef struct SVQ3Frame { AVFrame *f; - AVBufferRef *motion_val_buf[2]; + int16_t (*motion_val_buf[2])[2]; int16_t (*motion_val[2])[2]; - AVBufferRef *mb_type_buf; - uint32_t *mb_type; + uint32_t *mb_type_buf, *mb_type; } SVQ3Frame; typedef struct SVQ3Context { @@ -1325,9 +1324,9 @@ static void free_picture(AVCodecContext *avctx, SVQ3Frame *pic) { int i; for (i = 0; i < 2; i++) { - av_buffer_unref(&pic->motion_val_buf[i]); + av_freep(&pic->motion_val_buf[i]); } - av_buffer_unref(&pic->mb_type_buf); + av_freep(&pic->mb_type_buf); av_frame_unref(pic->f); } @@ -1343,19 +1342,19 @@ static int get_buffer(AVCodecContext *avctx, SVQ3Frame *pic) if (!pic->motion_val_buf[0]) { int i; - pic->mb_type_buf = av_buffer_allocz((big_mb_num + s->mb_stride) * sizeof(uint32_t)); + pic->mb_type_buf = av_calloc(big_mb_num + s->mb_stride, sizeof(uint32_t)); if (!pic->mb_type_buf) return AVERROR(ENOMEM); - pic->mb_type = (uint32_t*)pic->mb_type_buf->data + 2 * s->mb_stride + 1; + pic->mb_type = pic->mb_type_buf + 2 * s->mb_stride + 1; for (i = 0; i < 2; i++) { - pic->motion_val_buf[i] = av_buffer_allocz(2 * (b4_array_size + 4) * sizeof(int16_t)); + pic->motion_val_buf[i] = av_calloc(b4_array_size + 4, 2 * sizeof(int16_t)); if (!pic->motion_val_buf[i]) { ret = AVERROR(ENOMEM); goto fail; } - pic->motion_val[i] = (int16_t (*)[2])pic->motion_val_buf[i]->data + 4; + pic->motion_val[i] = pic->motion_val_buf[i] + 4; } }