This allows some optimizations in driver, such as not having to read back the data if write-only mapping is requested.
Unified · Split
| @@ -809,6 +809,9 @@ static int vaapi_map_frame(AVHWFramesContext *hwfc, · 808 unmodified lines | ||
| 809 | 809 | VAStatus vas; |
| 810 | 810 | void *address = NULL; |
| 811 | 811 | int err, i; |
| 812 | +#if VA_CHECK_VERSION(1, 21, 0) | |
| 813 | + uint32_t vaflags = 0; | |
| 814 | +#endif | |
| 812 | 815 | |
| 813 | 816 | surface_id = (VASurfaceID)(uintptr_t)src->data[3]; |
| 814 | 817 | av_log(hwfc, AV_LOG_DEBUG, "Map surface %#x.\n", surface_id); |
| @@ -892,7 +895,16 @@ static int vaapi_map_frame(AVHWFramesContext *hwfc, · 77 unmodified lines | ||
| 892 | 895 | } |
| 893 | 896 | } |
| 894 | 897 | |
| 898 | +#if VA_CHECK_VERSION(1, 21, 0) | |
| 899 | + if (flags & AV_HWFRAME_MAP_READ) | |
| 900 | + vaflags |= VA_MAPBUFFER_FLAG_READ; | |
| 901 | + if (flags & AV_HWFRAME_MAP_WRITE) | |
| 902 | + vaflags |= VA_MAPBUFFER_FLAG_WRITE; | |
| 903 | + // On drivers not implementing vaMapBuffer2 libva calls vaMapBuffer instead. | |
| 904 | + vas = vaMapBuffer2(hwctx->display, map->image.buf, &address, vaflags); | |
| 905 | +#else | |
| 895 | 906 | vas = vaMapBuffer(hwctx->display, map->image.buf, &address); |
| 907 | +#endif | |
| 896 | 908 | if (vas != VA_STATUS_SUCCESS) { |
| 897 | 909 | av_log(hwfc, AV_LOG_ERROR, "Failed to map image from surface " |
| 898 | 910 | "%#x: %d (%s).\n", surface_id, vas, vaErrorStr(vas)); |