From 8f5523200a086f092218e87ca2f2b3aeebd040b8 Mon Sep 17 00:00:00 2001 From: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> Date: Sat, 1 Mar 2025 23:37:50 +0100 Subject: [PATCH 07/77] avcodec/h261enc: Make h261_encode_init() call ff_mpv_encode_init() Right now, ff_mpv_encode_init() is set as FFCodec.init and calls ff_h261_encode_init(). The opposite is more natural and avoids a non-static function. Signed-off-by: Andreas Rheinhardt <andreas.rheinhardt@outlook.com> --- libavcodec/h261enc.c | 17 +++++++++-------- libavcodec/h261enc.h | 1 - libavcodec/mpegvideo_enc.c | 5 ----- 3 files changed, 9 insertions(+), 14 deletions(-) diff --git a/libavcodec/h261enc.c b/libavcodec/h261enc.c index 264efb0aa3..36c50db6df 100644 --- a/libavcodec/h261enc.c +++ b/libavcodec/h261enc.c @@ -352,20 +352,21 @@ static av_cold void h261_encode_init_static(void) mv_codes[0][1] = 1; } -av_cold int ff_h261_encode_init(MpegEncContext *s) +static av_cold int h261_encode_init(AVCodecContext *avctx) { - H261EncContext *const h = (H261EncContext*)s; static AVOnce init_static_once = AV_ONCE_INIT; + H261EncContext *const h = avctx->priv_data; + MpegEncContext *const s = &h->s.s; - if (s->width == 176 && s->height == 144) { + if (avctx->width == 176 && avctx->height == 144) { h->format = H261_QCIF; - } else if (s->width == 352 && s->height == 288) { + } else if (avctx->width == 352 && avctx->height == 288) { h->format = H261_CIF; } else { - av_log(s->avctx, AV_LOG_ERROR, + av_log(avctx, AV_LOG_ERROR, "The specified picture size of %dx%d is not valid for the " "H.261 codec.\nValid sizes are 176x144, 352x288\n", - s->width, s->height); + avctx->width, avctx->height); return AVERROR(EINVAL); } s->private_ctx = &h->common; @@ -380,7 +381,7 @@ av_cold int ff_h261_encode_init(MpegEncContext *s) s->intra_ac_vlc_last_length = s->inter_ac_vlc_last_length = uni_h261_rl_len_last; ff_thread_once(&init_static_once, h261_encode_init_static); - return 0; + return ff_mpv_encode_init(avctx); } const FFCodec ff_h261_encoder = { @@ -391,7 +392,7 @@ const FFCodec ff_h261_encoder = { .p.priv_class = &ff_mpv_enc_class, .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE, .priv_data_size = sizeof(H261EncContext), - .init = ff_mpv_encode_init, + .init = h261_encode_init, FF_CODEC_ENCODE_CB(ff_mpv_encode_picture), .close = ff_mpv_encode_end, .caps_internal = FF_CODEC_CAP_INIT_CLEANUP, diff --git a/libavcodec/h261enc.h b/libavcodec/h261enc.h index d8fdcad7aa..7877d8aa9d 100644 --- a/libavcodec/h261enc.h +++ b/libavcodec/h261enc.h @@ -34,6 +34,5 @@ void ff_h261_reorder_mb_index(MpegEncContext *s); void ff_h261_encode_mb(MpegEncContext *s, int16_t block[6][64], int motion_x, int motion_y); void ff_h261_encode_picture_header(MpegEncContext *s); -int ff_h261_encode_init(MpegEncContext *s); #endif diff --git a/libavcodec/mpegvideo_enc.c b/libavcodec/mpegvideo_enc.c index 1b7a4c1236..5c2f73b2d1 100644 --- a/libavcodec/mpegvideo_enc.c +++ b/libavcodec/mpegvideo_enc.c @@ -778,11 +778,6 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) s->low_delay = 1; break; case AV_CODEC_ID_H261: - if (!CONFIG_H261_ENCODER) - return AVERROR_ENCODER_NOT_FOUND; - ret = ff_h261_encode_init(s); - if (ret < 0) - return ret; s->out_format = FMT_H261; avctx->delay = 0; s->low_delay = 1; -- 2.45.2