From patchwork Mon Nov 22 20:53:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ridley Combs X-Patchwork-Id: 31541 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp7584924iob; Mon, 22 Nov 2021 12:56:06 -0800 (PST) X-Google-Smtp-Source: ABdhPJwnqol4XRlUUFPJCouSM7qY4LySaUfHRIL0+VgH3ytUPCclK5EbfXshW+iwxERKMNL/dYFH X-Received: by 2002:a17:906:fcba:: with SMTP id qw26mr146589ejb.448.1637614566250; Mon, 22 Nov 2021 12:56:06 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1637614566; cv=none; d=google.com; s=arc-20160816; b=AwkmUKXS8R/R4e2MzxzRVzDe0CKWeO+ziuHFi1VlPdSmnZdPtCDtB1XQn82U1n+NBs Ukh3C6UAaC2jaYdP6OcNI3y4g5o/lir2AQ/aPzqzxXYS0eoJzHkP26ReLcOIrPYshp6A WxW/LF7M+CbeLgWjgTwQYvIFVhe2vDYaIorVUxFXtxq2slhfY0ltxBWoFUZrlGG789VC 2UiMendBopt/TYl9xK3q/B06uKBwErq05Sdi3IlvUcN/+uJT4PZYVuQdbLrRxOEf/xU0 WaR3oEJqntNPMTasEA57GkvemNwHMIY6ckX/l0OYY0IdG28ju12DuB00B4z8jEcZPf/Z 32Og== 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=KIKC4iBBfvvd14X8eDTrYYGdL6e+NsLg/BCUhDFlxuFUeNjX0dTN26xT6aP1pckws/ KkmkClzgbfLFVxghbdYKHeaMafEwsUwl3oPveHg8AvWbUtNudY5mcadmdFKfeBFoeTvU oUYBJme11qxFeq7eqH+SzNCb4RpxBira8/d76AUX1Oi6V/16I33eAwVp21I39gFNX2T0 JKBtneajGB+nEhK2vIwhQV0uE+4NexhU7Irs3n7bdO8YHPpn1PLEtFy4IrF6Mm+DPhB6 HeANcm4Iik7O6HfLYIZM7QkGSSYXuH/oGx7eUi9sx/zhmy6wtvRFvwwRQzCWseEL4LWH yv2Q== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@rcombs.me header.s=google header.b=EWu+tJKg; 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 l10si29910101ejo.308.2021.11.22.12.56.05; Mon, 22 Nov 2021 12:56:06 -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=EWu+tJKg; 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 18FE968A8EE; Mon, 22 Nov 2021 22:53:56 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-io1-f52.google.com (mail-io1-f52.google.com [209.85.166.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 8FF3068AA67 for ; Mon, 22 Nov 2021 22:53:47 +0200 (EET) Received: by mail-io1-f52.google.com with SMTP id f9so24953403ioo.11 for ; Mon, 22 Nov 2021 12:53:47 -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=EWu+tJKgwS8YM4E2GzZVQO7VrmHiOY6gzAfxyVM1QhWBWVih1n1pZ8FJuAvTJ5nssI 1lQceMd3+1qLkT+1URmUt4ezLxWR3fOdelHlUnuKVztt53az23x9QaKLVb4eA+K1bVmb ZmqoGjun4HN5n5N9MdG3ADupSpJTIdkhhm5BXHU29o1Rya8VroCl5xSF/HfqPFI21bZW WK7FLcmdMldOuf45JSIr9kiEfJrc8nyL+h+RHUXnoy3ppMFFTei5nJqJqse2JYBcgMHl wb0mYQTAZhVKW45PmEeQ7fNsq2/Pl4iW/5E96NYUqU6r2QCD66HorWWeTgqNnsK1XCXM j/fQ== 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=Ugkt1LB4KcCishru6rTedq/UC0GxcApPyOl4VsCU3WGrDetkVd2gUGgt52Z8AARUp4 NbRbg4pBRra4wNCrB2ZYyGg/JW8fsUL58hn+R+Gtsj4Y/YJ09J3Mahps037zocQpOViI xKMLPlitsvxzjUBRnDIMC/j3nhot456EdKDBm9ORnmOn/oh/109aC0qn4BxQqWrWug5E 0hhlsPLvLMlie4Q8+0P4vi0G/usuXcE1jZIKc+jkkWdE3KbipXBcDsjnPwvhAE7P1H9v hFOUVvmUdbnpiuIdZlrr+HuKh2wK0+0DMe7+w7oe10PkWmn/sBJ15yCG+zhULkqpBLUb s/EA== X-Gm-Message-State: AOAM532LygK6AVIq9yIYC9O1F7DBJ+Hob4Vrc/IiP1PmYT1PanIthIlM +RiW2NsAKvjTO3AwwMe1hco58sueRa60hxE= X-Received: by 2002:a05:6602:2c07:: with SMTP id w7mr25595898iov.122.1637614425903; Mon, 22 Nov 2021 12:53:45 -0800 (PST) Received: from rcombs-mbp.localdomain ([2601:243:2000:5ac:edf5:499:2479:42a8]) by smtp.gmail.com with ESMTPSA id b3sm3571580ile.26.2021.11.22.12.53.44 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Mon, 22 Nov 2021 12:53:45 -0800 (PST) From: rcombs To: ffmpeg-devel@ffmpeg.org Date: Mon, 22 Nov 2021 14:53:28 -0600 Message-Id: <20211122205330.43546-14-rcombs@rcombs.me> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211122205330.43546-1-rcombs@rcombs.me> References: <20211122205330.43546-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: tC0lEUoXTBY/ --- 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;