X-Git-Url: https://git.sesse.net/?a=blobdiff_plain;f=modules%2Fdemux%2Fmjpeg.c;h=8315ca2e12ccf75426074c2317cf975bd1103ac2;hb=a18bc8ed46998dd6d3cef5af15f89cf8c9c10e0a;hp=afdc484d39f26277726ed2cce81ffb57acc5ff84;hpb=1cdbc7b6f2294024815f3d28128c8a7bf21156cb;p=vlc diff --git a/modules/demux/mjpeg.c b/modules/demux/mjpeg.c index afdc484d39..8315ca2e12 100644 --- a/modules/demux/mjpeg.c +++ b/modules/demux/mjpeg.c @@ -35,6 +35,7 @@ #include #include #include +#include "mxpeg_helper.h" /***************************************************************************** * Module descriptor @@ -172,7 +173,7 @@ static char* GetLine( demux_t *p_demux, int *p_pos ) static bool CheckMimeHeader( demux_t *p_demux, int *p_header_size ) { bool b_jpeg = false; - int i_pos; + int i_pos = 0; char *psz_line; char *p_ch; demux_sys_t *p_sys = p_demux->p_sys; @@ -192,33 +193,61 @@ static bool CheckMimeHeader( demux_t *p_demux, int *p_header_size ) if( strncmp( (char *)p_sys->p_peek, "--", 2 ) != 0 && strncmp( (char *)p_sys->p_peek, "\r\n--", 4 ) != 0 ) { - *p_header_size = 0; - return false; - } - i_pos = *p_sys->p_peek == '-' ? 2 : 4; - psz_line = GetLine( p_demux, &i_pos ); - if( NULL == psz_line ) - { - msg_Err( p_demux, "no EOL" ); - *p_header_size = -3; - return false; - } - - /* Read the separator and remember it if not yet stored */ - if( p_sys->psz_separator == NULL ) - { - p_sys->psz_separator = psz_line; - msg_Dbg( p_demux, "Multipart MIME detected, using separator: %s", - p_sys->psz_separator ); + /* Some broken stream may lack the first boundary */ + if ( p_sys->psz_separator == NULL ) + { + msg_Warn( p_demux, "Misformed stream. Trying to work around"); + char *content_type = stream_ContentType( p_demux->s ); + if ( content_type == NULL ) + return false; + const char* boundary = strstr( content_type, "boundary=--" ); + if ( boundary != NULL ) + { + p_sys->psz_separator = strdup( boundary + strlen( "boundary=--" ) ); + msg_Dbg( p_demux, "Video boundary extracted from Content-Type: %s", p_sys->psz_separator ); + free( content_type ); + /* Skip to HTTP header parsing as there's no boundary to extract + * from the stream */ + } + else + { + free( content_type ); + return false; + } + } + else + { + *p_header_size = 0; + return false; + } } else { - if( strcmp( psz_line, p_sys->psz_separator ) ) + i_pos = *p_sys->p_peek == '-' ? 2 : 4; + psz_line = GetLine( p_demux, &i_pos ); + if( NULL == psz_line ) { - msg_Warn( p_demux, "separator %s does not match %s", psz_line, - p_sys->psz_separator ); + msg_Err( p_demux, "no EOL" ); + *p_header_size = -3; + return false; + } + + /* Read the separator and remember it if not yet stored */ + if( p_sys->psz_separator == NULL ) + { + p_sys->psz_separator = psz_line; + msg_Dbg( p_demux, "Multipart MIME detected, using separator: %s", + p_sys->psz_separator ); + } + else + { + if( strcmp( psz_line, p_sys->psz_separator ) ) + { + msg_Warn( p_demux, "separator %s does not match %s", psz_line, + p_sys->psz_separator ); + } + free( psz_line ); } - free( psz_line ); } psz_line = GetLine( p_demux, &i_pos ); @@ -316,6 +345,12 @@ static int Open( vlc_object_t * p_this ) p_sys->psz_separator = NULL; p_sys->i_frame_size_estimate = 15 * 1024; + if( IsMxpeg( p_demux->s ) && !p_demux->b_force ) + { + // let avformat handle this case + goto error; + } + b_matched = CheckMimeHeader( p_demux, &i_size); if( b_matched ) {