/*****************************************************************************
* mjpeg.c : demuxes mjpeg webcam http streams
*****************************************************************************
- * Copyright (C) 2004 the VideoLAN team
+ * Copyright (C) 2004 VLC authors and VideoLAN
* $Id$
*
* Authors: Henry Jen (slowhog) <henryjen@ztune.net>
* Sigmund Augdal (Dnumgis)
* Laurent Aimar <fenrir@via.ecp.fr>
*
- * This program is free software; you can redistribute it and/or modify
- * it under the terms of the GNU General Public License as published by
- * the Free Software Foundation; either version 2 of the License, or
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation; either version 2.1 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- * GNU General Public License for more details.
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
*
- * You should have received a copy of the GNU General Public License
- * along with this program; if not, write to the Free Software
- * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.
*****************************************************************************/
/*****************************************************************************
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, "Malformed 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;
- }
+ *p_header_size = 0;
+ return false;
}
else
{
p_sys->psz_separator = NULL;
p_sys->i_frame_size_estimate = 15 * 1024;
+ char *content_type = stream_ContentType( p_demux->s );
+ if ( content_type )
+ {
+ //FIXME: this is not fully match to RFC
+ char* boundary = strstr( content_type, "boundary=" );
+ if( boundary )
+ {
+ boundary += strlen( "boundary=" );
+ size_t len = strlen( boundary );
+ if( len > 2 && boundary[0] == '"'
+ && boundary[len-1] == '"' )
+ {
+ boundary[len-1] = '\0';
+ boundary++;
+ }
+ p_sys->psz_separator = strdup( boundary );
+ if( !p_sys->psz_separator )
+ {
+ free( content_type );
+ goto error;
+ }
+ }
+ free( content_type );
+ }
+
b_matched = CheckMimeHeader( p_demux, &i_size);
if( b_matched )
{
return VLC_SUCCESS;
error:
+ free( p_sys->psz_separator );
free( p_sys );
return VLC_EGENERIC;
}
if( i_size > 0 )
{
- stream_Read( p_demux->s, NULL, i_size );
+ if( stream_Read( p_demux->s, NULL, i_size ) != i_size )
+ return 0;
}
else if( i_size < 0 )
{
}
}
- if( !strncmp( p_sys->psz_separator, (char *)(p_sys->p_peek + i + 2),
- strlen( p_sys->psz_separator ) ) )
+ /* Handle old and new style of separators */
+ if (!strncmp(p_sys->psz_separator, (char *)(p_sys->p_peek + i + 2),
+ strlen( p_sys->psz_separator ))
+ || ((strlen(p_sys->psz_separator) > 4)
+ && !strncmp(p_sys->psz_separator, "--", 2)
+ && !strncmp(p_sys->psz_separator, (char *)(p_sys->p_peek + i),
+ strlen( p_sys->psz_separator))))
{
break;
}