Commit 297c1018 authored by Jean-Paul Saman's avatar Jean-Paul Saman

VAAPI-X11: adjust subpicture cache refcounting

Do refcounting when the subpicture is actually attached to the picture,
thus only in SubpictureRegionsLink() and SubpictureRegionsUnlink() functions
parent 2983621b
......@@ -813,6 +813,7 @@ static int SubpictureRegionsLink(vout_display_t *vd, const picture_t *picture)
i_sub++;
}
cache_ref(cache);
vlc_mutex_unlock(&sys->cache_lock);
return VLC_SUCCESS;
......@@ -845,8 +846,8 @@ error:
static void SubpictureRegionsUnlink(vout_display_t *vd, picture_t *picture)
{
vout_display_sys_t *sys = vd->sys;
picture_sys_t *surface = picture->p_sys;
assert(surface);
assert(surface->i_id != VA_INVALID_SURFACE);
......@@ -858,6 +859,10 @@ static void SubpictureRegionsUnlink(vout_display_t *vd, picture_t *picture)
assert(cache->i_id != VA_INVALID_ID);
#ifdef VAAPI_DEBUG
msg_Dbg(vd, "unlink surface %d cache %d", surface->i_id, surface->i_cache);
#endif
const int count = vlc_array_count(&cache->subpictures);
for (int i = 0; i < count; i++)
{
......@@ -879,6 +884,20 @@ static void SubpictureRegionsUnlink(vout_display_t *vd, picture_t *picture)
}
}
cache_unref(cache);
/* Do we still need need this subpicture cache ? */
if ((cache->i_refcount == 0) &&
(sys->render.i_cache != surface->i_cache) &&
(mdate() > cache->i_stop))
{
int index = vlc_array_index_of_item(&sys->cache, (void*)cache);
vlc_array_remove(&sys->cache, index);
SubpictureCacheClean(vd, sys->conn, cache);
cache_destroy(cache);
cache = NULL;
}
error:
vlc_mutex_unlock(&sys->cache_lock);
}
......@@ -1084,7 +1103,7 @@ static int RenderDirectSubpicture(vout_display_t *vd, picture_t *picture, subpic
/* remember what was created, so it can be released in DisplayPicture() */
vlc_mutex_lock(&sys->cache_lock);
vlc_array_append(&sys->cache, (void *)cache);
cache_ref(cache);
//cache_ref(cache);
sys->render.i_cache = cache->i_id;
surface->i_cache = cache->i_id;
vlc_mutex_unlock(&sys->cache_lock);
......@@ -1169,7 +1188,7 @@ static int RenderCachedSubpictures(vout_display_t *vd, picture_t *picture,
goto cleanup;
picture->p_sys->i_cache = cache->i_id;
cache_ref(cache);
//cache_ref(cache);
vlc_mutex_unlock(&sys->cache_lock);
return VLC_SUCCESS;
......@@ -1270,6 +1289,8 @@ static void PictureRelease(picture_t *picture)
vlc_mutex_unlock(&vd->sys->cache_lock);
}
surface->i_cache = VA_INVALID_ID;
/* */
vd->sys->conn->lock();
vaDestroySurfaces(vd->sys->conn->p_display, &picture->p_sys->i_id, 1);
......@@ -1363,11 +1384,12 @@ static void PictureUnlock(picture_t *picture)
if (surface == NULL)
return;
vout_display_t *vd = (vout_display_t*) picture->p_sys->obj;
vout_display_sys_t *sys = (vout_display_sys_t *) vd->sys;
#if 0
if (surface->i_cache != VA_INVALID_ID)
{
vout_display_t *vd = (vout_display_t*) picture->p_sys->obj;
vout_display_sys_t *sys = (vout_display_sys_t *) vd->sys;
vlc_mutex_lock(&sys->cache_lock);
#ifdef VAAPI_DEBUG
msg_Dbg(vd, "unlink surface %d cache %d", surface->i_id, surface->i_cache);
......@@ -1391,7 +1413,7 @@ static void PictureUnlock(picture_t *picture)
}
vlc_mutex_unlock(&sys->cache_lock);
}
#endif
/* */
if (surface->i_refcount > 0)
surface->i_refcount--;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment