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
...@@ -193,33 +193,61 @@ static bool CheckMimeHeader( demux_t *p_demux, int *p_header_size ) ...@@ -193,33 +193,61 @@ static bool CheckMimeHeader( demux_t *p_demux, int *p_header_size )
if( strncmp( (char *)p_sys->p_peek, "--", 2 ) != 0 if( strncmp( (char *)p_sys->p_peek, "--", 2 ) != 0
&& strncmp( (char *)p_sys->p_peek, "\r\n--", 4 ) != 0 ) && strncmp( (char *)p_sys->p_peek, "\r\n--", 4 ) != 0 )
{ {
*p_header_size = 0; /* Some broken stream may lack the first boundary */
return false; if ( p_sys->psz_separator == NULL )
} {
i_pos = *p_sys->p_peek == '-' ? 2 : 4; msg_Warn( p_demux, "Misformed stream. Trying to work around");
psz_line = GetLine( p_demux, &i_pos ); char *content_type = stream_ContentType( p_demux->s );
if( NULL == psz_line ) if ( content_type == NULL )
{ return false;
msg_Err( p_demux, "no EOL" ); const char* boundary = strstr( content_type, "boundary=--" );
*p_header_size = -3; if ( boundary != NULL )
return false; {
} p_sys->psz_separator = strdup( boundary + strlen( "boundary=--" ) );
msg_Dbg( p_demux, "Video boundary extracted from Content-Type: %s", p_sys->psz_separator );
/* Read the separator and remember it if not yet stored */ free( content_type );
if( p_sys->psz_separator == NULL ) /* Skip to HTTP header parsing as there's no boundary to extract
{ * from the stream */
p_sys->psz_separator = psz_line; }
msg_Dbg( p_demux, "Multipart MIME detected, using separator: %s", else
p_sys->psz_separator ); {
free( content_type );
return false;
}
}
else
{
*p_header_size = 0;
return false;
}
} }
else 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, msg_Err( p_demux, "no EOL" );
p_sys->psz_separator ); *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 ); psz_line = GetLine( p_demux, &i_pos );
......
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