History

avcodec/mpeg12dec: Don't initialize IDCT more than once

Before 998c9f15d1ca8c7489775ebcca51623b915988f1, the IDCTDSPContext has only been initialized in ff_mpv_common_init() which is deferred until immediately before decoding a picture; to nevertheless parse the quant matrices in sequence headers or quant matrix extensions, a dummy (identity) permutation has been stored in the codec's init function; after ff_mpv_common_init() which could change the permutation the matrices were repermutated. Yet since said commit, the IDCTDSPContext is initialized during init and does not change afterwards (unless the user forces different CPU flags), so there is no need to reinitialize it; the repermutation code can be removed as well.

Andreas Rheinhardt committed 3 years ago

Commit bc7de8b1 parent 89c10d81 file · +0 −26Browse files

Showing the changes to libavcodec (1 of 1 file). Show all

Unified · Split

libavcodec/mpeg12dec.c+0−26
@@ -1057,8 +1057,6 @@ static av_cold int mpeg_decode_init(AVCodecContext *avctx) · 1056 unmodified lines
1057 avctx->coded_width = avctx->coded_height = 0; // do not trust dimensions from input1057 avctx->coded_width = avctx->coded_height = 0; // do not trust dimensions from input
1058 ff_mpv_decode_init(s2, avctx);1058 ff_mpv_decode_init(s2, avctx);
1059 1059
1060 /* we need some permutation to store matrices,
1061 * until the decoder sets the real permutation. */
1062 ff_mpv_idct_init(s2);1060 ff_mpv_idct_init(s2);
1063 ff_mpeg12_init_vlcs();1061 ff_mpeg12_init_vlcs();
1064 1062
@@ -1093,18 +1091,6 @@ static int mpeg_decode_update_thread_context(AVCodecContext *avctx, · 28 unmodified lines
1093}1091}
1094#endif1092#endif
1095 1093
1096static void quant_matrix_rebuild(uint16_t *matrix, const uint8_t *old_perm,
1097 const uint8_t *new_perm)
1098{
1099 uint16_t temp_matrix[64];
1100 int i;
1101
1102 memcpy(temp_matrix, matrix, 64 * sizeof(uint16_t));
1103
1104 for (i = 0; i < 64; i++)
1105 matrix[new_perm[i]] = temp_matrix[old_perm[i]];
1106}
1107
1108static const enum AVPixelFormat mpeg1_hwaccel_pixfmt_list_420[] = {1094static const enum AVPixelFormat mpeg1_hwaccel_pixfmt_list_420[] = {
1109#if CONFIG_MPEG1_NVDEC_HWACCEL1095#if CONFIG_MPEG1_NVDEC_HWACCEL
1110 AV_PIX_FMT_CUDA,1096 AV_PIX_FMT_CUDA,
@@ -1177,7 +1163,6 @@ static int mpeg_decode_postinit(AVCodecContext *avctx) · 66 unmodified lines
1177{1163{
1178 Mpeg1Context *s1 = avctx->priv_data;1164 Mpeg1Context *s1 = avctx->priv_data;
1179 MpegEncContext *s = &s1->mpeg_enc_ctx;1165 MpegEncContext *s = &s1->mpeg_enc_ctx;
1180 uint8_t old_permutation[64];
1181 int ret;1166 int ret;
1182 1167
1183 if (avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO) {1168 if (avctx->codec_id == AV_CODEC_ID_MPEG1VIDEO) {
@@ -1297,19 +1282,9 @@ FF_ENABLE_DEPRECATION_WARNINGS · 113 unmodified lines
1297 1282
1298 avctx->pix_fmt = mpeg_get_pixelformat(avctx);1283 avctx->pix_fmt = mpeg_get_pixelformat(avctx);
1299 1284
1300 /* Quantization matrices may need reordering
1301 * if DCT permutation is changed. */
1302 memcpy(old_permutation, s->idsp.idct_permutation, 64 * sizeof(uint8_t));
1303
1304 ff_mpv_idct_init(s);
1305 if ((ret = ff_mpv_common_init(s)) < 0)1285 if ((ret = ff_mpv_common_init(s)) < 0)
1306 return ret;1286 return ret;
1307 1287
1308 quant_matrix_rebuild(s->intra_matrix, old_permutation, s->idsp.idct_permutation);
1309 quant_matrix_rebuild(s->inter_matrix, old_permutation, s->idsp.idct_permutation);
1310 quant_matrix_rebuild(s->chroma_intra_matrix, old_permutation, s->idsp.idct_permutation);
1311 quant_matrix_rebuild(s->chroma_inter_matrix, old_permutation, s->idsp.idct_permutation);
1312
1313 s1->mpeg_enc_ctx_allocated = 1;1288 s1->mpeg_enc_ctx_allocated = 1;
1314 }1289 }
1315 return 0;1290 return 0;
@@ -2169,7 +2144,6 @@ static int vcr2_init_sequence(AVCodecContext *avctx) · 853 unmodified lines
2169 2144
2170 avctx->pix_fmt = mpeg_get_pixelformat(avctx);2145 avctx->pix_fmt = mpeg_get_pixelformat(avctx);
2171 2146
2172 ff_mpv_idct_init(s);
2173 if ((ret = ff_mpv_common_init(s)) < 0)2147 if ((ret = ff_mpv_common_init(s)) < 0)
2174 return ret;2148 return ret;
2175 s1->mpeg_enc_ctx_allocated = 1;2149 s1->mpeg_enc_ctx_allocated = 1;

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