[vlc-commits] [Git][videolan/vlc][master] 4 commits: dynamicoverlay: use vlc_vector instead of custom list handler

Steve Lhomme (@robUx4) gitlab at videolan.org
Sat Nov 4 09:41:01 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
bbe2ee00 by Steve Lhomme at 2023-11-04T09:21:01+00:00
dynamicoverlay: use vlc_vector instead of custom list handler

- - - - -
d5b02753 by Steve Lhomme at 2023-11-04T09:21:01+00:00
dynamicoverlay: remove dynamicoverlay_list.c

We can just handle the vector locally.

- - - - -
59d91704 by Steve Lhomme at 2023-11-04T09:21:01+00:00
dynamicoverlay: free the overlay_t in OverlayDestroy()

And don't return a constant value.

There was a leak when called from exec_DeleteImage(). It was removed from the
list/vector but the structure was not released and once the pointer is
removed from the list, it's not referenced elsewhere.

- - - - -
be937f8f by Steve Lhomme at 2023-11-04T09:21:01+00:00
dynamicoverlay: build on Windows

It builds fine. Not sure why it was disabled.

- - - - -


6 changed files:

- modules/spu/Makefile.am
- modules/spu/dynamicoverlay/dynamicoverlay.c
- modules/spu/dynamicoverlay/dynamicoverlay.h
- modules/spu/dynamicoverlay/dynamicoverlay_commands.c
- − modules/spu/dynamicoverlay/dynamicoverlay_list.c
- modules/spu/meson.build


Changes:

=====================================
modules/spu/Makefile.am
=====================================
@@ -25,9 +25,6 @@ spu_LTLIBRARIES += \
 libdynamicoverlay_plugin_la_SOURCES = \
 	spu/dynamicoverlay/dynamicoverlay_buffer.c \
 	spu/dynamicoverlay/dynamicoverlay_queue.c \
-	spu/dynamicoverlay/dynamicoverlay_list.c \
 	spu/dynamicoverlay/dynamicoverlay_commands.c \
 	spu/dynamicoverlay/dynamicoverlay.c spu/dynamicoverlay/dynamicoverlay.h
-if !HAVE_WIN32
 spu_LTLIBRARIES += libdynamicoverlay_plugin.la
-endif


=====================================
modules/spu/dynamicoverlay/dynamicoverlay.c
=====================================
@@ -104,7 +104,7 @@ static int Create( filter_t *p_filter )
     QueueInit( &p_sys->atomic );
     QueueInit( &p_sys->pending );
     QueueInit( &p_sys->processed );
-    do_ListInit( &p_sys->overlays );
+    vlc_vector_init( &p_sys->overlays );
 
     p_sys->i_inputfd = -1;
     p_sys->i_outputfd = -1;
@@ -143,7 +143,12 @@ static void Destroy( filter_t *p_filter )
     QueueDestroy( &p_sys->atomic );
     QueueDestroy( &p_sys->pending );
     QueueDestroy( &p_sys->processed );
-    do_ListDestroy( &p_sys->overlays );
+    overlay_t *p_cur;
+    vlc_vector_foreach(p_cur, &p_sys->overlays)
+    {
+        OverlayDestroy( p_cur );
+    }
+    vlc_vector_destroy( &p_sys->overlays );
     UnregisterCommand( p_filter );
 
     var_DelCallback( p_filter, "overlay-input", AdjustCallback, p_sys );
@@ -335,7 +340,7 @@ static subpicture_t *Filter( filter_t *p_filter, vlc_tick_t date )
         return NULL;
 
     subpicture_t *p_spu = NULL;
-    overlay_t *p_overlay = NULL;
+    overlay_t *p_overlay;
 
     p_spu = filter_NewSubpicture( p_filter );
     if( !p_spu )
@@ -347,8 +352,11 @@ static subpicture_t *Filter( filter_t *p_filter, vlc_tick_t date )
     p_spu->b_ephemer = true;
 
     subpicture_region_t **pp_region = &p_spu->p_region;
