[vlc-devel] [PATCH 2/4] vhs: remove dynamic allocation for planes data

Alexandre Janniaux ajanni at videolabs.io
Sun Sep 20 18:00:05 CEST 2020


Since the number of planes is bounded to a low value, allocating the
planes data statically is much easier and have no significative memory
footprint.
---
 modules/video_filter/vhs.c | 17 +++--------------
 1 file changed, 3 insertions(+), 14 deletions(-)

diff --git a/modules/video_filter/vhs.c b/modules/video_filter/vhs.c
index 6d5c13db8e..a76bc9500a 100644
--- a/modules/video_filter/vhs.c
+++ b/modules/video_filter/vhs.c
@@ -55,9 +55,9 @@ typedef struct
     /* general data */
     bool b_init;
     int32_t  i_planes;
-    int32_t *i_height; /* note: each plane may have different dimensions */
-    int32_t *i_width;
-    int32_t *i_visible_pitch;
+    int32_t i_height[VOUT_MAX_PLANES]; /* note: each plane may have different dimensions */
+    int32_t i_width[VOUT_MAX_PLANES];
+    int32_t i_visible_pitch[VOUT_MAX_PLANES];
     vlc_tick_t  i_start_time;
     vlc_tick_t  i_last_time;
     vlc_tick_t  i_cur_time;
@@ -223,14 +223,6 @@ static int vhs_allocate_data( filter_t *p_filter, picture_t *p_pic_in ) {
     * take into account different characteristics for each plane
     */
     p_sys->i_planes = p_pic_in->i_planes;
-    p_sys->i_height = calloc( p_sys->i_planes, sizeof(int32_t) );
-    p_sys->i_width  = calloc( p_sys->i_planes, sizeof(int32_t) );
-    p_sys->i_visible_pitch = calloc( p_sys->i_planes, sizeof(int32_t) );
-
-    if( unlikely( !p_sys->i_height || !p_sys->i_width || !p_sys->i_visible_pitch ) ) {
-        vhs_free_allocated_data( p_filter );
-        return VLC_ENOMEM;
-    }
 
     for ( int32_t i_p = 0; i_p < p_sys->i_planes; i_p++) {
         p_sys->i_visible_pitch [i_p] = (int) p_pic_in->p[i_p].i_visible_pitch;
@@ -250,9 +242,6 @@ static void vhs_free_allocated_data( filter_t *p_filter ) {
         FREENULL( p_sys->p_BR_lines[i_b] );
 
     p_sys->i_planes = 0;
-    FREENULL( p_sys->i_height );
-    FREENULL( p_sys->i_width );
-    FREENULL( p_sys->i_visible_pitch );
 }
 
 static vlc_tick_t RandomEnd(filter_sys_t *p_sys, vlc_tick_t modulo)
-- 
2.28.0



More information about the vlc-devel mailing list