summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAnton Khirnov <anton@khirnov.net>2022-11-27 10:19:20 +0100
committerAnton Khirnov <anton@khirnov.net>2022-11-28 10:34:10 +0100
commitef0ed45040b30a4116119f703b0d8d3e11fb64de (patch)
treef489fe7a2f07d4fe24ca7a5bc553f8550549e9fc
parent14c14662b2955bac9c9bdcebe2f5b1da187f82cf (diff)
lavc/libx264: factor out setting up the input frame
X264_frame() is currently too large and complex.
-rw-r--r--libavcodec/libx264.c45
1 files 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)) {