[vlc-commits] demux: webvtt: fix memstream usage
Francois Cartegnie
git at videolan.org
Wed Jan 15 16:54:50 CET 2020
vlc/vlc-3.0 | branch: master | Francois Cartegnie <fcvlcdev at free.fr> | Wed Jan 15 16:22:37 2020 +0100| [a9b4ad073aa476a48a010db81a4aace14f96d619] | committer: Francois Cartegnie
demux: webvtt: fix memstream usage
refs #21326
(cherry picked from commit 04fc9a272cf821455a12d7d2855bd226375d2d54)
> http://git.videolan.org/gitweb.cgi/vlc/vlc-3.0.git/?a=commit;h=a9b4ad073aa476a48a010db81a4aace14f96d619
---
modules/demux/webvtt.c | 44 +++++++++++++++++++++++++++++---------------
1 file changed, 29 insertions(+), 15 deletions(-)
diff --git a/modules/demux/webvtt.c b/modules/demux/webvtt.c
index ae672f9695..11b978a41e 100644
--- a/modules/demux/webvtt.c
+++ b/modules/demux/webvtt.c
@@ -138,26 +138,32 @@ static block_t *ConvertWEBVTT( const webvtt_cue_t *p_cue, bool b_continued )
return NULL;
}
-static void memstream_Append( struct vlc_memstream *ms, const char *psz )
+struct memstream_wrap
{
- if( ms->stream != NULL )
+ struct vlc_memstream memstream;
+ bool b_opened;
+};
+
+static void memstream_Append( struct memstream_wrap *mw, const char *psz )
+{
+ if( mw->b_opened )
{
- vlc_memstream_puts( ms, psz );
- vlc_memstream_putc( ms, '\n' );
+ vlc_memstream_puts( &mw->memstream, psz );
+ vlc_memstream_putc( &mw->memstream, '\n' );
}
}
-static void memstream_Grab( struct vlc_memstream *ms, void **pp, size_t *pi )
+static void memstream_Grab( struct memstream_wrap *mw, void **pp, size_t *pi )
{
- if( ms->stream != NULL && vlc_memstream_close( ms ) == VLC_SUCCESS )
+ if( mw->b_opened && vlc_memstream_close( &mw->memstream ) == VLC_SUCCESS )
{
- if( ms->length == 0 )
+ if( mw->memstream.length == 0 )
{
- free( ms->ptr );
- ms->ptr = NULL;
+ free( mw->memstream.ptr );
+ mw->memstream.ptr = NULL;
}
- *pp = ms->ptr;
- *pi = ms->length;
+ *pp = mw->memstream.ptr;
+ *pi = mw->memstream.length;
}
}
@@ -167,7 +173,7 @@ static void memstream_Grab( struct vlc_memstream *ms, void **pp, size_t *pi )
struct callback_ctx
{
demux_t *p_demux;
- struct vlc_memstream regions, styles;
+ struct memstream_wrap regions, styles;
bool b_ordered;
};
@@ -379,8 +385,8 @@ static int ReadWEBVTT( demux_t *p_demux )
if( p_parser == NULL )
return VLC_EGENERIC;
- (void) vlc_memstream_open( &ctx.regions );
- (void) vlc_memstream_open( &ctx.styles );
+ ctx.regions.b_opened = !vlc_memstream_open( &ctx.regions.memstream );
+ ctx.styles.b_opened = !vlc_memstream_open( &ctx.styles.memstream );
char *psz_line;
while( (psz_line = vlc_stream_ReadLine( p_demux->s )) )
@@ -412,7 +418,15 @@ static void MakeExtradata( demux_sys_t *p_sys, void **p_extra, size_t *pi_extra
p_sys->regions_headers.i_data );
vlc_memstream_write( &extradata, p_sys->styles_headers.p_data,
p_sys->styles_headers.i_data );
- memstream_Grab( &extradata, p_extra, pi_extra );
+ if( vlc_memstream_close( &extradata ) == VLC_SUCCESS )
+ {
+ if( extradata.length )
+ {
+ *p_extra = extradata.ptr;
+ *pi_extra = extradata.length;
+ }
+ else free( extradata.ptr );
+ }
}
/*****************************************************************************
More information about the vlc-commits
mailing list