[vlc-devel] [PATCH 01/10] vdpau: move the decoder device vdp_t in a structure
Steve Lhomme
robux4 at ycbcr.xyz
Fri Nov 22 14:12:29 CET 2019
---
modules/hw/vdpau/avcodec.c | 3 ++-
modules/hw/vdpau/vlc_vdpau.h | 21 ++++++++++++++++++-
modules/video_output/opengl/converter_vdpau.c | 21 ++++++++++++-------
3 files changed, 36 insertions(+), 9 deletions(-)
diff --git a/modules/hw/vdpau/avcodec.c b/modules/hw/vdpau/avcodec.c
index 74aa135f70c..e0eae43bb1c 100644
--- a/modules/hw/vdpau/avcodec.c
+++ b/modules/hw/vdpau/avcodec.c
@@ -228,7 +228,8 @@ static int Open(vlc_va_t *va, AVCodecContext *avctx, const AVPixFmtDescriptor *d
sys->width = width;
sys->height = height;
sys->hwaccel_context = NULL;
- vctx_priv->vdp = GetVDPAUOpaqueDevice(dec_device);
+ vdpau_decoder_device_t *vdpau_decoder = GetVDPAUOpaqueDevice(dec_device);
+ vctx_priv->vdp = vdpau_decoder->vdp;
vdp_hold_x11(vctx_priv->vdp, &sys->device);
unsigned flags = AV_HWACCEL_FLAG_ALLOW_HIGH_DEPTH;
diff --git a/modules/hw/vdpau/vlc_vdpau.h b/modules/hw/vdpau/vlc_vdpau.h
index ba5d1443bf0..81f5ad1c50a 100644
--- a/modules/hw/vdpau/vlc_vdpau.h
+++ b/modules/hw/vdpau/vlc_vdpau.h
@@ -275,13 +275,32 @@ typedef struct vlc_vdp_video_field
float sharpen;
} vlc_vdp_video_field_t;
-static inline vdp_t *GetVDPAUOpaqueDevice(vlc_decoder_device *device)
+typedef struct {
+ vdp_t *vdp;
+} vdpau_decoder_device_t;
+
+static inline vdpau_decoder_device_t *GetVDPAUOpaqueDevice(vlc_decoder_device *device)
{
if (device == NULL || device->type != VLC_DECODER_DEVICE_VDPAU)
return NULL;
return device->opaque;
}
+static inline vdpau_decoder_device_t *GetVDPAUOpaqueContext(vlc_video_context *vctx)
+{
+ vlc_decoder_device *device = vctx ? vlc_video_context_HoldDevice(vctx) : NULL;
+ if (unlikely(device == NULL))
+ return NULL;
+ vdpau_decoder_device_t *res = NULL;
+ if (device->type == VLC_DECODER_DEVICE_VDPAU)
+ {
+ assert(device->opaque != NULL);
+ res = GetVDPAUOpaqueDevice(device);
+ }
+ vlc_decoder_device_Release(device);
+ return res;
+}
+
/**
* Attaches a VDPAU video surface as context of a VLC picture.
*/
diff --git a/modules/video_output/opengl/converter_vdpau.c b/modules/video_output/opengl/converter_vdpau.c
index b2ab5459e8b..f71585bdf5a 100644
--- a/modules/video_output/opengl/converter_vdpau.c
+++ b/modules/video_output/opengl/converter_vdpau.c
@@ -68,7 +68,7 @@ tc_vdpau_gl_get_pool(opengl_tex_converter_t const *tc,
{
converter_sys_t *sys = tc->priv;
vlc_decoder_device *dec_device = sys->dec_device;
- return vlc_vdp_output_pool_create(GetVDPAUOpaqueDevice(dec_device),
+ return vlc_vdp_output_pool_create(GetVDPAUOpaqueDevice(dec_device)->vdp,
VDP_RGBA_FORMAT_B8G8R8A8,
&tc->fmt, requested_count);
}
@@ -120,7 +120,7 @@ Close(vlc_object_t *obj)
_glVDPAUFiniNV(); assert(tc->vt->GetError() == GL_NO_ERROR);
converter_sys_t *sys = tc->priv;
vlc_decoder_device *dec_device = sys->dec_device;
- vdp_release_x11(GetVDPAUOpaqueDevice(dec_device));
+ vdp_release_x11(GetVDPAUOpaqueDevice(dec_device)->vdp);
vlc_decoder_device_Release(dec_device);
}
@@ -153,7 +153,7 @@ Open(vlc_object_t *obj)
tc->fmt.i_chroma = VLC_CODEC_VDPAU_OUTPUT;
VdpDevice device;
- vdp_t *vdp = GetVDPAUOpaqueDevice(dec_device);
+ vdp_t *vdp = GetVDPAUOpaqueDevice(dec_device)->vdp;
vdp_hold_x11(vdp, &device);
void *vdp_gpa;
@@ -206,7 +206,8 @@ Open(vlc_object_t *obj)
static void
DecoderDeviceClose(vlc_decoder_device *device)
{
- vdp_release_x11(GetVDPAUOpaqueDevice(device));
+ vdpau_decoder_device_t *vdpau_dev = GetVDPAUOpaqueDevice(device);
+ vdp_release_x11(vdpau_dev->vdp);
}
static const struct vlc_decoder_device_operations dev_ops = {
@@ -219,15 +220,21 @@ DecoderDeviceOpen(vlc_decoder_device *device, vout_window_t *window)
if (!window || !vlc_xlib_init(VLC_OBJECT(window)))
return VLC_EGENERIC;
- vdp_t *vdp;
+ vdpau_decoder_device_t *sys = vlc_obj_malloc(VLC_OBJECT(device), sizeof(*sys));
+ if (unlikely(sys == NULL))
+ return VLC_ENOMEM;
+
VdpDevice vdpdevice;
- if (vdp_get_x11(window->display.x11, -1, &vdp, &vdpdevice) != VDP_STATUS_OK)
+ if (vdp_get_x11(window->display.x11, -1, &sys->vdp, &vdpdevice) != VDP_STATUS_OK)
+ {
+ vlc_obj_free(VLC_OBJECT(device), sys);
return VLC_EGENERIC;
+ }
device->ops = &dev_ops;
device->type = VLC_DECODER_DEVICE_VDPAU;
- device->opaque = vdp;
+ device->opaque = sys;
return VLC_SUCCESS;
}
--
2.17.1
More information about the vlc-devel
mailing list