History

avcodec/mjpegenc: Make mjpeg_encode_init() call ff_mpv_encode_init()

Right now, ff_mpv_encode_init() is set as FFCodec.init and calls ff_speedhq_encode_init(). The opposite is more natural, avoids a non-static function and allows to reuse e.g. slice_context_count instead of duplicating the logic from ff_mpv_common_init().

Andreas Rheinhardt committed 1 year ago

Commit dcd4dae1 parent 9928b9e3 files · +18 −22Browse files

Unified · Split

3 files
  1. libavcodec/mjpegenc.c +18 −19
  2. libavcodec/mjpegenc.h +0 −1
  3. libavcodec/mpegvideo_enc.c +0 −2
libavcodec/mjpegenc.c+18−19
@@ -283,10 +283,6 @@ static int alloc_huffman(MpegEncContext *s) · 282 unmodified lines
283283 size_t num_mbs, num_blocks, num_codes;
284284 int blocks_per_mb;
285285
286− // We need to init this here as the mjpeg init is called before the common init,
287− s->mb_width = (s->width + 15) / 16;
288− s->mb_height = (s->height + 15) / 16;
289−
290286 switch (s->chroma_format) {
291287 case CHROMA_420: blocks_per_mb = 6; break;
292288 case CHROMA_422: blocks_per_mb = 8; break;
@@ -305,34 +301,30 @@ static int alloc_huffman(MpegEncContext *s) · 12 unmodified lines
305301 return 0;
306302 }
307303
308−av_cold int ff_mjpeg_encode_init(MpegEncContext *s)
304+static av_cold int mjpeg_encode_init(AVCodecContext *avctx)
309305 {
310− MJpegContext *const m = &((MJPEGEncContext*)s)->mjpeg;
311− int ret, use_slices;
306+ MJPEGEncContext *const m2 = avctx->priv_data;
307+ MJpegContext *const m = &m2->mjpeg;
308+ MpegEncContext *const s = &m2->mpeg.s;
309+ int ret;
312310
313311 s->mjpeg_ctx = m;
314− use_slices = s->avctx->slices > 0 ? s->avctx->slices > 1 :
315− (s->avctx->active_thread_type & FF_THREAD_SLICE) &&
316− s->avctx->thread_count > 1;
317−
318− if (use_slices)
319− m->huffman = HUFFMAN_TABLE_DEFAULT;
320312
321313 if (s->mpv_flags & FF_MPV_FLAG_QP_RD) {
322314 // Used to produce garbage with MJPEG.
323− av_log(s->avctx, AV_LOG_ERROR,
315+ av_log(avctx, AV_LOG_ERROR,
324316 "QP RD is no longer compatible with MJPEG or AMV\n");
325317 return AVERROR(EINVAL);
326318 }
327319
328320 /* The following check is automatically true for AMV,
329321 * but it doesn't hurt either. */
330− ret = ff_mjpeg_encode_check_pix_fmt(s->avctx);
322+ ret = ff_mjpeg_encode_check_pix_fmt(avctx);
331323 if (ret < 0)
332324 return ret;
333325
334− if (s->width > 65500 || s->height > 65500) {
335− av_log(s->avctx, AV_LOG_ERROR, "JPEG does not support resolutions above 65500x65500\n");
326+ if (avctx->width > 65500 || avctx->height > 65500) {
327+ av_log(avctx, AV_LOG_ERROR, "JPEG does not support resolutions above 65500x65500\n");
336328 return AVERROR(EINVAL);
337329 }
338330
@@ -366,9 +358,16 @@ av_cold int ff_mjpeg_encode_init(MpegEncContext *s) · 27 unmodified lines
366358 s->intra_chroma_ac_vlc_length =
367359 s->intra_chroma_ac_vlc_last_length = m->uni_chroma_ac_vlc_len;
368360
361+ ret = ff_mpv_encode_init(avctx);
362+ if (ret < 0)
363+ return ret;
364+
369365 // Buffers start out empty.
370366 m->huff_ncode = 0;
371367
368+ if (s->slice_context_count > 1)
369+ m->huffman = HUFFMAN_TABLE_DEFAULT;
370+
372371 if (m->huffman == HUFFMAN_TABLE_OPTIMAL)
373372 return alloc_huffman(s);
374373
@@ -681,7 +680,7 @@ const FFCodec ff_mjpeg_encoder = { · 306 unmodified lines
681680 .p.type = AVMEDIA_TYPE_VIDEO,
682681 .p.id = AV_CODEC_ID_MJPEG,
683682 .priv_data_size = sizeof(MJPEGEncContext),
684− .init = ff_mpv_encode_init,
683+ .init = mjpeg_encode_init,
685684 FF_CODEC_ENCODE_CB(ff_mpv_encode_picture),
686685 .close = mjpeg_encode_close,
687686 .p.capabilities = AV_CODEC_CAP_DR1 |
@@ -711,7 +710,7 @@ const FFCodec ff_amv_encoder = { · 23 unmodified lines
711710 .p.id = AV_CODEC_ID_AMV,
712711 .p.capabilities = AV_CODEC_CAP_DR1 | AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE,
713712 .priv_data_size = sizeof(MJPEGEncContext),
714− .init = ff_mpv_encode_init,
713+ .init = mjpeg_encode_init,
715714 FF_CODEC_ENCODE_CB(amv_encode_picture),
716715 .close = mjpeg_encode_close,
717716 .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
libavcodec/mjpegenc.h+0−1
@@ -94,7 +94,6 @@ static inline void put_marker(PutBitContext *p, enum JpegMarker code) · 93 unmodified lines
9494
9595 typedef struct MpegEncContext MpegEncContext;
9696
97−int ff_mjpeg_encode_init(MpegEncContext *s);
9897 void ff_mjpeg_amv_encode_picture_header(MpegEncContext *s);
9998 void ff_mjpeg_encode_mb(MpegEncContext *s, int16_t block[12][64]);
10099 int ff_mjpeg_encode_stuffing(MpegEncContext *s);
libavcodec/mpegvideo_enc.c+0−2
@@ -765,8 +765,6 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) · 764 unmodified lines
765765 case AV_CODEC_ID_AMV:
766766 s->out_format = FMT_MJPEG;
767767 s->intra_only = 1; /* force intra only for jpeg */
768− if ((ret = ff_mjpeg_encode_init(s)) < 0)
769− return ret;
770768 avctx->delay = 0;
771769 s->low_delay = 1;
772770 break;

Keyboard shortcuts

General

Show keyboard shortcuts
?
Focus the current search
/

Issues and pull requests

Open filters
f

Issues, pull requests and Inbox

Select next item
j↓
Select previous item
k↑
Open selected item
Enter
Dismiss filters or clear selection
Esc

Repository code

Go to file
t