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) ...@@ -813,6 +813,7 @@ static int SubpictureRegionsLink(vout_display_t *vd, const picture_t *picture)
i_sub++; i_sub++;
} }
cache_ref(cache);
vlc_mutex_unlock(&sys->cache_lock); vlc_mutex_unlock(&sys->cache_lock);
return VLC_SUCCESS; return VLC_SUCCESS;
...@@ -845,8 +846,8 @@ error: ...@@ -845,8 +846,8 @@ error:
static void SubpictureRegionsUnlink(vout_display_t *vd, picture_t *picture) static void SubpictureRegionsUnlink(vout_display_t *vd, picture_t *picture)
{ {
vout_display_sys_t *sys = vd->sys; vout_display_sys_t *sys = vd->sys;
picture_sys_t *surface = picture->p_sys; picture_sys_t *surface = picture->p_sys;
assert(surface); assert(surface);
assert(surface->i_id != VA_INVALID_SURFACE); assert(surface->i_id != VA_INVALID_SURFACE);
...@@ -858,6 +859,10 @@ static void SubpictureRegionsUnlink(vout_display_t *vd, picture_t *picture) ...@@ -858,6 +859,10 @@ static void SubpictureRegionsUnlink(vout_display_t *vd, picture_t *picture)
assert(cache->i_id != VA_INVALID_ID); 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); const int count = vlc_array_count(&cache->subpictures);
for (int i = 0; i < count; i++) for (int i = 0; i < count; i++)
{ {
...@@ -879,6 +884,20 @@ static void SubpictureRegionsUnlink(vout_display_t *vd, picture_t *picture) ...@@ -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: error:
vlc_mutex_unlock(&sys->cache_lock); vlc_mutex_unlock(&sys->cache_lock);
} }
...@@ -1084,7 +1103,7 @@ static int RenderDirectSubpicture(vout_display_t *vd, picture_t *picture, subpic ...@@ -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() */ /* remember what was created, so it can be released in DisplayPicture() */
vlc_mutex_lock(&sys->cache_lock); vlc_mutex_lock(&sys->cache_lock);
vlc_array_append(&sys->cache, (void *)cache); vlc_array_append(&sys->cache, (void *)cache);
cache_ref(cache); //cache_ref(cache);
sys->render.i_cache = cache->i_id; sys->render.i_cache = cache->i_id;
surface->i_cache = cache->i_id; surface->i_cache = cache->i_id;
vlc_mutex_unlock(&sys->cache_lock); vlc_mutex_unlock(&sys->cache_lock);
...@@ -1169,7 +1188,7 @@ static int RenderCachedSubpictures(vout_display_t *vd, picture_t *picture, ...@@ -1169,7 +1188,7 @@ static int RenderCachedSubpictures(vout_display_t *vd, picture_t *picture,
goto cleanup; goto cleanup;
picture->p_sys->i_cache = cache->i_id; picture->p_sys->i_cache = cache->i_id;
cache_ref(cache); //cache_ref(cache);
vlc_mutex_unlock(&sys->cache_lock); vlc_mutex_unlock(&sys->cache_lock);
return VLC_SUCCESS; return VLC_SUCCESS;
...@@ -1270,6 +1289,8 @@ static void PictureRelease(picture_t *picture) ...@@ -1270,6 +1289,8 @@ static void PictureRelease(picture_t *picture)
vlc_mutex_unlock(&vd->sys->cache_lock); vlc_mutex_unlock(&vd->sys->cache_lock);
} }
surface->i_cache = VA_INVALID_ID;
/* */ /* */
vd->sys->conn->lock(); vd->sys->conn->lock();
vaDestroySurfaces(vd->sys->conn->p_display, &picture->p_sys->i_id, 1); vaDestroySurfaces(vd->sys->conn->p_display, &picture->p_sys->i_id, 1);
...@@ -1363,11 +1384,12 @@ static void PictureUnlock(picture_t *picture) ...@@ -1363,11 +1384,12 @@ static void PictureUnlock(picture_t *picture)
if (surface == NULL) if (surface == NULL)
return; return;
#if 0
if (surface->i_cache != VA_INVALID_ID)
{
vout_display_t *vd = (vout_display_t*) picture->p_sys->obj; vout_display_t *vd = (vout_display_t*) picture->p_sys->obj;
vout_display_sys_t *sys = (vout_display_sys_t *) vd->sys; vout_display_sys_t *sys = (vout_display_sys_t *) vd->sys;
if (surface->i_cache != VA_INVALID_ID)
{
vlc_mutex_lock(&sys->cache_lock); vlc_mutex_lock(&sys->cache_lock);
#ifdef VAAPI_DEBUG #ifdef VAAPI_DEBUG
msg_Dbg(vd, "unlink surface %d cache %d", surface->i_id, surface->i_cache); msg_Dbg(vd, "unlink surface %d cache %d", surface->i_id, surface->i_cache);
...@@ -1391,7 +1413,7 @@ static void PictureUnlock(picture_t *picture) ...@@ -1391,7 +1413,7 @@ static void PictureUnlock(picture_t *picture)
} }
vlc_mutex_unlock(&sys->cache_lock); vlc_mutex_unlock(&sys->cache_lock);
} }
#endif
/* */ /* */
if (surface->i_refcount > 0) if (surface->i_refcount > 0)
surface->i_refcount--; 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