[vlc-devel] [PATCH 2/5] codecs: subsusf: flatten karaoke string

Francois Cartegnie fcvlcdev at free.fr
Tue Jul 2 11:05:30 CEST 2019


was not displaying at all...
---
 modules/codec/subsusf.c | 43 ++++++++++++++++++++++++++++-------------
 1 file changed, 30 insertions(+), 13 deletions(-)

diff --git a/modules/codec/subsusf.c b/modules/codec/subsusf.c
index c02c52b52f..20eab12ed2 100644
--- a/modules/codec/subsusf.c
+++ b/modules/codec/subsusf.c
@@ -100,6 +100,7 @@ typedef struct
 
 static int           DecodeBlock   ( decoder_t *, block_t * );
 static char         *CreatePlainText( char * );
+static char         *StripTags( char *psz_subtitle );
 static int           ParseImageAttachments( decoder_t *p_dec );
 
 static subpicture_t        *ParseText     ( decoder_t *, block_t * );
@@ -850,21 +851,37 @@ static subpicture_region_t *ParseUSFString( decoder_t *p_dec,
                 {
                     subpicture_region_t  *p_text_region;
 
-                    psz_end += strcspn( psz_end, ">" ) + 1;
-
-                    p_text_region = CreateTextRegion( p_dec,
-                                                      psz_subtitle,
-                                                      p_sys->i_align );
-
-                    if( !p_region_first )
+                    char *psz_flat = NULL;
+                    char *psz_knodes = strndup( &psz_subtitle[9], psz_end - &psz_subtitle[9] );
+                    if( psz_knodes )
                     {
-                        p_region_first = p_region_upto = p_text_region;
-                    }
-                    else if( p_text_region )
-                    {
-                        p_region_upto->p_next = p_text_region;
-                        p_region_upto = p_region_upto->p_next;
+                        /* remove timing <k> tags */
+                        psz_flat = CreatePlainText( psz_knodes );
+                        free( psz_knodes );
+                        if( psz_flat )
+                        {
+                            p_text_region = CreateTextRegion( p_dec,
+                                                              psz_flat,
+                                                              p_sys->i_align );
+                            if( p_text_region )
+                            {
+                                free( p_text_region->p_text->psz_text );
+                                p_text_region->p_text->psz_text = psz_flat;
+                                if( !p_region_first )
+                                {
+                                    p_region_first = p_region_upto = p_text_region;
+                                }
+                                else if( p_text_region )
+                                {
+                                    p_region_upto->p_next = p_text_region;
+                                    p_region_upto = p_region_upto->p_next;
+                                }
+                            }
+                            else free( psz_flat );
+                        }
                     }
+
+                    psz_end += strcspn( psz_end, ">" ) + 1;
                 }
             }
             else if(( !strncasecmp( psz_subtitle, "<image ", 7 )) ||
-- 
2.20.1



More information about the vlc-devel mailing list