From a7fe47e49521009e2790e28c286ef199dae0b4f5 Mon Sep 17 00:00:00 2001 From: wm4 Date: Sun, 4 May 2014 10:50:32 +0200 Subject: vdpau: deduplicate video surface upload code This was a minor code duplication between vf_vdpaupp.c and vo_vdpau.c. (In theory, we could always require using vf_vdpaupp with vo_vdpau, but I think it's better if vo_vdpau can work standalone.) --- video/vdpau.c | 33 +++++++++++++++++++++++++++++++++ 1 file changed, 33 insertions(+) (limited to 'video/vdpau.c') diff --git a/video/vdpau.c b/video/vdpau.c index a53986c36e..35f5cf457d 100644 --- a/video/vdpau.c +++ b/video/vdpau.c @@ -273,3 +273,36 @@ bool mp_vdpau_get_format(int imgfmt, VdpChromaType *out_chroma_type, *out_pixel_format = ycbcr; return true; } + +// Use mp_vdpau_get_video_surface, and upload mpi to it. Return NULL on failure. +// If the image is already a vdpau video surface, just return a reference. +struct mp_image *mp_vdpau_upload_video_surface(struct mp_vdpau_ctx *ctx, + struct mp_image *mpi) +{ + struct vdp_functions *vdp = &ctx->vdp; + VdpStatus vdp_st; + + if (mpi->imgfmt == IMGFMT_VDPAU) + return mp_image_new_ref(mpi); + + VdpChromaType chroma_type; + VdpYCbCrFormat pixel_format; + if (!mp_vdpau_get_format(mpi->imgfmt, &chroma_type, &pixel_format)) + return NULL; + + struct mp_image *hwmpi = + mp_vdpau_get_video_surface(ctx, chroma_type, mpi->w, mpi->h); + if (!hwmpi) + return NULL; + + VdpVideoSurface surface = (intptr_t)hwmpi->planes[3]; + const void *destdata[3] = {mpi->planes[0], mpi->planes[2], mpi->planes[1]}; + if (mpi->imgfmt == IMGFMT_NV12) + destdata[1] = destdata[2]; + vdp_st = vdp->video_surface_put_bits_y_cb_cr(surface, + pixel_format, destdata, mpi->stride); + CHECK_VDP_WARNING(ctx, "Error when calling vdp_video_surface_put_bits_y_cb_cr"); + + mp_image_copy_attributes(hwmpi, mpi); + return hwmpi; +} -- cgit v1.2.3