From patchwork Mon Jul 22 07:13:55 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: hwren X-Patchwork-Id: 14034 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 0C51A448DAD for ; Mon, 22 Jul 2019 10:15:25 +0300 (EEST) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id E74D268A990; Mon, 22 Jul 2019 10:15:24 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-m964.mail.126.com (mail-m964.mail.126.com [123.126.96.4]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 2F5CB68A7E0 for ; Mon, 22 Jul 2019 10:15:10 +0300 (EEST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=126.com; s=s110527; h=From:Subject:Date:Message-Id; bh=+dDgjrUJWJxnITUUaj PcSG6uXTYj7pjsP5v90ndNayA=; b=lFP0G6iQ+1uN5HJT5DVyU9UAhSGTC+9ujq xidzcBQg+SHQuwn7j/Uoq/wAZ6LV0zcjukJFTve73xAkYL3Klv+Ag9gBb5lqh7xL CTznnDkLq4YifcA3NVq2AwZY4a6eJ1lMuZaI3uCbNlCEO52BbC8W+ljtX4utejul LXRyQJyqE= Received: from localhost.localdomain (unknown [210.22.22.131]) by smtp9 (Coremail) with SMTP id NeRpCgC3EhV4YjVdVAOtFA--.161S6; Mon, 22 Jul 2019 15:15:09 +0800 (CST) From: hwrenx To: ffmpeg-devel@ffmpeg.org Date: Mon, 22 Jul 2019 15:13:55 +0800 Message-Id: <1563779635-20749-4-git-send-email-hwrenx@126.com> X-Mailer: git-send-email 2.7.4 In-Reply-To: <1563779635-20749-1-git-send-email-hwrenx@126.com> References: <4B77BA39-17B7-4433-9EC9-5E47A0DD989A@gmx.de> <1563779635-20749-1-git-send-email-hwrenx@126.com> X-CM-TRANSID: NeRpCgC3EhV4YjVdVAOtFA--.161S6 X-Coremail-Antispam: 1Uf129KBjvJXoWxGF4rXF1DtF4UAFyfZry5Arb_yoW5uw1Upw 43ArZ3t3WUJFs7Ar93Jw1FvF45WrZ2gF48Kr4DJr109a40yryUtFWxtryI9ayI9FWkG343 KF4ktF15u3WDta7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUjbIjqfuFe4nvWSU5nxnvy2 9KBjDUYxBIdaVFxhVjvjDU0xZFpf9x07jzVbgUUUUU= X-Originating-IP: [210.22.22.131] X-CM-SenderInfo: pkzuv0b06rjloofrz/1tbi2x356VpD9pPvygAAsP Subject: [FFmpeg-devel] [PATCH v5 3/3] lavc/libdavs2.c: reduce memcpy 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" Can effectivly improved decoding speed when memcpy becomes a limitation for proccessing high resolution source. Tested under i7-8700k with `ffmpeg -i 7680x4320.avs2 -vsync 0 -f null -` got performance 23fps => 42fps Signed-off-by: hwrenx --- libavcodec/libdavs2.c | 52 ++++++++++++++++++++++++++++----------------------- 1 file changed, 29 insertions(+), 23 deletions(-) diff --git a/libavcodec/libdavs2.c b/libavcodec/libdavs2.c index 6d66209..32c07fe 100644 --- a/libavcodec/libdavs2.c +++ b/libavcodec/libdavs2.c @@ -73,13 +73,22 @@ static av_cold int davs2_init(AVCodecContext *avctx) return 0; } +static void davs2_frame_unref(void *opaque, uint8_t *data) { + DAVS2Context *cad = (DAVS2Context *)opaque; + davs2_picture_t pic; + + pic.magic = (davs2_picture_t *)data; + + if (cad->decoder) { + davs2_decoder_frame_unref(cad->decoder, &pic); + } +} + static int davs2_dump_frames(AVCodecContext *avctx, davs2_picture_t *pic, int *got_frame, davs2_seq_info_t *headerset, int ret_type, AVFrame *frame) { DAVS2Context *cad = avctx->priv_data; - int bytes_per_sample = pic->bytes_per_sample; - int plane = 0; - int line = 0; + int plane; if (!headerset) { *got_frame = 0; @@ -117,29 +126,28 @@ static int davs2_dump_frames(AVCodecContext *avctx, davs2_picture_t *pic, int *g return AVERROR_EXTERNAL; } - for (plane = 0; plane < 3; ++plane) { - int size_line = pic->widths[plane] * bytes_per_sample; - frame->buf[plane] = av_buffer_alloc(size_line * pic->lines[plane]); - - if (!frame->buf[plane]){ - av_log(avctx, AV_LOG_ERROR, "Decoder error: allocation failure, can't dump frames.\n"); - return AVERROR(ENOMEM); - } - - frame->data[plane] = frame->buf[plane]->data; - frame->linesize[plane] = size_line; - - for (line = 0; line < pic->lines[plane]; ++line) - memcpy(frame->data[plane] + line * size_line, - pic->planes[plane] + line * pic->strides[plane], - pic->widths[plane] * bytes_per_sample); - } - frame->width = cad->headerset.width; frame->height = cad->headerset.height; frame->pts = cad->out_frame.pts; frame->format = avctx->pix_fmt; + /* handle the actual picture in magic */ + frame->buf[0] = av_buffer_create((uint8_t *)pic->magic, + sizeof(davs2_picture_t *), + davs2_frame_unref, + (void *)cad, + AV_BUFFER_FLAG_READONLY); + if (!frame->buf[0]) { + av_log(avctx, AV_LOG_ERROR, + "Decoder error: allocation failure, can't dump frames.\n"); + return AVERROR(ENOMEM); + } + + for (plane = 0; plane < 3; ++plane) { + frame->linesize[plane] = pic->strides[plane]; + frame->data[plane] = pic->planes[plane]; + } + *got_frame = 1; return 0; } @@ -171,7 +179,6 @@ static int send_delayed_frame(AVCodecContext *avctx, AVFrame *frame, int *got_fr } if (ret == DAVS2_GOT_FRAME) { ret = davs2_dump_frames(avctx, &cad->out_frame, got_frame, &cad->headerset, ret, frame); - davs2_decoder_frame_unref(cad->decoder, &cad->out_frame); } return ret; } @@ -220,7 +227,6 @@ static int davs2_decode_frame(AVCodecContext *avctx, void *data, if (ret != DAVS2_DEFAULT) { ret = davs2_dump_frames(avctx, &cad->out_frame, got_frame, &cad->headerset, ret, frame); - davs2_decoder_frame_unref(cad->decoder, &cad->out_frame); } return ret == 0 ? buf_size : ret;