* stream_output.h : stream output module
*****************************************************************************
* Copyright (C) 2002 VideoLAN
- * $Id: stream_output.h,v 1.3 2003/01/08 10:38:32 fenrir Exp $
+ * $Id: stream_output.h,v 1.4 2003/01/13 02:33:13 fenrir Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
* Laurent Aimar <fenrir@via.ecp.fr>
* sout_instance_t: stream output thread descriptor
*****************************************************************************/
+/*
+ * i_allocated_size: size of allocated buffer
+ * p_allocated_buffer: where data has been allocated
+ *
+ * i_buffer_size: sizeof buffer from p_buffer
+ * p_buffer: where data begins
+ * i_size: size of valid data
+ *
+ */
struct sout_buffer_t
{
size_t i_allocated_size;
+ byte_t *p_allocated_buffer;
+
+ size_t i_buffer_size;
byte_t *p_buffer;
size_t i_size;
-// mtime_t i_date;
mtime_t i_length;
mtime_t i_dts;
module_t *p_access;
int i_method;
void *p_access_data;
+ int i_access_preheader;
int (* pf_write )( sout_instance_t *, sout_buffer_t * );
int (* pf_seek )( sout_instance_t *, off_t );
module_t *p_mux;
void *p_mux_data;
+ int i_mux_preheader;
int (* pf_mux_addstream )( sout_instance_t *,
sout_input_t * );
int (* pf_mux_delstream )( sout_instance_t *,
VLC_EXPORT( sout_buffer_t*, sout_BufferNew, ( sout_instance_t *, size_t ) );
VLC_EXPORT( int, sout_BufferRealloc,( sout_instance_t *, sout_buffer_t*, size_t ) );
+VLC_EXPORT( int, sout_BufferReallocFromPreHeader,( sout_instance_t *, sout_buffer_t*, size_t ) );
VLC_EXPORT( int, sout_BufferDelete, ( sout_instance_t *, sout_buffer_t* ) );
VLC_EXPORT( sout_buffer_t*, sout_BufferDuplicate,(sout_instance_t *, sout_buffer_t * ) );
VLC_EXPORT( void, sout_BufferChain, ( sout_buffer_t **, sout_buffer_t * ) );
* avi.c
*****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN
- * $Id: avi.c,v 1.1 2003/01/12 04:30:14 fenrir Exp $
+ * $Id: avi.c,v 1.2 2003/01/13 02:33:13 fenrir Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
*
p_sout->pf_mux_addstream = AddStream;
p_sout->pf_mux_delstream = DelStream;
p_sout->pf_mux = Mux;
-
p_sout->p_mux_data = (void*)p_mux;
+ p_sout->i_mux_preheader = 8; // (fourcc,length) header
/* room to add header at the end */
p_hdr = sout_BufferNew( p_sout, HDR_SIZE );
while( i_count > 0 )
{
sout_buffer_t *p_data;
- sout_buffer_t *p_hdr;
p_data = sout_FifoGet( p_fifo );
p_stream->i_duration += p_data->i_length;
p_stream->i_totalsize += p_data->i_size;
- p_hdr = sout_BufferNew( p_sout, 8 );
- SetFCC( p_hdr->p_buffer, p_stream->fcc );
- SetDWLE( p_hdr->p_buffer + 4, p_data->i_size );
+ if( sout_BufferReallocFromPreHeader( p_sout, p_data, 8 ) )
+ {
+ /* there isn't enough data in preheader */
+ sout_buffer_t *p_hdr;
+
+ p_hdr = sout_BufferNew( p_sout, 8 );
+ SetFCC( p_hdr->p_buffer, p_stream->fcc );
+ SetDWLE( p_hdr->p_buffer + 4, p_data->i_size );
+
+ p_sout->pf_write( p_sout, p_hdr );
+ p_mux->i_movi_size += p_hdr->i_size;
+
+ }
+ else
+ {
+ SetFCC( p_data->p_buffer, p_stream->fcc );
+ SetDWLE( p_data->p_buffer + 4, p_data->i_size - 8 );
+ }
if( p_data->i_size & 0x01 )
{
p_data->i_size += 1;
}
- p_sout->pf_write( p_sout, p_hdr );
- p_mux->i_movi_size += p_hdr->i_size;
p_sout->pf_write( p_sout, p_data );
p_mux->i_movi_size += p_data->i_size;
* ps.c
*****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN
- * $Id: ps.c,v 1.4 2003/01/08 10:34:58 fenrir Exp $
+ * $Id: ps.c,v 1.5 2003/01/13 02:33:13 fenrir Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Eric Petit <titer@videolan.org>
p_sout->pf_mux_delstream = DelStream;
p_sout->pf_mux = Mux;
p_sout->p_mux_data = (void*)p_mux;
+ p_sout->i_mux_preheader = 30; // really enough for a pes header
p_mux->i_stream_id_mpga = 0xc0;
p_mux->i_stream_id_a52 = 0x80;
* ts.c
*****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN
- * $Id: ts.c,v 1.6 2003/01/11 17:23:13 ipkiss Exp $
+ * $Id: ts.c,v 1.7 2003/01/13 02:33:13 fenrir Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Eric Petit <titer@videolan.org>
p_sout->pf_mux_delstream = DelStream;
p_sout->pf_mux = Mux;
p_sout->p_mux_data = (void*)p_mux;
+ p_sout->i_mux_preheader = 30; // really enough for a pes header
srand( (uint32_t)mdate() );
* mpegvideo.c
*****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN
- * $Id: mpegvideo.c,v 1.2 2003/01/08 10:26:49 fenrir Exp $
+ * $Id: mpegvideo.c,v 1.3 2003/01/13 02:33:13 fenrir Exp $
*
* Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Eric Petit <titer@videolan.org>
GetBits( &p_pack->bit_stream, 8 );
i_copy++;
- if( *pi_pos + 2048 > p_sout_buffer->i_allocated_size )
+ if( *pi_pos + 2048 > p_sout_buffer->i_buffer_size )
{
sout_BufferRealloc( p_pack->p_sout_input->p_sout,
p_sout_buffer,
- p_sout_buffer->i_allocated_size + 50 * 1024);
+ p_sout_buffer->i_buffer_size + 50 * 1024);
}
} while( ShowBits( &p_pack->bit_stream, 24 ) != 0x01 &&
* stream_output.c : stream output module
*****************************************************************************
* Copyright (C) 2002 VideoLAN
- * $Id: stream_output.c,v 1.8 2003/01/08 14:59:23 sam Exp $
+ * $Id: stream_output.c,v 1.9 2003/01/13 02:33:13 fenrir Exp $
*
* Authors: Christophe Massiot <massiot@via.ecp.fr>
* Laurent Aimar <fenrir@via.ecp.fr>
p_sout->psz_name = "";
p_sout->p_access = NULL;
p_sout->p_mux = NULL;
+ p_sout->i_access_preheader = 0;
+ p_sout->i_mux_preheader = 0;
p_sout->i_nb_inputs = 0;
p_sout->pp_inputs = NULL;
vlc_mutex_init( p_sout, &p_sout->lock );
sout_buffer_t *sout_BufferNew( sout_instance_t *p_sout, size_t i_size )
{
sout_buffer_t *p_buffer;
+ size_t i_prehader;
#ifdef DEBUG_BUFFER
msg_Dbg( p_sout, "allocating an new buffer, size:%d", (uint32_t)i_size );
#endif
p_buffer = malloc( sizeof( sout_buffer_t ) );
+ i_prehader = p_sout->i_access_preheader + p_sout->i_mux_preheader;
+
if( i_size > 0 )
{
- p_buffer->p_buffer = malloc( i_size );
+ p_buffer->p_allocated_buffer = malloc( i_size + i_prehader );
+ p_buffer->p_buffer = p_buffer->p_allocated_buffer + i_prehader;
}
else
{
+ p_buffer->p_allocated_buffer = NULL;
p_buffer->p_buffer = NULL;
}
- p_buffer->i_allocated_size = i_size;
+ p_buffer->i_allocated_size = i_size + i_prehader;
+ p_buffer->i_buffer_size = i_size;
+
p_buffer->i_size = i_size;
+ p_buffer->i_length = 0;
+ p_buffer->i_dts = 0;
+ p_buffer->i_pts = 0;
+ p_buffer->i_bitrate = 0;
p_buffer->p_next = NULL;
return( p_buffer );
}
int sout_BufferRealloc( sout_instance_t *p_sout, sout_buffer_t *p_buffer, size_t i_size )
{
+ size_t i_prehader;
+
#ifdef DEBUG_BUFFER
msg_Dbg( p_sout,
"realloc buffer old size:%d new size:%d",
(uint32_t)p_buffer->i_allocated_size,
(uint32_t)i_size );
#endif
- if( !( p_buffer->p_buffer = realloc( p_buffer->p_buffer, i_size ) ) )
+
+ i_prehader = p_buffer->p_buffer - p_buffer->p_allocated_buffer;
+
+ if( !( p_buffer->p_allocated_buffer = realloc( p_buffer->p_allocated_buffer, i_size + i_prehader ) ) )
{
msg_Err( p_sout, "realloc failed" );
p_buffer->i_allocated_size = 0;
+ p_buffer->i_buffer_size = 0;
p_buffer->i_size = 0;
-
+ p_buffer->p_buffer = NULL;
return( -1 );
}
+ p_buffer->p_buffer = p_buffer->p_allocated_buffer + i_prehader;
+
+ p_buffer->i_allocated_size = i_size + i_prehader;
+ p_buffer->i_buffer_size = i_size;
- p_buffer->i_allocated_size = i_size;
return( 0 );
}
+int sout_BufferReallocFromPreHeader( sout_instance_t *p_sout, sout_buffer_t *p_buffer, size_t i_size )
+{
+ size_t i_preheader;
+
+ i_preheader = p_buffer->p_buffer - p_buffer->p_allocated_buffer;
+
+ if( i_preheader < i_size )
+ {
+ return( -1 );
+ }
+
+ p_buffer->p_buffer -= i_size;
+ p_buffer->i_size += i_size;
+ p_buffer->i_buffer_size += i_size;
+}
+
int sout_BufferDelete( sout_instance_t *p_sout, sout_buffer_t *p_buffer )
{
#ifdef DEBUG_BUFFER
msg_Dbg( p_sout, "freeing buffer, size:%d", p_buffer->i_size );
#endif
- if( p_buffer->p_buffer )
+ if( p_buffer->p_allocated_buffer )
{
- free( p_buffer->p_buffer );
+ free( p_buffer->p_allocated_buffer );
}
free( p_buffer );
return( 0 );