| 822 | } |
| 823 | |
| 824 | static int vaapi_map_frame(AVHWFramesContext *hwfc, |
| 825 | AVFrame *dst, const AVFrame *src, int flags) |
| 826 | { |
| 827 | AVVAAPIDeviceContext *hwctx = hwfc->device_ctx->hwctx; |
| 828 | VAAPIFramesContext *ctx = hwfc->hwctx; |
| 829 | VASurfaceID surface_id; |
| 830 | const VAAPIFormatDescriptor *desc; |
| 831 | VAImageFormat *image_format; |
| 832 | VAAPIMapping *map; |
| 833 | VAStatus vas; |
| 834 | void *address = NULL; |
| 835 | int err, i; |
| 836 | #if VA_CHECK_VERSION(1, 21, 0) |
| 837 | uint32_t vaflags = 0; |
| 838 | #endif |
| 839 | |
| 840 | surface_id = (VASurfaceID)(uintptr_t)src->data[3]; |
| 841 | av_log(hwfc, AV_LOG_DEBUG, "Map surface %#x.\n", surface_id); |
| 842 | |
| 843 | if (!ctx->derive_works && (flags & AV_HWFRAME_MAP_DIRECT)) { |
| 844 | // Requested direct mapping but it is not possible. |
| 845 | return AVERROR(EINVAL); |
| 846 | } |
| 847 | if (dst->format == AV_PIX_FMT_NONE) |
| 848 | dst->format = hwfc->sw_format; |
| 849 | if (dst->format != hwfc->sw_format && (flags & AV_HWFRAME_MAP_DIRECT)) { |
| 850 | // Requested direct mapping but the formats do not match. |
| 851 | return AVERROR(EINVAL); |
| 852 | } |
| 853 | |
| 854 | err = vaapi_get_image_format(hwfc->device_ctx, dst->format, &image_format); |
| 855 | if (err < 0) { |
| 856 | // Requested format is not a valid output format. |
| 857 | return err; |
| 858 | } |
| 859 | |
| 860 | map = av_malloc(sizeof(*map)); |
| 861 | if (!map) |
| 862 | return AVERROR(ENOMEM); |
| 863 | map->flags = flags; |
| 864 | map->image.image_id = VA_INVALID_ID; |
| 865 | |
| 866 | vas = vaSyncSurface(hwctx->display, surface_id); |
| 867 | if (vas != VA_STATUS_SUCCESS) { |
| 868 | av_log(hwfc, AV_LOG_ERROR, "Failed to sync surface " |
| 869 | "%#x: %d (%s).\n", surface_id, vas, vaErrorStr(vas)); |
| 870 | err = AVERROR(EIO); |
| 871 | goto fail; |
| 872 | } |
| 873 | |
| 874 | // The memory which we map using derive need not be connected to the CPU |
| 875 | // in a way conducive to fast access. On Gen7-Gen9 Intel graphics, the |
| 876 | // memory is mappable but not cached, so normal memcpy()-like access is |
| 877 | // very slow to read it (but writing is ok). It is possible to read much |
| 878 | // faster with a copy routine which is aware of the limitation, but we |
| 879 | // assume for now that the user is not aware of that and would therefore |
| 880 | // prefer not to be given direct-mapped memory if they request read access. |
| 881 | if (ctx->derive_works && dst->format == hwfc->sw_format && |
no test coverage detected