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
subpicture_t *prev_subpicture;
} render;
vlc_mutex_t cache_lock;
vlc_array_t cache; /* array of subpicture_subpicture_cache_t */
vlc_va_spu_cache_t *spu;
xcb_cursor_t cursor; /* blank cursor */
xcb_window_t window; /* drawable X window */
......@@ -455,8 +454,12 @@ int OpenVaapiGLX(vlc_object_t *obj)
vd->sys = sys;
vlc_array_init(&sys->cache);
vlc_mutex_init(&sys->cache_lock);
sys->spu = vlc_va_spu_cache_New();
if (!sys->spu)
{
free(sys);
return VLC_ENOMEM;
}
sys->render.prev_subpicture = NULL;
sys->render.i_cache = 0;
......@@ -620,8 +623,8 @@ void CloseVaapiGLX(vlc_object_t *obj)
}
/* Cleanup cache */
vlc_mutex_destroy(&sys->cache_lock);
cache_SubpictureEmpty(obj, va, &sys->cache);
if (sys->spu)
vlc_va_spu_cache_Delete(va, sys->spu);
/* Cleanup VAAPI resources and connection */
if (va)
......@@ -692,47 +695,36 @@ static void Render(vout_display_t *vd, picture_t *picture, subpicture_t *subpict
subpicture, sys->render.prev_subpicture,
sys->render.i_cache, picture->p_sys->i_id);
#endif
vlc_mutex_lock(&sys->cache_lock);
int ret = RenderCachedSubpictures(VLC_OBJECT(vd), sys->va, &sys->cache,
sys->render.i_cache, picture, subpicture);
vlc_mutex_unlock(&sys->cache_lock);
int ret = vlc_va_spu_cache_Get(VLC_OBJECT(vd), sys->spu, sys->render.i_cache,
picture, subpicture);
if (ret == VLC_SUCCESS)
return;
}
/* new subpicture */
vlc_mutex_lock(&sys->cache_lock);
/* Release exra reference */
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 */
subpicture_cache_t *cache = RenderDirectSubpicture(VLC_OBJECT(vd), sys->va, &sys->sub_fmt,
picture, subpicture, sys->sflags);
spu_cache_t *cache = vlc_va_spu_cache_Prepare(VLC_OBJECT(vd), sys->va, &sys->sub_fmt,
picture, subpicture, sys->sflags);
if (cache == NULL)
{
vlc_mutex_unlock(&sys->cache_lock);
return;
}
#ifdef VAAPI_DEBUG
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
/* 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.i_start = subpicture->i_start;
sys->render.i_stop = subpicture->i_stop;
/* Hold extra reference */
cache_SubpictureHold(VLC_OBJECT(vd), &sys->cache, cache_GetCacheID(cache));
vlc_mutex_unlock(&sys->cache_lock);
vlc_va_spu_cache_Hold(sys->spu, vlc_va_spu_cache_GetID(cache));
}
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
if (subpicture)
{
vlc_mutex_lock(&sys->cache_lock);
ret = SubpictureRegionsLink(VLC_OBJECT(vd), sys->va, &sys->cache, picture, sys->sflags);
ret = vlc_va_spu_cache_Link(VLC_OBJECT(vd), sys->va, sys->spu, picture, sys->sflags);
if (ret == VLC_EGENERIC)
msg_Err(vd, "Failed linking subpicture to surface");
vlc_mutex_unlock(&sys->cache_lock);
}
if (!vlc_gl_Lock(&sys->gl))
......@@ -840,16 +830,14 @@ static void DisplayPicture(vout_display_t *vd, picture_t *picture, subpicture_t
if (subpicture)
{
vlc_mutex_lock(&sys->cache_lock);
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");
}
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;
vlc_mutex_unlock(&sys->cache_lock);
}
out:
......
This diff is collapsed.
......@@ -28,45 +28,39 @@ static const vlc_fourcc_t va_subpicture_chromas[] = {
0
};
/* NOTE: call all functions with sys->cache_lock held */
/* 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);
/* */
typedef struct vasubpicture_cache_t vasubpicture_cache_t;
typedef struct subpicture_cache_t subpicture_cache_t;
typedef struct vlc_va_spu_cache_t vlc_va_spu_cache_t;
typedef struct spu_cache_t spu_cache_t;
/* 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 */
void cache_SubpictureEmpty(vlc_object_t *obj, vlc_va_conn_t *va, vlc_array_t *restrict cache);
/* 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);
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);
/* Hold reference to subpicture cache object */
void cache_SubpictureHold(vlc_object_t *obj, vlc_array_t *cache_array, const int cache_id);
/* Release reference to subpicture cache object */
void cache_SubpictureRelease(vlc_object_t *obj, vlc_va_conn_t *va, vlc_array_t *cache_array, const int cache_id);
/* Hold and Release reference to subpicture cache object */
void vlc_va_spu_cache_Hold(vlc_va_spu_cache_t *spu, const int cache_id);
void vlc_va_spu_cache_Release(vlc_va_conn_t *va, vlc_va_spu_cache_t *spu, const int cache_id);
/* Link VASubpicture to VASurface */
int SubpictureRegionsLink(vlc_object_t *obj, vlc_va_conn_t *va, vlc_array_t *cache_array,
/* Link/Unlink VASubpicture to/from VASurface */
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);
/* Unlink VASubpicture from VASurface */
int SubpictureRegionsUnlink(vlc_object_t *obj, vlc_va_conn_t *va, vlc_array_t *cache_array,
int vlc_va_spu_cache_Unlink(vlc_object_t *obj, vlc_va_conn_t *va, vlc_va_spu_cache_t *spu,
const picture_t *picture);
/* Render 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,
picture_t *picture, subpicture_t *subpicture, int flags);
/* Create VLC subpictures as VASubpictures and put them into a subpicture cache */
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);
/* 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,
const unsigned int cache_id, picture_t *picture, subpicture_t *subpicture);
int vlc_va_spu_cache_Get(vlc_object_t *obj, vlc_va_spu_cache_t *spu, const unsigned int cache_id,
picture_t *picture, subpicture_t *subpicture);
void vlc_va_spu_cache_Put(vlc_va_spu_cache_t *spu, spu_cache_t *cache);
#endif
#endif
......@@ -92,8 +92,7 @@ struct vout_display_sys_t
subpicture_t *prev_subpicture;
} render;
vlc_mutex_t cache_lock;
vlc_array_t cache; /* array of subpicture_subpicture_cache_t */
vlc_va_spu_cache_t *spu;
xcb_cursor_t cursor; /* blank cursor */
xcb_window_t window; /* drawable X window */
......@@ -222,8 +221,12 @@ int OpenVaapiXCB(vlc_object_t *obj)
vd->sys = sys;
vlc_array_init(&sys->cache);
vlc_mutex_init(&sys->cache_lock);
sys->spu = vlc_va_spu_cache_New();
if (!sys->spu)
{
free(sys);
return VLC_ENOMEM;
}
sys->render.prev_subpicture = NULL;
sys->render.i_cache = 0;
......@@ -354,8 +357,8 @@ void CloseVaapiXCB(vlc_object_t *obj)
sys->visible = false;
/* Cleanup cache */
vlc_mutex_destroy(&sys->cache_lock);
cache_SubpictureEmpty(obj, va, &sys->cache);
if (sys->spu)
vlc_va_spu_cache_Delete(va, sys->spu);
/* */
if (va)
......@@ -424,47 +427,36 @@ static void Render(vout_display_t *vd, picture_t *picture, subpicture_t *subpict
subpicture, sys->render.prev_subpicture,
sys->render.i_cache, picture->p_sys->i_id);
#endif
vlc_mutex_lock(&sys->cache_lock);
int ret = RenderCachedSubpictures(VLC_OBJECT(vd), sys->va, &sys->cache,
sys->render.i_cache, picture, subpicture);
vlc_mutex_unlock(&sys->cache_lock);
int ret = vlc_va_spu_cache_Get(VLC_OBJECT(vd), sys->spu, sys->render.i_cache,
picture, subpicture);
if (ret == VLC_SUCCESS)
return;
}
/* new subpicture */
vlc_mutex_lock(&sys->cache_lock);
/* Release exra reference */
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 */
subpicture_cache_t *cache = RenderDirectSubpicture(VLC_OBJECT(vd), sys->va, &sys->sub_fmt,
picture, subpicture, sys->sflags);
spu_cache_t *cache = vlc_va_spu_cache_Prepare(VLC_OBJECT(vd), sys->va, &sys->sub_fmt,
picture, subpicture, sys->sflags);
if (cache == NULL)
{
vlc_mutex_unlock(&sys->cache_lock);
return;
}
#ifdef VAAPI_DEBUG
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
/* 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.i_start = subpicture->i_start;
sys->render.i_stop = subpicture->i_stop;
/* Hold extra reference */
cache_SubpictureHold(VLC_OBJECT(vd), &sys->cache, cache_GetCacheID(cache));
vlc_mutex_unlock(&sys->cache_lock);
vlc_va_spu_cache_Hold(sys->spu, vlc_va_spu_cache_GetID(cache));
}
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
if (subpicture)
{
vlc_mutex_lock(&sys->cache_lock);
ret = SubpictureRegionsLink(VLC_OBJECT(vd), sys->va, &sys->cache, picture, sys->sflags);
ret = vlc_va_spu_cache_Link(VLC_OBJECT(vd), sys->va, sys->spu, picture, sys->sflags);
if (ret == VLC_EGENERIC)
msg_Err(vd, "Failed linking subpicture to surface");
vlc_mutex_unlock(&sys->cache_lock);
}
DisplayVASurface(vd, picture);
if (subpicture)
{
vlc_mutex_lock(&sys->cache_lock);
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");
}
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;
vlc_mutex_unlock(&sys->cache_lock);
}
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