| 599 | } |
| 600 | |
| 601 | av_cold int ff_ffv1_encode_init(AVCodecContext *avctx) |
| 602 | { |
| 603 | FFV1Context *s = avctx->priv_data; |
| 604 | int i, j, k, m, ret; |
| 605 | |
| 606 | if ((avctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2)) || |
| 607 | avctx->slices > 1) |
| 608 | s->version = FFMAX(s->version, 2); |
| 609 | |
| 610 | if ((avctx->flags & (AV_CODEC_FLAG_PASS1 | AV_CODEC_FLAG_PASS2)) && s->ac == AC_GOLOMB_RICE) { |
| 611 | av_log(avctx, AV_LOG_ERROR, "2 Pass mode is not possible with golomb coding\n"); |
| 612 | return AVERROR(EINVAL); |
| 613 | } |
| 614 | |
| 615 | // Unspecified level & slices, we choose version 1.2+ to ensure multithreaded decodability |
| 616 | if (avctx->slices == 0 && avctx->level < 0 && avctx->width * avctx->height > 720*576) |
| 617 | s->version = FFMAX(s->version, 2); |
| 618 | |
| 619 | if (avctx->level <= 0 && s->version == 2) { |
| 620 | s->version = 3; |
| 621 | } |
| 622 | if (avctx->level >= 0 && avctx->level <= 4) { |
| 623 | if (avctx->level < s->version) { |
| 624 | av_log(avctx, AV_LOG_ERROR, "Version %d needed for requested features but %d requested\n", s->version, avctx->level); |
| 625 | return AVERROR(EINVAL); |
| 626 | } |
| 627 | s->version = avctx->level; |
| 628 | } else if (s->version < 3) |
| 629 | s->version = 3; |
| 630 | |
| 631 | if (s->ec < 0) { |
| 632 | if (s->version >= 4) { |
| 633 | s->ec = 2; |
| 634 | } else if (s->version >= 3) { |
| 635 | s->ec = 1; |
| 636 | } else |
| 637 | s->ec = 0; |
| 638 | } |
| 639 | |
| 640 | // CRC requires version 3+ |
| 641 | if (s->ec == 1) |
| 642 | s->version = FFMAX(s->version, 3); |
| 643 | if (s->ec == 2) { |
| 644 | s->version = FFMAX(s->version, 4); |
| 645 | s->crcref = 0x7a8c4079; |
| 646 | } |
| 647 | |
| 648 | if ((s->version == 2 || s->version>3) && avctx->strict_std_compliance > FF_COMPLIANCE_EXPERIMENTAL) { |
| 649 | av_log(avctx, AV_LOG_ERROR, "Version 2 or 4 needed for requested features but version 2 or 4 is experimental and not enabled\n"); |
| 650 | return AVERROR_INVALIDDATA; |
| 651 | } |
| 652 | |
| 653 | if (s->ac == AC_RANGE_CUSTOM_TAB) { |
| 654 | for (i = 1; i < 256; i++) |
| 655 | s->state_transition[i] = ver2_state[i]; |
| 656 | } else { |
| 657 | RangeCoder c; |
| 658 | ff_build_rac_states(&c, 0.05 * (1LL << 32), 256 - 8); |
no test coverage detected