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