History

avcodec/mpegvideo_enc: Factor checks out of loop

Also move this code to init_matrices().

Andreas Rheinhardt committed 1 year ago

Commit a4312441 parent 72233631 file · +27 −22Browse files

Unified · Split

libavcodec/mpegvideo_enc.c+27−22
@@ -350,6 +350,8 @@ static av_cold int me_cmp_init(MpegEncContext *s, AVCodecContext *avctx) · 349 unmodified lines
350 350
351static av_cold int init_matrices(MpegEncContext *s, AVCodecContext *avctx)351static av_cold int init_matrices(MpegEncContext *s, AVCodecContext *avctx)
352{352{
353 const uint16_t *intra_matrix, *inter_matrix;
354
353 if (s->out_format == FMT_MJPEG) {355 if (s->out_format == FMT_MJPEG) {
354 if (!FF_ALLOCZ_TYPED_ARRAY(s->q_chroma_intra_matrix, 32) ||356 if (!FF_ALLOCZ_TYPED_ARRAY(s->q_chroma_intra_matrix, 32) ||
355 !FF_ALLOCZ_TYPED_ARRAY(s->q_chroma_intra_matrix16, 32))357 !FF_ALLOCZ_TYPED_ARRAY(s->q_chroma_intra_matrix16, 32))
@@ -359,6 +361,31 @@ static av_cold int init_matrices(MpegEncContext *s, AVCodecContext *avctx) · 3 unmodified lines
359 s->q_chroma_intra_matrix16 = s->q_intra_matrix16;361 s->q_chroma_intra_matrix16 = s->q_intra_matrix16;
360 }362 }
361 363
364 if (CONFIG_MPEG4_ENCODER && s->codec_id == AV_CODEC_ID_MPEG4 &&
365 s->mpeg_quant) {
366 intra_matrix = ff_mpeg4_default_intra_matrix;
367 inter_matrix = ff_mpeg4_default_non_intra_matrix;
368 } else if (s->out_format == FMT_H263 || s->out_format == FMT_H261) {
369 intra_matrix =
370 inter_matrix = ff_mpeg1_default_non_intra_matrix;
371 } else {
372 /* MPEG-1/2, SpeedHQ */
373 intra_matrix = ff_mpeg1_default_intra_matrix;
374 inter_matrix = ff_mpeg1_default_non_intra_matrix;
375 }
376 if (avctx->intra_matrix)
377 intra_matrix = avctx->intra_matrix;
378 if (avctx->inter_matrix)
379 inter_matrix = avctx->inter_matrix;
380
381 /* init q matrix */
382 for (int i = 0; i < 64; i++) {
383 int j = s->idsp.idct_permutation[i];
384
385 s->intra_matrix[j] = s->chroma_intra_matrix[j] = intra_matrix[i];
386 s->inter_matrix[j] = inter_matrix[i];
387 }
388
362 return 0;389 return 0;
363}390}
364 391
@@ -982,28 +1009,6 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) · 617 unmodified lines
982#endif1009#endif
983 }1010 }
984 1011
985 /* init q matrix */
986 for (i = 0; i < 64; i++) {
987 int j = s->idsp.idct_permutation[i];
988 if (CONFIG_MPEG4_ENCODER && s->codec_id == AV_CODEC_ID_MPEG4 &&
989 s->mpeg_quant) {
990 s->intra_matrix[j] = ff_mpeg4_default_intra_matrix[i];
991 s->inter_matrix[j] = ff_mpeg4_default_non_intra_matrix[i];
992 } else if (s->out_format == FMT_H263 || s->out_format == FMT_H261) {
993 s->intra_matrix[j] =
994 s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i];
995 } else {
996 /* MPEG-1/2, SpeedHQ */
997 s->chroma_intra_matrix[j] =
998 s->intra_matrix[j] = ff_mpeg1_default_intra_matrix[i];
999 s->inter_matrix[j] = ff_mpeg1_default_non_intra_matrix[i];
1000 }
1001 if (avctx->intra_matrix)
1002 s->intra_matrix[j] = avctx->intra_matrix[i];
1003 if (avctx->inter_matrix)
1004 s->inter_matrix[j] = avctx->inter_matrix[i];
1005 }
1006
1007 /* precompute matrix */1012 /* precompute matrix */
1008 /* for mjpeg, we do include qscale in the matrix */1013 /* for mjpeg, we do include qscale in the matrix */
1009 if (s->out_format != FMT_MJPEG) {1014 if (s->out_format != FMT_MJPEG) {

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