Commit 41dc1ed0 authored by Hugo Beauzée-Luyssen's avatar Hugo Beauzée-Luyssen

mjpeg: Try to handle misformed streams.

Cameras such as D-Link's DCS-932L don't provide the first video
boundary.
parent 26303bdd
......@@ -192,10 +192,37 @@ 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 )
{
/* 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
{
i_pos = *p_sys->p_peek == '-' ? 2 : 4;
psz_line = GetLine( p_demux, &i_pos );
if( NULL == psz_line )
......@@ -221,6 +248,7 @@ static bool CheckMimeHeader( demux_t *p_demux, int *p_header_size )
}
free( psz_line );
}
}
psz_line = GetLine( p_demux, &i_pos );
while( psz_line && *psz_line )
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment