[vlc-devel] [PATCH 1/3] decoder: move device close callback
RĂ©mi Denis-Courmont
remi at remlab.net
Wed Jul 17 22:17:23 CEST 2019
This moves the decoder device close callback to a dedicated
type-specific structure, to avoid type-unsafe variable-arguments
vlc_module_unload().
---
include/vlc_codec.h | 9 +++++++--
modules/hw/vaapi/decoder_device.c | 7 ++++++-
modules/video_output/opengl/converter_vdpau.c | 5 +++++
src/input/decoder_helpers.c | 11 +++--------
4 files changed, 21 insertions(+), 11 deletions(-)
diff --git a/include/vlc_codec.h b/include/vlc_codec.h
index 86f092c029..aa45f36f36 100644
--- a/include/vlc_codec.h
+++ b/include/vlc_codec.h
@@ -494,6 +494,11 @@ enum vlc_decoder_device_type
VLC_DECODER_DEVICE_MMAL,
};
+struct vlc_decoder_device_operations
+{
+ void (*close)(struct vlc_decoder_device *);
+};
+
/**
* Decoder context struct
*/
@@ -501,6 +506,8 @@ typedef struct vlc_decoder_device
{
struct vlc_object_t obj;
+ const struct vlc_decoder_device_operations *ops;
+
/** Private context that could be used by the "decoder device" module
* implementation */
void *sys;
@@ -531,8 +538,6 @@ typedef struct vlc_decoder_device
**/
typedef int (*vlc_decoder_device_Open)(vlc_decoder_device *device,
vout_window_t *window);
-/** "decoder device" module close entry point */
-typedef void (*vlc_decoder_device_Close)(vlc_decoder_device *device);
/**
* Create a decoder device from a window
diff --git a/modules/hw/vaapi/decoder_device.c b/modules/hw/vaapi/decoder_device.c
index 99fd832849..6f5df9eb7e 100644
--- a/modules/hw/vaapi/decoder_device.c
+++ b/modules/hw/vaapi/decoder_device.c
@@ -216,6 +216,10 @@ Close(vlc_decoder_device *device)
vaapi_DestroyInstance(device->sys);
}
+static const struct vlc_decoder_device_operations ops = {
+ .close = Close,
+};
+
static int
Open(vlc_decoder_device *device, vout_window_t *window)
{
@@ -237,6 +241,7 @@ Open(vlc_decoder_device *device, vout_window_t *window)
return VLC_EGENERIC;
assert(vadpy != NULL);
+ device->ops = &ops;
device->sys = vainst;
device->type = VLC_DECODER_DEVICE_VAAPI;
device->opaque = vadpy;
@@ -260,7 +265,7 @@ Open(vlc_decoder_device *device, vout_window_t *window)
vlc_module_begin ()
set_description("VA-API decoder device for " DESCRIPTION_SUFFIX)
set_capability("decoder device", PRIORITY)
- set_callbacks(Open, Close)
+ set_callbacks(Open, NULL)
set_category(CAT_VIDEO)
set_subcategory(SUBCAT_VIDEO_VOUT)
add_shortcut("vaapi", SHORTCUT)
diff --git a/modules/video_output/opengl/converter_vdpau.c b/modules/video_output/opengl/converter_vdpau.c
index d40d5d181f..40f2fc4e41 100644
--- a/modules/video_output/opengl/converter_vdpau.c
+++ b/modules/video_output/opengl/converter_vdpau.c
@@ -184,6 +184,10 @@ DecoderContextClose(vlc_decoder_device *device)
vdp_release_x11(device->opaque);
}
+static const struct vlc_decoder_device_operations dev_ops = {
+ .close = DecoderContextClose,
+};
+
static int
DecoderContextOpen(vlc_decoder_device *device, vout_window_t *window)
{
@@ -196,6 +200,7 @@ DecoderContextOpen(vlc_decoder_device *device, vout_window_t *window)
if (vdp_get_x11(window->display.x11, -1, &vdp, &vdpdevice) != VDP_STATUS_OK)
return VLC_EGENERIC;
+ device->ops = &dev_ops;
device->type = VLC_DECODER_DEVICE_VDPAU;
device->opaque = vdp;
return VLC_SUCCESS;
diff --git a/src/input/decoder_helpers.c b/src/input/decoder_helpers.c
index 7384e2bda0..f1ef1bfd20 100644
--- a/src/input/decoder_helpers.c
+++ b/src/input/decoder_helpers.c
@@ -120,13 +120,6 @@ static int decoder_device_Open(void *func, bool forced, va_list ap)
return ret;
}
-static void decoder_device_Close(void *func, va_list ap)
-{
- vlc_decoder_device_Close close = func;
- vlc_decoder_device *device = va_arg(ap, vlc_decoder_device *);
- close(device);
-}
-
vlc_decoder_device *
vlc_decoder_device_Create(vout_window_t *window)
{
@@ -145,6 +138,7 @@ vlc_decoder_device_Create(vout_window_t *window)
vlc_object_delete(&priv->device);
return NULL;
}
+ assert(priv->device.ops != NULL);
vlc_atomic_rc_init(&priv->rc);
return &priv->device;
}
@@ -165,7 +159,8 @@ vlc_decoder_device_Release(vlc_decoder_device *device)
container_of(device, struct vlc_decoder_device_priv, device);
if (vlc_atomic_rc_dec(&priv->rc))
{
- vlc_module_unload(priv->module, decoder_device_Close, device);
+ assert(device->ops->close != NULL);
+ device->ops->close(device);
vlc_objres_clear(VLC_OBJECT(device));
vlc_object_delete(device);
}
--
2.22.0
More information about the vlc-devel
mailing list