From patchwork Sat Nov 13 21:09:15 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Ridley Combs X-Patchwork-Id: 31404 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a6b:d206:0:0:0:0:0 with SMTP id q6csp3679259iob; Sat, 13 Nov 2021 13:11:28 -0800 (PST) X-Google-Smtp-Source: ABdhPJx/68yT2iys+k0k5hZOtPOKV/XVZbiyz02JP7P/9L/pjlH3WOExd4p7mUpmusc7wkbPyc6g X-Received: by 2002:a17:907:7d94:: with SMTP id oz20mr34658849ejc.410.1636837888141; Sat, 13 Nov 2021 13:11:28 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636837888; cv=none; d=google.com; s=arc-20160816; b=E/Z9KhT9YD9ZjcwOIGyMs+L5YdROQqgQ7v1AR1qFRV4doppivgX+V/QCBYf5kBKMd7 1iXDEw0aMlsvvLDBMLbYO5lkHunX6DYGVMAKbnblcP6M7oRpGezY4+ABUuW0M5wKjpWo lSMHIRd1i5i6goF7q7Od+QMf6gZ80mCZ8BcOWZgYfIM4ECMj1R6Q77J94NO06hZXzHV2 YiHv4aWFgV+GXiiE80p50LAuwdVxc1u2gk73dqwWm58V6bQJtFkoHWZf6ElOMzVLk8J8 5aHhBK6hXoB2WL59glbPuzSy52GRE+uH1ap3F00a2lUGvLNkiC5ikq/aLYNLTCiTasvb Lt7A== 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=SsTs1IkaRKrZQ5f/w1GajpVmaEMRCMKl2Ug1/vpWmuXx0gFPS3mFIE1Fr2IJkDtzO1 1lhC6Zn0PPkZNFeQsjDyWcpXmTTJ1bYmiWk/xwe6KAMzWJEb3HXAjQfArZWXb8UmdJG/ /4RyF86U77NrWmctWiHsiNPwRwcrevdv8+SvO4SYy9pgB/huMf9AULp3YKJl4Aw3KG9X 7ZDD1VqHcbLuAeZKCfFw6J+6+BwiG7gKKDv/AadWbtViU58EPGkguyjYrUjiefAHeIOk dcjk4i3mERvWm4aQeAa5CP3SU2nR9myH+oyTGho+85KZSgyuvT84TlBhY1JIMVwLu+Al mvvQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=neutral (body hash did not verify) header.i=@rcombs.me header.s=google header.b="ghEL7/he"; 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 p15si22347104edj.97.2021.11.13.13.11.27; Sat, 13 Nov 2021 13:11:28 -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="ghEL7/he"; 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 1A3B368ACAB; Sat, 13 Nov 2021 23:09:41 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-il1-f174.google.com (mail-il1-f174.google.com [209.85.166.174]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 2BF6E68AE52 for ; Sat, 13 Nov 2021 23:09:34 +0200 (EET) Received: by mail-il1-f174.google.com with SMTP id s15so12409313ild.9 for ; Sat, 13 Nov 2021 13:09:34 -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=ghEL7/hen7ZY9sBAB2ahcUy4SNWucrtsJ5YfcF3KxKXQT+3MOyfTdSx259IUr3FqN2 TB1JjZfD4OA2rHNtLfFBw8k+RPW2pMv8yhHbh0pfpCi4nkmHFPZ+5cTZYfQcsHB9++vo 1WaGRLmKdmp5/qzaYx3/TUQ7OA3AqnDp5OnTm1MPOavPavVuwMWIromgs90yjukwVZ60 mAHsdi75SqVPX01LQxZO7/Xsa+x15ukaarTdaYPBRC3g3NFkYQYGmUpkQKw+R0NgAA9s cGz25s+3FIQV41wnNaQQLP1ZgbdMBKMky6/XR19L5AD5Q6NIemo6Emco71Ra2wi/UHMJ j/wg== 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=gr7xQ2RZuU4zmiUQI2328qeVoJVlPbE7Y6IWPMgBW09ZF6Hl+zwcO+qTsn8i4hP4AH x4yEi/4oD4clBHfjhkUNlb/wgZbdxb7+JgyPX8CBSdW6Ax2JZuF3hMSlJii9HurG2SmJ Q3oq/bVHtxcK1xz8zjvO0PlZQHbyxduHlDhl21OxPcyOiNMW7WmUsp3YtL0IAHqiFZLI CeCD+jxWYvuUXh9UA+14oiBIwGP4Hd+0joW5HESXqsgJp+5Yas8RMZS3gZTnWKNCU/Hv bCbBk1jv2QsUW4nbS/svhDecqbMcN1EnxTozOLWJgJXlx+m+UtXbGx9ylJL4lIOAo+o/ jvjA== X-Gm-Message-State: AOAM531pLXezo52sftloJMg2p7NhWJJ2KX/p94qNCzTTS6pzWdC3ETa5 ypQXh1JWJdKjttH3335ApQNBo1G7F+kqJHk= X-Received: by 2002:a05:6e02:1bed:: with SMTP id y13mr14243885ilv.279.1636837772523; Sat, 13 Nov 2021 13:09:32 -0800 (PST) Received: from rcombs-mbp.localdomain ([2601:243:2000:5ac:516:f322:7db9:ae0a]) by smtp.gmail.com with ESMTPSA id j23sm5243896iog.53.2021.11.13.13.09.31 for (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Sat, 13 Nov 2021 13:09:32 -0800 (PST) From: rcombs To: ffmpeg-devel@ffmpeg.org Date: Sat, 13 Nov 2021 15:09:15 -0600 Message-Id: <20211113210916.49167-14-rcombs@rcombs.me> X-Mailer: git-send-email 2.33.1 In-Reply-To: <20211113210916.49167-1-rcombs@rcombs.me> References: <20211113210916.49167-1-rcombs@rcombs.me> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 14/15] 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: s4aME1qXNv9b --- 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;