Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
e29303ed by Steve Lhomme at 2023-10-25T05:43:47+00:00
vout_subpictures: use subpicture_region_ForPicture()
No need to share internal code.
The region picture should always have the matching region format. They
are always read together.
- - - - -
adcfadf2 by Steve Lhomme at 2023-10-25T05:43:47+00:00
subpictures: move video_format_t init out of subpicture_region_NewInternal
- - - - -
3c281ed0 by Steve Lhomme at 2023-10-25T05:43:47+00:00
subpictures: add a region constructor for Text sources
The code should differentiate more from bitmaps. The VLC_CODEC_TEXT is
not really a "chroma".
- - - - -
8421939a by Steve Lhomme at 2023-10-25T05:43:47+00:00
subpictures: use subpicture_region_NewText to create VLC_CODEC_TEXT regions
- - - - -
775285ab by Steve Lhomme at 2023-10-25T05:43:47+00:00
subpictures: exclusively use subpicture_region_NewText() for text regions
- - - - -
ddfeaeaa by Steve Lhomme at 2023-10-25T05:43:47+00:00
subpictures: don't pass a video format for Text region creation
Most of the time we don't need one, and it can always be set after the
region creation.
- - - - -
18 changed files:
- include/vlc_subpicture.h
- modules/codec/arib/substext.h
- modules/codec/dvbsub.c
- modules/codec/kate.c
- modules/codec/substext.h
- modules/codec/subsusf.c
- modules/codec/telx.c
- modules/codec/zvbi.c
- modules/spu/dynamicoverlay/dynamicoverlay.c
- modules/spu/marq.c
- modules/spu/rss.c
- src/libvlccore.sym
- src/misc/subpicture.c
- src/misc/subpicture.h
- src/video_output/video_epg.c
- src/video_output/video_text.c
- src/video_output/vout_subpictures.c
- test/src/input/decoder/input_decoder_scenarios.c
Changes:
=====================================
include/vlc_subpicture.h
=====================================
@@ -101,9 +101,18 @@ struct vlc_spu_highlight_t
* This function will create a new subpicture region.
*
* You must use subpicture_region_Delete to destroy it.
+ *
+ * \note use subpicture_region_NewText() to create a text region
*/
VLC_API subpicture_region_t * subpicture_region_New( const video_format_t
*p_fmt );
+/**
+ * This function will create a new text subpicture region.
+ *
+ * You must use subpicture_region_Delete to destroy it.
+ */
+VLC_API subpicture_region_t * subpicture_region_NewText( void );
+
/**
* Create a subpicture region containing the picture.
*
=====================================
modules/codec/arib/substext.h
=====================================
@@ -73,28 +73,25 @@ static void SubpictureTextUpdate(subpicture_t *subpic,
return;
}
- video_format_t fmt;
- video_format_Init(&fmt, VLC_CODEC_TEXT);
- fmt.i_sar_num = 1;
- fmt.i_sar_den = 1;
-
subpicture_region_t *r = NULL;
arib_text_region_t *p_region;
for( p_region = sys->p_region; p_region; p_region = p_region->p_next )
{
if( !r )
{
- subpic->p_region = r = subpicture_region_New(&fmt);
+ subpic->p_region = r = subpicture_region_NewText();
}
else
{
- r->p_next = subpicture_region_New(&fmt);
+ r->p_next = subpicture_region_NewText();
r = r->p_next;
}
if( r == NULL )
{
return;
}
+ r->fmt.i_sar_num = 1;
+ r->fmt.i_sar_den = 1;
r->p_text = text_segment_New( p_region->psz_text );
r->i_align = SUBPICTURE_ALIGN_LEFT | SUBPICTURE_ALIGN_TOP;
=====================================
modules/codec/dvbsub.c
=====================================
@@ -1632,14 +1632,17 @@ static subpicture_t *render( decoder_t *p_dec )
continue;
/* Create new SPU region */
- video_format_Init( &fmt, VLC_CODEC_TEXT );
- fmt.i_sar_num = 1;
- fmt.i_sar_den = 1;
- fmt.i_width = fmt.i_visible_width = p_region->i_width;
- fmt.i_height = fmt.i_visible_height = p_region->i_height;
- fmt.i_x_offset = fmt.i_y_offset = 0;
- p_spu_region = subpicture_region_New( &fmt );
- video_format_Clean( &fmt );
+ p_spu_region = subpicture_region_NewText();
+ if( !p_spu_region )
+ {
+ msg_Err( p_dec, "cannot allocate SPU region" );
+ continue;
+ }
+
+ p_spu_region->fmt.i_sar_num = 1;
+ p_spu_region->fmt.i_sar_den = 1;
+ p_spu_region->fmt.i_width = p_spu_region->fmt.i_visible_width =
p_region->i_width;
+ p_spu_region->fmt.i_height = p_spu_region->fmt.i_visible_height =
p_region->i_height;
p_spu_region->p_text = text_segment_New( p_object_def->psz_text );
p_spu_region->i_x = i_base_x + p_regiondef->i_x +
p_object_def->i_x;
=====================================
modules/codec/kate.c
=====================================
@@ -1081,7 +1081,6 @@ static subpicture_t *SetupSimpleKateSPU( decoder_t
*p_dec, subpicture_t *p_spu,
const kate_event *ev )
{
decoder_sys_t *p_sys = p_dec->p_sys;
- video_format_t fmt;
subpicture_region_t *p_bitmap_region = NULL;
video_palette_t palette;
kate_tracker kin;
@@ -1121,6 +1120,7 @@ static subpicture_t *SetupSimpleKateSPU( decoder_t
*p_dec, subpicture_t *p_spu,
if (ev->bitmap && ev->bitmap->type==kate_bitmap_type_paletted &&
ev->palette) {
/* create a separate region for the bitmap */
+ video_format_t fmt;
video_format_Init( &fmt, VLC_CODEC_YUVP );
fmt.i_width = fmt.i_visible_width = ev->bitmap->width;
fmt.i_height = fmt.i_visible_height = ev->bitmap->height;
@@ -1143,13 +1143,7 @@ static subpicture_t *SetupSimpleKateSPU( decoder_t
*p_dec, subpicture_t *p_spu,
}
/* text region */
- video_format_Init( &fmt, VLC_CODEC_TEXT );
- fmt.i_sar_num = 0;
- fmt.i_sar_den = 1;
- fmt.i_width = fmt.i_height = 0;
- fmt.i_x_offset = fmt.i_y_offset = 0;
- p_spu->p_region = subpicture_region_New( &fmt );
- video_format_Clean( &fmt );
+ p_spu->p_region = subpicture_region_NewText();
if( !p_spu->p_region )
{
msg_Err( p_dec, "cannot allocate SPU region" );
@@ -1158,6 +1152,8 @@ static subpicture_t *SetupSimpleKateSPU( decoder_t
*p_dec, subpicture_t *p_spu,
subpicture_Delete( p_spu );
return NULL;
}
+ p_spu->p_region->fmt.i_sar_num = 0;
+ p_spu->p_region->fmt.i_sar_den = 1;
SetupText( p_dec, p_spu, ev );
=====================================
modules/codec/substext.h
=====================================
@@ -168,10 +168,11 @@ static void SubpictureTextUpdate(subpicture_t *subpic,
for( substext_updater_region_t *p_updtregion = &sys->region;
p_updtregion; p_updtregion =
p_updtregion->p_next )
{
- subpicture_region_t *r = *pp_last_region = subpicture_region_New(&fmt);
+ subpicture_region_t *r = *pp_last_region = subpicture_region_NewText();
if (!r)
return;
pp_last_region = &r->p_next;
+ video_format_Copy( &r->fmt, &fmt );
r->p_text = text_segment_Copy( p_updtregion->p_segments );
r->i_align = p_updtregion->align;
=====================================
modules/codec/subsusf.c
=====================================
@@ -416,15 +416,9 @@ static subpicture_region_t *CreateTextRegion( decoder_t
*p_dec,
{
decoder_sys_t *p_sys = p_dec->p_sys;
subpicture_region_t *p_text_region;
- video_format_t fmt;
/* Create a new subpicture region */
- video_format_Init( &fmt, VLC_CODEC_TEXT );
- fmt.i_width = fmt.i_height = 0;
- fmt.i_x_offset = fmt.i_y_offset = 0;
- p_text_region = subpicture_region_New( &fmt );
- video_format_Clean( &fmt );
-
+ p_text_region = subpicture_region_NewText();
if( p_text_region != NULL )
{
ssa_style_t *p_ssa_style = NULL;
=====================================
modules/codec/telx.c
=====================================
@@ -620,7 +620,6 @@ static int Decode( decoder_t *p_dec, block_t *p_block )
{
decoder_sys_t *p_sys = p_dec->p_sys;
subpicture_t *p_spu = NULL;
- video_format_t fmt;
/* int erase = 0; */
#if 0
int i_wanted_magazine = i_conf_wanted_page / 100;
@@ -730,8 +729,7 @@ static int Decode( decoder_t *p_dec, block_t *p_block )
}
/* Create a new subpicture region */
- video_format_Init(&fmt, VLC_CODEC_TEXT);
- p_spu->p_region = subpicture_region_New( &fmt );
+ p_spu->p_region = subpicture_region_NewText();
if( p_spu->p_region == NULL )
{
msg_Err( p_dec, "cannot allocate SPU region" );
=====================================
modules/codec/zvbi.c
=====================================
@@ -522,7 +522,6 @@ static subpicture_t *Subpicture( decoder_t *p_dec,
video_format_t *p_fmt,
int i_columns, int i_rows, int i_align,
vlc_tick_t i_pts )
{
- video_format_t fmt;
subpicture_t *p_spu=NULL;
/* If there is a page or sub to render, then we do that here */
@@ -537,16 +536,20 @@ static subpicture_t *Subpicture( decoder_t *p_dec,
video_format_t *p_fmt,
return NULL;
}
- video_format_Init(&fmt, b_text ? VLC_CODEC_TEXT : VLC_CODEC_RGBA);
if( !b_text )
{
+ video_format_t fmt;
+ video_format_Init(&fmt, VLC_CODEC_RGBA);
fmt.i_width = fmt.i_visible_width = i_columns * 12;
fmt.i_height = fmt.i_visible_height = i_rows * 10;
fmt.i_sar_num = fmt.i_sar_den = 0; /* let the vout set the correct AR
*/
+ p_spu->p_region = subpicture_region_New( &fmt );
+ }
+ else
+ {
+ p_spu->p_region = subpicture_region_NewText();
}
- fmt.i_x_offset = fmt.i_y_offset = 0;
- p_spu->p_region = subpicture_region_New( &fmt );
if( p_spu->p_region == NULL )
{
msg_Err( p_dec, "cannot allocate SPU region" );
@@ -564,11 +567,11 @@ static subpicture_t *Subpicture( decoder_t *p_dec,
video_format_t *p_fmt,
if( !b_text )
p_spu->p_region->i_align = i_align;
- p_spu->i_original_picture_width = fmt.i_width;
- p_spu->i_original_picture_height = fmt.i_height;
+ p_spu->i_original_picture_width = p_spu->p_region->fmt.i_width;
+ p_spu->i_original_picture_height = p_spu->p_region->fmt.i_height;
/* */
- *p_fmt = fmt;
+ *p_fmt = p_spu->p_region->fmt;
return p_spu;
}
=====================================
modules/spu/dynamicoverlay/dynamicoverlay.c
=====================================
@@ -352,7 +352,7 @@ static subpicture_t *Filter( filter_t *p_filter, vlc_tick_t
date )
subpicture_region_t *p_region;
if( p_overlay->format.i_chroma == VLC_CODEC_TEXT )
- p_region = subpicture_region_New( &p_overlay->format );
+ p_region = subpicture_region_NewText();
else
p_region = subpicture_region_ForPicture( &p_overlay->format,
p_overlay->data.p_pic );
if( unlikely(p_region == NULL) )
@@ -367,6 +367,7 @@ static subpicture_t *Filter( filter_t *p_filter, vlc_tick_t
date )
if( p_overlay->format.i_chroma == VLC_CODEC_TEXT )
{
+ video_format_Copy( &p_region->fmt, &p_overlay->format );
p_region->p_text = text_segment_New( p_overlay->data.p_text );
p_region->p_text->style = text_style_Duplicate(
p_overlay->p_fontstyle );
}
=====================================
modules/spu/marq.c
=====================================
@@ -284,16 +284,14 @@ static subpicture_t *Filter( filter_t *p_filter,
vlc_tick_t date )
if( !p_spu )
goto out;
- video_format_t vfmt;
- video_format_Init( &vfmt, VLC_CODEC_TEXT );
- vfmt.i_sar_den = vfmt.i_sar_num = 1;
- p_spu->p_region = subpicture_region_New( &vfmt );
+ p_spu->p_region = subpicture_region_NewText();
if( !p_spu->p_region )
{
subpicture_Delete( p_spu );
p_spu = NULL;
goto out;
}
+ p_spu->p_region->fmt.i_sar_den = p_spu->p_region->fmt.i_sar_num = 1;
p_sys->last_time = date;
=====================================
modules/spu/rss.c
=====================================
@@ -343,7 +343,6 @@ static subpicture_t *Filter( filter_t *p_filter, vlc_tick_t
date )
{
filter_sys_t *p_sys = p_filter->p_sys;
subpicture_t *p_spu;
- video_format_t fmt;
subpicture_region_t *p_region;
int i_item;
@@ -403,9 +402,7 @@ static subpicture_t *Filter( filter_t *p_filter, vlc_tick_t
date )
return NULL;
}
- video_format_Init( &fmt, VLC_CODEC_TEXT );
-
- p_spu->p_region = subpicture_region_New( &fmt );
+ p_spu->p_region = subpicture_region_NewText();
if( !p_spu->p_region )
{
subpicture_Delete( p_spu );
=====================================
src/libvlccore.sym
=====================================
@@ -410,6 +410,7 @@ subpicture_region_ChainDelete
subpicture_region_Copy
subpicture_region_Delete
subpicture_region_New
+subpicture_region_NewText
subpicture_region_ForPicture
text_segment_New
text_segment_NewInheritStyle
=====================================
src/misc/subpicture.c
=====================================
@@ -201,12 +201,27 @@ void subpicture_region_private_Delete(
subpicture_region_private_t *p_private )
free( p_private );
}
-subpicture_region_t * subpicture_region_NewInternal( const video_format_t
*p_fmt )
+static subpicture_region_t * subpicture_region_NewInternal( void )
{
subpicture_region_t *p_region = calloc( 1, sizeof(*p_region ) );
if( unlikely(p_region == NULL) )
return NULL;
+ p_region->zoom_h.den = p_region->zoom_h.num = 1;
+ p_region->zoom_v.den = p_region->zoom_v.num = 1;
+ p_region->i_alpha = 0xff;
+ p_region->b_balanced_text = true;
+
+ return p_region;
+}
+
+subpicture_region_t *subpicture_region_New( const video_format_t *p_fmt )
+{
+ assert(p_fmt->i_chroma != VLC_CODEC_TEXT);
+ subpicture_region_t *p_region = subpicture_region_NewInternal( );
+ if( !p_region )
+ return NULL;
+
video_format_Copy( &p_region->fmt, p_fmt );
if ( p_fmt->i_chroma == VLC_CODEC_YUVP || p_fmt->i_chroma ==
VLC_CODEC_RGBP )
{
@@ -227,31 +242,24 @@ subpicture_region_t * subpicture_region_NewInternal(
const video_format_t *p_fmt
assert(p_fmt->p_palette == NULL);
}
- p_region->zoom_h.den = p_region->zoom_h.num = 1;
- p_region->zoom_v.den = p_region->zoom_v.num = 1;
- p_region->i_alpha = 0xff;
- p_region->b_balanced_text = true;
+ p_region->p_picture = picture_NewFromFormat( p_fmt );
+ if( !p_region->p_picture )
+ {
+ video_format_Clean( &p_region->fmt );
+ free( p_region );
+ return NULL;
+ }
return p_region;
}
-subpicture_region_t *subpicture_region_New( const video_format_t *p_fmt )
+subpicture_region_t *subpicture_region_NewText( void )
{
- subpicture_region_t *p_region =
- subpicture_region_NewInternal( p_fmt );
+ subpicture_region_t *p_region = subpicture_region_NewInternal( );
if( !p_region )
return NULL;
- if( p_fmt->i_chroma == VLC_CODEC_TEXT )
- return p_region;
-
- p_region->p_picture = picture_NewFromFormat( p_fmt );
- if( !p_region->p_picture )
- {
- video_format_Clean( &p_region->fmt );
- free( p_region );
- return NULL;
- }
+ video_format_Init( &p_region->fmt, VLC_CODEC_TEXT );
return p_region;
}
@@ -261,10 +269,30 @@ subpicture_region_t *subpicture_region_ForPicture( const
video_format_t *p_fmt,
if ( !video_format_IsSameChroma( p_fmt, &pic->format ) )
return NULL;
- subpicture_region_t *p_region = subpicture_region_NewInternal( p_fmt );
+ subpicture_region_t *p_region = subpicture_region_NewInternal( );
if( !p_region )
return NULL;
+ video_format_Copy( &p_region->fmt, p_fmt );
+ if ( p_fmt->i_chroma == VLC_CODEC_YUVP || p_fmt->i_chroma ==
VLC_CODEC_RGBP )
+ {
+ /* YUVP/RGBP should have a palette */
+ if( p_region->fmt.p_palette == NULL )
+ {
+ p_region->fmt.p_palette = calloc( 1,
sizeof(*p_region->fmt.p_palette) );
+ if( p_region->fmt.p_palette == NULL )
+ {
+ video_format_Clean( &p_region->fmt );
+ free( p_region );
+ return NULL;
+ }
+ }
+ }
+ else
+ {
+ assert(p_fmt->p_palette == NULL);
+ }
+
p_region->p_picture = picture_Hold(pic);
return p_region;
=====================================
src/misc/subpicture.h
=====================================
@@ -25,8 +25,6 @@ struct subpicture_region_private_t {
picture_t *p_picture;
};
-subpicture_region_t * subpicture_region_NewInternal( const video_format_t
*p_fmt );
-
subpicture_region_private_t *subpicture_region_private_New(video_format_t *);
void subpicture_region_private_Delete(subpicture_region_private_t *);
=====================================
src/video_output/video_epg.c
=====================================
@@ -251,21 +251,18 @@ static void vout_OSDRegionConstrain(subpicture_region_t
*p_region, int w, int h)
static subpicture_region_t * vout_OSDTextRegion(text_segment_t *p_segment,
int x, int y )
{
- video_format_t fmt;
subpicture_region_t *region;
if (!p_segment)
return NULL;
/* Create a new subpicture region */
- video_format_Init(&fmt, VLC_CODEC_TEXT);
- fmt.i_sar_num = 1;
- fmt.i_sar_den = 1;
-
- region = subpicture_region_New(&fmt);
+ region = subpicture_region_NewText();
if (!region)
return NULL;
+ region->fmt.i_sar_num = 1;
+ region->fmt.i_sar_den = 1;
region->p_text = p_segment;
region->i_align = SUBPICTURE_ALIGN_LEFT | SUBPICTURE_ALIGN_TOP;
region->i_text_align = SUBPICTURE_ALIGN_LEFT | SUBPICTURE_ALIGN_TOP;
=====================================
src/video_output/video_text.c
=====================================
@@ -66,15 +66,12 @@ static void OSDTextUpdate(subpicture_t *subpic,
subpic->i_original_picture_width = fmt_dst->i_visible_width *
fmt_dst->i_sar_num / fmt_dst->i_sar_den;
subpic->i_original_picture_height = fmt_dst->i_visible_height;
- video_format_t fmt;
- video_format_Init( &fmt, VLC_CODEC_TEXT);
- fmt.i_sar_num = 1;
- fmt.i_sar_den = 1;
-
- subpicture_region_t *r = subpic->p_region = subpicture_region_New(&fmt);
+ subpicture_region_t *r = subpic->p_region = subpicture_region_NewText();
if (!r)
return;
+ r->fmt.i_sar_num = 1;
+ r->fmt.i_sar_den = 1;
r->p_text = text_segment_New( sys->text );
const float margin_ratio = 0.04f;
=====================================
src/video_output/vout_subpictures.c
=====================================
@@ -1114,13 +1114,12 @@ static void SpuRenderRegion(spu_t *spu,
}
}
- subpicture_region_t *dst = *dst_ptr =
subpicture_region_NewInternal(®ion_fmt);
+ assert(video_format_IsSameChroma( ®ion_fmt, ®ion_picture->format ));
+ subpicture_region_t *dst = *dst_ptr =
subpicture_region_ForPicture(®ion_fmt, region_picture);
if (dst) {
dst->i_x = x_offset;
dst->i_y = y_offset;
dst->i_align = 0;
- assert(!dst->p_picture);
- dst->p_picture = picture_Hold(region_picture);
int fade_alpha = 255;
if (subpic->b_fade) {
vlc_tick_t fade_start = subpic->i_start + 3 * (subpic->i_stop -
subpic->i_start) / 4;
=====================================
test/src/input/decoder/input_decoder_scenarios.c
=====================================
@@ -482,9 +482,7 @@ static int cc_decoder_decode_common(decoder_t *dec,
vlc_frame_t *in,
subpic->i_start = in->i_pts;
subpic->i_stop = subpic->i_start + in->i_length;
- video_format_t fmt;
- video_format_Init(&fmt, VLC_CODEC_TEXT);
- subpic->p_region = subpicture_region_New(&fmt);
+ subpic->p_region = subpicture_region_NewText();
assert(subpic->p_region != NULL);
subpic->p_region->p_text = text_segment_New(text);
View it on GitLab:
https://code.videolan.org/videolan/vlc/-/compare/d6f3ef7aaa28419b61cffd8314be9d3826383282...ddfeaeaa350b585d0d69570cf398781d2bea3c53
--
View it on GitLab:
https://code.videolan.org/videolan/vlc/-/compare/d6f3ef7aaa28419b61cffd8314be9d3826383282...ddfeaeaa350b585d0d69570cf398781d2bea3c53
You're receiving this email because of your account on code.videolan.org.
VideoLAN code repository instance
_______________________________________________
vlc-commits mailing list
vlc-commits@videolan.org
https://mailman.videolan.org/listinfo/vlc-commits