From 498ee00acbfe74a6cdcf52edca245541f42be996 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Reinhard=20Ni=C3=9Fl?= Date: Sun, 6 Feb 2011 19:29:20 +0100 Subject: Fix argb_layer handling in xine-libs OSD stack. xine-libs OSD stack is event driven and some memory blocks are not copied but responsibility to free the memory moves to different layers of the OSD stack. When argb_layer was introduced, this behavior was not taken into account and as such it is likely that for example osd_free_object() frees the argb_layer while vdpau_overlay_* functions still access the memory. Passing responsibility for the argb_layer is not that easy as it seems as the design goal of the argb_layer was to not duplicate any memory of the argb_buffer which all other OSD functions usually do. To solve this issue, argb_layer_t will be turned into a managed data structure by introducing a ref_count member. ref_count increases as more layers of the OSD stack hold a reference to that memory block, and it decreases when they are no longer interested in it. When ref_count reaches zero the memory block is freed automatically. To deal with ref counting, set_argb_layer_ptr() has been introduced. Some functions of the OSD layers had to be modified to deal with reference tracking. For convinience, osd_free_object() should clear the argb_buffer pointer so that the buffer may be freed safely after returning. --- include/xine/osd.h | 2 +- include/xine/video_out.h | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) (limited to 'include') diff --git a/include/xine/osd.h b/include/xine/osd.h index 00df97ad2..44471534b 100644 --- a/include/xine/osd.h +++ b/include/xine/osd.h @@ -69,7 +69,7 @@ struct osd_object_s { /* this holds an optional ARGB overlay, which * is only be used by supported video_out modules. * right now this is only vdpau */ - argb_layer_t argb_layer; + argb_layer_t *argb_layer; int32_t handle; }; diff --git a/include/xine/video_out.h b/include/xine/video_out.h index 9d5380884..799e8f726 100644 --- a/include/xine/video_out.h +++ b/include/xine/video_out.h @@ -449,6 +449,7 @@ typedef struct argb_layer_s { /* dirty area */ int x1, y1; int x2, y2; + int ref_count; } argb_layer_t; struct vo_overlay_s { @@ -489,6 +490,7 @@ struct vo_overlay_s { argb_layer_t *argb_layer; }; +void set_argb_layer_ptr(argb_layer_t **dst, argb_layer_t *src); /* API to video_overlay manager * -- cgit v1.2.3