[vlc-commits] [Git][videolan/vlc][master] 11 commits: vlc_subpicture: add a function that wraps an existing picture into a region
Steve Lhomme (@robUx4)
gitlab at videolan.org
Tue Aug 1 06:40:56 UTC 2023
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
0940ecf2 by Steve Lhomme at 2023-08-01T06:21:15+00:00
vlc_subpicture: add a function that wraps an existing picture into a region
- - - - -
67ffd867 by Steve Lhomme at 2023-08-01T06:21:15+00:00
subpicture: don't output a region if the picture wrapping failed
- - - - -
4619369d by Steve Lhomme at 2023-08-01T06:21:15+00:00
subpicture: avoid copying the region picture
No need to create a picture just to release right after.
- - - - -
8f9b4773 by Steve Lhomme at 2023-08-01T06:21:15+00:00
vout_spuregion_helper: avoid creating a temporary picture
We don't need to create a picture just to release it right after.
- - - - -
9ac3837e by Steve Lhomme at 2023-08-01T06:21:15+00:00
codec/ttml: keep the source picture in the subregion
No need to allocate a new picture and copy pixels. We can keep a reference
of the (RGBA) picture and set it in the region. The picture is refcounted.
- - - - -
693cddd7 by Steve Lhomme at 2023-08-01T06:21:15+00:00
logo: avoid copying the logo
We can pass a reference counted pointer to our internal (YUVA) picture.
The content of the picture doesn't change once it's loaded.
- - - - -
74609617 by Steve Lhomme at 2023-08-01T06:21:15+00:00
mosaic: avoid copying the pictures
We can pass a reference counted pointer to our internal (CPU) picture.
- - - - -
ab6b9ba6 by Steve Lhomme at 2023-08-01T06:21:15+00:00
rss: avoid copying the pictures
We can pass a reference counted pointer to our internal (RGBA) picture.
It also works with font scaling which scales the picture.
- - - - -
19657e3d by Steve Lhomme at 2023-08-01T06:21:15+00:00
dynamicoverlay: avoid copying the pictures
We can pass a reference counted pointer to our internal picture.
The internal pictures are recreated (release/new) when data change. So
the content of the region won't change unexpectedly.
- - - - -
1969266f by Steve Lhomme at 2023-08-01T06:21:15+00:00
logo: ensure the subpicture format is close to the picture
- - - - -
dcf2bdce by Steve Lhomme at 2023-08-01T06:21:15+00:00
rss: ensure the subpicture format is close to the picture
- - - - -
9 changed files:
- include/vlc_subpicture.h
- modules/codec/ttml/imageupdater.h
- modules/spu/dynamicoverlay/dynamicoverlay.c
- modules/spu/logo.c
- modules/spu/mosaic.c
- modules/spu/rss.c
- src/libvlccore.sym
- src/misc/subpicture.c
- src/video_output/vout_spuregion_helper.h
Changes:
=====================================
include/vlc_subpicture.h
=====================================
@@ -104,6 +104,19 @@ struct vlc_spu_highlight_t
*/
VLC_API subpicture_region_t * subpicture_region_New( const video_format_t *p_fmt );
+/**
+ * Create a subpicture region containing the picture.
+ *
+ * A reference will be added to the picture on success.
+ *
+ * You must use subpicture_region_Delete to destroy it.
+ *
+ * The chroma of the format must match the one of the picture.
+ * The dimensions of the format should not exceed the ones of the picture. This
+ * is not checked explicitly in the function.
+ */
+VLC_API subpicture_region_t * subpicture_region_ForPicture( const video_format_t *p_fmt, picture_t *pic );
+
/**
* This function will destroy a subpicture region allocated by
* subpicture_region_New.
=====================================
modules/codec/ttml/imageupdater.h
=====================================
@@ -101,16 +101,9 @@ static void TTML_ImageSpuUpdate(subpicture_t *p_spu,
for(ttml_image_updater_region_t *p_updtregion = p_sys->p_regions;
p_updtregion; p_updtregion = p_updtregion->p_next)
{
- subpicture_region_t *r = subpicture_region_New(&p_updtregion->p_pic->format);
- if (!r)
+ subpicture_region_t *r = subpicture_region_ForPicture(&p_updtregion->p_pic->format, p_updtregion->p_pic);
+ if (unlikely(r == NULL))
return;
- picture_Release(r->p_picture);
- r->p_picture = picture_Clone(p_updtregion->p_pic);
- if(!r->p_picture)
- {
- subpicture_region_Delete(r);
- return;
- }
r->i_align = SUBPICTURE_ALIGN_LEFT|SUBPICTURE_ALIGN_TOP;
=====================================
modules/spu/dynamicoverlay/dynamicoverlay.c
=====================================
@@ -351,9 +351,15 @@ static subpicture_t *Filter( filter_t *p_filter, vlc_tick_t date )
{
subpicture_region_t *p_region;
- *pp_region = p_region = subpicture_region_New( &p_overlay->format );
- if( !p_region )
+ if( p_overlay->format.i_chroma == VLC_CODEC_TEXT )
+ p_region = subpicture_region_New( &p_overlay->format );
+ else
+ p_region = subpicture_region_ForPicture( &p_overlay->format, p_overlay->data.p_pic );
+ if( unlikely(p_region == NULL) )
+ {
+ *pp_region = NULL;
break;
+ }
msg_Dbg( p_filter, "Displaying overlay: %4.4s, %d, %d, %d",
(char*)&p_overlay->format.i_chroma, p_overlay->i_x, p_overlay->i_y,
@@ -364,11 +370,6 @@ static subpicture_t *Filter( filter_t *p_filter, vlc_tick_t date )
p_region->p_text = text_segment_New( p_overlay->data.p_text );
p_region->p_text->style = text_style_Duplicate( p_overlay->p_fontstyle );
}
- else
- {
- /* FIXME the copy is probably not needed anymore */
- picture_Copy( p_region->p_picture, p_overlay->data.p_pic );
- }
p_region->i_x = p_overlay->i_x;
p_region->i_y = p_overlay->i_y;
p_region->i_align = SUBPICTURE_ALIGN_LEFT | SUBPICTURE_ALIGN_TOP;
=====================================
modules/spu/logo.c
=====================================
@@ -362,16 +362,13 @@ static subpicture_t *FilterSub( filter_t *p_filter, vlc_tick_t date )
goto exit;
/* Create new SPU region */
- video_format_Init( &fmt, VLC_CODEC_YUVA );
+ video_format_Copy(&fmt, &p_pic->format);
fmt.i_sar_num = fmt.i_sar_den = 1;
fmt.i_width = fmt.i_visible_width = p_pic->p[Y_PLANE].i_visible_pitch;
fmt.i_height = fmt.i_visible_height = p_pic->p[Y_PLANE].i_visible_lines;
fmt.i_x_offset = fmt.i_y_offset = 0;
- fmt.transfer = p_pic->format.transfer;
- fmt.primaries = p_pic->format.primaries;
- fmt.space = p_pic->format.space;
- fmt.color_range = p_pic->format.color_range;
- p_region = subpicture_region_New( &fmt );
+ p_region = subpicture_region_ForPicture( &fmt, p_pic );
+ video_format_Clean(&fmt);
if( !p_region )
{
msg_Err( p_filter, "cannot allocate SPU region" );
@@ -380,9 +377,6 @@ static subpicture_t *FilterSub( filter_t *p_filter, vlc_tick_t date )
goto exit;
}
- /* */
- picture_Copy( p_region->p_picture, p_pic );
-
/* where to locate the logo: */
if( p_sys->i_pos < 0 )
{ /* set to an absolute xy */
=====================================
modules/spu/mosaic.c
=====================================
@@ -644,10 +644,7 @@ static subpicture_t *Filter( filter_t *p_filter, vlc_tick_t date )
fmt_out.i_visible_height = fmt_out.i_height;
}
- p_region = subpicture_region_New( &fmt_out );
- /* FIXME the copy is probably not needed anymore */
- if( p_region )
- picture_Copy( p_region->p_picture, p_converted );
+ p_region = subpicture_region_ForPicture( &fmt_out, p_converted );
if( !p_sys->b_keep )
picture_Release( p_converted );
=====================================
modules/spu/rss.c
=====================================
@@ -504,7 +504,7 @@ static subpicture_t *Filter( filter_t *p_filter, vlc_tick_t date )
picture_t *p_pic = p_feed->p_pic;
video_format_t fmt_out;
- video_format_Init( &fmt_out, VLC_CODEC_YUVA );
+ video_format_Copy( &fmt_out, &p_pic->format );
fmt_out.i_sar_num = fmt_out.i_sar_den = 1;
fmt_out.i_width =
@@ -512,7 +512,7 @@ static subpicture_t *Filter( filter_t *p_filter, vlc_tick_t date )
fmt_out.i_height =
fmt_out.i_visible_height = p_pic->p[Y_PLANE].i_visible_lines;
- p_region = subpicture_region_New( &fmt_out );
+ p_region = subpicture_region_ForPicture( &fmt_out, p_pic );
if( !p_region )
{
msg_Err( p_filter, "cannot allocate SPU region" );
@@ -521,13 +521,12 @@ static subpicture_t *Filter( filter_t *p_filter, vlc_tick_t date )
{
p_region->i_x = p_spu->p_region->i_x;
p_region->i_y = p_spu->p_region->i_y;
- /* FIXME the copy is probably not needed anymore */
- picture_Copy( p_region->p_picture, p_pic );
p_spu->p_region->p_next = p_region;
/* Offset text to display right next to the image */
p_spu->p_region->i_x += fmt_out.i_visible_width;
}
+ video_format_Clean(&fmt_out);
}
vlc_mutex_unlock( &p_sys->lock );
=====================================
src/libvlccore.sym
=====================================
@@ -412,6 +412,7 @@ subpicture_region_ChainDelete
subpicture_region_Copy
subpicture_region_Delete
subpicture_region_New
+subpicture_region_ForPicture
text_segment_New
text_segment_NewInheritStyle
text_segment_Delete
=====================================
src/misc/subpicture.c
=====================================
@@ -133,16 +133,15 @@ subpicture_t *subpicture_NewFromPicture( vlc_object_t *p_obj,
fmt_out.i_sar_num =
fmt_out.i_sar_den = 0;
- p_subpic->p_region = subpicture_region_New( &fmt_out );
- if( p_subpic->p_region )
- {
- picture_Release( p_subpic->p_region->p_picture );
- p_subpic->p_region->p_picture = p_pip;
- }
- else
+ p_subpic->p_region = subpicture_region_ForPicture( &fmt_out, p_pip );
+ picture_Release( p_pip );
+
+ if (p_subpic->p_region == NULL)
{
- picture_Release( p_pip );
+ subpicture_Delete(p_subpic);
+ p_subpic = NULL;
}
+
return p_subpic;
}
@@ -258,6 +257,20 @@ subpicture_region_t *subpicture_region_New( const video_format_t *p_fmt )
return p_region;
}
+subpicture_region_t *subpicture_region_ForPicture( const video_format_t *p_fmt, picture_t *pic )
+{
+ if ( p_fmt->i_chroma != pic->format.i_chroma )
+ return NULL;
+
+ subpicture_region_t *p_region = subpicture_region_NewInternal( p_fmt );
+ if( !p_region )
+ return NULL;
+
+ p_region->p_picture = picture_Hold(pic);
+
+ return p_region;
+}
+
void subpicture_region_Delete( subpicture_region_t *p_region )
{
if( !p_region )
=====================================
src/video_output/vout_spuregion_helper.h
=====================================
@@ -84,15 +84,8 @@ spuregion_CreateFromPicture( vlc_object_t *p_this, video_format_t *p_fmt,
if(!p_pic)
return NULL;
- subpicture_region_t *region = subpicture_region_New(p_fmt);
- if (!region)
- {
- picture_Release( p_pic );
- return NULL;
- }
-
- picture_Release( region->p_picture );
- region->p_picture = p_pic;
+ subpicture_region_t *region = subpicture_region_ForPicture(p_fmt, p_pic);
+ picture_Release( p_pic );
return region;
}
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/fe85873b6bade3f1be39d73bb83fce8a0e64fb8e...dcf2bdce4598af97b01323b65ac412d63157a450
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/fe85873b6bade3f1be39d73bb83fce8a0e64fb8e...dcf2bdce4598af97b01323b65ac412d63157a450
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
More information about the vlc-commits
mailing list