Commit 1007fd93 authored by Laurent Aimar's avatar Laurent Aimar

* stream_output: sout_buffer_t -> block_t.

parent f31861b0
......@@ -51,10 +51,8 @@ static char *_sout_stream_url_to_chain( vlc_object_t *, char * );
typedef struct
{
char *psz_access;
char *psz_way;
char *psz_access;
char *psz_way;
char *psz_name;
} mrl_t;
......@@ -68,8 +66,7 @@ static void mrl_Clean( mrl_t *p_mrl );
/*****************************************************************************
* sout_NewInstance: creates a new stream output instance
*****************************************************************************/
sout_instance_t * __sout_NewInstance ( vlc_object_t *p_parent,
char * psz_dest )
sout_instance_t *__sout_NewInstance( vlc_object_t *p_parent, char * psz_dest )
{
sout_instance_t *p_sout;
vlc_value_t keep;
......@@ -120,8 +117,6 @@ sout_instance_t * __sout_NewInstance ( vlc_object_t *p_parent,
/* *** init descriptor *** */
p_sout->psz_sout = strdup( psz_dest );
p_sout->p_meta = NULL;
p_sout->i_preheader = 0;
p_sout->i_padding = 0;
p_sout->i_out_pace_nocontrol = 0;
p_sout->p_sys = NULL;
......@@ -146,7 +141,7 @@ sout_instance_t * __sout_NewInstance ( vlc_object_t *p_parent,
FREE( p_sout->psz_chain );
vlc_object_destroy( p_sout );
return( NULL );
return NULL;
}
vlc_object_attach( p_sout, p_parent );
......@@ -215,7 +210,9 @@ sout_packetizer_input_t *sout_InputNew( sout_instance_t *p_sout,
return( p_input );
}
/*****************************************************************************
*
*****************************************************************************/
int sout_InputDelete( sout_packetizer_input_t *p_input )
{
sout_instance_t *p_sout = p_input->p_sout;
......@@ -234,22 +231,24 @@ int sout_InputDelete( sout_packetizer_input_t *p_input )
return( VLC_SUCCESS);
}
/*****************************************************************************
*
*****************************************************************************/
int sout_InputSendBuffer( sout_packetizer_input_t *p_input,
sout_buffer_t *p_buffer )
block_t *p_buffer )
{
sout_instance_t *p_sout = p_input->p_sout;
int i_ret;
if( p_input->p_fmt->i_codec == VLC_FOURCC( 'n', 'u', 'l', 'l' ) )
{
sout_BufferDelete( p_input->p_sout, p_buffer );
block_Release( p_buffer );
return VLC_SUCCESS;
}
if( !p_buffer->i_dts )
if( p_buffer->i_dts <= 0 )
{
msg_Warn( p_sout, "trying to send non-dated packet to stream output!");
sout_BufferDelete( p_input->p_sout, p_buffer );
block_Release( p_buffer );
return VLC_SUCCESS;
}
......@@ -332,22 +331,22 @@ int sout_AccessOutSeek( sout_access_out_t *p_access, off_t i_pos )
/*****************************************************************************
* sout_AccessRead:
*****************************************************************************/
int sout_AccessOutRead( sout_access_out_t *p_access, sout_buffer_t *p_buffer )
int sout_AccessOutRead( sout_access_out_t *p_access, block_t *p_buffer )
{
return ( p_access->pf_read ?
p_access->pf_read( p_access, p_buffer ) : VLC_EGENERIC );
return( p_access->pf_read ?
p_access->pf_read( p_access, p_buffer ) : VLC_EGENERIC );
}
/*****************************************************************************
* sout_AccessWrite:
*****************************************************************************/
int sout_AccessOutWrite( sout_access_out_t *p_access, sout_buffer_t *p_buffer )
int sout_AccessOutWrite( sout_access_out_t *p_access, block_t *p_buffer )
{
return p_access->pf_write( p_access, p_buffer );
}
/*****************************************************************************
* MuxNew: allocate a new mux
* sout_MuxNew: create a new mux
*****************************************************************************/
sout_mux_t * sout_MuxNew ( sout_instance_t *p_sout,
char *psz_mux,
......@@ -371,7 +370,6 @@ sout_mux_t * sout_MuxNew ( sout_instance_t *p_sout,
free( psz_next );
}
p_mux->p_access = p_access;
p_mux->i_preheader = 0;
p_mux->pf_capacity = NULL;
p_mux->pf_addstream = NULL;
p_mux->pf_delstream = NULL;
......@@ -437,6 +435,9 @@ sout_mux_t * sout_MuxNew ( sout_instance_t *p_sout,
return p_mux;
}
/*****************************************************************************
* sout_MuxDelete:
*****************************************************************************/
void sout_MuxDelete( sout_mux_t *p_mux )
{
if( p_mux->p_module )
......@@ -450,6 +451,9 @@ void sout_MuxDelete( sout_mux_t *p_mux )
vlc_object_destroy( p_mux );
}
/*****************************************************************************
* sout_MuxAddStream:
*****************************************************************************/
sout_input_t *sout_MuxAddStream( sout_mux_t *p_mux, es_format_t *p_fmt )
{
sout_input_t *p_input;
......@@ -472,7 +476,7 @@ sout_input_t *sout_MuxAddStream( sout_mux_t *p_mux, es_format_t *p_fmt )
p_input = malloc( sizeof( sout_input_t ) );
p_input->p_sout = p_mux->p_sout;
p_input->p_fmt = p_fmt;
p_input->p_fifo = sout_FifoCreate( p_mux->p_sout );
p_input->p_fifo = block_FifoNew( p_mux->p_sout );
p_input->p_sys = NULL;
TAB_APPEND( p_mux->i_nb_inputs, p_mux->pp_inputs, p_input );
......@@ -480,16 +484,18 @@ sout_input_t *sout_MuxAddStream( sout_mux_t *p_mux, es_format_t *p_fmt )
{
msg_Err( p_mux, "cannot add this stream" );
TAB_REMOVE( p_mux->i_nb_inputs, p_mux->pp_inputs, p_input );
sout_FifoDestroy( p_mux->p_sout, p_input->p_fifo );
block_FifoRelease( p_input->p_fifo );
free( p_input );
return( NULL );
return NULL;
}
return( p_input );
return p_input;
}
void sout_MuxDeleteStream ( sout_mux_t *p_mux,
sout_input_t *p_input )
/*****************************************************************************
* sout_MuxDeleteStream:
*****************************************************************************/
void sout_MuxDeleteStream( sout_mux_t *p_mux, sout_input_t *p_input )
{
int i_index;
......@@ -509,16 +515,18 @@ void sout_MuxDeleteStream ( sout_mux_t *p_mux,
msg_Warn( p_mux, "no more input stream for this mux" );
}
sout_FifoDestroy( p_mux->p_sout, p_input->p_fifo );
block_FifoRelease( p_input->p_fifo );
free( p_input );
}
}
void sout_MuxSendBuffer ( sout_mux_t *p_mux,
sout_input_t *p_input,
sout_buffer_t *p_buffer )
/*****************************************************************************
* sout_MuxSendBuffer:
*****************************************************************************/
void sout_MuxSendBuffer( sout_mux_t *p_mux, sout_input_t *p_input,
block_t *p_buffer )
{
sout_FifoPut( p_input->p_fifo, p_buffer );
block_FifoPut( p_input->p_fifo, p_buffer );
if( p_mux->b_waiting_stream )
{
......@@ -536,266 +544,9 @@ void sout_MuxSendBuffer ( sout_mux_t *p_mux,
p_mux->pf_mux( p_mux );
}
sout_fifo_t *sout_FifoCreate( sout_instance_t *p_sout )
{
sout_fifo_t *p_fifo;
if( !( p_fifo = malloc( sizeof( sout_fifo_t ) ) ) )
{
return( NULL );
}
vlc_mutex_init( p_sout, &p_fifo->lock );
vlc_cond_init ( p_sout, &p_fifo->wait );
p_fifo->i_depth = 0;
p_fifo->p_first = NULL;
p_fifo->pp_last = &p_fifo->p_first;
return( p_fifo );
}
void sout_FifoFree( sout_instance_t *p_sout, sout_fifo_t *p_fifo )
{
sout_buffer_t *p_buffer;
vlc_mutex_lock( &p_fifo->lock );
p_buffer = p_fifo->p_first;
while( p_buffer )
{
sout_buffer_t *p_next;
p_next = p_buffer->p_next;
sout_BufferDelete( p_sout, p_buffer );
p_buffer = p_next;
}
vlc_mutex_unlock( &p_fifo->lock );
return;
}
void sout_FifoDestroy( sout_instance_t *p_sout, sout_fifo_t *p_fifo )
{
sout_FifoFree( p_sout, p_fifo );
vlc_mutex_destroy( &p_fifo->lock );
vlc_cond_destroy ( &p_fifo->wait );
free( p_fifo );
}
void sout_FifoPut( sout_fifo_t *p_fifo, sout_buffer_t *p_buffer )
{
vlc_mutex_lock( &p_fifo->lock );
do
{
*p_fifo->pp_last = p_buffer;
p_fifo->pp_last = &p_buffer->p_next;
p_fifo->i_depth++;
p_buffer = p_buffer->p_next;
} while( p_buffer );
/* warm there is data in this fifo */
vlc_cond_signal( &p_fifo->wait );
vlc_mutex_unlock( &p_fifo->lock );
}
sout_buffer_t *sout_FifoGet( sout_fifo_t *p_fifo )
{
sout_buffer_t *p_buffer;
vlc_mutex_lock( &p_fifo->lock );
if( p_fifo->p_first == NULL )
{
vlc_cond_wait( &p_fifo->wait, &p_fifo->lock );
}
p_buffer = p_fifo->p_first;
p_fifo->p_first = p_buffer->p_next;
p_fifo->i_depth--;
if( p_fifo->p_first == NULL )
{
p_fifo->pp_last = &p_fifo->p_first;
}
vlc_mutex_unlock( &p_fifo->lock );
p_buffer->p_next = NULL;
return( p_buffer );
}
sout_buffer_t *sout_FifoShow( sout_fifo_t *p_fifo )
{
sout_buffer_t *p_buffer;
vlc_mutex_lock( &p_fifo->lock );
if( p_fifo->p_first == NULL )
{
vlc_cond_wait( &p_fifo->wait, &p_fifo->lock );
}
p_buffer = p_fifo->p_first;
vlc_mutex_unlock( &p_fifo->lock );
return( p_buffer );
}
sout_buffer_t *sout_BufferNew( sout_instance_t *p_sout, size_t i_size )
{
sout_buffer_t *p_buffer;
size_t i_preheader, i_padding;
p_buffer = malloc( sizeof( sout_buffer_t ) );
i_preheader = p_sout->i_preheader;
i_padding = p_sout->i_padding;
#ifdef DEBUG_BUFFER
msg_Dbg( p_sout, "allocating an new buffer, size:%d, preheader:%d, "
"padding:%d", (uint32_t)i_size, i_preheader, i_padding );
#endif
if( i_size > 0 )
{
p_buffer->p_allocated_buffer =
malloc( i_size + i_preheader + i_padding );
p_buffer->p_buffer = p_buffer->p_allocated_buffer + i_preheader;
if( p_buffer->p_allocated_buffer && i_padding )
memset( p_buffer->p_allocated_buffer + i_size + i_preheader, 0,
i_padding );
}
else
{
p_buffer->p_allocated_buffer = NULL;
p_buffer->p_buffer = NULL;
}
p_buffer->i_allocated_size = i_size + i_preheader + i_padding;
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->i_flags = 0x0000;
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_preheader, i_padding;
i_preheader = p_buffer->p_buffer - p_buffer->p_allocated_buffer;
i_padding = p_buffer->i_allocated_size - p_buffer->i_buffer_size
- i_preheader;
#ifdef DEBUG_BUFFER
msg_Dbg( p_sout, "realloc buffer old size:%d new size:%d, preheader:%d, "
"padding:%d", (uint32_t)p_buffer->i_allocated_size,
(uint32_t)i_size, i_preheader, i_padding );
#endif
if( !( p_buffer->p_allocated_buffer =
realloc( p_buffer->p_allocated_buffer,
i_size + i_preheader + i_padding ) ) )
{
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_preheader;
p_buffer->i_allocated_size = i_size + i_preheader + i_padding;
p_buffer->i_buffer_size = i_size;
if( i_padding )
memset( p_buffer->p_allocated_buffer + i_size + i_preheader, 0,
i_padding );
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;
return( 0 );
}
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_allocated_buffer )
{
free( p_buffer->p_allocated_buffer );
}
free( p_buffer );
return( 0 );
}
sout_buffer_t *sout_BufferDuplicate( sout_instance_t *p_sout,
sout_buffer_t *p_buffer )
{
sout_buffer_t *p_dup;
p_dup = sout_BufferNew( p_sout, p_buffer->i_size );
p_dup->i_bitrate= p_buffer->i_bitrate;
p_dup->i_dts = p_buffer->i_dts;
p_dup->i_pts = p_buffer->i_pts;
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 );
return( p_dup );
}
void sout_BufferChain( sout_buffer_t **pp_chain,
sout_buffer_t *p_buffer )
{
if( *pp_chain == NULL )
{
*pp_chain = p_buffer;
}
else if( p_buffer != NULL )
{
sout_buffer_t *p = *pp_chain;
while( p->p_next )
{
p = p->p_next;
}
p->p_next = p_buffer;
}
}
/*****************************************************************************
*
*****************************************************************************/
static int mrl_Parse( mrl_t *p_mrl, char *psz_mrl )
{
char * psz_dup = strdup( psz_mrl );
......@@ -1034,8 +785,6 @@ char * sout_cfg_parser( char **ppsz_name, sout_cfg_t **pp_cfg, char *psz_chain )
*ppsz_name = _strndup( psz_chain, p - psz_chain );
/* fprintf( stderr, "name=%s - rest=%s\n", *ppsz_name, p ); */
SKIPSPACE( p );
if( *p == '{' )
......@@ -1073,39 +822,7 @@ char * sout_cfg_parser( char **ppsz_name, sout_cfg_t **pp_cfg, char *psz_chain )
char *end;
p++;
#if 0
SKIPSPACE( p );
if( *p == '"' )
{
char *end;
p++;
end = strchr( p, '"' );
if( end )
{
/* fprintf( stderr, "##%s -- %s\n", p, end ); */
cfg.psz_value = _strndup( p, end - p );
p = end + 1;
}
else
{
cfg.psz_value = strdup( p );
p += strlen( p );
}
}
else
{
psz_value = p;
while( *p && *p != ',' && *p != '}' && *p != ' ' && *p != '\t' )
{
p++;
}
cfg.psz_value = _strndup( psz_value, p - psz_value );
}
#endif
end = _get_chain_end( p );
if( end <= p )
{
......
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