[vlc-commits] [Git][videolan/vlc][master] 11 commits: bluray: limit the overlay dimensions to 16-bit unsigned

Steve Lhomme (@robUx4) gitlab at videolan.org
Thu Aug 3 15:10:25 UTC 2023



Steve Lhomme pushed to branch master at VideoLAN / VLC


Commits:
67f576fe by Steve Lhomme at 2023-08-03T14:49:52+00:00
bluray: limit the overlay dimensions to 16-bit unsigned

- - - - -
2eb90dc4 by Steve Lhomme at 2023-08-03T14:49:52+00:00
dvbsub: store the display with as 16-bit unsigned minus one

This is how we receive it.

- - - - -
2655a9f6 by Steve Lhomme at 2023-08-03T14:49:52+00:00
subsusf: only use the original dimensions if they are positive

atoi() may return negative values.

- - - - -
a84dbae8 by Steve Lhomme at 2023-08-03T14:49:52+00:00
zvbi: only use the original dimensions if they are positive

- - - - -
85d88424 by Steve Lhomme at 2023-08-03T14:49:52+00:00
arib: only use the original dimensions if they are positive

- - - - -
2ffa3016 by Steve Lhomme at 2023-08-03T14:49:52+00:00
avcodec: only use the original dimensions if they are positive

- - - - -
2fe02bc7 by Steve Lhomme at 2023-08-03T14:49:52+00:00
imem: limit the width/height to positive values

- - - - -
1e546048 by Steve Lhomme at 2023-08-03T14:49:52+00:00
mosaic: store the width/height as unsigned

The values were already restricted between 0 and INT_MAX

- - - - -
192f3410 by Steve Lhomme at 2023-08-03T14:49:52+00:00
turn SPU original dimensions into unsigned

It doesn't make sense to have width/height as negative.

The vobsub values are initialized to 0 (rather than -1) which signals the
dimensions are not known.

- - - - -
d5514be2 by Steve Lhomme at 2023-08-03T14:49:52+00:00
subpictures: make the SPU scaling values unsigned

- - - - -
ef763e7b by Steve Lhomme at 2023-08-03T14:49:52+00:00
subpictures: ensure scaling is never 0

It cannot be, the SAR cannot be 0, nor the original dimensions (fixed above)
and neither the visible sizes of the output format.

- - - - -


14 changed files:

- include/vlc_es.h
- include/vlc_subpicture.h
- modules/access/bluray.c
- modules/access/imem.c
- modules/codec/arib/substext.h
- modules/codec/avcodec/subtitle.c
- modules/codec/dvbsub.c
- modules/codec/substext.h
- modules/codec/subsusf.c
- modules/codec/zvbi.c
- modules/demux/vobsub.c
- modules/demux/vobsub.h
- modules/spu/mosaic.c
- src/video_output/vout_subpictures.c


Changes:

