Commit a464ed78 authored by Jean-Paul Saman's avatar Jean-Paul Saman

VAAPI: Cleanup video_output/vaapi/spu.{c,h}

Rename functions and structures.
parent 50eebc56
...@@ -94,8 +94,7 @@ struct vout_display_sys_t ...@@ -94,8 +94,7 @@ struct vout_display_sys_t
subpicture_t *prev_subpicture; subpicture_t *prev_subpicture;
} render; } render;
vlc_mutex_t cache_lock; vlc_va_spu_cache_t *spu;
vlc_array_t cache; /* array of subpicture_subpicture_cache_t */
xcb_cursor_t cursor; /* blank cursor */ xcb_cursor_t cursor; /* blank cursor */
xcb_window_t window; /* drawable X window */ xcb_window_t window; /* drawable X window */
...@@ -455,8 +454,12 @@ int OpenVaapiGLX(vlc_object_t *obj) ...@@ -455,8 +454,12 @@ int OpenVaapiGLX(vlc_object_t *obj)
vd->sys = sys; vd->sys = sys;
vlc_array_init(&sys->cache); sys->spu = vlc_va_spu_cache_New();
vlc_mutex_init(&sys->cache_lock); if (!sys->spu)
{
free(sys);
return VLC_ENOMEM;
}
sys->render.prev_subpicture = NULL; sys->render.prev_subpicture = NULL;
sys->render.i_cache = 0; sys->render.i_cache = 0;
...@@ -620,8 +623,8 @@ void CloseVaapiGLX(vlc_object_t *obj) ...@@ -620,8 +623,8 @@ void CloseVaapiGLX(vlc_object_t *obj)
} }
/* Cleanup cache */ /* Cleanup cache */
vlc_mutex_destroy(&sys->cache_lock); if (sys->spu)
cache_SubpictureEmpty(obj, va, &sys->cache); vlc_va_spu_cache_Delete(va, sys->spu);
/* Cleanup VAAPI resources and connection */ /* Cleanup VAAPI resources and connection */
if (va) if (va)
...@@ -692,47 +695,36 @@ static void Render(vout_display_t *vd, picture_t *picture, subpicture_t *subpict ...@@ -692,47 +695,36 @@ static void Render(vout_display_t *vd, picture_t *picture, subpicture_t *subpict
subpicture, sys->render.prev_subpicture, subpicture, sys->render.prev_subpicture,
sys->render.i_cache, picture->p_sys->i_id); sys->render.i_cache, picture->p_sys->i_id);
#endif #endif
vlc_mutex_lock(&sys->cache_lock); int ret = vlc_va_spu_cache_Get(VLC_OBJECT(vd), sys->spu, sys->render.i_cache,
int ret = RenderCachedSubpictures(VLC_OBJECT(vd), sys->va, &sys->cache, picture, subpicture);
sys->render.i_cache, picture, subpicture);
vlc_mutex_unlock(&sys->cache_lock);
if (ret == VLC_SUCCESS) if (ret == VLC_SUCCESS)
return; return;
} }
/* new subpicture */
vlc_mutex_lock(&sys->cache_lock);
/* Release exra reference */ /* Release exra reference */
if (sys->render.i_cache > 0) if (sys->render.i_cache > 0)
cache_SubpictureRelease(VLC_OBJECT(vd), sys->va, &sys->cache, sys->render.i_cache); vlc_va_spu_cache_Release(sys->va, sys->spu, sys->render.i_cache);
/* render new subpicture */ /* render new subpicture */
subpicture_cache_t *cache = RenderDirectSubpicture(VLC_OBJECT(vd), sys->va, &sys->sub_fmt, spu_cache_t *cache = vlc_va_spu_cache_Prepare(VLC_OBJECT(vd), sys->va, &sys->sub_fmt,
picture, subpicture, sys->sflags); picture, subpicture, sys->sflags);
if (cache == NULL) if (cache == NULL)
{
vlc_mutex_unlock(&sys->cache_lock);
return; return;
}
#ifdef VAAPI_DEBUG #ifdef VAAPI_DEBUG
msg_Dbg(vd, "new subpicture %p prev %p cache %d surface %d", msg_Dbg(vd, "new subpicture %p prev %p cache %d surface %d",
subpicture, sys->render.prev_subpicture, cache_GetCacheID(cache), surface->i_id); subpicture, sys->render.prev_subpicture, vlc_va_spu_cache_GetID(cache), surface->i_id);
#endif #endif
/* remember what was created, so it can be released in DisplayPicture() */ /* remember what was created, so it can be released in DisplayPicture() */
vlc_array_append(&sys->cache, (void *)cache); vlc_va_spu_cache_Put(sys->spu, cache);
sys->render.i_cache = cache_GetCacheID(cache); sys->render.i_cache = vlc_va_spu_cache_GetID(cache);
sys->render.prev_subpicture = subpicture; sys->render.prev_subpicture = subpicture;
sys->render.i_start = subpicture->i_start; sys->render.i_start = subpicture->i_start;
sys->render.i_stop = subpicture->i_stop; sys->render.i_stop = subpicture->i_stop;
/* Hold extra reference */ /* Hold extra reference */
cache_SubpictureHold(VLC_OBJECT(vd), &sys->cache, cache_GetCacheID(cache)); vlc_va_spu_cache_Hold(sys->spu, vlc_va_spu_cache_GetID(cache));
vlc_mutex_unlock(&sys->cache_lock);
} }
static void DisplayVASurfaceGLX(vout_display_t *vd, picture_t *picture) static void DisplayVASurfaceGLX(vout_display_t *vd, picture_t *picture)
...@@ -821,11 +813,9 @@ static void DisplayPicture(vout_display_t *vd, picture_t *picture, subpicture_t ...@@ -821,11 +813,9 @@ static void DisplayPicture(vout_display_t *vd, picture_t *picture, subpicture_t
if (subpicture) if (subpicture)
{ {
vlc_mutex_lock(&sys->cache_lock); ret = vlc_va_spu_cache_Link(VLC_OBJECT(vd), sys->va, sys->spu, picture, sys->sflags);
ret = SubpictureRegionsLink(VLC_OBJECT(vd), sys->va, &sys->cache, picture, sys->sflags);
if (ret == VLC_EGENERIC) if (ret == VLC_EGENERIC)
msg_Err(vd, "Failed linking subpicture to surface"); msg_Err(vd, "Failed linking subpicture to surface");
vlc_mutex_unlock(&sys->cache_lock);
} }
if (!vlc_gl_Lock(&sys->gl)) if (!vlc_gl_Lock(&sys->gl))
...@@ -840,16 +830,14 @@ static void DisplayPicture(vout_display_t *vd, picture_t *picture, subpicture_t ...@@ -840,16 +830,14 @@ static void DisplayPicture(vout_display_t *vd, picture_t *picture, subpicture_t
if (subpicture) if (subpicture)
{ {
vlc_mutex_lock(&sys->cache_lock);
if (ret == VLC_SUCCESS) if (ret == VLC_SUCCESS)
{ {
if (SubpictureRegionsUnlink(VLC_OBJECT(vd), sys->va, &sys->cache, picture) == VLC_EGENERIC) if (vlc_va_spu_cache_Unlink(VLC_OBJECT(vd), sys->va, sys->spu, picture) == VLC_EGENERIC)
msg_Err(vd, "Could not find subpicture in cache"); msg_Err(vd, "Could not find subpicture in cache");
} }
if (picture->p_sys->i_cache > 0) if (picture->p_sys->i_cache > 0)
cache_SubpictureRelease(VLC_OBJECT(vd), sys->va, &sys->cache, picture->p_sys->i_cache); vlc_va_spu_cache_Release(sys->va, sys->spu, picture->p_sys->i_cache);
picture->p_sys->i_cache = 0; picture->p_sys->i_cache = 0;
vlc_mutex_unlock(&sys->cache_lock);
} }
out: out:
......
This diff is collapsed.
...@@ -28,45 +28,39 @@ static const vlc_fourcc_t va_subpicture_chromas[] = { ...@@ -28,45 +28,39 @@ static const vlc_fourcc_t va_subpicture_chromas[] = {
0 0
}; };
/* NOTE: call all functions with sys->cache_lock held */
/* Check if subtitle format is supported by VA API */ /* Check if subtitle format is supported by VA API */
int VASubtitleFourCC(vlc_va_conn_t *va, const unsigned int vafourcc, VAImageFormat *sub_fmt, int *flags); int VASubtitleFourCC(vlc_va_conn_t *va, const unsigned int vafourcc, VAImageFormat *sub_fmt, int *flags);
/* */ /* */
typedef struct vasubpicture_cache_t vasubpicture_cache_t; typedef struct vlc_va_spu_cache_t vlc_va_spu_cache_t;
typedef struct subpicture_cache_t subpicture_cache_t; typedef struct spu_cache_t spu_cache_t;
/* Get Cache id */ /* Get Cache id */
unsigned int cache_GetCacheID(const subpicture_cache_t *cache); unsigned int vlc_va_spu_cache_GetID(const spu_cache_t *cache);
/* Empty the array of cached subpictures */ /* Empty the array of cached subpictures */
void cache_SubpictureEmpty(vlc_object_t *obj, vlc_va_conn_t *va, vlc_array_t *restrict cache); vlc_va_spu_cache_t *vlc_va_spu_cache_New(void);
void vlc_va_spu_cache_Delete(vlc_va_conn_t *va, vlc_va_spu_cache_t *restrict spu);
/* Create new VASubpicture */
vasubpicture_cache_t *cache_SubpictureCreate(vlc_object_t *obj, vlc_va_conn_t *va, VAImageFormat *sub_fmt,
const subpicture_t *subpicture, const subpicture_region_t *region, const int flags);
/* Destory VASubpicture and cached subpicture */
void cache_SubpictureDestroy(vlc_object_t *obj, vlc_va_conn_t *conn, subpicture_cache_t *cache, const bool b_force);
/* Hold reference to subpicture cache object */ /* Hold and Release reference to subpicture cache object */
void cache_SubpictureHold(vlc_object_t *obj, vlc_array_t *cache_array, const int cache_id); void vlc_va_spu_cache_Hold(vlc_va_spu_cache_t *spu, const int cache_id);
/* Release reference to subpicture cache object */ void vlc_va_spu_cache_Release(vlc_va_conn_t *va, vlc_va_spu_cache_t *spu, const int cache_id);
void cache_SubpictureRelease(vlc_object_t *obj, vlc_va_conn_t *va, vlc_array_t *cache_array, const int cache_id);
/* Link VASubpicture to VASurface */ /* Link/Unlink VASubpicture to/from VASurface */
int SubpictureRegionsLink(vlc_object_t *obj, vlc_va_conn_t *va, vlc_array_t *cache_array, int vlc_va_spu_cache_Link(vlc_object_t *obj, vlc_va_conn_t *va, vlc_va_spu_cache_t *spu,
const picture_t *picture, const int flags); const picture_t *picture, const int flags);
/* Unlink VASubpicture from VASurface */ int vlc_va_spu_cache_Unlink(vlc_object_t *obj, vlc_va_conn_t *va, vlc_va_spu_cache_t *spu,
int SubpictureRegionsUnlink(vlc_object_t *obj, vlc_va_conn_t *va, vlc_array_t *cache_array,
const picture_t *picture); const picture_t *picture);
/* Render VLC subpictures as VASubpictures and put them into a subpicture cache */ /* Create VLC subpictures as VASubpictures and put them into a subpicture cache */
subpicture_cache_t *RenderDirectSubpicture(vlc_object_t *obj, vlc_va_conn_t *va, VAImageFormat *fmt, spu_cache_t *vlc_va_spu_cache_Prepare(vlc_object_t *obj, vlc_va_conn_t *va, VAImageFormat *fmt,
picture_t *picture, subpicture_t *subpicture, int flags); picture_t *picture, subpicture_t *subpicture, int flags);
/* Check if cached subpicture can be reused for the next Subpicture Render cycle */ /* Check if cached subpicture can be reused for the next Subpicture Render cycle */
int RenderCachedSubpictures(vlc_object_t *obj, vlc_va_conn_t *va, vlc_array_t *cache_array, int vlc_va_spu_cache_Get(vlc_object_t *obj, vlc_va_spu_cache_t *spu, const unsigned int cache_id,
const unsigned int cache_id, picture_t *picture, subpicture_t *subpicture); picture_t *picture, subpicture_t *subpicture);
void vlc_va_spu_cache_Put(vlc_va_spu_cache_t *spu, spu_cache_t *cache);
#endif #endif
#endif #endif
...@@ -92,8 +92,7 @@ struct vout_display_sys_t ...@@ -92,8 +92,7 @@ struct vout_display_sys_t
subpicture_t *prev_subpicture; subpicture_t *prev_subpicture;
} render; } render;
vlc_mutex_t cache_lock; vlc_va_spu_cache_t *spu;
vlc_array_t cache; /* array of subpicture_subpicture_cache_t */
xcb_cursor_t cursor; /* blank cursor */ xcb_cursor_t cursor; /* blank cursor */
xcb_window_t window; /* drawable X window */ xcb_window_t window; /* drawable X window */
...@@ -222,8 +221,12 @@ int OpenVaapiXCB(vlc_object_t *obj) ...@@ -222,8 +221,12 @@ int OpenVaapiXCB(vlc_object_t *obj)
vd->sys = sys; vd->sys = sys;
vlc_array_init(&sys->cache); sys->spu = vlc_va_spu_cache_New();
vlc_mutex_init(&sys->cache_lock); if (!sys->spu)
{
free(sys);
return VLC_ENOMEM;
}
sys->render.prev_subpicture = NULL; sys->render.prev_subpicture = NULL;
sys->render.i_cache = 0; sys->render.i_cache = 0;
...@@ -354,8 +357,8 @@ void CloseVaapiXCB(vlc_object_t *obj) ...@@ -354,8 +357,8 @@ void CloseVaapiXCB(vlc_object_t *obj)
sys->visible = false; sys->visible = false;
/* Cleanup cache */ /* Cleanup cache */
vlc_mutex_destroy(&sys->cache_lock); if (sys->spu)
cache_SubpictureEmpty(obj, va, &sys->cache); vlc_va_spu_cache_Delete(va, sys->spu);
/* */ /* */
if (va) if (va)
...@@ -424,47 +427,36 @@ static void Render(vout_display_t *vd, picture_t *picture, subpicture_t *subpict ...@@ -424,47 +427,36 @@ static void Render(vout_display_t *vd, picture_t *picture, subpicture_t *subpict
subpicture, sys->render.prev_subpicture, subpicture, sys->render.prev_subpicture,
sys->render.i_cache, picture->p_sys->i_id); sys->render.i_cache, picture->p_sys->i_id);
#endif #endif
vlc_mutex_lock(&sys->cache_lock); int ret = vlc_va_spu_cache_Get(VLC_OBJECT(vd), sys->spu, sys->render.i_cache,
int ret = RenderCachedSubpictures(VLC_OBJECT(vd), sys->va, &sys->cache, picture, subpicture);
sys->render.i_cache, picture, subpicture);
vlc_mutex_unlock(&sys->cache_lock);
if (ret == VLC_SUCCESS) if (ret == VLC_SUCCESS)
return; return;
} }
/* new subpicture */
vlc_mutex_lock(&sys->cache_lock);
/* Release exra reference */ /* Release exra reference */
if (sys->render.i_cache > 0) if (sys->render.i_cache > 0)
cache_SubpictureRelease(VLC_OBJECT(vd), sys->va, &sys->cache, sys->render.i_cache); vlc_va_spu_cache_Release(sys->va, sys->spu, sys->render.i_cache);
/* render new subpicture */ /* render new subpicture */
subpicture_cache_t *cache = RenderDirectSubpicture(VLC_OBJECT(vd), sys->va, &sys->sub_fmt, spu_cache_t *cache = vlc_va_spu_cache_Prepare(VLC_OBJECT(vd), sys->va, &sys->sub_fmt,
picture, subpicture, sys->sflags); picture, subpicture, sys->sflags);
if (cache == NULL) if (cache == NULL)
{
vlc_mutex_unlock(&sys->cache_lock);
return; return;
}
#ifdef VAAPI_DEBUG #ifdef VAAPI_DEBUG
msg_Dbg(vd, "new subpicture %p prev %p cache %d surface %d", msg_Dbg(vd, "new subpicture %p prev %p cache %d surface %d",
subpicture, sys->render.prev_subpicture, cache_GetCacheID(cache), surface->i_id); subpicture, sys->render.prev_subpicture, vlc_va_spu_cache_GetID(cache), surface->i_id);
#endif #endif
/* remember what was created, so it can be released in DisplayPicture() */ /* remember what was created, so it can be released in DisplayPicture() */
vlc_array_append(&sys->cache, (void *)cache); vlc_va_spu_cache_Put(sys->spu, cache);
sys->render.i_cache = cache_GetCacheID(cache); sys->render.i_cache = vlc_va_spu_cache_GetID(cache);
sys->render.prev_subpicture = subpicture; sys->render.prev_subpicture = subpicture;
sys->render.i_start = subpicture->i_start; sys->render.i_start = subpicture->i_start;
sys->render.i_stop = subpicture->i_stop; sys->render.i_stop = subpicture->i_stop;
/* Hold extra reference */ /* Hold extra reference */
cache_SubpictureHold(VLC_OBJECT(vd), &sys->cache, cache_GetCacheID(cache)); vlc_va_spu_cache_Hold(sys->spu, vlc_va_spu_cache_GetID(cache));
vlc_mutex_unlock(&sys->cache_lock);
} }
static void DisplayVASurface(vout_display_t *vd, picture_t *picture) static void DisplayVASurface(vout_display_t *vd, picture_t *picture)
...@@ -531,26 +523,22 @@ static void DisplayPicture(vout_display_t *vd, picture_t *picture, subpicture_t ...@@ -531,26 +523,22 @@ static void DisplayPicture(vout_display_t *vd, picture_t *picture, subpicture_t
if (subpicture) if (subpicture)
{ {
vlc_mutex_lock(&sys->cache_lock); ret = vlc_va_spu_cache_Link(VLC_OBJECT(vd), sys->va, sys->spu, picture, sys->sflags);
ret = SubpictureRegionsLink(VLC_OBJECT(vd), sys->va, &sys->cache, picture, sys->sflags);
if (ret == VLC_EGENERIC) if (ret == VLC_EGENERIC)
msg_Err(vd, "Failed linking subpicture to surface"); msg_Err(vd, "Failed linking subpicture to surface");
vlc_mutex_unlock(&sys->cache_lock);
} }
DisplayVASurface(vd, picture); DisplayVASurface(vd, picture);
if (subpicture) if (subpicture)
{ {
vlc_mutex_lock(&sys->cache_lock);
if (ret == VLC_SUCCESS) if (ret == VLC_SUCCESS)
{ {
if (SubpictureRegionsUnlink(VLC_OBJECT(vd), sys->va, &sys->cache, picture) == VLC_EGENERIC) if (vlc_va_spu_cache_Unlink(VLC_OBJECT(vd), sys->va, sys->spu, picture) == VLC_EGENERIC)
msg_Err(vd, "Could not find subpicture in cache"); msg_Err(vd, "Could not find subpicture in cache");
} }
if (picture->p_sys->i_cache > 0) if (picture->p_sys->i_cache > 0)
cache_SubpictureRelease(VLC_OBJECT(vd), sys->va, &sys->cache, picture->p_sys->i_cache); vlc_va_spu_cache_Release(sys->va, sys->spu, picture->p_sys->i_cache);
picture->p_sys->i_cache = 0; picture->p_sys->i_cache = 0;
vlc_mutex_unlock(&sys->cache_lock);
} }
out: out:
......
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