vdpau: don't crash on flipped images

It seems the vdpau API does not support these.

Do a semi-expensive emulation of it. On the other hand, it's not like
this is a commonly-used feature. (It might be better to make --vf=flip
always copy instead of flipping it via pointer tricks - but everything
allows flipped images, and even decoders or libavfilter filters could
output them.)
This commit is contained in:
wm4 2014-08-05 00:18:57 +02:00
parent ee6df2f76c
commit d634f7b01a
1 changed files with 12 additions and 5 deletions

View File

@ -409,22 +409,29 @@ struct mp_image *mp_vdpau_upload_video_surface(struct mp_vdpau_ctx *ctx,
if (!hwmpi) if (!hwmpi)
return NULL; return NULL;
struct mp_image *src = mpi;
if (mpi->stride[0] < 0)
src = mp_image_new_copy(mpi); // unflips it when copying
if (hwmpi->imgfmt == IMGFMT_VDPAU) { if (hwmpi->imgfmt == IMGFMT_VDPAU) {
VdpVideoSurface surface = (intptr_t)hwmpi->planes[3]; VdpVideoSurface surface = (intptr_t)hwmpi->planes[3];
const void *destdata[3] = {mpi->planes[0], mpi->planes[2], mpi->planes[1]}; const void *destdata[3] = {src->planes[0], src->planes[2], src->planes[1]};
if (mpi->imgfmt == IMGFMT_NV12) if (src->imgfmt == IMGFMT_NV12)
destdata[1] = destdata[2]; destdata[1] = destdata[2];
vdp_st = vdp->video_surface_put_bits_y_cb_cr(surface, vdp_st = vdp->video_surface_put_bits_y_cb_cr(surface,
ycbcr, destdata, mpi->stride); ycbcr, destdata, src->stride);
} else { } else {
VdpOutputSurface rgb_surface = (intptr_t)hwmpi->planes[3]; VdpOutputSurface rgb_surface = (intptr_t)hwmpi->planes[3];
vdp_st = vdp->output_surface_put_bits_native(rgb_surface, vdp_st = vdp->output_surface_put_bits_native(rgb_surface,
&(const void *){mpi->planes[0]}, &(const void *){src->planes[0]},
&(uint32_t){mpi->stride[0]}, &(uint32_t){src->stride[0]},
NULL); NULL);
} }
CHECK_VDP_WARNING(ctx, "Error when uploading surface"); CHECK_VDP_WARNING(ctx, "Error when uploading surface");
if (src != mpi)
talloc_free(src);
mp_image_copy_attributes(hwmpi, mpi); mp_image_copy_attributes(hwmpi, mpi);
return hwmpi; return hwmpi;
} }