From patchwork Wed Mar 15 23:34:43 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Michael Niedermayer X-Patchwork-Id: 40690 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a20:d046:b0:cd:afd7:272c with SMTP id hv6csp3840341pzb; Wed, 15 Mar 2023 16:34:58 -0700 (PDT) X-Google-Smtp-Source: AK7set++8AI3v+FmsjhAO8xmJakqLOGyjLFuPM8SODcDvWzyIStGVqFcr+CMn1bqdyrLY21+G5AV X-Received: by 2002:a17:906:fe05:b0:930:1391:da7c with SMTP id wy5-20020a170906fe0500b009301391da7cmr1163472ejb.60.1678923298574; Wed, 15 Mar 2023 16:34:58 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1678923298; cv=none; d=google.com; s=arc-20160816; b=JIuoZcWX52ktIeUAFweqCEcb5DYpXO/0lFkivAY94FgYZcDI0guhW89wJa4eIEICbc Qall1c1UTQ9hY1rIoOrU5louAyhnxBLsEZd10J35lJxYrUgaRrYAgDk5Pk0rjBMM1LaJ H17dhnrffGcF4jONecXx1tiib2KkR6ZWinAPPRvxxhjgOO7wuo3RP0QW01H4ucOyVwh4 GwiZ3BdXvzDUoiMO+ne1JJYfgS5L+ZaCBccUoJH9GZJyF14wC5Ll/HMEAFfFCD1SIfOt JhVnAR4Y1DMdqPPVbv3xeL6JYpkhTbC15iX3Ury8eGeq+sGXiHxK4urPsAdOj634yCvH QrIw== 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:message-id:date:to:from:delivered-to; bh=3nVEyDONm2/8VU9F2mHz4eNQ9PUTqxW6dBZsIg6NwXM=; b=q7RbIT1sN30iS4HAP8gGmmo1OU213P6cINeXkqU8Hf03Zn8lrwJ9MYyXNE63cxmmDc aS5i0UQt/SBijyBwjSzHJT/SvwabjKKVp1ji/9I/cD3ninaVpZejNCetYPAwz9Bu8Ten flBZRKyPiFoiibuB3D7w5BHpxbvmCEoS0S4Ni3akDbQAsTwV7J0g/iPQn6Rtpq63E4em bNeRkytsmKd1NwkWif38cL47jlNMDLKTHPw8DxTa6cXzyitoGyrxZkvCQeyzTeboN8K1 NQdADlsUZoWnfSdPjlGvlKFoCRPz1AKfCvozatOsw/11behqCth98wCbiLpIWs98Vnyq bFyw== ARC-Authentication-Results: i=1; mx.google.com; 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 ga16-20020a1709070c1000b0092ec42d6a30si4361181ejc.407.2023.03.15.16.34.57; Wed, 15 Mar 2023 16:34:58 -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; 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 24EF868BCE6; Thu, 16 Mar 2023 01:34:54 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from relay4-d.mail.gandi.net (relay4-d.mail.gandi.net [217.70.183.196]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 61FD468AD1B for ; Thu, 16 Mar 2023 01:34:47 +0200 (EET) Received: (Authenticated sender: michael@niedermayer.cc) by mail.gandi.net (Postfix) with ESMTPSA id 37BADE0008 for ; Wed, 15 Mar 2023 23:34:45 +0000 (UTC) From: Michael Niedermayer To: FFmpeg development discussions and patches Date: Thu, 16 Mar 2023 00:34:43 +0100 Message-Id: <20230315233445.5282-1-michael@niedermayer.cc> X-Mailer: git-send-email 2.17.1 Subject: [FFmpeg-devel] [PATCH 1/3] avfilter/vf_uspp: update to new APIs 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 MIME-Version: 1.0 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" X-TUID: OOSeP/Pi93Bb Signed-off-by: Michael Niedermayer --- configure | 1 - libavfilter/vf_uspp.c | 49 ++++++++++++++++++++++++++++++++++++------- 2 files changed, 41 insertions(+), 9 deletions(-) diff --git a/configure b/configure index 03d3c429a5..0370e25577 100755 --- a/configure +++ b/configure @@ -7359,7 +7359,6 @@ enable frame_thread_encoder # they are kept disabled for now, but will be removed if # nobody updates and re-enables them disable mcdeint_filter -disable uspp_filter enabled asm || { arch=c; disable $ARCH_LIST $ARCH_EXT_LIST; } diff --git a/libavfilter/vf_uspp.c b/libavfilter/vf_uspp.c index 051de00771..43114e1b50 100644 --- a/libavfilter/vf_uspp.c +++ b/libavfilter/vf_uspp.c @@ -53,6 +53,7 @@ typedef struct USPPContext { int outbuf_size; uint8_t *outbuf; AVCodecContext *avctx_enc[BLOCK*BLOCK]; + AVCodecContext *avctx_dec[BLOCK*BLOCK]; AVPacket *pkt; AVFrame *frame; AVFrame *frame_dec; @@ -244,7 +245,6 @@ static void filter(USPPContext *p, uint8_t *dst[3], uint8_t *src[3], const int BLOCKc = BLOCK >> p->hsub; int offset; AVPacket *pkt = p->pkt; - int got_pkt_ptr; av_packet_unref(pkt); pkt->data = p->outbuf; @@ -255,14 +255,28 @@ static void filter(USPPContext *p, uint8_t *dst[3], uint8_t *src[3], p->frame->data[2] = p->src[2] + x1c + y1c * p->frame->linesize[2]; p->frame->format = p->avctx_enc[i]->pix_fmt; - ret = avcodec_encode_video2(p->avctx_enc[i], pkt, p->frame, &got_pkt_ptr); + ret = avcodec_send_frame(p->avctx_enc[i], p->frame); if (ret < 0) { - av_log(p->avctx_enc[i], AV_LOG_ERROR, "Encoding failed\n"); + av_log(p->avctx_enc[i], AV_LOG_ERROR, "Error sending a frame for encoding\n"); + continue; + } + ret = avcodec_receive_packet(p->avctx_enc[i], pkt); + if (ret < 0) { + av_log(p->avctx_enc[i], AV_LOG_ERROR, "Error receiving a packet from encoding\n"); continue; } - av_packet_unref(pkt); - p->frame_dec = p->avctx_enc[i]->coded_frame; + ret = avcodec_send_packet(p->avctx_dec[i], pkt); + av_packet_unref(pkt); + if (ret < 0) { + av_log(p->avctx_dec[i], AV_LOG_ERROR, "Error sending a packet for decoding\n"); + continue; + } + ret = avcodec_receive_frame(p->avctx_dec[i], p->frame_dec); + if (ret < 0) { + av_log(p->avctx_dec[i], AV_LOG_ERROR, "Error receiving a frame from decoding\n"); + continue; + } offset = (BLOCK-x1) + (BLOCK-y1) * p->frame_dec->linesize[0]; @@ -315,10 +329,15 @@ static int config_input(AVFilterLink *inlink) int i; const AVCodec *enc = avcodec_find_encoder(AV_CODEC_ID_SNOW); + const AVCodec *dec = avcodec_find_decoder(AV_CODEC_ID_SNOW); if (!enc) { av_log(ctx, AV_LOG_ERROR, "SNOW encoder not found.\n"); return AVERROR(EINVAL); } + if (!dec) { + av_log(ctx, AV_LOG_ERROR, "SNOW decoder not found.\n"); + return AVERROR(EINVAL); + } uspp->hsub = desc->log2_chroma_w; uspp->vsub = desc->log2_chroma_h; @@ -341,15 +360,20 @@ static int config_input(AVFilterLink *inlink) } for (i = 0; i < (1<log2_count); i++) { - AVCodecContext *avctx_enc; + AVCodecContext *avctx_enc, *avctx_dec; AVDictionary *opts = NULL; int ret; if (!(uspp->avctx_enc[i] = avcodec_alloc_context3(NULL))) return AVERROR(ENOMEM); + if (!(uspp->avctx_dec[i] = avcodec_alloc_context3(NULL))) + return AVERROR(ENOMEM); avctx_enc = uspp->avctx_enc[i]; + avctx_dec = uspp->avctx_dec[i]; + avctx_dec->width = avctx_enc->width = width + BLOCK; + avctx_dec->height = avctx_enc->height = height + BLOCK; avctx_enc->time_base = (AVRational){1,25}; // meaningless avctx_enc->gop_size = INT_MAX; @@ -358,17 +382,24 @@ static int config_input(AVFilterLink *inlink) avctx_enc->flags = AV_CODEC_FLAG_QSCALE | AV_CODEC_FLAG_LOW_DELAY; avctx_enc->strict_std_compliance = FF_COMPLIANCE_EXPERIMENTAL; avctx_enc->global_quality = 123; - av_dict_set(&opts, "no_bitstream", "1", 0); ret = avcodec_open2(avctx_enc, enc, &opts); av_dict_free(&opts); if (ret < 0) return ret; av_assert0(avctx_enc->codec); + + + ret = avcodec_open2(avctx_dec, dec, NULL); + if (ret < 0) + return ret; + } uspp->outbuf_size = (width + BLOCK) * (height + BLOCK) * 10; if (!(uspp->frame = av_frame_alloc())) return AVERROR(ENOMEM); + if (!(uspp->frame_dec = av_frame_alloc())) + return AVERROR(ENOMEM); if (!(uspp->pkt = av_packet_alloc())) return AVERROR(ENOMEM); if (!(uspp->outbuf = av_malloc(uspp->outbuf_size))) @@ -460,8 +491,10 @@ static av_cold void uninit(AVFilterContext *ctx) av_freep(&uspp->src[i]); } - for (i = 0; i < (1 << uspp->log2_count); i++) + for (i = 0; i < (1 << uspp->log2_count); i++) { avcodec_free_context(&uspp->avctx_enc[i]); + avcodec_free_context(&uspp->avctx_dec[i]); + } av_freep(&uspp->non_b_qp_table); av_freep(&uspp->outbuf);