[vlc-commits] encoder: webvtt: escape double newlines
Francois Cartegnie
git at videolan.org
Thu Feb 1 15:42:55 CET 2018
vlc | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Thu Feb 1 15:18:31 2018 +0100| [67add513f0fee37e480aebaff9af94e774820706] | committer: Francois Cartegnie
encoder: webvtt: escape double newlines
> http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=67add513f0fee37e480aebaff9af94e774820706
---
modules/codec/webvtt/encvtt.c | 30 +++++++++++++++++++++++++++++-
1 file changed, 29 insertions(+), 1 deletion(-)
diff --git a/modules/codec/webvtt/encvtt.c b/modules/codec/webvtt/encvtt.c
index 333363fc1e..8f6e8f380c 100644
--- a/modules/codec/webvtt/encvtt.c
+++ b/modules/codec/webvtt/encvtt.c
@@ -51,6 +51,31 @@ void webvtt_CloseEncoder( vlc_object_t *p_this )
(void)p_this;
}
+static void WriteText( const char *psz, bo_t *box, char *c_last )
+{
+ /* We need to break any double newline sequence
+ * in or over segments */
+ while(*psz)
+ {
+ const char *p = strchr( psz, '\n' );
+ if( p )
+ {
+ bo_add_mem( box, p - psz, psz );
+ if( *c_last == '\n' )
+ bo_add_8( box, '!' ); /* Add space */
+ bo_add_8( box, '\n' );
+ *c_last = '\n';
+ psz = p + 1;
+ }
+ else
+ {
+ size_t len = strlen(psz);
+ bo_add_mem( box, len, psz );
+ *c_last = (len > 0) ? psz[len - 1] : '\0';
+ break;
+ }
+ }
+}
static block_t *Encode( encoder_t *p_enc, subpicture_t *p_spu )
{
@@ -81,6 +106,7 @@ static block_t *Encode( encoder_t *p_enc, subpicture_t *p_spu )
bo_add_32be( &box, 0 );
bo_add_fourcc( &box, "payl" );
+ char prevchar = '\0';
/* This should already be UTF-8 encoded, so not much effort... */
for( const text_segment_t *p_segment = p_region->p_text;
p_segment; p_segment = p_segment->p_next )
@@ -101,7 +127,9 @@ static block_t *Encode( encoder_t *p_enc, subpicture_t *p_spu )
bo_add_mem( &box, 3, "<i>" );
}
}
- bo_add_mem( &box, strlen(p_segment->psz_text), p_segment->psz_text );
+
+ WriteText( p_segment->psz_text, &box, &prevchar );
+
if( style && style->i_features )
{
if( style->i_features & STYLE_HAS_FLAGS )
More information about the vlc-commits
mailing list