From patchwork Mon Nov 22 21:58:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ridley Combs X-Patchwork-Id: 31551 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp7667547iob; Mon, 22 Nov 2021 14:00:30 -0800 (PST) X-Google-Smtp-Source: ABdhPJxILLgrPi+jfElrTdZr5Xn5Xurwr9T1SlmRy7WugNAn9Gxjo2SCluiMv4e3qZmnPce4VSwV X-Received: by 2002:a05:6402:2806:: with SMTP id h6mr666354ede.120.1637618430571; Mon, 22 Nov 2021 14:00:30 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637618430; cv=none; d=google.com; s=arc-20160816; b=OYor6flGmESI4MKihXTvAWQX6t4O+npMotlrmMLHF3rOuhbDj7pYa25te2x2CpChY/ hqVUshwmr2jKXu5CqWpa9z0SNvOTSeIYKZjzPYh+KDzdHfGygH5ikBGjqCkSt6EfBGTe RlZRDuoh+QKBt+nydejxcpoGcGIvjRsqWZ3TA1bfg9GmGT4xDjggwOheeZqJkruCtwAG Uqzkgm0j1WwPJHiXxK/szofhyGYv6fdsONejP+oGrUX9irE+3jQnpczA8lZpVVEDhA/O JR7f/sJf92PUWxL6D2d5NnyWuLPRsoT4x/3Znpc3FOeNX9imB0an6fpON3md57aKOH/v OLfg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=sender:errors-to:content-transfer-encoding:reply-to:list-subscribe :list-help:list-post:list-archive:list-unsubscribe:list-id :precedence:subject:mime-version:references:in-reply-to:message-id :date:to:from:dkim-signature:delivered-to; bh=pEgnrnkKFRlF1NlpJGDuKRViWF0rIzbrbZElJrPDbWk=; b=JrpInMxIMGGSzuUMqVVwMOgoJbcDFvXhzc67+OEePa7d/P7amnkGWQHckombDI6kpQ R5+R0Ek6pW7/c+VzML42+ErWfI1W59jAWm6nSdPX8Hyfc5Xllxc1bNXtTtRk75JMGNpq pmHLGgWPRyFiQjEZxBR03xTvS7O/VKuE718B6GAd2BNpKmgECAi3M/ufYhtvCqOXSjt3 tLc57DuDVH1agGRpdFtSPxQ3303jvE8w8hESCn5HtCdTinGAPDSgLNK9plRfBmPwDYUT xpKoKnGRvL5UT5bBwLGCK03ODBx11/x57ZXudvX66yMiyVEzao22obz/qIrrSaZoTx0W hmPQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@rcombs.me header.s=google header.b=Nj0Zdc0K; 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=rcombs.me Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org. [79.124.17.100]) by mx.google.com with ESMTP id s24si24548904ejd.339.2021.11.22.14.00.30; Mon, 22 Nov 2021 14:00:30 -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=@rcombs.me header.s=google header.b=Nj0Zdc0K; 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=rcombs.me Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 8883168AE59; Mon, 22 Nov 2021 23:58:49 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-io1-f50.google.com (mail-io1-f50.google.com [209.85.166.50]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id BD8D268AE59 for ; Mon, 22 Nov 2021 23:58:44 +0200 (EET) Received: by mail-io1-f50.google.com with SMTP id x10so25337017ioj.9 for ; Mon, 22 Nov 2021 13:58:44 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rcombs.me; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=zz+HQHPSZK+EjF/L2hCcqBg66cCuZTNzMLSYw+djs8Y=; b=Nj0Zdc0KY5TCLf/K4fia3FEHij8gfrbDmntTNSjTTs7g/jPVfGSp5a3j/wTA7aBb83 Wbb0A1QJhGlCTPujdFBIwIFqu4NkZiKMMnyfhD98hqJj6+dAOlHh9ehL2Mm5Cv5CgGSN 9QVP/TdvwiYNT5AEOGTkVUb1gC5o0AgWO+9A83BKjd+NTobYox1t3QOwWzU2zuDUR/2g VqrDeU885vCsJPuA2w6ET5knlHSQ/YcnMMI1mIQS9mC1I/TJQZfKdHDVurXpaCS771ck 9iszznAdAnxBIIP8g+xxsWcb8bNCsocXXZBMZjmj6pde4RAZRFi/jREUlVkRm30S70mI +u+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=zz+HQHPSZK+EjF/L2hCcqBg66cCuZTNzMLSYw+djs8Y=; b=tnfVceyMJ/K/2rb96VErrcEQSjfIPjAL07BilWZrxfrotXVO4ooBm8VJlAx8jqX/eL aIJjrmYrb2e7cKBX4KX4R6C3v+zO/ZxyoWyJo7aTm3GBUCJgI1Ye1O7TdHY/qRA5QZC1 IcJWKbGqT9Aydr/LSZeNPR2JGgiXB0Ph8/uJiuYf+x22LkuJ1DslNXjEChT3Ob2LTp72 hKokJDslwOdfOiX6OkPOAow8S4IZwgPdqHHFHcYnliH4qs9dAx8fUlHSqgg/I8ATSiJr XHDqr9cuVaD2ICVxbgxTM8OjcQHSpIXwkQJ0M1Cf7sA1bWTKHbcMHa7GDV4W3TiQz/5j R9yg== X-Gm-Message-State: AOAM531VNXwTTJ2XLGH6yjuB6grUPel/uS6F24eZQPdEB37narE+Bf/R cdHZtHIwMYu0V49DhGeQ4QajN+lniHpPbfQ= X-Received: by 2002:a05:6602:1604:: with SMTP id x4mr107813iow.84.1637618322766; Mon, 22 Nov 2021 13:58:42 -0800 (PST) Received: from rcombs-mbp.localdomain ([2601:243:2000:5ac:edf5:499:2479:42a8]) by smtp.gmail.com with ESMTPSA id o1sm5668802ilj.41.2021.11.22.13.58.42 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Nov 2021 13:58:42 -0800 (PST) From: rcombs To: ffmpeg-devel@ffmpeg.org Date: Mon, 22 Nov 2021 15:58:19 -0600 Message-Id: <20211122215821.9849-14-rcombs@rcombs.me> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211122215821.9849-1-rcombs@rcombs.me> References: <20211122215821.9849-1-rcombs@rcombs.me> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 14/16] lavc/proresdec: add scaffolding for hwdec support X-BeenThere: ffmpeg-devel@ffmpeg.org X-Mailman-Version: 2.1.29 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: cgj0+Ol/OJaS --- libavcodec/proresdec.h | 1 + libavcodec/proresdec2.c | 48 ++++++++++++++++++++++++++++++++++------- 2 files changed, 41 insertions(+), 8 deletions(-) diff --git a/libavcodec/proresdec.h b/libavcodec/proresdec.h index 06e41dd09a..1e48752e6f 100644 --- a/libavcodec/proresdec.h +++ b/libavcodec/proresdec.h @@ -52,6 +52,7 @@ typedef struct { int first_field; int alpha_info; void (*unpack_alpha)(GetBitContext *gb, uint16_t *dst, int num_coeffs, const int num_bits); + enum AVPixelFormat pix_fmt; } ProresContext; #endif /* AVCODEC_PRORESDEC_H */ diff --git a/libavcodec/proresdec2.c b/libavcodec/proresdec2.c index 7750620b22..5b1d7da693 100644 --- a/libavcodec/proresdec2.c +++ b/libavcodec/proresdec2.c @@ -187,6 +187,8 @@ static av_cold int decode_init(AVCodecContext *avctx) permute(ctx->progressive_scan, ff_prores_progressive_scan, idct_permutation); permute(ctx->interlaced_scan, ff_prores_interlaced_scan, idct_permutation); + ctx->pix_fmt = AV_PIX_FMT_NONE; + if (avctx->bits_per_raw_sample == 10){ ctx->unpack_alpha = unpack_alpha_10; } else if (avctx->bits_per_raw_sample == 12){ @@ -204,6 +206,7 @@ static int decode_frame_header(ProresContext *ctx, const uint8_t *buf, int hdr_size, width, height, flags; int version; const uint8_t *ptr; + enum AVPixelFormat pix_fmt; hdr_size = AV_RB16(buf); ff_dlog(avctx, "header size %d\n", hdr_size); @@ -252,18 +255,34 @@ static int decode_frame_header(ProresContext *ctx, const uint8_t *buf, if (ctx->alpha_info) { if (avctx->bits_per_raw_sample == 10) { - avctx->pix_fmt = (buf[12] & 0xC0) == 0xC0 ? AV_PIX_FMT_YUVA444P10 : AV_PIX_FMT_YUVA422P10; + pix_fmt = (buf[12] & 0xC0) == 0xC0 ? AV_PIX_FMT_YUVA444P10 : AV_PIX_FMT_YUVA422P10; } else { /* 12b */ - avctx->pix_fmt = (buf[12] & 0xC0) == 0xC0 ? AV_PIX_FMT_YUVA444P12 : AV_PIX_FMT_YUVA422P12; + pix_fmt = (buf[12] & 0xC0) == 0xC0 ? AV_PIX_FMT_YUVA444P12 : AV_PIX_FMT_YUVA422P12; } } else { if (avctx->bits_per_raw_sample == 10) { - avctx->pix_fmt = (buf[12] & 0xC0) == 0xC0 ? AV_PIX_FMT_YUV444P10 : AV_PIX_FMT_YUV422P10; + pix_fmt = (buf[12] & 0xC0) == 0xC0 ? AV_PIX_FMT_YUV444P10 : AV_PIX_FMT_YUV422P10; } else { /* 12b */ - avctx->pix_fmt = (buf[12] & 0xC0) == 0xC0 ? AV_PIX_FMT_YUV444P12 : AV_PIX_FMT_YUV422P12; + pix_fmt = (buf[12] & 0xC0) == 0xC0 ? AV_PIX_FMT_YUV444P12 : AV_PIX_FMT_YUV422P12; } } + if (pix_fmt != ctx->pix_fmt) { +#define HWACCEL_MAX 0 + enum AVPixelFormat pix_fmts[HWACCEL_MAX + 2], *fmtp = pix_fmts; + int ret; + + ctx->pix_fmt = pix_fmt; + + *fmtp++ = ctx->pix_fmt; + *fmtp = AV_PIX_FMT_NONE; + + if ((ret = ff_thread_get_format(avctx, pix_fmts)) < 0) + return ret; + + avctx->pix_fmt = ret; + } + avctx->color_primaries = buf[14]; avctx->color_trc = buf[15]; avctx->colorspace = buf[16]; @@ -782,6 +801,22 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, buf += frame_hdr_size; buf_size -= frame_hdr_size; + if ((ret = ff_thread_get_buffer(avctx, &tframe, 0)) < 0) + return ret; + + if (avctx->hwaccel) { + ret = avctx->hwaccel->start_frame(avctx, NULL, 0); + if (ret < 0) + return ret; + ret = avctx->hwaccel->decode_slice(avctx, avpkt->data, avpkt->size); + if (ret < 0) + return ret; + ret = avctx->hwaccel->end_frame(avctx); + if (ret < 0) + return ret; + goto finish; + } + decode_picture: pic_size = decode_picture_header(avctx, buf, buf_size); if (pic_size < 0) { @@ -789,10 +824,6 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, return pic_size; } - if (ctx->first_field) - if ((ret = ff_thread_get_buffer(avctx, &tframe, 0)) < 0) - return ret; - if ((ret = decode_picture(avctx)) < 0) { av_log(avctx, AV_LOG_ERROR, "error decoding picture\n"); return ret; @@ -806,6 +837,7 @@ static int decode_frame(AVCodecContext *avctx, void *data, int *got_frame, goto decode_picture; } +finish: *got_frame = 1; return avpkt->size;