-    while( (p_overlay = ListWalk( &p_sys->overlays )) )
+    vlc_vector_foreach(p_overlay, &p_sys->overlays)
     {
+        if (!p_overlay->b_active || p_overlay->format.i_chroma == 0)
+            continue;
+
         subpicture_region_t *p_region;
 
         if( p_overlay->format.i_chroma == 0 )


=====================================
modules/spu/dynamicoverlay/dynamicoverlay.h
=====================================
@@ -26,6 +26,7 @@
 #include <vlc_common.h>
 #include <vlc_filter.h>
 #include <vlc_text_style.h>
+#include <vlc_vector.h>
 
 /*****************************************************************************
  * buffer_t: Command and response buffer
@@ -141,23 +142,13 @@ typedef struct overlay_t
 } overlay_t;
 
 overlay_t *OverlayCreate( void );
-int OverlayDestroy( overlay_t *p_ovl );
+void OverlayDestroy( overlay_t *p_ovl );
 
 /*****************************************************************************
  * list_t: Command queue
  *****************************************************************************/
 
-typedef struct list_t
-{
-    overlay_t **pp_head, **pp_tail;
-} list_t;
-
-int do_ListInit( list_t *p_list );
-int do_ListDestroy( list_t *p_list );
-ssize_t ListAdd( list_t *p_list, overlay_t *p_new );
-int ListRemove( list_t *p_list, size_t i_idx );
-overlay_t *ListGet( list_t *p_list, size_t i_idx );
-overlay_t *ListWalk( list_t *p_list );
+typedef struct VLC_VECTOR(overlay_t *) list_t;
 
 /*****************************************************************************
  * filter_sys_t: adjust filter method descriptor


=====================================
modules/spu/dynamicoverlay/dynamicoverlay_commands.c
=====================================
@@ -63,14 +63,13 @@ overlay_t *OverlayCreate( void )
     return p_ovl;
 }
 
-int OverlayDestroy( overlay_t *p_ovl )
+void OverlayDestroy( overlay_t *p_ovl )
 {
     if( p_ovl->data.p_pic != NULL )
         picture_Release( p_ovl->data.p_pic );
     free( p_ovl->data.p_text );
     text_style_Delete( p_ovl->p_fontstyle );
-
-    return VLC_SUCCESS;
+    free( p_ovl );
 }
 
 /*****************************************************************************
@@ -418,6 +417,13 @@ static int unparse_GetVisibility( const commandparams_t *p_results,
     return VLC_SUCCESS;
 }
 
+static inline overlay_t *ListGet( list_t *p_list, size_t i_idx )
+{
+    if (i_idx >= p_list->size)
+        return NULL;
+    return p_list->data[i_idx];
+}
+
 /*****************************************************************************
  * Command functions
  *****************************************************************************/
@@ -568,7 +574,13 @@ static int exec_DeleteImage( filter_t *p_filter,
     filter_sys_t *p_sys = p_filter->p_sys;
     p_sys->b_updated = true;
 
-    return ListRemove( &p_sys->overlays, p_params->i_id );
+    if ( p_params->i_id >= p_sys->overlays.size)
+        return VLC_EINVAL;
+
+    overlay_t *p_del = p_sys->overlays.data[p_params->i_id];
+    vlc_vector_remove(&p_sys->overlays, p_params->i_id);
+    OverlayDestroy( p_del );
+    return VLC_SUCCESS;
 }
 
 static int exec_EndAtomic( filter_t *p_filter,
@@ -594,11 +606,10 @@ static int exec_GenImage( filter_t *p_filter,
     if( p_ovl == NULL )
         return VLC_ENOMEM;
 
-    ssize_t i_idx = ListAdd( &p_sys->overlays, p_ovl );
-    if( i_idx < 0 )
-        return i_idx;
+    if (!vlc_vector_push(&p_sys->overlays, p_ovl))
+        return VLC_ENOMEM;
 
-    p_results->i_id = i_idx;
+    p_results->i_id = p_sys->overlays.size - 1;
     return VLC_SUCCESS;
 }
 


=====================================
modules/spu/dynamicoverlay/dynamicoverlay_list.c deleted
=====================================
@@ -1,139 +0,0 @@
-/*****************************************************************************
- * dynamicoverlay_list.c : dynamic overlay list
- *****************************************************************************
- * Copyright (C) 2008-2009 VLC authors and VideoLAN
- *
- * Author: Søren Bøg <avacore at videolan.org>
- *         Jean-Paul Saman <jpsaman at videolan.org>
- *
- * This program is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as published by
- * the Free Software Foundation; either version 2.1 of the License, or
- * (at your option) any later version.
- *
- * This program is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public License
- * along with this program; if not, write to the Free Software Foundation,
- * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
- *****************************************************************************/
-
-#ifdef HAVE_CONFIG_H
-# include "config.h"
-#endif
-
-#include <vlc_common.h>
-#include <vlc_arrays.h>
-
-#include "dynamicoverlay.h"
-
-/*****************************************************************************
- * list_t: Command queue
- *****************************************************************************/
-
-int do_ListInit( list_t *p_list )
-{
-    p_list->pp_head = calloc( 16, sizeof( overlay_t * ) );
-    if( p_list->pp_head == NULL )
-        return VLC_ENOMEM;
-
-    p_list->pp_tail = p_list->pp_head + 16;
-    return VLC_SUCCESS;
-}
-
-int do_ListDestroy( list_t *p_list )
-{
-    for( overlay_t **pp_cur = p_list->pp_head;
-         pp_cur < p_list->pp_tail;
-         ++pp_cur )
-    {
-        if( *pp_cur != NULL )
-        {
-            OverlayDestroy( *pp_cur );
-            free( *pp_cur );
-        }
-    }
-    free( p_list->pp_head );
-
-    return VLC_SUCCESS;
-}
-
-ssize_t ListAdd( list_t *p_list, overlay_t *p_new )
-{
-    /* Find an available slot */
-    for( overlay_t **pp_cur = p_list->pp_head;
-         pp_cur < p_list->pp_tail;
-         ++pp_cur )
-    {
-        if( *pp_cur == NULL )
-        {
-            *pp_cur = p_new;
-            return pp_cur - p_list->pp_head;
-        }
-    }
-
-    /* Have to expand */
-    size_t i_size = p_list->pp_tail - p_list->pp_head;
-    size_t i_newsize = i_size * 2;
-    p_list->pp_head = realloc_or_free( p_list->pp_head,
-                                       i_newsize * sizeof( overlay_t * ) );
-    if( p_list->pp_head == NULL )
-        return VLC_ENOMEM;
-
-    p_list->pp_tail = p_list->pp_head + i_newsize;
-    memset( p_list->pp_head + i_size, 0, i_size * sizeof( overlay_t * ) );
-    p_list->pp_head[i_size] = p_new;
-    return i_size;
-}
-
-int ListRemove( list_t *p_list, size_t i_idx )
-{
-    int ret;
-
-    if( ( i_idx >= (size_t)( p_list->pp_tail - p_list->pp_head ) ) ||
-        ( p_list->pp_head[i_idx] == NULL ) )
-    {
-        return VLC_EGENERIC;
-    }
-
-    ret = OverlayDestroy( p_list->pp_head[i_idx] );
-    free( p_list->pp_head[i_idx] );
-    p_list->pp_head[i_idx] = NULL;
-
-    return ret;
-}
-
-overlay_t *ListGet( list_t *p_list, size_t i_idx )
-{
-    if( ( i_idx >= (size_t)( p_list->pp_tail - p_list->pp_head ) ) ||
-        ( p_list->pp_head[i_idx] == NULL ) )
-    {
-        return NULL;
-    }
-    return p_list->pp_head[i_idx];
-}
-
-overlay_t *ListWalk( list_t *p_list )
-{
-    static overlay_t **pp_cur = NULL;
-
-    if( pp_cur == NULL )
-        pp_cur = p_list->pp_head;
-    else
-        pp_cur = pp_cur + 1;
-
-    for( ; pp_cur < p_list->pp_tail; ++pp_cur )
-    {
-        if( ( *pp_cur != NULL ) &&
-            ( (*pp_cur)->b_active )&&
-            ( (*pp_cur)->format.i_chroma != VLC_FOURCC( '\0','\0','\0','\0') ) )
-        {
-            return *pp_cur;
-        }
-    }
-    pp_cur = NULL;
-    return NULL;
-}


=====================================
modules/spu/meson.build
=====================================
@@ -36,16 +36,13 @@ vlc_modules += {
     'sources' : files('rss.c')
 }
 
-if host_system != 'windows'
-    # dynamicoverlay
-    vlc_modules += {
-        'name' : 'dynamicoverlay',
-        'sources' : files(
-            'dynamicoverlay/dynamicoverlay_buffer.c',
-            'dynamicoverlay/dynamicoverlay_queue.c',
-            'dynamicoverlay/dynamicoverlay_list.c',
-            'dynamicoverlay/dynamicoverlay_commands.c',
-            'dynamicoverlay/dynamicoverlay.c'
-        )
-    }
-endif
+# dynamicoverlay
+vlc_modules += {
+    'name' : 'dynamicoverlay',
+    'sources' : files(
+        'dynamicoverlay/dynamicoverlay_buffer.c',
+        'dynamicoverlay/dynamicoverlay_queue.c',
+        'dynamicoverlay/dynamicoverlay_commands.c',
+        'dynamicoverlay/dynamicoverlay.c'
+    )
+}



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/34ad4f2c777f56428963d99047ed7ecf45bdc590...be937f8f378af7002ce6e97351d06f9a4be80980

-- 
View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/34ad4f2c777f56428963d99047ed7ecf45bdc590...be937f8f378af7002ce6e97351d06f9a4be80980
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