Commit 9d72fcf7 authored by Laurent Aimar's avatar Laurent Aimar

* all: now mux and access_out can request to reserve some memory in front

of each sout buffer (will prevent some unnecessary memcpy :). Not yet
really used.
parent 4f21763a
...@@ -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.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> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* Laurent Aimar <fenrir@via.ecp.fr> * Laurent Aimar <fenrir@via.ecp.fr>
...@@ -27,13 +27,24 @@ ...@@ -27,13 +27,24 @@
* sout_instance_t: stream output thread descriptor * 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 struct sout_buffer_t
{ {
size_t i_allocated_size; size_t i_allocated_size;
byte_t *p_allocated_buffer;
size_t i_buffer_size;
byte_t *p_buffer; byte_t *p_buffer;
size_t i_size; size_t i_size;
// mtime_t i_date;
mtime_t i_length; mtime_t i_length;
mtime_t i_dts; mtime_t i_dts;
...@@ -91,11 +102,13 @@ struct sout_instance_t ...@@ -91,11 +102,13 @@ struct sout_instance_t
module_t *p_access; module_t *p_access;
int i_method; int i_method;
void *p_access_data; void *p_access_data;
int i_access_preheader;
int (* pf_write )( sout_instance_t *, sout_buffer_t * ); int (* pf_write )( sout_instance_t *, sout_buffer_t * );
int (* pf_seek )( sout_instance_t *, off_t ); int (* pf_seek )( sout_instance_t *, off_t );
module_t *p_mux; module_t *p_mux;
void *p_mux_data; void *p_mux_data;
int i_mux_preheader;
int (* pf_mux_addstream )( sout_instance_t *, int (* pf_mux_addstream )( sout_instance_t *,
sout_input_t * ); sout_input_t * );
int (* pf_mux_delstream )( sout_instance_t *, int (* pf_mux_delstream )( sout_instance_t *,
...@@ -135,6 +148,7 @@ VLC_EXPORT( int, sout_InputSendBuffer, ( sout_input_t *, sout_buffer ...@@ -135,6 +148,7 @@ VLC_EXPORT( int, sout_InputSendBuffer, ( sout_input_t *, sout_buffer
VLC_EXPORT( sout_buffer_t*, sout_BufferNew, ( sout_instance_t *, size_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_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( int, sout_BufferDelete, ( sout_instance_t *, sout_buffer_t* ) );
VLC_EXPORT( sout_buffer_t*, sout_BufferDuplicate,(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 * ) ); VLC_EXPORT( void, sout_BufferChain, ( sout_buffer_t **, sout_buffer_t * ) );
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* avi.c * avi.c
***************************************************************************** *****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN * 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> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* *
...@@ -140,8 +140,8 @@ static int Open( vlc_object_t *p_this ) ...@@ -140,8 +140,8 @@ static int Open( vlc_object_t *p_this )
p_sout->pf_mux_addstream = AddStream; p_sout->pf_mux_addstream = AddStream;
p_sout->pf_mux_delstream = DelStream; p_sout->pf_mux_delstream = DelStream;
p_sout->pf_mux = Mux; p_sout->pf_mux = Mux;
p_sout->p_mux_data = (void*)p_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 */ /* room to add header at the end */
p_hdr = sout_BufferNew( p_sout, HDR_SIZE ); p_hdr = sout_BufferNew( p_sout, HDR_SIZE );
...@@ -303,7 +303,6 @@ static int Mux ( sout_instance_t *p_sout ) ...@@ -303,7 +303,6 @@ static int Mux ( sout_instance_t *p_sout )
while( i_count > 0 ) while( i_count > 0 )
{ {
sout_buffer_t *p_data; sout_buffer_t *p_data;
sout_buffer_t *p_hdr;
p_data = sout_FifoGet( p_fifo ); p_data = sout_FifoGet( p_fifo );
...@@ -311,9 +310,24 @@ static int Mux ( sout_instance_t *p_sout ) ...@@ -311,9 +310,24 @@ static int Mux ( sout_instance_t *p_sout )
p_stream->i_duration += p_data->i_length; p_stream->i_duration += p_data->i_length;
p_stream->i_totalsize += p_data->i_size; p_stream->i_totalsize += p_data->i_size;
p_hdr = sout_BufferNew( p_sout, 8 ); if( sout_BufferReallocFromPreHeader( p_sout, p_data, 8 ) )
SetFCC( p_hdr->p_buffer, p_stream->fcc ); {
SetDWLE( p_hdr->p_buffer + 4, p_data->i_size ); /* 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 ) if( p_data->i_size & 0x01 )
{ {
...@@ -321,8 +335,6 @@ static int Mux ( sout_instance_t *p_sout ) ...@@ -321,8 +335,6 @@ static int Mux ( sout_instance_t *p_sout )
p_data->i_size += 1; 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_sout->pf_write( p_sout, p_data );
p_mux->i_movi_size += p_data->i_size; p_mux->i_movi_size += p_data->i_size;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* ps.c * ps.c
***************************************************************************** *****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN * 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> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Eric Petit <titer@videolan.org> * Eric Petit <titer@videolan.org>
...@@ -120,6 +120,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -120,6 +120,7 @@ static int Open( vlc_object_t *p_this )
p_sout->pf_mux_delstream = DelStream; p_sout->pf_mux_delstream = DelStream;
p_sout->pf_mux = Mux; p_sout->pf_mux = Mux;
p_sout->p_mux_data = (void*)p_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_mpga = 0xc0;
p_mux->i_stream_id_a52 = 0x80; p_mux->i_stream_id_a52 = 0x80;
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* ts.c * ts.c
***************************************************************************** *****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN * 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> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Eric Petit <titer@videolan.org> * Eric Petit <titer@videolan.org>
...@@ -158,6 +158,7 @@ static int Open( vlc_object_t *p_this ) ...@@ -158,6 +158,7 @@ static int Open( vlc_object_t *p_this )
p_sout->pf_mux_delstream = DelStream; p_sout->pf_mux_delstream = DelStream;
p_sout->pf_mux = Mux; p_sout->pf_mux = Mux;
p_sout->p_mux_data = (void*)p_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() ); srand( (uint32_t)mdate() );
......
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* mpegvideo.c * mpegvideo.c
***************************************************************************** *****************************************************************************
* Copyright (C) 2001, 2002 VideoLAN * 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> * Authors: Laurent Aimar <fenrir@via.ecp.fr>
* Eric Petit <titer@videolan.org> * Eric Petit <titer@videolan.org>
...@@ -188,11 +188,11 @@ static int CopyUntilNextStartCode( packetizer_t *p_pack, ...@@ -188,11 +188,11 @@ static int CopyUntilNextStartCode( packetizer_t *p_pack,
GetBits( &p_pack->bit_stream, 8 ); GetBits( &p_pack->bit_stream, 8 );
i_copy++; 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, sout_BufferRealloc( p_pack->p_sout_input->p_sout,
p_sout_buffer, 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 && } while( ShowBits( &p_pack->bit_stream, 24 ) != 0x01 &&
......
...@@ -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.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> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* Laurent Aimar <fenrir@via.ecp.fr> * Laurent Aimar <fenrir@via.ecp.fr>
...@@ -82,6 +82,8 @@ static int InitInstance( sout_instance_t * p_sout ) ...@@ -82,6 +82,8 @@ static int InitInstance( sout_instance_t * p_sout )
p_sout->psz_name = ""; p_sout->psz_name = "";
p_sout->p_access = NULL; p_sout->p_access = NULL;
p_sout->p_mux = 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->i_nb_inputs = 0;
p_sout->pp_inputs = NULL; p_sout->pp_inputs = NULL;
vlc_mutex_init( p_sout, &p_sout->lock ); vlc_mutex_init( p_sout, &p_sout->lock );
...@@ -478,55 +480,91 @@ sout_buffer_t *sout_FifoShow( sout_fifo_t *p_fifo ) ...@@ -478,55 +480,91 @@ sout_buffer_t *sout_FifoShow( sout_fifo_t *p_fifo )
sout_buffer_t *sout_BufferNew( sout_instance_t *p_sout, size_t i_size ) sout_buffer_t *sout_BufferNew( sout_instance_t *p_sout, size_t i_size )
{ {
sout_buffer_t *p_buffer; sout_buffer_t *p_buffer;
size_t i_prehader;
#ifdef DEBUG_BUFFER #ifdef DEBUG_BUFFER
msg_Dbg( p_sout, "allocating an new buffer, size:%d", (uint32_t)i_size ); msg_Dbg( p_sout, "allocating an new buffer, size:%d", (uint32_t)i_size );
#endif #endif
p_buffer = malloc( sizeof( sout_buffer_t ) ); p_buffer = malloc( sizeof( sout_buffer_t ) );
i_prehader = p_sout->i_access_preheader + p_sout->i_mux_preheader;
if( i_size > 0 ) 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 else
{ {
p_buffer->p_allocated_buffer = NULL;
p_buffer->p_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_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; p_buffer->p_next = NULL;
return( p_buffer ); return( p_buffer );
} }
int sout_BufferRealloc( sout_instance_t *p_sout, sout_buffer_t *p_buffer, size_t i_size ) int sout_BufferRealloc( sout_instance_t *p_sout, sout_buffer_t *p_buffer, size_t i_size )
{ {
size_t i_prehader;
#ifdef DEBUG_BUFFER #ifdef DEBUG_BUFFER
msg_Dbg( p_sout, msg_Dbg( p_sout,
"realloc buffer old size:%d new size:%d", "realloc buffer old size:%d new size:%d",
(uint32_t)p_buffer->i_allocated_size, (uint32_t)p_buffer->i_allocated_size,
(uint32_t)i_size ); (uint32_t)i_size );
#endif #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" ); msg_Err( p_sout, "realloc failed" );
p_buffer->i_allocated_size = 0; p_buffer->i_allocated_size = 0;
p_buffer->i_buffer_size = 0;
p_buffer->i_size = 0; p_buffer->i_size = 0;
p_buffer->p_buffer = NULL;
return( -1 ); 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 ); 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 ) int sout_BufferDelete( sout_instance_t *p_sout, sout_buffer_t *p_buffer )
{ {
#ifdef DEBUG_BUFFER #ifdef DEBUG_BUFFER
msg_Dbg( p_sout, "freeing buffer, size:%d", p_buffer->i_size ); msg_Dbg( p_sout, "freeing buffer, size:%d", p_buffer->i_size );
#endif #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 ); free( p_buffer );
return( 0 ); return( 0 );
......
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