Commit 199aac88 authored by Laurent Aimar's avatar Laurent Aimar

* input: fixed buffer overflow, add sanity check and big big clean up.

(for the user filter part).
 For now, when a user filter can't be inserted it is just ignored. (before
the whole audio chain failed).
parent fc16dcf8
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
* input.c : internal management of input streams for the audio output * input.c : internal management of input streams for the audio output
***************************************************************************** *****************************************************************************
* Copyright (C) 2002 VideoLAN * Copyright (C) 2002 VideoLAN
* $Id: input.c,v 1.36 2003/08/19 21:20:00 zorglub Exp $ * $Id: input.c,v 1.37 2003/08/23 14:51:30 fenrir Exp $
* *
* Authors: Christophe Massiot <massiot@via.ecp.fr> * Authors: Christophe Massiot <massiot@via.ecp.fr>
* *
...@@ -36,14 +36,6 @@ ...@@ -36,14 +36,6 @@
#include "audio_output.h" #include "audio_output.h"
#include "aout_internal.h" #include "aout_internal.h"
typedef struct user_filter_t
{
char *psz_name;
aout_filter_t * p_filter;
audio_sample_format_t filter_inter_format;
struct user_filter_t *p_next;
} user_filter_t;
/***************************************************************************** /*****************************************************************************
* aout_InputNew : allocate a new input and rework the filter pipeline * aout_InputNew : allocate a new input and rework the filter pipeline
...@@ -51,18 +43,8 @@ typedef struct user_filter_t ...@@ -51,18 +43,8 @@ typedef struct user_filter_t
int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input ) int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input )
{ {
audio_sample_format_t intermediate_format; audio_sample_format_t intermediate_format;
#if 0
headphone_intermediate_format;
aout_filter_t * p_headphone_filter;
vlc_bool_t b_use_headphone_filter = VLC_FALSE;
#endif
vlc_bool_t b_end=VLC_FALSE; char * psz_filters;
user_filter_t* p_first_filter=NULL;
user_filter_t* p_current_filter=NULL;
char * psz_filters, *psz_eof;
aout_FormatPrint( p_aout, "input", &p_input->input ); aout_FormatPrint( p_aout, "input", &p_input->input );
...@@ -75,132 +57,6 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input ) ...@@ -75,132 +57,6 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input )
sizeof(audio_sample_format_t) ); sizeof(audio_sample_format_t) );
intermediate_format.i_rate = p_input->input.i_rate; intermediate_format.i_rate = p_input->input.i_rate;
/* Build the list of user filters */
psz_filters = config_GetPsz( p_aout , "audio-filter" );
p_first_filter = (user_filter_t *)malloc( sizeof( user_filter_t ) );
if( !p_first_filter )
{
msg_Err( p_aout, "Out of memory" );
return -1;
}
p_current_filter = p_first_filter;
p_current_filter->p_next = NULL;
memcpy( &p_current_filter->filter_inter_format,
&p_aout->mixer.mixer,sizeof(audio_sample_format_t));
p_current_filter->filter_inter_format.i_rate= p_input->input.i_rate;
if(psz_filters != NULL)
{
msg_Dbg(p_aout,"Building list of user filters");
while(1)
{
psz_eof = strchr( psz_filters , ',' );
if( !psz_eof )
{
b_end = VLC_TRUE;
psz_eof = strchr( psz_filters,'\0');
}
if( psz_eof )
{
*psz_eof = '\0';
}
msg_Dbg(p_aout,"Adding user filter: %s",psz_filters);
/* Append the new filter to the list */
p_current_filter->p_next =
(user_filter_t *)malloc(sizeof(user_filter_t));
if( !p_current_filter->p_next )
{
msg_Err( p_aout, "Out of memory" );
return -1;
}
memcpy( &p_current_filter->p_next->filter_inter_format,
&p_current_filter->filter_inter_format,
sizeof(audio_sample_format_t) );
p_current_filter->p_next->filter_inter_format.i_rate =
p_current_filter->filter_inter_format.i_rate;
p_current_filter->p_next->
filter_inter_format.i_physical_channels =
p_current_filter->filter_inter_format.i_physical_channels;
p_current_filter->p_next->
filter_inter_format.i_original_channels =
p_current_filter->filter_inter_format.i_original_channels;
p_current_filter->p_next->filter_inter_format.i_bytes_per_frame =
p_current_filter->p_next->
filter_inter_format.i_bytes_per_frame *
aout_FormatNbChannels(&p_current_filter->p_next->
filter_inter_format) /
aout_FormatNbChannels( &intermediate_format);
/* Go to next filter */
p_current_filter = p_current_filter->p_next;
p_current_filter->p_next= NULL;
p_current_filter->psz_name = strdup(psz_filters);
psz_filters = psz_eof;
psz_filters++;
if(!*psz_filters || b_end == VLC_TRUE)
break;
}
}
#if 0
/* Headphone filter add-ons. */
memcpy( &headphone_intermediate_format, &p_aout->mixer.mixer,
sizeof(audio_sample_format_t) );
headphone_intermediate_format.i_rate =
p_input->input.i_rate;
if ( config_GetInt( p_aout , "headphone-opt" ) )
{
/* Do we use heaphone filter ? */
if ( intermediate_format.i_physical_channels
== ( AOUT_CHAN_LEFT | AOUT_CHAN_RIGHT )
&& ( intermediate_format.i_format != VLC_FOURCC('f','l','3','2')
|| intermediate_format.i_format != VLC_FOURCC('f','i','3','2')
) )
{
b_use_headphone_filter = VLC_TRUE;
}
}
if ( b_use_headphone_filter == VLC_TRUE )
{
/* Split the filter pipeline. */
headphone_intermediate_format.i_physical_channels =
p_input->input.i_physical_channels;
headphone_intermediate_format.i_original_channels =
p_input->input.i_original_channels;
headphone_intermediate_format.i_bytes_per_frame =
headphone_intermediate_format.i_bytes_per_frame
* aout_FormatNbChannels( &headphone_intermediate_format )
/ aout_FormatNbChannels( &intermediate_format );
}
/* Create filters. */
if ( aout_FiltersCreatePipeline( p_aout, p_input->pp_filters,
&p_input->i_nb_filters, &p_input->input,
&intermediate_format ) < 0 )
{
msg_Err( p_aout, "couldn't set an input pipeline" );
aout_FifoDestroy( p_aout, &p_input->fifo );
p_input->b_error = 1;
return -1;
}
#endif
/* Create filters. */ /* Create filters. */
if ( aout_FiltersCreatePipeline( p_aout, p_input->pp_filters, if ( aout_FiltersCreatePipeline( p_aout, p_input->pp_filters,
&p_input->i_nb_filters, &p_input->i_nb_filters,
...@@ -214,113 +70,81 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input ) ...@@ -214,113 +70,81 @@ int aout_InputNew( aout_instance_t * p_aout, aout_input_t * p_input )
p_input->b_error = 1; p_input->b_error = 1;
} }
if( p_first_filter->p_next) /* Now add user filters */
if( ( psz_filters = config_GetPsz( p_aout , "audio-filter" ) ) )
{ {
msg_Dbg(p_aout,"Searching user filters..."); char *psz_parser = psz_filters;
p_current_filter = p_first_filter->p_next; char *psz_next;
audio_sample_format_t format_in, format_out;
memcpy( &format_in, &p_aout->mixer.mixer, sizeof( audio_sample_format_t ) );
memcpy( &format_out,&p_aout->mixer.mixer, sizeof( audio_sample_format_t ) );
format_in.i_rate = p_input->input.i_rate;
format_out.i_rate = p_input->input.i_rate;
/* Ok, we now start to get the filters, from the first one */ while( psz_parser && *psz_parser )
while( p_current_filter )
{ {
/* Create a VLC object */ aout_filter_t * p_filter;
p_current_filter->p_filter = vlc_object_create( p_aout,
sizeof(aout_filter_t) ); if( p_input->i_nb_filters >= AOUT_MAX_FILTERS )
if(p_current_filter->p_filter == NULL )
{ {
msg_Err( p_aout, "couldn't open the requested filter module" ); msg_Dbg( p_aout, "max filter reached (%d)", AOUT_MAX_FILTERS );
aout_FifoDestroy( p_aout, &p_input->fifo ); break;
p_input->b_error = 1;
return -1;
} }
vlc_object_attach( p_current_filter->p_filter , p_aout );
memcpy(&p_current_filter->p_filter->input,
&p_current_filter->filter_inter_format,
sizeof(audio_sample_format_t) );
if( p_current_filter->p_next) while( *psz_parser == ' ' && *psz_parser == ',' )
{ {
memcpy(&p_current_filter->p_filter->output, psz_parser++;
&p_current_filter->p_next->filter_inter_format,
sizeof(audio_sample_format_t) );
} }
else if( ( psz_next = strchr( psz_parser , ',' ) ) )
{ {
memcpy(&p_current_filter->p_filter->output, *psz_next++ = '\0';
&intermediate_format,
sizeof(audio_sample_format_t) );
} }
p_current_filter->p_filter->p_module = if( *psz_parser =='\0' )
module_Need(p_current_filter->p_filter,"audio filter",
p_current_filter->psz_name);
if(p_current_filter->p_filter->p_module== NULL )
{ {
vlc_object_detach( p_current_filter->p_filter); break;
vlc_object_destroy( p_current_filter->p_filter);
msg_Err( p_aout, "couldn't open the requested module" );
aout_FifoDestroy( p_aout, &p_input->fifo );
p_input->b_error = 1;
return -1;
} }
/* success */
p_current_filter->p_filter->b_continuity = VLC_FALSE;
p_input->pp_filters[p_input->i_nb_filters++] =
p_current_filter->p_filter;
/* Go to next */ msg_Dbg( p_aout, "user filter %s", psz_parser );
p_current_filter = p_current_filter->p_next;
}
}
/* Free the list */ /* Create a VLC object */
p_current_filter = p_first_filter; p_filter = vlc_object_create( p_aout, sizeof(aout_filter_t) );
while (p_current_filter) if( p_filter == NULL )
{ {
user_filter_t * p_old_filter = p_current_filter; msg_Err( p_aout, "cannot add user filter %s (skipped)", psz_parser );
p_current_filter = p_current_filter->p_next; psz_parser = psz_next;
free(p_old_filter); continue;
} }
vlc_object_attach( p_filter , p_aout );
memcpy( &p_filter->input, &format_in, sizeof(audio_sample_format_t) );
memcpy( &p_filter->output,&format_out,sizeof(audio_sample_format_t) );
#if 0
/* Headphone filter add-ons. */ p_filter->p_module =
if ( b_use_headphone_filter == VLC_TRUE ) module_Need( p_filter,"audio filter", psz_parser );
{
/* create a vlc object */ if( p_filter->p_module== NULL )
p_headphone_filter = vlc_object_create( p_aout
, sizeof(aout_filter_t) );
if ( p_headphone_filter == NULL )
{
msg_Err( p_aout, "couldn't open the headphone virtual spatialization module" );
aout_FifoDestroy( p_aout, &p_input->fifo );
p_input->b_error = 1;
return -1;
}
vlc_object_attach( p_headphone_filter, p_aout );
/* find the headphone filter */
memcpy( &p_headphone_filter->input, &headphone_intermediate_format
, sizeof(audio_sample_format_t) );
memcpy( &p_headphone_filter->output, &intermediate_format
, sizeof(audio_sample_format_t) );
p_headphone_filter->p_module = module_Need( p_headphone_filter, "audio filter"
, "headphone" );
if ( p_headphone_filter->p_module == NULL )
{ {
vlc_object_detach( p_headphone_filter ); msg_Err( p_aout, "cannot add user filter %s (skipped)", psz_parser );
vlc_object_destroy( p_headphone_filter );
vlc_object_detach( p_filter );
vlc_object_destroy( p_filter );
psz_parser = psz_next;
continue;
msg_Err( p_aout, "couldn't open the headphone virtual spatialization module" );
aout_FifoDestroy( p_aout, &p_input->fifo );
p_input->b_error = 1;
return -1;
} }
p_filter->b_continuity = VLC_FALSE;
p_input->pp_filters[p_input->i_nb_filters++] = p_filter;
/* success */ /* next filter if any */
p_headphone_filter->b_continuity = VLC_FALSE; psz_parser = psz_next;
p_input->pp_filters[p_input->i_nb_filters++] = p_headphone_filter;
} }
#endif free( psz_filters );
}
/* Prepare hints for the buffer allocator. */ /* Prepare hints for the buffer allocator. */
p_input->input_alloc.i_alloc_type = AOUT_ALLOC_HEAP; p_input->input_alloc.i_alloc_type = AOUT_ALLOC_HEAP;
......
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