[vlc-commits] [Git][videolan/vlc][master] 9 commits: vout_subpictures: avoid double region lookup when updating position
Steve Lhomme (@robUx4)
gitlab at videolan.org
Fri Jun 6 15:21:10 UTC 2025
Steve Lhomme pushed to branch master at VideoLAN / VLC
Commits:
a2362f3c by Steve Lhomme at 2025-06-06T15:01:43+00:00
vout_subpictures: avoid double region lookup when updating position
If we already found the position for the region, no need to look for it again.
- - - - -
1e92e13d by Steve Lhomme at 2025-06-06T15:01:43+00:00
vout_subpictures: rename Add/FindRegion to Add/FindRelativeRegion
So it's clearer the cache only deals with relative positioning.
- - - - -
36c0e883 by Steve Lhomme at 2025-06-06T15:01:43+00:00
vout_subpictures: avoid a cache lookup for absolute regions
- - - - -
7cc7ecc9 by Steve Lhomme at 2025-06-06T15:01:43+00:00
vout_subpictures: avoid a cache lookup for non-subtitle regions
So it matches the AddRegion call.
- - - - -
3617fead by Steve Lhomme at 2025-06-06T15:01:43+00:00
vout_subpictures: avoid extra checks when caching a relative subtitle position
We already did the checks before.
The region is just passed as a blind pointer for later comparison.
- - - - -
cace9e94 by Steve Lhomme at 2025-06-06T15:01:43+00:00
vout_subpictures: initialize subtitle_area once
- - - - -
6cb0b447 by Steve Lhomme at 2025-06-06T15:01:43+00:00
vout_subpictures: keep all subtitle position regions
This is used to avoid overlap between regions and the array is meant to
contain all regions, not just the relative ones.
We can only reposition relatively positioned subtitles but they should
not overlap with any other subtitle, relative or absolute.
- - - - -
4fa1f91c by Steve Lhomme at 2025-06-06T15:01:43+00:00
vout_subpictures: compare the cached position to the new area
The cached position is the unscaled version, whereas output_last_ptr
has the final position in the display.
- - - - -
a615ef8f by Steve Lhomme at 2025-06-06T15:01:43+00:00
vout_subpictures: keep the current rendered regions as scaled for the vout
They are compared scaled in SpuRenderRegion().
- - - - -
1 changed file:
- src/video_output/vout_subpictures.c
Changes:
=====================================
src/video_output/vout_subpictures.c
=====================================
@@ -636,16 +636,10 @@ static void subtitles_positions_FinishUpdate(subtitles_positions_vector *subs)
}
}
-static struct subtitle_position_cache *subtitles_positions_FindRegion(
+static struct subtitle_position_cache *subtitles_positions_FindRelativeRegion(
const subtitles_positions_vector *subs,
- const subpicture_t *subpic,
const subpicture_region_t *region)
{
- if (!subpic->b_subtitle)
- return NULL;
- if (region->b_absolute)
- return NULL;
-
struct subtitle_position_cache *pos;
vlc_vector_foreach_ref(pos, subs)
{
@@ -657,20 +651,14 @@ static struct subtitle_position_cache *subtitles_positions_FindRegion(
return NULL;
}
-static void subtitles_positions_AddRegion(subtitles_positions_vector *subs,
- const subpicture_t *subpic,
+static void subtitles_positions_AddRelativeRegion(subtitles_positions_vector *subs,
const subpicture_region_t *region,
- const spu_area_t *area)
+ const spu_area_t *area,
+ struct subtitle_position_cache *write)
{
- assert(subpic->b_subtitle);
- if (region->b_absolute)
- return;
if (area->width <= 0 && area->height <= 0)
return;
- // find existing
- struct subtitle_position_cache *write =
- subtitles_positions_FindRegion(subs, subpic, region);
if (write == NULL)
{
if (unlikely(!vlc_vector_insert_hole(subs, subs->size, 1)))
@@ -1379,9 +1367,10 @@ static vlc_render_subpicture *SpuRenderSubpictures(spu_t *spu,
subtitles_positions_StartUpdate(&sys->subs_pos);
- subtitle_area = subtitle_area_buffer;
- if (subtitle_region_count > ARRAY_SIZE(subtitle_area_buffer))
+ if (unlikely(subtitle_region_count > ARRAY_SIZE(subtitle_area_buffer)))
subtitle_area = calloc(subtitle_region_count, sizeof(*subtitle_area));
+ else
+ subtitle_area = subtitle_area_buffer;
/* Process all subpictures and regions (in the right order) */
for (size_t index = 0; index < i_subpicture; index++) {
@@ -1468,22 +1457,24 @@ static vlc_render_subpicture *SpuRenderSubpictures(spu_t *spu,
/* Check scale validity */
assert(scale.w != 0 && scale.h != 0);
- bool cached_is_absolute;
bool cached_is_in_window;
int cached_alignment;
subpicture_t forced_subpic = *subpic;
- struct subtitle_position_cache *cache_pos =
- subtitles_positions_FindRegion(&sys->subs_pos, subpic, region);
- if (cache_pos != NULL)
+ struct subtitle_position_cache *cache_pos = NULL;
+ if (subpic->b_subtitle && !region->b_absolute)
{
- region->i_x = cache_pos->x;
- region->i_y = cache_pos->y;
- cached_is_absolute = region->b_absolute;
- cached_is_in_window = region->b_in_window;
- cached_alignment = region->i_align;
- region->i_align = SUBPICTURE_ALIGN_TOP | SUBPICTURE_ALIGN_LEFT;
- region->b_absolute = true;
- region->b_in_window = true;
+ cache_pos =
+ subtitles_positions_FindRelativeRegion(&sys->subs_pos, region);
+ if (cache_pos != NULL)
+ {
+ region->i_x = cache_pos->x;
+ region->i_y = cache_pos->y;
+ cached_is_in_window = region->b_in_window;
+ cached_alignment = region->i_align;
+ region->i_align = SUBPICTURE_ALIGN_TOP | SUBPICTURE_ALIGN_LEFT;
+ region->b_absolute = true;
+ region->b_in_window = true;
+ }
}
/* */
@@ -1505,21 +1496,24 @@ static vlc_render_subpicture *SpuRenderSubpictures(spu_t *spu,
if (cache_pos != NULL)
{
- region->b_absolute = cached_is_absolute;
+ region->b_absolute = false;
region->b_in_window = cached_is_in_window;
region->i_align = cached_alignment;
- assert(output_last_ptr->place.x == cache_pos->x);
- assert(output_last_ptr->place.y == cache_pos->y);
+ assert(area.x == cache_pos->x);
+ assert(area.y == cache_pos->y);
}
vlc_vector_push(&output->regions, output_last_ptr);
- if (subpic->b_subtitle && !region->b_absolute) {
- if (!external_scale)
- area = spu_area_unscaled(area, scale);
- if (subtitle_area)
+ if (subpic->b_subtitle) {
+ if (likely(subtitle_area))
subtitle_area[subtitle_area_count++] = area;
- subtitles_positions_AddRegion(&sys->subs_pos, subpic, region, &area);
+ if (!region->b_absolute)
+ {
+ if (!external_scale)
+ area = spu_area_unscaled(area, scale);
+ subtitles_positions_AddRelativeRegion(&sys->subs_pos, region, &area, cache_pos);
+ }
}
}
}
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/b1f3e4ef2833e2091aac6a34f8c5c4a996118d9e...a615ef8f10f3a02b9c5b43b247f845352cca6492
--
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/b1f3e4ef2833e2091aac6a34f8c5c4a996118d9e...a615ef8f10f3a02b9c5b43b247f845352cca6492
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