| @@ -915,8 +915,6 @@ av_cold int ff_mpv_encode_init(AVCodecContext *avctx) · 914 unmodified lines |
| 915 | 915 | return ret; |
| 916 | 916 | |
| 917 | 917 | if (!(avctx->stats_out = av_mallocz(256)) || |
| 918 | | − !FF_ALLOCZ_TYPED_ARRAY(s->input_picture, MPVENC_MAX_B_FRAMES + 1) || |
| 919 | | − !FF_ALLOCZ_TYPED_ARRAY(s->reordered_input_picture, MPVENC_MAX_B_FRAMES + 1) || |
| 920 | 918 | !(s->new_pic = av_frame_alloc()) || |
| 921 | 919 | !(s->picture_pool = ff_mpv_alloc_pic_pool(0))) |
| 922 | 920 | return AVERROR(ENOMEM); |
| @@ -1049,11 +1047,9 @@ av_cold int ff_mpv_encode_end(AVCodecContext *avctx) · 126 unmodified lines |
| 1049 | 1047 | ff_mpv_common_end(s); |
| 1050 | 1048 | av_refstruct_pool_uninit(&s->picture_pool); |
| 1051 | 1049 | |
| 1052 | | − if (s->input_picture && s->reordered_input_picture) { |
| 1053 | | − for (int i = 0; i < MPVENC_MAX_B_FRAMES + 1; i++) { |
| 1054 | | − av_refstruct_unref(&s->input_picture[i]); |
| 1055 | | − av_refstruct_unref(&s->reordered_input_picture[i]); |
| 1056 | | − } |
| 1050 | + for (int i = 0; i < MPVENC_MAX_B_FRAMES + 1; i++) { |
| 1051 | + av_refstruct_unref(&m->input_picture[i]); |
| 1052 | + av_refstruct_unref(&m->reordered_input_picture[i]); |
| 1057 | 1053 | } |
| 1058 | 1054 | for (int i = 0; i < FF_ARRAY_ELEMS(m->tmp_frames); i++) |
| 1059 | 1055 | av_frame_free(&m->tmp_frames[i]); |
| @@ -1077,8 +1073,6 @@ av_cold int ff_mpv_encode_end(AVCodecContext *avctx) · 17 unmodified lines |
| 1077 | 1073 | |
| 1078 | 1074 | av_freep(&s->q_intra_matrix); |
| 1079 | 1075 | av_freep(&s->q_intra_matrix16); |
| 1080 | | − av_freep(&s->input_picture); |
| 1081 | | − av_freep(&s->reordered_input_picture); |
| 1082 | 1076 | av_freep(&s->dct_offset); |
| 1083 | 1077 | av_freep(&s->mb_var); |
| 1084 | 1078 | av_freep(&s->mc_mb_var); |
| @@ -1260,7 +1254,7 @@ static int load_input_picture(MPVMainEncContext *const m, const AVFrame *pic_arg · 175 unmodified lines |
| 1260 | 1254 | int flush_offset = 1; |
| 1261 | 1255 | int direct = 1; |
| 1262 | 1256 | |
| 1263 | | − av_assert1(!s->input_picture[0]); |
| 1257 | + av_assert1(!m->input_picture[0]); |
| 1264 | 1258 | |
| 1265 | 1259 | if (pic_arg) { |
| 1266 | 1260 | pts = pic_arg->pts; |
| @@ -1363,14 +1357,14 @@ static int load_input_picture(MPVMainEncContext *const m, const AVFrame *pic_arg · 96 unmodified lines |
| 1363 | 1357 | |
| 1364 | 1358 | pic->display_picture_number = display_picture_number; |
| 1365 | 1359 | pic->f->pts = pts; // we set this here to avoid modifying pic_arg |
| 1366 | | − } else if (!s->reordered_input_picture[1]) { |
| 1360 | + } else if (!m->reordered_input_picture[1]) { |
| 1367 | 1361 | /* Flushing: When the above check is true, the encoder is about to run |
| 1368 | 1362 | * out of frames to encode. Check if there are input_pictures left; |
| 1369 | | − * if so, ensure s->input_picture[0] contains the first picture. |
| 1363 | + * if so, ensure m->input_picture[0] contains the first picture. |
| 1370 | 1364 | * A flush_offset != 1 will only happen if we did not receive enough |
| 1371 | 1365 | * input frames. */ |
| 1372 | 1366 | for (flush_offset = 0; flush_offset < encoding_delay + 1; flush_offset++) |
| 1373 | | − if (s->input_picture[flush_offset]) |
| 1367 | + if (m->input_picture[flush_offset]) |
| 1374 | 1368 | break; |
| 1375 | 1369 | |
| 1376 | 1370 | encoding_delay -= flush_offset - 1; |
| @@ -1378,11 +1372,11 @@ static int load_input_picture(MPVMainEncContext *const m, const AVFrame *pic_arg · 1 unmodified line |
| 1378 | 1372 | |
| 1379 | 1373 | /* shift buffer entries */ |
| 1380 | 1374 | for (int i = flush_offset; i <= MPVENC_MAX_B_FRAMES; i++) |
| 1381 | | − s->input_picture[i - flush_offset] = s->input_picture[i]; |
| 1375 | + m->input_picture[i - flush_offset] = m->input_picture[i]; |
| 1382 | 1376 | for (int i = MPVENC_MAX_B_FRAMES + 1 - flush_offset; i <= MPVENC_MAX_B_FRAMES; i++) |
| 1383 | | − s->input_picture[i] = NULL; |
| 1377 | + m->input_picture[i] = NULL; |
| 1384 | 1378 | |
| 1385 | | − s->input_picture[encoding_delay] = pic; |
| 1379 | + m->input_picture[encoding_delay] = pic; |
| 1386 | 1380 | |
| 1387 | 1381 | return 0; |
| 1388 | 1382 | fail: |
| @@ -1482,7 +1476,7 @@ static int estimate_best_b_count(MPVMainEncContext *const m) · 93 unmodified lines |
| 1482 | 1476 | FF_LAMBDA_SHIFT; |
| 1483 | 1477 | |
| 1484 | 1478 | for (int i = 0; i < m->max_b_frames + 2; i++) { |
| 1485 | | − const MPVPicture *pre_input_ptr = i ? s->input_picture[i - 1] : |
| 1479 | + const MPVPicture *pre_input_ptr = i ? m->input_picture[i - 1] : |
| 1486 | 1480 | s->next_pic.ptr; |
| 1487 | 1481 | |
| 1488 | 1482 | if (pre_input_ptr) { |
| @@ -1517,7 +1511,7 @@ static int estimate_best_b_count(MPVMainEncContext *const m) · 28 unmodified lines |
| 1517 | 1511 | AVCodecContext *c; |
| 1518 | 1512 | int64_t rd = 0; |
| 1519 | 1513 | |
| 1520 | | − if (!s->input_picture[j]) |
| 1514 | + if (!m->input_picture[j]) |
| 1521 | 1515 | break; |
| 1522 | 1516 | |
| 1523 | 1517 | c = avcodec_alloc_context3(NULL); |
| @@ -1612,16 +1606,16 @@ static int set_bframe_chain_length(MPVMainEncContext *const m) · 88 unmodified lines |
| 1612 | 1606 | MpegEncContext *const s = &m->s; |
| 1613 | 1607 | |
| 1614 | 1608 | /* Either nothing to do or can't do anything */ |
| 1615 | | − if (s->reordered_input_picture[0] || !s->input_picture[0]) |
| 1609 | + if (m->reordered_input_picture[0] || !m->input_picture[0]) |
| 1616 | 1610 | return 0; |
| 1617 | 1611 | |
| 1618 | 1612 | /* set next picture type & ordering */ |
| 1619 | 1613 | if (m->frame_skip_threshold || m->frame_skip_factor) { |
| 1620 | 1614 | if (m->picture_in_gop_number < m->gop_size && |
| 1621 | 1615 | s->next_pic.ptr && |
| 1622 | | − skip_check(m, s->input_picture[0], s->next_pic.ptr)) { |
| 1616 | + skip_check(m, m->input_picture[0], s->next_pic.ptr)) { |
| 1623 | 1617 | // FIXME check that the gop check above is +-1 correct |
| 1624 | | − av_refstruct_unref(&s->input_picture[0]); |
| 1618 | + av_refstruct_unref(&m->input_picture[0]); |
| 1625 | 1619 | |
| 1626 | 1620 | ff_vbv_update(m, 0); |
| 1627 | 1621 | |
| @@ -1631,48 +1625,48 @@ static int set_bframe_chain_length(MPVMainEncContext *const m) · 3 unmodified lines |
| 1631 | 1625 | |
| 1632 | 1626 | if (/* m->picture_in_gop_number >= m->gop_size || */ |
| 1633 | 1627 | !s->next_pic.ptr || m->intra_only) { |
| 1634 | | − s->reordered_input_picture[0] = s->input_picture[0]; |
| 1635 | | − s->input_picture[0] = NULL; |
| 1636 | | − s->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_I; |
| 1637 | | − s->reordered_input_picture[0]->coded_picture_number = |
| 1628 | + m->reordered_input_picture[0] = m->input_picture[0]; |
| 1629 | + m->input_picture[0] = NULL; |
| 1630 | + m->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_I; |
| 1631 | + m->reordered_input_picture[0]->coded_picture_number = |
| 1638 | 1632 | m->coded_picture_number++; |
| 1639 | 1633 | } else { |
| 1640 | 1634 | int b_frames = 0; |
| 1641 | 1635 | |
| 1642 | 1636 | if (s->avctx->flags & AV_CODEC_FLAG_PASS2) { |
| 1643 | 1637 | for (int i = 0; i < m->max_b_frames + 1; i++) { |
| 1644 | | − int pict_num = s->input_picture[0]->display_picture_number + i; |
| 1638 | + int pict_num = m->input_picture[0]->display_picture_number + i; |
| 1645 | 1639 | |
| 1646 | 1640 | if (pict_num >= m->rc_context.num_entries) |
| 1647 | 1641 | break; |
| 1648 | | − if (!s->input_picture[i]) { |
| 1642 | + if (!m->input_picture[i]) { |
| 1649 | 1643 | m->rc_context.entry[pict_num - 1].new_pict_type = AV_PICTURE_TYPE_P; |
| 1650 | 1644 | break; |
| 1651 | 1645 | } |
| 1652 | 1646 | |
| 1653 | | − s->input_picture[i]->f->pict_type = |
| 1647 | + m->input_picture[i]->f->pict_type = |
| 1654 | 1648 | m->rc_context.entry[pict_num].new_pict_type; |
| 1655 | 1649 | } |
| 1656 | 1650 | } |
| 1657 | 1651 | |
| 1658 | 1652 | if (m->b_frame_strategy == 0) { |
| 1659 | 1653 | b_frames = m->max_b_frames; |
| 1660 | | − while (b_frames && !s->input_picture[b_frames]) |
| 1654 | + while (b_frames && !m->input_picture[b_frames]) |
| 1661 | 1655 | b_frames--; |
| 1662 | 1656 | } else if (m->b_frame_strategy == 1) { |
| 1663 | 1657 | for (int i = 1; i < m->max_b_frames + 1; i++) { |
| 1664 | | − if (s->input_picture[i] && |
| 1665 | | − s->input_picture[i]->b_frame_score == 0) { |
| 1666 | | − s->input_picture[i]->b_frame_score = |
| 1658 | + if (m->input_picture[i] && |
| 1659 | + m->input_picture[i]->b_frame_score == 0) { |
| 1660 | + m->input_picture[i]->b_frame_score = |
| 1667 | 1661 | get_intra_count(s, |
| 1668 | | − s->input_picture[i ]->f->data[0], |
| 1669 | | − s->input_picture[i - 1]->f->data[0], |
| 1662 | + m->input_picture[i ]->f->data[0], |
| 1663 | + m->input_picture[i - 1]->f->data[0], |
| 1670 | 1664 | s->linesize) + 1; |
| 1671 | 1665 | } |
| 1672 | 1666 | } |
| 1673 | 1667 | for (int i = 0; i < m->max_b_frames + 1; i++) { |
| 1674 | | − if (!s->input_picture[i] || |
| 1675 | | − s->input_picture[i]->b_frame_score - 1 > |
| 1668 | + if (!m->input_picture[i] || |
| 1669 | + m->input_picture[i]->b_frame_score - 1 > |
| 1676 | 1670 | s->mb_num / m->b_sensitivity) { |
| 1677 | 1671 | b_frames = FFMAX(0, i - 1); |
| 1678 | 1672 | break; |
| @@ -1681,11 +1675,11 @@ static int set_bframe_chain_length(MPVMainEncContext *const m) · 2 unmodified lines |
| 1681 | 1675 | |
| 1682 | 1676 | /* reset scores */ |
| 1683 | 1677 | for (int i = 0; i < b_frames + 1; i++) |
| 1684 | | − s->input_picture[i]->b_frame_score = 0; |
| 1678 | + m->input_picture[i]->b_frame_score = 0; |
| 1685 | 1679 | } else if (m->b_frame_strategy == 2) { |
| 1686 | 1680 | b_frames = estimate_best_b_count(m); |
| 1687 | 1681 | if (b_frames < 0) { |
| 1688 | | − av_refstruct_unref(&s->input_picture[0]); |
| 1682 | + av_refstruct_unref(&m->input_picture[0]); |
| 1689 | 1683 | return b_frames; |
| 1690 | 1684 | } |
| 1691 | 1685 | } |
| @@ -1693,11 +1687,11 @@ static int set_bframe_chain_length(MPVMainEncContext *const m) · 1 unmodified line |
| 1693 | 1687 | emms_c(); |
| 1694 | 1688 | |
| 1695 | 1689 | for (int i = b_frames - 1; i >= 0; i--) { |
| 1696 | | − int type = s->input_picture[i]->f->pict_type; |
| 1690 | + int type = m->input_picture[i]->f->pict_type; |
| 1697 | 1691 | if (type && type != AV_PICTURE_TYPE_B) |
| 1698 | 1692 | b_frames = i; |
| 1699 | 1693 | } |
| 1700 | | − if (s->input_picture[b_frames]->f->pict_type == AV_PICTURE_TYPE_B && |
| 1694 | + if (m->input_picture[b_frames]->f->pict_type == AV_PICTURE_TYPE_B && |
| 1701 | 1695 | b_frames == m->max_b_frames) { |
| 1702 | 1696 | av_log(s->avctx, AV_LOG_ERROR, |
| 1703 | 1697 | "warning, too many B-frames in a row\n"); |
| @@ -1710,26 +1704,26 @@ static int set_bframe_chain_length(MPVMainEncContext *const m) · 6 unmodified lines |
| 1710 | 1704 | } else { |
| 1711 | 1705 | if (s->avctx->flags & AV_CODEC_FLAG_CLOSED_GOP) |
| 1712 | 1706 | b_frames = 0; |
| 1713 | | − s->input_picture[b_frames]->f->pict_type = AV_PICTURE_TYPE_I; |
| 1707 | + m->input_picture[b_frames]->f->pict_type = AV_PICTURE_TYPE_I; |
| 1714 | 1708 | } |
| 1715 | 1709 | } |
| 1716 | 1710 | |
| 1717 | 1711 | if ((s->avctx->flags & AV_CODEC_FLAG_CLOSED_GOP) && b_frames && |
| 1718 | | − s->input_picture[b_frames]->f->pict_type == AV_PICTURE_TYPE_I) |
| 1712 | + m->input_picture[b_frames]->f->pict_type == AV_PICTURE_TYPE_I) |
| 1719 | 1713 | b_frames--; |
| 1720 | 1714 | |
| 1721 | | − s->reordered_input_picture[0] = s->input_picture[b_frames]; |
| 1722 | | − s->input_picture[b_frames] = NULL; |
| 1723 | | − if (s->reordered_input_picture[0]->f->pict_type != AV_PICTURE_TYPE_I) |
| 1724 | | − s->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_P; |
| 1725 | | − s->reordered_input_picture[0]->coded_picture_number = |
| 1715 | + m->reordered_input_picture[0] = m->input_picture[b_frames]; |
| 1716 | + m->input_picture[b_frames] = NULL; |
| 1717 | + if (m->reordered_input_picture[0]->f->pict_type != AV_PICTURE_TYPE_I) |
| 1718 | + m->reordered_input_picture[0]->f->pict_type = AV_PICTURE_TYPE_P; |
| 1719 | + m->reordered_input_picture[0]->coded_picture_number = |
| 1726 | 1720 | m->coded_picture_number++; |
| 1727 | 1721 | for (int i = 0; i < b_frames; i++) { |
| 1728 | | − s->reordered_input_picture[i + 1] = s->input_picture[i]; |
| 1729 | | − s->input_picture[i] = NULL; |
| 1730 | | − s->reordered_input_picture[i + 1]->f->pict_type = |
| 1722 | + m->reordered_input_picture[i + 1] = m->input_picture[i]; |
| 1723 | + m->input_picture[i] = NULL; |
| 1724 | + m->reordered_input_picture[i + 1]->f->pict_type = |
| 1731 | 1725 | AV_PICTURE_TYPE_B; |
| 1732 | | − s->reordered_input_picture[i + 1]->coded_picture_number = |
| 1726 | + m->reordered_input_picture[i + 1]->coded_picture_number = |
| 1733 | 1727 | m->coded_picture_number++; |
| 1734 | 1728 | } |
| 1735 | 1729 | } |
| @@ -1742,34 +1736,34 @@ static int select_input_picture(MPVMainEncContext *const m) · 6 unmodified lines |
| 1742 | 1736 | MpegEncContext *const s = &m->s; |
| 1743 | 1737 | int ret; |
| 1744 | 1738 | |
| 1745 | | − av_assert1(!s->reordered_input_picture[0]); |
| 1739 | + av_assert1(!m->reordered_input_picture[0]); |
| 1746 | 1740 | |
| 1747 | 1741 | for (int i = 1; i <= MPVENC_MAX_B_FRAMES; i++) |
| 1748 | | − s->reordered_input_picture[i - 1] = s->reordered_input_picture[i]; |
| 1749 | | − s->reordered_input_picture[MPVENC_MAX_B_FRAMES] = NULL; |
| 1742 | + m->reordered_input_picture[i - 1] = m->reordered_input_picture[i]; |
| 1743 | + m->reordered_input_picture[MPVENC_MAX_B_FRAMES] = NULL; |
| 1750 | 1744 | |
| 1751 | 1745 | ret = set_bframe_chain_length(m); |
| 1752 | | − av_assert1(!s->input_picture[0]); |
| 1746 | + av_assert1(!m->input_picture[0]); |
| 1753 | 1747 | if (ret < 0) |
| 1754 | 1748 | return ret; |
| 1755 | 1749 | |
| 1756 | 1750 | av_frame_unref(s->new_pic); |
| 1757 | 1751 | |
| 1758 | | − if (s->reordered_input_picture[0]) { |
| 1759 | | − s->reordered_input_picture[0]->reference = |
| 1760 | | − s->reordered_input_picture[0]->f->pict_type != AV_PICTURE_TYPE_B; |
| 1752 | + if (m->reordered_input_picture[0]) { |
| 1753 | + m->reordered_input_picture[0]->reference = |
| 1754 | + m->reordered_input_picture[0]->f->pict_type != AV_PICTURE_TYPE_B; |
| 1761 | 1755 | |
| 1762 | | − if (s->reordered_input_picture[0]->shared || s->avctx->rc_buffer_size) { |
| 1756 | + if (m->reordered_input_picture[0]->shared || s->avctx->rc_buffer_size) { |
| 1763 | 1757 | // input is a shared pix, so we can't modify it -> allocate a new |
| 1764 | 1758 | // one & ensure that the shared one is reuseable |
| 1765 | | − av_frame_move_ref(s->new_pic, s->reordered_input_picture[0]->f); |
| 1759 | + av_frame_move_ref(s->new_pic, m->reordered_input_picture[0]->f); |
| 1766 | 1760 | |
| 1767 | | − ret = prepare_picture(s, s->reordered_input_picture[0]->f, s->new_pic); |
| 1761 | + ret = prepare_picture(s, m->reordered_input_picture[0]->f, s->new_pic); |
| 1768 | 1762 | if (ret < 0) |
| 1769 | 1763 | goto fail; |
| 1770 | 1764 | } else { |
| 1771 | 1765 | // input is not a shared pix -> reuse buffer for current_pix |
| 1772 | | − ret = av_frame_ref(s->new_pic, s->reordered_input_picture[0]->f); |
| 1766 | + ret = av_frame_ref(s->new_pic, m->reordered_input_picture[0]->f); |
| 1773 | 1767 | if (ret < 0) |
| 1774 | 1768 | goto fail; |
| 1775 | 1769 | for (int i = 0; i < MPV_MAX_PLANES; i++) { |
| @@ -1777,8 +1771,8 @@ static int select_input_picture(MPVMainEncContext *const m) · 1 unmodified line |
| 1777 | 1771 | s->new_pic->data[i] += INPLACE_OFFSET; |
| 1778 | 1772 | } |
| 1779 | 1773 | } |
| 1780 | | − s->cur_pic.ptr = s->reordered_input_picture[0]; |
| 1781 | | − s->reordered_input_picture[0] = NULL; |
| 1774 | + s->cur_pic.ptr = m->reordered_input_picture[0]; |
| 1775 | + m->reordered_input_picture[0] = NULL; |
| 1782 | 1776 | av_assert1(s->mb_width == s->buffer_pools.alloc_mb_width); |
| 1783 | 1777 | av_assert1(s->mb_height == s->buffer_pools.alloc_mb_height); |
| 1784 | 1778 | av_assert1(s->mb_stride == s->buffer_pools.alloc_mb_stride); |
| @@ -1793,7 +1787,7 @@ static int select_input_picture(MPVMainEncContext *const m) · 8 unmodified lines |
| 1793 | 1787 | } |
| 1794 | 1788 | return 0; |
| 1795 | 1789 | fail: |
| 1796 | | − av_refstruct_unref(&s->reordered_input_picture[0]); |
| 1790 | + av_refstruct_unref(&m->reordered_input_picture[0]); |
| 1797 | 1791 | return ret; |
| 1798 | 1792 | } |
| 1799 | 1793 | |