=====================================
include/vlc_es.h
=====================================
@@ -575,9 +575,9 @@ struct subs_format_t
     struct
     {
         /* the width of the original movie the spu was extracted from */
-        int i_original_frame_width;
+        unsigned i_original_frame_width;
         /* the height of the original movie the spu was extracted from */
-        int i_original_frame_height;
+        unsigned i_original_frame_height;
 
         /*  */
         uint32_t palette[VIDEO_PALETTE_CLUT_COUNT]; /* CLUT Palette AYVU */


=====================================
include/vlc_subpicture.h
=====================================
@@ -207,8 +207,8 @@ struct subpicture_t
     /**@{*/
     bool         b_subtitle;            /**< the picture is a movie subtitle */
     bool         b_absolute;                       /**< position is absolute */
-    int          i_original_picture_width;  /**< original width of the movie */
-    int          i_original_picture_height;/**< original height of the movie */
+    unsigned     i_original_picture_width;  /**< original width of the movie */
+    unsigned     i_original_picture_height;/**< original height of the movie */
     int          i_alpha;                                  /**< transparency */
      /**@}*/
 


=====================================
modules/access/bluray.c
=====================================
@@ -281,7 +281,7 @@ typedef struct bluray_overlay_t
     bool                b_on_vout;
     OverlayStatus       status;
     subpicture_region_t *p_regions;
-    int                 width, height;
+    uint16_t            width, height;
 
     /* pointer to last subpicture updater.
      * used to disconnect this overlay from vout when:
@@ -1857,7 +1857,7 @@ static void blurayClearOverlay(demux_t *p_demux, int plane)
     vlc_mutex_unlock(&ov->lock);
 }
 
-static void blurayInitOverlay(demux_t *p_demux, int plane, int width, int height)
+static void blurayInitOverlay(demux_t *p_demux, int plane, uint16_t width, uint16_t height)
 {
     demux_sys_t *p_sys = p_demux->p_sys;
 
@@ -2023,7 +2023,7 @@ static void blurayOverlayProc(void *ptr, const BD_OVERLAY *const overlay)
 /*
  * ARGB overlay (BD-J)
  */
-static void blurayInitArgbOverlay(demux_t *p_demux, int plane, int width, int height)
+static void blurayInitArgbOverlay(demux_t *p_demux, int plane, uint16_t width, uint16_t height)
 {
     blurayInitOverlay(p_demux, plane, width, height);
 }


=====================================
modules/access/imem.c
=====================================
@@ -152,10 +152,10 @@ vlc_module_begin()
         change_private()
         change_safe()
 
-    add_integer("imem-width", 0, WIDTH_TEXT, WIDTH_LONGTEXT)
+    add_integer_with_range("imem-width", 0, 0, UINT_MAX, WIDTH_TEXT, WIDTH_LONGTEXT)
         change_private()
         change_safe()
-    add_integer("imem-height", 0, HEIGHT_TEXT, HEIGHT_LONGTEXT)
+    add_integer_with_range("imem-height", 0, 0, UINT_MAX, HEIGHT_TEXT, HEIGHT_LONGTEXT)
         change_private()
         change_safe()
     add_string ("imem-dar", NULL, DAR_TEXT, DAR_LONGTEXT)


=====================================
modules/codec/arib/substext.h
=====================================
@@ -99,8 +99,11 @@ static void SubpictureTextUpdate(subpicture_t *subpic,
         r->p_text = text_segment_New( p_region->psz_text );
         r->i_align  = SUBPICTURE_ALIGN_LEFT | SUBPICTURE_ALIGN_TOP;
 
-        subpic->i_original_picture_width  = p_region->i_planewidth;
-        subpic->i_original_picture_height  = p_region->i_planeheight;
+        if (p_region->i_planewidth > 0 && p_region->i_planeheight > 0)
+        {
+            subpic->i_original_picture_width  = p_region->i_planewidth;
+            subpic->i_original_picture_height  = p_region->i_planeheight;
+        }
 
         r->i_x = p_region->i_charleft - (p_region->i_fontwidth + p_region->i_horint / 2) + p_region->i_charleft_adj;
         r->i_y = p_region->i_charbottom - (p_region->i_fontheight + p_region->i_verint / 2) + p_region->i_charbottom_adj;


=====================================
modules/codec/avcodec/subtitle.c
=====================================
@@ -330,7 +330,7 @@ static subpicture_t *ConvertSubtitle(decoder_t *dec, AVSubtitle *ffsub, vlc_tick
     spu->b_ephemer  = p_sys->b_need_ephemer;
                     /* We only show subtitle for i_stop time only */
 
-    if (avctx->coded_width != 0 && avctx->coded_height != 0) {
+    if (avctx->coded_width > 0 && avctx->coded_height > 0) {
         spu->i_original_picture_width = avctx->coded_width;
         spu->i_original_picture_height = avctx->coded_height;
     } else {


=====================================
modules/codec/dvbsub.c
=====================================
@@ -180,8 +180,8 @@ typedef struct dvbsub_display_s
     uint8_t                 i_id;
     uint8_t                 i_version;
 
-    int                     i_width;
-    int                     i_height;
+    uint16_t                i_width_minus1;
+    uint16_t                i_height_minus1;
 
     bool                    b_windowed;
     /* these values are only relevant if windowed */
@@ -1012,8 +1012,8 @@ static void decode_display_definition( decoder_t *p_dec, bs_t *s, uint16_t i_seg
     p_sys->display.i_version = i_version;
     p_sys->display.b_windowed = bs_read( s, 1 );
     bs_skip( s, 3 ); /* Reserved bits */
-    p_sys->display.i_width = bs_read( s, 16 )+1;
-    p_sys->display.i_height = bs_read( s, 16 )+1;
+    p_sys->display.i_width_minus1 = bs_read( s, 16 );
+    p_sys->display.i_height_minus1 = bs_read( s, 16 );
 
     if( p_sys->display.b_windowed )
     {
@@ -1032,9 +1032,9 @@ static void decode_display_definition( decoder_t *p_dec, bs_t *s, uint16_t i_seg
         /* if not windowed, setup the window variables to good defaults */
         /* not necessary, but to avoid future confusion.. */
         p_sys->display.i_x     = 0;
-        p_sys->display.i_max_x = p_sys->display.i_width-1;
+        p_sys->display.i_max_x = p_sys->display.i_width_minus1;
         p_sys->display.i_y     = 0;
-        p_sys->display.i_max_y = p_sys->display.i_height-1;
+        p_sys->display.i_max_y = p_sys->display.i_height_minus1;
     }
 
     if( i_processed_length != i_segment_length*8 )
@@ -1045,7 +1045,7 @@ static void decode_display_definition( decoder_t *p_dec, bs_t *s, uint16_t i_seg
 
 #ifdef DEBUG_DVBSUB
     msg_Dbg( p_dec, "version: %d, width: %d, height: %d",
-             p_sys->display.i_version, p_sys->display.i_width, p_sys->display.i_height );
+             p_sys->display.i_version, (int)p_sys->display.i_width_minus1+1, (int)p_sys->display.i_height_minus1+1 );
     if( p_sys->display.b_windowed )
         msg_Dbg( p_dec, "xmin: %d, xmax: %d, ymin: %d, ymax: %d",
                  p_sys->display.i_x, p_sys->display.i_max_x, p_sys->display.i_y, p_sys->display.i_max_y );
@@ -1494,8 +1494,8 @@ static subpicture_t *render( decoder_t *p_dec )
     i_base_x = p_sys->i_spu_x;
     i_base_y = p_sys->i_spu_y;
 
-    p_spu->i_original_picture_width = p_sys->display.i_width;
-    p_spu->i_original_picture_height = p_sys->display.i_height;
+    p_spu->i_original_picture_width = (unsigned)p_sys->display.i_width_minus1 + 1;
+    p_spu->i_original_picture_height = (unsigned)p_sys->display.i_height_minus1 + 1;
 
     if( p_sys->display.b_windowed )
     {
@@ -2633,8 +2633,8 @@ static void default_dds_init( decoder_t * p_dec )
 
     /* configure for SD res in case DDS is not present */
     p_sys->display.i_version = 0xff; /* an invalid version so it's always different */
-    p_sys->display.i_width = 720;
-    p_sys->display.i_height = 576;
+    p_sys->display.i_width_minus1 = 720-1;
+    p_sys->display.i_height_minus1 = 576-1;
     p_sys->display.b_windowed = false;
 }
 


=====================================
modules/codec/substext.h
=====================================
@@ -182,7 +182,7 @@ static void SubpictureTextUpdate(subpicture_t *subpic,
         if (!(p_updtregion->flags & UPDT_REGION_FIXED_DONE))
         {
             const float margin_ratio = sys->margin_ratio;
-            const int   margin_h     = margin_ratio * (( r->b_gridmode ) ? (unsigned) subpic->i_original_picture_width
+            const int   margin_h     = margin_ratio * (( r->b_gridmode ) ? subpic->i_original_picture_width
                                                                          : fmt_dst->i_visible_width );
             const int   margin_v     = margin_ratio * fmt_dst->i_visible_height;
 


=====================================
modules/codec/subsusf.c
=====================================
@@ -264,8 +264,11 @@ static subpicture_t *ParseText( decoder_t *p_dec, block_t *p_block )
     p_spu->i_stop = p_block->i_pts + p_block->i_length;
     p_spu->b_ephemer = (p_block->i_length == VLC_TICK_INVALID);
     p_spu->b_absolute = false;
-    p_spu->i_original_picture_width = p_sys->i_original_width;
-    p_spu->i_original_picture_height = p_sys->i_original_height;
+    if (p_sys->i_original_width > 0 && p_sys->i_original_height > 0)
+    {
+        p_spu->i_original_picture_width = p_sys->i_original_width;
+        p_spu->i_original_picture_height = p_sys->i_original_height;
+    }
 
     free( psz_subtitle );
 


=====================================
modules/codec/zvbi.c
=====================================
@@ -486,8 +486,11 @@ static int Decode( decoder_t *p_dec, block_t *p_block )
 
         /* Maintain subtitle position */
         p_spu->p_region->i_y = i_first_row*10;
-        p_spu->i_original_picture_width = p_page.columns*12;
-        p_spu->i_original_picture_height = p_page.rows*10;
+        if (p_page.columns > 0 && p_page.rows > 0)
+        {
+            p_spu->i_original_picture_width = p_page.columns*12;
+            p_spu->i_original_picture_height = p_page.rows*10;
+        }
 
         vbi_draw_vt_page_region( &p_page, ZVBI_PIXFMT_RGBA32,
                           p_spu->p_region->p_picture->p->p_pixels, -1,


=====================================
modules/demux/vobsub.c
=====================================
@@ -97,8 +97,8 @@ typedef struct
     int            i_tracks;
     vobsub_track_t *track;
 
-    int            i_original_frame_width;
-    int            i_original_frame_height;
+    unsigned       i_original_frame_width;
+    unsigned       i_original_frame_height;
     bool           b_palette;
     uint32_t       palette[VIDEO_PALETTE_CLUT_COUNT];
 } demux_sys_t;
@@ -149,8 +149,8 @@ static int Open ( vlc_object_t *p_this )
     p_sys->track = malloc( sizeof( vobsub_track_t ) );
     if( unlikely( !p_sys->track ) )
         goto error;
-    p_sys->i_original_frame_width = -1;
-    p_sys->i_original_frame_height = -1;
+    p_sys->i_original_frame_width = 0;
+    p_sys->i_original_frame_height = 0;
     p_sys->b_palette = false;
 
     /* Load the whole file */
@@ -480,7 +480,7 @@ static int ParseVobSubIDX( demux_t *p_demux )
             if( vobsub_size_parse( line, &p_sys->i_original_frame_width,
                                    &p_sys->i_original_frame_height ) == VLC_SUCCESS )
             {
-                msg_Dbg( p_demux, "original frame size: %dx%d", p_sys->i_original_frame_width, p_sys->i_original_frame_height );
+                msg_Dbg( p_demux, "original frame size: %ux%u", p_sys->i_original_frame_width, p_sys->i_original_frame_height );
             }
             else
             {


=====================================
modules/demux/vobsub.h
=====================================
@@ -59,11 +59,11 @@ static inline int vobsub_palette_parse( const char *psz_buf, uint32_t *pu_palett
 }
 
 static inline int vobsub_size_parse( const char *psz_buf,
-                                     int *pi_original_frame_width,
-                                     int *pi_original_frame_height )
+                                     unsigned *pi_original_frame_width,
+                                     unsigned *pi_original_frame_height )
 {
-    int w, h;
-    if( sscanf( psz_buf, "size: %dx%d", &w, &h ) == 2 )
+    unsigned w, h;
+    if( sscanf( psz_buf, "size: %ux%u", &w, &h ) == 2 )
     {
         *pi_original_frame_width = w;
         *pi_original_frame_height = h;
@@ -92,7 +92,7 @@ static inline void vobsub_extra_parse(vlc_object_t *o, subs_format_t *subs,
                             &subs->spu.i_original_frame_width,
                             &subs->spu.i_original_frame_height ) == VLC_SUCCESS )
     {
-        msg_Dbg( o, "original frame size: %dx%d",
+        msg_Dbg( o, "original frame size: %ux%u",
                     subs->spu.i_original_frame_width,
                     subs->spu.i_original_frame_height );
     }


=====================================
modules/spu/mosaic.c
=====================================
@@ -65,7 +65,7 @@ typedef struct
     int i_position;           /* Mosaic positioning method */
     bool b_ar;          /* Do we keep the aspect ratio ? */
     bool b_keep;        /* Do we keep the original picture format ? */
-    int i_width, i_height;    /* Mosaic height and width */
+    unsigned i_width, i_height; /* Mosaic height and width */
     int i_cols, i_rows;       /* Mosaic rows and cols */
     int i_align;              /* Mosaic alignment in background video */
     int i_xoffset, i_yoffset; /* Top left corner offset */
@@ -182,9 +182,9 @@ vlc_module_begin ()
     add_integer_with_range( CFG_PREFIX "alpha", 255, 0, 255,
                             ALPHA_TEXT, ALPHA_LONGTEXT )
 
-    add_integer_with_range( CFG_PREFIX "height", 100, 0, INT_MAX,
+    add_integer_with_range( CFG_PREFIX "height", 100, 0, UINT_MAX,
                  HEIGHT_TEXT, HEIGHT_LONGTEXT )
-    add_integer_with_range( CFG_PREFIX "width", 100, 0, INT_MAX,
+    add_integer_with_range( CFG_PREFIX "width", 100, 0, UINT_MAX,
                  WIDTH_TEXT, WIDTH_LONGTEXT )
 
     add_integer_with_range( CFG_PREFIX "align", 5, 0, 10,
@@ -761,16 +761,16 @@ static int MosaicCallback( vlc_object_t *p_this, char const *psz_var,
     else if( VAR_IS( "width" ) )
     {
         vlc_mutex_lock( &p_sys->lock );
-        msg_Dbg( p_this, "changing width from %dpx to %dpx",
-                         p_sys->i_width, (int)newval.i_int );
+        msg_Dbg( p_this, "changing width from %upx to %upx",
+                         p_sys->i_width, (unsigned)newval.i_int );
         p_sys->i_width = newval.i_int;
         vlc_mutex_unlock( &p_sys->lock );
     }
     else if( VAR_IS( "xoffset" ) )
     {
         vlc_mutex_lock( &p_sys->lock );
-        msg_Dbg( p_this, "changing x offset from %dpx to %dpx",
-                         p_sys->i_xoffset, (int)newval.i_int );
+        msg_Dbg( p_this, "changing x offset from %upx to %upx",
+                         p_sys->i_xoffset, (unsigned)newval.i_int );
         p_sys->i_xoffset = newval.i_int;
         vlc_mutex_unlock( &p_sys->lock );
     }


=====================================
src/video_output/vout_subpictures.c
=====================================
@@ -316,8 +316,8 @@ static filter_t *SpuRenderCreateAndLoadScale(vlc_object_t *object,
 
 static int SpuRenderText(spu_t *spu,
                           subpicture_region_t *region,
-                          int i_original_width,
-                          int i_original_height,
+                          unsigned i_original_width,
+                          unsigned i_original_height,
                           const vlc_fourcc_t *chroma_list)
 {
     spu_private_t *sys = spu->p;
@@ -360,16 +360,16 @@ static int SpuRenderText(spu_t *spu,
 
 #define SCALE_UNIT (10000)
 typedef struct {
-    int w;
-    int h;
+    unsigned w;
+    unsigned h;
 } spu_scale_t;
 
-static spu_scale_t spu_scale_create(int w, int h)
+static spu_scale_t spu_scale_create(unsigned w, unsigned h)
 {
     spu_scale_t s = { .w = w, .h = h };
-    if (s.w <= 0)
+    if (s.w == 0)
         s.w = SCALE_UNIT;
-    if (s.h <= 0)
+    if (s.h == 0)
         s.h = SCALE_UNIT;
     return s;
 }
@@ -377,7 +377,7 @@ static spu_scale_t spu_scale_unit(void)
 {
     return spu_scale_create(SCALE_UNIT, SCALE_UNIT);
 }
-static spu_scale_t spu_scale_createq(int64_t wn, int64_t wd, int64_t hn, int64_t hd)
+static spu_scale_t spu_scale_createq(uint64_t wn, uint64_t wd, uint64_t hn, uint64_t hd)
 {
     return spu_scale_create(wn * SCALE_UNIT / wd,
                             hn * SCALE_UNIT / hd);
@@ -1183,11 +1183,11 @@ static subpicture_t *SpuRenderSubpictures(spu_t *spu,
         if (!subpic->p_region)
             continue;
 
-        if (subpic->i_original_picture_width  <= 0 ||
-            subpic->i_original_picture_height <= 0) {
+        if (subpic->i_original_picture_width  == 0 ||
+            subpic->i_original_picture_height == 0) {
             if (subpic->i_original_picture_width  > 0 ||
                 subpic->i_original_picture_height > 0)
-                msg_Err(spu, "original picture size %dx%d is unsupported",
+                msg_Err(spu, "original picture size %ux%u is unsupported",
                          subpic->i_original_picture_width,
                          subpic->i_original_picture_height);
             else
@@ -1197,8 +1197,8 @@ static subpicture_t *SpuRenderSubpictures(spu_t *spu,
             subpic->i_original_picture_height = fmt_src->i_visible_height;
         }
 
-        const int i_original_width = subpic->i_original_picture_width;
-        const int i_original_height = subpic->i_original_picture_height;
+        const unsigned i_original_width = subpic->i_original_picture_width;
+        const unsigned i_original_height = subpic->i_original_picture_height;
 
         /* Render all regions
          * We always transform non absolute subtitle into absolute one on the
@@ -1224,14 +1224,13 @@ static subpicture_t *SpuRenderSubpictures(spu_t *spu,
              * FIXME The current scaling ensure that the heights match, the width being
              * cropped.
              */
-            spu_scale_t scale = spu_scale_createq((int64_t)fmt_dst->i_visible_height         * fmt_dst->i_sar_den * region_fmt.i_sar_num,
-                                                  (int64_t)subpic->i_original_picture_height * fmt_dst->i_sar_num * region_fmt.i_sar_den,
+            spu_scale_t scale = spu_scale_createq((uint64_t)fmt_dst->i_visible_height         * fmt_dst->i_sar_den * region_fmt.i_sar_num,
+                                                  (uint64_t)subpic->i_original_picture_height * fmt_dst->i_sar_num * region_fmt.i_sar_den,
                                                   fmt_dst->i_visible_height,
                                                   subpic->i_original_picture_height);
 
             /* Check scale validity */
-            if (scale.w <= 0 || scale.h <= 0)
-                continue;
+            assert(scale.w != 0 && scale.h != 0);
 
             const bool do_external_scale = external_scale && region->fmt.i_chroma != VLC_CODEC_TEXT;
             spu_scale_t virtual_scale = external_scale ? (spu_scale_t){ SCALE_UNIT, SCALE_UNIT } : scale;
@@ -1483,11 +1482,11 @@ static void spu_PrerenderText(spu_t *spu, subpicture_t *p_subpic,
                               video_format_t *fmtsrc, video_format_t *fmtdst,
                               vlc_fourcc_t *chroma_list)
 {
-    if (p_subpic->i_original_picture_width  <= 0 ||
-        p_subpic->i_original_picture_height <= 0) {
+    if (p_subpic->i_original_picture_width  == 0 ||
+        p_subpic->i_original_picture_height == 0) {
         if (p_subpic->i_original_picture_width  > 0 ||
             p_subpic->i_original_picture_height > 0)
-            msg_Err(spu, "original picture size %dx%d is unsupported",
+            msg_Err(spu, "original picture size %ux%u is unsupported",
                      p_subpic->i_original_picture_width,
                      p_subpic->i_original_picture_height);
         else
@@ -1501,8 +1500,8 @@ static void spu_PrerenderText(spu_t *spu, subpicture_t *p_subpic,
     subpicture_Update(p_subpic, fmtsrc, fmtdst,
                       p_subpic->b_subtitle ? p_subpic->i_start : vlc_tick_now());
 
-    const int i_original_picture_width = p_subpic->i_original_picture_width;
-    const int i_original_picture_height = p_subpic->i_original_picture_height;
+    const unsigned i_original_picture_width = p_subpic->i_original_picture_width;
+    const unsigned i_original_picture_height = p_subpic->i_original_picture_height;
 
     subpicture_region_t *region;
     for (region = p_subpic->p_region; region != NULL; region = region->p_next)



View it on GitLab: https://code.videolan.org/videolan/vlc/-/compare/d38e13adf24b881292b1edb5c83bf47930ae196b...ef763e7b1bb5837825805e8f0af8771f6099ad78

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