From patchwork Fri Nov 10 16:03:15 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Timo Rothenpieler X-Patchwork-Id: 5943 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.161.90 with SMTP id m26csp3545418jah; Fri, 10 Nov 2017 08:04:14 -0800 (PST) X-Google-Smtp-Source: AGs4zMYDHlL8JZjKSpLRP4M1HsioOflnYU511HLHuqFJ0ZJNgoiuVHYSCJx2RLymSV3ArlNyMgwQ X-Received: by 10.223.143.51 with SMTP id p48mr708150wrb.104.1510329854095; Fri, 10 Nov 2017 08:04:14 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1510329854; cv=none; d=google.com; s=arc-20160816; b=DhsAavl3wTb0o3zzIWmFW8Sut4+QWaEydnJZETxALeinDKyrJ1I+0en/Qsi6U8BT6r yo7g36OIOl2pFvOM56dZEUo3XCjQIic6F6HVrgvhe8hmB0SFzYuCP0gBpuN/MwLI2k4e tEzBwbYEt0dwUHOZCNDii43eqXKMvwsFL05u+08VWHQdRcjMz4FjvtJnFqQeENxaC5Ts hEuMvK9FP7yhY7clu9YgKhMf3MSsoeiUSziaPgLAELWGLL1zd18+SacYCvrK5Tr8uvEg v9ggaJqBFHCCbnYk8DTqqBhrgGZk9+gX4oMGH+ukfukLaKW/CPqjcFnfcogOyV+6w6xJ 9m3g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:mime-version:cc:reply-to :list-subscribe:list-help:list-post:list-archive:list-unsubscribe :list-id:precedence:subject:references:in-reply-to:message-id:date :to:from:dkim-signature:delivered-to:arc-authentication-results; bh=0bJdTsyZaUp6j9rtuWpwD1i2tU2vZ3BE30QkE0Qo9n0=; b=evb7VZcsH0FJYYLQZLQGGLXpI4vEdArVHVerab29k6Dwnt/auTafg688RNhneLr7/H JV8Goj1n1LOinn2NNtT82RGmnao7Rilqri22KzDAEkjQVAPsocZIPpr/BgV1nFHJuLM5 NUhge+lqFmvuLTHAtefCPh7qtPr0UiFhHZJvldROSU4+mojwpsOHDND8JSDixZ3wZI4h 5k7CYDoihAYtss8AFDOpeWYyEzrIldruC1IQMQZ+3wkFNXZKCVUPoA6JtZNSH9wIhOAC x09zKz9jyBUFR3ytJUIvqGJLt3A/F2lPIx2ezgProKgzskg1iY9l94bo+AJJaUI6UnEp O+Jw== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@rothenpieler.org header.s=mail header.b=EZza+z2W; 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 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 72si1415161wmf.124.2017.11.10.08.04.13; Fri, 10 Nov 2017 08:04:14 -0800 (PST) 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=@rothenpieler.org header.s=mail header.b=EZza+z2W; 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 Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 4D406689ED3; Fri, 10 Nov 2017 18:03:24 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from btbn.de (btbn.de [5.9.118.179]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 1BD80689E67 for ; Fri, 10 Nov 2017 18:03:17 +0200 (EET) Received: from localhost.localdomain (unknown [134.102.43.210]) by btbn.de (Postfix) with ESMTPSA id 5ACF13C73F; Fri, 10 Nov 2017 17:03:29 +0100 (CET) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=rothenpieler.org; s=mail; t=1510329809; bh=GBBqIVCrtNP3JdaYaSFpl8dRkFWOQ+VO0XNvcB62hM8=; h=From:To:Cc:Subject:Date:In-Reply-To:References; b=EZza+z2WMYzQaUlYAaMayeMQMKXYMJZls+8v42ywoAEBCzDqOCeeF3VT57KPmUcjm SvK43TpEZN+L+hK5ih9V9UNNOAr2fMC8D+WTZTiSJwFLqhPe8OS0QQZg7Q27mU8oND d+nqB8LPYu8ge4qWasq+BPq/wyC0q3mUoA3B9U7E= From: Timo Rothenpieler To: ffmpeg-devel@ffmpeg.org Date: Fri, 10 Nov 2017 17:03:15 +0100 Message-Id: <20171110160317.3584-2-timo@rothenpieler.org> X-Mailer: git-send-email 2.15.0 In-Reply-To: <20171110160317.3584-1-timo@rothenpieler.org> References: <20171110160317.3584-1-timo@rothenpieler.org> Subject: [FFmpeg-devel] [PATCH 2/4] decode: add a method for attaching lavc-internal data to frames 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: Anton Khirnov MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Anton Khirnov Use the AVFrame.private_ref field. This new struct will be useful in the following commits. Merges Libav commit 359a8a3e2d1194b52b6c386f94fd0929567dfb67. --- libavcodec/decode.c | 51 ++++++++++++++++++++++++++++++++++++++++++-- libavcodec/decode.h | 11 ++++++++++ libavcodec/wrapped_avframe.c | 7 ++++++ 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 86fe5aef52..0f215d6915 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -613,6 +613,16 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) if (ret == AVERROR_EOF) avci->draining_done = 1; + /* free the per-frame decode data */ + if (!ret) { + /* the only case where decode data is not set should be decoders + * that do not call ff_get_buffer() */ + av_assert0((frame->private_ref && frame->private_ref->size == sizeof(FrameDecodeData)) || + !(avctx->codec->capabilities & AV_CODEC_CAP_DR1)); + + av_buffer_unref(&frame->private_ref); + } + return ret; } @@ -1552,6 +1562,37 @@ static void validate_avframe_allocation(AVCodecContext *avctx, AVFrame *frame) } } +static void decode_data_free(void *opaque, uint8_t *data) +{ + FrameDecodeData *fdd = (FrameDecodeData*)data; + + av_freep(&fdd); +} + +int ff_attach_decode_data(AVFrame *frame) +{ + AVBufferRef *fdd_buf; + FrameDecodeData *fdd; + + av_assert1(!frame->private_ref); + av_buffer_unref(&frame->private_ref); + + fdd = av_mallocz(sizeof(*fdd)); + if (!fdd) + return AVERROR(ENOMEM); + + fdd_buf = av_buffer_create((uint8_t*)fdd, sizeof(*fdd), decode_data_free, + NULL, AV_BUFFER_FLAG_READONLY); + if (!fdd_buf) { + av_freep(&fdd); + return AVERROR(ENOMEM); + } + + frame->private_ref = fdd_buf; + + return 0; +} + static int get_buffer_internal(AVCodecContext *avctx, AVFrame *frame, int flags) { const AVHWAccel *hwaccel = avctx->hwaccel; @@ -1588,8 +1629,14 @@ static int get_buffer_internal(AVCodecContext *avctx, AVFrame *frame, int flags) avctx->sw_pix_fmt = avctx->pix_fmt; ret = avctx->get_buffer2(avctx, frame, flags); - if (ret >= 0) - validate_avframe_allocation(avctx, frame); + if (ret < 0) + goto end; + + validate_avframe_allocation(avctx, frame); + + ret = ff_attach_decode_data(frame); + if (ret < 0) + goto end; end: if (avctx->codec_type == AVMEDIA_TYPE_VIDEO && !override_dimensions && diff --git a/libavcodec/decode.h b/libavcodec/decode.h index c9630228dc..519f875c98 100644 --- a/libavcodec/decode.h +++ b/libavcodec/decode.h @@ -21,8 +21,17 @@ #ifndef AVCODEC_DECODE_H #define AVCODEC_DECODE_H +#include "libavutil/buffer.h" + #include "avcodec.h" +/** + * This struct stores per-frame lavc-internal data and is attached to it via + * private_ref. + */ +typedef struct FrameDecodeData { +} FrameDecodeData; + /** * Called by decoders to get the next packet for decoding. * @@ -36,4 +45,6 @@ int ff_decode_get_packet(AVCodecContext *avctx, AVPacket *pkt); void ff_decode_bsfs_uninit(AVCodecContext *avctx); +int ff_attach_decode_data(AVFrame *frame); + #endif /* AVCODEC_DECODE_H */ diff --git a/libavcodec/wrapped_avframe.c b/libavcodec/wrapped_avframe.c index 5f88a668b9..85ff32d13a 100644 --- a/libavcodec/wrapped_avframe.c +++ b/libavcodec/wrapped_avframe.c @@ -25,6 +25,7 @@ */ #include "avcodec.h" +#include "decode.h" #include "internal.h" #include "libavutil/internal.h" @@ -98,6 +99,12 @@ static int wrapped_avframe_decode(AVCodecContext *avctx, void *data, av_frame_move_ref(out, in); + err = ff_attach_decode_data(out); + if (err < 0) { + av_frame_unref(out); + return err; + } + *got_frame = 1; return 0; }