From patchwork Sun Nov 27 17:03:22 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Anton Khirnov X-Patchwork-Id: 39492 Delivered-To: ffmpegpatchwork2@gmail.com Received: by 2002:a05:6a21:999a:b0:a4:2148:650a with SMTP id ve26csp6959046pzb; Sun, 27 Nov 2022 09:06:03 -0800 (PST) X-Google-Smtp-Source: AA0mqf7jCNsrA0FF/SfNcjeefCpGca8mTTpMmSbc+rGqc+R0XY/TYitu49v84k1kZ6hi42VxC4YS X-Received: by 2002:a17:906:1412:b0:7a0:3313:a775 with SMTP id p18-20020a170906141200b007a03313a775mr30468426ejc.474.1669568763612; Sun, 27 Nov 2022 09:06:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669568763; cv=none; d=google.com; s=arc-20160816; b=r8lHDqKgtVT0PiDF9ZjKbQ79Mn/cIuiuAg5InpoBg1I25YVivz6f7Pmg1VCJetWhX0 9g00vHv4bdpPUzSpl6ruQPSMPo09ASyIHfwA7tg1hO4uvoCpYZtSYQOajlSljFZf2mYU 6Le8ug2CsmHu3IPnS9Z06mqojyjlCwxbdRtXQ1ebMNc8FHrrTi2SeB1XbwchXseIfk5O V7hnGAG4AdUSoCRjKssphyIanpezPZ+YvOBIZC28tTHdyThejTzG2mudUuhAPDgrbXOM qxusfXUYgOHqadIRR2gxhpp4rvDDynee/K0JQ1akMZ8Ca1Y3zaTZHvJpPCykL2QXDGpr c42A== 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:message-id:date:to:from :delivered-to; bh=F+rrUV0a0YT15G3deF8EYjGPEkC2cp9PTYca0kimLoc=; b=oRf5U93iPiQkleoJFjTL0/VDmbtLzGKMw0leSQoy/R5+xHpl9QFIqikjMFs+94BlnS f4CAI3le+BWuAHJL21SzhXggnkteuMZo59LF5p8jcsTpoxEctjy9zce6oCUrNsICN8Ou gXZmgq6n0490cmOR0dThdR7lPI2fPrNbXnoeuCfbwPGaaPxMqMjyBbys0L4+UHDyzHoB dJpYIPfKcNxfSFCHQ4PNsbIqvEs9qHGQk+0kY8TLSqxa7uMjjRqqKtNzhOjZ0jljbTR0 D2Tk/z+fXFqDCdu7qubkCu+qR3L4cq7K6xk5z8ZnBLCbWgx8lUVSLT58RXx4p8Q2bjeE Af0Q== 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 sc34-20020a1709078a2200b007808f3f4cbcsi9706843ejc.239.2022.11.27.09.06.03; Sun, 27 Nov 2022 09:06:03 -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; 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 5E7EC68B724; Sun, 27 Nov 2022 19:05:59 +0200 (EET) X-Original-To: ffmpeg-devel@ffmpeg.org Delivered-To: ffmpeg-devel@ffmpeg.org Received: from mail0.khirnov.net (red.khirnov.net [176.97.15.12]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTPS id 3D87D6808AB for ; Sun, 27 Nov 2022 19:05:53 +0200 (EET) Received: from localhost (localhost [IPv6:::1]) by mail0.khirnov.net (Postfix) with ESMTP id 4A4F0240D23 for ; Sun, 27 Nov 2022 18:05:52 +0100 (CET) Received: from mail0.khirnov.net ([IPv6:::1]) by localhost (mail0.khirnov.net [IPv6:::1]) (amavisd-new, port 10024) with ESMTP id b9rpZf8mRurn for ; Sun, 27 Nov 2022 18:05:51 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:2a00:c500:561:201::7]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange X25519 server-signature RSA-PSS (2048 bits) server-digest SHA256 client-signature RSA-PSS (2048 bits) client-digest SHA256) (Client CN "libav.khirnov.net", Issuer "smtp.khirnov.net SMTP CA" (verified OK)) by mail0.khirnov.net (Postfix) with ESMTPS id 5E2AF2400F5 for ; Sun, 27 Nov 2022 18:05:51 +0100 (CET) Received: from libav.khirnov.net (libav.khirnov.net [IPv6:::1]) by libav.khirnov.net (Postfix) with ESMTP id C60313A0D91 for ; Sun, 27 Nov 2022 18:05:45 +0100 (CET) From: Anton Khirnov To: ffmpeg-devel@ffmpeg.org Date: Sun, 27 Nov 2022 18:03:22 +0100 Message-Id: <20221127170351.11477-1-anton@khirnov.net> X-Mailer: git-send-email 2.35.1 MIME-Version: 1.0 Subject: [FFmpeg-devel] [PATCH 01/30] lavc/libx264: factor out setting up the input frame 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: HPLk+fwbAGUq X264_frame() is currently too large and complex. --- libavcodec/libx264.c | 45 +++++++++++++++++++++++++++++--------------- 1 file changed, 30 insertions(+), 15 deletions(-) diff --git a/libavcodec/libx264.c b/libavcodec/libx264.c index ca0b5a145b..009cad4bdf 100644 --- a/libavcodec/libx264.c +++ b/libavcodec/libx264.c @@ -333,19 +333,20 @@ static enum AVPixelFormat csp_to_pixfmt(int csp) return AV_PIX_FMT_NONE; } -static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame, - int *got_packet) +static int setup_frame(AVCodecContext *ctx, const AVFrame *frame, + x264_picture_t **ppic) { X264Context *x4 = ctx->priv_data; - x264_nal_t *nal; - int nnal, i, ret; - x264_picture_t pic_out = {0}; - int pict_type; - int bit_depth; + x264_sei_t *sei = &x4->pic.extra_sei; + unsigned int sei_data_size = 0; int64_t wallclock = 0; - X264Opaque *out_opaque; + int bit_depth, ret; AVFrameSideData *sd; + *ppic = NULL; + if (!frame) + return 0; + x264_picture_init( &x4->pic ); x4->pic.img.i_csp = x4->params.i_csp; #if X264_BUILD >= 153 @@ -357,11 +358,7 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame, x4->pic.img.i_csp |= X264_CSP_HIGH_DEPTH; x4->pic.img.i_plane = avfmt2_num_planes(ctx->pix_fmt); - if (frame) { - x264_sei_t *sei = &x4->pic.extra_sei; - unsigned int sei_data_size = 0; - - for (i = 0; i < x4->pic.img.i_plane; i++) { + for (int i = 0; i < x4->pic.img.i_plane; i++) { x4->pic.img.plane[i] = frame->data[i]; x4->pic.img.i_stride[i] = frame->linesize[i]; } @@ -512,10 +509,28 @@ static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame, sei->num_payloads++; } } - } + + *ppic = &x4->pic; + return 0; +} + +static int X264_frame(AVCodecContext *ctx, AVPacket *pkt, const AVFrame *frame, + int *got_packet) +{ + X264Context *x4 = ctx->priv_data; + x264_nal_t *nal; + int nnal, ret; + x264_picture_t pic_out = {0}, *pic_in; + int pict_type; + int64_t wallclock = 0; + X264Opaque *out_opaque; + + ret = setup_frame(ctx, frame, &pic_in); + if (ret < 0) + return ret; do { - if (x264_encoder_encode(x4->enc, &nal, &nnal, frame? &x4->pic: NULL, &pic_out) < 0) + if (x264_encoder_encode(x4->enc, &nal, &nnal, pic_in, &pic_out) < 0) return AVERROR_EXTERNAL; if (nnal && (ctx->flags & AV_CODEC_FLAG_RECON_FRAME)) {