From patchwork Tue Oct 3 13:15:13 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: wm4 X-Patchwork-Id: 5396 Delivered-To: ffmpegpatchwork@gmail.com Received: by 10.2.61.8 with SMTP id n8csp2710797jan; Tue, 3 Oct 2017 06:21:32 -0700 (PDT) X-Received: by 10.223.173.148 with SMTP id w20mr4628768wrc.253.1507036891943; Tue, 03 Oct 2017 06:21:31 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1507036891; cv=none; d=google.com; s=arc-20160816; b=nTxm5MTcwkbj4U8++XOwO8rL+LNm+eVab3qCABWEA4y0ZmeukREYqhlwcxPQHWbDsd 1JqIW/yTLTz8M7Zkn14yH6AQrq/9MbvowZGGM51+Ht5h/TCEiKEuosR72LpixCv6a9Ck 9XOTgT+eSHoQmPoFXYw6R8hqVFRnXWvBJ+1+gNdoZvLWAskOicGGuq79OpV/oU7jGvDw c4FYZt4hUF3DD3wYj6sDspW5i98RqNjq8xXYswGixitmdJRId9x7SIWXov5RZfJG3pDA Uzk7Vy86k4NuCkfgh3bJk8UY04GgUFwyiQlYcyKL/7HlgJPKE7zerEDVKO1jgRMspXOV v6ZA== 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: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=qwz/+Vwkc1jg/Q9kPsR4iLlE/637Y/i9Tm0Ne5oTCCY=; b=hlvpyDcUzisf1i7HpNEya0QO84DWFQErL4ZSNy3cNw45HOD2ukmjjKotBiYt/sBwjc 5JDjNvGyfrDOdfH0snVnXQdHXa4eW+BUObJRRsxzJX09w3IvtZJZlH1P4PHn7v+DTVIb oon3lxgx/8SIirokynv7uCWa+9Wd+KFcx7jKcimzJvAja3MVlOh1fx7aosapAVv/ABQE 2Be/XFRU3LIpa9rHb7rVUw/LG8Gko+iA0tBOO9GvU9wCYEmFZ/s/v1Qy8GNI2aO8js/j 4OXCV8UAaZBH9bclOQrXZaVum/Td+dFfnAc9StlFMQE+hVl4jQWtYvGcSMHDPuaLDdcQ A3vQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@googlemail.com header.s=20161025 header.b=UtIh18kC; 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id 93si2876363wrf.298.2017.10.03.06.21.31; Tue, 03 Oct 2017 06:21:31 -0700 (PDT) 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=@googlemail.com header.s=20161025 header.b=UtIh18kC; 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; dmarc=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=googlemail.com Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 0C0C3689FE3; Tue, 3 Oct 2017 16:21:15 +0300 (EEST) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-lf0-f67.google.com (mail-lf0-f67.google.com [209.85.215.67]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id ECF89689FDB for ; Tue, 3 Oct 2017 16:21:07 +0300 (EEST) Received: by mail-lf0-f67.google.com with SMTP id m142so5872867lfg.8 for ; Tue, 03 Oct 2017 06:21:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=googlemail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references; bh=av/tG4i3QSdRQWWbAqZAeK/hfseVe/XdCFUZaUf7Tms=; b=UtIh18kCPobBq7sk+lHEg1TluPRDhEfjqMM8zdSxc2/9xswG8czWFMl6CgOZV8vGav HiIaCoFO3kDv8PALl9t1NLEqWUqri8Co+xQ6MYzD7YAD4rX57hWkAXjGkoD9XeFRKHUG dyi3OAykyeM+TQ2D5vJ8GpLruUiNQ0u1EvO9LF7QOWFFeviyxhb8EEst2mk2cpR2sEXq G4tWDiy1jWIReNxSG5Da4uRIa8oZNWMJm6F3R2FjRkssNwpwIU81LgL+K3rlNMmIpnJ3 ENguMz+G9FEp55DtgXqCdQCA90Ah3jl8CVhjCcaKdMTK/BagDad4SEGGSoOyJLI1g52p VU8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references; bh=av/tG4i3QSdRQWWbAqZAeK/hfseVe/XdCFUZaUf7Tms=; b=oD1ld0VS93UqkMcFITkdWms1qPAzuN9P5KV6WZW44giNiQjLefWcX6Hwdekd9Du2v1 N/oXEo4c8QogzYS21iUfsQTJZMJXYL4FoRdsP3J5l7hTd6i0Fow60Dibzs5iMXV+dOiI SpPxJgPvN6iUA3KN/+bY+ijEfda5cpWkMV/vw6IrYnU0cetV23p08aBeESMQXLq6UDRx CQdGU0UfPknWcCUe1gXbtO/qEBny6B+r9pB/IvPysptgTecq46EYhgBphs7OKtOANg8L cZgUf90aWy3KxENZ+nHI0e4C4ptNyf9br1hJN9bN4jJAdVA/ah1q0DEQpwIARXDAv/ES bJNA== X-Gm-Message-State: AHPjjUg2x2LOFVgeeUtBUa2CQ5bVo99+RMVDmqkQEnAnwggZCGVE4prD +Uu2VQRFbfyqYeh7AvhJP43EvA== X-Google-Smtp-Source: AOwi7QCJZRiCZuWtWMmRY0TFHsriTtoWgSV/+Pvr/9E0S2OWyvVaankBH7fqeN8fYPZ3qN/6f81blg== X-Received: by 10.25.80.74 with SMTP id z10mr5195903lfj.76.1507036497862; Tue, 03 Oct 2017 06:14:57 -0700 (PDT) Received: from debian.speedport.ip (p2003006CCD5CDB6820D8428BCA02F6C5.dip0.t-ipconnect.de. [2003:6c:cd5c:db68:20d8:428b:ca02:f6c5]) by smtp.googlemail.com with ESMTPSA id 6sm2892024lju.45.2017.10.03.06.14.56 for (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Tue, 03 Oct 2017 06:14:56 -0700 (PDT) From: wm4 To: ffmpeg-devel@ffmpeg.org Date: Tue, 3 Oct 2017 15:15:13 +0200 Message-Id: <20171003131518.4557-3-nfxjfg@googlemail.com> X-Mailer: git-send-email 2.14.1 In-Reply-To: <20171003131518.4557-1-nfxjfg@googlemail.com> References: <20171003131518.4557-1-nfxjfg@googlemail.com> Subject: [FFmpeg-devel] [PATCH 2/7] 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" From: Anton Khirnov Use the AVFrame.opaque_ref field. The original user's opaque_ref is wrapped in the lavc struct and then unwrapped before the frame is returned to the caller. This new struct will be useful in the following commits. Merges Libav commit 359a8a3e2d1194b52b6c386f94fd0929567dfb67. --- libavcodec/decode.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++-- libavcodec/decode.h | 13 ++++++++++++ 2 files changed, 72 insertions(+), 2 deletions(-) diff --git a/libavcodec/decode.c b/libavcodec/decode.c index 437b848248..04f7156154 100644 --- a/libavcodec/decode.c +++ b/libavcodec/decode.c @@ -640,6 +640,26 @@ static int decode_receive_frame_internal(AVCodecContext *avctx, AVFrame *frame) if (ret == AVERROR_EOF) avci->draining_done = 1; + /* unwrap the per-frame decode data and restore the original opaque_ref*/ + if (!ret) { + /* the only case where decode data is not set should be decoders + * that do not call ff_get_buffer() */ + av_assert0((frame->opaque_ref && frame->opaque_ref->size == sizeof(FrameDecodeData)) || + !(avctx->codec->capabilities & AV_CODEC_CAP_DR1)); + + if (frame->opaque_ref) { + FrameDecodeData *fdd; + AVBufferRef *user_opaque_ref; + + fdd = (FrameDecodeData*)frame->opaque_ref->data; + + user_opaque_ref = fdd->user_opaque_ref; + fdd->user_opaque_ref = NULL; + av_buffer_unref(&frame->opaque_ref); + frame->opaque_ref = user_opaque_ref; + } + } + return ret; } @@ -1612,6 +1632,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_buffer_unref(&fdd->user_opaque_ref); + + av_freep(&fdd); +} + +static int attach_decode_data(AVFrame *frame) +{ + AVBufferRef *fdd_buf; + FrameDecodeData *fdd; + + 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); + } + + fdd->user_opaque_ref = frame->opaque_ref; + frame->opaque_ref = fdd_buf; + + return 0; +} + static int get_buffer_internal(AVCodecContext *avctx, AVFrame *frame, int flags) { const AVHWAccel *hwaccel = avctx->hwaccel; @@ -1648,8 +1699,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 = 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..ab8327f95c 100644 --- a/libavcodec/decode.h +++ b/libavcodec/decode.h @@ -21,8 +21,21 @@ #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 + * opaque_ref. + */ +typedef struct FrameDecodeData { + /** + * The original user-set opaque_ref. + */ + AVBufferRef *user_opaque_ref; +} FrameDecodeData; + /** * Called by decoders to get the next packet for decoding. *