| 1636 | } |
| 1637 | |
| 1638 | static av_cold int vaapi_encode_init_gop_structure(AVCodecContext *avctx) |
| 1639 | { |
| 1640 | FFHWBaseEncodeContext *base_ctx = avctx->priv_data; |
| 1641 | VAAPIEncodeContext *ctx = avctx->priv_data; |
| 1642 | VAStatus vas; |
| 1643 | VAConfigAttrib attr = { VAConfigAttribEncMaxRefFrames }; |
| 1644 | uint32_t ref_l0, ref_l1; |
| 1645 | int prediction_pre_only, err; |
| 1646 | |
| 1647 | vas = vaGetConfigAttributes(ctx->hwctx->display, |
| 1648 | ctx->va_profile, |
| 1649 | ctx->va_entrypoint, |
| 1650 | &attr, 1); |
| 1651 | if (vas != VA_STATUS_SUCCESS) { |
| 1652 | av_log(avctx, AV_LOG_ERROR, "Failed to query reference frames " |
| 1653 | "attribute: %d (%s).\n", vas, vaErrorStr(vas)); |
| 1654 | return AVERROR_EXTERNAL; |
| 1655 | } |
| 1656 | |
| 1657 | if (attr.value == VA_ATTRIB_NOT_SUPPORTED) { |
| 1658 | ref_l0 = ref_l1 = 0; |
| 1659 | } else { |
| 1660 | ref_l0 = attr.value & 0xffff; |
| 1661 | ref_l1 = attr.value >> 16 & 0xffff; |
| 1662 | } |
| 1663 | |
| 1664 | base_ctx->p_to_gpb = 0; |
| 1665 | prediction_pre_only = 0; |
| 1666 | |
| 1667 | #if VA_CHECK_VERSION(1, 9, 0) |
| 1668 | if (!(ctx->codec->flags & FF_HW_FLAG_INTRA_ONLY || |
| 1669 | avctx->gop_size <= 1)) { |
| 1670 | attr = (VAConfigAttrib) { VAConfigAttribPredictionDirection }; |
| 1671 | vas = vaGetConfigAttributes(ctx->hwctx->display, |
| 1672 | ctx->va_profile, |
| 1673 | ctx->va_entrypoint, |
| 1674 | &attr, 1); |
| 1675 | if (vas != VA_STATUS_SUCCESS) { |
| 1676 | av_log(avctx, AV_LOG_WARNING, "Failed to query prediction direction " |
| 1677 | "attribute: %d (%s).\n", vas, vaErrorStr(vas)); |
| 1678 | return AVERROR_EXTERNAL; |
| 1679 | } else if (attr.value == VA_ATTRIB_NOT_SUPPORTED) { |
| 1680 | av_log(avctx, AV_LOG_VERBOSE, "Driver does not report any additional " |
| 1681 | "prediction constraints.\n"); |
| 1682 | } else { |
| 1683 | if (((ref_l0 > 0 || ref_l1 > 0) && !(attr.value & VA_PREDICTION_DIRECTION_PREVIOUS)) || |
| 1684 | ((ref_l1 == 0) && (attr.value & (VA_PREDICTION_DIRECTION_FUTURE | VA_PREDICTION_DIRECTION_BI_NOT_EMPTY)))) { |
| 1685 | av_log(avctx, AV_LOG_ERROR, "Driver report incorrect prediction " |
| 1686 | "direction attribute.\n"); |
| 1687 | return AVERROR_EXTERNAL; |
| 1688 | } |
| 1689 | |
| 1690 | if (!(attr.value & VA_PREDICTION_DIRECTION_FUTURE)) { |
| 1691 | if (ref_l0 > 0 && ref_l1 > 0) { |
| 1692 | prediction_pre_only = 1; |
| 1693 | av_log(avctx, AV_LOG_VERBOSE, "Driver only support same reference " |
| 1694 | "lists for B-frames.\n"); |
| 1695 | } |
no test coverage detected