History

avcodec/mpegvideo: Redo aligning mb_height for VC-1

VC-1 can switch from between being progressive and interlaced on a per-frame basis. In the latter case, the number of macroblocks is aligned to two (or equivalently, the height to 32); therefore certain buffers are allocated for the bigger mb_height (see 950fb8acb42f4dab9b1638721992991c0584dbf5 and 017e234c204f8ffb5f85a073231247881be1ac6f). This commit changes how this is done: Aligning these buffers is restricted to VC-1 and it is done directly by aligning mb_height (but not MpegEncContext.mb_height) instead of adding something in an ad-hoc manner.

Andreas Rheinhardt committed 2 years ago

Commit a95591d1 parent 7ad13e11 file · +17 −14Browse files

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

Unified · Split

libavcodec/mpegvideo.c+17−14
@@ -364,14 +364,8 @@ av_cold void ff_mpv_idct_init(MpegEncContext *s) · 363 unmodified lines
364364
365365 static int init_duplicate_context(MpegEncContext *s)
366366 {
367− int y_size = s->b8_stride * (2 * s->mb_height + 1);
368− int c_size = s->mb_stride * (s->mb_height + 1);
369− int yc_size = y_size + 2 * c_size;
370367 int i;
371368
372− if (s->mb_height & 1)
373− yc_size += 2*s->b8_stride + 2*s->mb_stride;
374−
375369 if (s->encoding) {
376370 s->me.map = av_mallocz(2 * ME_MAP_SIZE * sizeof(*s->me.map));
377371 if (!s->me.map)
@@ -397,6 +391,11 @@ static int init_duplicate_context(MpegEncContext *s) · 19 unmodified lines
397391 }
398392
399393 if (s->out_format == FMT_H263) {
394+ int mb_height = s->msmpeg4_version == 6 /* VC-1 like */ ?
395+ FFALIGN(s->mb_height, 2) : s->mb_height;
396+ int y_size = s->b8_stride * (2 * mb_height + 1);
397+ int c_size = s->mb_stride * (mb_height + 1);
398+ int yc_size = y_size + 2 * c_size;
400399 /* ac values */
401400 if (!FF_ALLOCZ_TYPED_ARRAY(s->ac_val_base, yc_size))
402401 return AVERROR(ENOMEM);
@@ -538,17 +537,24 @@ void ff_mpv_common_defaults(MpegEncContext *s) · 135 unmodified lines
538537 int ff_mpv_init_context_frame(MpegEncContext *s)
539538 {
540539 int y_size, c_size, yc_size, i, mb_array_size, mv_table_size, x, y;
540+ int mb_height;
541541
542542 if (s->codec_id == AV_CODEC_ID_MPEG2VIDEO && !s->progressive_sequence)
543543 s->mb_height = (s->height + 31) / 32 * 2;
544544 else
545545 s->mb_height = (s->height + 15) / 16;
546546
547+ /* VC-1 can change from being progressive to interlaced on a per-frame
548+ * basis. We therefore allocate certain buffers so big that they work
549+ * in both instances. */
550+ mb_height = s->msmpeg4_version == 6 /* VC-1 like*/ ?
551+ FFALIGN(s->mb_height, 2) : s->mb_height;
552+
547553 s->mb_width = (s->width + 15) / 16;
548554 s->mb_stride = s->mb_width + 1;
549555 s->b8_stride = s->mb_width * 2 + 1;
550− mb_array_size = s->mb_height * s->mb_stride;
551− mv_table_size = (s->mb_height + 2) * s->mb_stride + 1;
556+ mb_array_size = mb_height * s->mb_stride;
557+ mv_table_size = (mb_height + 2) * s->mb_stride + 1;
552558
553559 /* set default edge pos, will be overridden
554560 * in decode_header if needed */
@@ -564,13 +570,10 @@ int ff_mpv_init_context_frame(MpegEncContext *s) · 9 unmodified lines
564570 s->block_wrap[4] =
565571 s->block_wrap[5] = s->mb_stride;
566572
567− y_size = s->b8_stride * (2 * s->mb_height + 1);
568− c_size = s->mb_stride * (s->mb_height + 1);
573+ y_size = s->b8_stride * (2 * mb_height + 1);
574+ c_size = s->mb_stride * (mb_height + 1);
569575 yc_size = y_size + 2 * c_size;
570576
571− if (s->mb_height & 1)
572− yc_size += 2*s->b8_stride + 2*s->mb_stride;
573−
574577 if (!FF_ALLOCZ_TYPED_ARRAY(s->mb_index2xy, s->mb_num + 1))
575578 return AVERROR(ENOMEM);
576579 for (y = 0; y < s->mb_height; y++)
@@ -602,7 +605,7 @@ int ff_mpv_init_context_frame(MpegEncContext *s) · 25 unmodified lines
602605 }
603606
604607 if (s->msmpeg4_version >= 3) {
605− s->coded_block_base = av_mallocz(y_size + (s->mb_height&1)*2*s->b8_stride);
608+ s->coded_block_base = av_mallocz(y_size);
606609 if (!s->coded_block_base)
607610 return AVERROR(ENOMEM);
608611 s->coded_block = s->coded_block_base + s->b8_stride + 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