Commit 626d8bea authored by Laurent Aimar's avatar Laurent Aimar

* stream_output.* : added a flags variable to sout_buffer_t, allowing to

mark headers.
 * httpd : added a way to use stream header, and changed the way that
stream data are stored (allow better client handling).
 * http : use stream header, and add mime type detection by looking
at file extention (could be improved).
 * ogg: fixed a segfault when removing a stream, mark header.
parent 08a2b6ba
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* httpd.h * httpd.h
***************************************************************************** *****************************************************************************
* Copyright (C) 2001-2003 VideoLAN * Copyright (C) 2001-2003 VideoLAN
* $Id: httpd.h,v 1.1 2003/02/23 19:05:22 fenrir Exp $ * $Id: httpd.h,v 1.2 2003/02/25 17:17:43 fenrir Exp $
* *
* Authors: Laurent Aimar <fenrir@via.ecp.fr> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* *
...@@ -57,6 +57,9 @@ struct httpd_t ...@@ -57,6 +57,9 @@ struct httpd_t
int (*pf_send_stream) ( httpd_t *, int (*pf_send_stream) ( httpd_t *,
httpd_stream_t *, httpd_stream_t *,
uint8_t *, int ); uint8_t *, int );
int (*pf_header_stream) ( httpd_t *,
httpd_stream_t *,
uint8_t *, int );
void (*pf_unregister_stream) ( httpd_t *, httpd_stream_t * ); void (*pf_unregister_stream) ( httpd_t *, httpd_stream_t * );
}; };
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* stream_output.h : stream output module * stream_output.h : stream output module
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * Copyright (C) 2002 VideoLAN
* $Id: stream_output.h,v 1.7 2003/02/24 11:00:54 fenrir Exp $ * $Id: stream_output.h,v 1.8 2003/02/25 17:17:43 fenrir Exp $
* *
* Authors: Christophe Massiot <massiot@via.ecp.fr> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* Laurent Aimar <fenrir@via.ecp.fr> * Laurent Aimar <fenrir@via.ecp.fr>
...@@ -36,6 +36,7 @@ ...@@ -36,6 +36,7 @@
* i_size: size of valid data * i_size: size of valid data
* *
*/ */
#define SOUT_BUFFER_FLAGS_HEADER 0x0001
struct sout_buffer_t struct sout_buffer_t
{ {
size_t i_allocated_size; size_t i_allocated_size;
...@@ -50,6 +51,7 @@ struct sout_buffer_t ...@@ -50,6 +51,7 @@ struct sout_buffer_t
mtime_t i_dts; mtime_t i_dts;
mtime_t i_pts; mtime_t i_pts;
uint32_t i_flags;
int i_bitrate; int i_bitrate;
struct sout_buffer_t *p_next; struct sout_buffer_t *p_next;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* http.c * http.c
***************************************************************************** *****************************************************************************
* Copyright (C) 2001-2003 VideoLAN * Copyright (C) 2001-2003 VideoLAN
* $Id: http.c,v 1.1 2003/02/23 19:05:22 fenrir Exp $ * $Id: http.c,v 1.2 2003/02/25 17:17:43 fenrir Exp $
* *
* Authors: Laurent Aimar <fenrir@via.ecp.fr> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* *
...@@ -66,8 +66,59 @@ struct sout_access_out_sys_t ...@@ -66,8 +66,59 @@ struct sout_access_out_sys_t
/* stream */ /* stream */
httpd_stream_t *p_httpd_stream; httpd_stream_t *p_httpd_stream;
/* gather header from stream */
int i_header_allocated;
int i_header_size;
uint8_t *p_header;
vlc_bool_t b_header_complete;
}; };
static struct
{
char *psz_ext;
char *psz_mime;
} http_mime[] =
{
{ ".avi", "video/avi" },
{ ".asf", "video/x-ms-asf" },
{ ".m1a", "audio/mpeg" },
{ ".m2a", "audio/mpeg" },
{ ".m1v", "video/mpeg" },
{ ".m2v", "video/mpeg" },
{ ".mp2", "audio/mpeg" },
{ ".mp3", "audio/mpeg" },
{ ".mpa", "audio/mpeg" },
{ ".mpg", "video/mpeg" },
{ ".mpeg", "video/mpeg" },
{ ".mpe", "video/mpeg" },
{ ".mov", "video/quicktime" },
{ ".moov", "video/quicktime" },
{ ".ogg", "application/ogg" },
{ ".ogm", "application/ogg" },
{ ".wav", "audio/wav" },
{ NULL, NULL }
};
static char *GetMime( char *psz_name )
{
char *psz_ext;
psz_ext = strrchr( psz_name, '.' );
if( psz_ext )
{
int i;
for( i = 0; http_mime[i].psz_ext != NULL ; i++ )
{
if( !strcmp( http_mime[i].psz_ext, psz_ext ) )
{
return( http_mime[i].psz_mime );
}
}
}
return( "application/octet-stream" );
}
/***************************************************************************** /*****************************************************************************
* Open: open the file * Open: open the file
*****************************************************************************/ *****************************************************************************/
...@@ -165,7 +216,8 @@ static int Open( vlc_object_t *p_this ) ...@@ -165,7 +216,8 @@ static int Open( vlc_object_t *p_this )
p_sys->p_httpd_stream = p_sys->p_httpd_stream =
p_sys->p_httpd->pf_register_stream( p_sys->p_httpd, p_sys->p_httpd->pf_register_stream( p_sys->p_httpd,
psz_file_name, "application/x-octet_stream", psz_file_name,
GetMime( psz_file_name ),
NULL, NULL ); NULL, NULL );
if( !p_sys->p_httpd_stream ) if( !p_sys->p_httpd_stream )
...@@ -181,6 +233,11 @@ static int Open( vlc_object_t *p_this ) ...@@ -181,6 +233,11 @@ static int Open( vlc_object_t *p_this )
return( VLC_EGENERIC ); return( VLC_EGENERIC );
} }
p_sys->i_header_allocated = 1024;
p_sys->i_header_size = 0;
p_sys->p_header = malloc( p_sys->i_header_allocated );
p_sys->b_header_complete = VLC_FALSE;
p_access->pf_write = Write; p_access->pf_write = Write;
p_access->pf_seek = Seek; p_access->pf_seek = Seek;
...@@ -200,6 +257,8 @@ static void Close( vlc_object_t * p_this ) ...@@ -200,6 +257,8 @@ static void Close( vlc_object_t * p_this )
httpd_Release( p_sys->p_httpd ); httpd_Release( p_sys->p_httpd );
FREE( p_sys->p_header );
msg_Info( p_access, "Close" ); msg_Info( p_access, "Close" );
free( p_sys ); free( p_sys );
...@@ -217,6 +276,34 @@ static int Write( sout_access_out_t *p_access, sout_buffer_t *p_buffer ) ...@@ -217,6 +276,34 @@ static int Write( sout_access_out_t *p_access, sout_buffer_t *p_buffer )
{ {
sout_buffer_t *p_next; sout_buffer_t *p_next;
if( p_buffer->i_flags & SOUT_BUFFER_FLAGS_HEADER )
{
/* gather header */
if( p_sys->b_header_complete )
{
/* free previously gathered header */
p_sys->i_header_size = 0;
p_sys->b_header_complete = VLC_FALSE;
}
if( p_buffer->i_size + p_sys->i_header_size > p_sys->i_header_allocated )
{
p_sys->i_header_allocated = p_buffer->i_size + p_sys->i_header_size + 1024;
p_sys->p_header = realloc( p_sys->p_header, p_sys->i_header_allocated );
}
memcpy( &p_sys->p_header[p_sys->i_header_size],
p_buffer->p_buffer,
p_buffer->i_size );
p_sys->i_header_size += p_buffer->i_size;
}
else if( !p_sys->b_header_complete )
{
p_sys->b_header_complete = VLC_TRUE;
p_sys->p_httpd->pf_header_stream( p_sys->p_httpd,
p_sys->p_httpd_stream,
p_sys->p_header, p_sys->i_header_size );
}
/* send data */
i_err = p_sys->p_httpd->pf_send_stream( p_sys->p_httpd, p_sys->p_httpd_stream, i_err = p_sys->p_httpd->pf_send_stream( p_sys->p_httpd, p_sys->p_httpd_stream,
p_buffer->p_buffer, p_buffer->i_size ); p_buffer->p_buffer, p_buffer->i_size );
...@@ -229,6 +316,7 @@ static int Write( sout_access_out_t *p_access, sout_buffer_t *p_buffer ) ...@@ -229,6 +316,7 @@ static int Write( sout_access_out_t *p_access, sout_buffer_t *p_buffer )
break; break;
} }
} }
if( i_err < 0 ) if( i_err < 0 )
{ {
sout_buffer_t *p_next; sout_buffer_t *p_next;
......
This diff is collapsed.
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* ogg.c * ogg.c
***************************************************************************** *****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN * Copyright (C) 2001, 2002 VideoLAN
* $Id: ogg.c,v 1.1 2003/02/24 23:27:20 fenrir Exp $ * $Id: ogg.c,v 1.2 2003/02/25 17:17:43 fenrir Exp $
* *
* Authors: Laurent Aimar <fenrir@via.ecp.fr> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* *
...@@ -327,9 +327,12 @@ static int DelStream( sout_instance_t *p_sout, sout_input_t *p_input ) ...@@ -327,9 +327,12 @@ static int DelStream( sout_instance_t *p_sout, sout_input_t *p_input )
/* flush all remaining data */ /* flush all remaining data */
p_og = OggStreamFlush( p_sout, &p_stream->os, 0 ); p_og = OggStreamFlush( p_sout, &p_stream->os, 0 );
if( p_og )
{
OggSetDate( p_og, p_stream->i_dts, p_stream->i_length ); OggSetDate( p_og, p_stream->i_dts, p_stream->i_length );
sout_AccessOutWrite( p_sout->p_access, p_og ); sout_AccessOutWrite( p_sout->p_access, p_og );
}
ogg_stream_clear( &p_stream->os ); ogg_stream_clear( &p_stream->os );
...@@ -509,6 +512,11 @@ static sout_buffer_t *OggCreateHeader( sout_instance_t *p_sout, mtime_t i_dts ) ...@@ -509,6 +512,11 @@ static sout_buffer_t *OggCreateHeader( sout_instance_t *p_sout, mtime_t i_dts )
sout_BufferChain( &p_hdr, p_og ); sout_BufferChain( &p_hdr, p_og );
} }
/* set HEADER flag */
for( p_og = p_hdr; p_og != NULL; p_og = p_og->p_next )
{
p_og->i_flags |= SOUT_BUFFER_FLAGS_HEADER;
}
return( p_hdr ); return( p_hdr );
} }
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* stream_output.c : stream output module * stream_output.c : stream output module
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * Copyright (C) 2002 VideoLAN
* $Id: stream_output.c,v 1.15 2003/02/24 23:28:18 fenrir Exp $ * $Id: stream_output.c,v 1.16 2003/02/25 17:17:43 fenrir Exp $
* *
* Authors: Christophe Massiot <massiot@via.ecp.fr> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* Laurent Aimar <fenrir@via.ecp.fr> * Laurent Aimar <fenrir@via.ecp.fr>
...@@ -639,6 +639,7 @@ sout_buffer_t *sout_BufferNew( sout_instance_t *p_sout, size_t i_size ) ...@@ -639,6 +639,7 @@ sout_buffer_t *sout_BufferNew( sout_instance_t *p_sout, size_t i_size )
p_buffer->i_dts = 0; p_buffer->i_dts = 0;
p_buffer->i_pts = 0; p_buffer->i_pts = 0;
p_buffer->i_bitrate = 0; p_buffer->i_bitrate = 0;
p_buffer->i_flags = 0x0000;
p_buffer->p_next = NULL; p_buffer->p_next = NULL;
return( p_buffer ); return( p_buffer );
...@@ -715,6 +716,7 @@ sout_buffer_t *sout_BufferDuplicate( sout_instance_t *p_sout, ...@@ -715,6 +716,7 @@ sout_buffer_t *sout_BufferDuplicate( sout_instance_t *p_sout,
p_dup->i_dts = p_buffer->i_dts; p_dup->i_dts = p_buffer->i_dts;
p_dup->i_pts = p_buffer->i_pts; p_dup->i_pts = p_buffer->i_pts;
p_dup->i_length = p_buffer->i_length; p_dup->i_length = p_buffer->i_length;
p_dup->i_flags = p_buffer->i_flags;
p_sout->p_vlc->pf_memcpy( p_dup->p_buffer, p_buffer->p_buffer, p_buffer->i_size ); p_sout->p_vlc->pf_memcpy( p_dup->p_buffer, p_buffer->p_buffer, p_buffer->i_size );
return( p_dup ); return( p_dup );
......
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