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

codec/avcodec/vaapi*: Share SubpictureDestroy() between vaapi.c and vaapi_x11.c.

Share SubpictureDestroy() between vaapi.c and vaapi_x11.c.
parent 1c5acb4f
...@@ -507,6 +507,45 @@ static void Delete( vlc_va_t *p_external ) ...@@ -507,6 +507,45 @@ static void Delete( vlc_va_t *p_external )
free( p_va ); free( p_va );
} }
/* */
void SubpictureDestroy( vlc_va_conn_t *p_connection, VASurfaceID *i_surface_id,
vlc_va_subpicture_t *subpicture, const int i_sub )
{
VAStatus status;
for( int i = 0; i < i_sub; i++ )
{
if( ((*i_surface_id) != VA_INVALID_SURFACE) &&
(subpicture[i].i_id != VA_INVALID_ID) )
{
status = vaDeassociateSubpicture( p_connection->p_display, subpicture[i].i_id,
i_surface_id, 1) ;
assert( status == VA_STATUS_SUCCESS );
}
if( subpicture[i].i_id != VA_INVALID_ID )
{
status = vaDestroySubpicture( p_connection->p_display,
subpicture[i].i_id );
assert( status == VA_STATUS_SUCCESS );
}
if( subpicture[i].image.image_id != VA_INVALID_ID )
{
status = vaDestroyImage( p_connection->p_display,
subpicture[i].image.image_id );
assert( status == VA_STATUS_SUCCESS );
}
subpicture[i].image.image_id = VA_INVALID_ID;
subpicture[i].image.buf = VA_INVALID_ID;
subpicture[i].i_id = VA_INVALID_ID;
}
/* */
free( subpicture );
}
/* */ /* */
vlc_va_t *vlc_va_NewVaapi( vlc_object_t *obj, int i_codec_id ) vlc_va_t *vlc_va_NewVaapi( vlc_object_t *obj, int i_codec_id )
{ {
......
...@@ -50,4 +50,8 @@ struct picture_sys_t ...@@ -50,4 +50,8 @@ struct picture_sys_t
vlc_va_subpicture_t *subpicture; vlc_va_subpicture_t *subpicture;
unsigned int i_sub; /* number of vlc_va_subpicures_t */ unsigned int i_sub; /* number of vlc_va_subpicures_t */
}; };
void SubpictureDestroy( vlc_va_conn_t *p_connection, VASurfaceID *i_surface_id,
vlc_va_subpicture_t *subpicture, const int i_sub );
#endif #endif
...@@ -67,12 +67,11 @@ struct vout_display_sys_t ...@@ -67,12 +67,11 @@ struct vout_display_sys_t
vout_window_t *embed; vout_window_t *embed;
picture_pool_t *pool; /* picture pool */ picture_pool_t *pool; /* picture pool */
VAImageFormat sub_fmt; /* Subpicture format VA_FOURCC_RGBA */
VAImageFormat img_fmt; VAImageFormat img_fmt;
VAImageFormat sub_fmt; /* Subpicture format VA_FOURCC_RGBA */
int sflags; /* Subtitle format flags */
unsigned int i_display_order; unsigned int i_display_order;
bool b_alpha; /* whether subpictures support alpha */
bool b_chroma; /* whether subpictures support chroma keying */
bool visible; /* whether to draw */ bool visible; /* whether to draw */
}; };
...@@ -106,8 +105,7 @@ static int VASubtitleFourCC(vout_display_t *vd) ...@@ -106,8 +105,7 @@ static int VASubtitleFourCC(vout_display_t *vd)
VAImageFormat format = p_fmt[i]; VAImageFormat format = p_fmt[i];
if (format.fourcc == VA_FOURCC_RGBA) if (format.fourcc == VA_FOURCC_RGBA)
{ {
sys->b_alpha = (flags[i] & VA_SUBPICTURE_GLOBAL_ALPHA); sys->sflags = flags[i];
sys->b_chroma = (flags[i] & VA_SUBPICTURE_CHROMA_KEYING);
memcpy((void*)&sys->sub_fmt, (void*)&format, sizeof(VAImageFormat)); memcpy((void*)&sys->sub_fmt, (void*)&format, sizeof(VAImageFormat));
free(p_fmt); free(p_fmt);
free(flags); free(flags);
...@@ -202,10 +200,7 @@ int OpenVaapiX11 (vlc_object_t *obj) ...@@ -202,10 +200,7 @@ int OpenVaapiX11 (vlc_object_t *obj)
sys->conn = NULL; sys->conn = NULL;
sys->pool = NULL; sys->pool = NULL;
sys->b_alpha = false;
sys->b_chroma = false;
sys->visible = false; sys->visible = false;
sys->i_display_order = 0;
sys->embed = MakeWindow(vd); sys->embed = MakeWindow(vd);
if (unlikely(sys->embed == NULL)) if (unlikely(sys->embed == NULL))
...@@ -362,7 +357,7 @@ static int Control (vout_display_t *vd, int query, va_list ap) ...@@ -362,7 +357,7 @@ static int Control (vout_display_t *vd, int query, va_list ap)
} }
static VASubpictureID SubpictureCreate(vout_display_t *vd, const subpicture_t *subpicture, static VASubpictureID SubpictureCreate(vout_display_t *vd, const subpicture_t *subpicture,
const subpicture_region_t *region, vlc_va_subpicture_t *vasubpicture) const subpicture_region_t *region, vlc_va_subpicture_t *vasubpicture, const int flags)
{ {
vout_display_sys_t *sys = vd->sys; vout_display_sys_t *sys = vd->sys;
...@@ -373,9 +368,12 @@ static VASubpictureID SubpictureCreate(vout_display_t *vd, const subpicture_t *s ...@@ -373,9 +368,12 @@ static VASubpictureID SubpictureCreate(vout_display_t *vd, const subpicture_t *s
if (status != VA_STATUS_SUCCESS) if (status != VA_STATUS_SUCCESS)
return VA_INVALID_ID; return VA_INVALID_ID;
if (sys->b_alpha) bool b_alpha = (flags & VA_SUBPICTURE_GLOBAL_ALPHA);
bool b_chroma = (flags & VA_SUBPICTURE_CHROMA_KEYING);
if (b_alpha)
{ {
assert(!sys->b_chroma); assert(!b_chroma);
float global_alpha = (float)(subpicture->i_alpha * region->i_alpha / 255) / 255; float global_alpha = (float)(subpicture->i_alpha * region->i_alpha / 255) / 255;
status = vaSetSubpictureGlobalAlpha(sys->conn->p_display, subpic, global_alpha); status = vaSetSubpictureGlobalAlpha(sys->conn->p_display, subpic, global_alpha);
...@@ -383,9 +381,9 @@ static VASubpictureID SubpictureCreate(vout_display_t *vd, const subpicture_t *s ...@@ -383,9 +381,9 @@ static VASubpictureID SubpictureCreate(vout_display_t *vd, const subpicture_t *s
msg_Err(vd, "Failed applying alpha value to subpicture"); msg_Err(vd, "Failed applying alpha value to subpicture");
} }
if (sys->b_chroma) if (b_chroma)
{ {
assert(!sys->b_alpha); assert(!b_alpha);
/* chromakey values */ /* chromakey values */
const unsigned int min = 0x0; /* ? */ const unsigned int min = 0x0; /* ? */
...@@ -400,9 +398,6 @@ static VASubpictureID SubpictureCreate(vout_display_t *vd, const subpicture_t *s ...@@ -400,9 +398,6 @@ static VASubpictureID SubpictureCreate(vout_display_t *vd, const subpicture_t *s
msg_Err(vd, "Failed applying chroma valuesto subpicture"); msg_Err(vd, "Failed applying chroma valuesto subpicture");
} }
int flags = sys->b_alpha ? VA_SUBPICTURE_GLOBAL_ALPHA :
(sys->b_chroma ? VA_SUBPICTURE_CHROMA_KEYING : 0);
/* subpicture positioning */ /* subpicture positioning */
vout_display_place_t video; vout_display_place_t video;
vout_display_PlacePicture (&video, &vd->source, vd->cfg, false); vout_display_PlacePicture (&video, &vd->source, vd->cfg, false);
...@@ -437,49 +432,6 @@ static VASubpictureID SubpictureCreate(vout_display_t *vd, const subpicture_t *s ...@@ -437,49 +432,6 @@ static VASubpictureID SubpictureCreate(vout_display_t *vd, const subpicture_t *s
return subpic; return subpic;
} }
static void SubpictureDestroy(vout_display_t *vd, vlc_va_subpicture_t *subpicture, const int i_sub)
{
vout_display_sys_t *sys = vd->sys;
VAStatus status;
for (int i = 0; i < i_sub; i++)
{
if ((subpicture[i].i_surface != VA_INVALID_SURFACE) &&
(subpicture[i].i_id != VA_INVALID_ID))
{
status = vaDeassociateSubpicture(sys->conn->p_display,
subpicture[i].i_id,
&subpicture[i].i_surface, 1);
if (status != VA_STATUS_SUCCESS)
msg_Err(vd, "Failed unlinking subpicture from surface (%d)", status);
}
if (subpicture[i].i_id != VA_INVALID_ID)
{
status = vaDestroySubpicture(sys->conn->p_display,
subpicture[i].i_id);
if (status != VA_STATUS_SUCCESS)
msg_Err(vd, "Failed destroying subpicture");
}
if (subpicture[i].image.image_id != VA_INVALID_ID)
{
status = vaDestroyImage(sys->conn->p_display,
subpicture[i].image.image_id);
if (status != VA_STATUS_SUCCESS)
msg_Err(vd, "Failed destroying subpicture image");
}
subpicture[i].i_surface = VA_INVALID_SURFACE;
subpicture[i].image.image_id = VA_INVALID_ID;
subpicture[i].image.buf = VA_INVALID_ID;
subpicture[i].i_id = VA_INVALID_ID;
}
/* */
free(subpicture);
}
static int CopyPictureToVAImage(vout_display_t *vd, picture_t *pic, static int CopyPictureToVAImage(vout_display_t *vd, picture_t *pic,
VAImage *image, VAImageFormat *fmt) VAImage *image, VAImageFormat *fmt)
{ {
...@@ -597,7 +549,7 @@ static int RenderDirectSubpicture(vout_display_t *vd, picture_t *picture, subpic ...@@ -597,7 +549,7 @@ static int RenderDirectSubpicture(vout_display_t *vd, picture_t *picture, subpic
/* Create Subpicture */ /* Create Subpicture */
vasubpic[i_sub].i_id = SubpictureCreate(vd, subpicture, region, vasubpic[i_sub].i_id = SubpictureCreate(vd, subpicture, region,
&vasubpic[i_sub]); &vasubpic[i_sub], sys->sflags);
if (vasubpic[i_sub].i_id == VA_INVALID_ID) if (vasubpic[i_sub].i_id == VA_INVALID_ID)
{ {
vaDestroyImage(sys->conn->p_display, vasubpic[i_sub].image.image_id); vaDestroyImage(sys->conn->p_display, vasubpic[i_sub].image.image_id);
...@@ -662,6 +614,8 @@ static void PictureRelease(picture_t *picture) ...@@ -662,6 +614,8 @@ static void PictureRelease(picture_t *picture)
static void Render(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture) static void Render(vout_display_t *vd, picture_t *picture, subpicture_t *subpicture)
{ {
vout_display_sys_t *sys = vd->sys;
if (!subpicture) if (!subpicture)
return; return;
...@@ -672,7 +626,8 @@ static void Render(vout_display_t *vd, picture_t *picture, subpicture_t *subpict ...@@ -672,7 +626,8 @@ static void Render(vout_display_t *vd, picture_t *picture, subpicture_t *subpict
picture->p_sys->subpicture && picture->p_sys->subpicture &&
(picture->format.i_chroma == VLC_CODEC_VAAPI_SURFACE)) (picture->format.i_chroma == VLC_CODEC_VAAPI_SURFACE))
{ {
SubpictureDestroy(vd, picture->p_sys->subpicture, picture->p_sys->i_sub); SubpictureDestroy(sys->conn, &picture->p_sys->subpicture->i_surface,
picture->p_sys->subpicture, picture->p_sys->i_sub);
picture->p_sys->subpicture = NULL; picture->p_sys->subpicture = NULL;
picture->p_sys->i_sub = 0; picture->p_sys->i_sub = 0;
} }
...@@ -747,7 +702,8 @@ static void DisplayPicture(vout_display_t *vd, picture_t *pic, subpicture_t *sub ...@@ -747,7 +702,8 @@ static void DisplayPicture(vout_display_t *vd, picture_t *pic, subpicture_t *sub
assert(pic->format.i_chroma == VLC_CODEC_VAAPI_SURFACE); assert(pic->format.i_chroma == VLC_CODEC_VAAPI_SURFACE);
msg_Err(vd, "Discarding picture without surface information: %p", pic); msg_Err(vd, "Discarding picture without surface information: %p", pic);
if (pic->p_sys->subpicture) if (pic->p_sys->subpicture)
SubpictureDestroy(vd, pic->p_sys->subpicture, pic->p_sys->i_sub); SubpictureDestroy(sys->conn, &pic->p_sys->subpicture->i_surface,
pic->p_sys->subpicture, pic->p_sys->i_sub);
if (subpicture) if (subpicture)
subpicture_Delete(subpicture); subpicture_Delete(subpicture);
pic->p_sys->subpicture = NULL; pic->p_sys->subpicture = NULL;
...@@ -776,7 +732,8 @@ static void DisplayPicture(vout_display_t *vd, picture_t *pic, subpicture_t *sub ...@@ -776,7 +732,8 @@ static void DisplayPicture(vout_display_t *vd, picture_t *pic, subpicture_t *sub
cleanup: cleanup:
if (pic->p_sys->subpicture) if (pic->p_sys->subpicture)
SubpictureDestroy(vd, pic->p_sys->subpicture, pic->p_sys->i_sub); SubpictureDestroy(sys->conn, &pic->p_sys->subpicture->i_surface,
pic->p_sys->subpicture, pic->p_sys->i_sub);
if (subpicture) if (subpicture)
subpicture_Delete(subpicture); subpicture_Delete(subpicture);
......
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