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.
Showing the changes to libavcodec (1 of 1 file). Show all
Unified · Split
| @@ -364,14 +364,8 @@ av_cold void ff_mpv_idct_init(MpegEncContext *s) · 363 unmodified lines | ||
| 364 | 364 | |
| 365 | 365 | static int init_duplicate_context(MpegEncContext *s) |
| 366 | 366 | { |
| 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; | |
| 370 | 367 | int i; |
| 371 | 368 | |
| 372 | − if (s->mb_height & 1) | |
| 373 | − yc_size += 2*s->b8_stride + 2*s->mb_stride; | |
| 374 | − | |
| 375 | 369 | if (s->encoding) { |
| 376 | 370 | s->me.map = av_mallocz(2 * ME_MAP_SIZE * sizeof(*s->me.map)); |
| 377 | 371 | if (!s->me.map) |
| @@ -397,6 +391,11 @@ static int init_duplicate_context(MpegEncContext *s) · 19 unmodified lines | ||
| 397 | 391 | } |
| 398 | 392 | |
| 399 | 393 | 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; | |
| 400 | 399 | /* ac values */ |
| 401 | 400 | if (!FF_ALLOCZ_TYPED_ARRAY(s->ac_val_base, yc_size)) |
| 402 | 401 | return AVERROR(ENOMEM); |
| @@ -538,17 +537,24 @@ void ff_mpv_common_defaults(MpegEncContext *s) · 135 unmodified lines | ||
| 538 | 537 | int ff_mpv_init_context_frame(MpegEncContext *s) |
| 539 | 538 | { |
| 540 | 539 | int y_size, c_size, yc_size, i, mb_array_size, mv_table_size, x, y; |
| 540 | + int mb_height; | |
| 541 | 541 | |
| 542 | 542 | if (s->codec_id == AV_CODEC_ID_MPEG2VIDEO && !s->progressive_sequence) |
| 543 | 543 | s->mb_height = (s->height + 31) / 32 * 2; |
| 544 | 544 | else |
| 545 | 545 | s->mb_height = (s->height + 15) / 16; |
| 546 | 546 | |
| 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 | + | |
| 547 | 553 | s->mb_width = (s->width + 15) / 16; |
| 548 | 554 | s->mb_stride = s->mb_width + 1; |
| 549 | 555 | 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; | |
| 552 | 558 | |
| 553 | 559 | /* set default edge pos, will be overridden |
| 554 | 560 | * in decode_header if needed */ |
| @@ -564,13 +570,10 @@ int ff_mpv_init_context_frame(MpegEncContext *s) · 9 unmodified lines | ||
| 564 | 570 | s->block_wrap[4] = |
| 565 | 571 | s->block_wrap[5] = s->mb_stride; |
| 566 | 572 | |
| 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); | |
| 569 | 575 | yc_size = y_size + 2 * c_size; |
| 570 | 576 | |
| 571 | − if (s->mb_height & 1) | |
| 572 | − yc_size += 2*s->b8_stride + 2*s->mb_stride; | |
| 573 | − | |
| 574 | 577 | if (!FF_ALLOCZ_TYPED_ARRAY(s->mb_index2xy, s->mb_num + 1)) |
| 575 | 578 | return AVERROR(ENOMEM); |
| 576 | 579 | for (y = 0; y < s->mb_height; y++) |
| @@ -602,7 +605,7 @@ int ff_mpv_init_context_frame(MpegEncContext *s) · 25 unmodified lines | ||
| 602 | 605 | } |
| 603 | 606 | |
| 604 | 607 | 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); | |
| 606 | 609 | if (!s->coded_block_base) |
| 607 | 610 | return AVERROR(ENOMEM); |
| 608 | 611 | s->coded_block = s->coded_block_base + s->b8_stride + 1; |