From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from ffbox0-bg.mplayerhq.hu (ffbox0-bg.ffmpeg.org [79.124.17.100]) by master.gitmailbox.com (Postfix) with ESMTP id 9D6A34413E for ; Sun, 27 Nov 2022 17:06:01 +0000 (UTC) Received: from [127.0.1.1] (localhost [127.0.0.1]) by ffbox0-bg.mplayerhq.hu (Postfix) with ESMTP id 26B9668B6F2; Sun, 27 Nov 2022 19:05:59 +0200 (EET) 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 Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Errors-To: ffmpeg-devel-bounces@ffmpeg.org Sender: "ffmpeg-devel" Archived-At: List-Archive: List-Post: 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)) { -- 2.35.1 _______________________________________________ ffmpeg-devel mailing list ffmpeg-devel@ffmpeg.org https://ffmpeg.org/mailman/listinfo/ffmpeg-devel To unsubscribe, visit link above, or email ffmpeg-devel-request@ffmpeg.org with subject "unsubscribe".