va: Fix/add buffer stride/offset validation
On my system, Vega64, VA element tries P010 decoding and exporting that to DMABuf, and that goes terribly wrong and fail.
0:08:13.958544331 410736 0x7fff840990c0 ERROR videometa gstvideometa.c:242:default_map: plane 1, no memory at offset 16588800
0:08:13.958598383 410736 0x7fff840990c0 ERROR default video-frame.c:168:gst_video_frame_map_id: failed to map video frame plane 1
While debugging that, I've stumbled what looks like driver bug, but also pretty much dislike the sloppiness of the dmabuf exporting code (gst_va_dmabuf_allocator_setup_buffer_full()). This function is partially implemented and is missing any kind of validation. Here's the prime descriptor that I'm getting:
$4 = {
fourcc = 808530000,
width = 3840,
height = 2160,
num_objects = 2,
objects = {{
fd = 28,
size = 8294400,
drm_format_modifier = 0
}, {
fd = 29,
size = 8294400,
drm_format_modifier = 0
}, {
fd = 0,
size = 0,
drm_format_modifier = 0
}, {
fd = 0,
size = 0,
drm_format_modifier = 0
}},
num_layers = 2,
layers = {{
drm_format = 540422482,
num_planes = 1,
object_index = {0, 0, 0, 0},
offset = {0, 0, 0, 0},
pitch = {7680, 0, 0, 0}
}, {
drm_format = 842224199,
num_planes = 1,
object_index = {1, 0, 0, 0},
offset = {16588800, 0, 0, 0},
pitch = {7680, 0, 0, 0}
}, {
drm_format = 0,
num_planes = 0,
object_index = {0, 0, 0, 0},
offset = {0, 0, 0, 0},
pitch = {0, 0, 0, 0}
}, {
drm_format = 0,
num_planes = 0,
object_index = {0, 0, 0, 0},
offset = {0, 0, 0, 0},
pitch = {0, 0, 0, 0}
}}
}
So basically two DMABuf and 2 layers. That makes sense, more of less, I'm a little surprise that the offset aren't relative to the object starts here if you see what I mean. But perhaps this is documented somewhere ? In short, first bug, the size of the first DMABuf should have been at least 16588800 (which matches the offset), but has been set to 8294400. The pitch looks fine, the second dmabuf size is fine, since its sub-sampled. We should be able to fail early and cleanly on this type of driver error imho.