From patchwork Thu Feb 27 18:02:02 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: James Almer X-Patchwork-Id: 17943 Return-Path: X-Original-To: patchwork@ffaux-bg.ffmpeg.org Delivered-To: patchwork@ffaux-bg.ffmpeg.org Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by ffaux.localdomain (Postfix) with ESMTP id E3CB644B25D for ; Thu, 27 Feb 2020 20:03:24 +0200 (EET) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id CCF3F68B735; Thu, 27 Feb 2020 20:03:24 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail-qv1-f52.google.com (mail-qv1-f52.google.com [209.85.219.52]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id CFD1268B6F9 for ; Thu, 27 Feb 2020 20:03:17 +0200 (EET) Received: by mail-qv1-f52.google.com with SMTP id y8so1978480qvk.6 for ; Thu, 27 Feb 2020 10:03:17 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=O2BOu+PJytEU7lwXRwQ9br49UxDEwUOYnxWd1Wv31oI=; b=RREYLyzAtlEnvcMtbX6Vg8C/zKpE+w0UesH1qQlzzOHHcf8NDaO4WugUbBtRYfX/aU Ftvz3FNPnuPySsabY9mZYv/2eUIhsoheps/rv1PxRAauiuP+KVNb/DNOTwLYTg7in1zY C15sUdlXRTYw02w894oTiD4l3oJO3QKsBeoB+uN3dPSOOZan21QdLulXfMx8cXX5/gN+ iGeNi1Orklle9KxQJRsaUevOrncd9tJ75qAEvPtsyOUm/QaLa5Yz3+8OlMQ68a/1vosK KGaSLh+SrbEx0AzsdJjXQjdVrTPN2r9Ldk6d2S+Wj0wi3WkOsn5fAM/K5B1H8VgGePZ3 JwRQ== 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:mime-version:content-transfer-encoding; bh=O2BOu+PJytEU7lwXRwQ9br49UxDEwUOYnxWd1Wv31oI=; b=D/sCGFe9rN3/N02vNhWebwMSIawKpPhDYJgVot/Ll2Fl9VfH0O80Zb78bO9t4ytk/j 6SI2UBy99gR6qt0d47p+JbRubFJ7yxgLxzBZxcVh9TdagEcTllKvqxAIGRdfAwu3r3gs vTgaeZO1Qgbp0lrQdXgMwlZHazODVk0UPmSbr6ZlZGqhiVi45qDux7Uk1tqYwlRrTJDi l/kWTZEOvFL/179qBIuWsxWpv2PmhuDWPoPTL2MU11Gc0J+VAeST93FvPEGa2G2pTDhS DYtFY2Nn7D12v64b/XZz3nkKynvCW/H7+pQeSavF6zL0OIOCyXrA3OjHGVtfURaAWQIw p5KQ== X-Gm-Message-State: APjAAAUkkuWS3iwOQJIMjImm3ELeiLn1JypFdkd6MRd0aTtGLDMWzjIB SY3qih/RIk8ZLjIeTrfqGrrEIULY X-Google-Smtp-Source: APXvYqwN3ou/u4aq+bMOvK751uGNcSnUfQoSmVuuQhvy/VGjlOsGz/RkCF7MApziAG8y8ZcAIoGj9A== X-Received: by 2002:a05:6214:6f0:: with SMTP id bk16mr38102qvb.23.1582826595955; Thu, 27 Feb 2020 10:03:15 -0800 (PST) Received: from localhost.localdomain ([191.83.210.181]) by smtp.gmail.com with ESMTPSA id v80sm3523323qka.15.2020.02.27.10.03.14 for (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 27 Feb 2020 10:03:15 -0800 (PST) From: James Almer To: ffmpeg-devel@ffmpeg.org Date: Thu, 27 Feb 2020 15:02:02 -0300 Message-Id: <20200227180202.30982-5-jamrial@gmail.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200227180202.30982-1-jamrial@gmail.com> References: <20200227180202.30982-1-jamrial@gmail.com> MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 4/4] avcodec/librav1e: adapt to the new internal encode API 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 Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Signed-off-by: James Almer --- Must be squashed into PATCH 2/2 libavcodec/librav1e.c | 65 ++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 29 deletions(-) diff --git a/libavcodec/librav1e.c b/libavcodec/librav1e.c index b8b1b4f8f1..02e9c0902f 100644 --- a/libavcodec/librav1e.c +++ b/libavcodec/librav1e.c @@ -30,12 +30,14 @@ #include "libavutil/opt.h" #include "libavutil/pixdesc.h" #include "avcodec.h" +#include "encode.h" #include "internal.h" typedef struct librav1eContext { const AVClass *class; RaContext *ctx; + AVFrame *frame; AVBSFContext *bsf; uint8_t *pass_data; @@ -166,6 +168,7 @@ static av_cold int librav1e_encode_close(AVCodecContext *avctx) ctx->ctx = NULL; } + av_frame_free(&ctx->frame); av_bsf_free(&ctx->bsf); av_freep(&ctx->pass_data); @@ -180,6 +183,10 @@ static av_cold int librav1e_encode_init(AVCodecContext *avctx) int rret; int ret = 0; + ctx->frame = av_frame_alloc(); + if (!ctx->frame) + return AVERROR(ENOMEM); + cfg = rav1e_config_default(); if (!cfg) { av_log(avctx, AV_LOG_ERROR, "Could not allocate rav1e config.\n"); @@ -399,27 +406,36 @@ end: return ret; } -static int librav1e_send_frame(AVCodecContext *avctx, const AVFrame *frame) +static int librav1e_receive_packet(AVCodecContext *avctx, AVPacket *pkt) { librav1eContext *ctx = avctx->priv_data; + AVFrame *frame = ctx->frame; RaFrame *rframe = NULL; + RaPacket *rpkt = NULL; int ret; - if (frame) { - const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format); + if (!frame->buf[0]) { + const AVPixFmtDescriptor *desc; - rframe = rav1e_frame_new(ctx->ctx); - if (!rframe) { - av_log(avctx, AV_LOG_ERROR, "Could not allocate new rav1e frame.\n"); - return AVERROR(ENOMEM); - } + ret = ff_encode_get_frame(avctx, frame); + if (ret < 0 && ret != AVERROR_EOF) + return ret; - for (int i = 0; i < desc->nb_components; i++) { - int shift = i ? desc->log2_chroma_h : 0; - int bytes = desc->comp[0].depth == 8 ? 1 : 2; - rav1e_frame_fill_plane(rframe, i, frame->data[i], - (frame->height >> shift) * frame->linesize[i], - frame->linesize[i], bytes); + if (frame->buf[0]) { + rframe = rav1e_frame_new(ctx->ctx); + if (!rframe) { + av_log(avctx, AV_LOG_ERROR, "Could not allocate new rav1e frame.\n"); + return AVERROR(ENOMEM); + } + + desc = av_pix_fmt_desc_get(frame->format); + for (int i = 0; i < desc->nb_components; i++) { + int shift = i ? desc->log2_chroma_h : 0; + int bytes = desc->comp[0].depth == 8 ? 1 : 2; + rav1e_frame_fill_plane(rframe, i, frame->data[i], + (frame->height >> shift) * frame->linesize[i], + frame->linesize[i], bytes); + } } } @@ -427,28 +443,22 @@ static int librav1e_send_frame(AVCodecContext *avctx, const AVFrame *frame) if (rframe) rav1e_frame_unref(rframe); /* No need to unref if flushing. */ - switch (ret) { + switch(ret) { case RA_ENCODER_STATUS_SUCCESS: + av_frame_unref(frame); break; case RA_ENCODER_STATUS_ENOUGH_DATA: - return AVERROR(EAGAIN); + break; case RA_ENCODER_STATUS_FAILURE: av_log(avctx, AV_LOG_ERROR, "Could not send frame: %s\n", rav1e_status_to_str(ret)); + av_frame_unref(frame); return AVERROR_EXTERNAL; default: av_log(avctx, AV_LOG_ERROR, "Unknown return code %d from rav1e_send_frame: %s\n", ret, rav1e_status_to_str(ret)); + av_frame_unref(frame); return AVERROR_UNKNOWN; } - return 0; -} - -static int librav1e_receive_packet(AVCodecContext *avctx, AVPacket *pkt) -{ - librav1eContext *ctx = avctx->priv_data; - RaPacket *rpkt = NULL; - int ret; - retry: if (avctx->flags & AV_CODEC_FLAG_PASS1) { @@ -473,9 +483,7 @@ retry: } return AVERROR_EOF; case RA_ENCODER_STATUS_ENCODED: - if (avctx->internal->draining) - goto retry; - return AVERROR(EAGAIN); + goto retry; case RA_ENCODER_STATUS_NEED_MORE_DATA: if (avctx->internal->draining) { av_log(avctx, AV_LOG_ERROR, "Unexpected error when receiving packet after EOF.\n"); @@ -575,7 +583,6 @@ AVCodec ff_librav1e_encoder = { .type = AVMEDIA_TYPE_VIDEO, .id = AV_CODEC_ID_AV1, .init = librav1e_encode_init, - .send_frame = librav1e_send_frame, .receive_packet = librav1e_receive_packet, .close = librav1e_encode_close, .priv_data_size = sizeof(librav1eContext),